Netfilter updates for net-next
Subsystems (4)
Pablo Neira Ayuso
maintainercover Netfilter updates for net-next
Hi David,
The following patchset contains Netfilter updates for your net-next tree, mostly ipset improvements and enhancements features, they are:
* Don't call ip_nest_end needlessly in the error path from me, suggested by Pablo Neira Ayuso, from Jozsef Kadlecsik.
* Fixed sparse warnings about shadowed variable and missing rcu annotation and fix of "may be used uninitialized" warnings, also from Jozsef.
* Renamed simple macro names to avoid namespace issues, reported by David Laight, again from Jozsef.
* Use fix sized type for timeout in the extension part, and cosmetic ordering of matches and targets separatedly in xt_set.c, from Jozsef.
* Support package fragments for IPv4 protos without ports from Anders K. Pedersen. For example this allows a hash:ip,port ipset containing the entry 192.168.0.1,gre:0 to match all package fragments for PPTP VPN tunnels to/from the host. Without this patch only the first package fragment (with fragment offset 0) was matched.
* Introduced a new operation to get both setname and family, from Jozsef. ip[6]tables set match and SET target need to know the family of the set in order to reject adding rules which refer to a set with a non-mathcing family. Currently such rules are silently accepted and then ignored instead of generating an error message to the user.
* Reworked extensions support in ipset types from Jozsef. The approach of defining structures with all variations is not manageable as the number of extensions grows. Therefore a blob for the extensions is introduced, somewhat similar to conntrack. The support of extensions which need a per data destroy function is added as well.
* When an element timed out in a list:set type of set, the garbage collector skipped the checking of the next element. So the purging was delayed to the next run of the gc, fixed by Jozsef.
* A small Kconfig fix: NETFILTER_NETLINK cannot be selected and ipset requires it.
* hash:net,net type from Oliver Smith. The type provides the ability to store pairs of subnets in a set.
* Comment for ipset entries from Oliver Smith. This makes possible to annotate entries in a set with comments, for example:
ipset n foo hash:net,net comment
ipset a foo 10.0.0.0/21,192.168.1.0/24 comment "office nets A and B"
* Fix of hash types resizing with comment extension from Jozsef.
* Fix of new extensions for list:set type when an element is added into a slot from where another element was pushed away from Jozsef.
* Introduction of a common function for the listing of the element extensions from Jozsef.
* Net namespace support for ipset from Vitaly Lavrov.
* hash:net,port,net type from Oliver Smith, which makes possible to store the triples of two subnets and a protocol, port pair in a set.
* Get xt_TCPMSS working with net namespace, by Gao feng.
* Use the proper net netnamespace to allocate skbs, also by Gao feng.
* A couple of cleanups for the conntrack SIP helper, by Holger Eitzenberger.
* Extend cttimeout to allow setting default conntrack timeouts via nfnetlink, so we can get rid of all our sysctl/proc interfaces in the future for timeout tuning, from me.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git master
Thanks!
----------------------------------------------------------------
The following changes since commit 8ce440610357b77587433d0df647cea69a6890a8:
ipv6: do not allow ipv6 module to be removed (2013-09-24 11:31:58 -0400)
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 91cb498e6a34b429a032f8cfbb57dde28cd20e0c:
netfilter: cttimeout: allow to set/get default protocol timeouts (2013-10-01 13:17:39 +0200)
----------------------------------------------------------------
Anders K. Pedersen (1):
netfilter: ipset: Support package fragments for IPv4 protos without ports
Gao feng (4):
netfilter: xt_TCPMSS: Get mtu only if clamp-mss-to-pmtu is specified
netfilter: xt_TCPMSS: lookup route from proper net namespace
netfilter: nfnetlink_queue: use proper net namespace to allocate skb
netfilter: nfnetlink_log: use proper net to allocate skb
Jozsef Kadlecsik (18):
netfilter: ipset: Don't call ip_nest_end needlessly in the error path
netfilter: ipset: Sparse warning about shadowed variable fixed
netfilter: ipset: Fix sparse warnings due to missing rcu annotations
netfilter: ipset: Rename simple macro names to avoid namespace issues.
netfilter: ipset: Fix "may be used uninitialized" warnings
netfilter: ipset: Use fix sized type for timeout in the extension part
netfilter: ipset: order matches and targets separatedly in xt_set.c
netfilter: ipset: Introduce new operation to get both setname and family
netfilter: ipset: Prepare ipset to support multiple networks for hash types
netfilter: ipset: Rename extension offset ids to extension ids
netfilter: ipset: Move extension data to set structure
netfilter: ipset: Generalize extensions support
netfilter: ipset: Support extensions which need a per data destroy function
netfilter: ipset: list:set: make sure all elements are checked by the gc
netfilter: ipset: Kconfig: ipset needs NETFILTER_NETLINK
netfilter: ipset: Fix hash resizing with comments
netfilter: ipset: For set:list types, replaced elements must be zeroed out
netfilter: ipset: Use a common function at listing the extensions
Oliver Smith (6):
netfilter: ipset: Add hash:net,net module to kernel.
netfilter: ipset: Support comments for ipset entries in the core.
netfilter: ipset: Support comments in bitmap-type ipsets.
netfilter: ipset: Support comments in the list-type ipset.
netfilter: ipset: Support comments in hash-type ipsets.
netfilter: ipset: Add hash:net,port,net module to kernel.
Pablo Neira Ayuso (1):
netfilter: cttimeout: allow to set/get default protocol timeouts
Vitaly Lavrov (1):
netfiler: ipset: Add net namespace for ipset
[email protected] (2):
netfilter: nf_ct_sip: extend RCU read lock in set_expected_rtp_rtcp()
netfilter: nf_ct_sip: consolidate NAT hook functions
include/linux/netfilter/ipset/ip_set.h | 151 ++++- include/linux/netfilter/ipset/ip_set_comment.h | 57 ++ include/linux/netfilter/ipset/ip_set_timeout.h | 4 +- include/linux/netfilter/nf_conntrack_sip.h | 107 ++-- include/uapi/linux/netfilter/ipset/ip_set.h | 16 +- include/uapi/linux/netfilter/nfnetlink_cttimeout.h | 2 + net/netfilter/ipset/Kconfig | 20 +- net/netfilter/ipset/Makefile | 2 + net/netfilter/ipset/ip_set_bitmap_gen.h | 163 +++--- net/netfilter/ipset/ip_set_bitmap_ip.c | 125 ++--- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 156 ++---- net/netfilter/ipset/ip_set_bitmap_port.c | 112 +--- net/netfilter/ipset/ip_set_core.c | 361 ++++++++---- net/netfilter/ipset/ip_set_getport.c | 18 +- net/netfilter/ipset/ip_set_hash_gen.h | 526 ++++++++--------- net/netfilter/ipset/ip_set_hash_ip.c | 58 +- net/netfilter/ipset/ip_set_hash_ipport.c | 80 +-- net/netfilter/ipset/ip_set_hash_ipportip.c | 86 +-- net/netfilter/ipset/ip_set_hash_ipportnet.c | 108 +--- net/netfilter/ipset/ip_set_hash_net.c | 85 +-- net/netfilter/ipset/ip_set_hash_netiface.c | 98 +--- net/netfilter/ipset/ip_set_hash_netnet.c | 483 ++++++++++++++++ net/netfilter/ipset/ip_set_hash_netport.c | 92 +-- net/netfilter/ipset/ip_set_hash_netportnet.c | 588 ++++++++++++++++++++ net/netfilter/ipset/ip_set_list_set.c | 263 ++++----- net/netfilter/nf_conntrack_sip.c | 133 ++--- net/netfilter/nf_nat_sip.c | 35 +- net/netfilter/nfnetlink_cttimeout.c | 161 +++++- net/netfilter/nfnetlink_log.c | 11 +- net/netfilter/nfnetlink_queue_core.c | 6 +- net/netfilter/xt_TCPMSS.c | 72 +-- net/netfilter/xt_set.c | 222 ++++---- net/sched/em_ipset.c | 7 +- 33 files changed, 2677 insertions(+), 1731 deletions(-) create mode 100644 include/linux/netfilter/ipset/ip_set_comment.h create mode 100644 net/netfilter/ipset/ip_set_hash_netnet.c create mode 100644 net/netfilter/ipset/ip_set_hash_netportnet.c
Pablo Neira Ayuso
maintainerPATCH 1/33 netfilter: nf_ct_sip: extend RCU read lock in set_expected_rtp_rtcp()
From: "[email protected]" <[email protected]>
Currently set_expected_rtp_rtcp() in the SIP helper uses rcu_dereference() two times to access two different NAT hook functions. However, only the first one is protected by the RCU reader lock, but the 2nd isn't. Fix it by extending the RCU protected area.
This is more a cosmetic thing since we rely on all netfilter hooks being rcu_read_lock()ed by nf_hook_slow() in many places anyways, as Patrick McHardy clarified.
--- net/netfilter/nf_conntrack_sip.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/netfilter/nf_conntrack_sip.c +4 -2
@@ -966,7 +966,6 @@ static int set_expected_rtp_rtcp(struct sk_buff *skb, unsigned int protoff,#endif skip_expect =1 ; }while (!skip_expect); -rcu_read_unlock (); base_port =ntohs (tuple.dst.u.udp.port) & ~1 ; rtp_port =htons (base_port);
@@ -980,8 +979,10 @@ static int set_expected_rtp_rtcp(struct sk_buff *skb, unsigned int protoff, goto err1; } -if (skip_expect) +if (skip_expect) { +rcu_read_unlock ();return NF_ACCEPT ; + } rtp_exp =nf_ct_expect_alloc (ct);if (rtp_exp ==NULL )
@@ -1012,6 +1013,7 @@ static int set_expected_rtp_rtcp(struct sk_buff *skb, unsigned int protoff, err2:nf_ct_expect_put (rtp_exp); err1: +rcu_read_unlock ();return ret; }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 2/33 netfilter: xt_TCPMSS: Get mtu only if clamp-mss-to-pmtu is specified
In reply to Pablo Neira AyusoFrom: Gao feng <[email protected]>
This patch refactors the code to skip tcpmss_reverse_mtu if no clamp-mss-to-pmtu is specified.
--- net/netfilter/xt_TCPMSS.c | 70 +++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 34 deletions(-)
net/netfilter/xt_TCPMSS.c +36 -34
@@ -43,10 +43,41 @@ optlen(const u_int8_t *opt, unsigned int offset)return opt[offset+1 ]; } +static u_int32_t tcpmss_reverse_mtu (const struct sk_buff *skb, +unsigned int family) +{ +struct flowi fl; +const struct nf_afinfo *ai; +struct rtable *rt =NULL ; +u_int32_t mtu = ~0U ; + +if (family ==PF_INET ) { +struct flowi4 *fl4 = &fl.u.ip4; +memset (fl4,0 ,sizeof (*fl4)); + fl4->daddr =ip_hdr (skb)->saddr; + }else { +struct flowi6 *fl6 = &fl.u.ip6; + +memset (fl6,0 ,sizeof (*fl6)); + fl6->daddr =ipv6_hdr (skb)->saddr; + } +rcu_read_lock (); + ai =nf_get_afinfo (family); +if (ai !=NULL ) + ai->route (&init_net, (struct dst_entry **)&rt, &fl, false); +rcu_read_unlock (); + +if (rt !=NULL ) { + mtu =dst_mtu (&rt->dst); +dst_release (&rt->dst); + } +return mtu; +} +static int tcpmss_mangle_packet (struct sk_buff *skb,const struct xt_action_param *par, -unsigned int in_mtu, +unsigned int family,unsigned int tcphoff,unsigned int minlen) {
@@ -76,6 +107,8 @@ tcpmss_mangle_packet(struct sk_buff *skb,return -1 ;if (info->mss ==XT_TCPMSS_CLAMP_PMTU ) { +unsigned int in_mtu =tcpmss_reverse_mtu (skb, family); +if (dst_mtu (skb_dst (skb)) <= minlen) {net_err_ratelimited ("unknown or invalid path-MTU (%u)\n" ,dst_mtu (skb_dst (skb)));
@@ -165,37 +198,6 @@ tcpmss_mangle_packet(struct sk_buff *skb,return TCPOLEN_MSS ; } -static u_int32_t tcpmss_reverse_mtu (const struct sk_buff *skb, -unsigned int family) -{ -struct flowi fl; -const struct nf_afinfo *ai; -struct rtable *rt =NULL ; -u_int32_t mtu = ~0U ; - -if (family ==PF_INET ) { -struct flowi4 *fl4 = &fl.u.ip4; -memset (fl4,0 ,sizeof (*fl4)); - fl4->daddr =ip_hdr (skb)->saddr; - }else { -struct flowi6 *fl6 = &fl.u.ip6; - -memset (fl6,0 ,sizeof (*fl6)); - fl6->daddr =ipv6_hdr (skb)->saddr; - } -rcu_read_lock (); - ai =nf_get_afinfo (family); -if (ai !=NULL ) - ai->route (&init_net, (struct dst_entry **)&rt, &fl, false); -rcu_read_unlock (); - -if (rt !=NULL ) { - mtu =dst_mtu (&rt->dst); -dst_release (&rt->dst); - } -return mtu; -} -static unsigned int tcpmss_tg4 (struct sk_buff *skb,const struct xt_action_param *par) {
@@ -204,7 +206,7 @@ tcpmss_tg4(struct sk_buff *skb, const struct xt_action_param *par)int ret; ret =tcpmss_mangle_packet (skb, par, -tcpmss_reverse_mtu (skb,PF_INET ), +PF_INET , iph->ihl *4 ,sizeof (*iph) +sizeof (struct tcphdr ));if (ret <0 )
@@ -233,7 +235,7 @@ tcpmss_tg6(struct sk_buff *skb, const struct xt_action_param *par)if (tcphoff <0 )return NF_DROP ; ret =tcpmss_mangle_packet (skb, par, -tcpmss_reverse_mtu (skb,PF_INET6 ), +PF_INET6 , tcphoff,sizeof (*ipv6h) +sizeof (struct tcphdr ));if (ret <0 )
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 3/33 netfilter: xt_TCPMSS: lookup route from proper net namespace
In reply to Pablo Neira AyusoFrom: Gao feng <[email protected]>
Otherwise the pmtu will be incorrect.
--- net/netfilter/xt_TCPMSS.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
net/netfilter/xt_TCPMSS.c +5 -3
@@ -43,7 +43,8 @@ optlen(const u_int8_t *opt, unsigned int offset)return opt[offset+1 ]; } -static u_int32_t tcpmss_reverse_mtu (const struct sk_buff *skb, +static u_int32_t tcpmss_reverse_mtu (struct net *net, +const struct sk_buff *skb,unsigned int family) {struct flowi fl;
@@ -64,7 +65,7 @@ static u_int32_t tcpmss_reverse_mtu(const struct sk_buff *skb,rcu_read_lock (); ai =nf_get_afinfo (family);if (ai !=NULL ) - ai->route (&init_net, (struct dst_entry **)&rt, &fl, false); + ai->route (net, (struct dst_entry **)&rt, &fl, false);rcu_read_unlock ();if (rt !=NULL ) {
@@ -107,7 +108,8 @@ tcpmss_mangle_packet(struct sk_buff *skb,return -1 ;if (info->mss ==XT_TCPMSS_CLAMP_PMTU ) { -unsigned int in_mtu =tcpmss_reverse_mtu (skb, family); +struct net *net =dev_net (par->in ? par->in : par->out); +unsigned int in_mtu =tcpmss_reverse_mtu (net, skb, family);if (dst_mtu (skb_dst (skb)) <= minlen) { net_err_ratelimited("unknown or invalid path-MTU (%u)\n",
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 4/33 netfilter: ipset: Don't call ip_nest_end needlessly in the error path
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
--- net/netfilter/ipset/ip_set_bitmap_gen.h | 2 +- net/netfilter/ipset/ip_set_hash_gen.h | 2 +- net/netfilter/ipset/ip_set_list_set.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
net/netfilter/ipset/ip_set_bitmap_gen.h +1 -1
@@ -228,11 +228,11 @@ mtype_list(const struct ip_set *set, nla_put_failure:nla_nest_cancel (skb, nested); -ipset_nest_end (skb, adt);if (unlikely (id == first)) { cb->args[2 ] =0 ;return -EMSGSIZE ; } +ipset_nest_end (skb, adt);return 0 ; }
net/netfilter/ipset/ip_set_hash_gen.h +1 -1
@@ -909,13 +909,13 @@ mtype_list(const struct ip_set *set, nla_put_failure:nlmsg_trim (skb, incomplete); -ipset_nest_end (skb, atd);if (unlikely (first == cb->args[2 ])) {pr_warning ("Can't list set %s: one bucket does not fit into " "a message. Please report it!\n" , set->name); cb->args[2 ] =0 ;return -EMSGSIZE ; } +ipset_nest_end (skb, atd);return 0 ; }
net/netfilter/ipset/ip_set_list_set.c +1 -1
@@ -550,11 +550,11 @@ finish: nla_put_failure:nla_nest_cancel (skb, nested); -ipset_nest_end (skb, atd);if (unlikely (i == first)) { cb->args[2 ] =0 ;return -EMSGSIZE ; } +ipset_nest_end (skb, atd);return 0 ; }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 5/33 netfilter: ipset: Sparse warning about shadowed variable fixed
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
net/netfilter/ipset/ip_set_hash_ipportnet.c:275:20:
warning: symbol 'cidr' shadows an earlier one
--- net/netfilter/ipset/ip_set_hash_ipportnet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipset/ip_set_hash_ipportnet.c +1 -1
@@ -272,7 +272,7 @@ hash_ipportnet4_uadt(struct ip_set *set, struct nlattr *tb[],if (ip > ip_to)swap (ip, ip_to); }else if (tb[IPSET_ATTR_CIDR ]) { -u8 cidr =nla_get_u8 (tb[IPSET_ATTR_CIDR ]); + cidr =nla_get_u8 (tb[IPSET_ATTR_CIDR ]);if (!cidr || cidr >32 )return -IPSET_ERR_INVALID_CIDR ;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 6/33 netfilter: ipset: Fix sparse warnings due to missing rcu annotations
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
--- net/netfilter/ipset/ip_set_hash_gen.h | 87 +++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 32 deletions(-)
net/netfilter/ipset/ip_set_hash_gen.h +55 -32
@@ -15,6 +15,8 @@#define rcu_dereference_bh (p) rcu_dereference(p)#endif +#define rcu_dereference_bh_nfnl (p) rcu_dereference_bh_check(p, 1) +#define CONCAT (a, b) a##b#define TOKEN (a, b) CONCAT(a, b)
@@ -269,7 +271,7 @@ hbucket_elem_add(struct hbucket *n, u8 ahash_max, size_t dsize)/* The generic hash structure */ struct htype { -struct htable *table;/* the hash table */ +struct htable __rcu *table;/* the hash table */ u32 maxelem;/* max elements in the hash */ u32 elements;/* current element (vs timeout) */ u32 initval;/* random jhash init value */
@@ -347,10 +349,10 @@ mtype_del_cidr(struct htype *h, u8 cidr, u8 nets_length)/* Calculate the actual memory size of the set data */ static size_t -mtype_ahash_memsize (const struct htype *h,u8 nets_length) +mtype_ahash_memsize (const struct htype *h,const struct htable *t, +u8 nets_length) {u32 i; -struct htable *t = h->table;size_t memsize =sizeof (*h) + sizeof(*t)#ifdef IP_SET_HASH_WITH_NETS
@@ -369,10 +371,11 @@ static void mtype_flush(struct ip_set *set) {struct htype *h = set->data; -struct htable *t = h->table; +struct htable *t;struct hbucket *n;u32 i; + t =rcu_dereference_bh_nfnl (h->table);for (i =0 ; i <jhash_size (t->htable_bits); i++) { n =hbucket (t, i);if (n->size) {
@@ -397,7 +400,7 @@ mtype_destroy(struct ip_set *set)if (set->extensions &IPSET_EXT_TIMEOUT )del_timer_sync (&h->gc); -ahash_destroy (h->table); +ahash_destroy (rcu_dereference_bh_nfnl (h->table));#ifdef IP_SET_HASH_WITH_RBTREE rbtree_destroy (&h->rbtree);#endif
@@ -443,12 +446,14 @@ mtype_same_set(const struct ip_set *a, const struct ip_set *b)static void mtype_expire (struct htype *h,u8 nets_length,size_t dsize) { -struct htable *t = h->table; +struct htable *t;struct hbucket *n;struct mtype_elem *data;u32 i;int j; +rcu_read_lock_bh (); + t =rcu_dereference_bh (h->table);for (i =0 ; i <jhash_size (t->htable_bits); i++) { n =hbucket (t, i);for (j =0 ; j < n->pos; j++) {
@@ -481,6 +486,7 @@ mtype_expire(struct htype *h, u8 nets_length, size_t dsize) n->value = tmp; } } +rcu_read_unlock_bh (); } static void
@@ -505,7 +511,7 @@ static int mtype_resize(struct ip_set *set, bool retried) {struct htype *h = set->data; -struct htable *t, *orig = h->table; +struct htable *t, *orig =rcu_dereference_bh_nfnl (h->table);u8 htable_bits = orig->htable_bits;#ifdef IP_SET_HASH_WITH_NETS u8 flags;
@@ -682,13 +688,15 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext, struct ip_set_ext *mext, u32 flags) {struct htype *h = set->data; -struct htable *t = h->table; +struct htable *t;const struct mtype_elem *d = value;struct mtype_elem *data;struct hbucket *n; -int i; +int i, ret = -IPSET_ERR_EXIST ;u32 key, multi =0 ; +rcu_read_lock_bh (); + t =rcu_dereference_bh (h->table); key =HKEY (value, h->initval, t->htable_bits); n =hbucket (t, key);for (i =0 ; i < n->pos; i++) {
@@ -697,7 +705,7 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext,continue ;if (SET_WITH_TIMEOUT (set) &&ip_set_timeout_expired (ext_timeout (data, h))) -return -IPSET_ERR_EXIST ; + goto out;if (i != n->pos -1 )/* Not last one */ memcpy(data, ahash_data(n, n->pos - 1, h->dsize),
@@ -712,17 +720,22 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext,void *tmp =kzalloc ((n->size -AHASH_INIT_SIZE ) * h->dsize,GFP_ATOMIC ); -if (!tmp) -return 0 ; +if (!tmp) { + ret =0 ; + goto out; + } n->size -=AHASH_INIT_SIZE ;memcpy (tmp, n->value, n->size * h->dsize);kfree (n->value); n->value = tmp; } -return 0 ; + ret =0 ; + goto out; } -return -IPSET_ERR_EXIST ; +out: +rcu_read_unlock_bh (); +return ret; } static inline int
@@ -745,7 +758,7 @@ mtype_test_cidrs(struct ip_set *set, struct mtype_elem *d, struct ip_set_ext *mext, u32 flags) {struct htype *h = set->data; -struct htable *t = h->table; +struct htable *t =rcu_dereference_bh (h->table);struct hbucket *n;struct mtype_elem *data;int i, j =0 ;
@@ -785,18 +798,22 @@ mtype_test(struct ip_set *set, void *value, const struct ip_set_ext *ext, struct ip_set_ext *mext, u32 flags) {struct htype *h = set->data; -struct htable *t = h->table; +struct htable *t;struct mtype_elem *d = value;struct hbucket *n;struct mtype_elem *data; -int i; +int i, ret =0 ;u32 key, multi =0 ; +rcu_read_lock_bh (); + t =rcu_dereference_bh (h->table);#ifdef IP_SET_HASH_WITH_NETS /* If we test an IP address and not a network address, * try all possible network sizes */ -if (CIDR (d->cidr) ==SET_HOST_MASK (set->family)) -return mtype_test_cidrs (set, d, ext, mext, flags); +if (CIDR (d->cidr) ==SET_HOST_MASK (set->family)) { + ret =mtype_test_cidrs (set, d, ext, mext, flags); + goto out; + }#endif key =HKEY (d, h->initval, t->htable_bits);
@@ -805,10 +822,14 @@ mtype_test(struct ip_set *set, void *value, const struct ip_set_ext *ext, data =ahash_data (n, i, h->dsize);if (mtype_data_equal (data, d, &multi) && !(SET_WITH_TIMEOUT (set) && -ip_set_timeout_expired (ext_timeout (data, h)))) -return mtype_data_match (data, ext, mext, set, flags); +ip_set_timeout_expired (ext_timeout (data, h)))) { + ret =mtype_data_match (data, ext, mext, set, flags); + goto out; + } } -return 0 ; +out: +rcu_read_unlock_bh (); +return ret; }/* Reply a HEADER request: fill out the header part of the set */
@@ -816,18 +837,18 @@ static int mtype_head(struct ip_set *set, struct sk_buff *skb) { const struct htype *h = set->data; +const struct htable *t;struct nlattr *nested;size_t memsize; -read_lock_bh (&set->lock); - memsize =mtype_ahash_memsize (h,NETS_LENGTH (set->family)); -read_unlock_bh (&set->lock); + t =rcu_dereference_bh_nfnl (h->table); + memsize =mtype_ahash_memsize (h, t,NETS_LENGTH (set->family)); nested =ipset_nest_start (skb,IPSET_ATTR_DATA );if (!nested) goto nla_put_failure;if (nla_put_net32 (skb,IPSET_ATTR_HASHSIZE , -htonl (jhash_size (h->table->htable_bits))) || +htonl (jhash_size (t->htable_bits))) ||nla_put_net32 (skb,IPSET_ATTR_MAXELEM ,htonl (h->maxelem))) goto nla_put_failure;#ifdef IP_SET_HASH_WITH_NETMASK
@@ -856,7 +877,7 @@ mtype_list(const struct ip_set *set, struct sk_buff *skb, struct netlink_callback *cb) { const struct htype *h = set->data; -const struct htable *t = h->table; +const struct htable *t =rcu_dereference_bh_nfnl (h->table);struct nlattr *atd, *nested;const struct hbucket *n;const struct mtype_elem *e;
@@ -956,6 +977,7 @@ TOKEN(HTYPE, _create)(struct ip_set *set, struct nlattr *tb[], u32 flags)#endif size_t hsize;struct HTYPE *h; +struct htable *t;if (!(set->family ==NFPROTO_IPV4 || set->family ==NFPROTO_IPV6 ))return -IPSET_ERR_INVALID_FAMILY ;
@@ -1013,12 +1035,13 @@ TOKEN(HTYPE, _create)(struct ip_set *set, struct nlattr *tb[], u32 flags)kfree (h);return -ENOMEM ; } - h->table =ip_set_alloc (hsize); -if (!h->table) { + t =ip_set_alloc (hsize); +if (!t) {kfree (h);return -ENOMEM ; } - h->table->htable_bits = hbits; + t->htable_bits = hbits; +rcu_assign_pointer (h->table, t); set->data = h;if (set->family ==NFPROTO_IPV4 )
@@ -1096,8 +1119,8 @@ TOKEN(HTYPE, _create)(struct ip_set *set, struct nlattr *tb[], u32 flags) }pr_debug ("create %s hashsize %u (%u) maxelem %u: %p(%p)\n" , - set->name,jhash_size (h->table->htable_bits), - h->table->htable_bits, h->maxelem, set->data, h->table); + set->name,jhash_size (t->htable_bits), + t->htable_bits, h->maxelem, set->data, t);return 0 ; }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 7/33 netfilter: ipset: Rename simple macro names to avoid namespace issues.
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
--- include/linux/netfilter/ipset/ip_set.h | 3 + net/netfilter/ipset/ip_set_bitmap_gen.h | 47 ++++----- net/netfilter/ipset/ip_set_bitmap_ip.c | 10 +- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 10 +- net/netfilter/ipset/ip_set_bitmap_port.c | 10 +- net/netfilter/ipset/ip_set_hash_gen.h | 147 ++++++++++++++------------- net/netfilter/ipset/ip_set_hash_ip.c | 10 +- net/netfilter/ipset/ip_set_hash_ipport.c | 12 +-- net/netfilter/ipset/ip_set_hash_ipportip.c | 12 +-- net/netfilter/ipset/ip_set_hash_ipportnet.c | 16 +-- net/netfilter/ipset/ip_set_hash_net.c | 14 +-- net/netfilter/ipset/ip_set_hash_netiface.c | 14 +-- net/netfilter/ipset/ip_set_hash_netport.c | 16 +-- net/netfilter/ipset/ip_set_list_set.c | 10 +- 14 files changed, 169 insertions(+), 162 deletions(-)
include/linux/netfilter/ipset/ip_set.h +3 -0
@@ -398,4 +398,7 @@ bitmap_bytes(u32 a, u32 b) { .bytes = ULLONG_MAX, .packets = ULLONG_MAX, \ .timeout = (map)->timeout } +#define IPSET_CONCAT (a, b) a##b +#define IPSET_TOKEN (a, b) IPSET_CONCAT(a, b) +#endif /*_IP_SET_H */
net/netfilter/ipset/ip_set_bitmap_gen.h +22 -25
53 lines not on this page · raw message
net/netfilter/ipset/ip_set_bitmap_ip.c +5 -5
@@ -25,12 +25,12 @@#include <linux/netfilter/ipset/ip_set.h> #include <linux/netfilter/ipset/ip_set_bitmap.h> -#define REVISION_MIN 0 -#define REVISION_MAX 1/* Counter support added */ +#define IPSET_TYPE_REV_MIN 0 +#define IPSET_TYPE_REV_MAX 1/* Counter support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" ); -IP_SET_MODULE_DESC ("bitmap:ip" ,REVISION_MIN ,REVISION_MAX ); +IP_SET_MODULE_DESC ("bitmap:ip" ,IPSET_TYPE_REV_MIN ,IPSET_TYPE_REV_MAX );MODULE_ALIAS ("ip_set_bitmap:ip" );#define MTYPE bitmap_ip
@@ -401,8 +401,8 @@ static struct ip_set_type bitmap_ip_type __read_mostly = { .features = IPSET_TYPE_IP, .dimension = IPSET_DIM_ONE, .family = NFPROTO_IPV4, - .revision_min = REVISION_MIN, - .revision_max = REVISION_MAX, + .revision_min = IPSET_TYPE_REV_MIN, + .revision_max = IPSET_TYPE_REV_MAX, .create = bitmap_ip_create, .create_policy = { [IPSET_ATTR_IP] = { .type = NLA_NESTED },
net/netfilter/ipset/ip_set_bitmap_ipmac.c +5 -5
@@ -25,12 +25,12 @@#include <linux/netfilter/ipset/ip_set.h> #include <linux/netfilter/ipset/ip_set_bitmap.h> -#define REVISION_MIN 0 -#define REVISION_MAX 1/* Counter support added */ +#define IPSET_TYPE_REV_MIN 0 +#define IPSET_TYPE_REV_MAX 1/* Counter support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" ); -IP_SET_MODULE_DESC ("bitmap:ip,mac" ,REVISION_MIN ,REVISION_MAX ); +IP_SET_MODULE_DESC ("bitmap:ip,mac" ,IPSET_TYPE_REV_MIN ,IPSET_TYPE_REV_MAX );MODULE_ALIAS ("ip_set_bitmap:ip,mac" );#define MTYPE bitmap_ipmac
@@ -460,8 +460,8 @@ static struct ip_set_type bitmap_ipmac_type = { .features = IPSET_TYPE_IP | IPSET_TYPE_MAC, .dimension = IPSET_DIM_TWO, .family = NFPROTO_IPV4, - .revision_min = REVISION_MIN, - .revision_max = REVISION_MAX, + .revision_min = IPSET_TYPE_REV_MIN, + .revision_max = IPSET_TYPE_REV_MAX, .create = bitmap_ipmac_create, .create_policy = { [IPSET_ATTR_IP] = { .type = NLA_NESTED },
net/netfilter/ipset/ip_set_bitmap_port.c +5 -5
@@ -20,12 +20,12 @@#include <linux/netfilter/ipset/ip_set_bitmap.h> #include <linux/netfilter/ipset/ip_set_getport.h> -#define REVISION_MIN 0 -#define REVISION_MAX 1/* Counter support added */ +#define IPSET_TYPE_REV_MIN 0 +#define IPSET_TYPE_REV_MAX 1/* Counter support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" ); -IP_SET_MODULE_DESC ("bitmap:port" ,REVISION_MIN ,REVISION_MAX ); +IP_SET_MODULE_DESC ("bitmap:port" ,IPSET_TYPE_REV_MIN ,IPSET_TYPE_REV_MAX );MODULE_ALIAS ("ip_set_bitmap:port" );#define MTYPE bitmap_port
@@ -333,8 +333,8 @@ static struct ip_set_type bitmap_port_type = { .features = IPSET_TYPE_PORT, .dimension = IPSET_DIM_ONE, .family = NFPROTO_UNSPEC, - .revision_min = REVISION_MIN, - .revision_max = REVISION_MAX, + .revision_min = IPSET_TYPE_REV_MIN, + .revision_max = IPSET_TYPE_REV_MAX, .create = bitmap_port_create, .create_policy = { [IPSET_ATTR_PORT] = { .type = NLA_U16 },
net/netfilter/ipset/ip_set_hash_gen.h +77 -70
220 lines not on this page · raw message
net/netfilter/ipset/ip_set_hash_ip.c +5 -5
@@ -23,12 +23,12 @@#include <linux/netfilter/ipset/ip_set.h> #include <linux/netfilter/ipset/ip_set_hash.h> -#define REVISION_MIN 0 -#define REVISION_MAX 1/* Counters support */ +#define IPSET_TYPE_REV_MIN 0 +#define IPSET_TYPE_REV_MAX 1/* Counters support */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" ); -IP_SET_MODULE_DESC ("hash:ip" ,REVISION_MIN ,REVISION_MAX ); +IP_SET_MODULE_DESC ("hash:ip" ,IPSET_TYPE_REV_MIN ,IPSET_TYPE_REV_MAX );MODULE_ALIAS ("ip_set_hash:ip" );/* Type specific function prefix */
@@ -304,8 +304,8 @@ static struct ip_set_type hash_ip_type __read_mostly = { .features = IPSET_TYPE_IP, .dimension = IPSET_DIM_ONE, .family = NFPROTO_UNSPEC, - .revision_min = REVISION_MIN, - .revision_max = REVISION_MAX, + .revision_min = IPSET_TYPE_REV_MIN, + .revision_max = IPSET_TYPE_REV_MAX, .create = hash_ip_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_ipport.c +6 -6
@@ -24,13 +24,13 @@#include <linux/netfilter/ipset/ip_set_getport.h> #include <linux/netfilter/ipset/ip_set_hash.h> -#define REVISION_MIN 0 -/* 1 SCTP and UDPLITE support added */ -#define REVISION_MAX 2/* Counters support added */ +#define IPSET_TYPE_REV_MIN 0 +/* 1 SCTP and UDPLITE support added */ +#define IPSET_TYPE_REV_MAX 2/* Counters support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" ); -IP_SET_MODULE_DESC ("hash:ip,port" ,REVISION_MIN ,REVISION_MAX ); +IP_SET_MODULE_DESC ("hash:ip,port" ,IPSET_TYPE_REV_MIN ,IPSET_TYPE_REV_MAX );MODULE_ALIAS ("ip_set_hash:ip,port" );/* Type specific function prefix */
@@ -396,8 +396,8 @@ static struct ip_set_type hash_ipport_type __read_mostly = { .features = IPSET_TYPE_IP | IPSET_TYPE_PORT, .dimension = IPSET_DIM_TWO, .family = NFPROTO_UNSPEC, - .revision_min = REVISION_MIN, - .revision_max = REVISION_MAX, + .revision_min = IPSET_TYPE_REV_MIN, + .revision_max = IPSET_TYPE_REV_MAX, .create = hash_ipport_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_ipportip.c +6 -6
@@ -24,13 +24,13 @@#include <linux/netfilter/ipset/ip_set_getport.h> #include <linux/netfilter/ipset/ip_set_hash.h> -#define REVISION_MIN 0 -/* 1 SCTP and UDPLITE support added */ -#define REVISION_MAX 2/* Counters support added */ +#define IPSET_TYPE_REV_MIN 0 +/* 1 SCTP and UDPLITE support added */ +#define IPSET_TYPE_REV_MAX 2/* Counters support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" ); -IP_SET_MODULE_DESC ("hash:ip,port,ip" ,REVISION_MIN ,REVISION_MAX ); +IP_SET_MODULE_DESC ("hash:ip,port,ip" ,IPSET_TYPE_REV_MIN ,IPSET_TYPE_REV_MAX );MODULE_ALIAS ("ip_set_hash:ip,port,ip" );/* Type specific function prefix */
@@ -414,8 +414,8 @@ static struct ip_set_type hash_ipportip_type __read_mostly = { .features = IPSET_TYPE_IP | IPSET_TYPE_PORT | IPSET_TYPE_IP2, .dimension = IPSET_DIM_THREE, .family = NFPROTO_UNSPEC, - .revision_min = REVISION_MIN, - .revision_max = REVISION_MAX, + .revision_min = IPSET_TYPE_REV_MIN, + .revision_max = IPSET_TYPE_REV_MAX, .create = hash_ipportip_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_ipportnet.c +8 -8
@@ -24,15 +24,15 @@#include <linux/netfilter/ipset/ip_set_getport.h> #include <linux/netfilter/ipset/ip_set_hash.h> -#define REVISION_MIN 0 -/* 1 SCTP and UDPLITE support added */ -/* 2 Range as input support for IPv4 added */ -/* 3 nomatch flag support added */ -#define REVISION_MAX 4/* Counters support added */ +#define IPSET_TYPE_REV_MIN 0 +/* 1 SCTP and UDPLITE support added */ +/* 2 Range as input support for IPv4 added */ +/* 3 nomatch flag support added */ +#define IPSET_TYPE_REV_MAX 4/* Counters support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" ); -IP_SET_MODULE_DESC ("hash:ip,port,net" ,REVISION_MIN ,REVISION_MAX ); +IP_SET_MODULE_DESC ("hash:ip,port,net" ,IPSET_TYPE_REV_MIN ,IPSET_TYPE_REV_MAX );MODULE_ALIAS ("ip_set_hash:ip,port,net" );/* Type specific function prefix */
@@ -574,8 +574,8 @@ static struct ip_set_type hash_ipportnet_type __read_mostly = { IPSET_TYPE_NOMATCH, .dimension = IPSET_DIM_THREE, .family = NFPROTO_UNSPEC, - .revision_min = REVISION_MIN, - .revision_max = REVISION_MAX, + .revision_min = IPSET_TYPE_REV_MIN, + .revision_max = IPSET_TYPE_REV_MAX, .create = hash_ipportnet_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_net.c +7 -7
@@ -22,14 +22,14 @@#include <linux/netfilter/ipset/ip_set.h> #include <linux/netfilter/ipset/ip_set_hash.h> -#define REVISION_MIN 0 -/* 1 Range as input support for IPv4 added */ -/* 2 nomatch flag support added */ -#define REVISION_MAX 3/* Counters support added */ +#define IPSET_TYPE_REV_MIN 0 +/* 1 Range as input support for IPv4 added */ +/* 2 nomatch flag support added */ +#define IPSET_TYPE_REV_MAX 3/* Counters support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" ); -IP_SET_MODULE_DESC ("hash:net" ,REVISION_MIN ,REVISION_MAX ); +IP_SET_MODULE_DESC ("hash:net" ,IPSET_TYPE_REV_MIN ,IPSET_TYPE_REV_MAX );MODULE_ALIAS ("ip_set_hash:net" );/* Type specific function prefix */
@@ -406,8 +406,8 @@ static struct ip_set_type hash_net_type __read_mostly = { .features = IPSET_TYPE_IP | IPSET_TYPE_NOMATCH, .dimension = IPSET_DIM_ONE, .family = NFPROTO_UNSPEC, - .revision_min = REVISION_MIN, - .revision_max = REVISION_MAX, + .revision_min = IPSET_TYPE_REV_MIN, + .revision_max = IPSET_TYPE_REV_MAX, .create = hash_net_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_netiface.c +7 -7
@@ -23,14 +23,14 @@#include <linux/netfilter/ipset/ip_set.h> #include <linux/netfilter/ipset/ip_set_hash.h> -#define REVISION_MIN 0 -/* 1 nomatch flag support added */ -/* 2 /0 support added */ -#define REVISION_MAX 3/* Counters support added */ +#define IPSET_TYPE_REV_MIN 0 +/* 1 nomatch flag support added */ +/* 2 /0 support added */ +#define IPSET_TYPE_REV_MAX 3/* Counters support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" ); -IP_SET_MODULE_DESC ("hash:net,iface" ,REVISION_MIN ,REVISION_MAX ); +IP_SET_MODULE_DESC ("hash:net,iface" ,IPSET_TYPE_REV_MIN ,IPSET_TYPE_REV_MAX );MODULE_ALIAS ("ip_set_hash:net,iface" );/* Interface name rbtree */
@@ -645,8 +645,8 @@ static struct ip_set_type hash_netiface_type __read_mostly = { IPSET_TYPE_NOMATCH, .dimension = IPSET_DIM_TWO, .family = NFPROTO_UNSPEC, - .revision_min = REVISION_MIN, - .revision_max = REVISION_MAX, + .revision_min = IPSET_TYPE_REV_MIN, + .revision_max = IPSET_TYPE_REV_MAX, .create = hash_netiface_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_netport.c +8 -8
@@ -23,15 +23,15 @@#include <linux/netfilter/ipset/ip_set_getport.h> #include <linux/netfilter/ipset/ip_set_hash.h> -#define REVISION_MIN 0 -/* 1 SCTP and UDPLITE support added */ -/* 2 Range as input support for IPv4 added */ -/* 3 nomatch flag support added */ -#define REVISION_MAX 4/* Counters support added */ +#define IPSET_TYPE_REV_MIN 0 +/* 1 SCTP and UDPLITE support added */ +/* 2 Range as input support for IPv4 added */ +/* 3 nomatch flag support added */ +#define IPSET_TYPE_REV_MAX 4/* Counters support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" ); -IP_SET_MODULE_DESC ("hash:net,port" ,REVISION_MIN ,REVISION_MAX ); +IP_SET_MODULE_DESC ("hash:net,port" ,IPSET_TYPE_REV_MIN ,IPSET_TYPE_REV_MAX );MODULE_ALIAS ("ip_set_hash:net,port" );/* Type specific function prefix */
@@ -518,8 +518,8 @@ static struct ip_set_type hash_netport_type __read_mostly = { .features = IPSET_TYPE_IP | IPSET_TYPE_PORT | IPSET_TYPE_NOMATCH, .dimension = IPSET_DIM_TWO, .family = NFPROTO_UNSPEC, - .revision_min = REVISION_MIN, - .revision_max = REVISION_MAX, + .revision_min = IPSET_TYPE_REV_MIN, + .revision_max = IPSET_TYPE_REV_MAX, .create = hash_netport_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_list_set.c +5 -5
@@ -15,12 +15,12 @@#include <linux/netfilter/ipset/ip_set.h> #include <linux/netfilter/ipset/ip_set_list.h> -#define REVISION_MIN 0 -#define REVISION_MAX 1/* Counters support added */ +#define IPSET_TYPE_REV_MIN 0 +#define IPSET_TYPE_REV_MAX 1/* Counters support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" ); -IP_SET_MODULE_DESC ("list:set" ,REVISION_MIN ,REVISION_MAX ); +IP_SET_MODULE_DESC ("list:set" ,IPSET_TYPE_REV_MIN ,IPSET_TYPE_REV_MAX );MODULE_ALIAS ("ip_set_list:set" );/* Member elements */
@@ -703,8 +703,8 @@ static struct ip_set_type list_set_type __read_mostly = { .features = IPSET_TYPE_NAME | IPSET_DUMP_LAST, .dimension = IPSET_DIM_ONE, .family = NFPROTO_UNSPEC, - .revision_min = REVISION_MIN, - .revision_max = REVISION_MAX, + .revision_min = IPSET_TYPE_REV_MIN, + .revision_max = IPSET_TYPE_REV_MAX, .create = list_set_create, .create_policy = { [IPSET_ATTR_SIZE] = { .type = NLA_U32 },
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 8/33 netfilter: ipset: Fix "may be used uninitialized" warnings
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
--- net/netfilter/ipset/ip_set_bitmap_ip.c | 4 ++-- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 4 ++-- net/netfilter/ipset/ip_set_hash_ip.c | 2 +- net/netfilter/ipset/ip_set_hash_ipport.c | 2 +- net/netfilter/ipset/ip_set_hash_ipportip.c | 2 +- net/netfilter/ipset/ip_set_hash_ipportnet.c | 4 ++-- net/netfilter/ipset/ip_set_hash_net.c | 2 +- net/netfilter/ipset/ip_set_hash_netiface.c | 2 +- net/netfilter/ipset/ip_set_hash_netport.c | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-)
net/netfilter/ipset/ip_set_bitmap_ip.c +2 -2
@@ -131,7 +131,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, ip_to; +u32 ip =0 , ip_to =0 ;struct bitmap_ip_adt_elem e = { };struct ip_set_ext ext =IP_SET_INIT_UEXT (map);int ret =0 ;
@@ -264,7 +264,7 @@ static int bitmap_ip_create(struct ip_set *set, struct nlattr *tb[], u32 flags) { struct bitmap_ip *map; -u32 first_ip, last_ip, hosts, cadt_flags =0 ; +u32 first_ip =0 , last_ip =0 , hosts, cadt_flags =0 ;u64 elements;u8 netmask =32 ;int ret;
net/netfilter/ipset/ip_set_bitmap_ipmac.c +2 -2
@@ -246,7 +246,7 @@ bitmap_ipmac_uadt(struct ip_set *set, struct nlattr *tb[],ipset_adtfn adtfn = set->variant->adt[adt];struct bitmap_ipmac_adt_elem e = {};struct ip_set_ext ext =IP_SET_INIT_UEXT (map); -u32 ip; +u32 ip =0 ;int ret =0 ; if (unlikely(!tb[IPSET_ATTR_IP] ||
@@ -355,7 +355,7 @@ static int bitmap_ipmac_create(struct ip_set *set, struct nlattr *tb[], u32 flags) { - u32 first_ip, last_ip, cadt_flags = 0; + u32 first_ip = 0, last_ip = 0, cadt_flags = 0;u64 elements;struct bitmap_ipmac *map;int ret;
net/netfilter/ipset/ip_set_hash_ip.c +1 -1
@@ -119,7 +119,7 @@ hash_ip4_uadt(struct ip_set *set, struct nlattr *tb[],ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ip4_elem e = {};struct ip_set_ext ext =IP_SET_INIT_UEXT (h); -u32 ip, ip_to, hosts; +u32 ip =0 , ip_to =0 , hosts;int ret =0 ; if (unlikely(!tb[IPSET_ATTR_IP] ||
net/netfilter/ipset/ip_set_hash_ipport.c +1 -1
@@ -137,7 +137,7 @@ hash_ipport4_uadt(struct ip_set *set, struct nlattr *tb[],ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipport4_elem e = { };struct ip_set_ext ext =IP_SET_INIT_UEXT (h); -u32 ip, ip_to, p =0 , port, port_to; +u32 ip, ip_to =0 , p =0 , port, port_to;bool with_ports = false;int ret;
net/netfilter/ipset/ip_set_hash_ipportip.c +1 -1
@@ -142,7 +142,7 @@ hash_ipportip4_uadt(struct ip_set *set, struct nlattr *tb[],ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipportip4_elem e = { };struct ip_set_ext ext =IP_SET_INIT_UEXT (h); -u32 ip, ip_to, p =0 , port, port_to; +u32 ip, ip_to =0 , p =0 , port, port_to;bool with_ports = false;int ret;
net/netfilter/ipset/ip_set_hash_ipportnet.c +2 -2
@@ -196,8 +196,8 @@ hash_ipportnet4_uadt(struct ip_set *set, struct nlattr *tb[],ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipportnet4_elem e = { .cidr =HOST_MASK -1 };struct ip_set_ext ext =IP_SET_INIT_UEXT (h); -u32 ip, ip_to, p =0 , port, port_to; -u32 ip2_from, ip2_to, ip2_last, ip2; +u32 ip =0 , ip_to =0 , p =0 , port, port_to; +u32 ip2_from =0 , ip2_to =0 , ip2_last, ip2;bool with_ports = false;u8 cidr;int ret;
net/netfilter/ipset/ip_set_hash_net.c +1 -1
@@ -166,7 +166,7 @@ hash_net4_uadt(struct ip_set *set, struct nlattr *tb[],ipset_adtfn adtfn = set->variant->adt[adt];struct hash_net4_elem e = { .cidr =HOST_MASK };struct ip_set_ext ext =IP_SET_INIT_UEXT (h); -u32 ip =0 , ip_to, last; +u32 ip =0 , ip_to =0 , last;int ret; if (unlikely(!tb[IPSET_ATTR_IP] ||
net/netfilter/ipset/ip_set_hash_netiface.c +1 -1
@@ -320,7 +320,7 @@ hash_netiface4_uadt(struct ip_set *set, struct nlattr *tb[],ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netiface4_elem e = { .cidr =HOST_MASK , .elem =1 };struct ip_set_ext ext =IP_SET_INIT_UEXT (h); -u32 ip =0 , ip_to, last; +u32 ip =0 , ip_to =0 , last;char iface[IFNAMSIZ ];int ret;
net/netfilter/ipset/ip_set_hash_netport.c +1 -1
@@ -187,7 +187,7 @@ hash_netport4_uadt(struct ip_set *set, struct nlattr *tb[],ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netport4_elem e = { .cidr =HOST_MASK -1 };struct ip_set_ext ext =IP_SET_INIT_UEXT (h); -u32 port, port_to, p =0 , ip =0 , ip_to, last; +u32 port, port_to, p =0 , ip =0 , ip_to =0 , last;bool with_ports = false;u8 cidr;int ret;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 9/33 netfilter: ipset: Use fix sized type for timeout in the extension part
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
--- include/linux/netfilter/ipset/ip_set.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/netfilter/ipset/ip_set.h +1 -1
@@ -67,7 +67,7 @@ enum ip_set_offset {#define SET_WITH_COUNTER (s) ((s)->extensions & IPSET_EXT_COUNTER)struct ip_set_ext { -unsigned long timeout; +u32 timeout;u64 packets;u64 bytes; };
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 10/33 netfilter: ipset: Support package fragments for IPv4 protos without ports
In reply to Pablo Neira AyusoFrom: "Anders K. Pedersen" <[email protected]>
Enable ipset port set types to match IPv4 package fragments for protocols that doesn't have ports (or the port information isn't supported by ipset).
For example this allows a hash:ip,port ipset containing the entry 192.168.0.1,gre:0 to match all package fragments for PPTP VPN tunnels to/from the host. Without this patch only the first package fragment (with fragment offset 0) was matched, while subsequent fragments wasn't.
This is not possible for IPv6, where the protocol is in the fragmented part of the package unlike IPv4, where the protocol is in the IP header.
IPPROTO_ICMPV6 is deliberately not included, because it isn't relevant for IPv4.
--- net/netfilter/ipset/ip_set_getport.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
net/netfilter/ipset/ip_set_getport.c +17 -1
@@ -102,9 +102,25 @@ ip_set_get_ip4_port(const struct sk_buff *skb, bool src,int protocol = iph->protocol;/* See comments at tcp_match in ip_tables.c */ -if (protocol <=0 || (ntohs (iph->frag_off) &IP_OFFSET )) +if (protocol <=0 )return false; +if (ntohs (iph->frag_off) &IP_OFFSET ) +switch (protocol) { +case IPPROTO_TCP : +case IPPROTO_SCTP : +case IPPROTO_UDP : +case IPPROTO_UDPLITE : +case IPPROTO_ICMP : +/* Port info not available for fragment offset > 0 */ +return false; +default : +/* Other protocols doesn't have ports, +so we can match fragments */ + *proto = protocol; +return true; + } +return get_port (skb, protocol, protooff, src, port, proto); }EXPORT_SYMBOL_GPL (ip_set_get_ip4_port);
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 11/33 netfilter: ipset: order matches and targets separatedly in xt_set.c
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
--- net/netfilter/xt_set.c | 188 ++++++++++++++++++++++++------------------------ 1 file changed, 96 insertions(+), 92 deletions(-)
net/netfilter/xt_set.c +96 -92
@@ -109,6 +109,101 @@ set_match_v0_destroy(const struct xt_mtdtor_param *par)ip_set_nfnl_put (info->match_set.index); } +/* Revision 1 match */ + +static bool +set_match_v1 (const struct sk_buff *skb,struct xt_action_param *par) +{ +const struct xt_set_info_match_v1 *info = par->matchinfo; +ADT_OPT (opt, par->family, info->match_set.dim, + info->match_set.flags,0 ,UINT_MAX ); + +if (opt.flags &IPSET_RETURN_NOMATCH ) + opt.cmdflags |=IPSET_FLAG_RETURN_NOMATCH ; + +return match_set (info->match_set.index, skb, par, &opt, + info->match_set.flags &IPSET_INV_MATCH ); +} + +static int +set_match_v1_checkentry (const struct xt_mtchk_param *par) +{ +struct xt_set_info_match_v1 *info = par->matchinfo; +ip_set_id_t index; + + index =ip_set_nfnl_get_byindex (info->match_set.index); + +if (index ==IPSET_INVALID_ID ) { +pr_warning ("Cannot find set indentified by id %u to match\n" , + info->match_set.index); +return -ENOENT ; + } +if (info->match_set.dim >IPSET_DIM_MAX ) { +pr_warning ("Protocol error: set match dimension " +"is over the limit!\n" ); +ip_set_nfnl_put (info->match_set.index); +return -ERANGE ; + } + +return 0 ; +} + +static void +set_match_v1_destroy (const struct xt_mtdtor_param *par) +{ +struct xt_set_info_match_v1 *info = par->matchinfo; + +ip_set_nfnl_put (info->match_set.index); +} + +/* Revision 3 match */ + +static bool +match_counter (u64 counter,const struct ip_set_counter_match *info) +{ +switch (info->op) { +case IPSET_COUNTER_NONE : +return true; +case IPSET_COUNTER_EQ : +return counter == info->value; +case IPSET_COUNTER_NE : +return counter != info->value; +case IPSET_COUNTER_LT : +return counter < info->value; +case IPSET_COUNTER_GT : +return counter > info->value; + } +return false; +} + +static bool +set_match_v3 (const struct sk_buff *skb,struct xt_action_param *par) +{ +const struct xt_set_info_match_v3 *info = par->matchinfo; +ADT_OPT (opt, par->family, info->match_set.dim, + info->match_set.flags, info->flags,UINT_MAX ); +int ret; + +if (info->packets.op !=IPSET_COUNTER_NONE || + info->bytes.op !=IPSET_COUNTER_NONE ) + opt.cmdflags |=IPSET_FLAG_MATCH_COUNTERS ; + + ret =match_set (info->match_set.index, skb, par, &opt, + info->match_set.flags &IPSET_INV_MATCH ); + +if (!(ret && opt.cmdflags &IPSET_FLAG_MATCH_COUNTERS )) +return ret; + +if (!match_counter (opt.ext.packets, &info->packets)) +return 0 ; +return match_counter (opt.ext.bytes, &info->bytes); +} + +#define set_match_v3_checkentry set_match_v1_checkentry +#define set_match_v3_destroy set_match_v1_destroy + +/* Revision 0 interface: backward compatible with netfilter/iptables */ +static unsigned int set_target_v0 (struct sk_buff *skb,const struct xt_action_param *par) {
@@ -180,52 +275,7 @@ set_target_v0_destroy(const struct xt_tgdtor_param *par)ip_set_nfnl_put (info->del_set.index); } -/* Revision 1 match and target */ - -static bool -set_match_v1 (const struct sk_buff *skb,struct xt_action_param *par) -{ -const struct xt_set_info_match_v1 *info = par->matchinfo; -ADT_OPT (opt, par->family, info->match_set.dim, - info->match_set.flags,0 ,UINT_MAX ); - -if (opt.flags &IPSET_RETURN_NOMATCH ) - opt.cmdflags |=IPSET_FLAG_RETURN_NOMATCH ; - -return match_set (info->match_set.index, skb, par, &opt, - info->match_set.flags &IPSET_INV_MATCH ); -} - -static int -set_match_v1_checkentry (const struct xt_mtchk_param *par) -{ -struct xt_set_info_match_v1 *info = par->matchinfo; -ip_set_id_t index; - - index =ip_set_nfnl_get_byindex (info->match_set.index); - -if (index ==IPSET_INVALID_ID ) { -pr_warning ("Cannot find set indentified by id %u to match\n" , - info->match_set.index); -return -ENOENT ; - } -if (info->match_set.dim >IPSET_DIM_MAX ) { -pr_warning ("Protocol error: set match dimension " -"is over the limit!\n" ); -ip_set_nfnl_put (info->match_set.index); -return -ERANGE ; - } - -return 0 ; -} - -static void -set_match_v1_destroy (const struct xt_mtdtor_param *par) -{ -struct xt_set_info_match_v1 *info = par->matchinfo; - -ip_set_nfnl_put (info->match_set.index); -} +/* Revision 1 target */ static unsigned int set_target_v1 (struct sk_buff *skb,const struct xt_action_param *par)
@@ -320,52 +370,6 @@ set_target_v2(struct sk_buff *skb, const struct xt_action_param *par)#define set_target_v2_checkentry set_target_v1_checkentry#define set_target_v2_destroy set_target_v1_destroy -/* Revision 3 match */ - -static bool -match_counter (u64 counter,const struct ip_set_counter_match *info) -{ -switch (info->op) { -case IPSET_COUNTER_NONE : -return true; -case IPSET_COUNTER_EQ : -return counter == info->value; -case IPSET_COUNTER_NE : -return counter != info->value; -case IPSET_COUNTER_LT : -return counter < info->value; -case IPSET_COUNTER_GT : -return counter > info->value; - } -return false; -} - -static bool -set_match_v3 (const struct sk_buff *skb,struct xt_action_param *par) -{ -const struct xt_set_info_match_v3 *info = par->matchinfo; -ADT_OPT (opt, par->family, info->match_set.dim, - info->match_set.flags, info->flags,UINT_MAX ); -int ret; - -if (info->packets.op !=IPSET_COUNTER_NONE || - info->bytes.op !=IPSET_COUNTER_NONE ) - opt.cmdflags |=IPSET_FLAG_MATCH_COUNTERS ; - - ret =match_set (info->match_set.index, skb, par, &opt, - info->match_set.flags &IPSET_INV_MATCH ); - -if (!(ret && opt.cmdflags &IPSET_FLAG_MATCH_COUNTERS )) -return ret; - -if (!match_counter (opt.ext.packets, &info->packets)) -return 0 ; -return match_counter (opt.ext.bytes, &info->bytes); -} - -#define set_match_v3_checkentry set_match_v1_checkentry -#define set_match_v3_destroy set_match_v1_destroy -static struct xt_match set_matches[]__read_mostly = { { .name ="set" ,
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 12/33 netfilter: ipset: Introduce new operation to get both setname and family
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
ip[6]tables set match and SET target need to know the family of the set in order to reject adding rules which refer to a set with a non-mathcing family. Currently such rules are silently accepted and then ignored instead of generating a clear error message to the user, which is not helpful.
--- include/uapi/linux/netfilter/ipset/ip_set.h | 8 ++++++++ net/netfilter/ipset/ip_set_core.c | 17 +++++++++++++++++ 2 files changed, 25 insertions(+)
include/uapi/linux/netfilter/ipset/ip_set.h +8 -0
@@ -250,6 +250,14 @@ struct ip_set_req_get_set {#define IP_SET_OP_GET_BYINDEX 0x00000007/* Get set name by index */ /* Uses ip_set_req_get_set */ +#define IP_SET_OP_GET_FNAME 0x00000008/* Get set index and family */ +struct ip_set_req_get_set_family { +unsigned int op; +unsigned int version; +unsigned int family; +union ip_set_name_index set; +}; +#define IP_SET_OP_VERSION 0x00000100/* Ask kernel version */ struct ip_set_req_version {unsigned int op;
net/netfilter/ipset/ip_set_core.c +17 -0
@@ -1788,6 +1788,23 @@ ip_set_sockfn_get(struct sock *sk, int optval, void __user *user, int *len)nfnl_unlock (NFNL_SUBSYS_IPSET ); goto copy; } +case IP_SET_OP_GET_FNAME : { +struct ip_set_req_get_set_family *req_get = data; +ip_set_id_t id; + +if (*len !=sizeof (struct ip_set_req_get_set_family )) { + ret = -EINVAL ; + goto done; + } + req_get->set.name[IPSET_MAXNAMELEN -1 ] ='\0' ; +nfnl_lock (NFNL_SUBSYS_IPSET ); +find_set_and_id (req_get->set.name, &id); + req_get->set.index = id; +if (id !=IPSET_INVALID_ID ) + req_get->family =nfnl_set (id)->family; +nfnl_unlock (NFNL_SUBSYS_IPSET ); + goto copy; + }case IP_SET_OP_GET_BYINDEX : {struct ip_set_req_get_set *req_get = data;struct ip_set *set;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 13/33 netfilter: ipset: Prepare ipset to support multiple networks for hash types
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
In order to support hash:net,net, hash:net,port,net etc. types, arrays are introduced for the book-keeping of existing cidr sizes and network numbers in a set.
--- include/linux/netfilter/ipset/ip_set.h | 2 + net/netfilter/ipset/ip_set_hash_gen.h | 78 ++++++++++++++------------- net/netfilter/ipset/ip_set_hash_ipportnet.c | 4 +- net/netfilter/ipset/ip_set_hash_net.c | 4 +- net/netfilter/ipset/ip_set_hash_netiface.c | 4 +- net/netfilter/ipset/ip_set_hash_netport.c | 4 +- 6 files changed, 50 insertions(+), 46 deletions(-)
include/linux/netfilter/ipset/ip_set.h +2 -0
@@ -398,6 +398,8 @@ bitmap_bytes(u32 a, u32 b) { .bytes = ULLONG_MAX, .packets = ULLONG_MAX, \ .timeout = (map)->timeout } +#define IP_SET_INIT_CIDR (a, b) ((a) ? (a) : (b)) +#define IPSET_CONCAT (a, b) a##b#define IPSET_TOKEN (a, b) IPSET_CONCAT(a, b)
net/netfilter/ipset/ip_set_hash_gen.h +40 -38
189 lines not on this page · raw message
net/netfilter/ipset/ip_set_hash_ipportnet.c +2 -2
@@ -170,7 +170,7 @@ hash_ipportnet4_kadt(struct ip_set *set, const struct sk_buff *skb,const struct hash_ipportnet *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipportnet4_elem e = { - .cidr = h->nets[0 ].cidr ? h->nets[0 ].cidr -1 :HOST_MASK -1 + .cidr =IP_SET_INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ) -1 , };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, h);
@@ -454,7 +454,7 @@ hash_ipportnet6_kadt(struct ip_set *set, const struct sk_buff *skb,const struct hash_ipportnet *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipportnet6_elem e = { - .cidr = h->nets[0 ].cidr ? h->nets[0 ].cidr -1 :HOST_MASK -1 + .cidr =IP_SET_INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ) -1 , };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, h);
net/netfilter/ipset/ip_set_hash_net.c +2 -2
@@ -143,7 +143,7 @@ hash_net4_kadt(struct ip_set *set, const struct sk_buff *skb,const struct hash_net *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_net4_elem e = { - .cidr = h->nets[0 ].cidr ? h->nets[0 ].cidr :HOST_MASK + .cidr =IP_SET_INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ), };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, h);
@@ -338,7 +338,7 @@ hash_net6_kadt(struct ip_set *set, const struct sk_buff *skb,const struct hash_net *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_net6_elem e = { - .cidr = h->nets[0 ].cidr ? h->nets[0 ].cidr :HOST_MASK + .cidr =IP_SET_INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ), };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, h);
net/netfilter/ipset/ip_set_hash_netiface.c +2 -2
@@ -265,7 +265,7 @@ hash_netiface4_kadt(struct ip_set *set, const struct sk_buff *skb,struct hash_netiface *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netiface4_elem e = { - .cidr = h->nets[0 ].cidr ? h->nets[0 ].cidr :HOST_MASK , + .cidr =IP_SET_INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ), .elem =1 , };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, h);
@@ -534,7 +534,7 @@ hash_netiface6_kadt(struct ip_set *set, const struct sk_buff *skb,struct hash_netiface *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netiface6_elem e = { - .cidr = h->nets[0 ].cidr ? h->nets[0 ].cidr :HOST_MASK , + .cidr =IP_SET_INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ), .elem =1 , };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, h);
net/netfilter/ipset/ip_set_hash_netport.c +2 -2
@@ -162,7 +162,7 @@ hash_netport4_kadt(struct ip_set *set, const struct sk_buff *skb,const struct hash_netport *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netport4_elem e = { - .cidr = h->nets[0 ].cidr ? h->nets[0 ].cidr -1 :HOST_MASK -1 + .cidr =IP_SET_INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ) -1 , };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, h);
@@ -407,7 +407,7 @@ hash_netport6_kadt(struct ip_set *set, const struct sk_buff *skb,const struct hash_netport *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netport6_elem e = { - .cidr = h->nets[0 ].cidr ? h->nets[0 ].cidr -1 :HOST_MASK -1 , + .cidr =IP_SET_INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ) -1 , };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, h);
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 14/33 netfilter: ipset: Rename extension offset ids to extension ids
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
--- include/linux/netfilter/ipset/ip_set.h | 16 ++++++++-------- net/netfilter/ipset/ip_set_bitmap_gen.h | 4 ++-- net/netfilter/ipset/ip_set_bitmap_ip.c | 10 +++++----- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 10 +++++----- net/netfilter/ipset/ip_set_bitmap_port.c | 10 +++++----- net/netfilter/ipset/ip_set_hash_gen.h | 22 +++++++++++----------- net/netfilter/ipset/ip_set_list_set.c | 14 +++++++------- 7 files changed, 43 insertions(+), 43 deletions(-)
include/linux/netfilter/ipset/ip_set.h +8 -8
@@ -56,20 +56,20 @@ enum ip_set_extension { IPSET_EXT_COUNTER = (1 << IPSET_EXT_BIT_COUNTER), }; -/* Extension offsets */ -enum ip_set_offset { -IPSET_OFFSET_TIMEOUT =0 , -IPSET_OFFSET_COUNTER , -IPSET_OFFSET_MAX , -}; -#define SET_WITH_TIMEOUT (s) ((s)->extensions & IPSET_EXT_TIMEOUT)#define SET_WITH_COUNTER (s) ((s)->extensions & IPSET_EXT_COUNTER) +/* Extension id, in size order */ +enum ip_set_ext_id { +IPSET_EXT_ID_COUNTER =0 , +IPSET_EXT_ID_TIMEOUT , +IPSET_EXT_ID_MAX , +}; +struct ip_set_ext { -u32 timeout;u64 packets;u64 bytes; +u32 timeout; };struct ip_set ;
net/netfilter/ipset/ip_set_bitmap_gen.h +2 -2
@@ -33,9 +33,9 @@#define mtype MTYPE#define ext_timeout (e, m) \ - (unsigned long *)((e) + (m)->offset[IPSET_OFFSET_TIMEOUT]) + (unsigned long *)((e) + (m)->offset[IPSET_EXT_ID_TIMEOUT])#define ext_counter (e, m) \ - (struct ip_set_counter *)((e) + (m)->offset[IPSET_OFFSET_COUNTER]) + (struct ip_set_counter *)((e) + (m)->offset[IPSET_EXT_ID_COUNTER])#define get_ext (map, id) ((map)->extensions + (map)->dsize * (id)) static void
net/netfilter/ipset/ip_set_bitmap_ip.c +5 -5
@@ -45,7 +45,7 @@ struct bitmap_ip {u32 hosts;/* number of hosts in a subnet */ size_t memsize;/* members size */ size_t dsize;/* extensions struct size */ -size_t offset[IPSET_OFFSET_MAX ];/* Offsets to extensions */ +size_t offset[IPSET_EXT_ID_MAX ];/* Offsets to extensions */ u8 netmask;/* subnet netmask */ u32 timeout;/* timeout parameter */ struct timer_list gc;/* garbage collection */
@@ -342,9 +342,9 @@ bitmap_ip_create(struct ip_set *set, struct nlattr *tb[], u32 flags) set->extensions |=IPSET_EXT_COUNTER ; if (tb[IPSET_ATTR_TIMEOUT]) { map->dsize = sizeof(struct bitmap_ipct_elem); - map->offset[IPSET_OFFSET_TIMEOUT] = + map->offset[IPSET_EXT_ID_TIMEOUT] = offsetof(struct bitmap_ipct_elem, timeout); - map->offset[IPSET_OFFSET_COUNTER] = + map->offset[IPSET_EXT_ID_COUNTER] = offsetof(struct bitmap_ipct_elem, counter); if (!init_map_ip(set, map, first_ip, last_ip,
@@ -360,7 +360,7 @@ bitmap_ip_create(struct ip_set *set, struct nlattr *tb[], u32 flags)bitmap_ip_gc_init (set, bitmap_ip_gc); } else { map->dsize = sizeof(struct bitmap_ipc_elem); - map->offset[IPSET_OFFSET_COUNTER] = + map->offset[IPSET_EXT_ID_COUNTER] = offsetof(struct bitmap_ipc_elem, counter); if (!init_map_ip(set, map, first_ip, last_ip,
@@ -371,7 +371,7 @@ bitmap_ip_create(struct ip_set *set, struct nlattr *tb[], u32 flags) } } else if (tb[IPSET_ATTR_TIMEOUT]) { map->dsize = sizeof(struct bitmap_ipt_elem); - map->offset[IPSET_OFFSET_TIMEOUT] = + map->offset[IPSET_EXT_ID_TIMEOUT] = offsetof(struct bitmap_ipt_elem, timeout); if (!init_map_ip(set, map, first_ip, last_ip,
net/netfilter/ipset/ip_set_bitmap_ipmac.c +5 -5
@@ -52,7 +52,7 @@ struct bitmap_ipmac {struct timer_list gc;/* garbage collector */ size_t memsize;/* members size */ size_t dsize;/* size of element */ -size_t offset[IPSET_OFFSET_MAX ];/* Offsets to extensions */ +size_t offset[IPSET_EXT_ID_MAX ];/* Offsets to extensions */ };/* ADT structure for generic function args */
@@ -405,9 +405,9 @@ bitmap_ipmac_create(struct ip_set *set, struct nlattr *tb[], set->extensions |=IPSET_EXT_COUNTER ; if (tb[IPSET_ATTR_TIMEOUT]) { map->dsize = sizeof(struct bitmap_ipmacct_elem); - map->offset[IPSET_OFFSET_TIMEOUT] = + map->offset[IPSET_EXT_ID_TIMEOUT] = offsetof(struct bitmap_ipmacct_elem, timeout); - map->offset[IPSET_OFFSET_COUNTER] = + map->offset[IPSET_EXT_ID_COUNTER] = offsetof(struct bitmap_ipmacct_elem, counter); if (!init_map_ipmac(set, map, first_ip, last_ip,
@@ -421,7 +421,7 @@ bitmap_ipmac_create(struct ip_set *set, struct nlattr *tb[],bitmap_ipmac_gc_init (set, bitmap_ipmac_gc); } else { map->dsize = sizeof(struct bitmap_ipmacc_elem); - map->offset[IPSET_OFFSET_COUNTER] = + map->offset[IPSET_EXT_ID_COUNTER] = offsetof(struct bitmap_ipmacc_elem, counter); if (!init_map_ipmac(set, map, first_ip, last_ip,
@@ -432,7 +432,7 @@ bitmap_ipmac_create(struct ip_set *set, struct nlattr *tb[], } }else if (tb[IPSET_ATTR_TIMEOUT ]) { map->dsize =sizeof (struct bitmap_ipmact_elem ); - map->offset[IPSET_OFFSET_TIMEOUT ] = + map->offset[IPSET_EXT_ID_TIMEOUT ] = offsetof(struct bitmap_ipmact_elem , timeout);if (!init_map_ipmac (set, map, first_ip, last_ip, elements)) {
net/netfilter/ipset/ip_set_bitmap_port.c +5 -5
@@ -39,7 +39,7 @@ struct bitmap_port {u32 elements;/* number of max elements in the set */ size_t memsize;/* members size */ size_t dsize;/* extensions struct size */ -size_t offset[IPSET_OFFSET_MAX ];/* Offsets to extensions */ +size_t offset[IPSET_EXT_ID_MAX ];/* Offsets to extensions */ u32 timeout;/* timeout parameter */ struct timer_list gc;/* garbage collection */ };
@@ -282,9 +282,9 @@ bitmap_port_create(struct ip_set *set, struct nlattr *tb[], u32 flags) set->extensions |=IPSET_EXT_COUNTER ;if (tb[IPSET_ATTR_TIMEOUT ]) { map->dsize =sizeof (struct bitmap_portct_elem ); - map->offset[IPSET_OFFSET_TIMEOUT ] = + map->offset[IPSET_EXT_ID_TIMEOUT ] = offsetof(struct bitmap_portct_elem , timeout); - map->offset[IPSET_OFFSET_COUNTER ] = + map->offset[IPSET_EXT_ID_COUNTER ] = offsetof(struct bitmap_portct_elem , counter);if (!init_map_port (set, map, first_port, last_port)) {kfree (map);
@@ -297,7 +297,7 @@ bitmap_port_create(struct ip_set *set, struct nlattr *tb[], u32 flags)bitmap_port_gc_init (set, bitmap_port_gc); }else { map->dsize =sizeof (struct bitmap_portc_elem ); - map->offset[IPSET_OFFSET_COUNTER ] = + map->offset[IPSET_EXT_ID_COUNTER ] = offsetof(struct bitmap_portc_elem , counter);if (!init_map_port (set, map, first_port, last_port)) {kfree (map);
@@ -306,7 +306,7 @@ bitmap_port_create(struct ip_set *set, struct nlattr *tb[], u32 flags) } }else if (tb[IPSET_ATTR_TIMEOUT ]) { map->dsize =sizeof (struct bitmap_portt_elem ); - map->offset[IPSET_OFFSET_TIMEOUT ] = + map->offset[IPSET_EXT_ID_TIMEOUT ] = offsetof(struct bitmap_portt_elem , timeout);if (!init_map_port (set, map, first_port, last_port)) {kfree (map);
net/netfilter/ipset/ip_set_hash_gen.h +11 -11
@@ -179,9 +179,9 @@ hbucket_elem_add(struct hbucket *n, u8 ahash_max, size_t dsize)#endif /* IP_SET_HASH_WITH_NETS */ #define ext_timeout (e, h) \ -(unsigned long *)(((void *)(e)) + (h)->offset[IPSET_OFFSET_TIMEOUT]) +(unsigned long *)(((void *)(e)) + (h)->offset[IPSET_EXT_ID_TIMEOUT])#define ext_counter (e, h) \ -(struct ip_set_counter *)(((void *)(e)) + (h)->offset[IPSET_OFFSET_COUNTER]) +(struct ip_set_counter *)(((void *)(e)) + (h)->offset[IPSET_EXT_ID_COUNTER])#endif /* _IP_SET_HASH_GEN_H */
@@ -278,7 +278,7 @@ struct htype {u32 initval;/* random jhash init value */ u32 timeout;/* timeout value, if enabled */ size_t dsize;/* data struct size */ -size_t offset[IPSET_OFFSET_MAX ];/* Offsets to extensions */ +size_t offset[IPSET_EXT_ID_MAX ];/* Offsets to extensions */ struct timer_list gc;/* garbage collection when timeout enabled */ struct mtype_elem next;/* temporary storage for uadd */ #ifdef IP_SET_HASH_WITH_MULTI
@@ -1059,11 +1059,11 @@ IPSET_TOKEN(HTYPE, _create)(struct ip_set *set, struct nlattr *tb[], u32 flags)if (set->family ==NFPROTO_IPV4 ) { h->dsize =sizeof (struct IPSET_TOKEN(HTYPE, 4ct_elem)); - h->offset[IPSET_OFFSET_TIMEOUT ] = + h->offset[IPSET_EXT_ID_TIMEOUT ] = offsetof(struct IPSET_TOKEN(HTYPE, 4ct_elem), timeout); - h->offset[IPSET_OFFSET_COUNTER ] = + h->offset[IPSET_EXT_ID_COUNTER ] = offsetof(struct IPSET_TOKEN(HTYPE, 4ct_elem), counter);
@@ -1072,11 +1072,11 @@ IPSET_TOKEN(HTYPE, _create)(struct ip_set *set, struct nlattr *tb[], u32 flags) }else { h->dsize =sizeof (struct IPSET_TOKEN(HTYPE, 6ct_elem)); - h->offset[IPSET_OFFSET_TIMEOUT ] = + h->offset[IPSET_EXT_ID_TIMEOUT ] = offsetof(struct IPSET_TOKEN(HTYPE, 6ct_elem), timeout); - h->offset[IPSET_OFFSET_COUNTER ] = + h->offset[IPSET_EXT_ID_COUNTER ] = offsetof(struct IPSET_TOKEN(HTYPE, 6ct_elem), counter);
@@ -1088,7 +1088,7 @@ IPSET_TOKEN(HTYPE, _create)(struct ip_set *set, struct nlattr *tb[], u32 flags) h->dsize =sizeof (struct IPSET_TOKEN(HTYPE, 4c_elem)); - h->offset[IPSET_OFFSET_COUNTER ] = + h->offset[IPSET_EXT_ID_COUNTER ] = offsetof(struct IPSET_TOKEN(HTYPE, 4c_elem), counter);
@@ -1096,7 +1096,7 @@ IPSET_TOKEN(HTYPE, _create)(struct ip_set *set, struct nlattr *tb[], u32 flags) h->dsize =sizeof (struct IPSET_TOKEN(HTYPE, 6c_elem)); - h->offset[IPSET_OFFSET_COUNTER ] = + h->offset[IPSET_EXT_ID_COUNTER ] = offsetof(struct IPSET_TOKEN(HTYPE, 6c_elem), counter);
@@ -1107,14 +1107,14 @@ IPSET_TOKEN(HTYPE, _create)(struct ip_set *set, struct nlattr *tb[], u32 flags) set->extensions |=IPSET_EXT_TIMEOUT ;if (set->family ==NFPROTO_IPV4 ) { h->dsize = sizeof(struct IPSET_TOKEN(HTYPE, 4t_elem)); - h->offset[IPSET_OFFSET_TIMEOUT ] = + h->offset[IPSET_EXT_ID_TIMEOUT ] = offsetof(struct IPSET_TOKEN(HTYPE, 4t_elem), timeout); IPSET_TOKEN(HTYPE, 4_gc_init)(set, IPSET_TOKEN(HTYPE, 4_gc)); }else { h->dsize = sizeof(struct IPSET_TOKEN(HTYPE, 6t_elem)); - h->offset[IPSET_OFFSET_TIMEOUT ] = + h->offset[IPSET_EXT_ID_TIMEOUT ] = offsetof(struct IPSET_TOKEN(HTYPE, 6t_elem), timeout); IPSET_TOKEN(HTYPE, 6_gc_init)(set,
net/netfilter/ipset/ip_set_list_set.c +7 -7
@@ -59,7 +59,7 @@ struct set_adt_elem {/* Type structure */ struct list_set {size_t dsize;/* element size */ -size_t offset[IPSET_OFFSET_MAX ];/* Offsets to extensions */ +size_t offset[IPSET_EXT_ID_MAX ];/* Offsets to extensions */ u32 size;/* size of set list array */ u32 timeout;/* timeout value */ struct timer_list gc;/* garbage collection */
@@ -73,9 +73,9 @@ list_set_elem(const struct list_set *map, u32 id) }#define ext_timeout (e, m) \ -(unsigned long *)((void *)(e) + (m)->offset[IPSET_OFFSET_TIMEOUT]) +(unsigned long *)((void *)(e) + (m)->offset[IPSET_EXT_ID_TIMEOUT])#define ext_counter (e, m) \ -(struct ip_set_counter *)((void *)(e) + (m)->offset[IPSET_OFFSET_COUNTER]) +(struct ip_set_counter *)((void *)(e) + (m)->offset[IPSET_EXT_ID_COUNTER]) static int list_set_ktest(struct ip_set *set, const struct sk_buff *skb,
@@ -667,9 +667,9 @@ list_set_create(struct ip_set *set, struct nlattr *tb[], u32 flags)if (!map)return -ENOMEM ; set->extensions |=IPSET_EXT_TIMEOUT ; - map->offset[IPSET_OFFSET_TIMEOUT ] = + map->offset[IPSET_EXT_ID_TIMEOUT ] = offsetof(struct setct_elem , timeout); - map->offset[IPSET_OFFSET_COUNTER ] = + map->offset[IPSET_EXT_ID_COUNTER ] = offsetof(struct setct_elem , counter);list_set_gc_init (set, list_set_gc); }else {
@@ -677,7 +677,7 @@ list_set_create(struct ip_set *set, struct nlattr *tb[], u32 flags) sizeof(struct setc_elem), 0);if (!map)return -ENOMEM ; - map->offset[IPSET_OFFSET_COUNTER ] = + map->offset[IPSET_EXT_ID_COUNTER ] = offsetof(struct setc_elem , counter); } }else if (tb[IPSET_ATTR_TIMEOUT ]) {
@@ -686,7 +686,7 @@ list_set_create(struct ip_set *set, struct nlattr *tb[], u32 flags)if (!map)return -ENOMEM ; set->extensions |=IPSET_EXT_TIMEOUT ; - map->offset[IPSET_OFFSET_TIMEOUT ] = + map->offset[IPSET_EXT_ID_TIMEOUT ] = offsetof(struct sett_elem , timeout);list_set_gc_init (set, list_set_gc); }else {
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 15/33 netfilter: ipset: Move extension data to set structure
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
Default timeout and extension offsets are moved to struct set, because all set types supports all extensions and it makes possible to generalize extension support.
--- include/linux/netfilter/ipset/ip_set.h | 29 ++++-- include/linux/netfilter/ipset/ip_set_timeout.h | 4 +- net/netfilter/ipset/ip_set_bitmap_gen.h | 59 ++++++----- net/netfilter/ipset/ip_set_bitmap_ip.c | 45 ++++----- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 64 ++++++------ net/netfilter/ipset/ip_set_bitmap_port.c | 44 ++++---- net/netfilter/ipset/ip_set_hash_gen.h | 127 +++++++++++------------- net/netfilter/ipset/ip_set_hash_ip.c | 8 +- net/netfilter/ipset/ip_set_hash_ipport.c | 10 +- net/netfilter/ipset/ip_set_hash_ipportip.c | 10 +- net/netfilter/ipset/ip_set_hash_ipportnet.c | 14 +-- net/netfilter/ipset/ip_set_hash_net.c | 9 +- net/netfilter/ipset/ip_set_hash_netiface.c | 8 +- net/netfilter/ipset/ip_set_hash_netport.c | 8 +- net/netfilter/ipset/ip_set_list_set.c | 116 ++++++++++------------ 15 files changed, 266 insertions(+), 289 deletions(-)
include/linux/netfilter/ipset/ip_set.h +20 -9
@@ -72,6 +72,16 @@ struct ip_set_ext {u32 timeout; }; +struct ip_set_counter { +atomic64_t bytes; +atomic64_t packets; +}; + +#define ext_timeout (e, s) \ +(unsigned long *)(((void *)(e)) + (s)->offset[IPSET_EXT_ID_TIMEOUT]) +#define ext_counter (e, s) \ +(struct ip_set_counter *)(((void *)(e)) + (s)->offset[IPSET_EXT_ID_COUNTER]) +struct ip_set ; typedef int (*ipset_adtfn)(struct ip_set *set, void *value,
@@ -179,15 +189,16 @@ struct ip_set {u8 revision;/* Extensions */ u8 extensions; +/* Default timeout value, if enabled */ +u32 timeout; +/* Element data size */ +size_t dsize; +/* Offsets to extensions in elements */ +size_t offset[IPSET_EXT_ID_MAX ];/* The type specific data */ void *data; }; -struct ip_set_counter { -atomic64_t bytes; -atomic64_t packets; -}; -static inline void ip_set_add_bytes (u64 bytes,struct ip_set_counter *counter) {
@@ -390,13 +401,13 @@ bitmap_bytes(u32 a, u32 b)#include <linux/netfilter/ipset/ip_set_timeout.h> -#define IP_SET_INIT_KEXT (skb, opt, map) \ +#define IP_SET_INIT_KEXT (skb, opt, set) \ { .bytes = (skb)->len, .packets = 1, \ - .timeout = ip_set_adt_opt_timeout(opt, map) } + .timeout = ip_set_adt_opt_timeout(opt, set) } -#define IP_SET_INIT_UEXT (map) \ +#define IP_SET_INIT_UEXT (set) \ { .bytes = ULLONG_MAX, .packets = ULLONG_MAX, \ - .timeout = (map)->timeout } + .timeout = (set)->timeout }#define IP_SET_INIT_CIDR (a, b) ((a) ? (a) : (b))
include/linux/netfilter/ipset/ip_set_timeout.h +2 -2
@@ -23,8 +23,8 @@/* Set is defined with timeout support: timeout value may be 0 */ #define IPSET_NO_TIMEOUT UINT_MAX -#define ip_set_adt_opt_timeout (opt, map) \ -((opt)->ext.timeout != IPSET_NO_TIMEOUT ? (opt)->ext.timeout : (map)->timeout) +#define ip_set_adt_opt_timeout (opt, set) \ +((opt)->ext.timeout != IPSET_NO_TIMEOUT ? (opt)->ext.timeout : (set)->timeout)static inline unsigned int ip_set_timeout_uget (struct nlattr *tb)
net/netfilter/ipset/ip_set_bitmap_gen.h +28 -31
164 lines not on this page · raw message
net/netfilter/ipset/ip_set_bitmap_ip.c +22 -23
139 lines not on this page · raw message
net/netfilter/ipset/ip_set_bitmap_ipmac.c +31 -33
193 lines not on this page · raw message
net/netfilter/ipset/ip_set_bitmap_port.c +21 -23
135 lines not on this page · raw message
net/netfilter/ipset/ip_set_hash_gen.h +59 -68
391 lines not on this page · raw message
net/netfilter/ipset/ip_set_hash_ip.c +4 -4
@@ -99,7 +99,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 ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, h); +struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);__be32 ip;ip4addrptr (skb, opt->flags &IPSET_DIM_ONE_SRC , &ip);
@@ -118,7 +118,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 ip_set_ext ext =IP_SET_INIT_UEXT (h); +struct ip_set_ext ext =IP_SET_INIT_UEXT (set);u32 ip =0 , ip_to =0 , hosts;int ret =0 ;
@@ -253,7 +253,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 ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, h); +struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);ip6addrptr (skb, opt->flags &IPSET_DIM_ONE_SRC , &e.ip.in6);hash_ip6_netmask (&e.ip, h->netmask);
@@ -270,7 +270,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 ip_set_ext ext =IP_SET_INIT_UEXT (h); +struct ip_set_ext ext =IP_SET_INIT_UEXT (set);int ret; if (unlikely(!tb[IPSET_ATTR_IP] ||
net/netfilter/ipset/ip_set_hash_ipport.c +4 -6
@@ -116,10 +116,9 @@ hash_ipport4_kadt(struct ip_set *set, const struct sk_buff *skb,const struct xt_action_param *par, enum ipset_adt adt, struct ip_set_adt_opt *opt) { - const struct hash_ipport *h = set->data; ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipport4_elem e = { }; -struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, h); +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 , &e.port, &e.proto))
@@ -136,7 +135,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 ip_set_ext ext =IP_SET_INIT_UEXT (h); +struct ip_set_ext ext =IP_SET_INIT_UEXT (set);u32 ip, ip_to =0 , p =0 , port, port_to;bool with_ports = false;int ret;
@@ -306,10 +305,9 @@ hash_ipport6_kadt(struct ip_set *set, const struct sk_buff *skb,const struct xt_action_param *par, enum ipset_adt adt, struct ip_set_adt_opt *opt) { - const struct hash_ipport *h = set->data; ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipport6_elem e = { }; -struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, h); +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 , &e.port, &e.proto))
@@ -326,7 +324,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 ip_set_ext ext =IP_SET_INIT_UEXT (h); +struct ip_set_ext ext =IP_SET_INIT_UEXT (set);u32 port, port_to;bool with_ports = false;int ret;
net/netfilter/ipset/ip_set_hash_ipportip.c +4 -6
@@ -120,10 +120,9 @@ hash_ipportip4_kadt(struct ip_set *set, const struct sk_buff *skb,const struct xt_action_param *par, enum ipset_adt adt, struct ip_set_adt_opt *opt) { - const struct hash_ipportip *h = set->data; ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipportip4_elem e = { }; -struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, h); +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 , &e.port, &e.proto))
@@ -141,7 +140,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 ip_set_ext ext =IP_SET_INIT_UEXT (h); +struct ip_set_ext ext =IP_SET_INIT_UEXT (set);u32 ip, ip_to =0 , p =0 , port, port_to;bool with_ports = false;int ret;
@@ -319,10 +318,9 @@ hash_ipportip6_kadt(struct ip_set *set, const struct sk_buff *skb,const struct xt_action_param *par, enum ipset_adt adt, struct ip_set_adt_opt *opt) { - const struct hash_ipportip *h = set->data; ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipportip6_elem e = { }; -struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, h); +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 , &e.port, &e.proto))
@@ -340,7 +338,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 ip_set_ext ext =IP_SET_INIT_UEXT (h); +struct ip_set_ext ext =IP_SET_INIT_UEXT (set);u32 port, port_to;bool with_ports = false;int ret;
net/netfilter/ipset/ip_set_hash_ipportnet.c +7 -7
@@ -172,7 +172,7 @@ hash_ipportnet4_kadt(struct ip_set *set, const struct sk_buff *skb,struct hash_ipportnet4_elem e = { .cidr =IP_SET_INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ) -1 , }; -struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, h); +struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);if (adt ==IPSET_TEST ) e.cidr =HOST_MASK -1 ;
@@ -195,7 +195,7 @@ hash_ipportnet4_uadt(struct ip_set *set, struct nlattr *tb[],const struct hash_ipportnet *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipportnet4_elem e = { .cidr =HOST_MASK -1 }; -struct ip_set_ext ext =IP_SET_INIT_UEXT (h); +struct ip_set_ext ext =IP_SET_INIT_UEXT (set);u32 ip =0 , ip_to =0 , p =0 , port, port_to;u32 ip2_from =0 , ip2_to =0 , ip2_last, ip2;bool with_ports = false;
@@ -306,9 +306,9 @@ hash_ipportnet4_uadt(struct ip_set *set, struct nlattr *tb[], : port;for (; p <= port_to; p++) { e.port =htons (p); - ip2 = retried - && ip ==ntohl (h->next.ip) - && p ==ntohs (h->next.port) + ip2 = retried && + ip ==ntohl (h->next.ip) && + p ==ntohs (h->next.port) ?ntohl (h->next.ip2) : ip2_from;while (!after (ip2, ip2_to)) { e.ip2 =htonl (ip2);
@@ -456,7 +456,7 @@ hash_ipportnet6_kadt(struct ip_set *set, const struct sk_buff *skb,struct hash_ipportnet6_elem e = { .cidr =IP_SET_INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ) -1 , }; -struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, h); +struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);if (adt ==IPSET_TEST ) e.cidr =HOST_MASK -1 ;
@@ -479,7 +479,7 @@ hash_ipportnet6_uadt(struct ip_set *set, struct nlattr *tb[],const struct hash_ipportnet *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipportnet6_elem e = { .cidr =HOST_MASK -1 }; -struct ip_set_ext ext =IP_SET_INIT_UEXT (h); +struct ip_set_ext ext =IP_SET_INIT_UEXT (set);u32 port, port_to;bool with_ports = false;u8 cidr;
net/netfilter/ipset/ip_set_hash_net.c +4 -5
@@ -145,7 +145,7 @@ hash_net4_kadt(struct ip_set *set, const struct sk_buff *skb,struct hash_net4_elem e = { .cidr =IP_SET_INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ), }; -struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, h); +struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);if (e.cidr ==0 )return -EINVAL ;
@@ -165,7 +165,7 @@ hash_net4_uadt(struct ip_set *set, struct nlattr *tb[],const struct hash_net *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_net4_elem e = { .cidr =HOST_MASK }; -struct ip_set_ext ext =IP_SET_INIT_UEXT (h); +struct ip_set_ext ext =IP_SET_INIT_UEXT (set);u32 ip =0 , ip_to =0 , last;int ret;
@@ -340,7 +340,7 @@ hash_net6_kadt(struct ip_set *set, const struct sk_buff *skb,struct hash_net6_elem e = { .cidr =IP_SET_INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ), }; -struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, h); +struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);if (e.cidr ==0 )return -EINVAL ;
@@ -357,10 +357,9 @@ static int hash_net6_uadt(struct ip_set *set, struct nlattr *tb[], enum ipset_adt adt, u32 *lineno, u32 flags, bool retried) { - const struct hash_net *h = set->data; ipset_adtfn adtfn = set->variant->adt[adt];struct hash_net6_elem e = { .cidr =HOST_MASK }; -struct ip_set_ext ext =IP_SET_INIT_UEXT (h); +struct ip_set_ext ext =IP_SET_INIT_UEXT (set);int ret; if (unlikely(!tb[IPSET_ATTR_IP] ||
net/netfilter/ipset/ip_set_hash_netiface.c +4 -4
@@ -268,7 +268,7 @@ hash_netiface4_kadt(struct ip_set *set, const struct sk_buff *skb, .cidr = IP_SET_INIT_CIDR(h->nets[0].cidr[0], HOST_MASK), .elem = 1, }; -struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, h); +struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);int ret;if (e.cidr ==0 )
@@ -319,7 +319,7 @@ hash_netiface4_uadt(struct ip_set *set, struct nlattr *tb[],struct hash_netiface *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netiface4_elem e = { .cidr =HOST_MASK , .elem =1 }; -struct ip_set_ext ext =IP_SET_INIT_UEXT (h); +struct ip_set_ext ext =IP_SET_INIT_UEXT (set);u32 ip =0 , ip_to =0 , last;char iface[IFNAMSIZ ];int ret;
@@ -537,7 +537,7 @@ hash_netiface6_kadt(struct ip_set *set, const struct sk_buff *skb, .cidr = IP_SET_INIT_CIDR(h->nets[0].cidr[0], HOST_MASK), .elem = 1, }; -struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, h); +struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);int ret;if (e.cidr ==0 )
@@ -584,7 +584,7 @@ hash_netiface6_uadt(struct ip_set *set, struct nlattr *tb[],struct hash_netiface *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netiface6_elem e = { .cidr =HOST_MASK , .elem =1 }; -struct ip_set_ext ext =IP_SET_INIT_UEXT (h); +struct ip_set_ext ext =IP_SET_INIT_UEXT (set);char iface[IFNAMSIZ ];int ret;
net/netfilter/ipset/ip_set_hash_netport.c +4 -4
@@ -164,7 +164,7 @@ hash_netport4_kadt(struct ip_set *set, const struct sk_buff *skb,struct hash_netport4_elem e = { .cidr =IP_SET_INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ) -1 , }; -struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, h); +struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);if (adt ==IPSET_TEST ) e.cidr =HOST_MASK -1 ;
@@ -186,7 +186,7 @@ hash_netport4_uadt(struct ip_set *set, struct nlattr *tb[],const struct hash_netport *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netport4_elem e = { .cidr =HOST_MASK -1 }; -struct ip_set_ext ext =IP_SET_INIT_UEXT (h); +struct ip_set_ext ext =IP_SET_INIT_UEXT (set);u32 port, port_to, p =0 , ip =0 , ip_to =0 , last;bool with_ports = false;u8 cidr;
@@ -409,7 +409,7 @@ hash_netport6_kadt(struct ip_set *set, const struct sk_buff *skb,struct hash_netport6_elem e = { .cidr =IP_SET_INIT_CIDR (h->nets[0 ].cidr[0 ],HOST_MASK ) -1 , }; -struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, h); +struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);if (adt ==IPSET_TEST ) e.cidr =HOST_MASK -1 ;
@@ -431,7 +431,7 @@ hash_netport6_uadt(struct ip_set *set, struct nlattr *tb[],const struct hash_netport *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netport6_elem e = { .cidr =HOST_MASK -1 }; -struct ip_set_ext ext =IP_SET_INIT_UEXT (h); +struct ip_set_ext ext =IP_SET_INIT_UEXT (set);u32 port, port_to;bool with_ports = false;u8 cidr;
net/netfilter/ipset/ip_set_list_set.c +52 -64
342 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 16/33 netfilter: ipset: Generalize extensions support
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
Get rid of the structure based extensions and introduce a blob for the extensions. Thus we can support more extension types easily.
--- include/linux/netfilter/ipset/ip_set.h | 13 ++++ net/netfilter/ipset/ip_set_bitmap_ip.c | 81 +++--------------------- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 91 +++------------------------ net/netfilter/ipset/ip_set_bitmap_port.c | 71 ++------------------- net/netfilter/ipset/ip_set_core.c | 46 ++++++++++++++ net/netfilter/ipset/ip_set_hash_gen.h | 86 +++---------------------- net/netfilter/ipset/ip_set_hash_ip.c | 36 +---------- net/netfilter/ipset/ip_set_hash_ipport.c | 54 +--------------- net/netfilter/ipset/ip_set_hash_ipportip.c | 60 +----------------- net/netfilter/ipset/ip_set_hash_ipportnet.c | 66 +------------------ net/netfilter/ipset/ip_set_hash_net.c | 54 +--------------- net/netfilter/ipset/ip_set_hash_netiface.c | 68 +------------------- net/netfilter/ipset/ip_set_hash_netport.c | 60 +----------------- net/netfilter/ipset/ip_set_list_set.c | 81 ++++-------------------- 14 files changed, 118 insertions(+), 749 deletions(-)
include/linux/netfilter/ipset/ip_set.h +13 -0
@@ -66,6 +66,17 @@ enum ip_set_ext_id { IPSET_EXT_ID_MAX, }; +/* Extension type */ +struct ip_set_ext_type { +enum ip_set_extension type; +enum ipset_cadt_flags flag; +/* Size and minimal alignment */ +u8 len; +u8 align; +}; + +extern const struct ip_set_ext_type ip_set_extensions[]; +struct ip_set_ext {u64 packets;u64 bytes;
@@ -283,6 +294,8 @@ extern void *ip_set_alloc(size_t size);extern void ip_set_free (void *members);extern int ip_set_get_ipaddr4 (struct nlattr *nla,__be32 *ipaddr);extern int ip_set_get_ipaddr6 (struct nlattr *nla,union nf_inet_addr *ipaddr); +extern size_t ip_set_elem_len (struct ip_set *set,struct nlattr *tb[], +size_t len);extern int ip_set_get_extensions (struct ip_set *set,struct nlattr *tb[],struct ip_set_ext *ext);
net/netfilter/ipset/ip_set_bitmap_ip.c +8 -73
101 lines not on this page · raw message
net/netfilter/ipset/ip_set_bitmap_ipmac.c +9 -82
117 lines not on this page · raw message
net/netfilter/ipset/ip_set_bitmap_port.c +6 -65
91 lines not on this page · raw message
net/netfilter/ipset/ip_set_core.c +46 -0
52 lines not on this page · raw message
net/netfilter/ipset/ip_set_hash_gen.h +10 -76
105 lines not on this page · raw message
net/netfilter/ipset/ip_set_hash_ip.c +2 -34
@@ -35,7 +35,7 @@ MODULE_ALIAS("ip_set_hash:ip");#define HTYPE hash_ip#define IP_SET_HASH_WITH_NETMASK -/* IPv4 variants */ +/* IPv4 variant */ /* Member elements */ struct hash_ip4_elem {
@@ -43,22 +43,6 @@ struct hash_ip4_elem {__be32 ip; }; -struct hash_ip4t_elem { -__be32 ip; -unsigned long timeout; -}; - -struct hash_ip4c_elem { -__be32 ip; -struct ip_set_counter counter; -}; - -struct hash_ip4ct_elem { -__be32 ip; -struct ip_set_counter counter; -unsigned long timeout; -}; -/* Common functions */ static inline bool
@@ -178,29 +162,13 @@ hash_ip4_uadt(struct ip_set *set, struct nlattr *tb[],return ret; } -/* IPv6 variants */ +/* IPv6 variant */ /* Member elements */ struct hash_ip6_elem {union nf_inet_addr ip; }; -struct hash_ip6t_elem { -union nf_inet_addr ip; -unsigned long timeout; -}; - -struct hash_ip6c_elem { -union nf_inet_addr ip; -struct ip_set_counter counter; -}; - -struct hash_ip6ct_elem { -union nf_inet_addr ip; -struct ip_set_counter counter; -unsigned long timeout; -}; -/* Common functions */ static inline bool
net/netfilter/ipset/ip_set_hash_ipport.c +2 -52
78 lines not on this page · raw message
net/netfilter/ipset/ip_set_hash_ipportip.c +2 -58
84 lines not on this page · raw message
net/netfilter/ipset/ip_set_hash_ipportnet.c +2 -64
90 lines not on this page · raw message
net/netfilter/ipset/ip_set_hash_net.c +2 -52
78 lines not on this page · raw message
net/netfilter/ipset/ip_set_hash_netiface.c +3 -65
98 lines not on this page · raw message
net/netfilter/ipset/ip_set_hash_netport.c +2 -58
84 lines not on this page · raw message
net/netfilter/ipset/ip_set_list_set.c +11 -70
120 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 17/33 netfilter: ipset: Support extensions which need a per data destroy function
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
--- include/linux/netfilter/ipset/ip_set.h | 22 +++++++--- net/netfilter/ipset/ip_set_bitmap_gen.h | 38 ++++++++++++++--- net/netfilter/ipset/ip_set_hash_gen.h | 71 ++++++++++++++++++++----------- net/netfilter/ipset/ip_set_list_set.c | 19 ++++++--- 4 files changed, 107 insertions(+), 43 deletions(-)
include/linux/netfilter/ipset/ip_set.h +17 -5
@@ -49,11 +49,13 @@ enum ip_set_feature {/* Set extensions */ enum ip_set_extension { -IPSET_EXT_NONE =0 , -IPSET_EXT_BIT_TIMEOUT =1 , +IPSET_EXT_BIT_TIMEOUT =0 ,IPSET_EXT_TIMEOUT = (1 <<IPSET_EXT_BIT_TIMEOUT ), -IPSET_EXT_BIT_COUNTER =2 , +IPSET_EXT_BIT_COUNTER =1 ,IPSET_EXT_COUNTER = (1 <<IPSET_EXT_BIT_COUNTER ), +/* Mark set with an extension which needs to call destroy */ +IPSET_EXT_BIT_DESTROY =7 , +IPSET_EXT_DESTROY = (1 <<IPSET_EXT_BIT_DESTROY ), };#define SET_WITH_TIMEOUT (s) ((s)->extensions & IPSET_EXT_TIMEOUT)
@@ -68,6 +70,8 @@ enum ip_set_ext_id {/* Extension type */ struct ip_set_ext_type { +/* Destroy extension private data (can be NULL) */ +void (*destroy)(void *ext);enum ip_set_extension type;enum ipset_cadt_flags flag;/* Size and minimal alignment */
@@ -88,13 +92,21 @@ struct ip_set_counter {atomic64_t packets; }; +struct ip_set ; + +static inline void +ip_set_ext_destroy (struct ip_set *set,void *data) +{ +/* Check that the extension is enabled for the set and +* call it's destroy function for its extension part in data. +*/ +} +#define ext_timeout (e, s) \ (unsigned long *)(((void *)(e)) + (s)->offset[IPSET_EXT_ID_TIMEOUT])#define ext_counter (e, s) \ (struct ip_set_counter *)(((void *)(e)) + (s)->offset[IPSET_EXT_ID_COUNTER]) -struct ip_set ; -typedef int (*ipset_adtfn )(struct ip_set *set,void *value,const struct ip_set_ext *ext,struct ip_set_ext *mext,u32 cmdflags);
net/netfilter/ipset/ip_set_bitmap_gen.h +31 -7
@@ -12,6 +12,7 @@#define mtype_gc_test IPSET_TOKEN(MTYPE, _gc_test)#define mtype_is_filled IPSET_TOKEN(MTYPE, _is_filled)#define mtype_do_add IPSET_TOKEN(MTYPE, _do_add) +#define mtype_ext_cleanup IPSET_TOKEN(MTYPE, _ext_cleanup)#define mtype_do_del IPSET_TOKEN(MTYPE, _do_del)#define mtype_do_list IPSET_TOKEN(MTYPE, _do_list)#define mtype_do_head IPSET_TOKEN(MTYPE, _do_head)
@@ -47,6 +48,17 @@ mtype_gc_init(struct ip_set *set, void (*gc)(unsigned long ul_set)) }static void +mtype_ext_cleanup (struct ip_set *set) +{ +struct mtype *map = set->data; +u32 id; + +for (id =0 ; id < map->elements; id++) +if (test_bit (id, map->members)) +ip_set_ext_destroy (set,get_ext (set, map, id)); +} + +static void mtype_destroy (struct ip_set *set) {struct mtype *map = set->data;
@@ -55,8 +67,11 @@ mtype_destroy(struct ip_set *set)del_timer_sync (&map->gc);ip_set_free (map->members); -if (set->dsize) +if (set->dsize) { +if (set->extensions &IPSET_EXT_DESTROY ) +mtype_ext_cleanup (set);ip_set_free (map->extensions); + }kfree (map); set->data =NULL ;
@@ -67,6 +82,8 @@ mtype_flush(struct ip_set *set) {struct mtype *map = set->data; +if (set->extensions &IPSET_EXT_DESTROY ) +mtype_ext_cleanup (set);memset (map->members,0 , map->memsize); }
@@ -132,6 +149,8 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext, ret =0 ; else if (!(flags & IPSET_FLAG_EXIST))return -IPSET_ERR_EXIST ; +/* Element is re-added, cleanup extensions */ +ip_set_ext_destroy (set, x); }if (SET_WITH_TIMEOUT (set))
@@ -152,11 +171,14 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext, {struct mtype *map = set->data;const struct mtype_adt_elem *e = value; -const void *x =get_ext (set, map, e->id); +void *x =get_ext (set, map, e->id); -if (mtype_do_del (e, map) || - (SET_WITH_TIMEOUT (set) && -ip_set_timeout_expired (ext_timeout (x, set)))) +if (mtype_do_del (e, map)) +return -IPSET_ERR_EXIST ; + +ip_set_ext_destroy (set, x); +if (SET_WITH_TIMEOUT (set) && +ip_set_timeout_expired (ext_timeout (x, set)))return -IPSET_ERR_EXIST ;return 0 ;
@@ -235,7 +257,7 @@ mtype_gc(unsigned long ul_set) {struct ip_set *set = (struct ip_set *) ul_set;struct mtype *map = set->data; -const void *x; +void *x;u32 id;/* We run parallel with other readers (test element)
@@ -244,8 +266,10 @@ mtype_gc(unsigned long ul_set)for (id =0 ; id < map->elements; id++)if (mtype_gc_test (id, map, set->dsize)) { x =get_ext (set, map, id); -if (ip_set_timeout_expired (ext_timeout (x, set))) +if (ip_set_timeout_expired (ext_timeout (x, set))) {clear_bit (id, map->members); +ip_set_ext_destroy (set, x); + } }read_unlock_bh (&set->lock);
net/netfilter/ipset/ip_set_hash_gen.h +46 -25
155 lines not on this page · raw message
net/netfilter/ipset/ip_set_list_set.c +13 -6
@@ -168,16 +168,19 @@ list_set_add(struct ip_set *set, u32 i, struct set_adt_elem *d,struct set_elem *e =list_set_elem (set, map, i);if (e->id !=IPSET_INVALID_ID ) { -if (i == map->size -1 ) +if (i == map->size -1 ) {/* Last element replaced: e.g. add new,before,last */ ip_set_put_byindex (e->id); -else { +ip_set_ext_destroy (set, e); + }else {struct set_elem *x =list_set_elem (set, map, map->size -1 );/* Last element pushed off */ -if (x->id !=IPSET_INVALID_ID ) +if (x->id !=IPSET_INVALID_ID ) {ip_set_put_byindex (x->id); +ip_set_ext_destroy (set, x); + }memmove (list_set_elem (set, map, i +1 ), e, set->dsize * (map->size - (i +1 ))); }
@@ -198,6 +201,7 @@ list_set_del(struct ip_set *set, u32 i)struct set_elem *e =list_set_elem (set, map, i);ip_set_put_byindex (e->id); +ip_set_ext_destroy (set, e);if (i < map->size -1 ) memmove(e, list_set_elem(set, map, i + 1),
@@ -266,14 +270,14 @@ list_set_uadd(struct ip_set *set, void *value, const struct ip_set_ext *ext,bool flag_exist = flags &IPSET_FLAG_EXIST ;u32 i, ret =0 ; +if (SET_WITH_TIMEOUT (set)) +set_cleanup_entries (set); +/* Check already added element */ for (i =0 ; i < map->size; i++) { e =list_set_elem (set, map, i);if (e->id ==IPSET_INVALID_ID ) goto insert; -else if (SET_WITH_TIMEOUT (set) && -ip_set_timeout_expired (ext_timeout (e, set))) -continue ;else if (e->id != d->id)continue ;
@@ -286,6 +290,8 @@ list_set_uadd(struct ip_set *set, void *value, const struct ip_set_ext *ext,/* Can't re-add */ return -IPSET_ERR_EXIST ;/* Update extensions */ +ip_set_ext_destroy (set, e); +if (SET_WITH_TIMEOUT (set))ip_set_timeout_set (ext_timeout (e, set), ext->timeout);if (SET_WITH_COUNTER (set))
@@ -423,6 +429,7 @@ list_set_flush(struct ip_set *set) e =list_set_elem (set, map, i);if (e->id !=IPSET_INVALID_ID ) {ip_set_put_byindex (e->id); +ip_set_ext_destroy (set, e); e->id =IPSET_INVALID_ID ; } }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 18/33 netfilter: ipset: list:set: make sure all elements are checked by the gc
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
When an element timed out, the next one was skipped by the garbage collector, fixed.
--- net/netfilter/ipset/ip_set_list_set.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/netfilter/ipset/ip_set_list_set.c +5 -2
@@ -218,13 +218,16 @@ set_cleanup_entries(struct ip_set *set) {struct list_set *map = set->data;struct set_elem *e; -u32 i; +u32 i =0 ; -for (i =0 ; i < map->size; i++) { +while (i < map->size) { e =list_set_elem (set, map, i);if (e->id !=IPSET_INVALID_ID &&ip_set_timeout_expired (ext_timeout (e, set)))list_set_del (set, i); +/* Check element moved to position i in next loop */ +else + i++; } }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 19/33 netfilter: ipset: Kconfig: ipset needs NETFILTER_NETLINK
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
--- net/netfilter/ipset/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipset/Kconfig +1 -1
@@ -1,7 +1,7 @@ menuconfig IP_SET tristate "IP set support" depends on INET && NETFILTER - depends on NETFILTER_NETLINK + select NETFILTER_NETLINK help This option adds IP set support to the kernel. In order to define and use the sets, you need the userspace utility
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 20/33 netfilter: ipset: Add hash:net,net module to kernel.
In reply to Pablo Neira AyusoFrom: Oliver Smith <[email protected]>
This adds a new set that provides the ability to configure pairs of subnets. A small amount of additional handling code has been added to the generic hash header file - this code is conditionally activated by a preprocessor definition.
--- net/netfilter/ipset/Kconfig | 9 + net/netfilter/ipset/Makefile | 1 + net/netfilter/ipset/ip_set_hash_gen.h | 58 +++- net/netfilter/ipset/ip_set_hash_netnet.c | 482 ++++++++++++++++++++++++++++++ 4 files changed, 541 insertions(+), 9 deletions(-) create mode 100644 net/netfilter/ipset/ip_set_hash_netnet.c
net/netfilter/ipset/Kconfig +9 -0
@@ -99,6 +99,15 @@ config IP_SET_HASH_NET To compile it as a module, choose M here. If unsure, say N. +config IP_SET_HASH_NETNET + tristate "hash:net,net set support" + depends on IP_SET + help + This option adds the hash:net,net set type support, by which + one can store IPv4/IPv6 network address/prefix pairs in a set. + + To compile it as a module, choose M here. If unsure, say N. + config IP_SET_HASH_NETPORT tristate "hash:net,port set support" depends on IP_SET
net/netfilter/ipset/Makefile +1 -0
@@ -20,6 +20,7 @@ obj-$(CONFIG_IP_SET_HASH_IPPORTNET) += ip_set_hash_ipportnet.o obj-$(CONFIG_IP_SET_HASH_NET) += ip_set_hash_net.o obj-$(CONFIG_IP_SET_HASH_NETPORT) += ip_set_hash_netport.o obj-$(CONFIG_IP_SET_HASH_NETIFACE) += ip_set_hash_netiface.o +obj-$(CONFIG_IP_SET_HASH_NETNET) += ip_set_hash_netnet.o # list types obj-$(CONFIG_IP_SET_LIST_SET) += ip_set_list_set.o
net/netfilter/ipset/ip_set_hash_gen.h +49 -9
134 lines not on this page · raw message
net/netfilter/ipset/ip_set_hash_netnet.c new file +482 -0
482 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 21/33 netfilter: ipset: Support comments for ipset entries in the core.
In reply to Pablo Neira AyusoFrom: Oliver Smith <[email protected]>
This adds the core support for having comments on ipset entries.
The comments are stored as standard null-terminated strings in dynamically allocated memory after being passed to the kernel. As a result of this, code has been added to the generic destroy function to iterate all extensions and call that extension's destroy task if the set has that extension activated, and if such a task is defined.
--- include/linux/netfilter/ipset/ip_set.h | 51 +++++++++++++++++---- include/linux/netfilter/ipset/ip_set_comment.h | 57 ++++++++++++++++++++++++ include/uapi/linux/netfilter/ipset/ip_set.h | 8 +++- net/netfilter/ipset/ip_set_core.c | 14 ++++++ 4 files changed, 121 insertions(+), 9 deletions(-) create mode 100644 include/linux/netfilter/ipset/ip_set_comment.h
include/linux/netfilter/ipset/ip_set.h +43 -8
@@ -53,6 +53,8 @@ enum ip_set_extension {IPSET_EXT_TIMEOUT = (1 <<IPSET_EXT_BIT_TIMEOUT ),IPSET_EXT_BIT_COUNTER =1 ,IPSET_EXT_COUNTER = (1 <<IPSET_EXT_BIT_COUNTER ), +IPSET_EXT_BIT_COMMENT =2 , +IPSET_EXT_COMMENT = (1 <<IPSET_EXT_BIT_COMMENT ),/* Mark set with an extension which needs to call destroy */ IPSET_EXT_BIT_DESTROY =7 , IPSET_EXT_DESTROY = (1 << IPSET_EXT_BIT_DESTROY),
@@ -60,11 +62,13 @@ enum ip_set_extension {#define SET_WITH_TIMEOUT (s) ((s)->extensions & IPSET_EXT_TIMEOUT)#define SET_WITH_COUNTER (s) ((s)->extensions & IPSET_EXT_COUNTER) +#define SET_WITH_COMMENT (s) ((s)->extensions & IPSET_EXT_COMMENT)/* Extension id, in size order */ enum ip_set_ext_id {IPSET_EXT_ID_COUNTER =0 ,IPSET_EXT_ID_TIMEOUT , +IPSET_EXT_ID_COMMENT ,IPSET_EXT_ID_MAX , };
@@ -85,6 +89,7 @@ struct ip_set_ext {u64 packets;u64 bytes;u32 timeout; +char *comment; };struct ip_set_counter {
@@ -92,20 +97,19 @@ struct ip_set_counter {atomic64_t packets; }; -struct ip_set ; +struct ip_set_comment { +char *str; +}; -static inline void -ip_set_ext_destroy (struct ip_set *set,void *data) -{ -/* Check that the extension is enabled for the set and -* call it's destroy function for its extension part in data. -*/ -} +struct ip_set ;#define ext_timeout (e, s) \ (unsigned long *)(((void *)(e)) + (s)->offset[IPSET_EXT_ID_TIMEOUT])#define ext_counter (e, s) \ (struct ip_set_counter *)(((void *)(e)) + (s)->offset[IPSET_EXT_ID_COUNTER]) +#define ext_comment (e, s) \ +(struct ip_set_comment *)(((void *)(e)) + (s)->offset[IPSET_EXT_ID_COMMENT]) + typedef int (*ipset_adtfn)(struct ip_set *set, void *value, const struct ip_set_ext *ext,
@@ -223,6 +227,36 @@ struct ip_set { };static inline void +ip_set_ext_destroy (struct ip_set *set,void *data) +{ +/* Check that the extension is enabled for the set and +* call it's destroy function for its extension part in data. +*/ +if (SET_WITH_COMMENT (set)) + ip_set_extensions[IPSET_EXT_ID_COMMENT ].destroy ( +ext_comment (data, set)); +} + +static inline int +ip_set_put_flags (struct sk_buff *skb,struct ip_set *set) +{ +u32 cadt_flags =0 ; + +if (SET_WITH_TIMEOUT (set)) +if (unlikely (nla_put_net32 (skb,IPSET_ATTR_TIMEOUT , +htonl (set->timeout)))) +return -EMSGSIZE ; +if (SET_WITH_COUNTER (set)) + cadt_flags |=IPSET_FLAG_WITH_COUNTERS ; +if (SET_WITH_COMMENT (set)) + cadt_flags |=IPSET_FLAG_WITH_COMMENT ; + +if (!cadt_flags) +return 0 ; +return nla_put_net32 (skb,IPSET_ATTR_CADT_FLAGS ,htonl (cadt_flags)); +} + +static inline void ip_set_add_bytes (u64 bytes,struct ip_set_counter *counter) {atomic64_add ((long long )bytes, &(counter)->bytes);
@@ -425,6 +459,7 @@ bitmap_bytes(u32 a, u32 b) }#include <linux/netfilter/ipset/ip_set_timeout.h> +#include <linux/netfilter/ipset/ip_set_comment.h> #define IP_SET_INIT_KEXT (skb, opt, set) \ { .bytes = (skb)->len, .packets = 1, \
include/linux/netfilter/ipset/ip_set_comment.h new file +57 -0
57 lines not on this page · raw message
include/uapi/linux/netfilter/ipset/ip_set.h +7 -1
@@ -10,12 +10,14 @@#ifndef _UAPI_IP_SET_H#define _UAPI_IP_SET_H -#include <linux/types.h> /* The protocol version */ #define IPSET_PROTOCOL 6 +/* The maximum permissible comment length we will accept over netlink */ +#define IPSET_MAX_COMMENT_SIZE 255 +/* The max length of strings including NUL: set and type identifiers */ #define IPSET_MAXNAMELEN 32
@@ -110,6 +112,7 @@ enum {IPSET_ATTR_IFACE ,IPSET_ATTR_BYTES ,IPSET_ATTR_PACKETS , +IPSET_ATTR_COMMENT , __IPSET_ATTR_ADT_MAX, };#define IPSET_ATTR_ADT_MAX (__IPSET_ATTR_ADT_MAX - 1)
@@ -140,6 +143,7 @@ enum ipset_errno {IPSET_ERR_IPADDR_IPV4 ,IPSET_ERR_IPADDR_IPV6 ,IPSET_ERR_COUNTER , +IPSET_ERR_COMMENT ,/* Type specific error codes */ IPSET_ERR_TYPE_SPECIFIC = 4352,
@@ -176,6 +180,8 @@ enum ipset_cadt_flags {IPSET_FLAG_NOMATCH = (1 <<IPSET_FLAG_BIT_NOMATCH ),IPSET_FLAG_BIT_WITH_COUNTERS =3 ,IPSET_FLAG_WITH_COUNTERS = (1 <<IPSET_FLAG_BIT_WITH_COUNTERS ), +IPSET_FLAG_BIT_WITH_COMMENT =4 , +IPSET_FLAG_WITH_COMMENT = (1 <<IPSET_FLAG_BIT_WITH_COMMENT ), IPSET_FLAG_CADT_MAX = 15, };
net/netfilter/ipset/ip_set_core.c +14 -0
@@ -315,6 +315,7 @@ ip_set_get_ipaddr6(struct nlattr *nla, union nf_inet_addr *ipaddr) }EXPORT_SYMBOL_GPL (ip_set_get_ipaddr6); +typedef void (*destroyer )(void *);/* ipset data extension types, in size order */ const struct ip_set_ext_type ip_set_extensions[] = {
@@ -329,6 +330,13 @@ const struct ip_set_ext_type ip_set_extensions[] = { .len = sizeof(unsigned long), .align = __alignof__(unsigned long), }, + [IPSET_EXT_ID_COMMENT] = { + .type = IPSET_EXT_COMMENT | IPSET_EXT_DESTROY, + .flag = IPSET_FLAG_WITH_COMMENT, + .len = sizeof(struct ip_set_comment), + .align = __alignof__(struct ip_set_comment), + .destroy = (destroyer) ip_set_comment_free, + }, };EXPORT_SYMBOL_GPL (ip_set_extensions);
@@ -380,6 +388,12 @@ ip_set_get_extensions(struct ip_set *set, struct nlattr *tb[], ext->packets =be64_to_cpu (nla_get_be64 ( tb[IPSET_ATTR_PACKETS ])); } +if (tb[IPSET_ATTR_COMMENT ]) { +if (!(set->extensions &IPSET_EXT_COMMENT )) +return -IPSET_ERR_COMMENT ; + ext->comment =ip_set_comment_uget (tb[IPSET_ATTR_COMMENT ]); + } +return 0 ; }EXPORT_SYMBOL_GPL (ip_set_get_extensions);
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 22/33 netfilter: ipset: Support comments in bitmap-type ipsets.
In reply to Pablo Neira AyusoFrom: Oliver Smith <[email protected]>
This provides kernel support for creating bitmap ipsets with comment support.
As is the case for hashes, this incurs a penalty when flushing or destroying the entire ipset as the entries must first be walked in order to free the comment strings. This penalty is of course far less than the cost of listing an ipset to userspace. Any set created without support for comments will be flushed/destroyed as before.
--- net/netfilter/ipset/ip_set_bitmap_gen.h | 14 ++++++++------ 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 +++- 4 files changed, 17 insertions(+), 9 deletions(-)
net/netfilter/ipset/ip_set_bitmap_gen.h +8 -6
@@ -101,12 +101,9 @@ mtype_head(struct ip_set *set, struct sk_buff *skb)nla_put_net32 (skb,IPSET_ATTR_MEMSIZE ,htonl (sizeof (*map) + map->memsize + - set->dsize * map->elements)) || - (SET_WITH_TIMEOUT (set) && -nla_put_net32 (skb,IPSET_ATTR_TIMEOUT ,htonl (set->timeout))) || - (SET_WITH_COUNTER (set) && -nla_put_net32 (skb,IPSET_ATTR_CADT_FLAGS , - htonl(IPSET_FLAG_WITH_COUNTERS)))) + set->dsize * map->elements))) + goto nla_put_failure; +if (unlikely (ip_set_put_flags (skb, set))) goto nla_put_failure;ipset_nest_end (skb, nested);
@@ -162,6 +159,8 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,if (SET_WITH_COUNTER (set))ip_set_init_counter (ext_counter (x, set), ext); +if (SET_WITH_COMMENT (set)) +ip_set_init_comment (ext_comment (x, set), ext);return 0 ; }
@@ -233,6 +232,9 @@ mtype_list(const struct ip_set *set,if (SET_WITH_COUNTER (set) &&ip_set_put_counter (skb,ext_counter (x, set))) goto nla_put_failure; +if (SET_WITH_COMMENT (set) && +ip_set_put_comment (skb,ext_comment (x, set))) + goto nla_put_failure;ipset_nest_end (skb, nested); }ipset_nest_end (skb, adt);
net/netfilter/ipset/ip_set_bitmap_ip.c +3 -1
@@ -26,7 +26,8 @@#include <linux/netfilter/ipset/ip_set_bitmap.h> #define IPSET_TYPE_REV_MIN 0 -#define IPSET_TYPE_REV_MAX 1/* Counter support added */ +/* 1 Counter support added */ +#define IPSET_TYPE_REV_MAX 2/* Comment support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -354,6 +355,7 @@ static struct ip_set_type bitmap_ip_type __read_mostly = { [IPSET_ATTR_LINENO] = { .type = NLA_U32 }, [IPSET_ATTR_BYTES] = { .type = NLA_U64 }, [IPSET_ATTR_PACKETS] = { .type = NLA_U64 }, + [IPSET_ATTR_COMMENT ] = { .type =NLA_NUL_STRING }, }, .me = THIS_MODULE, };
net/netfilter/ipset/ip_set_bitmap_ipmac.c +3 -1
@@ -26,7 +26,8 @@#include <linux/netfilter/ipset/ip_set_bitmap.h> #define IPSET_TYPE_REV_MIN 0 -#define IPSET_TYPE_REV_MAX 1/* Counter support added */ +/* 1 Counter support added */ +#define IPSET_TYPE_REV_MAX 2/* Comment support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -403,6 +404,7 @@ static struct ip_set_type bitmap_ipmac_type = { [IPSET_ATTR_LINENO] = { .type = NLA_U32 }, [IPSET_ATTR_BYTES] = { .type = NLA_U64 }, [IPSET_ATTR_PACKETS] = { .type = NLA_U64 }, + [IPSET_ATTR_COMMENT ] = { .type =NLA_NUL_STRING }, }, .me = THIS_MODULE, };
net/netfilter/ipset/ip_set_bitmap_port.c +3 -1
@@ -21,7 +21,8 @@#include <linux/netfilter/ipset/ip_set_getport.h> #define IPSET_TYPE_REV_MIN 0 -#define IPSET_TYPE_REV_MAX 1/* Counter support added */ +/* 1 Counter support added */ +#define IPSET_TYPE_REV_MAX 2/* Comment support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -288,6 +289,7 @@ static struct ip_set_type bitmap_port_type = { [IPSET_ATTR_LINENO] = { .type = NLA_U32 }, [IPSET_ATTR_BYTES] = { .type = NLA_U64 }, [IPSET_ATTR_PACKETS] = { .type = NLA_U64 }, + [IPSET_ATTR_COMMENT ] = { .type =NLA_NUL_STRING }, }, .me = THIS_MODULE, };
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 23/33 netfilter: ipset: Support comments in the list-type ipset.
In reply to Pablo Neira AyusoFrom: Oliver Smith <[email protected]>
This provides kernel support for creating list ipsets with the comment annotation extension.
--- net/netfilter/ipset/ip_set_list_set.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
net/netfilter/ipset/ip_set_list_set.c +12 -6
@@ -16,7 +16,8 @@#include <linux/netfilter/ipset/ip_set_list.h> #define IPSET_TYPE_REV_MIN 0 -#define IPSET_TYPE_REV_MAX 1/* Counters support added */ +/* 1 Counters support added */ +#define IPSET_TYPE_REV_MAX 2/* Comments support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -191,6 +192,8 @@ list_set_add(struct ip_set *set, u32 i, struct set_adt_elem *d,ip_set_timeout_set (ext_timeout (e, set), ext->timeout);if (SET_WITH_COUNTER (set))ip_set_init_counter (ext_counter (e, set), ext); +if (SET_WITH_COMMENT (set) && ext->comment) +ip_set_init_comment (ext_comment (e, set), ext);return 0 ; }
@@ -299,6 +302,8 @@ list_set_uadd(struct ip_set *set, void *value, const struct ip_set_ext *ext,ip_set_timeout_set (ext_timeout (e, set), ext->timeout);if (SET_WITH_COUNTER (set))ip_set_init_counter (ext_counter (e, set), ext); +if (SET_WITH_COMMENT (set)) +ip_set_init_comment (ext_comment (e, set), ext);/* Set is already added to the list */ ip_set_put_byindex (d->id);return 0 ;
@@ -461,15 +466,12 @@ list_set_head(struct ip_set *set, struct sk_buff *skb)if (!nested) goto nla_put_failure;if (nla_put_net32 (skb,IPSET_ATTR_SIZE ,htonl (map->size)) || - (SET_WITH_TIMEOUT (set) && -nla_put_net32 (skb,IPSET_ATTR_TIMEOUT ,htonl (set->timeout))) || - (SET_WITH_COUNTER (set) && -nla_put_net32 (skb,IPSET_ATTR_CADT_FLAGS , -htonl (IPSET_FLAG_WITH_COUNTERS ))) ||nla_put_net32 (skb,IPSET_ATTR_REFERENCES ,htonl (set->ref -1 )) ||nla_put_net32 (skb,IPSET_ATTR_MEMSIZE ,htonl (sizeof (*map) + map->size * set->dsize))) goto nla_put_failure; +if (unlikely (ip_set_put_flags (skb, set))) + goto nla_put_failure;ipset_nest_end (skb, nested);return 0 ;
@@ -516,6 +518,9 @@ list_set_list(const struct ip_set *set,if (SET_WITH_COUNTER (set) &&ip_set_put_counter (skb,ext_counter (e, set))) goto nla_put_failure; +if (SET_WITH_COMMENT (set) && +ip_set_put_comment (skb,ext_comment (e, set))) + goto nla_put_failure;ipset_nest_end (skb, nested); } finish:
@@ -660,6 +665,7 @@ static struct ip_set_type list_set_type __read_mostly = { [IPSET_ATTR_CADT_FLAGS] = { .type = NLA_U32 }, [IPSET_ATTR_BYTES] = { .type = NLA_U64 }, [IPSET_ATTR_PACKETS] = { .type = NLA_U64 }, + [IPSET_ATTR_COMMENT ] = { .type =NLA_NUL_STRING }, }, .me = THIS_MODULE, };
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 24/33 netfilter: ipset: Support comments in hash-type ipsets.
In reply to Pablo Neira AyusoFrom: Oliver Smith <[email protected]>
This provides kernel support for creating ipsets with comment support.
This does incur a penalty to flushing/destroying an ipset since all entries are walked in order to free the allocated strings, this penalty is of course less expensive than the operation of listing an ipset to userspace, so for general-purpose usage the overall impact is expected to be little to none.
--- net/netfilter/ipset/ip_set_hash_gen.h | 14 ++++++++------ net/netfilter/ipset/ip_set_hash_ip.c | 4 +++- net/netfilter/ipset/ip_set_hash_ipport.c | 4 +++- net/netfilter/ipset/ip_set_hash_ipportip.c | 4 +++- net/netfilter/ipset/ip_set_hash_ipportnet.c | 4 +++- net/netfilter/ipset/ip_set_hash_net.c | 4 +++- net/netfilter/ipset/ip_set_hash_netiface.c | 4 +++- net/netfilter/ipset/ip_set_hash_netnet.c | 1 + net/netfilter/ipset/ip_set_hash_netport.c | 4 +++- 9 files changed, 30 insertions(+), 13 deletions(-)
net/netfilter/ipset/ip_set_hash_gen.h +8 -6
@@ -701,6 +701,8 @@ reuse_slot:ip_set_timeout_set (ext_timeout (data, set), ext->timeout);if (SET_WITH_COUNTER (set))ip_set_init_counter (ext_counter (data, set), ext); +if (SET_WITH_COMMENT (set)) +ip_set_init_comment (ext_comment (data, set), ext); out:rcu_read_unlock_bh ();
@@ -908,12 +910,9 @@ mtype_head(struct ip_set *set, struct sk_buff *skb) goto nla_put_failure;#endif if (nla_put_net32 (skb,IPSET_ATTR_REFERENCES ,htonl (set->ref -1 )) || -nla_put_net32 (skb,IPSET_ATTR_MEMSIZE ,htonl (memsize)) || - ((set->extensions &IPSET_EXT_TIMEOUT ) && -nla_put_net32 (skb,IPSET_ATTR_TIMEOUT ,htonl (set->timeout))) || - ((set->extensions &IPSET_EXT_COUNTER ) && -nla_put_net32 (skb,IPSET_ATTR_CADT_FLAGS , -htonl (IPSET_FLAG_WITH_COUNTERS )))) +nla_put_net32 (skb,IPSET_ATTR_MEMSIZE ,htonl (memsize))) + goto nla_put_failure; +if (unlikely (ip_set_put_flags (skb, set))) goto nla_put_failure;ipset_nest_end (skb, nested);
@@ -970,6 +969,9 @@ mtype_list(const struct ip_set *set,if (SET_WITH_COUNTER (set) &&ip_set_put_counter (skb,ext_counter (e, set))) goto nla_put_failure; +if (SET_WITH_COMMENT (set) && +ip_set_put_comment (skb,ext_comment (e, set))) + goto nla_put_failure;ipset_nest_end (skb, nested); } }
net/netfilter/ipset/ip_set_hash_ip.c +3 -1
@@ -24,7 +24,8 @@#include <linux/netfilter/ipset/ip_set_hash.h> #define IPSET_TYPE_REV_MIN 0 -#define IPSET_TYPE_REV_MAX 1/* Counters support */ +/* 1 Counters support */ +#define IPSET_TYPE_REV_MAX 2/* Comments support */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -292,6 +293,7 @@ static struct ip_set_type hash_ip_type __read_mostly = { [IPSET_ATTR_LINENO] = { .type = NLA_U32 }, [IPSET_ATTR_BYTES] = { .type = NLA_U64 }, [IPSET_ATTR_PACKETS] = { .type = NLA_U64 }, + [IPSET_ATTR_COMMENT ] = { .type =NLA_NUL_STRING }, }, .me = THIS_MODULE, };
net/netfilter/ipset/ip_set_hash_ipport.c +3 -1
@@ -26,7 +26,8 @@#define IPSET_TYPE_REV_MIN 0/* 1 SCTP and UDPLITE support added */ -#define IPSET_TYPE_REV_MAX 2/* Counters support added */ +/* 2 Counters support added */ +#define IPSET_TYPE_REV_MAX 3/* Comments support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -367,6 +368,7 @@ static struct ip_set_type hash_ipport_type __read_mostly = { [IPSET_ATTR_LINENO] = { .type = NLA_U32 }, [IPSET_ATTR_BYTES] = { .type = NLA_U64 }, [IPSET_ATTR_PACKETS] = { .type = NLA_U64 }, + [IPSET_ATTR_COMMENT ] = { .type =NLA_NUL_STRING }, }, .me = THIS_MODULE, };
net/netfilter/ipset/ip_set_hash_ipportip.c +3 -1
@@ -26,7 +26,8 @@#define IPSET_TYPE_REV_MIN 0/* 1 SCTP and UDPLITE support added */ -#define IPSET_TYPE_REV_MAX 2/* Counters support added */ +/* 2 Counters support added */ +#define IPSET_TYPE_REV_MAX 3/* Comments support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -379,6 +380,7 @@ static struct ip_set_type hash_ipportip_type __read_mostly = { [IPSET_ATTR_LINENO] = { .type = NLA_U32 }, [IPSET_ATTR_BYTES] = { .type = NLA_U64 }, [IPSET_ATTR_PACKETS] = { .type = NLA_U64 }, + [IPSET_ATTR_COMMENT ] = { .type =NLA_NUL_STRING }, }, .me = THIS_MODULE, };
net/netfilter/ipset/ip_set_hash_ipportnet.c +3 -1
@@ -28,7 +28,8 @@/* 1 SCTP and UDPLITE support added */ /* 2 Range as input support for IPv4 added */ /* 3 nomatch flag support added */ -#define IPSET_TYPE_REV_MAX 4/* Counters support added */ +/* 4 Counters support added */ +#define IPSET_TYPE_REV_MAX 5/* Comments support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -538,6 +539,7 @@ static struct ip_set_type hash_ipportnet_type __read_mostly = { [IPSET_ATTR_LINENO] = { .type = NLA_U32 }, [IPSET_ATTR_BYTES] = { .type = NLA_U64 }, [IPSET_ATTR_PACKETS] = { .type = NLA_U64 }, + [IPSET_ATTR_COMMENT ] = { .type =NLA_NUL_STRING }, }, .me = THIS_MODULE, };
net/netfilter/ipset/ip_set_hash_net.c +3 -1
@@ -25,7 +25,8 @@#define IPSET_TYPE_REV_MIN 0/* 1 Range as input support for IPv4 added */ /* 2 nomatch flag support added */ -#define IPSET_TYPE_REV_MAX 3/* Counters support added */ +/* 3 Counters support added */ +#define IPSET_TYPE_REV_MAX 4/* Comments support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -374,6 +375,7 @@ static struct ip_set_type hash_net_type __read_mostly = { [IPSET_ATTR_CADT_FLAGS] = { .type = NLA_U32 }, [IPSET_ATTR_BYTES] = { .type = NLA_U64 }, [IPSET_ATTR_PACKETS] = { .type = NLA_U64 }, + [IPSET_ATTR_COMMENT ] = { .type =NLA_NUL_STRING }, }, .me = THIS_MODULE, };
net/netfilter/ipset/ip_set_hash_netiface.c +3 -1
@@ -26,7 +26,8 @@#define IPSET_TYPE_REV_MIN 0/* 1 nomatch flag support added */ /* 2 /0 support added */ -#define IPSET_TYPE_REV_MAX 3/* Counters support added */ +/* 3 Counters support added */ +#define IPSET_TYPE_REV_MAX 4/* Comments support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -606,6 +607,7 @@ static struct ip_set_type hash_netiface_type __read_mostly = { [IPSET_ATTR_LINENO] = { .type = NLA_U32 }, [IPSET_ATTR_BYTES] = { .type = NLA_U64 }, [IPSET_ATTR_PACKETS] = { .type = NLA_U64 }, + [IPSET_ATTR_COMMENT ] = { .type =NLA_NUL_STRING }, }, .me = THIS_MODULE, };
net/netfilter/ipset/ip_set_hash_netnet.c +1 -0
@@ -462,6 +462,7 @@ static struct ip_set_type hash_netnet_type __read_mostly = { [IPSET_ATTR_CADT_FLAGS] = { .type = NLA_U32 }, [IPSET_ATTR_BYTES] = { .type = NLA_U64 }, [IPSET_ATTR_PACKETS] = { .type = NLA_U64 }, + [IPSET_ATTR_COMMENT ] = { .type =NLA_NUL_STRING }, }, .me = THIS_MODULE, };
net/netfilter/ipset/ip_set_hash_netport.c +3 -1
@@ -27,7 +27,8 @@/* 1 SCTP and UDPLITE support added */ /* 2 Range as input support for IPv4 added */ /* 3 nomatch flag support added */ -#define IPSET_TYPE_REV_MAX 4/* Counters support added */ +/* 4 Counters support added */ +#define IPSET_TYPE_REV_MAX 5/* Comments support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -486,6 +487,7 @@ static struct ip_set_type hash_netport_type __read_mostly = { [IPSET_ATTR_CADT_FLAGS] = { .type = NLA_U32 }, [IPSET_ATTR_BYTES] = { .type = NLA_U64 }, [IPSET_ATTR_PACKETS] = { .type = NLA_U64 }, + [IPSET_ATTR_COMMENT ] = { .type =NLA_NUL_STRING }, }, .me = THIS_MODULE, };
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 25/33 netfilter: ipset: Fix hash resizing with comments
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
The destroy function must take into account that resizing doesn't create new extensions so those cannot be destroyed at resize.
--- net/netfilter/ipset/ip_set_hash_gen.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
net/netfilter/ipset/ip_set_hash_gen.h +5 -5
@@ -393,7 +393,7 @@ mtype_flush(struct ip_set *set)/* Destroy the hashtable part of the set */ static void -mtype_ahash_destroy (struct ip_set *set,struct htable *t) +mtype_ahash_destroy (struct ip_set *set,struct htable *t,bool ext_destroy) {struct hbucket *n;u32 i;
@@ -401,7 +401,7 @@ mtype_ahash_destroy(struct ip_set *set, struct htable *t)for (i =0 ; i <jhash_size (t->htable_bits); i++) { n =hbucket (t, i);if (n->size) { -if (set->extensions &IPSET_EXT_DESTROY ) +if (set->extensions &IPSET_EXT_DESTROY && ext_destroy)mtype_ext_cleanup (set, n);/* FIXME: use slab cache */ kfree (n->value);
@@ -420,7 +420,7 @@ mtype_destroy(struct ip_set *set)if (set->extensions &IPSET_EXT_TIMEOUT )del_timer_sync (&h->gc); -mtype_ahash_destroy (set,rcu_dereference_bh_nfnl (h->table)); +mtype_ahash_destroy (set,rcu_dereference_bh_nfnl (h->table), true);#ifdef IP_SET_HASH_WITH_RBTREE rbtree_destroy (&h->rbtree);#endif
@@ -586,7 +586,7 @@ retry:mtype_data_reset_flags (data, &flags);#endif read_unlock_bh (&set->lock); -mtype_ahash_destroy (set, t); +mtype_ahash_destroy (set, t, false);if (ret == -EAGAIN ) goto retry;return ret;
@@ -607,7 +607,7 @@ retry:pr_debug ("set %s resized from %u (%p) to %u (%p)\n" , set->name, orig->htable_bits, orig, t->htable_bits, t); -mtype_ahash_destroy (set, orig); +mtype_ahash_destroy (set, orig, false);return 0 ; }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 26/33 netfilter: ipset: For set:list types, replaced elements must be zeroed out
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
The new extensions require zero initialization for the new element to be added into a slot from where another element was pushed away.
--- net/netfilter/ipset/ip_set_list_set.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/netfilter/ipset/ip_set_list_set.c +3 -1
@@ -184,6 +184,8 @@ list_set_add(struct ip_set *set, u32 i, struct set_adt_elem *d, }memmove (list_set_elem (set, map, i +1 ), e, set->dsize * (map->size - (i +1 ))); +/* Extensions must be initialized to zero */ +memset (e,0 , set->dsize); } }
@@ -192,7 +194,7 @@ list_set_add(struct ip_set *set, u32 i, struct set_adt_elem *d,ip_set_timeout_set (ext_timeout (e, set), ext->timeout);if (SET_WITH_COUNTER (set))ip_set_init_counter (ext_counter (e, set), ext); -if (SET_WITH_COMMENT (set) && ext->comment) +if (SET_WITH_COMMENT (set))ip_set_init_comment (ext_comment (e, set), ext);return 0 ; }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 27/33 netfilter: ipset: Use a common function at listing the extensions
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
--- include/linux/netfilter/ipset/ip_set.h | 21 +++++++++++++++++++++ net/netfilter/ipset/ip_set_bitmap_gen.h | 29 ++++++++++------------------- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 11 ----------- net/netfilter/ipset/ip_set_hash_gen.h | 11 +---------- net/netfilter/ipset/ip_set_list_set.c | 11 +---------- 5 files changed, 33 insertions(+), 50 deletions(-)
include/linux/netfilter/ipset/ip_set.h +21 -0
@@ -461,6 +461,27 @@ bitmap_bytes(u32 a, u32 b)#include <linux/netfilter/ipset/ip_set_timeout.h> #include <linux/netfilter/ipset/ip_set_comment.h> +static inline int +ip_set_put_extensions (struct sk_buff *skb,const struct ip_set *set, +const void *e,bool active) +{ +if (SET_WITH_TIMEOUT (set)) { +unsigned long *timeout =ext_timeout (e, set); + +if (nla_put_net32 (skb,IPSET_ATTR_TIMEOUT , +htonl (active ?ip_set_timeout_get (timeout) + : *timeout))) +return -EMSGSIZE ; + } +if (SET_WITH_COUNTER (set) && +ip_set_put_counter (skb,ext_counter (e, set))) +return -EMSGSIZE ; +if (SET_WITH_COMMENT (set) && +ip_set_put_comment (skb,ext_comment (e, set))) +return -EMSGSIZE ; +return 0 ; +} +#define IP_SET_INIT_KEXT (skb, opt, set) \ { .bytes = (skb)->len, .packets = 1, \ .timeout = ip_set_adt_opt_timeout(opt, set) }
net/netfilter/ipset/ip_set_bitmap_gen.h +10 -19
@@ -183,6 +183,14 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext,return 0 ; } +#ifndef IP_SET_BITMAP_STORED_TIMEOUT +static inline bool +mtype_is_filled (const struct mtype_elem *x) +{ +return true; +} +#endif +static int mtype_list (const struct ip_set *set,struct sk_buff *skb,struct netlink_callback *cb)
@@ -215,25 +223,8 @@ mtype_list(const struct ip_set *set, }if (mtype_do_list (skb, map, id, set->dsize)) goto nla_put_failure; -if (SET_WITH_TIMEOUT (set)) { -#ifdef IP_SET_BITMAP_STORED_TIMEOUT -if (nla_put_net32 (skb,IPSET_ATTR_TIMEOUT , -htonl (ip_set_timeout_stored (map, id, -ext_timeout (x, set), - set->dsize)))) - goto nla_put_failure; -#else -if (nla_put_net32 (skb,IPSET_ATTR_TIMEOUT , -htonl (ip_set_timeout_get ( -ext_timeout (x, set))))) - goto nla_put_failure; -#endif - } -if (SET_WITH_COUNTER (set) && -ip_set_put_counter (skb,ext_counter (x, set))) - goto nla_put_failure; -if (SET_WITH_COMMENT (set) && -ip_set_put_comment (skb,ext_comment (x, set))) +if (ip_set_put_extensions (skb, set, x, +mtype_is_filled ((const struct mtype_elem *) x))) goto nla_put_failure;ipset_nest_end (skb, nested); }
net/netfilter/ipset/ip_set_bitmap_ipmac.c +0 -11
@@ -176,17 +176,6 @@ bitmap_ipmac_do_del(const struct bitmap_ipmac_adt_elem *e,return !test_and_clear_bit (e->id, map->members); } -static inline unsigned long -ip_set_timeout_stored (struct bitmap_ipmac *map,u32 id,unsigned long *timeout, -size_t dsize) -{ -const struct bitmap_ipmac_elem *elem = -get_elem (map->extensions, id, dsize); - -return elem->filled ==MAC_FILLED ?ip_set_timeout_get (timeout) : - *timeout; -} -static inline int bitmap_ipmac_do_list (struct sk_buff *skb,const struct bitmap_ipmac *map,u32 id,size_t dsize)
net/netfilter/ipset/ip_set_hash_gen.h +1 -10
@@ -961,16 +961,7 @@ mtype_list(const struct ip_set *set, }if (mtype_data_list (skb, e)) goto nla_put_failure; -if (SET_WITH_TIMEOUT (set) && -nla_put_net32 (skb,IPSET_ATTR_TIMEOUT , -htonl (ip_set_timeout_get ( -ext_timeout (e, set))))) - goto nla_put_failure; -if (SET_WITH_COUNTER (set) && -ip_set_put_counter (skb,ext_counter (e, set))) - goto nla_put_failure; -if (SET_WITH_COMMENT (set) && -ip_set_put_comment (skb,ext_comment (e, set))) +if (ip_set_put_extensions (skb, set, e, true)) goto nla_put_failure;ipset_nest_end (skb, nested); }
net/netfilter/ipset/ip_set_list_set.c +1 -10
@@ -512,16 +512,7 @@ list_set_list(const struct ip_set *set,if (nla_put_string (skb,IPSET_ATTR_NAME ,ip_set_name_byindex (e->id))) goto nla_put_failure; -if (SET_WITH_TIMEOUT (set) && -nla_put_net32 (skb,IPSET_ATTR_TIMEOUT , -htonl (ip_set_timeout_get ( -ext_timeout (e, set))))) - goto nla_put_failure; -if (SET_WITH_COUNTER (set) && -ip_set_put_counter (skb,ext_counter (e, set))) - goto nla_put_failure; -if (SET_WITH_COMMENT (set) && -ip_set_put_comment (skb,ext_comment (e, set))) +if (ip_set_put_extensions (skb, set, e, true)) goto nla_put_failure;ipset_nest_end (skb, nested); }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 28/33 netfiler: ipset: Add net namespace for ipset
In reply to Pablo Neira AyusoFrom: Vitaly Lavrov <[email protected]>
This patch adds netns support for ipset.
Major changes were made in ip_set_core.c and ip_set.h.
Global variables are moved to per net namespace.
Added initialization code and the destruction of the network namespace ipset subsystem. In the prototypes of public functions ip_set_* added parameter "struct net*".
The remaining corrections related to the change prototypes of public functions ip_set_*.
The patch for git://git.netfilter.org/ipset.git commit 6a4ec96c0b8caac5c35474e40e319704d92ca347
--- include/linux/netfilter/ipset/ip_set.h | 16 +- net/netfilter/ipset/ip_set_bitmap_ip.c | 3 +- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 2 +- net/netfilter/ipset/ip_set_bitmap_port.c | 3 +- net/netfilter/ipset/ip_set_core.c | 288 +++++++++++++++++++---------- net/netfilter/ipset/ip_set_hash_gen.h | 3 +- net/netfilter/ipset/ip_set_list_set.c | 31 ++-- net/netfilter/xt_set.c | 40 ++-- net/sched/em_ipset.c | 7 +- 9 files changed, 245 insertions(+), 148 deletions(-)
include/linux/netfilter/ipset/ip_set.h +9 -7
@@ -184,7 +184,8 @@ struct ip_set_type {u8 revision_min, revision_max;/* Create set */ -int (*create)(struct ip_set *set,struct nlattr *tb[],u32 flags); +int (*create)(struct net *net,struct ip_set *set, +struct nlattr *tb[],u32 flags);/* Attribute policies */ const struct nla_policy create_policy[IPSET_ATTR_CREATE_MAX +1 ];
@@ -316,12 +317,13 @@ ip_set_init_counter(struct ip_set_counter *counter, }/* register and unregister set references */ -extern ip_set_id_t ip_set_get_byname (const char *name,struct ip_set **set); -extern void ip_set_put_byindex (ip_set_id_t index); -extern const char *ip_set_name_byindex (ip_set_id_t index); -extern ip_set_id_t ip_set_nfnl_get (const char *name); -extern ip_set_id_t ip_set_nfnl_get_byindex (ip_set_id_t index); -extern void ip_set_nfnl_put (ip_set_id_t index); +extern ip_set_id_t ip_set_get_byname (struct net *net, +const char *name,struct ip_set **set); +extern void ip_set_put_byindex (struct net *net,ip_set_id_t index); +extern const char *ip_set_name_byindex (struct net *net,ip_set_id_t index); +extern ip_set_id_t ip_set_nfnl_get (struct net *net,const char *name); +extern ip_set_id_t ip_set_nfnl_get_byindex (struct net *net,ip_set_id_t index); +extern void ip_set_nfnl_put (struct net *net,ip_set_id_t index);/* API for iptables set match, and SET target */
net/netfilter/ipset/ip_set_bitmap_ip.c +2 -1
@@ -242,7 +242,8 @@ init_map_ip(struct ip_set *set, struct bitmap_ip *map, }static int -bitmap_ip_create (struct ip_set *set,struct nlattr *tb[],u32 flags) +bitmap_ip_create (struct net *net,struct ip_set *set,struct nlattr *tb[], +u32 flags) {struct bitmap_ip *map;u32 first_ip =0 , last_ip =0 , hosts;
net/netfilter/ipset/ip_set_bitmap_ipmac.c +1 -1
@@ -309,7 +309,7 @@ init_map_ipmac(struct ip_set *set, struct bitmap_ipmac *map, }static int -bitmap_ipmac_create (struct ip_set *set,struct nlattr *tb[], +bitmap_ipmac_create (struct net *net,struct ip_set *set,struct nlattr *tb[],u32 flags) {u32 first_ip =0 , last_ip =0 ;
net/netfilter/ipset/ip_set_bitmap_port.c +2 -1
@@ -228,7 +228,8 @@ init_map_port(struct ip_set *set, struct bitmap_port *map, }static int -bitmap_port_create (struct ip_set *set,struct nlattr *tb[],u32 flags) +bitmap_port_create (struct net *net,struct ip_set *set,struct nlattr *tb[], +u32 flags) {struct bitmap_port *map;u16 first_port, last_port;
net/netfilter/ipset/ip_set_core.c +187 -101
726 lines not on this page · raw message
net/netfilter/ipset/ip_set_hash_gen.h +2 -1
@@ -1011,7 +1011,8 @@ static const struct ip_set_type_variant mtype_variant = {#ifdef IP_SET_EMIT_CREATE static int -IPSET_TOKEN (HTYPE ,_create )(struct ip_set *set,struct nlattr *tb[],u32 flags) +IPSET_TOKEN (HTYPE ,_create )(struct net *net,struct ip_set *set, +struct nlattr *tb[],u32 flags) {u32 hashsize =IPSET_DEFAULT_HASHSIZE , maxelem =IPSET_DEFAULT_MAXELEM ;u8 hbits;
net/netfilter/ipset/ip_set_list_set.c +18 -13
@@ -39,6 +39,7 @@ struct set_adt_elem {struct list_set {u32 size;/* size of set list array */ struct timer_list gc;/* garbage collection */ +struct net *net;/* namespace */ struct set_elem members[0 ];/* the set members */ };
@@ -171,7 +172,7 @@ list_set_add(struct ip_set *set, u32 i, struct set_adt_elem *d,if (e->id !=IPSET_INVALID_ID ) {if (i == map->size -1 ) {/* Last element replaced: e.g. add new,before,last */ -ip_set_put_byindex (e->id); +ip_set_put_byindex (map->net, e->id);ip_set_ext_destroy (set, e); }else { struct set_elem *x = list_set_elem(set, map,
@@ -179,7 +180,7 @@ list_set_add(struct ip_set *set, u32 i, struct set_adt_elem *d,/* Last element pushed off */ if (x->id !=IPSET_INVALID_ID ) { -ip_set_put_byindex (x->id); +ip_set_put_byindex (map->net, x->id);ip_set_ext_destroy (set, x); } memmove(list_set_elem(set, map, i + 1), e,
@@ -205,7 +206,7 @@ list_set_del(struct ip_set *set, u32 i)struct list_set *map = set->data;struct set_elem *e =list_set_elem (set, map, i); -ip_set_put_byindex (e->id); +ip_set_put_byindex (map->net, e->id);ip_set_ext_destroy (set, e);if (i < map->size -1 )
@@ -307,7 +308,7 @@ list_set_uadd(struct ip_set *set, void *value, const struct ip_set_ext *ext,if (SET_WITH_COMMENT (set))ip_set_init_comment (ext_comment (e, set), ext);/* Set is already added to the list */ -ip_set_put_byindex (d->id); +ip_set_put_byindex (map->net, d->id);return 0 ; } insert:
@@ -366,6 +367,7 @@ static int list_set_uadt(struct ip_set *set, struct nlattr *tb[], enum ipset_adt adt, u32 *lineno, u32 flags, bool retried) { + struct list_set *map = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct set_adt_elem e = { .refid =IPSET_INVALID_ID };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);
@@ -385,7 +387,7 @@ list_set_uadt(struct ip_set *set, struct nlattr *tb[], ret =ip_set_get_extensions (set, tb, &ext);if (ret)return ret; - e.id =ip_set_get_byname (nla_data (tb[IPSET_ATTR_NAME ]), &s); + e.id =ip_set_get_byname (map->net,nla_data (tb[IPSET_ATTR_NAME ]), &s);if (e.id ==IPSET_INVALID_ID )return -IPSET_ERR_NAME ;/* "Loop detection" */
@@ -405,7 +407,8 @@ list_set_uadt(struct ip_set *set, struct nlattr *tb[], }if (tb[IPSET_ATTR_NAMEREF ]) { - e.refid =ip_set_get_byname (nla_data (tb[IPSET_ATTR_NAMEREF ]), + e.refid =ip_set_get_byname (map->net, +nla_data (tb[IPSET_ATTR_NAMEREF ]), &s);if (e.refid ==IPSET_INVALID_ID ) { ret = -IPSET_ERR_NAMEREF ;
@@ -421,9 +424,9 @@ list_set_uadt(struct ip_set *set, struct nlattr *tb[], finish:if (e.refid !=IPSET_INVALID_ID ) -ip_set_put_byindex (e.refid); +ip_set_put_byindex (map->net, e.refid);if (adt !=IPSET_ADD || ret) -ip_set_put_byindex (e.id); +ip_set_put_byindex (map->net, e.id);return ip_set_eexist (ret, flags) ?0 : ret; }
@@ -438,7 +441,7 @@ list_set_flush(struct ip_set *set)for (i =0 ; i < map->size; i++) { e =list_set_elem (set, map, i);if (e->id !=IPSET_INVALID_ID ) { -ip_set_put_byindex (e->id); +ip_set_put_byindex (map->net, e->id);ip_set_ext_destroy (set, e); e->id =IPSET_INVALID_ID ; }
@@ -510,7 +513,7 @@ list_set_list(const struct ip_set *set, goto nla_put_failure; }if (nla_put_string (skb,IPSET_ATTR_NAME , -ip_set_name_byindex (e->id))) +ip_set_name_byindex (map->net, e->id))) goto nla_put_failure;if (ip_set_put_extensions (skb, set, e, true)) goto nla_put_failure;
@@ -587,7 +590,7 @@ list_set_gc_init(struct ip_set *set, void (*gc)(unsigned long ul_set))/* Create list:set type of sets */ static bool -init_list_set (struct ip_set *set,u32 size) +init_list_set (struct net *net,struct ip_set *set,u32 size) {struct list_set *map;struct set_elem *e;
@@ -598,6 +601,7 @@ init_list_set(struct ip_set *set, u32 size)return false; map->size = size; + map->net = net; set->data = map;for (i =0 ; i < size; i++) {
@@ -609,7 +613,8 @@ init_list_set(struct ip_set *set, u32 size) }static int -list_set_create (struct ip_set *set,struct nlattr *tb[],u32 flags) +list_set_create (struct net *net,struct ip_set *set,struct nlattr *tb[], +u32 flags) {u32 size =IP_SET_LIST_DEFAULT_SIZE ;
@@ -625,7 +630,7 @@ list_set_create(struct ip_set *set, struct nlattr *tb[], u32 flags) set->variant = &set_variant; set->dsize =ip_set_elem_len (set, tb,sizeof (struct set_elem )); -if (!init_list_set (set, size)) +if (!init_list_set (net, set, size))return -ENOMEM ;if (tb[IPSET_ATTR_TIMEOUT ]) { set->timeout =ip_set_timeout_uget (tb[IPSET_ATTR_TIMEOUT ]);
net/netfilter/xt_set.c +20 -20
@@ -81,7 +81,7 @@ set_match_v0_checkentry(const struct xt_mtchk_param *par)struct xt_set_info_match_v0 *info = par->matchinfo;ip_set_id_t index; - index =ip_set_nfnl_get_byindex (info->match_set.index); + index =ip_set_nfnl_get_byindex (par->net, info->match_set.index);if (index ==IPSET_INVALID_ID ) { pr_warning("Cannot find set indentified by id %u to match\n",
@@ -91,7 +91,7 @@ set_match_v0_checkentry(const struct xt_mtchk_param *par)if (info->match_set.u.flags[IPSET_DIM_MAX -1 ] !=0 ) {pr_warning ("Protocol error: set match dimension " "is over the limit!\n" ); -ip_set_nfnl_put (info->match_set.index); +ip_set_nfnl_put (par->net, info->match_set.index);return -ERANGE ; }
@@ -106,7 +106,7 @@ set_match_v0_destroy(const struct xt_mtdtor_param *par) {struct xt_set_info_match_v0 *info = par->matchinfo; -ip_set_nfnl_put (info->match_set.index); +ip_set_nfnl_put (par->net, info->match_set.index); }/* Revision 1 match */
@@ -131,7 +131,7 @@ set_match_v1_checkentry(const struct xt_mtchk_param *par)struct xt_set_info_match_v1 *info = par->matchinfo;ip_set_id_t index; - index =ip_set_nfnl_get_byindex (info->match_set.index); + index =ip_set_nfnl_get_byindex (par->net, info->match_set.index);if (index ==IPSET_INVALID_ID ) { pr_warning("Cannot find set indentified by id %u to match\n",
@@ -141,7 +141,7 @@ set_match_v1_checkentry(const struct xt_mtchk_param *par)if (info->match_set.dim >IPSET_DIM_MAX ) {pr_warning ("Protocol error: set match dimension " "is over the limit!\n" ); -ip_set_nfnl_put (info->match_set.index); +ip_set_nfnl_put (par->net, info->match_set.index);return -ERANGE ; }
@@ -153,7 +153,7 @@ set_match_v1_destroy(const struct xt_mtdtor_param *par) {struct xt_set_info_match_v1 *info = par->matchinfo; -ip_set_nfnl_put (info->match_set.index); +ip_set_nfnl_put (par->net, info->match_set.index); }/* Revision 3 match */
@@ -228,7 +228,7 @@ set_target_v0_checkentry(const struct xt_tgchk_param *par)ip_set_id_t index;if (info->add_set.index !=IPSET_INVALID_ID ) { - index =ip_set_nfnl_get_byindex (info->add_set.index); + index =ip_set_nfnl_get_byindex (par->net, info->add_set.index);if (index ==IPSET_INVALID_ID ) {pr_warning ("Cannot find add_set index %u as target\n" , info->add_set.index);
@@ -237,12 +237,12 @@ set_target_v0_checkentry(const struct xt_tgchk_param *par) }if (info->del_set.index !=IPSET_INVALID_ID ) { - index =ip_set_nfnl_get_byindex (info->del_set.index); + index =ip_set_nfnl_get_byindex (par->net, info->del_set.index);if (index ==IPSET_INVALID_ID ) {pr_warning ("Cannot find del_set index %u as target\n" , info->del_set.index);if (info->add_set.index !=IPSET_INVALID_ID ) -ip_set_nfnl_put (info->add_set.index); +ip_set_nfnl_put (par->net, info->add_set.index);return -ENOENT ; } }
@@ -251,9 +251,9 @@ set_target_v0_checkentry(const struct xt_tgchk_param *par)pr_warning ("Protocol error: SET target dimension " "is over the limit!\n" );if (info->add_set.index !=IPSET_INVALID_ID ) -ip_set_nfnl_put (info->add_set.index); +ip_set_nfnl_put (par->net, info->add_set.index);if (info->del_set.index !=IPSET_INVALID_ID ) -ip_set_nfnl_put (info->del_set.index); +ip_set_nfnl_put (par->net, info->del_set.index);return -ERANGE ; }
@@ -270,9 +270,9 @@ set_target_v0_destroy(const struct xt_tgdtor_param *par)const struct xt_set_info_target_v0 *info = par->targinfo;if (info->add_set.index !=IPSET_INVALID_ID ) -ip_set_nfnl_put (info->add_set.index); +ip_set_nfnl_put (par->net, info->add_set.index);if (info->del_set.index !=IPSET_INVALID_ID ) -ip_set_nfnl_put (info->del_set.index); +ip_set_nfnl_put (par->net, info->del_set.index); }/* Revision 1 target */
@@ -301,7 +301,7 @@ set_target_v1_checkentry(const struct xt_tgchk_param *par)ip_set_id_t index;if (info->add_set.index !=IPSET_INVALID_ID ) { - index =ip_set_nfnl_get_byindex (info->add_set.index); + index =ip_set_nfnl_get_byindex (par->net, info->add_set.index);if (index ==IPSET_INVALID_ID ) {pr_warning ("Cannot find add_set index %u as target\n" , info->add_set.index);
@@ -310,12 +310,12 @@ set_target_v1_checkentry(const struct xt_tgchk_param *par) }if (info->del_set.index !=IPSET_INVALID_ID ) { - index =ip_set_nfnl_get_byindex (info->del_set.index); + index =ip_set_nfnl_get_byindex (par->net, info->del_set.index);if (index ==IPSET_INVALID_ID ) {pr_warning ("Cannot find del_set index %u as target\n" , info->del_set.index);if (info->add_set.index !=IPSET_INVALID_ID ) -ip_set_nfnl_put (info->add_set.index); +ip_set_nfnl_put (par->net, info->add_set.index);return -ENOENT ; } }
@@ -324,9 +324,9 @@ set_target_v1_checkentry(const struct xt_tgchk_param *par)pr_warning ("Protocol error: SET target dimension " "is over the limit!\n" );if (info->add_set.index !=IPSET_INVALID_ID ) -ip_set_nfnl_put (info->add_set.index); +ip_set_nfnl_put (par->net, info->add_set.index);if (info->del_set.index !=IPSET_INVALID_ID ) -ip_set_nfnl_put (info->del_set.index); +ip_set_nfnl_put (par->net, info->del_set.index);return -ERANGE ; }
@@ -339,9 +339,9 @@ set_target_v1_destroy(const struct xt_tgdtor_param *par)const struct xt_set_info_target_v1 *info = par->targinfo;if (info->add_set.index !=IPSET_INVALID_ID ) -ip_set_nfnl_put (info->add_set.index); +ip_set_nfnl_put (par->net, info->add_set.index);if (info->del_set.index !=IPSET_INVALID_ID ) -ip_set_nfnl_put (info->del_set.index); +ip_set_nfnl_put (par->net, info->del_set.index); }/* Revision 2 target */
net/sched/em_ipset.c +4 -3
@@ -24,11 +24,12 @@ static int em_ipset_change(struct tcf_proto *tp, void *data, int data_len, {struct xt_set_info *set = data;ip_set_id_t index; +struct net *net =qdisc_dev (tp->q)->nd_net;if (data_len !=sizeof (*set))return -EINVAL ; - index =ip_set_nfnl_get_byindex (set->index); + index =ip_set_nfnl_get_byindex (net, set->index);if (index ==IPSET_INVALID_ID )return -ENOENT ;
@@ -37,7 +38,7 @@ static int em_ipset_change(struct tcf_proto *tp, void *data, int data_len,if (em->data)return 0 ; -ip_set_nfnl_put (index); +ip_set_nfnl_put (net, index);return -ENOMEM ; }
@@ -45,7 +46,7 @@ static void em_ipset_destroy(struct tcf_proto *p, struct tcf_ematch *em) {const struct xt_set_info *set = (const void *) em->data;if (set) { -ip_set_nfnl_put (set->index); +ip_set_nfnl_put (qdisc_dev (p->q)->nd_net, set->index);kfree ((void *) em->data); } }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 29/33 netfilter: ipset: Add hash:net,port,net module to kernel.
In reply to Pablo Neira AyusoFrom: Oliver Smith <[email protected]>
This adds a new set that provides similar functionality to ip,port,net but permits arbitrary size subnets for both the first and last parameter.
--- net/netfilter/ipset/Kconfig | 9 + net/netfilter/ipset/Makefile | 1 + net/netfilter/ipset/ip_set_hash_netportnet.c | 588 ++++++++++++++++++++++++++ 3 files changed, 598 insertions(+) create mode 100644 net/netfilter/ipset/ip_set_hash_netportnet.c
net/netfilter/ipset/Kconfig +9 -0
@@ -90,6 +90,15 @@ config IP_SET_HASH_IPPORTNET To compile it as a module, choose M here. If unsure, say N. +config IP_SET_HASH_NETPORTNET + tristate "hash:net,port,net set support" + depends on IP_SET + help + This option adds the hash:net,port,net set type support, by which + one can store two IPv4/IPv6 subnets, and a protocol/port in a set. + + To compile it as a module, choose M here. If unsure, say N. + config IP_SET_HASH_NET tristate "hash:net set support" depends on IP_SET
net/netfilter/ipset/Makefile +1 -0
@@ -21,6 +21,7 @@ obj-$(CONFIG_IP_SET_HASH_NET) += ip_set_hash_net.o obj-$(CONFIG_IP_SET_HASH_NETPORT) += ip_set_hash_netport.o obj-$(CONFIG_IP_SET_HASH_NETIFACE) += ip_set_hash_netiface.o obj-$(CONFIG_IP_SET_HASH_NETNET) += ip_set_hash_netnet.o +obj-$(CONFIG_IP_SET_HASH_NETPORTNET) += ip_set_hash_netportnet.o # list types obj-$(CONFIG_IP_SET_LIST_SET) += ip_set_list_set.o
net/netfilter/ipset/ip_set_hash_netportnet.c new file +588 -0
588 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 30/33 netfilter: nfnetlink_queue: use proper net namespace to allocate skb
In reply to Pablo Neira AyusoFrom: Gao feng <[email protected]>
Use proper net struct to allocate skb, otherwise netlink mmap will have no effect.
--- net/netfilter/nfnetlink_queue_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/netfilter/nfnetlink_queue_core.c +3 -3
@@ -298,7 +298,7 @@ nfqnl_put_packet_info(struct sk_buff *nlskb, struct sk_buff *packet, }static struct sk_buff * -nfqnl_build_packet_message (struct nfqnl_instance *queue, +nfqnl_build_packet_message (struct net *net,struct nfqnl_instance *queue,struct nf_queue_entry *entry,__be32 **packet_id_ptr) {
@@ -372,7 +372,7 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,if (queue->flags &NFQA_CFG_F_CONNTRACK ) ct =nfqnl_ct_get (entskb, &size, &ctinfo); - skb =nfnetlink_alloc_skb (&init_net, size, queue->peer_portid, + skb =nfnetlink_alloc_skb (net, size, queue->peer_portid,GFP_ATOMIC );if (!skb)return NULL ;
@@ -525,7 +525,7 @@ __nfqnl_enqueue_packet(struct net *net, struct nfqnl_instance *queue,__be32 *packet_id_ptr;int failopen =0 ; - nskb =nfqnl_build_packet_message (queue, entry, &packet_id_ptr); + nskb =nfqnl_build_packet_message (net, queue, entry, &packet_id_ptr);if (nskb ==NULL ) { err = -ENOMEM ; goto err_out;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 31/33 netfilter: nfnetlink_log: use proper net to allocate skb
In reply to Pablo Neira AyusoFrom: Gao feng <[email protected]>
Use proper net struct to allocate skb, otherwise
netlink mmap will be of no effect.
--- net/netfilter/nfnetlink_log.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
net/netfilter/nfnetlink_log.c +6 -5
@@ -319,7 +319,8 @@ nfulnl_set_flags(struct nfulnl_instance *inst, u_int16_t flags) }static struct sk_buff * -nfulnl_alloc_skb (u32 peer_portid,unsigned int inst_size,unsigned int pkt_size) +nfulnl_alloc_skb (struct net *net,u32 peer_portid,unsigned int inst_size, +unsigned int pkt_size) {struct sk_buff *skb;unsigned int n;
@@ -328,13 +329,13 @@ nfulnl_alloc_skb(u32 peer_portid, unsigned int inst_size, unsigned int pkt_size)* message. WARNING: has to be <= 128k due to slab restrictions */ n =max (inst_size, pkt_size); - skb =nfnetlink_alloc_skb (&init_net, n, peer_portid,GFP_ATOMIC ); + skb =nfnetlink_alloc_skb (net, n, peer_portid,GFP_ATOMIC );if (!skb) {if (n > pkt_size) {/* try to allocate only as much as we need for current * packet */ - skb =nfnetlink_alloc_skb (&init_net, pkt_size, + skb =nfnetlink_alloc_skb (net, pkt_size, peer_portid,GFP_ATOMIC );if (!skb) pr_err("nfnetlink_log: can't even alloc %u bytes\n",
@@ -702,8 +703,8 @@ nfulnl_log_packet(struct net *net, }if (!inst->skb) { - inst->skb =nfulnl_alloc_skb (inst->peer_portid, inst->nlbufsiz, - size); + inst->skb =nfulnl_alloc_skb (net, inst->peer_portid, + inst->nlbufsiz, size);if (!inst->skb) goto alloc_failure; }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 32/33 netfilter: nf_ct_sip: consolidate NAT hook functions
In reply to Pablo Neira AyusoFrom: "[email protected]" <[email protected]>
There are currently seven different NAT hooks used in both nf_conntrack_sip and nf_nat_sip, each of the hooks is exported in nf_conntrack_sip, then set from the nf_nat_sip NAT helper.
And because each of them is exported there is quite some overhead introduced due of this.
By introducing nf_nat_sip_hooks I am able to reduce both text/data somewhat. For nf_conntrack_sip e. g. I get
text data bss dec old 15243 5256 32 20531 new 15010 5192 32 20234
--- include/linux/netfilter/nf_conntrack_sip.h | 107 ++++++++++++----------- net/netfilter/nf_conntrack_sip.c | 127 ++++++++-------------------- net/netfilter/nf_nat_sip.c | 35 +++----- 3 files changed, 107 insertions(+), 162 deletions(-)
include/linux/netfilter/nf_conntrack_sip.h +58 -49
@@ -107,55 +107,64 @@ enum sdp_header_types { SDP_HDR_MEDIA, }; -extern unsigned int (*nf_nat_sip_hook)(struct sk_buff *skb, -unsigned int protoff, -unsigned int dataoff, -const char **dptr, -unsigned int *datalen); -extern void (*nf_nat_sip_seq_adjust_hook)(struct sk_buff *skb, -unsigned int protoff,s16 off); -extern unsigned int (*nf_nat_sip_expect_hook)(struct sk_buff *skb, -unsigned int protoff, -unsigned int dataoff, -const char **dptr, -unsigned int *datalen, -struct nf_conntrack_expect *exp, -unsigned int matchoff, -unsigned int matchlen); -extern unsigned int (*nf_nat_sdp_addr_hook)(struct sk_buff *skb, -unsigned int protoff, -unsigned int dataoff, -const char **dptr, -unsigned int *datalen, -unsigned int sdpoff, -enum sdp_header_types type, -enum sdp_header_types term, -const union nf_inet_addr *addr); -extern unsigned int (*nf_nat_sdp_port_hook)(struct sk_buff *skb, -unsigned int protoff, -unsigned int dataoff, -const char **dptr, -unsigned int *datalen, -unsigned int matchoff, -unsigned int matchlen, -u_int16_t port); -extern unsigned int (*nf_nat_sdp_session_hook)(struct sk_buff *skb, -unsigned int protoff, -unsigned int dataoff, -const char **dptr, -unsigned int *datalen, -unsigned int sdpoff, -const union nf_inet_addr *addr); -extern unsigned int (*nf_nat_sdp_media_hook)(struct sk_buff *skb, -unsigned int protoff, -unsigned int dataoff, -const char **dptr, -unsigned int *datalen, -struct nf_conntrack_expect *rtp_exp, -struct nf_conntrack_expect *rtcp_exp, -unsigned int mediaoff, -unsigned int medialen, -union nf_inet_addr *rtp_addr); +struct nf_nat_sip_hooks { +unsigned int (*msg)(struct sk_buff *skb, +unsigned int protoff, +unsigned int dataoff, +const char **dptr, +unsigned int *datalen); + +void (*seq_adjust)(struct sk_buff *skb, +unsigned int protoff,s16 off); + +unsigned int (*expect)(struct sk_buff *skb, +unsigned int protoff, +unsigned int dataoff, +const char **dptr, +unsigned int *datalen, +struct nf_conntrack_expect *exp, +unsigned int matchoff, +unsigned int matchlen); + +unsigned int (*sdp_addr)(struct sk_buff *skb, +unsigned int protoff, +unsigned int dataoff, +const char **dptr, +unsigned int *datalen, +unsigned int sdpoff, +enum sdp_header_types type, +enum sdp_header_types term, +const union nf_inet_addr *addr); + +unsigned int (*sdp_port)(struct sk_buff *skb, +unsigned int protoff, +unsigned int dataoff, +const char **dptr, +unsigned int *datalen, +unsigned int matchoff, +unsigned int matchlen, +u_int16_t port); + +unsigned int (*sdp_session)(struct sk_buff *skb, +unsigned int protoff, +unsigned int dataoff, +const char **dptr, +unsigned int *datalen, +unsigned int sdpoff, +const union nf_inet_addr *addr); + +unsigned int (*sdp_media)(struct sk_buff *skb, +unsigned int protoff, +unsigned int dataoff, +const char **dptr, +unsigned int *datalen, +struct nf_conntrack_expect *rtp_exp, +struct nf_conntrack_expect *rtcp_exp, +unsigned int mediaoff, +unsigned int medialen, +union nf_inet_addr *rtp_addr); +}; +extern const struct nf_nat_sip_hooks *nf_nat_sip_hooks; extern int ct_sip_parse_request(const struct nf_conn *ct, const char *dptr, unsigned int datalen,
net/netfilter/nf_conntrack_sip.c +35 -92
214 lines not on this page · raw message
net/netfilter/nf_nat_sip.c +14 -21
@@ -625,33 +625,26 @@ static struct nf_ct_helper_expectfn sip_nat = { static void __exit nf_nat_sip_fini(void) { -RCU_INIT_POINTER (nf_nat_sip_hook,NULL ); -RCU_INIT_POINTER (nf_nat_sip_seq_adjust_hook,NULL ); -RCU_INIT_POINTER (nf_nat_sip_expect_hook,NULL ); -RCU_INIT_POINTER (nf_nat_sdp_addr_hook,NULL ); -RCU_INIT_POINTER (nf_nat_sdp_port_hook,NULL ); -RCU_INIT_POINTER (nf_nat_sdp_session_hook,NULL ); -RCU_INIT_POINTER (nf_nat_sdp_media_hook,NULL ); +RCU_INIT_POINTER (nf_nat_sip_hooks,NULL ); +nf_ct_helper_expectfn_unregister (&sip_nat);synchronize_rcu (); } +static const struct nf_nat_sip_hooks sip_hooks = { + .msg = nf_nat_sip, + .seq_adjust = nf_nat_sip_seq_adjust, + .expect = nf_nat_sip_expect, + .sdp_addr = nf_nat_sdp_addr, + .sdp_port = nf_nat_sdp_port, + .sdp_session = nf_nat_sdp_session, + .sdp_media = nf_nat_sdp_media, +}; +static int __init nf_nat_sip_init (void ) { -BUG_ON (nf_nat_sip_hook !=NULL ); -BUG_ON (nf_nat_sip_seq_adjust_hook !=NULL ); -BUG_ON (nf_nat_sip_expect_hook !=NULL ); -BUG_ON (nf_nat_sdp_addr_hook !=NULL ); -BUG_ON (nf_nat_sdp_port_hook !=NULL ); -BUG_ON (nf_nat_sdp_session_hook !=NULL ); -BUG_ON (nf_nat_sdp_media_hook !=NULL ); -RCU_INIT_POINTER (nf_nat_sip_hook, nf_nat_sip); -RCU_INIT_POINTER (nf_nat_sip_seq_adjust_hook, nf_nat_sip_seq_adjust); -RCU_INIT_POINTER (nf_nat_sip_expect_hook, nf_nat_sip_expect); -RCU_INIT_POINTER (nf_nat_sdp_addr_hook, nf_nat_sdp_addr); -RCU_INIT_POINTER (nf_nat_sdp_port_hook, nf_nat_sdp_port); -RCU_INIT_POINTER (nf_nat_sdp_session_hook, nf_nat_sdp_session); -RCU_INIT_POINTER (nf_nat_sdp_media_hook, nf_nat_sdp_media); +BUG_ON (nf_nat_sip_hooks !=NULL ); +RCU_INIT_POINTER (nf_nat_sip_hooks, &sip_hooks);nf_ct_helper_expectfn_register (&sip_nat);return 0 ; }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 33/33 netfilter: cttimeout: allow to set/get default protocol timeouts
In reply to Pablo Neira AyusoDefault timeouts are currently set via proc/sysctl interface, the typical pattern is a file name like:
/proc/sys/net/netfilter/nf_conntrack_PROTOCOL_timeout_STATE
This results in one entry per default protocol state timeout. This patch simplifies this by allowing to set default protocol timeouts via cttimeout netlink interface.
This should allow us to get rid of the existing proc/sysctl code in the midterm.
--- include/uapi/linux/netfilter/nfnetlink_cttimeout.h | 2 + net/netfilter/nfnetlink_cttimeout.c | 161 +++++++++++++++++++- 2 files changed, 155 insertions(+), 8 deletions(-)
include/uapi/linux/netfilter/nfnetlink_cttimeout.h +2 -0
@@ -6,6 +6,8 @@ enum ctnl_timeout_msg_types {IPCTNL_MSG_TIMEOUT_NEW ,IPCTNL_MSG_TIMEOUT_GET ,IPCTNL_MSG_TIMEOUT_DELETE , +IPCTNL_MSG_TIMEOUT_DEFAULT_SET , +IPCTNL_MSG_TIMEOUT_DEFAULT_GET , IPCTNL_MSG_TIMEOUT_MAX };
net/netfilter/nfnetlink_cttimeout.c +153 -8
197 lines not on this page · raw message
Signature · 1 line
1.7.10.4
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Fri, 4 Oct 2013 10:32:45 +0200
Quoted 2 lines
The following patchset contains Netfilter updates for your net-next tree, mostly ipset improvements and enhancements features, they are:
...
Pulled, thanks a lot Pablo.