nf-next pull request
Subsystems (5)
Pablo Neira Ayuso
maintainercover nf-next pull request
Hi David,
The following patchset contains Netfilter/IPVS updates for your net-next tree. Regarding nf_tables, most updates focus on consolidating the NAT infrastructure and adding support for masquerading. More specifically, they are:
1) use __u8 instead of u_int8_t in arptables header, from Mike Frysinger.
2) Add support to match by skb->pkttype to the meta expression, from Ana Rey.
3) Add support to match by cpu to the meta expression, also from Ana Rey.
4) A smatch warning about IPSET_ATTR_MARKMASK validation, patch from Vytas Dauksa.
5) Fix netnet and netportnet hash types the range support for IPv4, from Sergey Popovich.
6) Fix missing-field-initializer warnings resolved, from Mark Rustad.
7) Dan Carperter reported possible integer overflows in ipset, from Jozsef Kadlecsick.
8) Filter out accounting objects in nfacct by type, so you can selectively reset quotas, from Alexey Perevalov.
9) Move specific NAT IPv4 functions to the core so x_tables and nf_tables can share the same NAT IPv4 engine.
10) Use the new NAT IPv4 functions from nft_chain_nat_ipv4.
11) Move specific NAT IPv6 functions to the core so x_tables and nf_tables can share the same NAT IPv4 engine.
12) Use the new NAT IPv6 functions from nft_chain_nat_ipv6.
13) Refactor code to add nft_delrule(), which can be reused in the enhancement of the NFT_MSG_DELTABLE to remove a table and its content, from Arturo Borrero.
14) Add a helper function to unregister chain hooks, from Arturo Borrero.
15) A cleanup to rename to nft_delrule_by_chain for consistency with the new nft_*() functions, also from Arturo.
16) Add support to match devgroup to the meta expression, from Ana Rey.
17) Reduce stack usage for IPVS socket option, from Julian Anastasov.
18) Remove unnecessary textsearch state initialization in xt_string, from Bojan Prtvar.
19) Add several helper functions to nf_tables, more work to prepare the enhancement of NFT_MSG_DELTABLE, again from Arturo Borrero.
20) Enhance NFT_MSG_DELTABLE to delete a table and its content, from Arturo Borrero.
21) Support NAT flags in the nat expression to indicate the flavour, eg. random fully, from Arturo.
22) Add missing audit code to ebtables when replacing tables, from Nicolas Dichtel.
23) Generalize the IPv4 masquerading code to allow its re-use from nf_tables, from Arturo.
24) Generalize the IPv6 masquerading code, also from Arturo.
25) Add the new masq expression to support IPv4/IPv6 masquerading from nf_tables, also from Arturo.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Thanks!
----------------------------------------------------------------
The following changes since commit c9d26423e56ce1ab4d786f92aebecf859d419293:
Merge tag 'pm+acpi-3.17-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm (2014-08-14 18:13:46 -0600)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git master
for you to fetch changes up to 9ba1f726bec090399eb9bb9157eb32dedc8e8c45:
netfilter: nf_tables: add new nft_masq expression (2014-09-09 16:31:30 +0200)
----------------------------------------------------------------
Alexey Perevalov (1):
netfilter: nfnetlink_acct: add filter support to nfacct counter list/reset
Ana Rey (3):
netfilter: nft_meta: add pkttype support
netfilter: nft_meta: Add cpu attribute support
netfilter: nf_tables: add devgroup support in meta expresion
Arturo Borrero (9):
netfilter: nf_tables: refactor rule deletion helper
netfilter: nf_tables: add helper to unregister chain hooks
netfilter: nf_tables: rename nf_table_delrule_by_chain()
netfilter: nf_tables: add helpers to schedule objects deletion
netfilter: nf_tables: extend NFT_MSG_DELTABLE to support flushing the ruleset
netfilter: nft_nat: include a flag attribute
netfilter: nf_nat: generalize IPv4 masquerading support for nf_tables
netfilter: nf_nat: generalize IPv6 masquerading support for nf_tables
netfilter: nf_tables: add new nft_masq expression
Bojan Prtvar (1):
netfilter: xt_string: Remove unnecessary initialization of struct ts_state
Jozsef Kadlecsik (1):
netfilter: ipset: Fix warn: integer overflows 'sizeof(*map) + size * set->dsize'
Julian Anastasov (1):
ipvs: reduce stack usage for sockopt data
Mark Rustad (1):
netfilter: ipset: Resolve missing-field-initializer warnings
Mike Frysinger (1):
uapi: netfilter_arp: use __u8 instead of u_int8_t
Nicolas Dichtel (1):
netfilter: ebtables: create audit records for replaces
Pablo Neira Ayuso (4):
netfilter: nat: move specific NAT IPv4 to core
netfilter: nft_chain_nat_ipv4: use generic IPv4 NAT code from core
netfilter: nat: move specific NAT IPv6 to core
netfilter: nft_chain_nat_ipv6: use generic IPv6 NAT code from core
Sergey Popovich (1):
netfilter: ipset: netnet,netportnet: Fix value range support for IPv4
Vytas Dauksa (1):
netfilter: ipset: Removed invalid IPSET_ATTR_MARKMASK validation
include/linux/netfilter/ipset/ip_set_list.h | 1 + include/net/netfilter/ipv4/nf_nat_masquerade.h | 14 + include/net/netfilter/ipv6/nf_nat_masquerade.h | 10 + include/net/netfilter/nf_nat_l3proto.h | 75 ++++ include/net/netfilter/nft_masq.h | 16 + include/uapi/linux/netfilter/nf_nat.h | 5 + include/uapi/linux/netfilter/nf_tables.h | 21 ++ include/uapi/linux/netfilter/nfnetlink_acct.h | 8 + include/uapi/linux/netfilter_arp/arpt_mangle.h | 2 +- net/bridge/netfilter/ebtables.c | 15 + net/ipv4/netfilter/Kconfig | 13 + net/ipv4/netfilter/Makefile | 2 + net/ipv4/netfilter/ipt_MASQUERADE.c | 108 +----- net/ipv4/netfilter/iptable_nat.c | 233 ++---------- net/ipv4/netfilter/nf_nat_l3proto_ipv4.c | 199 +++++++++++ net/ipv4/netfilter/nf_nat_masquerade_ipv4.c | 153 ++++++++ net/ipv4/netfilter/nft_chain_nat_ipv4.c | 157 ++------ net/ipv4/netfilter/nft_masq_ipv4.c | 89 +++++ net/ipv6/netfilter/Kconfig | 13 + net/ipv6/netfilter/Makefile | 2 + net/ipv6/netfilter/ip6t_MASQUERADE.c | 76 +--- net/ipv6/netfilter/ip6table_nat.c | 233 ++---------- net/ipv6/netfilter/nf_nat_l3proto_ipv6.c | 199 +++++++++++ net/ipv6/netfilter/nf_nat_masquerade_ipv6.c | 120 +++++++ net/ipv6/netfilter/nft_chain_nat_ipv6.c | 165 ++------- net/ipv6/netfilter/nft_masq_ipv6.c | 89 +++++ net/netfilter/Kconfig | 9 + net/netfilter/Makefile | 1 + net/netfilter/ipset/ip_set_bitmap_ip.c | 4 +- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 4 +- net/netfilter/ipset/ip_set_bitmap_port.c | 4 +- net/netfilter/ipset/ip_set_hash_gen.h | 2 +- net/netfilter/ipset/ip_set_hash_ip.c | 8 +- net/netfilter/ipset/ip_set_hash_ipport.c | 8 +- net/netfilter/ipset/ip_set_hash_ipportip.c | 8 +- net/netfilter/ipset/ip_set_hash_netnet.c | 13 +- net/netfilter/ipset/ip_set_hash_netportnet.c | 6 +- net/netfilter/ipset/ip_set_list_set.c | 4 +- net/netfilter/ipvs/ip_vs_ctl.c | 111 +++--- net/netfilter/nf_tables_api.c | 454 +++++++++++++++--------- net/netfilter/nfnetlink_acct.c | 54 +++ net/netfilter/nft_masq.c | 59 +++ net/netfilter/nft_meta.c | 45 +++ net/netfilter/nft_nat.c | 16 + net/netfilter/xt_string.c | 1 - 45 files changed, 1759 insertions(+), 1070 deletions(-) create mode 100644 include/net/netfilter/ipv4/nf_nat_masquerade.h create mode 100644 include/net/netfilter/ipv6/nf_nat_masquerade.h create mode 100644 include/net/netfilter/nft_masq.h create mode 100644 net/ipv4/netfilter/nf_nat_masquerade_ipv4.c create mode 100644 net/ipv4/netfilter/nft_masq_ipv4.c create mode 100644 net/ipv6/netfilter/nf_nat_masquerade_ipv6.c create mode 100644 net/ipv6/netfilter/nft_masq_ipv6.c create mode 100644 net/netfilter/nft_masq.c
Pablo Neira Ayuso
maintainerPATCH 1/25 uapi: netfilter_arp: use __u8 instead of u_int8_t
From: Mike Frysinger <[email protected]>
Similarly, the u_int8_t type is non-standard and not defined. Change it to use __u8 like the rest of the netfilter headers.
--- include/uapi/linux/netfilter_arp/arpt_mangle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/uapi/linux/netfilter_arp/arpt_mangle.h +1 -1
@@ -13,7 +13,7 @@ struct arpt_mangleunion {struct in_addr tgt_ip; } u_t; -u_int8_t flags; +__u8 flags;int target; };
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 2/25 netfilter: nft_meta: add pkttype support
In reply to Pablo Neira AyusoFrom: Ana Rey <[email protected]>
Add pkttype support for ip, ipv6 and inet families of tables.
This allows you to fetch the meta packet type based on the link layer information. The loopback traffic is a special case, the packet type is guessed from the network layer header.
No special handling for bridge and arp since we're not going to see such traffic in the loopback interface.
Joint work with Alvaro Neira Ayuso <[email protected]>
--- include/uapi/linux/netfilter/nf_tables.h | 2 ++ net/netfilter/nft_meta.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -571,6 +571,7 @@ enum nft_exthdr_attributes {* @NFT_META_L4PROTO: layer 4 protocol number * @NFT_META_BRI_IIFNAME: packet input bridge interface name * @NFT_META_BRI_OIFNAME: packet output bridge interface name +* @NFT_META_PKTTYPE: packet type (skb->pkt_type), special handling for loopback */ enum nft_meta_keys {NFT_META_LEN ,
@@ -592,6 +593,7 @@ enum nft_meta_keys {NFT_META_L4PROTO ,NFT_META_BRI_IIFNAME ,NFT_META_BRI_OIFNAME , + NFT_META_PKTTYPE, };/**
net/netfilter/nft_meta.c +28 -0
@@ -14,6 +14,9 @@#include <linux/netlink.h> #include <linux/netfilter.h> #include <linux/netfilter/nf_tables.h> +#include <linux/in.h> +#include <linux/ip.h> +#include <linux/ipv6.h> #include <net/dst.h> #include <net/sock.h> #include <net/tcp_states.h> /* for TCP_TIME_WAIT */
@@ -124,6 +127,30 @@ void nft_meta_get_eval(const struct nft_expr *expr, dest->data[0 ] = skb->secmark;break ;#endif +case NFT_META_PKTTYPE : +if (skb->pkt_type !=PACKET_LOOPBACK ) { + dest->data[0 ] = skb->pkt_type; +break ; + } + +switch (pkt->ops->pf) { +case NFPROTO_IPV4 : +if (ipv4_is_multicast (ip_hdr (skb)->daddr)) + dest->data[0 ] =PACKET_MULTICAST ; +else + dest->data[0 ] =PACKET_BROADCAST ; +break ; +case NFPROTO_IPV6 : +if (ipv6_hdr (skb)->daddr.s6_addr[0 ] ==0xFF ) + dest->data[0 ] =PACKET_MULTICAST ; +else + dest->data[0 ] =PACKET_BROADCAST ; +break ; +default : +WARN_ON (1 ); + goto err; + } +break ;default :WARN_ON (1 ); goto err;
@@ -195,6 +222,7 @@ int nft_meta_get_init(const struct nft_ctx *ctx,#ifdef CONFIG_NETWORK_SECMARK case NFT_META_SECMARK :#endif +case NFT_META_PKTTYPE :break ;default :return -EOPNOTSUPP ;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 3/25 netfilter: nft_meta: Add cpu attribute support
In reply to Pablo Neira AyusoFrom: Ana Rey <[email protected]>
Add cpu support to meta expresion.
This allows you to match packets with cpu number.
--- include/uapi/linux/netfilter/nf_tables.h | 2 ++ net/netfilter/nft_meta.c | 5 +++++ 2 files changed, 7 insertions(+)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -572,6 +572,7 @@ enum nft_exthdr_attributes {* @NFT_META_BRI_IIFNAME: packet input bridge interface name * @NFT_META_BRI_OIFNAME: packet output bridge interface name * @NFT_META_PKTTYPE: packet type (skb->pkt_type), special handling for loopback +* @NFT_META_CPU: cpu id through smp_processor_id() */ enum nft_meta_keys {NFT_META_LEN ,
@@ -594,6 +595,7 @@ enum nft_meta_keys {NFT_META_BRI_IIFNAME ,NFT_META_BRI_OIFNAME ,NFT_META_PKTTYPE , + NFT_META_CPU, };/**
net/netfilter/nft_meta.c +5 -0
@@ -17,6 +17,7 @@#include <linux/in.h> #include <linux/ip.h> #include <linux/ipv6.h> +#include <linux/smp.h> #include <net/dst.h> #include <net/sock.h> #include <net/tcp_states.h> /* for TCP_TIME_WAIT */
@@ -151,6 +152,9 @@ void nft_meta_get_eval(const struct nft_expr *expr, goto err; }break ; +case NFT_META_CPU : + dest->data[0 ] =smp_processor_id (); +break ;default :WARN_ON (1 ); goto err;
@@ -223,6 +227,7 @@ int nft_meta_get_init(const struct nft_ctx *ctx,case NFT_META_SECMARK :#endif case NFT_META_PKTTYPE : +case NFT_META_CPU :break ;default :return -EOPNOTSUPP ;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 4/25 netfilter: ipset: Removed invalid IPSET_ATTR_MARKMASK validation
In reply to Pablo Neira AyusoFrom: Vytas Dauksa <[email protected]>
Markmask is an u32, hence it can't be greater then 4294967295 ( i.e. 0xffffffff ). This was causing smatch warning:
net/netfilter/ipset/ip_set_hash_gen.h:1084 hash_ipmark_create() warn:
impossible condition '(markmask > 4294967295) => (0-u32max > u32max)'
--- net/netfilter/ipset/ip_set_hash_gen.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipset/ip_set_hash_gen.h +1 -1
@@ -1093,7 +1093,7 @@ IPSET_TOKEN(HTYPE, _create)(struct net *net, struct ip_set *set,if (tb[IPSET_ATTR_MARKMASK ]) { markmask =ntohl (nla_get_u32 (tb[IPSET_ATTR_MARKMASK ])); -if ((markmask >4294967295u ) || markmask ==0 ) +if (markmask ==0 )return -IPSET_ERR_INVALID_MARKMASK ; }#endif
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 5/25 netfilter: ipset: netnet,netportnet: Fix value range support for IPv4
In reply to Pablo Neira AyusoFrom: Sergey Popovich <[email protected]>
Ranges of values are broken with hash:net,net and hash:net,port,net.
hash:net,net
============
# ipset create test-nn hash:net,net # ipset add test-nn 10.0.10.1-10.0.10.127,10.0.0.0/8
# ipset list test-nn Name: test-nn Type: hash:net,net Revision: 0 Header: family inet hashsize 1024 maxelem 65536 Size in memory: 16960 References: 0 Members: 10.0.10.1,10.0.0.0/8
# ipset test test-nn 10.0.10.65,10.0.0.1 10.0.10.65,10.0.0.1 is NOT in set test-nn. # ipset test test-nn 10.0.10.1,10.0.0.1 10.0.10.1,10.0.0.1 is in set test-nn.
hash:net,port,net
=================
# ipset create test-npn hash:net,port,net # ipset add test-npn 10.0.10.1-10.0.10.127,tcp:80,10.0.0.0/8 # ipset list test-npn Name: test-npn Type: hash:net,port,net Revision: 0 Header: family inet hashsize 1024 maxelem 65536 Size in memory: 17344 References: 0 Members: 10.0.10.8/29,tcp:80,10.0.0.0 10.0.10.16/28,tcp:80,10.0.0.0 10.0.10.2/31,tcp:80,10.0.0.0 10.0.10.64/26,tcp:80,10.0.0.0 10.0.10.32/27,tcp:80,10.0.0.0 10.0.10.4/30,tcp:80,10.0.0.0 10.0.10.1,tcp:80,10.0.0.0 # ipset list test-npn # ipset test test-npn 10.0.10.126,tcp:80,10.0.0.2 10.0.10.126,tcp:80,10.0.0.2 is NOT in set test-npn. # ipset test test-npn 10.0.10.126,tcp:80,10.0.0.0 10.0.10.126,tcp:80,10.0.0.0 is in set test-npn.
# ipset create test-npn hash:net,port,net # ipset add test-npn 10.0.10.0/24,tcp:80-81,10.0.0.0/8 # ipset list test-npn Name: test-npn Type: hash:net,port,net Revision: 0 Header: family inet hashsize 1024 maxelem 65536 Size in memory: 17024 References: 0 Members: 10.0.10.0,tcp:80,10.0.0.0 10.0.10.0,tcp:81,10.0.0.0 # ipset test test-npn 10.0.10.126,tcp:80,10.0.0.0 10.0.10.126,tcp:80,10.0.0.0 is NOT in set test-npn. # ipset test test-npn 10.0.10.0,tcp:80,10.0.0.0 10.0.10.0,tcp:80,10.0.0.0 is in set test-npn.
Correctly setup from..to variables where no IPSET_ATTR_IP_TO{,2} attribute is given, so in range processing loop we construct proper cidr value. Check whenever we have no ranges and can short cut in hash:net,net properly. Use unlikely() where appropriate, to comply with other modules.
--- net/netfilter/ipset/ip_set_hash_netnet.c | 13 +++++++------ net/netfilter/ipset/ip_set_hash_netportnet.c | 6 ++++-- 2 files changed, 11 insertions(+), 8 deletions(-)
net/netfilter/ipset/ip_set_hash_netnet.c +7 -6
@@ -203,7 +203,7 @@ hash_netnet4_uadt(struct ip_set *set, struct nlattr *tb[], flags |= (IPSET_FLAG_NOMATCH <<16 ); } -if (adt ==IPSET_TEST || !(tb[IPSET_ATTR_IP_TO ] && +if (adt ==IPSET_TEST || !(tb[IPSET_ATTR_IP_TO ] || tb[IPSET_ATTR_IP2_TO ])) { e.ip[0 ] =htonl (ip &ip_set_hostmask (e.cidr[0 ])); e.ip[1 ] =htonl (ip2_from &ip_set_hostmask (e.cidr[1 ]));
@@ -219,9 +219,10 @@ hash_netnet4_uadt(struct ip_set *set, struct nlattr *tb[],return ret;if (ip_to < ip)swap (ip, ip_to); -if (ip +UINT_MAX == ip_to) +if (unlikely (ip +UINT_MAX == ip_to))return -IPSET_ERR_HASH_RANGE ; - } + }else +ip_set_mask_from_to (ip, ip_to, e.cidr[0 ]); ip2_to = ip2_from;if (tb[IPSET_ATTR_IP2_TO ]) {
@@ -230,10 +231,10 @@ hash_netnet4_uadt(struct ip_set *set, struct nlattr *tb[],return ret;if (ip2_to < ip2_from)swap (ip2_from, ip2_to); -if (ip2_from +UINT_MAX == ip2_to) +if (unlikely (ip2_from +UINT_MAX == ip2_to))return -IPSET_ERR_HASH_RANGE ; - - } + }else +ip_set_mask_from_to (ip2_from, ip2_to, e.cidr[1 ]);if (retried) ip =ntohl (h->next.ip[0 ]);
net/netfilter/ipset/ip_set_hash_netportnet.c +4 -2
@@ -257,7 +257,8 @@ hash_netportnet4_uadt(struct ip_set *set, struct nlattr *tb[],swap (ip, ip_to);if (unlikely (ip +UINT_MAX == ip_to))return -IPSET_ERR_HASH_RANGE ; - } + }else +ip_set_mask_from_to (ip, ip_to, e.cidr[0 ]); port_to = port =ntohs (e.port);if (tb[IPSET_ATTR_PORT_TO ]) {
@@ -275,7 +276,8 @@ hash_netportnet4_uadt(struct ip_set *set, struct nlattr *tb[],swap (ip2_from, ip2_to);if (unlikely (ip2_from +UINT_MAX == ip2_to))return -IPSET_ERR_HASH_RANGE ; - } + }else +ip_set_mask_from_to (ip2_from, ip2_to, e.cidr[1 ]);if (retried) ip =ntohl (h->next.ip[0 ]);
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 6/25 netfilter: ipset: Resolve missing-field-initializer warnings
In reply to Pablo Neira AyusoFrom: Mark Rustad <[email protected]>
Resolve missing-field-initializer warnings by providing a directed initializer.
--- net/netfilter/ipset/ip_set_bitmap_ip.c | 4 ++-- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 4 ++-- net/netfilter/ipset/ip_set_bitmap_port.c | 4 ++-- net/netfilter/ipset/ip_set_hash_ip.c | 8 ++++---- net/netfilter/ipset/ip_set_hash_ipport.c | 8 ++++---- net/netfilter/ipset/ip_set_hash_ipportip.c | 8 ++++---- 6 files changed, 18 insertions(+), 18 deletions(-)
net/netfilter/ipset/ip_set_bitmap_ip.c +2 -2
@@ -112,7 +112,7 @@ bitmap_ip_kadt(struct ip_set *set, const struct sk_buff *skb, {struct bitmap_ip *map = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; -struct bitmap_ip_adt_elem e = { }; +struct bitmap_ip_adt_elem e = { .id =0 };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);u32 ip;
@@ -132,7 +132,7 @@ bitmap_ip_uadt(struct ip_set *set, struct nlattr *tb[],struct bitmap_ip *map = set->data;ipset_adtfn adtfn = set->variant->adt[adt];u32 ip =0 , ip_to =0 ; -struct bitmap_ip_adt_elem e = { }; +struct bitmap_ip_adt_elem e = { .id =0 };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);int ret =0 ;
net/netfilter/ipset/ip_set_bitmap_ipmac.c +2 -2
@@ -203,7 +203,7 @@ bitmap_ipmac_kadt(struct ip_set *set, const struct sk_buff *skb, {struct bitmap_ipmac *map = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; -struct bitmap_ipmac_adt_elem e = {}; +struct bitmap_ipmac_adt_elem e = { .id =0 };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);u32 ip;
@@ -232,7 +232,7 @@ bitmap_ipmac_uadt(struct ip_set *set, struct nlattr *tb[], {const struct bitmap_ipmac *map = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; -struct bitmap_ipmac_adt_elem e = {}; +struct bitmap_ipmac_adt_elem e = { .id =0 };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);u32 ip =0 ;int ret =0 ;
net/netfilter/ipset/ip_set_bitmap_port.c +2 -2
@@ -104,7 +104,7 @@ bitmap_port_kadt(struct ip_set *set, const struct sk_buff *skb, {struct bitmap_port *map = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; -struct bitmap_port_adt_elem e = {}; +struct bitmap_port_adt_elem e = { .id =0 };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);__be16 __port;u16 port =0 ;
@@ -129,7 +129,7 @@ bitmap_port_uadt(struct ip_set *set, struct nlattr *tb[], {struct bitmap_port *map = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; -struct bitmap_port_adt_elem e = {}; +struct bitmap_port_adt_elem e = { .id =0 };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);u32 port;/* wraparound */ u16 port_to;
net/netfilter/ipset/ip_set_hash_ip.c +4 -4
@@ -84,7 +84,7 @@ hash_ip4_kadt(struct ip_set *set, const struct sk_buff *skb, {const struct hash_ip *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; -struct hash_ip4_elem e = {}; +struct hash_ip4_elem e = {0 };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);__be32 ip;
@@ -103,7 +103,7 @@ hash_ip4_uadt(struct ip_set *set, struct nlattr *tb[], {const struct hash_ip *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; -struct hash_ip4_elem e = {}; +struct hash_ip4_elem e = {0 };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);u32 ip =0 , ip_to =0 , hosts;int ret =0 ;
@@ -222,7 +222,7 @@ hash_ip6_kadt(struct ip_set *set, const struct sk_buff *skb, {const struct hash_ip *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; -struct hash_ip6_elem e = {}; +struct hash_ip6_elem e = { { .all = {0 } } };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);ip6addrptr (skb, opt->flags &IPSET_DIM_ONE_SRC , &e.ip.in6);
@@ -239,7 +239,7 @@ hash_ip6_uadt(struct ip_set *set, struct nlattr *tb[], {const struct hash_ip *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; -struct hash_ip6_elem e = {}; +struct hash_ip6_elem e = { { .all = {0 } } };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);int ret;
net/netfilter/ipset/ip_set_hash_ipport.c +4 -4
@@ -94,7 +94,7 @@ hash_ipport4_kadt(struct ip_set *set, const struct sk_buff *skb, enum ipset_adt adt, struct ip_set_adt_opt *opt) { ipset_adtfn adtfn = set->variant->adt[adt]; -struct hash_ipport4_elem e = { }; +struct hash_ipport4_elem e = { .ip =0 };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set); if (!ip_set_get_ip4_port(skb, opt->flags & IPSET_DIM_TWO_SRC,
@@ -111,7 +111,7 @@ hash_ipport4_uadt(struct ip_set *set, struct nlattr *tb[], {const struct hash_ipport *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; -struct hash_ipport4_elem e = { }; +struct hash_ipport4_elem e = { .ip =0 };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);u32 ip, ip_to =0 , p =0 , port, port_to;bool with_ports = false;
@@ -258,7 +258,7 @@ hash_ipport6_kadt(struct ip_set *set, const struct sk_buff *skb, enum ipset_adt adt, struct ip_set_adt_opt *opt) { ipset_adtfn adtfn = set->variant->adt[adt]; -struct hash_ipport6_elem e = { }; +struct hash_ipport6_elem e = { .ip = { .all = {0 } } };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set); if (!ip_set_get_ip6_port(skb, opt->flags & IPSET_DIM_TWO_SRC,
@@ -275,7 +275,7 @@ hash_ipport6_uadt(struct ip_set *set, struct nlattr *tb[], {const struct hash_ipport *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; -struct hash_ipport6_elem e = { }; +struct hash_ipport6_elem e = { .ip = { .all = {0 } } };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);u32 port, port_to;bool with_ports = false;
net/netfilter/ipset/ip_set_hash_ipportip.c +4 -4
@@ -95,7 +95,7 @@ hash_ipportip4_kadt(struct ip_set *set, const struct sk_buff *skb, enum ipset_adt adt, struct ip_set_adt_opt *opt) { ipset_adtfn adtfn = set->variant->adt[adt]; -struct hash_ipportip4_elem e = { }; +struct hash_ipportip4_elem e = { .ip =0 };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set); if (!ip_set_get_ip4_port(skb, opt->flags & IPSET_DIM_TWO_SRC,
@@ -113,7 +113,7 @@ hash_ipportip4_uadt(struct ip_set *set, struct nlattr *tb[], {const struct hash_ipportip *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; -struct hash_ipportip4_elem e = { }; +struct hash_ipportip4_elem e = { .ip =0 };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);u32 ip, ip_to =0 , p =0 , port, port_to;bool with_ports = false;
@@ -265,7 +265,7 @@ hash_ipportip6_kadt(struct ip_set *set, const struct sk_buff *skb, enum ipset_adt adt, struct ip_set_adt_opt *opt) { ipset_adtfn adtfn = set->variant->adt[adt]; -struct hash_ipportip6_elem e = { }; +struct hash_ipportip6_elem e = { .ip = { .all = {0 } } };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set); if (!ip_set_get_ip6_port(skb, opt->flags & IPSET_DIM_TWO_SRC,
@@ -283,7 +283,7 @@ hash_ipportip6_uadt(struct ip_set *set, struct nlattr *tb[], {const struct hash_ipportip *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; -struct hash_ipportip6_elem e = { }; +struct hash_ipportip6_elem e = { .ip = { .all = {0 } } };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);u32 port, port_to;bool with_ports = false;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 7/25 netfilter: ipset: Fix warn: integer overflows 'sizeof(*map) + size * set->dsize'
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
Dan Carpenter reported that the static checker emits the warning
net/netfilter/ipset/ip_set_list_set.c:600 init_list_set()
warn: integer overflows 'sizeof(*map) + size * set->dsize'Limit the maximal number of elements in list type of sets.
--- include/linux/netfilter/ipset/ip_set_list.h | 1 + net/netfilter/ipset/ip_set_list_set.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)
include/linux/netfilter/ipset/ip_set_list.h +1 -0
@@ -6,5 +6,6 @@#define IP_SET_LIST_DEFAULT_SIZE 8#define IP_SET_LIST_MIN_SIZE 4 +#define IP_SET_LIST_MAX_SIZE 65536#endif /* __IP_SET_LIST_H */
net/netfilter/ipset/ip_set_list_set.c +3 -1
@@ -597,7 +597,9 @@ init_list_set(struct net *net, struct ip_set *set, u32 size)struct set_elem *e;u32 i; - map =kzalloc (sizeof (*map) + size * set->dsize,GFP_KERNEL ); + map =kzalloc (sizeof (*map) + +min_t (u32, size,IP_SET_LIST_MAX_SIZE ) * set->dsize, +GFP_KERNEL );if (!map)return false;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 8/25 netfilter: nfnetlink_acct: add filter support to nfacct counter list/reset
In reply to Pablo Neira AyusoFrom: Alexey Perevalov <[email protected]>
You can use this to skip accounting objects when listing/resetting via NFNL_MSG_ACCT_GET/NFNL_MSG_ACCT_GET_CTRZERO messages with the NLM_F_DUMP netlink flag. The filtering covers the following cases:
1. No filter specified. In this case, the client will get old behaviour,
2. List/reset counter object only: In this case, you have to use NFACCT_F_QUOTA as mask and value 0.
3. List/reset quota objects only: You have to use NFACCT_F_QUOTA_PKTS as mask and value - the same, for byte based quota mask should be NFACCT_F_QUOTA_BYTES and value - the same.
If you want to obtain the object with any quota type (ie. NFACCT_F_QUOTA_PKTS|NFACCT_F_QUOTA_BYTES), you need to perform two dump requests, one to obtain NFACCT_F_QUOTA_PKTS objects and another for NFACCT_F_QUOTA_BYTES.
--- include/uapi/linux/netfilter/nfnetlink_acct.h | 8 ++++ net/netfilter/nfnetlink_acct.c | 54 +++++++++++++++++++++++++ 2 files changed, 62 insertions(+)
include/uapi/linux/netfilter/nfnetlink_acct.h +8 -0
@@ -28,9 +28,17 @@ enum nfnl_acct_type {NFACCT_USE ,NFACCT_FLAGS ,NFACCT_QUOTA , +NFACCT_FILTER , __NFACCT_MAX };#define NFACCT_MAX (__NFACCT_MAX - 1) +enum nfnl_attr_filter_type { +NFACCT_FILTER_UNSPEC , +NFACCT_FILTER_MASK , +NFACCT_FILTER_VALUE , + __NFACCT_FILTER_MAX +}; +#define NFACCT_FILTER_MAX (__NFACCT_FILTER_MAX - 1)#endif /* _UAPI_NFNL_ACCT_H_ */
net/netfilter/nfnetlink_acct.c +54 -0
91 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 9/25 netfilter: nat: move specific NAT IPv4 to core
In reply to Pablo Neira AyusoMove the specific NAT IPv4 core functions that are called from the hooks from iptable_nat.c to nf_nat_l3proto_ipv4.c. This prepares the ground to allow iptables and nft to use the same NAT engine code that comes in a follow up patch.
--- include/net/netfilter/nf_nat_l3proto.h | 38 +++++ net/ipv4/netfilter/iptable_nat.c | 233 +++++------------------------- net/ipv4/netfilter/nf_nat_l3proto_ipv4.c | 199 +++++++++++++++++++++++++ 3 files changed, 271 insertions(+), 199 deletions(-)
include/net/netfilter/nf_nat_l3proto.h +38 -0
@@ -42,6 +42,44 @@ const struct nf_nat_l3proto *__nf_nat_l3proto_find(u8 l3proto);int nf_nat_icmp_reply_translation (struct sk_buff *skb,struct nf_conn *ct,enum ip_conntrack_info ctinfo,unsigned int hooknum); + +unsigned int nf_nat_ipv4_in (const struct nf_hook_ops *ops,struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +unsigned int (*do_chain)(const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +struct nf_conn *ct)); + +unsigned int nf_nat_ipv4_out (const struct nf_hook_ops *ops,struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +unsigned int (*do_chain)(const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +struct nf_conn *ct)); + +unsigned int nf_nat_ipv4_local_fn (const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +unsigned int (*do_chain)(const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +struct nf_conn *ct)); + +unsigned int nf_nat_ipv4_fn (const struct nf_hook_ops *ops,struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +unsigned int (*do_chain)(const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +struct nf_conn *ct)); +int nf_nat_icmpv6_reply_translation (struct sk_buff *skb,struct nf_conn *ct,enum ip_conntrack_info ctinfo,unsigned int hooknum,unsigned int hdrlen);
net/ipv4/netfilter/iptable_nat.c +34 -199
277 lines not on this page · raw message
net/ipv4/netfilter/nf_nat_l3proto_ipv4.c +199 -0
205 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 10/25 netfilter: nft_chain_nat_ipv4: use generic IPv4 NAT code from core
In reply to Pablo Neira AyusoUse the exported IPv4 NAT functions that are provided by the core. This removes duplicated code so iptables and nft use the same NAT codebase.
--- net/ipv4/netfilter/nft_chain_nat_ipv4.c | 157 ++++++++----------------------- 1 file changed, 37 insertions(+), 120 deletions(-)
net/ipv4/netfilter/nft_chain_nat_ipv4.c +37 -120
@@ -26,136 +26,53 @@#include <net/netfilter/nf_nat_l3proto.h> #include <net/ip.h> -/* -* NAT chains -*/ - -static unsigned int nf_nat_fn (const struct nf_hook_ops *ops, -struct sk_buff *skb, -const struct net_device *in, -const struct net_device *out, -int (*okfn)(struct sk_buff *)) +static unsigned int nft_nat_do_chain (const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +struct nf_conn *ct) { -enum ip_conntrack_info ctinfo; -struct nf_conn *ct =nf_ct_get (skb, &ctinfo); -struct nf_conn_nat *nat; -enum nf_nat_manip_type maniptype =HOOK2MANIP (ops->hooknum);struct nft_pktinfo pkt; -unsigned int ret; - -if (ct ==NULL ||nf_ct_is_untracked (ct)) -return NF_ACCEPT ; - -NF_CT_ASSERT (!(ip_hdr (skb)->frag_off &htons (IP_MF |IP_OFFSET ))); - - nat =nf_ct_nat_ext_add (ct); -if (nat ==NULL ) -return NF_ACCEPT ; - -switch (ctinfo) { -case IP_CT_RELATED : -case IP_CT_RELATED +IP_CT_IS_REPLY : -if (ip_hdr (skb)->protocol ==IPPROTO_ICMP ) { -if (!nf_nat_icmp_reply_translation (skb, ct, ctinfo, - ops->hooknum)) -return NF_DROP ; -else -return NF_ACCEPT ; - } -/* Fall through */ -case IP_CT_NEW : -if (nf_nat_initialized (ct, maniptype)) -break ; -nft_set_pktinfo_ipv4 (&pkt, ops, skb, in, out); +nft_set_pktinfo_ipv4 (&pkt, ops, skb, in, out); - ret =nft_do_chain (&pkt, ops); -if (ret !=NF_ACCEPT ) -return ret; -if (!nf_nat_initialized (ct, maniptype)) { - ret =nf_nat_alloc_null_binding (ct, ops->hooknum); -if (ret !=NF_ACCEPT ) -return ret; - } -default : -break ; - } - -return nf_nat_packet (ct, ctinfo, ops->hooknum, skb); +return nft_do_chain (&pkt, ops); } -static unsigned int nf_nat_prerouting (const struct nf_hook_ops *ops, -struct sk_buff *skb, -const struct net_device *in, -const struct net_device *out, -int (*okfn)(struct sk_buff *)) +static unsigned int nft_nat_ipv4_fn (const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +int (*okfn)(struct sk_buff *)) { -__be32 daddr =ip_hdr (skb)->daddr; -unsigned int ret; - - ret =nf_nat_fn (ops, skb, in, out, okfn); -if (ret !=NF_DROP && ret !=NF_STOLEN && -ip_hdr (skb)->daddr != daddr) { -skb_dst_drop (skb); - } -return ret; +return nf_nat_ipv4_fn (ops, skb, in, out, nft_nat_do_chain); } -static unsigned int nf_nat_postrouting (const struct nf_hook_ops *ops, -struct sk_buff *skb, -const struct net_device *in, -const struct net_device *out, -int (*okfn)(struct sk_buff *)) +static unsigned int nft_nat_ipv4_in (const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +int (*okfn)(struct sk_buff *)) { -enum ip_conntrack_info ctinfo__maybe_unused ; -const struct nf_conn *ct__maybe_unused ; -unsigned int ret; - - ret =nf_nat_fn (ops, skb, in, out, okfn); -#ifdef CONFIG_XFRM -if (ret !=NF_DROP && ret !=NF_STOLEN && - (ct =nf_ct_get (skb, &ctinfo)) !=NULL ) { -enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo); - -if (ct->tuplehash[dir].tuple.src.u3.ip != - ct->tuplehash[!dir].tuple.dst.u3.ip || - ct->tuplehash[dir].tuple.src.u.all != - ct->tuplehash[!dir].tuple.dst.u.all) -return nf_xfrm_me_harder (skb,AF_INET ) ==0 ? - ret :NF_DROP ; - } -#endif -return ret; +return nf_nat_ipv4_in (ops, skb, in, out, nft_nat_do_chain); } -static unsigned int nf_nat_output (const struct nf_hook_ops *ops, -struct sk_buff *skb, -const struct net_device *in, -const struct net_device *out, -int (*okfn)(struct sk_buff *)) +static unsigned int nft_nat_ipv4_out (const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +int (*okfn)(struct sk_buff *)) { -enum ip_conntrack_info ctinfo; -const struct nf_conn *ct; -unsigned int ret; - - ret =nf_nat_fn (ops, skb, in, out, okfn); -if (ret !=NF_DROP && ret !=NF_STOLEN && - (ct =nf_ct_get (skb, &ctinfo)) !=NULL ) { -enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo); +return nf_nat_ipv4_out (ops, skb, in, out, nft_nat_do_chain); +} -if (ct->tuplehash[dir].tuple.dst.u3.ip != - ct->tuplehash[!dir].tuple.src.u3.ip) { -if (ip_route_me_harder (skb,RTN_UNSPEC )) - ret =NF_DROP ; - } -#ifdef CONFIG_XFRM - else if (ct->tuplehash[dir].tuple.dst.u.all != - ct->tuplehash[!dir].tuple.src.u.all) - if (nf_xfrm_me_harder(skb, AF_INET)) - ret =NF_DROP ; -#endif - } -return ret; +static unsigned int nft_nat_ipv4_local_fn (const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +int (*okfn)(struct sk_buff *)) +{ +return nf_nat_ipv4_local_fn (ops, skb, in, out, nft_nat_do_chain); }static const struct nf_chain_type nft_chain_nat_ipv4 = {
@@ -168,10 +85,10 @@ static const struct nf_chain_type nft_chain_nat_ipv4 = { (1 <<NF_INET_LOCAL_OUT ) | (1 << NF_INET_LOCAL_IN), .hooks = { - [NF_INET_PRE_ROUTING] = nf_nat_prerouting, - [NF_INET_POST_ROUTING] = nf_nat_postrouting, - [NF_INET_LOCAL_OUT] = nf_nat_output, - [NF_INET_LOCAL_IN] = nf_nat_fn, + [NF_INET_PRE_ROUTING] = nft_nat_ipv4_in, + [NF_INET_POST_ROUTING] = nft_nat_ipv4_out, + [NF_INET_LOCAL_OUT] = nft_nat_ipv4_local_fn, + [NF_INET_LOCAL_IN] = nft_nat_ipv4_fn, }, };
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 11/25 netfilter: nat: move specific NAT IPv6 to core
In reply to Pablo Neira AyusoMove the specific NAT IPv6 core functions that are called from the hooks from ip6table_nat.c to nf_nat_l3proto_ipv6.c. This prepares the ground to allow iptables and nft to use the same NAT engine code that comes in a follow up patch.
This also renames nf_nat_ipv6_fn to nft_nat_ipv6_fn in net/ipv6/netfilter/nft_chain_nat_ipv6.c to avoid a compilation breakage.
--- include/net/netfilter/nf_nat_l3proto.h | 37 +++++ net/ipv6/netfilter/ip6table_nat.c | 233 +++++------------------------- net/ipv6/netfilter/nf_nat_l3proto_ipv6.c | 199 +++++++++++++++++++++++++ net/ipv6/netfilter/nft_chain_nat_ipv6.c | 10 +- 4 files changed, 275 insertions(+), 204 deletions(-)
include/net/netfilter/nf_nat_l3proto.h +37 -0
@@ -84,4 +84,41 @@ int nf_nat_icmpv6_reply_translation(struct sk_buff *skb, struct nf_conn *ct,enum ip_conntrack_info ctinfo, unsigned int hooknum, unsigned int hdrlen); +unsigned int nf_nat_ipv6_in (const struct nf_hook_ops *ops,struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +unsigned int (*do_chain)(const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +struct nf_conn *ct)); + +unsigned int nf_nat_ipv6_out (const struct nf_hook_ops *ops,struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +unsigned int (*do_chain)(const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +struct nf_conn *ct)); + +unsigned int nf_nat_ipv6_local_fn (const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +unsigned int (*do_chain)(const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +struct nf_conn *ct)); + +unsigned int nf_nat_ipv6_fn (const struct nf_hook_ops *ops,struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +unsigned int (*do_chain)(const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +struct nf_conn *ct)); +#endif /* _NF_NAT_L3PROTO_H */
net/ipv6/netfilter/ip6table_nat.c +34 -199
277 lines not on this page · raw message
net/ipv6/netfilter/nf_nat_l3proto_ipv6.c +199 -0
205 lines not on this page · raw message
net/ipv6/netfilter/nft_chain_nat_ipv6.c +5 -5
@@ -28,7 +28,7 @@* IPv6 NAT chains */ -static unsigned int nf_nat_ipv6_fn(const struct nf_hook_ops *ops, +static unsigned int nft_nat_ipv6_fn(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
@@ -97,7 +97,7 @@ static unsigned int nf_nat_ipv6_prerouting(const struct nf_hook_ops *ops,struct in6_addr daddr =ipv6_hdr (skb)->daddr;unsigned int ret; - ret =nf_nat_ipv6_fn (ops, skb, in, out, okfn); + ret =nft_nat_ipv6_fn (ops, skb, in, out, okfn);if (ret !=NF_DROP && ret !=NF_STOLEN &&ipv6_addr_cmp (&daddr, &ipv6_hdr (skb)->daddr))skb_dst_drop (skb);
@@ -115,7 +115,7 @@ static unsigned int nf_nat_ipv6_postrouting(const struct nf_hook_ops *ops,const struct nf_conn *ct__maybe_unused ;unsigned int ret; - ret =nf_nat_ipv6_fn (ops, skb, in, out, okfn); + ret =nft_nat_ipv6_fn (ops, skb, in, out, okfn);#ifdef CONFIG_XFRM if (ret != NF_DROP && ret != NF_STOLEN && !(IP6CB(skb)->flags & IP6SKB_XFRM_TRANSFORMED) &&
@@ -143,7 +143,7 @@ static unsigned int nf_nat_ipv6_output(const struct nf_hook_ops *ops,const struct nf_conn *ct;unsigned int ret; - ret =nf_nat_ipv6_fn (ops, skb, in, out, okfn); + ret =nft_nat_ipv6_fn (ops, skb, in, out, okfn);if (ret !=NF_DROP && ret !=NF_STOLEN && (ct =nf_ct_get (skb, &ctinfo)) !=NULL ) {enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo);
@@ -177,7 +177,7 @@ static const struct nf_chain_type nft_chain_nat_ipv6 = { [NF_INET_PRE_ROUTING] = nf_nat_ipv6_prerouting, [NF_INET_POST_ROUTING] = nf_nat_ipv6_postrouting, [NF_INET_LOCAL_OUT] = nf_nat_ipv6_output, - [NF_INET_LOCAL_IN] = nf_nat_ipv6_fn, + [NF_INET_LOCAL_IN] = nft_nat_ipv6_fn, }, };
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 12/25 netfilter: nft_chain_nat_ipv6: use generic IPv6 NAT code from core
In reply to Pablo Neira AyusoUse the exported IPv6 NAT functions that are provided by the core. This removes duplicated code so iptables and nft use the same NAT codebase.
--- net/ipv6/netfilter/nft_chain_nat_ipv6.c | 163 +++++++------------------------ 1 file changed, 36 insertions(+), 127 deletions(-)
net/ipv6/netfilter/nft_chain_nat_ipv6.c +36 -127
@@ -24,144 +24,53 @@#include <net/netfilter/nf_nat_l3proto.h> #include <net/ipv6.h> -/* -* IPv6 NAT chains -*/ - -static unsigned int nft_nat_ipv6_fn (const struct nf_hook_ops *ops, -struct sk_buff *skb, -const struct net_device *in, -const struct net_device *out, -int (*okfn)(struct sk_buff *)) +static unsigned int nft_nat_do_chain (const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +struct nf_conn *ct) { -enum ip_conntrack_info ctinfo; -struct nf_conn *ct =nf_ct_get (skb, &ctinfo); -struct nf_conn_nat *nat; -enum nf_nat_manip_type maniptype =HOOK2MANIP (ops->hooknum); -__be16 frag_off; -int hdrlen; -u8 nexthdr;struct nft_pktinfo pkt; -unsigned int ret; - -if (ct ==NULL ||nf_ct_is_untracked (ct)) -return NF_ACCEPT ; - - nat =nf_ct_nat_ext_add (ct); -if (nat ==NULL ) -return NF_ACCEPT ; - -switch (ctinfo) { -case IP_CT_RELATED : -case IP_CT_RELATED +IP_CT_IS_REPLY : - nexthdr =ipv6_hdr (skb)->nexthdr; - hdrlen =ipv6_skip_exthdr (skb,sizeof (struct ipv6hdr ), - &nexthdr, &frag_off); - -if (hdrlen >=0 && nexthdr ==IPPROTO_ICMPV6 ) { -if (!nf_nat_icmpv6_reply_translation (skb, ct, ctinfo, - ops->hooknum, - hdrlen)) -return NF_DROP ; -else -return NF_ACCEPT ; - } -/* Fall through */ -case IP_CT_NEW : -if (nf_nat_initialized (ct, maniptype)) -break ; - -nft_set_pktinfo_ipv6 (&pkt, ops, skb, in, out); - ret =nft_do_chain (&pkt, ops); -if (ret !=NF_ACCEPT ) -return ret; -if (!nf_nat_initialized (ct, maniptype)) { - ret =nf_nat_alloc_null_binding (ct, ops->hooknum); -if (ret !=NF_ACCEPT ) -return ret; - } -default : -break ; - } +nft_set_pktinfo_ipv6 (&pkt, ops, skb, in, out); -return nf_nat_packet (ct, ctinfo, ops->hooknum, skb); +return nft_do_chain (&pkt, ops); } -static unsigned int nf_nat_ipv6_prerouting (const struct nf_hook_ops *ops, -struct sk_buff *skb, -const struct net_device *in, -const struct net_device *out, -int (*okfn)(struct sk_buff *)) +static unsigned int nft_nat_ipv6_fn (const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +int (*okfn)(struct sk_buff *)) { -struct in6_addr daddr =ipv6_hdr (skb)->daddr; -unsigned int ret; - - ret =nft_nat_ipv6_fn (ops, skb, in, out, okfn); -if (ret !=NF_DROP && ret !=NF_STOLEN && -ipv6_addr_cmp (&daddr, &ipv6_hdr (skb)->daddr)) -skb_dst_drop (skb); - -return ret; +return nf_nat_ipv6_fn (ops, skb, in, out, nft_nat_do_chain); } -static unsigned int nf_nat_ipv6_postrouting (const struct nf_hook_ops *ops, -struct sk_buff *skb, -const struct net_device *in, -const struct net_device *out, -int (*okfn)(struct sk_buff *)) +static unsigned int nft_nat_ipv6_in (const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +int (*okfn)(struct sk_buff *)) { -enum ip_conntrack_info ctinfo__maybe_unused ; -const struct nf_conn *ct__maybe_unused ; -unsigned int ret; - - ret =nft_nat_ipv6_fn (ops, skb, in, out, okfn); -#ifdef CONFIG_XFRM -if (ret !=NF_DROP && ret !=NF_STOLEN && - !(IP6CB (skb)->flags &IP6SKB_XFRM_TRANSFORMED ) && - (ct =nf_ct_get (skb, &ctinfo)) !=NULL ) { -enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo); - -if (!nf_inet_addr_cmp (&ct->tuplehash[dir].tuple.src.u3, - &ct->tuplehash[!dir].tuple.dst.u3) || - (ct->tuplehash[dir].tuple.src.u.all != - ct->tuplehash[!dir].tuple.dst.u.all)) -if (nf_xfrm_me_harder (skb,AF_INET6 ) <0 ) - ret =NF_DROP ; - } -#endif -return ret; +return nf_nat_ipv6_in (ops, skb, in, out, nft_nat_do_chain); } -static unsigned int nf_nat_ipv6_output (const struct nf_hook_ops *ops, -struct sk_buff *skb, -const struct net_device *in, -const struct net_device *out, -int (*okfn)(struct sk_buff *)) +static unsigned int nft_nat_ipv6_out (const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +int (*okfn)(struct sk_buff *)) { -enum ip_conntrack_info ctinfo; -const struct nf_conn *ct; -unsigned int ret; - - ret =nft_nat_ipv6_fn (ops, skb, in, out, okfn); -if (ret !=NF_DROP && ret !=NF_STOLEN && - (ct =nf_ct_get (skb, &ctinfo)) !=NULL ) { -enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo); +return nf_nat_ipv6_out (ops, skb, in, out, nft_nat_do_chain); +} -if (!nf_inet_addr_cmp (&ct->tuplehash[dir].tuple.dst.u3, - &ct->tuplehash[!dir].tuple.src.u3)) { -if (ip6_route_me_harder (skb)) - ret =NF_DROP ; - } -#ifdef CONFIG_XFRM - else if (!(IP6CB(skb)->flags & IP6SKB_XFRM_TRANSFORMED) && - ct->tuplehash[dir].tuple.dst.u.all != - ct->tuplehash[!dir].tuple.src.u.all) -if (nf_xfrm_me_harder (skb,AF_INET6 )) - ret =NF_DROP ; -#endif - } -return ret; +static unsigned int nft_nat_ipv6_local_fn (const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +int (*okfn)(struct sk_buff *)) +{ +return nf_nat_ipv6_local_fn (ops, skb, in, out, nft_nat_do_chain); }static const struct nf_chain_type nft_chain_nat_ipv6 = {
@@ -174,9 +83,9 @@ static const struct nf_chain_type nft_chain_nat_ipv6 = { (1 <<NF_INET_LOCAL_OUT ) | (1 << NF_INET_LOCAL_IN), .hooks = { - [NF_INET_PRE_ROUTING] = nf_nat_ipv6_prerouting, - [NF_INET_POST_ROUTING] = nf_nat_ipv6_postrouting, - [NF_INET_LOCAL_OUT] = nf_nat_ipv6_output, + [NF_INET_PRE_ROUTING] = nft_nat_ipv6_in, + [NF_INET_POST_ROUTING] = nft_nat_ipv6_out, + [NF_INET_LOCAL_OUT] = nft_nat_ipv6_local_fn, [NF_INET_LOCAL_IN] = nft_nat_ipv6_fn, }, };
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 13/25 netfilter: nf_tables: refactor rule deletion helper
In reply to Pablo Neira AyusoFrom: Arturo Borrero <[email protected]>
This helper function always schedule the rule to be removed in the following transaction.
In follow-up patches, it is interesting to handle separately the logic of rule activation/disactivation from the transaction mechanism.
So, this patch simply splits the original nf_tables_delrule_one() in two functions, allowing further control.
While at it, for the sake of homigeneize the function naming scheme, let's rename nf_tables_delrule_one() to nft_delrule().
--- net/netfilter/nf_tables_api.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-)
net/netfilter/nf_tables_api.c +21 -5
@@ -1868,12 +1868,10 @@ err1: }static int -nf_tables_delrule_one (struct nft_ctx *ctx,struct nft_rule *rule) +nf_tables_delrule_deactivate (struct nft_ctx *ctx,struct nft_rule *rule) {/* You cannot delete the same rule twice */ if (nft_rule_is_active_next (ctx->net, rule)) { -if (nft_trans_rule_add (ctx,NFT_MSG_DELRULE , rule) ==NULL ) -return -ENOMEM ;nft_rule_disactivate_next (ctx->net, rule); ctx->chain->use--;return 0 ;
@@ -1881,13 +1879,31 @@ nf_tables_delrule_one(struct nft_ctx *ctx, struct nft_rule *rule)return -ENOENT ; } +static int nft_delrule (struct nft_ctx *ctx,struct nft_rule *rule) +{ +struct nft_trans *trans; +int err; + + trans =nft_trans_rule_add (ctx,NFT_MSG_DELRULE , rule); +if (trans ==NULL ) +return -ENOMEM ; + + err =nf_tables_delrule_deactivate (ctx, rule); +if (err <0 ) { +nft_trans_destroy (trans); +return err; + } + +return 0 ; +} +static int nf_table_delrule_by_chain (struct nft_ctx *ctx) {struct nft_rule *rule;int err;list_for_each_entry (rule, &ctx->chain->rules, list) { - err =nf_tables_delrule_one (ctx, rule); + err =nft_delrule (ctx, rule);if (err <0 )return err; }
@@ -1932,7 +1948,7 @@ static int nf_tables_delrule(struct sock *nlsk, struct sk_buff *skb,if (IS_ERR (rule))return PTR_ERR (rule); - err =nf_tables_delrule_one (&ctx, rule); + err =nft_delrule (&ctx, rule); }else { err =nf_table_delrule_by_chain (&ctx); }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 14/25 netfilter: nf_tables: add helper to unregister chain hooks
In reply to Pablo Neira AyusoFrom: Arturo Borrero <[email protected]>
This patch adds a helper function to unregister chain hooks in the chain deletion path. Basically, a code factorization.
The new function is useful in follow-up patches.
--- net/netfilter/nf_tables_api.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
net/netfilter/nf_tables_api.c +16 -15
@@ -127,6 +127,15 @@ static void nft_trans_destroy(struct nft_trans *trans)kfree (trans); } +static void nf_tables_unregister_hooks (const struct nft_table *table, +const struct nft_chain *chain, +unsigned int hook_nops) +{ +if (!(table->flags &NFT_TABLE_F_DORMANT ) && + chain->flags &NFT_BASE_CHAIN ) +nf_unregister_hooks (nft_base_chain (chain)->ops, hook_nops); +} +/* * Tables */
@@ -1157,11 +1166,7 @@ static int nf_tables_newchain(struct sock *nlsk, struct sk_buff *skb,list_add_tail_rcu (&chain->list, &table->chains);return 0 ; err2: -if (!(table->flags &NFT_TABLE_F_DORMANT ) && - chain->flags &NFT_BASE_CHAIN ) { -nf_unregister_hooks (nft_base_chain (chain)->ops, - afi->nops); - } +nf_tables_unregister_hooks (table, chain, afi->nops); err1:nf_tables_chain_destroy (chain);return err;
@@ -3368,11 +3373,9 @@ static int nf_tables_commit(struct sk_buff *skb)break ;case NFT_MSG_DELCHAIN :nf_tables_chain_notify (&trans->ctx,NFT_MSG_DELCHAIN ); -if (!(trans->ctx.table->flags &NFT_TABLE_F_DORMANT ) && - trans->ctx.chain->flags &NFT_BASE_CHAIN ) { -nf_unregister_hooks (nft_base_chain (trans->ctx.chain)->ops, - trans->ctx.afi->nops); - } +nf_tables_unregister_hooks (trans->ctx.table, + trans->ctx.chain, + trans->ctx.afi->nops);break ;case NFT_MSG_NEWRULE :nft_rule_clear (trans->ctx.net,nft_trans_rule (trans));
@@ -3495,11 +3498,9 @@ static int nf_tables_abort(struct sk_buff *skb) }else { trans->ctx.table->use--;list_del_rcu (&trans->ctx.chain->list); -if (!(trans->ctx.table->flags &NFT_TABLE_F_DORMANT ) && - trans->ctx.chain->flags &NFT_BASE_CHAIN ) { -nf_unregister_hooks (nft_base_chain (trans->ctx.chain)->ops, - trans->ctx.afi->nops); - } +nf_tables_unregister_hooks (trans->ctx.table, + trans->ctx.chain, + trans->ctx.afi->nops); }break ;case NFT_MSG_DELCHAIN :
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 15/25 netfilter: nf_tables: rename nf_table_delrule_by_chain()
In reply to Pablo Neira AyusoFrom: Arturo Borrero <[email protected]>
For the sake of homogenize the function naming scheme, let's rename nf_table_delrule_by_chain() to nft_delrule_by_chain().
--- net/netfilter/nf_tables_api.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/netfilter/nf_tables_api.c +3 -3
@@ -1902,7 +1902,7 @@ static int nft_delrule(struct nft_ctx *ctx, struct nft_rule *rule)return 0 ; } -static int nf_table_delrule_by_chain (struct nft_ctx *ctx) +static int nft_delrule_by_chain (struct nft_ctx *ctx) {struct nft_rule *rule;int err;
@@ -1955,12 +1955,12 @@ static int nf_tables_delrule(struct sock *nlsk, struct sk_buff *skb, err =nft_delrule (&ctx, rule); }else { - err =nf_table_delrule_by_chain (&ctx); + err =nft_delrule_by_chain (&ctx); } }else {list_for_each_entry (chain, &table->chains, list) { ctx.chain = chain; - err =nf_table_delrule_by_chain (&ctx); + err =nft_delrule_by_chain (&ctx);if (err <0 )break ; }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 16/25 netfilter: nf_tables: add devgroup support in meta expresion
In reply to Pablo Neira AyusoFrom: Ana Rey <[email protected]>
Add devgroup support to let us match device group of a packets incoming or outgoing interface.
--- include/uapi/linux/netfilter/nf_tables.h | 4 ++++ net/netfilter/nft_meta.c | 12 ++++++++++++ 2 files changed, 16 insertions(+)
include/uapi/linux/netfilter/nf_tables.h +4 -0
@@ -573,6 +573,8 @@ enum nft_exthdr_attributes {* @NFT_META_BRI_OIFNAME: packet output bridge interface name * @NFT_META_PKTTYPE: packet type (skb->pkt_type), special handling for loopback * @NFT_META_CPU: cpu id through smp_processor_id() +* @NFT_META_IIFGROUP: packet input interface group +* @NFT_META_OIFGROUP: packet output interface group */ enum nft_meta_keys {NFT_META_LEN ,
@@ -596,6 +598,8 @@ enum nft_meta_keys {NFT_META_BRI_OIFNAME ,NFT_META_PKTTYPE ,NFT_META_CPU , +NFT_META_IIFGROUP , + NFT_META_OIFGROUP, };/**
net/netfilter/nft_meta.c +12 -0
@@ -155,6 +155,16 @@ void nft_meta_get_eval(const struct nft_expr *expr,case NFT_META_CPU : dest->data[0 ] =smp_processor_id ();break ; +case NFT_META_IIFGROUP : +if (in ==NULL ) + goto err; + dest->data[0 ] = in->group; +break ; +case NFT_META_OIFGROUP : +if (out ==NULL ) + goto err; + dest->data[0 ] = out->group; +break ;default :WARN_ON (1 ); goto err;
@@ -228,6 +238,8 @@ int nft_meta_get_init(const struct nft_ctx *ctx,#endif case NFT_META_PKTTYPE :case NFT_META_CPU : +case NFT_META_IIFGROUP : +case NFT_META_OIFGROUP :break ;default :return -EOPNOTSUPP ;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 17/25 ipvs: reduce stack usage for sockopt data
In reply to Pablo Neira AyusoFrom: Julian Anastasov <[email protected]>
Use union to reserve the required stack space for sockopt data which is less than the currently hardcoded value of 128. Now the tables for commands should be more readable. The checks added for readability are optimized by compiler, others warn at compile time if command uses too much stack or exceeds the storage of set_arglen and get_arglen.
As Dan Carpenter points out, we can run for unprivileged user, so we can silent some error messages.
--- net/netfilter/ipvs/ip_vs_ctl.c | 111 ++++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 50 deletions(-)
net/netfilter/ipvs/ip_vs_ctl.c +61 -50
@@ -2179,29 +2179,41 @@ static int ip_vs_set_timeout(struct net *net, struct ip_vs_timeout_user *u)return 0 ; } +#define CMDID (cmd) (cmd - IP_VS_BASE_CTL) -#define SET_CMDID (cmd) (cmd - IP_VS_BASE_CTL) -#define SERVICE_ARG_LEN (sizeof(struct ip_vs_service_user)) -#define SVCDEST_ARG_LEN (sizeof(struct ip_vs_service_user) + \ - sizeof(struct ip_vs_dest_user)) -#define TIMEOUT_ARG_LEN (sizeof(struct ip_vs_timeout_user)) -#define DAEMON_ARG_LEN (sizeof(struct ip_vs_daemon_user)) -#define MAX_ARG_LEN SVCDEST_ARG_LEN - -static const unsigned char set_arglen[SET_CMDID (IP_VS_SO_SET_MAX )+1 ] = { - [SET_CMDID (IP_VS_SO_SET_ADD )] =SERVICE_ARG_LEN , - [SET_CMDID (IP_VS_SO_SET_EDIT )] =SERVICE_ARG_LEN , - [SET_CMDID (IP_VS_SO_SET_DEL )] =SERVICE_ARG_LEN , - [SET_CMDID (IP_VS_SO_SET_FLUSH )] =0 , - [SET_CMDID (IP_VS_SO_SET_ADDDEST )] =SVCDEST_ARG_LEN , - [SET_CMDID (IP_VS_SO_SET_DELDEST )] =SVCDEST_ARG_LEN , - [SET_CMDID (IP_VS_SO_SET_EDITDEST )] =SVCDEST_ARG_LEN , - [SET_CMDID (IP_VS_SO_SET_TIMEOUT )] =TIMEOUT_ARG_LEN , - [SET_CMDID (IP_VS_SO_SET_STARTDAEMON )] =DAEMON_ARG_LEN , - [SET_CMDID (IP_VS_SO_SET_STOPDAEMON )] =DAEMON_ARG_LEN , - [SET_CMDID (IP_VS_SO_SET_ZERO )] =SERVICE_ARG_LEN , +struct ip_vs_svcdest_user { +struct ip_vs_service_user s; +struct ip_vs_dest_user d; }; +static const unsigned char set_arglen[CMDID (IP_VS_SO_SET_MAX ) +1 ] = { + [CMDID (IP_VS_SO_SET_ADD )] =sizeof (struct ip_vs_service_user ), + [CMDID (IP_VS_SO_SET_EDIT )] =sizeof (struct ip_vs_service_user ), + [CMDID (IP_VS_SO_SET_DEL )] =sizeof (struct ip_vs_service_user ), + [CMDID (IP_VS_SO_SET_ADDDEST )] =sizeof (struct ip_vs_svcdest_user ), + [CMDID (IP_VS_SO_SET_DELDEST )] =sizeof (struct ip_vs_svcdest_user ), + [CMDID (IP_VS_SO_SET_EDITDEST )] =sizeof (struct ip_vs_svcdest_user ), + [CMDID (IP_VS_SO_SET_TIMEOUT )] =sizeof (struct ip_vs_timeout_user ), + [CMDID (IP_VS_SO_SET_STARTDAEMON )] =sizeof (struct ip_vs_daemon_user ), + [CMDID (IP_VS_SO_SET_STOPDAEMON )] =sizeof (struct ip_vs_daemon_user ), + [CMDID (IP_VS_SO_SET_ZERO )] =sizeof (struct ip_vs_service_user ), +}; + +union ip_vs_set_arglen { +struct ip_vs_service_user field_IP_VS_SO_SET_ADD; +struct ip_vs_service_user field_IP_VS_SO_SET_EDIT; +struct ip_vs_service_user field_IP_VS_SO_SET_DEL; +struct ip_vs_svcdest_user field_IP_VS_SO_SET_ADDDEST; +struct ip_vs_svcdest_user field_IP_VS_SO_SET_DELDEST; +struct ip_vs_svcdest_user field_IP_VS_SO_SET_EDITDEST; +struct ip_vs_timeout_user field_IP_VS_SO_SET_TIMEOUT; +struct ip_vs_daemon_user field_IP_VS_SO_SET_STARTDAEMON; +struct ip_vs_daemon_user field_IP_VS_SO_SET_STOPDAEMON; +struct ip_vs_service_user field_IP_VS_SO_SET_ZERO; +}; + +#define MAX_SET_ARGLEN sizeof(union ip_vs_set_arglen) +static void ip_vs_copy_usvc_compat (struct ip_vs_service_user_kern *usvc,struct ip_vs_service_user *usvc_compat) {
@@ -2239,7 +2251,7 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len) {struct net *net =sock_net (sk);int ret; -unsigned char arg[MAX_ARG_LEN ]; +unsigned char arg[MAX_SET_ARGLEN ];struct ip_vs_service_user *usvc_compat;struct ip_vs_service_user_kern usvc;struct ip_vs_service *svc;
@@ -2247,16 +2259,15 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)struct ip_vs_dest_user_kern udest;struct netns_ipvs *ipvs =net_ipvs (net); +BUILD_BUG_ON (sizeof (arg) >255 );if (!ns_capable (sock_net (sk)->user_ns,CAP_NET_ADMIN ))return -EPERM ;if (cmd <IP_VS_BASE_CTL || cmd >IP_VS_SO_SET_MAX )return -EINVAL ; -if (len <0 || len >MAX_ARG_LEN ) -return -EINVAL ; -if (len != set_arglen[SET_CMDID (cmd)]) { -pr_err ("set_ctl: len %u != %u\n" , - len, set_arglen[SET_CMDID (cmd)]); +if (len != set_arglen[CMDID (cmd)]) { +IP_VS_DBG (1 ,"set_ctl: len %u != %u\n" , + len, set_arglen[CMDID (cmd)]);return -EINVAL ; }
@@ -2512,51 +2523,51 @@ __ip_vs_get_timeouts(struct net *net, struct ip_vs_timeout_user *u)#endif } +static const unsigned char get_arglen[CMDID (IP_VS_SO_GET_MAX ) +1 ] = { + [CMDID (IP_VS_SO_GET_VERSION )] =64 , + [CMDID (IP_VS_SO_GET_INFO )] =sizeof (struct ip_vs_getinfo ), + [CMDID (IP_VS_SO_GET_SERVICES )] =sizeof (struct ip_vs_get_services ), + [CMDID (IP_VS_SO_GET_SERVICE )] =sizeof (struct ip_vs_service_entry ), + [CMDID (IP_VS_SO_GET_DESTS )] =sizeof (struct ip_vs_get_dests ), + [CMDID (IP_VS_SO_GET_TIMEOUT )] =sizeof (struct ip_vs_timeout_user ), + [CMDID (IP_VS_SO_GET_DAEMON )] =2 *sizeof (struct ip_vs_daemon_user ), +}; -#define GET_CMDID (cmd) (cmd - IP_VS_BASE_CTL) -#define GET_INFO_ARG_LEN (sizeof(struct ip_vs_getinfo)) -#define GET_SERVICES_ARG_LEN (sizeof(struct ip_vs_get_services)) -#define GET_SERVICE_ARG_LEN (sizeof(struct ip_vs_service_entry)) -#define GET_DESTS_ARG_LEN (sizeof(struct ip_vs_get_dests)) -#define GET_TIMEOUT_ARG_LEN (sizeof(struct ip_vs_timeout_user)) -#define GET_DAEMON_ARG_LEN (sizeof(struct ip_vs_daemon_user) * 2) - -static const unsigned char get_arglen[GET_CMDID (IP_VS_SO_GET_MAX )+1 ] = { - [GET_CMDID (IP_VS_SO_GET_VERSION )] =64 , - [GET_CMDID (IP_VS_SO_GET_INFO )] =GET_INFO_ARG_LEN , - [GET_CMDID (IP_VS_SO_GET_SERVICES )] =GET_SERVICES_ARG_LEN , - [GET_CMDID (IP_VS_SO_GET_SERVICE )] =GET_SERVICE_ARG_LEN , - [GET_CMDID (IP_VS_SO_GET_DESTS )] =GET_DESTS_ARG_LEN , - [GET_CMDID (IP_VS_SO_GET_TIMEOUT )] =GET_TIMEOUT_ARG_LEN , - [GET_CMDID (IP_VS_SO_GET_DAEMON )] =GET_DAEMON_ARG_LEN , +union ip_vs_get_arglen { +char field_IP_VS_SO_GET_VERSION[64 ]; +struct ip_vs_getinfo field_IP_VS_SO_GET_INFO; +struct ip_vs_get_services field_IP_VS_SO_GET_SERVICES; +struct ip_vs_service_entry field_IP_VS_SO_GET_SERVICE; +struct ip_vs_get_dests field_IP_VS_SO_GET_DESTS; +struct ip_vs_timeout_user field_IP_VS_SO_GET_TIMEOUT; +struct ip_vs_daemon_user field_IP_VS_SO_GET_DAEMON[2 ]; }; +#define MAX_GET_ARGLEN sizeof(union ip_vs_get_arglen) +static int do_ip_vs_get_ctl (struct sock *sk,int cmd,void __user *user,int *len) { -unsigned char arg[128 ]; +unsigned char arg[MAX_GET_ARGLEN ];int ret =0 ;unsigned int copylen;struct net *net =sock_net (sk);struct netns_ipvs *ipvs =net_ipvs (net);BUG_ON (!net); +BUILD_BUG_ON (sizeof (arg) >255 );if (!ns_capable (sock_net (sk)->user_ns,CAP_NET_ADMIN ))return -EPERM ;if (cmd <IP_VS_BASE_CTL || cmd >IP_VS_SO_GET_MAX )return -EINVAL ; -if (*len < get_arglen[GET_CMDID (cmd)]) { -pr_err ("get_ctl: len %u < %u\n" , - *len, get_arglen[GET_CMDID (cmd)]); + copylen = get_arglen[CMDID (cmd)]; +if (*len < (int ) copylen) { +IP_VS_DBG (1 ,"get_ctl: len %d < %u\n" , *len, copylen);return -EINVAL ; } - copylen = get_arglen[GET_CMDID (cmd)]; -if (copylen >128 ) -return -EINVAL ; -if (copy_from_user (arg, user, copylen) !=0 )return -EFAULT ;/*
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 18/25 netfilter: xt_string: Remove unnecessary initialization of struct ts_state
In reply to Pablo Neira AyusoFrom: Bojan Prtvar <[email protected]>
The skb_find_text() accepts uninitialized textsearch state variable.
--- net/netfilter/xt_string.c | 1 - 1 file changed, 1 deletion(-)
net/netfilter/xt_string.c +0 -1
@@ -29,7 +29,6 @@ string_mt(const struct sk_buff *skb, struct xt_action_param *par)struct ts_state state;bool invert; -memset (&state,0 ,sizeof (struct ts_state )); invert = conf->u.v1.flags &XT_STRING_FLAG_INVERT ; return (skb_find_text((struct sk_buff *)skb, conf->from_offset,
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 19/25 netfilter: nf_tables: add helpers to schedule objects deletion
In reply to Pablo Neira AyusoFrom: Arturo Borrero <[email protected]>
This patch refactor the code to schedule objects deletion. They are useful in follow-up patches.
In order to be able to use these new helper functions in all the code, they are placed in the top of the file, with all the dependant functions and symbols.
nft_rule_disactivate_next has been renamed to nft_rule_deactivate.
--- net/netfilter/nf_tables_api.c | 363 ++++++++++++++++++++++------------------- 1 file changed, 194 insertions(+), 169 deletions(-)
net/netfilter/nf_tables_api.c +194 -169
@@ -136,6 +136,195 @@ static void nf_tables_unregister_hooks(const struct nft_table *table,nf_unregister_hooks (nft_base_chain (chain)->ops, hook_nops); } +/* Internal table flags */ +#define NFT_TABLE_INACTIVE (1 << 15) + +static int nft_trans_table_add (struct nft_ctx *ctx,int msg_type) +{ +struct nft_trans *trans; + + trans =nft_trans_alloc (ctx, msg_type,sizeof (struct nft_trans_table )); +if (trans ==NULL ) +return -ENOMEM ; + +if (msg_type ==NFT_MSG_NEWTABLE ) + ctx->table->flags |=NFT_TABLE_INACTIVE ; + +list_add_tail (&trans->list, &ctx->net->nft.commit_list); +return 0 ; +} + +static int nft_deltable (struct nft_ctx *ctx) +{ +int err; + + err =nft_trans_table_add (ctx,NFT_MSG_DELTABLE ); +if (err <0 ) +return err; + +list_del_rcu (&ctx->table->list); +return err; +} + +static int nft_trans_chain_add (struct nft_ctx *ctx,int msg_type) +{ +struct nft_trans *trans; + + trans =nft_trans_alloc (ctx, msg_type,sizeof (struct nft_trans_chain )); +if (trans ==NULL ) +return -ENOMEM ; + +if (msg_type ==NFT_MSG_NEWCHAIN ) + ctx->chain->flags |=NFT_CHAIN_INACTIVE ; + +list_add_tail (&trans->list, &ctx->net->nft.commit_list); +return 0 ; +} + +static int nft_delchain (struct nft_ctx *ctx) +{ +int err; + + err =nft_trans_chain_add (ctx,NFT_MSG_DELCHAIN ); +if (err <0 ) +return err; + + ctx->table->use--; +list_del_rcu (&ctx->chain->list); + +return err; +} + +static inline bool +nft_rule_is_active (struct net *net,const struct nft_rule *rule) +{ +return (rule->genmask & (1 << net->nft.gencursor)) ==0 ; +} + +static inline int gencursor_next (struct net *net) +{ +return net->nft.gencursor+1 ==1 ?1 :0 ; +} + +static inline int +nft_rule_is_active_next (struct net *net,const struct nft_rule *rule) +{ +return (rule->genmask & (1 <<gencursor_next (net))) ==0 ; +} + +static inline void +nft_rule_activate_next (struct net *net,struct nft_rule *rule) +{ +/* Now inactive, will be active in the future */ + rule->genmask = (1 << net->nft.gencursor); +} + +static inline void +nft_rule_deactivate_next (struct net *net,struct nft_rule *rule) +{ + rule->genmask = (1 <<gencursor_next (net)); +} + +static inline void nft_rule_clear (struct net *net,struct nft_rule *rule) +{ + rule->genmask =0 ; +} + +static int +nf_tables_delrule_deactivate (struct nft_ctx *ctx,struct nft_rule *rule) +{ +/* You cannot delete the same rule twice */ +if (nft_rule_is_active_next (ctx->net, rule)) { +nft_rule_deactivate_next (ctx->net, rule); + ctx->chain->use--; +return 0 ; + } +return -ENOENT ; +} + +static struct nft_trans *nft_trans_rule_add (struct nft_ctx *ctx,int msg_type, +struct nft_rule *rule) +{ +struct nft_trans *trans; + + trans =nft_trans_alloc (ctx, msg_type,sizeof (struct nft_trans_rule )); +if (trans ==NULL ) +return NULL ; + +nft_trans_rule (trans) = rule; +list_add_tail (&trans->list, &ctx->net->nft.commit_list); + +return trans; +} + +static int nft_delrule (struct nft_ctx *ctx,struct nft_rule *rule) +{ +struct nft_trans *trans; +int err; + + trans =nft_trans_rule_add (ctx,NFT_MSG_DELRULE , rule); +if (trans ==NULL ) +return -ENOMEM ; + + err =nf_tables_delrule_deactivate (ctx, rule); +if (err <0 ) { +nft_trans_destroy (trans); +return err; + } + +return 0 ; +} + +static int nft_delrule_by_chain (struct nft_ctx *ctx) +{ +struct nft_rule *rule; +int err; + +list_for_each_entry (rule, &ctx->chain->rules, list) { + err =nft_delrule (ctx, rule); +if (err <0 ) +return err; + } +return 0 ; +} + +/* Internal set flag */ +#define NFT_SET_INACTIVE (1 << 15) + +static int nft_trans_set_add (struct nft_ctx *ctx,int msg_type, +struct nft_set *set) +{ +struct nft_trans *trans; + + trans =nft_trans_alloc (ctx, msg_type,sizeof (struct nft_trans_set )); +if (trans ==NULL ) +return -ENOMEM ; + +if (msg_type ==NFT_MSG_NEWSET && ctx->nla[NFTA_SET_ID ] !=NULL ) { +nft_trans_set_id (trans) = +ntohl (nla_get_be32 (ctx->nla[NFTA_SET_ID ])); + set->flags |=NFT_SET_INACTIVE ; + } +nft_trans_set (trans) = set; +list_add_tail (&trans->list, &ctx->net->nft.commit_list); + +return 0 ; +} + +static int nft_delset (struct nft_ctx *ctx,struct nft_set *set) +{ +int err; + + err =nft_trans_set_add (ctx,NFT_MSG_DELSET , set); +if (err <0 ) +return err; + +list_del_rcu (&set->list); + ctx->table->use--; + +return err; +} +/* * Tables */
@@ -318,9 +507,6 @@ done:return skb->len; } -/* Internal table flags */ -#define NFT_TABLE_INACTIVE (1 << 15) -static int nf_tables_gettable (struct sock *nlsk,struct sk_buff *skb,const struct nlmsghdr *nlh,const struct nlattr *const nla[])
@@ -452,21 +638,6 @@ err:return ret; } -static int nft_trans_table_add (struct nft_ctx *ctx,int msg_type) -{ -struct nft_trans *trans; - - trans =nft_trans_alloc (ctx, msg_type,sizeof (struct nft_trans_table )); -if (trans ==NULL ) -return -ENOMEM ; - -if (msg_type ==NFT_MSG_NEWTABLE ) - ctx->table->flags |=NFT_TABLE_INACTIVE ; - -list_add_tail (&trans->list, &ctx->net->nft.commit_list); -return 0 ; -} -static int nf_tables_newtable (struct sock *nlsk,struct sk_buff *skb,const struct nlmsghdr *nlh,const struct nlattr *const nla[])
@@ -544,7 +715,7 @@ static int nf_tables_deltable(struct sock *nlsk, struct sk_buff *skb,struct nft_af_info *afi;struct nft_table *table;struct net *net =sock_net (skb->sk); -int family = nfmsg->nfgen_family, err; +int family = nfmsg->nfgen_family;struct nft_ctx ctx; afi =nf_tables_afinfo_lookup (net, family, false);
@@ -560,12 +731,8 @@ static int nf_tables_deltable(struct sock *nlsk, struct sk_buff *skb,return -EBUSY ;nft_ctx_init (&ctx, skb, nlh, afi, table,NULL , nla); - err =nft_trans_table_add (&ctx,NFT_MSG_DELTABLE ); -if (err <0 ) -return err; -list_del_rcu (&table->list); -return 0 ; +return nft_deltable (&ctx); }static void nf_tables_table_destroy (struct nft_ctx *ctx)
@@ -922,21 +1089,6 @@ static void nft_chain_stats_replace(struct nft_base_chain *chain,rcu_assign_pointer (chain->stats, newstats); } -static int nft_trans_chain_add (struct nft_ctx *ctx,int msg_type) -{ -struct nft_trans *trans; - - trans =nft_trans_alloc (ctx, msg_type,sizeof (struct nft_trans_chain )); -if (trans ==NULL ) -return -ENOMEM ; - -if (msg_type ==NFT_MSG_NEWCHAIN ) - ctx->chain->flags |=NFT_CHAIN_INACTIVE ; - -list_add_tail (&trans->list, &ctx->net->nft.commit_list); -return 0 ; -} -static void nf_tables_chain_destroy (struct nft_chain *chain) {BUG_ON (chain->use >0 );
@@ -1183,7 +1335,6 @@ static int nf_tables_delchain(struct sock *nlsk, struct sk_buff *skb,struct net *net =sock_net (skb->sk);int family = nfmsg->nfgen_family;struct nft_ctx ctx; -int err; afi =nf_tables_afinfo_lookup (net, family, false);if (IS_ERR (afi))
@@ -1204,13 +1355,8 @@ static int nf_tables_delchain(struct sock *nlsk, struct sk_buff *skb,return -EBUSY ;nft_ctx_init (&ctx, skb, nlh, afi, table, chain, nla); - err =nft_trans_chain_add (&ctx,NFT_MSG_DELCHAIN ); -if (err <0 ) -return err; - table->use--; -list_del_rcu (&chain->list); -return 0 ; +return nft_delchain (&ctx); }/*
@@ -1532,41 +1678,6 @@ err:return err; } -static inline bool -nft_rule_is_active (struct net *net,const struct nft_rule *rule) -{ -return (rule->genmask & (1 << net->nft.gencursor)) ==0 ; -} - -static inline int gencursor_next (struct net *net) -{ -return net->nft.gencursor+1 ==1 ?1 :0 ; -} - -static inline int -nft_rule_is_active_next (struct net *net,const struct nft_rule *rule) -{ -return (rule->genmask & (1 <<gencursor_next (net))) ==0 ; -} - -static inline void -nft_rule_activate_next (struct net *net,struct nft_rule *rule) -{ -/* Now inactive, will be active in the future */ - rule->genmask = (1 << net->nft.gencursor); -} - -static inline void -nft_rule_disactivate_next (struct net *net,struct nft_rule *rule) -{ - rule->genmask = (1 <<gencursor_next (net)); -} - -static inline void nft_rule_clear (struct net *net,struct nft_rule *rule) -{ - rule->genmask =0 ; -} -static int nf_tables_dump_rules (struct sk_buff *skb,struct netlink_callback *cb) {
@@ -1692,21 +1803,6 @@ static void nf_tables_rule_destroy(const struct nft_ctx *ctx,kfree (rule); } -static struct nft_trans *nft_trans_rule_add (struct nft_ctx *ctx,int msg_type, -struct nft_rule *rule) -{ -struct nft_trans *trans; - - trans =nft_trans_alloc (ctx, msg_type,sizeof (struct nft_trans_rule )); -if (trans ==NULL ) -return NULL ; - -nft_trans_rule (trans) = rule; -list_add_tail (&trans->list, &ctx->net->nft.commit_list); - -return trans; -} -#define NFT_RULE_MAXEXPRS 128static struct nft_expr_info *info;
@@ -1828,7 +1924,7 @@ static int nf_tables_newrule(struct sock *nlsk, struct sk_buff *skb, err = -ENOMEM ; goto err2; } -nft_rule_disactivate_next (net, old_rule); +nft_rule_deactivate_next (net, old_rule); chain->use--;list_add_tail_rcu (&rule->list, &old_rule->list); }else {
@@ -1872,49 +1968,6 @@ err1:return err; } -static int -nf_tables_delrule_deactivate (struct nft_ctx *ctx,struct nft_rule *rule) -{ -/* You cannot delete the same rule twice */ -if (nft_rule_is_active_next (ctx->net, rule)) { -nft_rule_disactivate_next (ctx->net, rule); - ctx->chain->use--; -return 0 ; - } -return -ENOENT ; -} - -static int nft_delrule (struct nft_ctx *ctx,struct nft_rule *rule) -{ -struct nft_trans *trans; -int err; - - trans =nft_trans_rule_add (ctx,NFT_MSG_DELRULE , rule); -if (trans ==NULL ) -return -ENOMEM ; - - err =nf_tables_delrule_deactivate (ctx, rule); -if (err <0 ) { -nft_trans_destroy (trans); -return err; - } - -return 0 ; -} - -static int nft_delrule_by_chain (struct nft_ctx *ctx) -{ -struct nft_rule *rule; -int err; - -list_for_each_entry (rule, &ctx->chain->rules, list) { - err =nft_delrule (ctx, rule); -if (err <0 ) -return err; - } -return 0 ; -} -static int nf_tables_delrule (struct sock *nlsk,struct sk_buff *skb,const struct nlmsghdr *nlh,const struct nlattr *const nla[])
@@ -2343,8 +2396,6 @@ static int nf_tables_dump_sets_done(struct netlink_callback *cb)return 0 ; } -#define NFT_SET_INACTIVE (1 << 15)/* Internal set flag */ -static int nf_tables_getset (struct sock *nlsk,struct sk_buff *skb,const struct nlmsghdr *nlh,const struct nlattr *const nla[])
@@ -2419,26 +2470,6 @@ static int nf_tables_set_desc_parse(const struct nft_ctx *ctx,return 0 ; } -static int nft_trans_set_add (struct nft_ctx *ctx,int msg_type, -struct nft_set *set) -{ -struct nft_trans *trans; - - trans =nft_trans_alloc (ctx, msg_type,sizeof (struct nft_trans_set )); -if (trans ==NULL ) -return -ENOMEM ; - -if (msg_type ==NFT_MSG_NEWSET && ctx->nla[NFTA_SET_ID ] !=NULL ) { -nft_trans_set_id (trans) = -ntohl (nla_get_be32 (ctx->nla[NFTA_SET_ID ])); - set->flags |=NFT_SET_INACTIVE ; - } -nft_trans_set (trans) = set; -list_add_tail (&trans->list, &ctx->net->nft.commit_list); - -return 0 ; -} -static int nf_tables_newset (struct sock *nlsk,struct sk_buff *skb,const struct nlmsghdr *nlh,const struct nlattr *const nla[])
@@ -2632,13 +2663,7 @@ static int nf_tables_delset(struct sock *nlsk, struct sk_buff *skb,if (!list_empty (&set->bindings))return -EBUSY ; - err =nft_trans_set_add (&ctx,NFT_MSG_DELSET , set); -if (err <0 ) -return err; - -list_del_rcu (&set->list); - ctx.table->use--; -return 0 ; +return nft_delset (&ctx, set); } static int nf_tables_bind_check_setelem(const struct nft_ctx *ctx,
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 20/25 netfilter: nf_tables: extend NFT_MSG_DELTABLE to support flushing the ruleset
In reply to Pablo Neira AyusoFrom: Arturo Borrero <[email protected]>
This patch extend the NFT_MSG_DELTABLE call to support flushing the entire ruleset.
The options now are:
* No family speficied, no table specified: flush all the ruleset.
* Family specified, no table specified: flush all tables in the AF.
* Family specified, table specified: flush the given table.
--- net/netfilter/nf_tables_api.c | 72 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 4 deletions(-)
net/netfilter/nf_tables_api.c +68 -4
@@ -707,6 +707,67 @@ static int nf_tables_newtable(struct sock *nlsk, struct sk_buff *skb,return 0 ; } +static int nft_flush_table (struct nft_ctx *ctx) +{ +int err; +struct nft_chain *chain, *nc; +struct nft_set *set, *ns; + +list_for_each_entry_safe (chain, nc, &ctx->table->chains, list) { + ctx->chain = chain; + + err =nft_delrule_by_chain (ctx); +if (err <0 ) + goto out; + + err =nft_delchain (ctx); +if (err <0 ) + goto out; + } + +list_for_each_entry_safe (set, ns, &ctx->table->sets, list) { +if (set->flags &NFT_SET_ANONYMOUS && + !list_empty (&set->bindings)) +continue ; + + err =nft_delset (ctx, set); +if (err <0 ) + goto out; + } + + err =nft_deltable (ctx); +out: +return err; +} + +static int nft_flush (struct nft_ctx *ctx,int family) +{ +struct nft_af_info *afi; +struct nft_table *table, *nt; +const struct nlattr *const *nla = ctx->nla; +int err =0 ; + +list_for_each_entry (afi, &ctx->net->nft.af_info, list) { +if (family !=AF_UNSPEC && afi->family != family) +continue ; + + ctx->afi = afi; +list_for_each_entry_safe (table, nt, &afi->tables, list) { +if (nla[NFTA_TABLE_NAME ] && +nla_strcmp (nla[NFTA_TABLE_NAME ], table->name) !=0 ) +continue ; + + ctx->table = table; + + err =nft_flush_table (ctx); +if (err <0 ) + goto out; + } + } +out: +return err; +} +static int nf_tables_deltable (struct sock *nlsk,struct sk_buff *skb,const struct nlmsghdr *nlh,const struct nlattr *const nla[])
@@ -718,6 +779,10 @@ static int nf_tables_deltable(struct sock *nlsk, struct sk_buff *skb,int family = nfmsg->nfgen_family;struct nft_ctx ctx; +nft_ctx_init (&ctx, skb, nlh,NULL ,NULL ,NULL , nla); +if (family ==AF_UNSPEC || nla[NFTA_TABLE_NAME ] ==NULL ) +return nft_flush (&ctx, family); + afi =nf_tables_afinfo_lookup (net, family, false);if (IS_ERR (afi))return PTR_ERR (afi);
@@ -727,12 +792,11 @@ static int nf_tables_deltable(struct sock *nlsk, struct sk_buff *skb,return PTR_ERR (table);if (table->flags &NFT_TABLE_INACTIVE )return -ENOENT ; -if (table->use >0 ) -return -EBUSY ; -nft_ctx_init (&ctx, skb, nlh, afi, table,NULL , nla); + ctx.afi = afi; + ctx.table = table; -return nft_deltable (&ctx); +return nft_flush_table (&ctx); }static void nf_tables_table_destroy (struct nft_ctx *ctx)
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 21/25 netfilter: nft_nat: include a flag attribute
In reply to Pablo Neira AyusoFrom: Arturo Borrero <[email protected]>
Both SNAT and DNAT (and the upcoming masquerade) can have additional configuration parameters, such as port randomization and NAT addressing persistence. We can cover these scenarios by simply adding a flag attribute for userspace to fill when needed.
The flags to use are defined in include/uapi/linux/netfilter/nf_nat.h:
NF_NAT_RANGE_MAP_IPS
NF_NAT_RANGE_PROTO_SPECIFIED
NF_NAT_RANGE_PROTO_RANDOM
NF_NAT_RANGE_PERSISTENT
NF_NAT_RANGE_PROTO_RANDOM_FULLY
NF_NAT_RANGE_PROTO_RANDOM_ALL
The caller must take care of not messing up with the flags, as they are added unconditionally to the final resulting nf_nat_range.
--- include/uapi/linux/netfilter/nf_nat.h | 5 +++++ include/uapi/linux/netfilter/nf_tables.h | 2 ++ net/netfilter/nft_nat.c | 16 ++++++++++++++++ 3 files changed, 23 insertions(+)
include/uapi/linux/netfilter/nf_nat.h +5 -0
@@ -13,6 +13,11 @@#define NF_NAT_RANGE_PROTO_RANDOM_ALL \ (NF_NAT_RANGE_PROTO_RANDOM | NF_NAT_RANGE_PROTO_RANDOM_FULLY) +#define NF_NAT_RANGE_MASK \ + (NF_NAT_RANGE_MAP_IPS | NF_NAT_RANGE_PROTO_SPECIFIED | \ + NF_NAT_RANGE_PROTO_RANDOM | NF_NAT_RANGE_PERSISTENT | \ + NF_NAT_RANGE_PROTO_RANDOM_FULLY) +struct nf_nat_ipv4_range {unsigned int flags;__be32 min_ip;
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -785,6 +785,7 @@ enum nft_nat_types {* @NFTA_NAT_REG_ADDR_MAX: source register of address range end (NLA_U32: nft_registers) * @NFTA_NAT_REG_PROTO_MIN: source register of proto range start (NLA_U32: nft_registers) * @NFTA_NAT_REG_PROTO_MAX: source register of proto range end (NLA_U32: nft_registers) +* @NFTA_NAT_FLAGS: NAT flags (see NF_NAT_RANGE_* in linux/netfilter/nf_nat.h) (NLA_U32) */ enum nft_nat_attributes {NFTA_NAT_UNSPEC ,
@@ -794,6 +795,7 @@ enum nft_nat_attributes {NFTA_NAT_REG_ADDR_MAX ,NFTA_NAT_REG_PROTO_MIN ,NFTA_NAT_REG_PROTO_MAX , +NFTA_NAT_FLAGS , __NFTA_NAT_MAX };#define NFTA_NAT_MAX (__NFTA_NAT_MAX - 1)
net/netfilter/nft_nat.c +16 -0
@@ -33,6 +33,7 @@ struct nft_nat { enum nft_registers sreg_proto_max:8; enum nf_nat_manip_type type:8;u8 family; +u16 flags; }; static void nft_nat_eval(const struct nft_expr *expr,
@@ -71,6 +72,8 @@ static void nft_nat_eval(const struct nft_expr *expr, range.flags |=NF_NAT_RANGE_PROTO_SPECIFIED ; } + range.flags |= priv->flags; + data[NFT_REG_VERDICT ].verdict =nf_nat_setup_info (ct, &range, priv->type); }
@@ -82,6 +85,7 @@ static const struct nla_policy nft_nat_policy[NFTA_NAT_MAX + 1] = { [NFTA_NAT_REG_ADDR_MAX] = { .type = NLA_U32 }, [NFTA_NAT_REG_PROTO_MIN] = { .type = NLA_U32 }, [NFTA_NAT_REG_PROTO_MAX] = { .type = NLA_U32 }, + [NFTA_NAT_FLAGS] = { .type = NLA_U32 }, }; static int nft_nat_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
@@ -149,6 +153,12 @@ static int nft_nat_init(const struct nft_ctx *ctx, const struct nft_expr *expr, }else priv->sreg_proto_max = priv->sreg_proto_min; +if (tb[NFTA_NAT_FLAGS ]) { + priv->flags =ntohl (nla_get_be32 (tb[NFTA_NAT_FLAGS ])); +if (priv->flags & ~NF_NAT_RANGE_MASK ) +return -EINVAL ; + } +return 0 ; }
@@ -183,6 +193,12 @@ static int nft_nat_dump(struct sk_buff *skb, const struct nft_expr *expr) htonl(priv->sreg_proto_max))) goto nla_put_failure; } + +if (priv->flags !=0 ) { +if (nla_put_be32 (skb,NFTA_NAT_FLAGS ,htonl (priv->flags))) + goto nla_put_failure; + } +return 0 ; nla_put_failure:
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 22/25 netfilter: ebtables: create audit records for replaces
In reply to Pablo Neira AyusoFrom: Nicolas Dichtel <[email protected]>
This is already done for x_tables (family AF_INET and AF_INET6), let's do it for AF_BRIDGE also.
--- net/bridge/netfilter/ebtables.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
net/bridge/netfilter/ebtables.c +15 -0
@@ -26,6 +26,7 @@#include <asm/uaccess.h> #include <linux/smp.h> #include <linux/cpumask.h> +#include <linux/audit.h> #include <net/sock.h> /* needed for logical [in,out]-dev filtering */ #include "../br_private.h"
@@ -1058,6 +1059,20 @@ static int do_replace_finish(struct net *net, struct ebt_replace *repl,vfree (table);vfree (counterstmp); + +#ifdef CONFIG_AUDIT +if (audit_enabled) { +struct audit_buffer *ab; + + ab =audit_log_start (current->audit_context,GFP_KERNEL , +AUDIT_NETFILTER_CFG ); +if (ab) { +audit_log_format (ab,"table=%s family=%u entries=%u" , + repl->name,AF_BRIDGE , repl->nentries); +audit_log_end (ab); + } + } +#endif return ret; free_unlock:
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 23/25 netfilter: nf_nat: generalize IPv4 masquerading support for nf_tables
In reply to Pablo Neira AyusoFrom: Arturo Borrero <[email protected]>
Let's refactor the code so we can reach the masquerade functionality from outside the xt context (ie. nftables).
The patch includes the addition of an atomic counter to the masquerade
notifier: the stuff to be done by the notifier is the same for xt and nftables. Therefore, only one notification handler is needed.
This factorization only involves IPv4; a similar patch follows to handle IPv6.
--- include/net/netfilter/ipv4/nf_nat_masquerade.h | 14 +++ net/ipv4/netfilter/Kconfig | 7 ++ net/ipv4/netfilter/Makefile | 1 + net/ipv4/netfilter/ipt_MASQUERADE.c | 108 ++--------------- net/ipv4/netfilter/nf_nat_masquerade_ipv4.c | 153 ++++++++++++++++++++++++ 5 files changed, 184 insertions(+), 99 deletions(-) create mode 100644 include/net/netfilter/ipv4/nf_nat_masquerade.h create mode 100644 net/ipv4/netfilter/nf_nat_masquerade_ipv4.c
include/net/netfilter/ipv4/nf_nat_masquerade.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef _NF_NAT_MASQUERADE_IPV4_H_ +#define _NF_NAT_MASQUERADE_IPV4_H_ + +#include <net/netfilter/nf_nat.h> + +unsigned int +nf_nat_masquerade_ipv4 (struct sk_buff *skb,unsigned int hooknum, +const struct nf_nat_range *range, +const struct net_device *out); + +void nf_nat_masquerade_ipv4_register_notifier (void ); +void nf_nat_masquerade_ipv4_unregister_notifier (void ); + +#endif /*_NF_NAT_MASQUERADE_IPV4_H_ */
net/ipv4/netfilter/Kconfig +7 -0
@@ -184,8 +184,15 @@ config NF_NAT_IPV4 if NF_NAT_IPV4 +config NF_NAT_MASQUERADE_IPV4 + tristate "IPv4 masquerade support" + help + This is the kernel functionality to provide NAT in the masquerade + flavour (automatic source address selection). + config IP_NF_TARGET_MASQUERADE tristate "MASQUERADE target support" + select NF_NAT_MASQUERADE_IPV4 default m if NETFILTER_ADVANCED=n help Masquerading is a special case of NAT: all outgoing connections are
net/ipv4/netfilter/Makefile +1 -0
@@ -27,6 +27,7 @@ obj-$(CONFIG_NF_LOG_IPV4) += nf_log_ipv4.o obj-$(CONFIG_NF_NAT_H323) += nf_nat_h323.o obj-$(CONFIG_NF_NAT_PPTP) += nf_nat_pptp.o obj-$(CONFIG_NF_NAT_SNMP_BASIC) += nf_nat_snmp_basic.o +obj-$(CONFIG_NF_NAT_MASQUERADE_IPV4) += nf_nat_masquerade_ipv4.o # NAT protocols (nf_nat) obj-$(CONFIG_NF_NAT_PROTO_GRE) += nf_nat_proto_gre.o
net/ipv4/netfilter/ipt_MASQUERADE.c +9 -99
138 lines not on this page · raw message
net/ipv4/netfilter/nf_nat_masquerade_ipv4.c new file +153 -0
153 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 24/25 netfilter: nf_nat: generalize IPv6 masquerading support for nf_tables
In reply to Pablo Neira AyusoFrom: Arturo Borrero <[email protected]>
Let's refactor the code so we can reach the masquerade functionality from outside the xt context (ie. nftables).
The patch includes the addition of an atomic counter to the masquerade
notifier: the stuff to be done by the notifier is the same for xt and nftables. Therefore, only one notification handler is needed.
This factorization only involves IPv6; a similar patch exists to handle IPv4.
--- include/net/netfilter/ipv6/nf_nat_masquerade.h | 10 ++ net/ipv6/netfilter/Kconfig | 7 ++ net/ipv6/netfilter/Makefile | 1 + net/ipv6/netfilter/ip6t_MASQUERADE.c | 76 +-------------- net/ipv6/netfilter/nf_nat_masquerade_ipv6.c | 120 ++++++++++++++++++++++++ 5 files changed, 143 insertions(+), 71 deletions(-) create mode 100644 include/net/netfilter/ipv6/nf_nat_masquerade.h create mode 100644 net/ipv6/netfilter/nf_nat_masquerade_ipv6.c
include/net/netfilter/ipv6/nf_nat_masquerade.h new file +10 -0
@@ -0,0 +1,10 @@ +#ifndef _NF_NAT_MASQUERADE_IPV6_H_ +#define _NF_NAT_MASQUERADE_IPV6_H_ + +unsigned int +nf_nat_masquerade_ipv6 (struct sk_buff *skb,const struct nf_nat_range *range, +const struct net_device *out); +void nf_nat_masquerade_ipv6_register_notifier (void ); +void nf_nat_masquerade_ipv6_unregister_notifier (void ); + +#endif /* _NF_NAT_MASQUERADE_IPV6_H_ */
net/ipv6/netfilter/Kconfig +7 -0
@@ -246,8 +246,15 @@ config NF_NAT_IPV6 if NF_NAT_IPV6 +config NF_NAT_MASQUERADE_IPV6 + tristate "IPv6 masquerade support" + help + This is the kernel functionality to provide NAT in the masquerade + flavour (automatic source address selection) for IPv6. + config IP6_NF_TARGET_MASQUERADE tristate "MASQUERADE target support" + select NF_NAT_MASQUERADE_IPV6 help Masquerading is a special case of NAT: all outgoing connections are changed to seem to come from a particular interface's address, and
net/ipv6/netfilter/Makefile +1 -0
@@ -18,6 +18,7 @@ obj-$(CONFIG_NF_CONNTRACK_IPV6) += nf_conntrack_ipv6.o nf_nat_ipv6-y := nf_nat_l3proto_ipv6.o nf_nat_proto_icmpv6.o obj-$(CONFIG_NF_NAT_IPV6) += nf_nat_ipv6.o +obj-$(CONFIG_NF_NAT_MASQUERADE_IPV6) += nf_nat_masquerade_ipv6.o # defrag nf_defrag_ipv6-y := nf_defrag_ipv6_hooks.o nf_conntrack_reasm.o
net/ipv6/netfilter/ip6t_MASQUERADE.c +5 -71
103 lines not on this page · raw message
net/ipv6/netfilter/nf_nat_masquerade_ipv6.c new file +120 -0
120 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 25/25 netfilter: nf_tables: add new nft_masq expression
In reply to Pablo Neira AyusoFrom: Arturo Borrero <[email protected]>
The nft_masq expression is intended to perform NAT in the masquerade flavour.
We decided to have the masquerade functionality in a separated expression other than nft_nat.
--- include/net/netfilter/nft_masq.h | 16 ++++++ include/uapi/linux/netfilter/nf_tables.h | 11 ++++ net/ipv4/netfilter/Kconfig | 6 ++ net/ipv4/netfilter/Makefile | 1 + net/ipv4/netfilter/nft_masq_ipv4.c | 89 ++++++++++++++++++++++++++++++ net/ipv6/netfilter/Kconfig | 6 ++ net/ipv6/netfilter/Makefile | 1 + net/ipv6/netfilter/nft_masq_ipv6.c | 89 ++++++++++++++++++++++++++++++ net/netfilter/Kconfig | 9 +++ net/netfilter/Makefile | 1 + net/netfilter/nft_masq.c | 59 ++++++++++++++++++++ 11 files changed, 288 insertions(+) create mode 100644 include/net/netfilter/nft_masq.h create mode 100644 net/ipv4/netfilter/nft_masq_ipv4.c create mode 100644 net/ipv6/netfilter/nft_masq_ipv6.c create mode 100644 net/netfilter/nft_masq.c
include/net/netfilter/nft_masq.h new file +16 -0
@@ -0,0 +1,16 @@ +#ifndef _NFT_MASQ_H_ +#define _NFT_MASQ_H_ + +struct nft_masq { +u32 flags; +}; + +extern const struct nla_policy nft_masq_policy[]; + +int nft_masq_init (const struct nft_ctx *ctx, +const struct nft_expr *expr, +const struct nlattr *const tb[]); + +int nft_masq_dump (struct sk_buff *skb,const struct nft_expr *expr); + +#endif /* _NFT_MASQ_H_ */
include/uapi/linux/netfilter/nf_tables.h +11 -0
@@ -800,4 +800,15 @@ enum nft_nat_attributes { };#define NFTA_NAT_MAX (__NFTA_NAT_MAX - 1) +/** +* enum nft_masq_attributes - nf_tables masquerade expression attributes +* +* @NFTA_MASQ_FLAGS: NAT flags (see NF_NAT_RANGE_* in linux/netfilter/nf_nat.h) (NLA_U32) +*/ +enum nft_masq_attributes { +NFTA_MASQ_FLAGS , + __NFTA_MASQ_MAX +}; +#define NFTA_MASQ_MAX (__NFTA_MASQ_MAX - 1) +#endif /* _LINUX_NF_TABLES_H */
net/ipv4/netfilter/Kconfig +6 -0
@@ -190,6 +190,12 @@ config NF_NAT_MASQUERADE_IPV4 This is the kernel functionality to provide NAT in the masquerade flavour (automatic source address selection). +config NFT_MASQ_IPV4 + tristate "IPv4 masquerading support for nf_tables" + depends on NF_TABLES_IPV4 + depends on NFT_MASQ + select NF_NAT_MASQUERADE_IPV4 + config IP_NF_TARGET_MASQUERADE tristate "MASQUERADE target support" select NF_NAT_MASQUERADE_IPV4
net/ipv4/netfilter/Makefile +1 -0
@@ -36,6 +36,7 @@ obj-$(CONFIG_NF_TABLES_IPV4) += nf_tables_ipv4.o obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV4) += nft_chain_route_ipv4.o obj-$(CONFIG_NFT_CHAIN_NAT_IPV4) += nft_chain_nat_ipv4.o obj-$(CONFIG_NFT_REJECT_IPV4) += nft_reject_ipv4.o +obj-$(CONFIG_NFT_MASQ_IPV4) += nft_masq_ipv4.o obj-$(CONFIG_NF_TABLES_ARP) += nf_tables_arp.o # generic IP tables
net/ipv4/netfilter/nft_masq_ipv4.c new file +89 -0
89 lines not on this page · raw message
net/ipv6/netfilter/Kconfig +6 -0
@@ -252,6 +252,12 @@ config NF_NAT_MASQUERADE_IPV6 This is the kernel functionality to provide NAT in the masquerade flavour (automatic source address selection) for IPv6. +config NFT_MASQ_IPV6 + tristate "IPv6 masquerade support for nf_tables" + depends on NF_TABLES_IPV6 + depends on NFT_MASQ + select NF_NAT_MASQUERADE_IPV6 + config IP6_NF_TARGET_MASQUERADE tristate "MASQUERADE target support" select NF_NAT_MASQUERADE_IPV6
net/ipv6/netfilter/Makefile +1 -0
@@ -32,6 +32,7 @@ obj-$(CONFIG_NF_TABLES_IPV6) += nf_tables_ipv6.o obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV6) += nft_chain_route_ipv6.o obj-$(CONFIG_NFT_CHAIN_NAT_IPV6) += nft_chain_nat_ipv6.o obj-$(CONFIG_NFT_REJECT_IPV6) += nft_reject_ipv6.o +obj-$(CONFIG_NFT_MASQ_IPV6) += nft_masq_ipv6.o # matches obj-$(CONFIG_IP6_NF_MATCH_AH) += ip6t_ah.o
net/ipv6/netfilter/nft_masq_ipv6.c new file +89 -0
89 lines not on this page · raw message
net/netfilter/Kconfig +9 -0
@@ -496,6 +496,15 @@ config NFT_LIMIT This option adds the "limit" expression that you can use to ratelimit rule matchings. +config NFT_MASQ + depends on NF_TABLES + depends on NF_CONNTRACK + depends on NF_NAT + tristate "Netfilter nf_tables masquerade support" + help + This option adds the "masquerade" expression that you can use + to perform NAT in the masquerade flavour. + config NFT_NAT depends on NF_TABLES depends on NF_CONNTRACK
net/netfilter/Makefile +1 -0
@@ -87,6 +87,7 @@ obj-$(CONFIG_NFT_RBTREE) += nft_rbtree.o obj-$(CONFIG_NFT_HASH) += nft_hash.o obj-$(CONFIG_NFT_COUNTER) += nft_counter.o obj-$(CONFIG_NFT_LOG) += nft_log.o +obj-$(CONFIG_NFT_MASQ) += nft_masq.o # generic X tables obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
net/netfilter/nft_masq.c new file +59 -0
59 lines not on this page · raw message
Signature · 1 line
1.7.10.4
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Wed, 10 Sep 2014 17:10:17 +0200
Quoted 3 lines
The following patchset contains Netfilter/IPVS updates for your net-next tree. Regarding
nf_tables, most updates focus on consolidating the NAT infrastructure and adding support for masquerading.
Pulled, thanks Pablo.