Netfilter updates for net-next
Subsystems (7)
Pablo Neira Ayuso
maintainercover Netfilter updates for net-next
Hi David,
The following patchset contains a second batch of Netfilter updates for your net-next tree. This includes a rework of the core hook infrastructure that improves Netfilter performance by ~15% according to synthetic benchmarks. Then, a large batch with ipset updates, including a new hash:ipmac set type, via Jozsef Kadlecsik. This also includes a couple of assorted updates.
Regarding the core hook infrastructure rework to improve performance, using this simple drop-all packets ruleset from ingress:
nft add table netdev x
nft add chain netdev x y { type filter hook ingress device eth0 priority 0\; } nft add rule netdev x y drop
And generating traffic through Jesper Brouer's samples/pktgen/pktgen_bench_xmit_mode_netif_receive.sh script using -i option. perf report shows nf_tables calls in its top 10:
17.30% kpktgend_0 [nf_tables] [k] nft_do_chain
15.75% kpktgend_0 [kernel.vmlinux] [k] __netif_receive_skb_core
10.39% kpktgend_0 [nf_tables_netdev] [k] nft_do_chain_netdevI'm measuring here an improvement of ~15% in performance with this patchset, so we got +2.5Mpps more. I have used my old laptop Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz 4-cores.
This rework contains more specifically, in strict order, these patches:
1) Remove compile-time debugging from core.
2) Remove obsolete comments that predate the rcu era. These days it is well known that a Netfilter hook always runs under rcu_read_lock().
3) Remove threshold handling, this is only used by br_netfilter too. We already have specific code to handle this from br_netfilter, so remove this code from the core path.
4) Deprecate NF_STOP, as this is only used by br_netfilter.
5) Place nf_state_hook pointer into xt_action_param structure, so this structure fits into one single cacheline according to pahole. This also implicit affects nftables since it also relies on the xt_action_param structure.
6) Move state->hook_entries into nf_queue entry. The hook_entries pointer is only required by nf_queue(), so we can store this in the queue entry instead.
7) use switch() statement to handle verdict cases.
8) Remove hook_entries field from nf_hook_state structure, this is only required by nf_queue, so store it in nf_queue_entry structure.
9) Merge nf_iterate() into nf_hook_slow() that results in a much more simple and readable function.
10) Handle NF_REPEAT away from the core, so far the only client is nf_conntrack_in() and we can restart the packet processing using a simple goto to jump back there when the TCP requires it. This update required a second pass to fix fallout, fix from Arnd Bergmann.
11) Set random seed from nft_hash when no seed is specified from userspace.
12) Simplify nf_tables expression registration, in a much smarter way to save lots of boiler plate code, by Liping Zhang.
13) Simplify layer 4 protocol conntrack tracker registration, from Davide Caratti.
14) Missing CONFIG_NF_SOCKET_IPV4 dependency for udp4_lib_lookup, due to recent generalization of the socket infrastructure, from Arnd Bergmann.
15) Then, the ipset batch from Jozsef, he describes it as it follows:
* Cleanup: Remove extra whitespaces in ip_set.h
* Cleanup: Mark some of the helpers arguments as const in ip_set.h
* Cleanup: Group counter helper functions together in ip_set.h
* struct ip_set_skbinfo is introduced instead of open coded fields in skbinfo get/init helper funcions.
* Use kmalloc() in comment extension helper instead of kzalloc() because it is unnecessary to zero out the area just before explicit initialization.
* Cleanup: Split extensions into separate files.
* Cleanup: Separate memsize calculation code into dedicated function.
* Cleanup: group ip_set_put_extensions() and ip_set_get_extensions() together.
* Add element count to hash headers by Eric B Munson.
* Add element count to all set types header for uniform output across all set types.
* Count non-static extension memory into memsize calculation for userspace.
* Cleanup: Remove redundant mtype_expire() arguments, because they can be get from other parameters.
* Cleanup: Simplify mtype_expire() for hash types by removing one level of intendation.
* Make NLEN compile time constant for hash types.
* Make sure element data size is a multiple of u32 for the hash set types.
* Optimize hash creation routine, exit as early as possible.
* Make struct htype per ipset family so nets array becomes fixed size and thus simplifies the struct htype allocation.
* Collapse same condition body into a single one.
* Fix reported memory size for hash:* types, base hash bucket structure was not taken into account.
* hash:ipmac type support added to ipset by Tomasz Chilinski.
* Use setup_timer() and mod_timer() instead of init_timer() by Muhammad Falak R Wani, individually for the set type families.
16) Remove useless connlabel field in struct netns_ct, patch from Florian Westphal.
17) xt_find_table_lock() doesn't return ERR_PTR() anymore, so simplify {ip,ip6,arp}tables code that uses this.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Thanks!
----------------------------------------------------------------
The following changes since commit 17197236d62c44da127be461c63ac5cc2cce1e53:
enic: set skb->hash type properly (2016-11-02 15:32:53 -0400)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git HEAD
for you to fetch changes up to eb1a6bdc28268afa964e4c9f3399961dff9fd691:
netfilter: x_tables: simplify IS_ERR_OR_NULL to NULL test (2016-11-13 22:26:13 +0100)
----------------------------------------------------------------
Arnd Bergmann (2):
udp: provide udp{4,6}_lib_lookup for nf_socket_ipv{4,6}
netfilter: conntrack: fix NF_REPEAT handling
Davide Caratti (1):
netfilter: conntrack: simplify init/uninit of L4 protocol trackers
Eric B Munson (1):
netfilter: ipset: Add element count to hash headers
Florian Westphal (1):
netfilter: conntrack: remove unused netns_ct member
Jozsef Kadlecsik (19):
netfilter: ipset: Remove extra whitespaces in ip_set.h
netfilter: ipset: Mark some helper args as const.
netfilter: ipset: Headers file cleanup
netfilter: ipset: Improve skbinfo get/init helpers
netfilter: ipset: Use kmalloc() in comment extension helper
netfilter: ipset: Split extensions into separate files
netfilter: ipset: Separate memsize calculation code into dedicated function
netfilter: ipset: Regroup ip_set_put_extensions and add extern
netfilter: ipset: Add element count to all set types header
netfilter: ipset: Count non-static extension memory for userspace
netfilter: ipset: Remove redundant mtype_expire() arguments
netfilter: ipset: Simplify mtype_expire() for hash types
netfilter: ipset: Make NLEN compile time constant for hash types
netfilter: ipset: Make sure element data size is a multiple of u32
netfilter: ipset: Optimize hash creation routine
netfilter: ipset: Make struct htype per ipset family
netfilter: ipset: Collapse same condition body to a single one
netfilter: ipset: Fix reported memory size for hash:* types
netfilter: ipset: use setup_timer() and mod_timer().
Julia Lawall (1):
netfilter: x_tables: simplify IS_ERR_OR_NULL to NULL test
Liping Zhang (1):
netfilter: nf_tables: simplify the basic expressions' init routine
Pablo Neira Ayuso (11):
netfilter: get rid of useless debugging from core
netfilter: remove comments that predate rcu days
netfilter: kill NF_HOOK_THRESH() and state->tresh
netfilter: deprecate NF_STOP
netfilter: x_tables: move hook state into xt_action_param structure
netfilter: nf_tables: use hook state from xt_action_param structure
netfilter: use switch() to handle verdict cases from nf_hook_slow()
netfilter: remove hook_entries field from nf_hook_state
netfilter: merge nf_iterate() into nf_hook_slow()
netfilter: handle NF_REPEAT from nf_conntrack_in()
netfilter: nft_hash: get random bytes if seed is not specified
Tomasz Chilinski (1):
netfilter: ipset: hash:ipmac type support added to ipset
kbuild test robot (1):
netfilter: ipset: hash: fix boolreturn.cocci warnings
include/linux/netfilter.h | 58 ++--- include/linux/netfilter/ipset/ip_set.h | 136 ++--------- include/linux/netfilter/ipset/ip_set_bitmap.h | 2 +- include/linux/netfilter/ipset/ip_set_comment.h | 11 +- include/linux/netfilter/ipset/ip_set_counter.h | 75 ++++++ include/linux/netfilter/ipset/ip_set_skbinfo.h | 46 ++++ include/linux/netfilter/ipset/ip_set_timeout.h | 4 +- include/linux/netfilter/x_tables.h | 48 +++- include/linux/netfilter_ingress.h | 4 +- include/net/netfilter/nf_conntrack_l4proto.h | 18 +- include/net/netfilter/nf_queue.h | 1 + include/net/netfilter/nf_tables.h | 36 ++- include/net/netfilter/nf_tables_core.h | 33 +-- include/net/netns/conntrack.h | 1 - include/uapi/linux/netfilter.h | 2 +- net/bridge/br_netfilter_hooks.c | 16 +- net/bridge/netfilter/ebt_arpreply.c | 3 +- net/bridge/netfilter/ebt_log.c | 11 +- net/bridge/netfilter/ebt_nflog.c | 6 +- net/bridge/netfilter/ebt_redirect.c | 6 +- net/bridge/netfilter/ebtable_broute.c | 2 +- net/bridge/netfilter/ebtables.c | 6 +- net/bridge/netfilter/nft_meta_bridge.c | 2 +- net/bridge/netfilter/nft_reject_bridge.c | 30 ++- net/ipv4/netfilter/arp_tables.c | 26 +- net/ipv4/netfilter/ip_tables.c | 26 +- net/ipv4/netfilter/ipt_MASQUERADE.c | 3 +- net/ipv4/netfilter/ipt_REJECT.c | 4 +- net/ipv4/netfilter/ipt_SYNPROXY.c | 4 +- net/ipv4/netfilter/ipt_rpfilter.c | 2 +- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 76 ++---- net/ipv4/netfilter/nft_dup_ipv4.c | 2 +- net/ipv4/netfilter/nft_fib_ipv4.c | 14 +- net/ipv4/netfilter/nft_masq_ipv4.c | 4 +- net/ipv4/netfilter/nft_redir_ipv4.c | 3 +- net/ipv4/netfilter/nft_reject_ipv4.c | 4 +- net/ipv4/udp.c | 3 +- net/ipv6/netfilter/ip6_tables.c | 26 +- net/ipv6/netfilter/ip6t_MASQUERADE.c | 2 +- net/ipv6/netfilter/ip6t_REJECT.c | 23 +- net/ipv6/netfilter/ip6t_SYNPROXY.c | 4 +- net/ipv6/netfilter/ip6t_rpfilter.c | 3 +- net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 78 ++---- net/ipv6/netfilter/nft_dup_ipv6.c | 2 +- net/ipv6/netfilter/nft_fib_ipv6.c | 16 +- net/ipv6/netfilter/nft_masq_ipv6.c | 3 +- net/ipv6/netfilter/nft_redir_ipv6.c | 3 +- net/ipv6/netfilter/nft_reject_ipv6.c | 6 +- net/ipv6/udp.c | 3 +- net/netfilter/core.c | 86 +++---- net/netfilter/ipset/Kconfig | 9 + net/netfilter/ipset/Makefile | 1 + net/netfilter/ipset/ip_set_bitmap_gen.h | 31 ++- net/netfilter/ipset/ip_set_core.c | 20 +- net/netfilter/ipset/ip_set_hash_gen.h | 254 +++++++++----------- net/netfilter/ipset/ip_set_hash_ip.c | 10 +- net/netfilter/ipset/ip_set_hash_ipmac.c | 315 +++++++++++++++++++++++++ net/netfilter/ipset/ip_set_hash_ipmark.c | 10 +- net/netfilter/ipset/ip_set_hash_ipport.c | 6 +- net/netfilter/ipset/ip_set_hash_ipportip.c | 6 +- net/netfilter/ipset/ip_set_hash_ipportnet.c | 10 +- net/netfilter/ipset/ip_set_hash_net.c | 8 +- net/netfilter/ipset/ip_set_hash_netiface.c | 10 +- net/netfilter/ipset/ip_set_hash_netnet.c | 8 +- net/netfilter/ipset/ip_set_hash_netport.c | 10 +- net/netfilter/ipset/ip_set_hash_netportnet.c | 10 +- net/netfilter/ipset/ip_set_list_set.c | 37 ++- net/netfilter/nf_conntrack_core.c | 19 +- net/netfilter/nf_conntrack_proto.c | 85 ++++++- net/netfilter/nf_conntrack_proto_dccp.c | 48 +--- net/netfilter/nf_conntrack_proto_gre.c | 11 +- net/netfilter/nf_conntrack_proto_sctp.c | 50 +--- net/netfilter/nf_conntrack_proto_udplite.c | 50 +--- net/netfilter/nf_dup_netdev.c | 2 +- net/netfilter/nf_internals.h | 5 - net/netfilter/nf_queue.c | 35 ++- net/netfilter/nf_tables_core.c | 90 +++---- net/netfilter/nf_tables_trace.c | 8 +- net/netfilter/nfnetlink_queue.c | 2 +- net/netfilter/nft_bitwise.c | 13 +- net/netfilter/nft_byteorder.c | 13 +- net/netfilter/nft_cmp.c | 13 +- net/netfilter/nft_dynset.c | 13 +- net/netfilter/nft_fib.c | 2 +- net/netfilter/nft_fib_inet.c | 2 +- net/netfilter/nft_hash.c | 6 +- net/netfilter/nft_immediate.c | 13 +- net/netfilter/nft_log.c | 5 +- net/netfilter/nft_lookup.c | 18 +- net/netfilter/nft_meta.c | 6 +- net/netfilter/nft_payload.c | 13 +- net/netfilter/nft_queue.c | 2 +- net/netfilter/nft_range.c | 13 +- net/netfilter/nft_reject_inet.c | 18 +- net/netfilter/nft_rt.c | 4 +- net/netfilter/x_tables.c | 2 +- net/netfilter/xt_AUDIT.c | 10 +- net/netfilter/xt_LOG.c | 6 +- net/netfilter/xt_NETMAP.c | 20 +- net/netfilter/xt_NFLOG.c | 6 +- net/netfilter/xt_NFQUEUE.c | 4 +- net/netfilter/xt_REDIRECT.c | 4 +- net/netfilter/xt_TCPMSS.c | 4 +- net/netfilter/xt_TEE.c | 4 +- net/netfilter/xt_TPROXY.c | 16 +- net/netfilter/xt_addrtype.c | 10 +- net/netfilter/xt_cluster.c | 2 +- net/netfilter/xt_connlimit.c | 8 +- net/netfilter/xt_conntrack.c | 8 +- net/netfilter/xt_devgroup.c | 4 +- net/netfilter/xt_dscp.c | 2 +- net/netfilter/xt_ipvs.c | 4 +- net/netfilter/xt_nfacct.c | 2 +- net/netfilter/xt_osf.c | 10 +- net/netfilter/xt_owner.c | 2 +- net/netfilter/xt_pkttype.c | 4 +- net/netfilter/xt_policy.c | 4 +- net/netfilter/xt_recent.c | 10 +- net/netfilter/xt_set.c | 38 +-- net/netfilter/xt_socket.c | 4 +- net/openvswitch/conntrack.c | 8 +- net/sched/act_ipt.c | 12 +- net/sched/em_ipset.c | 17 +- 123 files changed, 1351 insertions(+), 1171 deletions(-) create mode 100644 include/linux/netfilter/ipset/ip_set_counter.h create mode 100644 include/linux/netfilter/ipset/ip_set_skbinfo.h create mode 100644 net/netfilter/ipset/ip_set_hash_ipmac.c
Pablo Neira Ayuso
maintainerPATCH 1/39 netfilter: get rid of useless debugging from core
This patch remove compile time code to catch inconventional verdicts. We have better ways to handle this case these days, eg. pr_debug() but even though I don't think this is useful at all, so let's remove this.
--- net/netfilter/core.c | 9 --------- 1 file changed, 9 deletions(-)
net/netfilter/core.c +0 -9
@@ -323,15 +323,6 @@ unsigned int nf_iterate(struct sk_buff *skb, repeat: verdict = (*entryp)->ops.hook ((*entryp)->ops.priv, skb, state);if (verdict !=NF_ACCEPT ) { -#ifdef CONFIG_NETFILTER_DEBUG -if (unlikely ((verdict &NF_VERDICT_MASK ) - >NF_MAX_VERDICT )) { -NFDEBUG ("Evil return from %p(%u).\n" , - (*entryp)->ops.hook, state->hook); - *entryp =rcu_dereference ((*entryp)->next); -continue ; - } -#endif if (verdict !=NF_REPEAT )return verdict; goto repeat;
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 2/39 netfilter: remove comments that predate rcu days
In reply to Pablo Neira AyusoWe cannot block/sleep on nf_iterate because netfilter runs under rcu read lock these days, where blocking is well-known to be illegal. So let's remove these old comments.
--- net/netfilter/core.c | 7 ------- 1 file changed, 7 deletions(-)
net/netfilter/core.c +0 -7
@@ -308,18 +308,11 @@ unsigned int nf_iterate(struct sk_buff *skb, {unsigned int verdict; -/* -* The caller must not block between calls to this -* function because of risk of continuing from deleted element. -*/ while (*entryp) {if (state->thresh > (*entryp)->ops.priority) { *entryp =rcu_dereference ((*entryp)->next);continue ; } - -/* Optimization: we don't need to hold module -reference here, since function can't sleep. --RR */ repeat: verdict = (*entryp)->ops.hook ((*entryp)->ops.priv, skb, state);if (verdict !=NF_ACCEPT ) {
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 3/39 netfilter: kill NF_HOOK_THRESH() and state->tresh
In reply to Pablo Neira AyusoPatch c5136b15ea36 ("netfilter: bridge: add and use br_nf_hook_thresh") introduced br_nf_hook_thresh().
Replace NF_HOOK_THRESH() by br_nf_hook_thresh from br_nf_forward_finish(), so we have no more callers for this macro.
As a result, state->thresh and explicit thresh parameter in the hook state structure is not required anymore. And we can get rid of skip-hook-under-thresh loop in nf_iterate() in the core path that is only used by br_netfilter to search for the filter hook.
--- include/linux/netfilter.h | 50 +++++++++-------------------------- include/linux/netfilter_ingress.h | 2 +- net/bridge/br_netfilter_hooks.c | 8 +++--- net/bridge/netfilter/ebtable_broute.c | 2 +- net/netfilter/core.c | 4 --- net/netfilter/nf_queue.c | 2 -- 6 files changed, 19 insertions(+), 49 deletions(-)
include/linux/netfilter.h +13 -37
@@ -49,7 +49,6 @@ struct sock;struct nf_hook_state {unsigned int hook; -int thresh;u_int8_t pf;struct net_device *in;struct net_device *out;
@@ -84,7 +83,7 @@ struct nf_hook_entry { static inline void nf_hook_state_init(struct nf_hook_state *p, struct nf_hook_entry *hook_entry, unsigned int hook, - int thresh, u_int8_t pf, + u_int8_t pf, struct net_device *indev, struct net_device *outdev, struct sock *sk,
@@ -92,7 +91,6 @@ static inline void nf_hook_state_init(struct nf_hook_state *p, int (*okfn)(struct net *, struct sock *, struct sk_buff *)) { p->hook = hook; - p->thresh = thresh; p->pf = pf; p->in = indev; p->out = outdev;
@@ -155,20 +153,16 @@ extern struct static_key nf_hooks_needed[NFPROTO_NUMPROTO][NF_MAX_HOOKS];int nf_hook_slow (struct sk_buff *skb,struct nf_hook_state *state);/** -* nf_hook_thresh - call a netfilter hook +* nf_hook - call a netfilter hook * * Returns 1 if the hook has allowed the packet to pass. The function * okfn must be invoked by the caller in this case. Any other return * value indicates the packet has been consumed by the hook. */ -static inline int nf_hook_thresh (u_int8_t pf,unsigned int hook, -struct net *net, -struct sock *sk, -struct sk_buff *skb, -struct net_device *indev, -struct net_device *outdev, -int (*okfn)(struct net *,struct sock *,struct sk_buff *), -int thresh) +static inline int nf_hook (u_int8_t pf,unsigned int hook,struct net *net, +struct sock *sk,struct sk_buff *skb, +struct net_device *indev,struct net_device *outdev, +int (*okfn)(struct net *,struct sock *,struct sk_buff *)) {struct nf_hook_entry *hook_head;int ret =1 ;
@@ -185,8 +179,8 @@ static inline int nf_hook_thresh(u_int8_t pf, unsigned int hook,if (hook_head) {struct nf_hook_state state; -nf_hook_state_init (&state, hook_head, hook, thresh, - pf, indev, outdev, sk, net, okfn); +nf_hook_state_init (&state, hook_head, hook, pf, indev, outdev, + sk, net, okfn); ret =nf_hook_slow (skb, &state); }
@@ -195,14 +189,6 @@ static inline int nf_hook_thresh(u_int8_t pf, unsigned int hook,return ret; } -static inline int nf_hook (u_int8_t pf,unsigned int hook,struct net *net, -struct sock *sk,struct sk_buff *skb, -struct net_device *indev,struct net_device *outdev, -int (*okfn)(struct net *,struct sock *,struct sk_buff *)) -{ -return nf_hook_thresh (pf, hook, net, sk, skb, indev, outdev, okfn,INT_MIN ); -} -/* Activate hook; either okfn or kfree_skb called, unless a hook returns NF_STOLEN (in which case, it's up to the hook to deal with the consequences).
@@ -221,19 +207,6 @@ static inline int nf_hook(u_int8_t pf, unsigned int hook, struct net *net,*/ static inline int -NF_HOOK_THRESH (uint8_t pf,unsigned int hook,struct net *net,struct sock *sk, -struct sk_buff *skb,struct net_device *in, -struct net_device *out, -int (*okfn)(struct net *,struct sock *,struct sk_buff *), -int thresh) -{ -int ret =nf_hook_thresh (pf, hook, net, sk, skb, in, out, okfn, thresh); -if (ret ==1 ) - ret =okfn (net, sk, skb); -return ret; -} - -static inline int NF_HOOK_COND(uint8_t pf, unsigned int hook, struct net *net, struct sock *sk, struct sk_buff *skb, struct net_device *in, struct net_device *out, int (*okfn)(struct net *, struct sock *, struct sk_buff *),
@@ -242,7 +215,7 @@ NF_HOOK_COND(uint8_t pf, unsigned int hook, struct net *net, struct sock *sk,int ret;if (!cond || - ((ret =nf_hook_thresh (pf, hook, net, sk, skb, in, out, okfn,INT_MIN )) ==1 )) + ((ret =nf_hook (pf, hook, net, sk, skb, in, out, okfn)) ==1 )) ret =okfn (net, sk, skb);return ret; }
@@ -252,7 +225,10 @@ NF_HOOK(uint8_t pf, unsigned int hook, struct net *net, struct sock *sk, struct struct net_device *in, struct net_device *out, int (*okfn)(struct net *, struct sock *, struct sk_buff *)) { - return NF_HOOK_THRESH(pf, hook, net, sk, skb, in, out, okfn, INT_MIN); + int ret = nf_hook(pf, hook, net, sk, skb, in, out, okfn); +if (ret ==1 ) + ret =okfn (net, sk, skb); +return ret; }/* Call setsockopt() */
include/linux/netfilter_ingress.h +1 -1
@@ -26,7 +26,7 @@ static inline int nf_hook_ingress(struct sk_buff *skb)if (unlikely (!e))return 0 ; -nf_hook_state_init (&state, e,NF_NETDEV_INGRESS ,INT_MIN , +nf_hook_state_init (&state, e,NF_NETDEV_INGRESS ,NFPROTO_NETDEV , skb->dev,NULL ,NULL ,dev_net (skb->dev),NULL );return nf_hook_slow (skb, &state);
net/bridge/br_netfilter_hooks.c +4 -4
@@ -561,8 +561,8 @@ static int br_nf_forward_finish(struct net *net, struct sock *sk, struct sk_buff }nf_bridge_push_encap_header (skb); -NF_HOOK_THRESH (NFPROTO_BRIDGE ,NF_BR_FORWARD , net, sk, skb, - in, skb->dev, br_forward_finish,1 ); +br_nf_hook_thresh (NF_BR_FORWARD , net, sk, skb, in, skb->dev, + br_forward_finish);return 0 ; }
@@ -1016,8 +1016,8 @@ int br_nf_hook_thresh(unsigned int hook, struct net *net,/* We may already have this, but read-locks nest anyway */ rcu_read_lock (); -nf_hook_state_init (&state, elem, hook,NF_BR_PRI_BRNF +1 , -NFPROTO_BRIDGE , indev, outdev, sk, net, okfn); +nf_hook_state_init (&state, elem, hook,NFPROTO_BRIDGE , indev, outdev, + sk, net, okfn); ret =nf_hook_slow (skb, &state);rcu_read_unlock ();
net/bridge/netfilter/ebtable_broute.c +1 -1
@@ -53,7 +53,7 @@ static int ebt_broute(struct sk_buff *skb)struct nf_hook_state state;int ret; -nf_hook_state_init (&state,NULL ,NF_BR_BROUTING ,INT_MIN , +nf_hook_state_init (&state,NULL ,NF_BR_BROUTING ,NFPROTO_BRIDGE , skb->dev,NULL ,NULL ,dev_net (skb->dev),NULL );
net/netfilter/core.c +0 -4
@@ -309,10 +309,6 @@ unsigned int nf_iterate(struct sk_buff *skb,unsigned int verdict;while (*entryp) { -if (state->thresh > (*entryp)->ops.priority) { - *entryp =rcu_dereference ((*entryp)->next); -continue ; - } repeat: verdict = (*entryp)->ops.hook ((*entryp)->ops.priv, skb, state);if (verdict !=NF_ACCEPT ) {
net/netfilter/nf_queue.c +0 -2
@@ -200,8 +200,6 @@ void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict) verdict =NF_DROP ; } - entry->state.thresh =INT_MIN ; -if (verdict ==NF_ACCEPT ) { hook_entry =rcu_dereference (hook_entry->next);if (hook_entry)
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 4/39 netfilter: deprecate NF_STOP
In reply to Pablo Neira AyusoNF_STOP is only used by br_netfilter these days, and it can be emulated with a combination of NF_STOLEN plus explicit call to the ->okfn() function as Florian suggests.
To retain binary compatibility with userspace nf_queue application, we have to keep NF_STOP around, so libnetfilter_queue userspace userspace applications still work if they use NF_STOP for some exotic reason.
Out of tree modules using NF_STOP would break, but we don't care about those.
--- include/uapi/linux/netfilter.h | 2 +- net/bridge/br_netfilter_hooks.c | 6 ++++-- net/netfilter/core.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-)
include/uapi/linux/netfilter.h +1 -1
@@ -13,7 +13,7 @@#define NF_STOLEN 2#define NF_QUEUE 3#define NF_REPEAT 4 -#define NF_STOP 5 +#define NF_STOP 5/* Deprecated, for userspace nf_queue compatibility. */ #define NF_MAX_VERDICT NF_STOP/* we overload the higher bits for encoding auxiliary data such as the queue
net/bridge/br_netfilter_hooks.c +4 -2
@@ -845,8 +845,10 @@ static unsigned int ip_sabotage_in(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { -if (skb->nf_bridge && !skb->nf_bridge->in_prerouting) -return NF_STOP ; +if (skb->nf_bridge && !skb->nf_bridge->in_prerouting) { + state->okfn (state->net, state->sk, skb); +return NF_STOLEN ; + }return NF_ACCEPT ; }
net/netfilter/core.c +1 -1
@@ -333,7 +333,7 @@ int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state) entry =rcu_dereference (state->hook_entries); next_hook: verdict =nf_iterate (skb, state, &entry); -if (verdict ==NF_ACCEPT || verdict ==NF_STOP ) { +if (verdict ==NF_ACCEPT ) { ret =1 ; }else if ((verdict &NF_VERDICT_MASK ) ==NF_DROP ) {kfree_skb (skb);
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 5/39 netfilter: x_tables: move hook state into xt_action_param structure
In reply to Pablo Neira AyusoPlace pointer to hook state in xt_action_param structure instead of copying the fields that we need. After this change xt_action_param fits into one cacheline.
This patch also adds a set of new wrapper functions to fetch relevant hook state structure fields.
--- include/linux/netfilter/x_tables.h | 48 +++++++++++++++++++++++------- include/net/netfilter/nf_tables.h | 11 +++---- net/bridge/netfilter/ebt_arpreply.c | 3 +- net/bridge/netfilter/ebt_log.c | 11 +++---- net/bridge/netfilter/ebt_nflog.c | 6 ++-- net/bridge/netfilter/ebt_redirect.c | 6 ++-- net/bridge/netfilter/ebtables.c | 6 +--- net/ipv4/netfilter/arp_tables.c | 6 +--- net/ipv4/netfilter/ip_tables.c | 6 +--- net/ipv4/netfilter/ipt_MASQUERADE.c | 3 +- net/ipv4/netfilter/ipt_REJECT.c | 4 +-- net/ipv4/netfilter/ipt_SYNPROXY.c | 4 +-- net/ipv4/netfilter/ipt_rpfilter.c | 2 +- net/ipv6/netfilter/ip6_tables.c | 6 +--- net/ipv6/netfilter/ip6t_MASQUERADE.c | 2 +- net/ipv6/netfilter/ip6t_REJECT.c | 23 ++++++++------ net/ipv6/netfilter/ip6t_SYNPROXY.c | 4 +-- net/ipv6/netfilter/ip6t_rpfilter.c | 3 +- net/netfilter/ipset/ip_set_core.c | 6 ++-- net/netfilter/ipset/ip_set_hash_netiface.c | 2 +- net/netfilter/xt_AUDIT.c | 10 +++---- net/netfilter/xt_LOG.c | 6 ++-- net/netfilter/xt_NETMAP.c | 20 ++++++------- net/netfilter/xt_NFLOG.c | 6 ++-- net/netfilter/xt_NFQUEUE.c | 4 +-- net/netfilter/xt_REDIRECT.c | 4 +-- net/netfilter/xt_TCPMSS.c | 4 +-- net/netfilter/xt_TEE.c | 4 +-- net/netfilter/xt_TPROXY.c | 16 +++++----- net/netfilter/xt_addrtype.c | 10 +++---- net/netfilter/xt_cluster.c | 2 +- net/netfilter/xt_connlimit.c | 8 ++--- net/netfilter/xt_conntrack.c | 8 ++--- net/netfilter/xt_devgroup.c | 4 +-- net/netfilter/xt_dscp.c | 2 +- net/netfilter/xt_ipvs.c | 4 +-- net/netfilter/xt_nfacct.c | 2 +- net/netfilter/xt_osf.c | 10 +++---- net/netfilter/xt_owner.c | 2 +- net/netfilter/xt_pkttype.c | 4 +-- net/netfilter/xt_policy.c | 4 +-- net/netfilter/xt_recent.c | 10 +++---- net/netfilter/xt_set.c | 26 ++++++++-------- net/netfilter/xt_socket.c | 4 +-- net/sched/act_ipt.c | 12 ++++---- net/sched/em_ipset.c | 17 ++++++----- 46 files changed, 196 insertions(+), 169 deletions(-)
include/linux/netfilter/x_tables.h +38 -10
@@ -4,6 +4,7 @@#include <linux/netdevice.h> #include <linux/static_key.h> +#include <linux/netfilter.h> #include <uapi/linux/netfilter/x_tables.h> /* Test a struct->invflags and a boolean for inequality */
@@ -17,14 +18,9 @@* @target: the target extension * @matchinfo: per-match data * @targetinfo: per-target data -* @net network namespace through which the action was invoked -* @in: input netdevice -* @out: output netdevice +* @state: pointer to hook state this packet came from * @fragoff: packet is a fragment, this is the data offset * @thoff: position of transport header relative to skb->data -* @hook: hook number given packet came from -* @family: Actual NFPROTO_* through which the function is invoked -* (helpful when match->family == NFPROTO_UNSPEC) * * Fields written to by extensions: *
@@ -38,15 +34,47 @@ struct xt_action_param {union {const void *matchinfo, *targinfo; }; -struct net *net; -const struct net_device *in, *out; +const struct nf_hook_state *state;int fragoff;unsigned int thoff; -unsigned int hooknum; -u_int8_t family;bool hotdrop; }; +static inline struct net *xt_net (const struct xt_action_param *par) +{ +return par->state->net; +} + +static inline struct net_device *xt_in (const struct xt_action_param *par) +{ +return par->state->in; +} + +static inline const char *xt_inname (const struct xt_action_param *par) +{ +return par->state->in->name; +} + +static inline struct net_device *xt_out (const struct xt_action_param *par) +{ +return par->state->out; +} + +static inline const char *xt_outname (const struct xt_action_param *par) +{ +return par->state->out->name; +} + +static inline unsigned int xt_hooknum (const struct xt_action_param *par) +{ +return par->state->hook; +} + +static inline u_int8_t xt_family (const struct xt_action_param *par) +{ +return par->state->pf; +} +/** * struct xt_mtchk_param - parameters for match extensions' * checkentry functions
include/net/netfilter/nf_tables.h +6 -5
@@ -30,11 +30,12 @@ static inline void nft_set_pktinfo(struct nft_pktinfo *pkt, const struct nf_hook_state *state) { pkt->skb = skb; - pkt->net = pkt->xt.net = state->net; - pkt->in = pkt->xt.in = state->in; - pkt->out = pkt->xt.out = state->out; - pkt->hook = pkt->xt.hooknum = state->hook; - pkt->pf = pkt->xt.family = state->pf; + pkt->net = state->net; + pkt->in = state->in; + pkt->out = state->out; + pkt->hook = state->hook; + pkt->pf = state->pf; + pkt->xt.state = state; } static inline void nft_set_pktinfo_proto_unspec(struct nft_pktinfo *pkt,
net/bridge/netfilter/ebt_arpreply.c +2 -1
@@ -51,7 +51,8 @@ ebt_arpreply_tg(struct sk_buff *skb, const struct xt_action_param *par)if (diptr ==NULL )return EBT_DROP ; -arp_send (ARPOP_REPLY ,ETH_P_ARP , *siptr, (struct net_device *)par->in, +arp_send (ARPOP_REPLY ,ETH_P_ARP , *siptr, + (struct net_device *)xt_in (par), *diptr, shp, info->mac, shp);return info->target;
net/bridge/netfilter/ebt_log.c +6 -5
@@ -179,7 +179,7 @@ ebt_log_tg(struct sk_buff *skb, const struct xt_action_param *par) {const struct ebt_log_info *info = par->targinfo;struct nf_loginfo li; -struct net *net = par->net; +struct net *net =xt_net (par); li.type =NF_LOG_TYPE_LOG ; li.u.log.level = info->loglevel;
@@ -190,11 +190,12 @@ ebt_log_tg(struct sk_buff *skb, const struct xt_action_param *par)* nf_log_packet() with NFT_LOG_TYPE_LOG here. --Pablo */ if (info->bitmask &EBT_LOG_NFLOG ) -nf_log_packet (net,NFPROTO_BRIDGE , par->hooknum, skb, - par->in, par->out, &li,"%s" , info->prefix); +nf_log_packet (net,NFPROTO_BRIDGE ,xt_hooknum (par), skb, +xt_in (par),xt_out (par), &li,"%s" , + info->prefix);else -ebt_log_packet (net,NFPROTO_BRIDGE , par->hooknum, skb, par->in, - par->out, &li, info->prefix); +ebt_log_packet (net,NFPROTO_BRIDGE ,xt_hooknum (par), skb, +xt_in (par),xt_out (par), &li, info->prefix);return EBT_CONTINUE ; }
net/bridge/netfilter/ebt_nflog.c +3 -3
@@ -23,16 +23,16 @@ static unsigned int ebt_nflog_tg(struct sk_buff *skb, const struct xt_action_param *par) { const struct ebt_nflog_info *info = par->targinfo; +struct net *net =xt_net (par);struct nf_loginfo li; -struct net *net = par->net; li.type =NF_LOG_TYPE_ULOG ; li.u.ulog.copy_len = info->len; li.u.ulog.group = info->group; li.u.ulog.qthreshold = info->threshold; -nf_log_packet (net,PF_BRIDGE , par->hooknum, skb, par->in, - par->out, &li,"%s" , info->prefix); +nf_log_packet (net,PF_BRIDGE ,xt_hooknum (par), skb,xt_in (par), +xt_out (par), &li,"%s" , info->prefix);return EBT_CONTINUE ; }
net/bridge/netfilter/ebt_redirect.c +3 -3
@@ -23,12 +23,12 @@ ebt_redirect_tg(struct sk_buff *skb, const struct xt_action_param *par)if (!skb_make_writable (skb,0 ))return EBT_DROP ; -if (par->hooknum !=NF_BR_BROUTING ) +if (xt_hooknum (par) !=NF_BR_BROUTING )/* rcu_read_lock()ed by nf_hook_thresh */ ether_addr_copy (eth_hdr (skb)->h_dest, -br_port_get_rcu (par->in)->br->dev->dev_addr); +br_port_get_rcu (xt_in (par))->br->dev->dev_addr);else -ether_addr_copy (eth_hdr (skb)->h_dest, par->in->dev_addr); +ether_addr_copy (eth_hdr (skb)->h_dest,xt_in (par)->dev_addr); skb->pkt_type =PACKET_HOST ;return info->target; }
net/bridge/netfilter/ebtables.c +1 -5
@@ -194,12 +194,8 @@ unsigned int ebt_do_table(struct sk_buff *skb,const struct ebt_table_info *private;struct xt_action_param acpar; - acpar.family =NFPROTO_BRIDGE ; - acpar.net = state->net; - acpar.in = state->in; - acpar.out = state->out; + acpar.state = state; acpar.hotdrop = false; - acpar.hooknum = hook;read_lock_bh (&table->lock); private = table->private;
net/ipv4/netfilter/arp_tables.c +1 -5
@@ -217,11 +217,7 @@ unsigned int arpt_do_table(struct sk_buff *skb,*/ e =get_entry (table_base, private->hook_entry[hook]); - acpar.net = state->net; - acpar.in = state->in; - acpar.out = state->out; - acpar.hooknum = hook; - acpar.family =NFPROTO_ARP ; + acpar.state = state; acpar.hotdrop = false; arp =arp_hdr (skb);
net/ipv4/netfilter/ip_tables.c +1 -5
@@ -261,11 +261,7 @@ ipt_do_table(struct sk_buff *skb, acpar.fragoff =ntohs (ip->frag_off) &IP_OFFSET ; acpar.thoff =ip_hdrlen (skb); acpar.hotdrop = false; - acpar.net = state->net; - acpar.in = state->in; - acpar.out = state->out; - acpar.family =NFPROTO_IPV4 ; - acpar.hooknum = hook; + acpar.state = state;IP_NF_ASSERT (table->valid_hooks & (1 << hook));local_bh_disable ();
net/ipv4/netfilter/ipt_MASQUERADE.c +2 -1
@@ -55,7 +55,8 @@ masquerade_tg(struct sk_buff *skb, const struct xt_action_param *par) range.min_proto = mr->range[0 ].min; range.max_proto = mr->range[0 ].max; -return nf_nat_masquerade_ipv4 (skb, par->hooknum, &range, par->out); +return nf_nat_masquerade_ipv4 (skb,xt_hooknum (par), &range, +xt_out (par)); }static struct xt_target masquerade_tg_reg__read_mostly = {
net/ipv4/netfilter/ipt_REJECT.c +2 -2
@@ -34,7 +34,7 @@ static unsigned int reject_tg(struct sk_buff *skb, const struct xt_action_param *par) { const struct ipt_reject_info *reject = par->targinfo; -int hook = par->hooknum; +int hook =xt_hooknum (par);switch (reject->with) {case IPT_ICMP_NET_UNREACHABLE :
@@ -59,7 +59,7 @@ reject_tg(struct sk_buff *skb, const struct xt_action_param *par)nf_send_unreach (skb,ICMP_PKT_FILTERED , hook);break ;case IPT_TCP_RESET : -nf_send_reset (par->net, skb, hook); +nf_send_reset (xt_net (par), skb, hook);case IPT_ICMP_ECHOREPLY :/* Doesn't happen. */ break ;
net/ipv4/netfilter/ipt_SYNPROXY.c +2 -2
@@ -263,12 +263,12 @@ static unsigned int synproxy_tg4(struct sk_buff *skb, const struct xt_action_param *par) { const struct xt_synproxy_info *info = par->targinfo; -struct net *net = par->net; +struct net *net =xt_net (par);struct synproxy_net *snet =synproxy_pernet (net);struct synproxy_options opts = {};struct tcphdr *th, _th; -if (nf_ip_checksum (skb, par->hooknum, par->thoff,IPPROTO_TCP )) +if (nf_ip_checksum (skb,xt_hooknum (par), par->thoff,IPPROTO_TCP ))return NF_DROP ; th =skb_header_pointer (skb, par->thoff,sizeof (_th), &_th);
net/ipv4/netfilter/ipt_rpfilter.c +1 -1
@@ -95,7 +95,7 @@ static bool rpfilter_mt(const struct sk_buff *skb, struct xt_action_param *par) flow.flowi4_tos =RT_TOS (iph->tos); flow.flowi4_scope =RT_SCOPE_UNIVERSE ; -return rpfilter_lookup_reverse (par->net, &flow, par->in, info->flags) ^ invert; +return rpfilter_lookup_reverse (xt_net (par), &flow,xt_in (par), info->flags) ^ invert; }static int rpfilter_check (const struct xt_mtchk_param *par)
net/ipv6/netfilter/ip6_tables.c +1 -5
@@ -291,11 +291,7 @@ ip6t_do_table(struct sk_buff *skb,* rule is also a fragment-specific rule, non-fragments won't * match it. */ acpar.hotdrop = false; - acpar.net = state->net; - acpar.in = state->in; - acpar.out = state->out; - acpar.family =NFPROTO_IPV6 ; - acpar.hooknum = hook; + acpar.state = state;IP_NF_ASSERT (table->valid_hooks & (1 << hook));
net/ipv6/netfilter/ip6t_MASQUERADE.c +1 -1
@@ -24,7 +24,7 @@static unsigned int masquerade_tg6 (struct sk_buff *skb,const struct xt_action_param *par) { -return nf_nat_masquerade_ipv6 (skb, par->targinfo, par->out); +return nf_nat_masquerade_ipv6 (skb, par->targinfo,xt_out (par)); }static int masquerade_tg6_checkentry (const struct xt_tgchk_param *par)
net/ipv6/netfilter/ip6t_REJECT.c +14 -9
@@ -39,35 +39,40 @@ static unsigned int reject_tg6(struct sk_buff *skb, const struct xt_action_param *par) { const struct ip6t_reject_info *reject = par->targinfo; -struct net *net = par->net; +struct net *net =xt_net (par);switch (reject->with) {case IP6T_ICMP6_NO_ROUTE : -nf_send_unreach6 (net, skb,ICMPV6_NOROUTE , par->hooknum); +nf_send_unreach6 (net, skb,ICMPV6_NOROUTE ,xt_hooknum (par));break ;case IP6T_ICMP6_ADM_PROHIBITED : -nf_send_unreach6 (net, skb,ICMPV6_ADM_PROHIBITED , par->hooknum); +nf_send_unreach6 (net, skb,ICMPV6_ADM_PROHIBITED , +xt_hooknum (par));break ;case IP6T_ICMP6_NOT_NEIGHBOUR : -nf_send_unreach6 (net, skb,ICMPV6_NOT_NEIGHBOUR , par->hooknum); +nf_send_unreach6 (net, skb,ICMPV6_NOT_NEIGHBOUR , +xt_hooknum (par));break ;case IP6T_ICMP6_ADDR_UNREACH : -nf_send_unreach6 (net, skb,ICMPV6_ADDR_UNREACH , par->hooknum); +nf_send_unreach6 (net, skb,ICMPV6_ADDR_UNREACH , +xt_hooknum (par));break ;case IP6T_ICMP6_PORT_UNREACH : -nf_send_unreach6 (net, skb,ICMPV6_PORT_UNREACH , par->hooknum); +nf_send_unreach6 (net, skb,ICMPV6_PORT_UNREACH , +xt_hooknum (par));break ;case IP6T_ICMP6_ECHOREPLY :/* Do nothing */ break ;case IP6T_TCP_RESET : -nf_send_reset6 (net, skb, par->hooknum); +nf_send_reset6 (net, skb,xt_hooknum (par));break ;case IP6T_ICMP6_POLICY_FAIL : -nf_send_unreach6 (net, skb,ICMPV6_POLICY_FAIL , par->hooknum); +nf_send_unreach6 (net, skb,ICMPV6_POLICY_FAIL ,xt_hooknum (par));break ;case IP6T_ICMP6_REJECT_ROUTE : -nf_send_unreach6 (net, skb,ICMPV6_REJECT_ROUTE , par->hooknum); +nf_send_unreach6 (net, skb,ICMPV6_REJECT_ROUTE , +xt_hooknum (par));break ; }
net/ipv6/netfilter/ip6t_SYNPROXY.c +2 -2
@@ -277,12 +277,12 @@ static unsigned int synproxy_tg6(struct sk_buff *skb, const struct xt_action_param *par) { const struct xt_synproxy_info *info = par->targinfo; -struct net *net = par->net; +struct net *net =xt_net (par);struct synproxy_net *snet =synproxy_pernet (net);struct synproxy_options opts = {};struct tcphdr *th, _th; -if (nf_ip6_checksum (skb, par->hooknum, par->thoff,IPPROTO_TCP )) +if (nf_ip6_checksum (skb,xt_hooknum (par), par->thoff,IPPROTO_TCP ))return NF_DROP ; th =skb_header_pointer (skb, par->thoff,sizeof (_th), &_th);
net/ipv6/netfilter/ip6t_rpfilter.c +2 -1
@@ -93,7 +93,8 @@ static bool rpfilter_mt(const struct sk_buff *skb, struct xt_action_param *par)if (unlikely (saddrtype ==IPV6_ADDR_ANY ))return true ^ invert;/* not routable: forward path will drop it */ -return rpfilter_lookup_reverse6 (par->net, skb, par->in, info->flags) ^ invert; +return rpfilter_lookup_reverse6 (xt_net (par), skb,xt_in (par), + info->flags) ^ invert; }static int rpfilter_check (const struct xt_mtchk_param *par)
net/netfilter/ipset/ip_set_core.c +3 -3
@@ -541,7 +541,7 @@ int ip_set_test(ip_set_id_t index, const struct sk_buff *skb, const struct xt_action_param *par, struct ip_set_adt_opt *opt) { - struct ip_set *set = ip_set_rcu_get(par->net, index); + struct ip_set *set = ip_set_rcu_get(xt_net(par), index);int ret =0 ;BUG_ON (!set);
@@ -579,7 +579,7 @@ int ip_set_add(ip_set_id_t index, const struct sk_buff *skb, const struct xt_action_param *par, struct ip_set_adt_opt *opt) { - struct ip_set *set = ip_set_rcu_get(par->net, index); + struct ip_set *set = ip_set_rcu_get(xt_net(par), index);int ret;BUG_ON (!set);
@@ -601,7 +601,7 @@ int ip_set_del(ip_set_id_t index, const struct sk_buff *skb, const struct xt_action_param *par, struct ip_set_adt_opt *opt) { - struct ip_set *set = ip_set_rcu_get(par->net, index); + struct ip_set *set = ip_set_rcu_get(xt_net(par), index);int ret =0 ;BUG_ON (!set);
net/netfilter/ipset/ip_set_hash_netiface.c +1 -1
@@ -170,7 +170,7 @@ hash_netiface4_kadt(struct ip_set *set, const struct sk_buff *skb,ip4addrptr (skb, opt->flags &IPSET_DIM_ONE_SRC , &e.ip); e.ip &=ip_set_netmask (e.cidr); -#define IFACE (dir) (par->dir ? par->dir->name : "") +#define IFACE (dir) (par->state->dir ? par->state->dir->name : "")#define SRCDIR (opt->flags & IPSET_DIM_TWO_SRC)if (opt->cmdflags &IPSET_FLAG_PHYSDEV ) {
net/netfilter/xt_AUDIT.c +5 -5
@@ -132,9 +132,9 @@ audit_tg(struct sk_buff *skb, const struct xt_action_param *par) goto errout;audit_log_format (ab,"action=%hhu hook=%u len=%u inif=%s outif=%s" , - info->type, par->hooknum, skb->len, - par->in ? par->in->name :"?" , - par->out ? par->out->name :"?" ); + info->type,xt_hooknum (par), skb->len, +xt_in (par) ?xt_inname (par) :"?" , +xt_out (par) ?xt_outname (par) :"?" );if (skb->mark)audit_log_format (ab," mark=%#x" , skb->mark);
@@ -144,7 +144,7 @@ audit_tg(struct sk_buff *skb, const struct xt_action_param *par)eth_hdr (skb)->h_source,eth_hdr (skb)->h_dest, ntohs(eth_hdr(skb)->h_proto)); -if (par->family ==NFPROTO_BRIDGE ) { +if (xt_family (par) ==NFPROTO_BRIDGE ) {switch (eth_hdr (skb)->h_proto) {case htons (ETH_P_IP ):audit_ip4 (ab, skb);
@@ -157,7 +157,7 @@ audit_tg(struct sk_buff *skb, const struct xt_action_param *par) } } -switch (par->family) { +switch (xt_family (par)) {case NFPROTO_IPV4 :audit_ip4 (ab, skb);break ;
net/netfilter/xt_LOG.c +3 -3
@@ -32,15 +32,15 @@ static unsigned int log_tg(struct sk_buff *skb, const struct xt_action_param *par) { const struct xt_log_info *loginfo = par->targinfo; +struct net *net =xt_net (par);struct nf_loginfo li; -struct net *net = par->net; li.type =NF_LOG_TYPE_LOG ; li.u.log.level = loginfo->level; li.u.log.logflags = loginfo->logflags; -nf_log_packet (net, par->family, par->hooknum, skb, par->in, par->out, - &li,"%s" , loginfo->prefix); +nf_log_packet (net,xt_family (par),xt_hooknum (par), skb,xt_in (par), +xt_out (par), &li,"%s" , loginfo->prefix);return XT_CONTINUE ; }
net/netfilter/xt_NETMAP.c +10 -10
@@ -33,8 +33,8 @@ netmap_tg6(struct sk_buff *skb, const struct xt_action_param *par) netmask.ip6[i] = ~(range->min_addr.ip6[i] ^ range->max_addr.ip6[i]); -if (par->hooknum ==NF_INET_PRE_ROUTING || - par->hooknum ==NF_INET_LOCAL_OUT ) +if (xt_hooknum (par) ==NF_INET_PRE_ROUTING || +xt_hooknum (par) ==NF_INET_LOCAL_OUT ) new_addr.in6 =ipv6_hdr (skb)->daddr;else new_addr.in6 =ipv6_hdr (skb)->saddr;
@@ -51,7 +51,7 @@ netmap_tg6(struct sk_buff *skb, const struct xt_action_param *par) newrange.min_proto = range->min_proto; newrange.max_proto = range->max_proto; -return nf_nat_setup_info (ct, &newrange,HOOK2MANIP (par->hooknum)); +return nf_nat_setup_info (ct, &newrange,HOOK2MANIP (xt_hooknum (par))); }static int netmap_tg6_checkentry (const struct xt_tgchk_param *par)
@@ -72,16 +72,16 @@ netmap_tg4(struct sk_buff *skb, const struct xt_action_param *par)const struct nf_nat_ipv4_multi_range_compat *mr = par->targinfo;struct nf_nat_range newrange; -NF_CT_ASSERT (par->hooknum ==NF_INET_PRE_ROUTING || - par->hooknum ==NF_INET_POST_ROUTING || - par->hooknum ==NF_INET_LOCAL_OUT || - par->hooknum ==NF_INET_LOCAL_IN ); +NF_CT_ASSERT (xt_hooknum (par) ==NF_INET_PRE_ROUTING || +xt_hooknum (par) ==NF_INET_POST_ROUTING || +xt_hooknum (par) ==NF_INET_LOCAL_OUT || +xt_hooknum (par) ==NF_INET_LOCAL_IN ); ct =nf_ct_get (skb, &ctinfo); netmask = ~(mr->range[0 ].min_ip ^ mr->range[0 ].max_ip); -if (par->hooknum ==NF_INET_PRE_ROUTING || - par->hooknum ==NF_INET_LOCAL_OUT ) +if (xt_hooknum (par) ==NF_INET_PRE_ROUTING || +xt_hooknum (par) ==NF_INET_LOCAL_OUT ) new_ip =ip_hdr (skb)->daddr & ~netmask;else new_ip =ip_hdr (skb)->saddr & ~netmask;
@@ -96,7 +96,7 @@ netmap_tg4(struct sk_buff *skb, const struct xt_action_param *par) newrange.max_proto = mr->range[0 ].max;/* Hand modified range to generic setup. */ -return nf_nat_setup_info (ct, &newrange,HOOK2MANIP (par->hooknum)); +return nf_nat_setup_info (ct, &newrange,HOOK2MANIP (xt_hooknum (par))); }static int netmap_tg4_check (const struct xt_tgchk_param *par)
net/netfilter/xt_NFLOG.c +3 -3
@@ -25,8 +25,8 @@ static unsigned int nflog_tg(struct sk_buff *skb, const struct xt_action_param *par) { const struct xt_nflog_info *info = par->targinfo; +struct net *net =xt_net (par);struct nf_loginfo li; -struct net *net = par->net; li.type =NF_LOG_TYPE_ULOG ; li.u.ulog.copy_len = info->len;
@@ -37,8 +37,8 @@ nflog_tg(struct sk_buff *skb, const struct xt_action_param *par)if (info->flags &XT_NFLOG_F_COPY_LEN ) li.u.ulog.flags |=NF_LOG_F_COPY_LEN ; -nfulnl_log_packet (net, par->family, par->hooknum, skb, par->in, - par->out, &li, info->prefix); +nfulnl_log_packet (net,xt_family (par),xt_hooknum (par), skb, +xt_in (par),xt_out (par), &li, info->prefix);return XT_CONTINUE ; }
net/netfilter/xt_NFQUEUE.c +2 -2
@@ -43,7 +43,7 @@ nfqueue_tg_v1(struct sk_buff *skb, const struct xt_action_param *par)if (info->queues_total >1 ) { queue =nfqueue_hash (skb, queue, info->queues_total, - par->family, jhash_initval); +xt_family (par), jhash_initval); }return NF_QUEUE_NR (queue); }
@@ -98,7 +98,7 @@ nfqueue_tg_v3(struct sk_buff *skb, const struct xt_action_param *par) queue = info->queuenum + cpu % info->queues_total; }else { queue =nfqueue_hash (skb, queue, info->queues_total, - par->family, jhash_initval); +xt_family (par), jhash_initval); } }
net/netfilter/xt_REDIRECT.c +2 -2
@@ -31,7 +31,7 @@static unsigned int redirect_tg6 (struct sk_buff *skb,const struct xt_action_param *par) { -return nf_nat_redirect_ipv6 (skb, par->targinfo, par->hooknum); +return nf_nat_redirect_ipv6 (skb, par->targinfo,xt_hooknum (par)); }static int redirect_tg6_checkentry (const struct xt_tgchk_param *par)
@@ -62,7 +62,7 @@ static int redirect_tg4_check(const struct xt_tgchk_param *par)static unsigned int redirect_tg4 (struct sk_buff *skb,const struct xt_action_param *par) { -return nf_nat_redirect_ipv4 (skb, par->targinfo, par->hooknum); +return nf_nat_redirect_ipv4 (skb, par->targinfo,xt_hooknum (par)); }static struct xt_target redirect_tg_reg[]__read_mostly = {
net/netfilter/xt_TCPMSS.c +2 -2
@@ -108,7 +108,7 @@ tcpmss_mangle_packet(struct sk_buff *skb,return -1 ;if (info->mss ==XT_TCPMSS_CLAMP_PMTU ) { -struct net *net = par->net; +struct net *net =xt_net (par);unsigned int in_mtu =tcpmss_reverse_mtu (net, skb, family);unsigned int min_mtu =min (dst_mtu (skb_dst (skb)), in_mtu);
@@ -172,7 +172,7 @@ tcpmss_mangle_packet(struct sk_buff *skb,* length IPv6 header of 60, ergo the default MSS value is 1220 * Since no MSS was provided, we must use the default values */ -if (par->family ==NFPROTO_IPV4 ) +if (xt_family (par) ==NFPROTO_IPV4 ) newmss =min (newmss, (u16 )536 );else newmss =min (newmss, (u16 )1220 );
net/netfilter/xt_TEE.c +2 -2
@@ -33,7 +33,7 @@ tee_tg4(struct sk_buff *skb, const struct xt_action_param *par)const struct xt_tee_tginfo *info = par->targinfo;int oif = info->priv ? info->priv->oif :0 ; -nf_dup_ipv4 (par->net, skb, par->hooknum, &info->gw.in, oif); +nf_dup_ipv4 (xt_net (par), skb,xt_hooknum (par), &info->gw.in, oif);return XT_CONTINUE ; }
@@ -45,7 +45,7 @@ tee_tg6(struct sk_buff *skb, const struct xt_action_param *par)const struct xt_tee_tginfo *info = par->targinfo;int oif = info->priv ? info->priv->oif :0 ; -nf_dup_ipv6 (par->net, skb, par->hooknum, &info->gw.in6, oif); +nf_dup_ipv6 (xt_net (par), skb,xt_hooknum (par), &info->gw.in6, oif);return XT_CONTINUE ; }
net/netfilter/xt_TPROXY.c +9 -7
@@ -364,7 +364,8 @@ tproxy_tg4_v0(struct sk_buff *skb, const struct xt_action_param *par) {const struct xt_tproxy_target_info *tgi = par->targinfo; -return tproxy_tg4 (par->net, skb, tgi->laddr, tgi->lport, tgi->mark_mask, tgi->mark_value); +return tproxy_tg4 (xt_net (par), skb, tgi->laddr, tgi->lport, + tgi->mark_mask, tgi->mark_value); } static unsigned int
@@ -372,7 +373,8 @@ tproxy_tg4_v1(struct sk_buff *skb, const struct xt_action_param *par) {const struct xt_tproxy_target_info_v1 *tgi = par->targinfo; -return tproxy_tg4 (par->net, skb, tgi->laddr.ip, tgi->lport, tgi->mark_mask, tgi->mark_value); +return tproxy_tg4 (xt_net (par), skb, tgi->laddr.ip, tgi->lport, + tgi->mark_mask, tgi->mark_value); }#ifdef XT_TPROXY_HAVE_IPV6
@@ -442,7 +444,7 @@ tproxy_handle_time_wait6(struct sk_buff *skb, int tproto, int thoff,* to a listener socket if there's one */ struct sock *sk2; - sk2 = nf_tproxy_get_sock_v6(par->net, skb, thoff, hp, tproto, + sk2 = nf_tproxy_get_sock_v6(xt_net(par), skb, thoff, hp, tproto, &iph->saddr, tproxy_laddr6(skb, &tgi->laddr.in6, &iph->daddr), hp->source,
@@ -485,10 +487,10 @@ tproxy_tg6_v1(struct sk_buff *skb, const struct xt_action_param *par)* addresses, this happens if the redirect already happened * and the current packet belongs to an already established * connection */ - sk =nf_tproxy_get_sock_v6 (par->net, skb, thoff, hp, tproto, + sk =nf_tproxy_get_sock_v6 (xt_net (par), skb, thoff, hp, tproto, &iph->saddr, &iph->daddr, hp->source, hp->dest, - par->in,NFT_LOOKUP_ESTABLISHED ); +xt_in (par),NFT_LOOKUP_ESTABLISHED ); laddr =tproxy_laddr6 (skb, &tgi->laddr.in6, &iph->daddr); lport = tgi->lport ? tgi->lport : hp->dest;
@@ -500,10 +502,10 @@ tproxy_tg6_v1(struct sk_buff *skb, const struct xt_action_param *par)else if (!sk)/* no there's no established connection, check if * there's a listener on the redirected addr/port */ - sk =nf_tproxy_get_sock_v6 (par->net, skb, thoff, hp, + sk =nf_tproxy_get_sock_v6 (xt_net (par), skb, thoff, hp, tproto, &iph->saddr, laddr, hp->source, lport, - par->in,NFT_LOOKUP_LISTENER ); +xt_in (par),NFT_LOOKUP_LISTENER );/* NOTE: assign_sock consumes our sk reference */ if (sk &&tproxy_sk_is_transparent (sk)) {
net/netfilter/xt_addrtype.c +5 -5
@@ -125,7 +125,7 @@ static inline bool match_type(struct net *net, const struct net_device *dev,static bool addrtype_mt_v0 (const struct sk_buff *skb,struct xt_action_param *par) { -struct net *net = par->net; +struct net *net =xt_net (par);const struct xt_addrtype_info *info = par->matchinfo;const struct iphdr *iph =ip_hdr (skb);bool ret = true;
@@ -143,19 +143,19 @@ addrtype_mt_v0(const struct sk_buff *skb, struct xt_action_param *par)static bool addrtype_mt_v1 (const struct sk_buff *skb,struct xt_action_param *par) { -struct net *net = par->net; +struct net *net =xt_net (par);const struct xt_addrtype_info_v1 *info = par->matchinfo;const struct iphdr *iph;const struct net_device *dev =NULL ;bool ret = true;if (info->flags &XT_ADDRTYPE_LIMIT_IFACE_IN ) - dev = par->in; + dev =xt_in (par);else if (info->flags &XT_ADDRTYPE_LIMIT_IFACE_OUT ) - dev = par->out; + dev =xt_out (par);#if IS_ENABLED (CONFIG_IP6_NF_IPTABLES ) -if (par->family ==NFPROTO_IPV6 ) +if (xt_family (par) ==NFPROTO_IPV6 )return addrtype_mt6 (net, dev, skb, info);#endif iph =ip_hdr (skb);
net/netfilter/xt_cluster.c +1 -1
@@ -112,7 +112,7 @@ xt_cluster_mt(const struct sk_buff *skb, struct xt_action_param *par)* know, matches should not alter packets, but we are doing this here * because we would need to add a PKTTYPE target for this sole purpose. */ -if (!xt_cluster_is_multicast_addr (skb, par->family) && +if (!xt_cluster_is_multicast_addr (skb,xt_family (par)) && skb->pkt_type ==PACKET_MULTICAST ) { pskb->pkt_type =PACKET_HOST ; }
net/netfilter/xt_connlimit.c +4 -4
@@ -317,7 +317,7 @@ static int count_them(struct net *net,static bool connlimit_mt (const struct sk_buff *skb,struct xt_action_param *par) { -struct net *net = par->net; +struct net *net =xt_net (par);const struct xt_connlimit_info *info = par->matchinfo;union nf_inet_addr addr;struct nf_conntrack_tuple tuple;
@@ -332,11 +332,11 @@ connlimit_mt(const struct sk_buff *skb, struct xt_action_param *par) tuple_ptr = &ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple; zone =nf_ct_zone (ct); }else if (!nf_ct_get_tuplepr (skb,skb_network_offset (skb), - par->family, net, &tuple)) { +xt_family (par), net, &tuple)) { goto hotdrop; } -if (par->family ==NFPROTO_IPV6 ) { +if (xt_family (par) ==NFPROTO_IPV6 ) {const struct ipv6hdr *iph =ipv6_hdr (skb);memcpy (&addr.ip6, (info->flags &XT_CONNLIMIT_DADDR ) ? &iph->daddr : &iph->saddr,sizeof (addr.ip6));
@@ -347,7 +347,7 @@ connlimit_mt(const struct sk_buff *skb, struct xt_action_param *par) } connections =count_them (net, info->data, tuple_ptr, &addr, - &info->mask, par->family, zone); + &info->mask,xt_family (par), zone);if (connections ==0 )/* kmalloc failed, drop it entirely */ goto hotdrop;
net/netfilter/xt_conntrack.c +4 -4
@@ -200,22 +200,22 @@ conntrack_mt(const struct sk_buff *skb, struct xt_action_param *par,return false;if (info->match_flags &XT_CONNTRACK_ORIGSRC ) -if (conntrack_mt_origsrc (ct, info, par->family) ^ +if (conntrack_mt_origsrc (ct, info,xt_family (par)) ^ !(info->invert_flags &XT_CONNTRACK_ORIGSRC ))return false;if (info->match_flags &XT_CONNTRACK_ORIGDST ) -if (conntrack_mt_origdst (ct, info, par->family) ^ +if (conntrack_mt_origdst (ct, info,xt_family (par)) ^ !(info->invert_flags &XT_CONNTRACK_ORIGDST ))return false;if (info->match_flags &XT_CONNTRACK_REPLSRC ) -if (conntrack_mt_replsrc (ct, info, par->family) ^ +if (conntrack_mt_replsrc (ct, info,xt_family (par)) ^ !(info->invert_flags &XT_CONNTRACK_REPLSRC ))return false;if (info->match_flags &XT_CONNTRACK_REPLDST ) -if (conntrack_mt_repldst (ct, info, par->family) ^ +if (conntrack_mt_repldst (ct, info,xt_family (par)) ^ !(info->invert_flags &XT_CONNTRACK_REPLDST ))return false;
net/netfilter/xt_devgroup.c +2 -2
@@ -24,12 +24,12 @@ static bool devgroup_mt(const struct sk_buff *skb, struct xt_action_param *par)const struct xt_devgroup_info *info = par->matchinfo;if (info->flags &XT_DEVGROUP_MATCH_SRC && - (((info->src_group ^ par->in->group) & info->src_mask ?1 :0 ) ^ + (((info->src_group ^xt_in (par)->group) & info->src_mask ?1 :0 ) ^ ((info->flags &XT_DEVGROUP_INVERT_SRC ) ?1 :0 )))return false;if (info->flags &XT_DEVGROUP_MATCH_DST && - (((info->dst_group ^ par->out->group) & info->dst_mask ?1 :0 ) ^ + (((info->dst_group ^xt_out (par)->group) & info->dst_mask ?1 :0 ) ^ ((info->flags &XT_DEVGROUP_INVERT_DST ) ?1 :0 )))return false;
net/netfilter/xt_dscp.c +1 -1
@@ -58,7 +58,7 @@ static bool tos_mt(const struct sk_buff *skb, struct xt_action_param *par) {const struct xt_tos_match_info *info = par->matchinfo; -if (par->family ==NFPROTO_IPV4 ) +if (xt_family (par) ==NFPROTO_IPV4 )return ((ip_hdr (skb)->tos & info->tos_mask) == info->tos_value) ^ !!info->invert;else
net/netfilter/xt_ipvs.c +2 -2
@@ -48,9 +48,9 @@ static bool ipvs_mt(const struct sk_buff *skb, struct xt_action_param *par) { const struct xt_ipvs_mtinfo *data = par->matchinfo; -struct netns_ipvs *ipvs =net_ipvs (par->net); +struct netns_ipvs *ipvs =net_ipvs (xt_net (par));/* ipvs_mt_check ensures that family is only NFPROTO_IPV[46]. */ -const u_int8_t family = par->family; +const u_int8_t family =xt_family (par);struct ip_vs_iphdr iph;struct ip_vs_protocol *pp;struct ip_vs_conn *cp;
net/netfilter/xt_nfacct.c +1 -1
@@ -26,7 +26,7 @@ static bool nfacct_mt(const struct sk_buff *skb, struct xt_action_param *par)nfnl_acct_update (skb, info->nfacct); - overquota =nfnl_acct_overquota (par->net, skb, info->nfacct); + overquota =nfnl_acct_overquota (xt_net (par), skb, info->nfacct);return overquota ==NFACCT_UNDERQUOTA ? false : true; }
net/netfilter/xt_osf.c +5 -5
@@ -201,7 +201,7 @@ xt_osf_match_packet(const struct sk_buff *skb, struct xt_action_param *p)unsigned char opts[MAX_IPOPTLEN ];const struct xt_osf_finger *kf;const struct xt_osf_user_finger *f; -struct net *net = p->net; +struct net *net =xt_net (p);if (!info)return false;
@@ -326,8 +326,8 @@ xt_osf_match_packet(const struct sk_buff *skb, struct xt_action_param *p) fcount++;if (info->flags &XT_OSF_LOG ) - nf_log_packet(net, p->family, p->hooknum, skb, - p->in, p->out, NULL, + nf_log_packet(net, xt_family(p), xt_hooknum(p), skb, + xt_in(p), xt_out(p), NULL, "%s [%s:%s] : %pI4:%d -> %pI4:%d hops=%d\n", f->genre, f->version, f->subtype, &ip->saddr, ntohs(tcp->source),
@@ -341,8 +341,8 @@ xt_osf_match_packet(const struct sk_buff *skb, struct xt_action_param *p)rcu_read_unlock ();if (!fcount && (info->flags &XT_OSF_LOG )) -nf_log_packet (net, p->family, p->hooknum, skb, p->in, - p->out,NULL , +nf_log_packet (net,xt_family (p),xt_hooknum (p), skb,xt_in (p), +xt_out (p),NULL ,"Remote OS is not known: %pI4:%u -> %pI4:%u\n" , &ip->saddr,ntohs (tcp->source), &ip->daddr,ntohs (tcp->dest));
net/netfilter/xt_owner.c +1 -1
@@ -63,7 +63,7 @@ owner_mt(const struct sk_buff *skb, struct xt_action_param *par)const struct xt_owner_match_info *info = par->matchinfo;const struct file *filp;struct sock *sk =skb_to_full_sk (skb); -struct net *net = par->net; +struct net *net =xt_net (par);if (sk ==NULL || sk->sk_socket ==NULL )return (info->match ^ info->invert) ==0 ;
net/netfilter/xt_pkttype.c +2 -2
@@ -30,10 +30,10 @@ pkttype_mt(const struct sk_buff *skb, struct xt_action_param *par)if (skb->pkt_type !=PACKET_LOOPBACK ) type = skb->pkt_type; -else if (par->family ==NFPROTO_IPV4 && +else if (xt_family (par) ==NFPROTO_IPV4 &&ipv4_is_multicast (ip_hdr (skb)->daddr)) type =PACKET_MULTICAST ; -else if (par->family ==NFPROTO_IPV6 && +else if (xt_family (par) ==NFPROTO_IPV6 &&ipv6_hdr (skb)->daddr.s6_addr[0 ] ==0xFF ) type =PACKET_MULTICAST ;else
net/netfilter/xt_policy.c +2 -2
@@ -116,9 +116,9 @@ policy_mt(const struct sk_buff *skb, struct xt_action_param *par)int ret;if (info->flags &XT_POLICY_MATCH_IN ) - ret =match_policy_in (skb, info, par->family); + ret =match_policy_in (skb, info,xt_family (par));else - ret =match_policy_out (skb, info, par->family); + ret =match_policy_out (skb, info,xt_family (par));if (ret <0 ) ret = info->flags &XT_POLICY_MATCH_NONE ? true : false;
net/netfilter/xt_recent.c +5 -5
@@ -236,7 +236,7 @@ static void recent_table_flush(struct recent_table *t)static bool recent_mt (const struct sk_buff *skb,struct xt_action_param *par) { -struct net *net = par->net; +struct net *net =xt_net (par);struct recent_net *recent_net =recent_pernet (net);const struct xt_recent_mtinfo_v1 *info = par->matchinfo;struct recent_table *t;
@@ -245,7 +245,7 @@ recent_mt(const struct sk_buff *skb, struct xt_action_param *par)u_int8_t ttl;bool ret = info->invert; -if (par->family ==NFPROTO_IPV4 ) { +if (xt_family (par) ==NFPROTO_IPV4 ) {const struct iphdr *iph =ip_hdr (skb);if (info->side ==XT_RECENT_DEST )
@@ -266,7 +266,7 @@ recent_mt(const struct sk_buff *skb, struct xt_action_param *par) }/* use TTL as seen before forwarding */ -if (par->out !=NULL && skb->sk ==NULL ) +if (xt_out (par) !=NULL && skb->sk ==NULL ) ttl++;spin_lock_bh (&recent_lock);
@@ -274,12 +274,12 @@ recent_mt(const struct sk_buff *skb, struct xt_action_param *par)nf_inet_addr_mask (&addr, &addr_mask, &t->mask); - e =recent_entry_lookup (t, &addr_mask, par->family, + e =recent_entry_lookup (t, &addr_mask,xt_family (par), (info->check_set &XT_RECENT_TTL ) ? ttl :0 );if (e ==NULL ) {if (!(info->check_set &XT_RECENT_SET )) goto out; - e =recent_entry_init (t, &addr_mask, par->family, ttl); + e =recent_entry_init (t, &addr_mask,xt_family (par), ttl);if (e ==NULL ) par->hotdrop = true; ret = !ret;
net/netfilter/xt_set.c +13 -13
@@ -55,7 +55,7 @@ set_match_v0(const struct sk_buff *skb, struct xt_action_param *par) {const struct xt_set_info_match_v0 *info = par->matchinfo; -ADT_OPT (opt, par->family, info->match_set.u.compat.dim, +ADT_OPT (opt,xt_family (par), info->match_set.u.compat.dim, info->match_set.u.compat.flags,0 ,UINT_MAX ); return match_set(info->match_set.index, skb, par, &opt,
@@ -118,7 +118,7 @@ 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, +ADT_OPT (opt,xt_family (par), info->match_set.dim, info->match_set.flags,0 ,UINT_MAX );if (opt.flags &IPSET_RETURN_NOMATCH )
@@ -184,7 +184,7 @@ set_match_v3(const struct sk_buff *skb, struct xt_action_param *par)const struct xt_set_info_match_v3 *info = par->matchinfo;int ret; -ADT_OPT (opt, par->family, info->match_set.dim, +ADT_OPT (opt,xt_family (par), info->match_set.dim, info->match_set.flags, info->flags,UINT_MAX ); if (info->packets.op != IPSET_COUNTER_NONE ||
@@ -231,7 +231,7 @@ set_match_v4(const struct sk_buff *skb, struct xt_action_param *par)const struct xt_set_info_match_v4 *info = par->matchinfo;int ret; -ADT_OPT (opt, par->family, info->match_set.dim, +ADT_OPT (opt,xt_family (par), info->match_set.dim, info->match_set.flags, info->flags,UINT_MAX ); if (info->packets.op != IPSET_COUNTER_NONE ||
@@ -259,9 +259,9 @@ set_target_v0(struct sk_buff *skb, const struct xt_action_param *par) {const struct xt_set_info_target_v0 *info = par->targinfo; -ADT_OPT (add_opt, par->family, info->add_set.u.compat.dim, +ADT_OPT (add_opt,xt_family (par), info->add_set.u.compat.dim, info->add_set.u.compat.flags,0 ,UINT_MAX ); -ADT_OPT (del_opt, par->family, info->del_set.u.compat.dim, +ADT_OPT (del_opt,xt_family (par), info->del_set.u.compat.dim, info->del_set.u.compat.flags,0 ,UINT_MAX );if (info->add_set.index !=IPSET_INVALID_ID )
@@ -332,9 +332,9 @@ set_target_v1(struct sk_buff *skb, const struct xt_action_param *par) {const struct xt_set_info_target_v1 *info = par->targinfo; -ADT_OPT (add_opt, par->family, info->add_set.dim, +ADT_OPT (add_opt,xt_family (par), info->add_set.dim, info->add_set.flags,0 ,UINT_MAX ); -ADT_OPT (del_opt, par->family, info->del_set.dim, +ADT_OPT (del_opt,xt_family (par), info->del_set.dim, info->del_set.flags,0 ,UINT_MAX );if (info->add_set.index !=IPSET_INVALID_ID )
@@ -401,9 +401,9 @@ set_target_v2(struct sk_buff *skb, const struct xt_action_param *par) {const struct xt_set_info_target_v2 *info = par->targinfo; -ADT_OPT (add_opt, par->family, info->add_set.dim, +ADT_OPT (add_opt,xt_family (par), info->add_set.dim, info->add_set.flags, info->flags, info->timeout); -ADT_OPT (del_opt, par->family, info->del_set.dim, +ADT_OPT (del_opt,xt_family (par), info->del_set.dim, info->del_set.flags,0 ,UINT_MAX );/* Normalize to fit into jiffies */
@@ -429,11 +429,11 @@ set_target_v3(struct sk_buff *skb, const struct xt_action_param *par)const struct xt_set_info_target_v3 *info = par->targinfo;int ret; -ADT_OPT (add_opt, par->family, info->add_set.dim, +ADT_OPT (add_opt,xt_family (par), info->add_set.dim, info->add_set.flags, info->flags, info->timeout); -ADT_OPT (del_opt, par->family, info->del_set.dim, +ADT_OPT (del_opt,xt_family (par), info->del_set.dim, info->del_set.flags,0 ,UINT_MAX ); -ADT_OPT (map_opt, par->family, info->map_set.dim, +ADT_OPT (map_opt,xt_family (par), info->map_set.dim, info->map_set.flags,0 ,UINT_MAX );/* Normalize to fit into jiffies */
net/netfilter/xt_socket.c +2 -2
@@ -57,7 +57,7 @@ socket_match(const struct sk_buff *skb, struct xt_action_param *par,struct sock *sk = skb->sk;if (!sk) - sk =nf_sk_lookup_slow_v4 (par->net, skb, par->in); + sk =nf_sk_lookup_slow_v4 (xt_net (par), skb,xt_in (par));if (sk) {bool wildcard;bool transparent = true;
@@ -114,7 +114,7 @@ socket_mt6_v1_v2_v3(const struct sk_buff *skb, struct xt_action_param *par)struct sock *sk = skb->sk;if (!sk) - sk =nf_sk_lookup_slow_v6 (par->net, skb, par->in); + sk =nf_sk_lookup_slow_v6 (xt_net (par), skb,xt_in (par));if (sk) {bool wildcard;bool transparent = true;
net/sched/act_ipt.c +7 -5
@@ -213,6 +213,12 @@ static int tcf_ipt(struct sk_buff *skb, const struct tc_action *a,int ret =0 , result =0 ;struct tcf_ipt *ipt =to_ipt (a);struct xt_action_param par; +struct nf_hook_state state = { + .net =dev_net (skb->dev), + .in = skb->dev, + .hook = ipt->tcfi_hook, + .pf =NFPROTO_IPV4 , + };if (skb_unclone (skb,GFP_ATOMIC ))return TC_ACT_UNSPEC ;
@@ -226,13 +232,9 @@ static int tcf_ipt(struct sk_buff *skb, const struct tc_action *a,* worry later - danger - this API seems to have changed * from earlier kernels */ - par.net =dev_net (skb->dev); - par.in = skb->dev; - par.out =NULL ; - par.hooknum = ipt->tcfi_hook; + par.state = &state; par.target = ipt->tcfi_t->u.kernel.target; par.targinfo = ipt->tcfi_t->data; - par.family =NFPROTO_IPV4 ; ret = par.target->target (skb, &par);switch (ret) {
net/sched/em_ipset.c +9 -8
@@ -57,17 +57,20 @@ static int em_ipset_match(struct sk_buff *skb, struct tcf_ematch *em,struct xt_action_param acpar;const struct xt_set_info *set = (const void *) em->data;struct net_device *dev, *indev =NULL ; +struct nf_hook_state state = { + .net = em->net, + };int ret, network_offset;switch (tc_skb_protocol (skb)) {case htons (ETH_P_IP ): - acpar.family =NFPROTO_IPV4 ; + state.pf =NFPROTO_IPV4 ;if (!pskb_network_may_pull (skb,sizeof (struct iphdr )))return 0 ; acpar.thoff =ip_hdrlen (skb);break ;case htons (ETH_P_IPV6 ): - acpar.family =NFPROTO_IPV6 ; + state.pf =NFPROTO_IPV6 ;if (!pskb_network_may_pull (skb,sizeof (struct ipv6hdr )))return 0 ;/* doesn't call ipv6_find_hdr() because ipset doesn't use thoff, yet */
@@ -77,9 +80,7 @@ static int em_ipset_match(struct sk_buff *skb, struct tcf_ematch *em,return 0 ; } - acpar.hooknum =0 ; - - opt.family = acpar.family; + opt.family = state.pf; opt.dim = set->dim; opt.flags = set->flags; opt.cmdflags =0 ;
@@ -95,9 +96,9 @@ static int em_ipset_match(struct sk_buff *skb, struct tcf_ematch *em,if (skb->skb_iif) indev =dev_get_by_index_rcu (em->net, skb->skb_iif); - acpar.net = em->net; - acpar.in = indev ? indev : dev; - acpar.out = dev; + state.in = indev ? indev : dev; + state.out = dev; + acpar.state = &state; ret =ip_set_test (set->index, skb, &acpar, &opt);
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 6/39 netfilter: nf_tables: use hook state from xt_action_param structure
In reply to Pablo Neira AyusoDon't copy relevant fields from hook state structure, instead use the one that is already available in struct xt_action_param.
This patch also adds a set of new wrapper functions to fetch relevant hook state structure fields.
--- include/net/netfilter/nf_tables.h | 35 +++++++++++++++++++++++--------- net/bridge/netfilter/nft_meta_bridge.c | 2 +- net/bridge/netfilter/nft_reject_bridge.c | 30 ++++++++++++++++----------- net/ipv4/netfilter/nft_dup_ipv4.c | 2 +- net/ipv4/netfilter/nft_fib_ipv4.c | 14 ++++++------- net/ipv4/netfilter/nft_masq_ipv4.c | 4 ++-- net/ipv4/netfilter/nft_redir_ipv4.c | 3 +-- net/ipv4/netfilter/nft_reject_ipv4.c | 4 ++-- net/ipv6/netfilter/nft_dup_ipv6.c | 2 +- net/ipv6/netfilter/nft_fib_ipv6.c | 16 +++++++-------- net/ipv6/netfilter/nft_masq_ipv6.c | 3 ++- net/ipv6/netfilter/nft_redir_ipv6.c | 3 ++- net/ipv6/netfilter/nft_reject_ipv6.c | 6 +++--- net/netfilter/nf_dup_netdev.c | 2 +- net/netfilter/nf_tables_core.c | 10 ++++----- net/netfilter/nf_tables_trace.c | 8 ++++---- net/netfilter/nft_fib.c | 2 +- net/netfilter/nft_fib_inet.c | 2 +- net/netfilter/nft_log.c | 5 +++-- net/netfilter/nft_lookup.c | 5 ++--- net/netfilter/nft_meta.c | 6 +++--- net/netfilter/nft_queue.c | 2 +- net/netfilter/nft_reject_inet.c | 18 ++++++++-------- net/netfilter/nft_rt.c | 4 ++-- 24 files changed, 105 insertions(+), 83 deletions(-)
include/net/netfilter/nf_tables.h +25 -10
@@ -14,27 +14,42 @@struct nft_pktinfo {struct sk_buff *skb; -struct net *net; -const struct net_device *in; -const struct net_device *out; -u8 pf; -u8 hook;bool tprot_set;u8 tprot;/* for x_tables compatibility */ struct xt_action_param xt; }; +static inline struct net *nft_net (const struct nft_pktinfo *pkt) +{ +return pkt->xt.state->net; +} + +static inline unsigned int nft_hook (const struct nft_pktinfo *pkt) +{ +return pkt->xt.state->hook; +} + +static inline u8 nft_pf (const struct nft_pktinfo *pkt) +{ +return pkt->xt.state->pf; +} + +static inline const struct net_device *nft_in (const struct nft_pktinfo *pkt) +{ +return pkt->xt.state->in; +} + +static inline const struct net_device *nft_out (const struct nft_pktinfo *pkt) +{ +return pkt->xt.state->out; +} +static inline void nft_set_pktinfo (struct nft_pktinfo *pkt,struct sk_buff *skb,const struct nf_hook_state *state) { pkt->skb = skb; - pkt->net = state->net; - pkt->in = state->in; - pkt->out = state->out; - pkt->hook = state->hook; - pkt->pf = state->pf; pkt->xt.state = state; }
net/bridge/netfilter/nft_meta_bridge.c +1 -1
@@ -23,7 +23,7 @@ static void nft_meta_bridge_get_eval(const struct nft_expr *expr, const struct nft_pktinfo *pkt) {const struct nft_meta *priv =nft_expr_priv (expr); -const struct net_device *in = pkt->in, *out = pkt->out; +const struct net_device *in =nft_in (pkt), *out =nft_out (pkt);u32 *dest = ®s->data[priv->dreg];const struct net_bridge_port *p;
net/bridge/netfilter/nft_reject_bridge.c +18 -12
@@ -315,17 +315,20 @@ static void nft_reject_bridge_eval(const struct nft_expr *expr,case htons (ETH_P_IP ):switch (priv->type) {case NFT_REJECT_ICMP_UNREACH : -nft_reject_br_send_v4_unreach (pkt->net, pkt->skb, - pkt->in, pkt->hook, +nft_reject_br_send_v4_unreach (nft_net (pkt), pkt->skb, +nft_in (pkt), +nft_hook (pkt), priv->icmp_code);break ;case NFT_REJECT_TCP_RST : -nft_reject_br_send_v4_tcp_reset (pkt->net, pkt->skb, - pkt->in, pkt->hook); +nft_reject_br_send_v4_tcp_reset (nft_net (pkt), pkt->skb, +nft_in (pkt), +nft_hook (pkt));break ;case NFT_REJECT_ICMPX_UNREACH : -nft_reject_br_send_v4_unreach (pkt->net, pkt->skb, - pkt->in, pkt->hook, +nft_reject_br_send_v4_unreach (nft_net (pkt), pkt->skb, +nft_in (pkt), +nft_hook (pkt),nft_reject_icmp_code (priv->icmp_code));break ; }
@@ -333,17 +336,20 @@ static void nft_reject_bridge_eval(const struct nft_expr *expr,case htons (ETH_P_IPV6 ):switch (priv->type) {case NFT_REJECT_ICMP_UNREACH : -nft_reject_br_send_v6_unreach (pkt->net, pkt->skb, - pkt->in, pkt->hook, +nft_reject_br_send_v6_unreach (nft_net (pkt), pkt->skb, +nft_in (pkt), +nft_hook (pkt), priv->icmp_code);break ;case NFT_REJECT_TCP_RST : -nft_reject_br_send_v6_tcp_reset (pkt->net, pkt->skb, - pkt->in, pkt->hook); +nft_reject_br_send_v6_tcp_reset (nft_net (pkt), pkt->skb, +nft_in (pkt), +nft_hook (pkt));break ;case NFT_REJECT_ICMPX_UNREACH : -nft_reject_br_send_v6_unreach (pkt->net, pkt->skb, - pkt->in, pkt->hook, +nft_reject_br_send_v6_unreach (nft_net (pkt), pkt->skb, +nft_in (pkt), +nft_hook (pkt),nft_reject_icmpv6_code (priv->icmp_code));break ; }
net/ipv4/netfilter/nft_dup_ipv4.c +1 -1
@@ -30,7 +30,7 @@ static void nft_dup_ipv4_eval(const struct nft_expr *expr, };int oif = regs->data[priv->sreg_dev]; -nf_dup_ipv4 (pkt->net, pkt->skb, pkt->hook, &gw, oif); +nf_dup_ipv4 (nft_net (pkt), pkt->skb,nft_hook (pkt), &gw, oif); } static int nft_dup_ipv4_init(const struct nft_ctx *ctx,
net/ipv4/netfilter/nft_fib_ipv4.c +7 -7
@@ -45,9 +45,9 @@ void nft_fib4_eval_type(const struct nft_expr *expr, struct nft_regs *regs,__be32 addr;if (priv->flags &NFTA_FIB_F_IIF ) - dev = pkt->in; + dev =nft_in (pkt);else if (priv->flags &NFTA_FIB_F_OIF ) - dev = pkt->out; + dev =nft_out (pkt); iph =ip_hdr (pkt->skb);if (priv->flags &NFTA_FIB_F_DADDR )
@@ -55,7 +55,7 @@ void nft_fib4_eval_type(const struct nft_expr *expr, struct nft_regs *regs,else addr = iph->saddr; - *dst =inet_dev_addr_type (pkt->net, dev, addr); + *dst =inet_dev_addr_type (nft_net (pkt), dev, addr); }EXPORT_SYMBOL_GPL (nft_fib4_eval_type);
@@ -89,13 +89,13 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,* Search results for the desired outinterface instead. */ if (priv->flags &NFTA_FIB_F_OIF ) - oif = pkt->out; + oif =nft_out (pkt);else if (priv->flags &NFTA_FIB_F_IIF ) - oif = pkt->in; + oif =nft_in (pkt);else oif =NULL ; -if (pkt->hook ==NF_INET_PRE_ROUTING &&fib4_is_local (pkt->skb)) { +if (nft_hook (pkt) ==NF_INET_PRE_ROUTING &&fib4_is_local (pkt->skb)) {nft_fib_store_result (dest, priv->result, pkt,LOOPBACK_IFINDEX );return ; }
@@ -122,7 +122,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs, fl4.saddr =get_saddr (iph->daddr); } -if (fib_lookup (pkt->net, &fl4, &res,FIB_LOOKUP_IGNORE_LINKSTATE )) +if (fib_lookup (nft_net (pkt), &fl4, &res,FIB_LOOKUP_IGNORE_LINKSTATE ))return ;switch (res.type) {
net/ipv4/netfilter/nft_masq_ipv4.c +2 -2
@@ -31,8 +31,8 @@ static void nft_masq_ipv4_eval(const struct nft_expr *expr, range.max_proto.all = *(__be16 *)®s->data[priv->sreg_proto_max]; } - regs->verdict.code =nf_nat_masquerade_ipv4 (pkt->skb, pkt->hook, - &range, pkt->out); + regs->verdict.code =nf_nat_masquerade_ipv4 (pkt->skb,nft_hook (pkt), + &range,nft_out (pkt)); }static struct nft_expr_type nft_masq_ipv4_type;
net/ipv4/netfilter/nft_redir_ipv4.c +1 -2
@@ -35,8 +35,7 @@ static void nft_redir_ipv4_eval(const struct nft_expr *expr, mr.range[0 ].flags |= priv->flags; - regs->verdict.code =nf_nat_redirect_ipv4 (pkt->skb, &mr, - pkt->hook); + regs->verdict.code =nf_nat_redirect_ipv4 (pkt->skb, &mr,nft_hook (pkt)); }static struct nft_expr_type nft_redir_ipv4_type;
net/ipv4/netfilter/nft_reject_ipv4.c +2 -2
@@ -27,10 +27,10 @@ static void nft_reject_ipv4_eval(const struct nft_expr *expr,switch (priv->type) {case NFT_REJECT_ICMP_UNREACH : -nf_send_unreach (pkt->skb, priv->icmp_code, pkt->hook); +nf_send_unreach (pkt->skb, priv->icmp_code,nft_hook (pkt));break ;case NFT_REJECT_TCP_RST : -nf_send_reset (pkt->net, pkt->skb, pkt->hook); +nf_send_reset (nft_net (pkt), pkt->skb,nft_hook (pkt));break ;default :break ;
net/ipv6/netfilter/nft_dup_ipv6.c +1 -1
@@ -28,7 +28,7 @@ static void nft_dup_ipv6_eval(const struct nft_expr *expr,struct in6_addr *gw = (struct in6_addr *)®s->data[priv->sreg_addr];int oif = regs->data[priv->sreg_dev]; -nf_dup_ipv6 (pkt->net, pkt->skb, pkt->hook, gw, oif); +nf_dup_ipv6 (nft_net (pkt), pkt->skb,nft_hook (pkt), gw, oif); } static int nft_dup_ipv6_init(const struct nft_ctx *ctx,
net/ipv6/netfilter/nft_fib_ipv6.c +8 -8
@@ -80,17 +80,17 @@ static u32 __nft_fib6_eval_type(const struct nft_fib *priv,return RTN_UNREACHABLE ;if (priv->flags &NFTA_FIB_F_IIF ) - dev = pkt->in; + dev =nft_in (pkt);else if (priv->flags &NFTA_FIB_F_OIF ) - dev = pkt->out; + dev =nft_out (pkt);nft_fib6_flowi_init (&fl6, priv, pkt, dev); v6ops =nf_get_ipv6_ops (); -if (dev && v6ops && v6ops->chk_addr (pkt->net, &fl6.daddr, dev, true)) +if (dev && v6ops && v6ops->chk_addr (nft_net (pkt), &fl6.daddr, dev, true)) ret =RTN_LOCAL ; - route_err = afinfo->route (pkt->net, (struct dst_entry **)&rt, + route_err = afinfo->route (nft_net (pkt), (struct dst_entry **)&rt,flowi6_to_flowi (&fl6), false);if (route_err) goto err;
@@ -158,20 +158,20 @@ void nft_fib6_eval(const struct nft_expr *expr, struct nft_regs *regs,int lookup_flags;if (priv->flags &NFTA_FIB_F_IIF ) - oif = pkt->in; + oif =nft_in (pkt);else if (priv->flags &NFTA_FIB_F_OIF ) - oif = pkt->out; + oif =nft_out (pkt); lookup_flags =nft_fib6_flowi_init (&fl6, priv, pkt, oif); -if (pkt->hook ==NF_INET_PRE_ROUTING &&fib6_is_local (pkt->skb)) { +if (nft_hook (pkt) ==NF_INET_PRE_ROUTING &&fib6_is_local (pkt->skb)) {nft_fib_store_result (dest, priv->result, pkt,LOOPBACK_IFINDEX );return ; } *dest =0 ; again: - rt = (void *)ip6_route_lookup (pkt->net, &fl6, lookup_flags); + rt = (void *)ip6_route_lookup (nft_net (pkt), &fl6, lookup_flags);if (rt->dst.error) goto put_rt_err;
net/ipv6/netfilter/nft_masq_ipv6.c +2 -1
@@ -32,7 +32,8 @@ static void nft_masq_ipv6_eval(const struct nft_expr *expr, range.max_proto.all = *(__be16 *)®s->data[priv->sreg_proto_max]; } - regs->verdict.code =nf_nat_masquerade_ipv6 (pkt->skb, &range, pkt->out); + regs->verdict.code =nf_nat_masquerade_ipv6 (pkt->skb, &range, +nft_out (pkt)); }static struct nft_expr_type nft_masq_ipv6_type;
net/ipv6/netfilter/nft_redir_ipv6.c +2 -1
@@ -35,7 +35,8 @@ static void nft_redir_ipv6_eval(const struct nft_expr *expr, range.flags |= priv->flags; - regs->verdict.code =nf_nat_redirect_ipv6 (pkt->skb, &range, pkt->hook); + regs->verdict.code = +nf_nat_redirect_ipv6 (pkt->skb, &range,nft_hook (pkt)); }static struct nft_expr_type nft_redir_ipv6_type;
net/ipv6/netfilter/nft_reject_ipv6.c +3 -3
@@ -27,11 +27,11 @@ static void nft_reject_ipv6_eval(const struct nft_expr *expr,switch (priv->type) {case NFT_REJECT_ICMP_UNREACH : -nf_send_unreach6 (pkt->net, pkt->skb, priv->icmp_code, - pkt->hook); +nf_send_unreach6 (nft_net (pkt), pkt->skb, priv->icmp_code, +nft_hook (pkt));break ;case NFT_REJECT_TCP_RST : -nf_send_reset6 (pkt->net, pkt->skb, pkt->hook); +nf_send_reset6 (nft_net (pkt), pkt->skb,nft_hook (pkt));break ;default :break ;
net/netfilter/nf_dup_netdev.c +1 -1
@@ -19,7 +19,7 @@ void nf_dup_netdev_egress(const struct nft_pktinfo *pkt, int oif)struct net_device *dev;struct sk_buff *skb; - dev =dev_get_by_index_rcu (pkt->net, oif); + dev =dev_get_by_index_rcu (nft_net (pkt), oif);if (dev ==NULL )return ;
net/netfilter/nf_tables_core.c +5 -5
@@ -53,10 +53,10 @@ static noinline void __nft_trace_packet(struct nft_traceinfo *info,nft_trace_notify (info); -nf_log_trace (pkt->net, pkt->pf, pkt->hook, pkt->skb, pkt->in, - pkt->out, &trace_loginfo,"TRACE: %s:%s:%s:%u " , - chain->table->name, chain->name, comments[type], - rulenum); +nf_log_trace (nft_net (pkt),nft_pf (pkt),nft_hook (pkt), pkt->skb, +nft_in (pkt),nft_out (pkt), &trace_loginfo, +"TRACE: %s:%s:%s:%u " , + chain->table->name, chain->name, comments[type], rulenum); } static inline void nft_trace_packet(struct nft_traceinfo *info,
@@ -124,7 +124,7 @@ unsigned int nft_do_chain(struct nft_pktinfo *pkt, void *priv) { const struct nft_chain *chain = priv, *basechain = chain; -const struct net *net = pkt->net; +const struct net *net =nft_net (pkt);const struct nft_rule *rule;const struct nft_expr *expr, *last;struct nft_regs regs;
net/netfilter/nf_tables_trace.c +4 -4
@@ -171,7 +171,7 @@ void nft_trace_notify(struct nft_traceinfo *info)unsigned int size;int event = (NFNL_SUBSYS_NFTABLES <<8 ) |NFT_MSG_TRACE ; -if (!nfnetlink_has_listeners (pkt->net,NFNLGRP_NFTRACE )) +if (!nfnetlink_has_listeners (nft_net (pkt),NFNLGRP_NFTRACE ))return ; size = nlmsg_total_size(sizeof(struct nfgenmsg)) +
@@ -207,7 +207,7 @@ void nft_trace_notify(struct nft_traceinfo *info) nfmsg->version =NFNETLINK_V0 ; nfmsg->res_id =0 ; -if (nla_put_be32 (skb,NFTA_TRACE_NFPROTO ,htonl (pkt->pf))) +if (nla_put_be32 (skb,NFTA_TRACE_NFPROTO ,htonl (nft_pf (pkt)))) goto nla_put_failure;if (nla_put_be32 (skb,NFTA_TRACE_TYPE ,htonl (info->type)))
@@ -249,7 +249,7 @@ void nft_trace_notify(struct nft_traceinfo *info) goto nla_put_failure;if (!info->packet_dumped) { -if (nf_trace_fill_dev_info (skb, pkt->in, pkt->out)) +if (nf_trace_fill_dev_info (skb,nft_in (pkt),nft_out (pkt))) goto nla_put_failure;if (nf_trace_fill_pkt_info (skb, pkt))
@@ -258,7 +258,7 @@ void nft_trace_notify(struct nft_traceinfo *info) }nlmsg_end (skb, nlh); -nfnetlink_send (skb, pkt->net,0 ,NFNLGRP_NFTRACE ,0 ,GFP_ATOMIC ); +nfnetlink_send (skb,nft_net (pkt),0 ,NFNLGRP_NFTRACE ,0 ,GFP_ATOMIC );return ; nla_put_failure:
net/netfilter/nft_fib.c +1 -1
@@ -144,7 +144,7 @@ void nft_fib_store_result(void *reg, enum nft_fib_result r, *dreg = index;break ;case NFT_FIB_RESULT_OIFNAME : - dev =dev_get_by_index_rcu (pkt->net, index); + dev =dev_get_by_index_rcu (nft_net (pkt), index);strncpy (reg, dev ? dev->name :"" ,IFNAMSIZ );break ;default :
net/netfilter/nft_fib_inet.c +1 -1
@@ -21,7 +21,7 @@ static void nft_fib_inet_eval(const struct nft_expr *expr, {const struct nft_fib *priv =nft_expr_priv (expr); -switch (pkt->pf) { +switch (nft_pf (pkt)) {case NFPROTO_IPV4 :switch (priv->result) {case NFT_FIB_RESULT_OIF :
net/netfilter/nft_log.c +3 -2
@@ -32,8 +32,9 @@ static void nft_log_eval(const struct nft_expr *expr, {const struct nft_log *priv =nft_expr_priv (expr); -nf_log_packet (pkt->net, pkt->pf, pkt->hook, pkt->skb, pkt->in, - pkt->out, &priv->loginfo,"%s" , priv->prefix); +nf_log_packet (nft_net (pkt),nft_pf (pkt),nft_hook (pkt), pkt->skb, +nft_in (pkt),nft_out (pkt), &priv->loginfo,"%s" , + priv->prefix); }static const struct nla_policy nft_log_policy[NFTA_LOG_MAX +1 ] = {
net/netfilter/nft_lookup.c +2 -3
@@ -35,9 +35,8 @@ static void nft_lookup_eval(const struct nft_expr *expr,const struct nft_set_ext *ext;bool found; - found = set->ops->lookup (pkt->net, set, ®s->data[priv->sreg], &ext) ^ - priv->invert; - + found = set->ops->lookup (nft_net (pkt), set, ®s->data[priv->sreg], + &ext) ^ priv->invert;if (!found) { regs->verdict.code =NFT_BREAK ;return ;
net/netfilter/nft_meta.c +3 -3
@@ -36,7 +36,7 @@ void nft_meta_get_eval(const struct nft_expr *expr, {const struct nft_meta *priv =nft_expr_priv (expr);const struct sk_buff *skb = pkt->skb; -const struct net_device *in = pkt->in, *out = pkt->out; +const struct net_device *in =nft_in (pkt), *out =nft_out (pkt);struct sock *sk;u32 *dest = ®s->data[priv->dreg];
@@ -49,7 +49,7 @@ void nft_meta_get_eval(const struct nft_expr *expr, *(__be16 *)dest = skb->protocol;break ;case NFT_META_NFPROTO : - *dest = pkt->pf; + *dest =nft_pf (pkt);break ;case NFT_META_L4PROTO :if (!pkt->tprot_set)
@@ -146,7 +146,7 @@ void nft_meta_get_eval(const struct nft_expr *expr,break ; } -switch (pkt->pf) { +switch (nft_pf (pkt)) {case NFPROTO_IPV4 :if (ipv4_is_multicast (ip_hdr (skb)->daddr)) *dest =PACKET_MULTICAST ;
net/netfilter/nft_queue.c +1 -1
@@ -43,7 +43,7 @@ static void nft_queue_eval(const struct nft_expr *expr, queue = priv->queuenum + cpu % priv->queues_total; }else { queue =nfqueue_hash (pkt->skb, queue, - priv->queues_total, pkt->pf, + priv->queues_total,nft_pf (pkt), jhash_initval); } }
net/netfilter/nft_reject_inet.c +9 -9
@@ -23,36 +23,36 @@ static void nft_reject_inet_eval(const struct nft_expr *expr, {struct nft_reject *priv =nft_expr_priv (expr); -switch (pkt->pf) { +switch (nft_pf (pkt)) {case NFPROTO_IPV4 :switch (priv->type) {case NFT_REJECT_ICMP_UNREACH :nf_send_unreach (pkt->skb, priv->icmp_code, - pkt->hook); +nft_hook (pkt));break ;case NFT_REJECT_TCP_RST : -nf_send_reset (pkt->net, pkt->skb, pkt->hook); +nf_send_reset (nft_net (pkt), pkt->skb,nft_hook (pkt));break ;case NFT_REJECT_ICMPX_UNREACH :nf_send_unreach (pkt->skb,nft_reject_icmp_code (priv->icmp_code), - pkt->hook); +nft_hook (pkt));break ; }break ;case NFPROTO_IPV6 :switch (priv->type) {case NFT_REJECT_ICMP_UNREACH : -nf_send_unreach6 (pkt->net, pkt->skb, priv->icmp_code, - pkt->hook); +nf_send_unreach6 (nft_net (pkt), pkt->skb, + priv->icmp_code,nft_hook (pkt));break ;case NFT_REJECT_TCP_RST : -nf_send_reset6 (pkt->net, pkt->skb, pkt->hook); +nf_send_reset6 (nft_net (pkt), pkt->skb,nft_hook (pkt));break ;case NFT_REJECT_ICMPX_UNREACH : -nf_send_unreach6 (pkt->net, pkt->skb, +nf_send_unreach6 (nft_net (pkt), pkt->skb,nft_reject_icmpv6_code (priv->icmp_code), - pkt->hook); +nft_hook (pkt));break ; }break ;
net/netfilter/nft_rt.c +2 -2
@@ -43,14 +43,14 @@ void nft_rt_get_eval(const struct nft_expr *expr,break ;#endif case NFT_RT_NEXTHOP4 : -if (pkt->pf !=NFPROTO_IPV4 ) +if (nft_pf (pkt) !=NFPROTO_IPV4 ) goto err; *dest =rt_nexthop ((const struct rtable *)dst,ip_hdr (skb)->daddr);break ;case NFT_RT_NEXTHOP6 : -if (pkt->pf !=NFPROTO_IPV6 ) +if (nft_pf (pkt) !=NFPROTO_IPV6 ) goto err; memcpy(dest, rt6_nexthop((struct rt6_info *)dst,
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 7/39 netfilter: use switch() to handle verdict cases from nf_hook_slow()
In reply to Pablo Neira AyusoUse switch() for verdict handling and add explicit handling for NF_STOLEN and other non-conventional verdicts.
--- net/netfilter/core.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
net/netfilter/core.c +14 -4
@@ -328,22 +328,32 @@ int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state) {struct nf_hook_entry *entry;unsigned int verdict; -int ret =0 ; +int ret; entry =rcu_dereference (state->hook_entries); next_hook: verdict =nf_iterate (skb, state, &entry); -if (verdict ==NF_ACCEPT ) { +switch (verdict &NF_VERDICT_MASK ) { +case NF_ACCEPT : ret =1 ; - }else if ((verdict &NF_VERDICT_MASK ) ==NF_DROP ) { +break ; +case NF_DROP :kfree_skb (skb); ret =NF_DROP_GETERR (verdict);if (ret ==0 ) ret = -EPERM ; - }else if ((verdict &NF_VERDICT_MASK ) ==NF_QUEUE ) { +break ; +case NF_QUEUE : ret =nf_queue (skb, state, &entry, verdict);if (ret ==1 && entry) goto next_hook; +/* Fall through. */ +default : +/* Implicit handling for NF_STOLEN, as well as any other non +* conventional verdicts. +*/ + ret =0 ; +break ; }return ret; }
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 8/39 netfilter: remove hook_entries field from nf_hook_state
In reply to Pablo Neira AyusoThis field is only useful for nf_queue, so store it in the nf_queue_entry structure instead, away from the core path. Pass hook_head to nf_hook_slow().
Since we always have a valid entry on the first iteration in nf_iterate(), we can use 'do { ... } while (entry)' loop instead.
--- include/linux/netfilter.h | 10 ++++------ include/linux/netfilter_ingress.h | 4 ++-- include/net/netfilter/nf_queue.h | 1 + net/bridge/br_netfilter_hooks.c | 4 ++-- net/bridge/netfilter/ebtable_broute.c | 2 +- net/netfilter/core.c | 9 ++++----- net/netfilter/nf_queue.c | 13 +++++-------- net/netfilter/nfnetlink_queue.c | 2 +- 8 files changed, 20 insertions(+), 25 deletions(-)
include/linux/netfilter.h +4 -6
@@ -54,7 +54,6 @@ struct nf_hook_state {struct net_device *out;struct sock *sk;struct net *net; -struct nf_hook_entry __rcu *hook_entries;int (*okfn)(struct net *,struct sock *,struct sk_buff *); };
@@ -81,7 +80,6 @@ struct nf_hook_entry { }; static inline void nf_hook_state_init(struct nf_hook_state *p, - struct nf_hook_entry *hook_entry, unsigned int hook, u_int8_t pf, struct net_device *indev,
@@ -96,7 +94,6 @@ static inline void nf_hook_state_init(struct nf_hook_state *p, p->out = outdev; p->sk = sk; p->net = net; -RCU_INIT_POINTER (p->hook_entries, hook_entry); p->okfn = okfn; }
@@ -150,7 +147,8 @@ void nf_unregister_sockopt(struct nf_sockopt_ops *reg);extern struct static_key nf_hooks_needed[NFPROTO_NUMPROTO ][NF_MAX_HOOKS ];#endif -int nf_hook_slow (struct sk_buff *skb,struct nf_hook_state *state); +int nf_hook_slow (struct sk_buff *skb,struct nf_hook_state *state, +struct nf_hook_entry *entry);/** * nf_hook - call a netfilter hook
@@ -179,10 +177,10 @@ static inline int nf_hook(u_int8_t pf, unsigned int hook, struct net *net,if (hook_head) {struct nf_hook_state state; -nf_hook_state_init (&state, hook_head, hook, pf, indev, outdev, +nf_hook_state_init (&state, hook, pf, indev, outdev, sk, net, okfn); - ret =nf_hook_slow (skb, &state); + ret =nf_hook_slow (skb, &state, hook_head); }rcu_read_unlock ();
include/linux/netfilter_ingress.h +2 -2
@@ -26,10 +26,10 @@ static inline int nf_hook_ingress(struct sk_buff *skb)if (unlikely (!e))return 0 ; -nf_hook_state_init (&state, e,NF_NETDEV_INGRESS , +nf_hook_state_init (&state,NF_NETDEV_INGRESS ,NFPROTO_NETDEV , skb->dev,NULL ,NULL ,dev_net (skb->dev),NULL ); -return nf_hook_slow (skb, &state); +return nf_hook_slow (skb, &state, e); }static inline void nf_hook_ingress_init (struct net_device *dev)
include/net/netfilter/nf_queue.h +1 -0
@@ -12,6 +12,7 @@ struct nf_queue_entry {unsigned int id;struct nf_hook_state state; +struct nf_hook_entry *hook;u16 size;/* sizeof(entry) + saved route keys */ /* extra space to store route keys */
net/bridge/br_netfilter_hooks.c +2 -2
@@ -1018,10 +1018,10 @@ int br_nf_hook_thresh(unsigned int hook, struct net *net,/* We may already have this, but read-locks nest anyway */ rcu_read_lock (); -nf_hook_state_init (&state, elem, hook,NFPROTO_BRIDGE , indev, outdev, +nf_hook_state_init (&state, hook,NFPROTO_BRIDGE , indev, outdev, sk, net, okfn); - ret =nf_hook_slow (skb, &state); + ret =nf_hook_slow (skb, &state, elem);rcu_read_unlock ();if (ret ==1 ) ret =okfn (net, sk, skb);
net/bridge/netfilter/ebtable_broute.c +1 -1
@@ -53,7 +53,7 @@ static int ebt_broute(struct sk_buff *skb)struct nf_hook_state state;int ret; -nf_hook_state_init (&state,NULL ,NF_BR_BROUTING , +nf_hook_state_init (&state,NF_BR_BROUTING ,NFPROTO_BRIDGE , skb->dev,NULL ,NULL ,dev_net (skb->dev),NULL );
net/netfilter/core.c +4 -5
@@ -308,7 +308,7 @@ unsigned int nf_iterate(struct sk_buff *skb, {unsigned int verdict; -while (*entryp) { + do { repeat: verdict = (*entryp)->ops.hook((*entryp)->ops.priv, skb, state); if (verdict != NF_ACCEPT) {
@@ -317,20 +317,19 @@ unsigned int nf_iterate(struct sk_buff *skb, goto repeat; } *entryp =rcu_dereference ((*entryp)->next); - } + }while (*entryp);return NF_ACCEPT ; }/* Returns 1 if okfn() needs to be executed by the caller, * -EPERM for NF_DROP, 0 otherwise. Caller must hold rcu_read_lock. */ -int nf_hook_slow (struct sk_buff *skb,struct nf_hook_state *state) +int nf_hook_slow (struct sk_buff *skb,struct nf_hook_state *state, +struct nf_hook_entry *entry) { -struct nf_hook_entry *entry;unsigned int verdict;int ret; - entry =rcu_dereference (state->hook_entries); next_hook: verdict =nf_iterate (skb, state, &entry);switch (verdict &NF_VERDICT_MASK ) {
net/netfilter/nf_queue.c +5 -8
@@ -108,7 +108,7 @@ void nf_queue_nf_hook_drop(struct net *net, const struct nf_hook_entry *entry) }static int __nf_queue (struct sk_buff *skb,const struct nf_hook_state *state, -unsigned int queuenum) +struct nf_hook_entry *hook_entry,unsigned int queuenum) {int status = -ENOENT ;struct nf_queue_entry *entry =NULL ;
@@ -136,6 +136,7 @@ static int __nf_queue(struct sk_buff *skb, const struct nf_hook_state *state, *entry = (struct nf_queue_entry ) { .skb = skb, .state = *state, + .hook = hook_entry, .size =sizeof (*entry) + afinfo->route_key_size, };
@@ -163,8 +164,7 @@ int nf_queue(struct sk_buff *skb, struct nf_hook_state *state,struct nf_hook_entry *entry = *entryp;int ret; -RCU_INIT_POINTER (state->hook_entries, entry); - ret =__nf_queue (skb, state, verdict >>NF_VERDICT_QBITS ); + ret =__nf_queue (skb, state, entry, verdict >>NF_VERDICT_QBITS );if (ret <0 ) {if (ret == -ESRCH && (verdict &NF_VERDICT_FLAG_QUEUE_BYPASS )) {
@@ -179,15 +179,12 @@ int nf_queue(struct sk_buff *skb, struct nf_hook_state *state,void nf_reinject (struct nf_queue_entry *entry,unsigned int verdict) { -struct nf_hook_entry *hook_entry; +struct nf_hook_entry *hook_entry = entry->hook; +struct nf_hook_ops *elem = &hook_entry->ops;struct sk_buff *skb = entry->skb;const struct nf_afinfo *afinfo; -struct nf_hook_ops *elem;int err; - hook_entry =rcu_dereference (entry->state.hook_entries); - elem = &hook_entry->ops; -nf_queue_entry_release_refs (entry);/* Continue traversal iff userspace said ok... */
net/netfilter/nfnetlink_queue.c +1 -1
@@ -919,7 +919,7 @@ static struct notifier_block nfqnl_dev_notifier = {static int nf_hook_cmp (struct nf_queue_entry *entry,unsigned long entry_ptr) { -return rcu_access_pointer (entry->state.hook_entries) == +return rcu_access_pointer (entry->hook) == (struct nf_hook_entry *)entry_ptr; }
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 9/39 netfilter: merge nf_iterate() into nf_hook_slow()
In reply to Pablo Neira Ayusonf_iterate() has become rather simple, we can integrate this code into nf_hook_slow() to reduce the amount of LOC in the core path.
However, we still need nf_iterate() around for nf_queue packet handling, so move this function there where we only need it. I think it should be possible to refactor nf_queue code to get rid of it definitely, but given this is slow path anyway, let's have a look this later.
--- net/netfilter/core.c | 73 +++++++++++++++++--------------------------- net/netfilter/nf_internals.h | 5 --- net/netfilter/nf_queue.c | 20 ++++++++++++ 3 files changed, 48 insertions(+), 50 deletions(-)
net/netfilter/core.c +28 -45
@@ -302,26 +302,6 @@ void _nf_unregister_hooks(struct nf_hook_ops *reg, unsigned int n) }EXPORT_SYMBOL (_nf_unregister_hooks); -unsigned int nf_iterate (struct sk_buff *skb, -struct nf_hook_state *state, -struct nf_hook_entry **entryp) -{ -unsigned int verdict; - -do { -repeat: - verdict = (*entryp)->ops.hook ((*entryp)->ops.priv, skb, state); -if (verdict !=NF_ACCEPT ) { -if (verdict !=NF_REPEAT ) -return verdict; - goto repeat; - } - *entryp =rcu_dereference ((*entryp)->next); - }while (*entryp); -return NF_ACCEPT ; -} - -/* Returns 1 if okfn() needs to be executed by the caller, * -EPERM for NF_DROP, 0 otherwise. Caller must hold rcu_read_lock. */ int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state,
@@ -330,31 +310,34 @@ int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state,unsigned int verdict;int ret; -next_hook: - verdict =nf_iterate (skb, state, &entry); -switch (verdict &NF_VERDICT_MASK ) { -case NF_ACCEPT : - ret =1 ; -break ; -case NF_DROP : -kfree_skb (skb); - ret =NF_DROP_GETERR (verdict); -if (ret ==0 ) - ret = -EPERM ; -break ; -case NF_QUEUE : - ret =nf_queue (skb, state, &entry, verdict); -if (ret ==1 && entry) - goto next_hook; -/* Fall through. */ -default : -/* Implicit handling for NF_STOLEN, as well as any other non -* conventional verdicts. -*/ - ret =0 ; -break ; - } -return ret; +do { + verdict = entry->ops.hook (entry->ops.priv, skb, state); +switch (verdict &NF_VERDICT_MASK ) { +case NF_ACCEPT : + entry =rcu_dereference (entry->next); +break ; +case NF_DROP : +kfree_skb (skb); + ret =NF_DROP_GETERR (verdict); +if (ret ==0 ) + ret = -EPERM ; +return ret; +case NF_REPEAT : +continue ; +case NF_QUEUE : + ret =nf_queue (skb, state, &entry, verdict); +if (ret ==1 && entry) +continue ; +return ret; +default : +/* Implicit handling for NF_STOLEN, as well as any other +* non conventional verdicts. +*/ +return 0 ; + } + }while (entry); + +return 1 ; }EXPORT_SYMBOL (nf_hook_slow);
net/netfilter/nf_internals.h +0 -5
@@ -11,11 +11,6 @@ #define NFDEBUG(format, args...)#endif - -/* core.c */ -unsigned int nf_iterate (struct sk_buff *skb,struct nf_hook_state *state, -struct nf_hook_entry **entryp); -/* nf_queue.c */ int nf_queue (struct sk_buff *skb,struct nf_hook_state *state,struct nf_hook_entry **entryp,unsigned int verdict);
net/netfilter/nf_queue.c +20 -0
@@ -177,6 +177,26 @@ int nf_queue(struct sk_buff *skb, struct nf_hook_state *state,return 0 ; } +static unsigned int nf_iterate (struct sk_buff *skb, +struct nf_hook_state *state, +struct nf_hook_entry **entryp) +{ +unsigned int verdict; + +do { +repeat: + verdict = (*entryp)->ops.hook ((*entryp)->ops.priv, skb, state); +if (verdict !=NF_ACCEPT ) { +if (verdict !=NF_REPEAT ) +return verdict; + goto repeat; + } + *entryp =rcu_dereference ((*entryp)->next); + }while (*entryp); + +return NF_ACCEPT ; +} +void nf_reinject (struct nf_queue_entry *entry,unsigned int verdict) {struct nf_hook_entry *hook_entry = entry->hook;
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 10/39 netfilter: handle NF_REPEAT from nf_conntrack_in()
In reply to Pablo Neira AyusoNF_REPEAT is only needed from nf_conntrack_in() under a very specific case required by the TCP protocol tracker, we can handle this case without returning to the core hook path. Handling of NF_REPEAT from the nf_reinject() is left untouched.
--- net/netfilter/core.c | 2 -- net/netfilter/nf_conntrack_core.c | 11 ++++++----- net/openvswitch/conntrack.c | 8 ++------ 3 files changed, 8 insertions(+), 13 deletions(-)
net/netfilter/core.c +0 -2
@@ -322,8 +322,6 @@ int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state,if (ret ==0 ) ret = -EPERM ;return ret; -case NF_REPEAT : -continue ;case NF_QUEUE : ret =nf_queue (skb, state, &entry, verdict);if (ret ==1 && entry)
net/netfilter/nf_conntrack_core.c +6 -5
@@ -1305,7 +1305,7 @@ nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum,if (skb->nfct) goto out; } - +repeat: ct =resolve_normal_ct (net, tmpl, skb, dataoff, pf, protonum, l3proto, l4proto, &set_reply, &ctinfo);if (!ct) {
@@ -1345,11 +1345,12 @@ nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum,nf_conntrack_event_cache (IPCT_REPLY , ct); out:if (tmpl) { -/* Special case: we have to repeat this hook, assign the -* template again to this packet. We assume that this packet -* has no conntrack assigned. This is used by nf_ct_tcp. */ +/* Special case: TCP tracker reports an attempt to reopen a +* closed/aborted connection. We have to go back and create a +* fresh conntrack. +*/ if (ret ==NF_REPEAT ) - skb->nfct = (struct nf_conntrack *)tmpl; + goto repeat;else nf_ct_put (tmpl); }
net/openvswitch/conntrack.c +2 -6
@@ -725,12 +725,8 @@ static int __ovs_ct_lookup(struct net *net, struct sw_flow_key *key, skb->nfctinfo =IP_CT_NEW ; } -/* Repeat if requested, see nf_iterate(). */ -do { - err =nf_conntrack_in (net, info->family, -NF_INET_PRE_ROUTING , skb); - }while (err ==NF_REPEAT ); - + err =nf_conntrack_in (net, info->family, +NF_INET_PRE_ROUTING , skb);if (err !=NF_ACCEPT )return -ENOENT ;
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 11/39 netfilter: nft_hash: get random bytes if seed is not specified
In reply to Pablo Neira AyusoIf the user doesn't specify a seed, generate one at configuration time.
--- net/netfilter/nft_hash.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/netfilter/nft_hash.c +4 -2
@@ -57,7 +57,6 @@ static int nft_hash_init(const struct nft_ctx *ctx,if (!tb[NFTA_HASH_SREG ] || !tb[NFTA_HASH_DREG ] || !tb[NFTA_HASH_LEN ] || - !tb[NFTA_HASH_SEED ] || !tb[NFTA_HASH_MODULUS ])return -EINVAL ;
@@ -80,7 +79,10 @@ static int nft_hash_init(const struct nft_ctx *ctx,if (priv->offset + priv->modulus -1 < priv->offset)return -EOVERFLOW ; - priv->seed =ntohl (nla_get_be32 (tb[NFTA_HASH_SEED ])); +if (tb[NFTA_HASH_SEED ]) + priv->seed =ntohl (nla_get_be32 (tb[NFTA_HASH_SEED ])); +else +get_random_bytes (&priv->seed,sizeof (priv->seed));return nft_validate_register_load (priv->sreg, len) && nft_validate_register_store(ctx, priv->dreg, NULL,
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 12/39 netfilter: nf_tables: simplify the basic expressions' init routine
In reply to Pablo Neira AyusoFrom: Liping Zhang <[email protected]>
Some basic expressions are built into nf_tables.ko, such as nft_cmp, nft_lookup, nft_range and so on. But these basic expressions' init routine is a little ugly, too many goto errX labels, and we forget to call nft_range_module_exit in the exit routine, although it is harmless.
Acctually, the init and exit routines of these basic expressions are same, i.e. do nft_register_expr in the init routine and do nft_unregister_expr in the exit routine.
So it's better to arrange them into an array and deal with them together.
--- include/net/netfilter/nf_tables_core.h | 33 ++++---------- net/netfilter/nf_tables_core.c | 80 +++++++++++----------------------- net/netfilter/nft_bitwise.c | 13 +----- net/netfilter/nft_byteorder.c | 13 +----- net/netfilter/nft_cmp.c | 13 +----- net/netfilter/nft_dynset.c | 13 +----- net/netfilter/nft_immediate.c | 13 +----- net/netfilter/nft_lookup.c | 13 +----- net/netfilter/nft_payload.c | 13 +----- net/netfilter/nft_range.c | 13 +----- 10 files changed, 43 insertions(+), 174 deletions(-)
include/net/netfilter/nf_tables_core.h +9 -24
@@ -1,12 +1,18 @@ #ifndef _NET_NF_TABLES_CORE_H #define _NET_NF_TABLES_CORE_H +extern struct nft_expr_type nft_imm_type; +extern struct nft_expr_type nft_cmp_type; +extern struct nft_expr_type nft_lookup_type; +extern struct nft_expr_type nft_bitwise_type; +extern struct nft_expr_type nft_byteorder_type; +extern struct nft_expr_type nft_payload_type; +extern struct nft_expr_type nft_dynset_type; +extern struct nft_expr_type nft_range_type; + int nf_tables_core_module_init(void); void nf_tables_core_module_exit(void); -int nft_immediate_module_init(void); -void nft_immediate_module_exit(void); - struct nft_cmp_fast_expr { u32 data; enum nft_registers sreg:8;
@@ -25,24 +31,6 @@ static inline u32 nft_cmp_fast_mask(unsigned int len)extern const struct nft_expr_ops nft_cmp_fast_ops; -int nft_cmp_module_init (void ); -void nft_cmp_module_exit (void ); - -int nft_range_module_init (void ); -void nft_range_module_exit (void ); - -int nft_lookup_module_init (void ); -void nft_lookup_module_exit (void ); - -int nft_dynset_module_init (void ); -void nft_dynset_module_exit (void ); - -int nft_bitwise_module_init (void ); -void nft_bitwise_module_exit (void ); - -int nft_byteorder_module_init (void ); -void nft_byteorder_module_exit (void ); -struct nft_payload {enum nft_payload_bases base:8 ;u8 offset;
@@ -62,7 +50,4 @@ struct nft_payload_set {extern const struct nft_expr_ops nft_payload_fast_ops;extern struct static_key_false nft_trace_enabled; -int nft_payload_module_init (void ); -void nft_payload_module_exit (void ); -#endif /* _NET_NF_TABLES_CORE_H */
net/netfilter/nf_tables_core.c +26 -54
94 lines not on this page · raw message
net/netfilter/nft_bitwise.c +1 -12
@@ -121,7 +121,6 @@ static int nft_bitwise_dump(struct sk_buff *skb, const struct nft_expr *expr)return -1 ; } -static struct nft_expr_type nft_bitwise_type;static const struct nft_expr_ops nft_bitwise_ops = { .type = &nft_bitwise_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_bitwise )),
@@ -130,20 +129,10 @@ static const struct nft_expr_ops nft_bitwise_ops = { .dump = nft_bitwise_dump, }; -static struct nft_expr_type nft_bitwise_type__read_mostly = { +struct nft_expr_type nft_bitwise_type__read_mostly = { .name ="bitwise" , .ops = &nft_bitwise_ops, .policy = nft_bitwise_policy, .maxattr =NFTA_BITWISE_MAX , .owner =THIS_MODULE , }; - -int __init nft_bitwise_module_init (void ) -{ -return nft_register_expr (&nft_bitwise_type); -} - -void nft_bitwise_module_exit (void ) -{ -nft_unregister_expr (&nft_bitwise_type); -}
net/netfilter/nft_byteorder.c +1 -12
@@ -169,7 +169,6 @@ static int nft_byteorder_dump(struct sk_buff *skb, const struct nft_expr *expr)return -1 ; } -static struct nft_expr_type nft_byteorder_type;static const struct nft_expr_ops nft_byteorder_ops = { .type = &nft_byteorder_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_byteorder )),
@@ -178,20 +177,10 @@ static const struct nft_expr_ops nft_byteorder_ops = { .dump = nft_byteorder_dump, }; -static struct nft_expr_type nft_byteorder_type__read_mostly = { +struct nft_expr_type nft_byteorder_type__read_mostly = { .name ="byteorder" , .ops = &nft_byteorder_ops, .policy = nft_byteorder_policy, .maxattr =NFTA_BYTEORDER_MAX , .owner =THIS_MODULE , }; - -int __init nft_byteorder_module_init (void ) -{ -return nft_register_expr (&nft_byteorder_type); -} - -void nft_byteorder_module_exit (void ) -{ -nft_unregister_expr (&nft_byteorder_type); -}
net/netfilter/nft_cmp.c +1 -12
@@ -107,7 +107,6 @@ static int nft_cmp_dump(struct sk_buff *skb, const struct nft_expr *expr)return -1 ; } -static struct nft_expr_type nft_cmp_type;static const struct nft_expr_ops nft_cmp_ops = { .type = &nft_cmp_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_cmp_expr )),
@@ -208,20 +207,10 @@ nft_cmp_select_ops(const struct nft_ctx *ctx, const struct nlattr * const tb[])return &nft_cmp_ops; } -static struct nft_expr_type nft_cmp_type__read_mostly = { +struct nft_expr_type nft_cmp_type__read_mostly = { .name ="cmp" , .select_ops = nft_cmp_select_ops, .policy = nft_cmp_policy, .maxattr =NFTA_CMP_MAX , .owner =THIS_MODULE , }; - -int __init nft_cmp_module_init (void ) -{ -return nft_register_expr (&nft_cmp_type); -} - -void nft_cmp_module_exit (void ) -{ -nft_unregister_expr (&nft_cmp_type); -}
net/netfilter/nft_dynset.c +1 -12
@@ -261,7 +261,6 @@ static int nft_dynset_dump(struct sk_buff *skb, const struct nft_expr *expr)return -1 ; } -static struct nft_expr_type nft_dynset_type;static const struct nft_expr_ops nft_dynset_ops = { .type = &nft_dynset_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_dynset )),
@@ -271,20 +270,10 @@ static const struct nft_expr_ops nft_dynset_ops = { .dump = nft_dynset_dump, }; -static struct nft_expr_type nft_dynset_type__read_mostly = { +struct nft_expr_type nft_dynset_type__read_mostly = { .name ="dynset" , .ops = &nft_dynset_ops, .policy = nft_dynset_policy, .maxattr =NFTA_DYNSET_MAX , .owner =THIS_MODULE , }; - -int __init nft_dynset_module_init (void ) -{ -return nft_register_expr (&nft_dynset_type); -} - -void nft_dynset_module_exit (void ) -{ -nft_unregister_expr (&nft_dynset_type); -}
net/netfilter/nft_immediate.c +1 -12
@@ -102,7 +102,6 @@ static int nft_immediate_validate(const struct nft_ctx *ctx,return 0 ; } -static struct nft_expr_type nft_imm_type;static const struct nft_expr_ops nft_imm_ops = { .type = &nft_imm_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_immediate_expr )),
@@ -113,20 +112,10 @@ static const struct nft_expr_ops nft_imm_ops = { .validate = nft_immediate_validate, }; -static struct nft_expr_type nft_imm_type__read_mostly = { +struct nft_expr_type nft_imm_type__read_mostly = { .name ="immediate" , .ops = &nft_imm_ops, .policy = nft_immediate_policy, .maxattr =NFTA_IMMEDIATE_MAX , .owner =THIS_MODULE , }; - -int __init nft_immediate_module_init (void ) -{ -return nft_register_expr (&nft_imm_type); -} - -void nft_immediate_module_exit (void ) -{ -nft_unregister_expr (&nft_imm_type); -}
net/netfilter/nft_lookup.c +1 -12
@@ -154,7 +154,6 @@ static int nft_lookup_dump(struct sk_buff *skb, const struct nft_expr *expr)return -1 ; } -static struct nft_expr_type nft_lookup_type;static const struct nft_expr_ops nft_lookup_ops = { .type = &nft_lookup_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_lookup )),
@@ -164,20 +163,10 @@ static const struct nft_expr_ops nft_lookup_ops = { .dump = nft_lookup_dump, }; -static struct nft_expr_type nft_lookup_type__read_mostly = { +struct nft_expr_type nft_lookup_type__read_mostly = { .name ="lookup" , .ops = &nft_lookup_ops, .policy = nft_lookup_policy, .maxattr =NFTA_LOOKUP_MAX , .owner =THIS_MODULE , }; - -int __init nft_lookup_module_init (void ) -{ -return nft_register_expr (&nft_lookup_type); -} - -void nft_lookup_module_exit (void ) -{ -nft_unregister_expr (&nft_lookup_type); -}
net/netfilter/nft_payload.c +1 -12
@@ -148,7 +148,6 @@ static int nft_payload_dump(struct sk_buff *skb, const struct nft_expr *expr)return -1 ; } -static struct nft_expr_type nft_payload_type;static const struct nft_expr_ops nft_payload_ops = { .type = &nft_payload_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_payload )),
@@ -320,20 +319,10 @@ nft_payload_select_ops(const struct nft_ctx *ctx,return &nft_payload_ops; } -static struct nft_expr_type nft_payload_type__read_mostly = { +struct nft_expr_type nft_payload_type__read_mostly = { .name ="payload" , .select_ops = nft_payload_select_ops, .policy = nft_payload_policy, .maxattr =NFTA_PAYLOAD_MAX , .owner =THIS_MODULE , }; - -int __init nft_payload_module_init (void ) -{ -return nft_register_expr (&nft_payload_type); -} - -void nft_payload_module_exit (void ) -{ -nft_unregister_expr (&nft_payload_type); -}
net/netfilter/nft_range.c +1 -12
@@ -122,7 +122,6 @@ static int nft_range_dump(struct sk_buff *skb, const struct nft_expr *expr)return -1 ; } -static struct nft_expr_type nft_range_type;static const struct nft_expr_ops nft_range_ops = { .type = &nft_range_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_range_expr )),
@@ -131,20 +130,10 @@ static const struct nft_expr_ops nft_range_ops = { .dump = nft_range_dump, }; -static struct nft_expr_type nft_range_type__read_mostly = { +struct nft_expr_type nft_range_type__read_mostly = { .name ="range" , .ops = &nft_range_ops, .policy = nft_range_policy, .maxattr =NFTA_RANGE_MAX , .owner =THIS_MODULE , }; - -int __init nft_range_module_init (void ) -{ -return nft_register_expr (&nft_range_type); -} - -void nft_range_module_exit (void ) -{ -nft_unregister_expr (&nft_range_type); -}
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 13/39 netfilter: conntrack: simplify init/uninit of L4 protocol trackers
In reply to Pablo Neira AyusoFrom: Davide Caratti <[email protected]>
modify registration and deregistration of layer-4 protocol trackers to facilitate inclusion of new elements into the current list of builtin protocols. Both builtin (TCP, UDP, ICMP) and non-builtin (DCCP, GRE, SCTP, UDPlite) layer-4 protocol trackers usually register/deregister themselves using consecutive calls to nf_ct_l4proto_{,pernet}_{,un}register(...). This sequence is interrupted and rolled back in case of error; in order to simplify addition of builtin protocols, the input of the above functions has been modified to allow registering/unregistering multiple protocols.
--- include/net/netfilter/nf_conntrack_l4proto.h | 18 ++++-- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 76 +++++++---------------- net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 78 ++++++++--------------- net/netfilter/nf_conntrack_proto.c | 85 ++++++++++++++++++++++---- net/netfilter/nf_conntrack_proto_dccp.c | 48 ++++----------- net/netfilter/nf_conntrack_proto_gre.c | 11 ++-- net/netfilter/nf_conntrack_proto_sctp.c | 50 ++++----------- net/netfilter/nf_conntrack_proto_udplite.c | 50 ++++----------- 8 files changed, 179 insertions(+), 237 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +14 -4
@@ -125,14 +125,24 @@ struct nf_conntrack_l4proto *nf_ct_l4proto_find_get(u_int16_t l3proto,void nf_ct_l4proto_put (struct nf_conntrack_l4proto *p);/* Protocol pernet registration. */ +int nf_ct_l4proto_pernet_register_one (struct net *net, +struct nf_conntrack_l4proto *proto); +void nf_ct_l4proto_pernet_unregister_one (struct net *net, +struct nf_conntrack_l4proto *proto);int nf_ct_l4proto_pernet_register (struct net *net, -struct nf_conntrack_l4proto *proto); +struct nf_conntrack_l4proto *proto[], +unsigned int num_proto);void nf_ct_l4proto_pernet_unregister (struct net *net, -struct nf_conntrack_l4proto *proto); +struct nf_conntrack_l4proto *proto[], +unsigned int num_proto);/* Protocol global registration. */ -int nf_ct_l4proto_register (struct nf_conntrack_l4proto *proto); -void nf_ct_l4proto_unregister (struct nf_conntrack_l4proto *proto); +int nf_ct_l4proto_register_one (struct nf_conntrack_l4proto *proto); +void nf_ct_l4proto_unregister_one (struct nf_conntrack_l4proto *proto); +int nf_ct_l4proto_register (struct nf_conntrack_l4proto *proto[], +unsigned int num_proto); +void nf_ct_l4proto_unregister (struct nf_conntrack_l4proto *proto[], +unsigned int num_proto);/* Generic netlink helpers */ int nf_ct_port_tuple_to_nlattr(struct sk_buff *skb,
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +23 -53
116 lines not on this page · raw message
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +24 -54
117 lines not on this page · raw message
net/netfilter/nf_conntrack_proto.c +73 -12
130 lines not on this page · raw message
net/netfilter/nf_conntrack_proto_dccp.c +13 -35
72 lines not on this page · raw message
net/netfilter/nf_conntrack_proto_gre.c +6 -5
@@ -396,7 +396,9 @@ static struct nf_conntrack_l4proto nf_conntrack_l4proto_gre4 __read_mostly = {static int proto_gre_net_init (struct net *net) {int ret =0 ; - ret =nf_ct_l4proto_pernet_register (net, &nf_conntrack_l4proto_gre4); + + ret =nf_ct_l4proto_pernet_register_one (net, + &nf_conntrack_l4proto_gre4);if (ret <0 )pr_err ("nf_conntrack_gre4: pernet registration failed.\n" );return ret;
@@ -404,7 +406,7 @@ static int proto_gre_net_init(struct net *net)static void proto_gre_net_exit (struct net *net) { -nf_ct_l4proto_pernet_unregister (net, &nf_conntrack_l4proto_gre4); +nf_ct_l4proto_pernet_unregister_one (net, &nf_conntrack_l4proto_gre4);nf_ct_gre_keymap_flush (net); }
@@ -422,8 +424,7 @@ static int __init nf_ct_proto_gre_init(void) ret =register_pernet_subsys (&proto_gre_net_ops);if (ret <0 ) goto out_pernet; - - ret =nf_ct_l4proto_register (&nf_conntrack_l4proto_gre4); + ret =nf_ct_l4proto_register_one (&nf_conntrack_l4proto_gre4);if (ret <0 ) goto out_gre4;
@@ -436,7 +437,7 @@ static int __init nf_ct_proto_gre_init(void) static void __exit nf_ct_proto_gre_fini(void) { -nf_ct_l4proto_unregister (&nf_conntrack_l4proto_gre4); +nf_ct_l4proto_unregister_one (&nf_conntrack_l4proto_gre4);unregister_pernet_subsys (&proto_gre_net_ops); }
net/netfilter/nf_conntrack_proto_sctp.c +13 -37
74 lines not on this page · raw message
net/netfilter/nf_conntrack_proto_udplite.c +13 -37
74 lines not on this page · raw message
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 14/39 udp: provide udp{4,6}_lib_lookup for nf_socket_ipv{4,6}
In reply to Pablo Neira AyusoFrom: Arnd Bergmann <[email protected]>
Since commit ca065d0cf80f ("udp: no longer use SLAB_DESTROY_BY_RCU") the udp6_lib_lookup and udp4_lib_lookup functions are only provided when it is actually possible to call them.
However, moving the callers now caused a link error:
net/built-in.o: In function `nf_sk_lookup_slow_v6':
(.text+0x131a39): undefined reference to udp6_lib_lookup' net/ipv4/netfilter/nf_socket_ipv4.o: In function nf_sk_lookup_slow_v4':
nf_socket_ipv4.c:(.text.nf_sk_lookup_slow_v4+0x114): undefined reference to `udp4_lib_lookup'
This extends the #ifdef so we also provide the functions when CONFIG_NF_SOCKET_IPV4 or CONFIG_NF_SOCKET_IPV6, respectively are set.
--- net/ipv4/udp.c | 3 ++- net/ipv6/udp.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
net/ipv4/udp.c +2 -1
@@ -580,7 +580,8 @@ EXPORT_SYMBOL_GPL(udp4_lib_lookup_skb);* Does increment socket refcount. */ #if IS_ENABLED (CONFIG_NETFILTER_XT_MATCH_SOCKET ) || \ -IS_ENABLED (CONFIG_NETFILTER_XT_TARGET_TPROXY ) +IS_ENABLED (CONFIG_NETFILTER_XT_TARGET_TPROXY ) || \ +IS_ENABLED (CONFIG_NF_SOCKET_IPV4 )struct sock *udp4_lib_lookup (struct net *net,__be32 saddr,__be16 sport,__be32 daddr,__be16 dport,int dif) {
net/ipv6/udp.c +2 -1
@@ -302,7 +302,8 @@ EXPORT_SYMBOL_GPL(udp6_lib_lookup_skb);* Does increment socket refcount. */ #if IS_ENABLED (CONFIG_NETFILTER_XT_MATCH_SOCKET ) || \ -IS_ENABLED (CONFIG_NETFILTER_XT_TARGET_TPROXY ) +IS_ENABLED (CONFIG_NETFILTER_XT_TARGET_TPROXY ) || \ +IS_ENABLED (CONFIG_NF_SOCKET_IPV6 )struct sock *udp6_lib_lookup (struct net *net,const struct in6_addr *saddr,__be16 sport,const struct in6_addr *daddr,__be16 dport,int dif) {
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 15/39 netfilter: conntrack: fix NF_REPEAT handling
In reply to Pablo Neira AyusoFrom: Arnd Bergmann <[email protected]>
gcc correctly identified a theoretical uninitialized variable use:
net/netfilter/nf_conntrack_core.c: In function 'nf_conntrack_in':net/netfilter/nf_conntrack_core.c:1125:14: error: 'l4proto' may be used uninitialized in this function [-Werror=maybe-uninitialized]
This could only happen when we 'goto out' before looking up l4proto, and then enter the retry, implying that l3proto->get_l4proto() returned NF_REPEAT. This does not currently get returned in any code path and probably won't ever happen, but is not good to rely on.
Moving the repeat handling up a little should have the same behavior as today but avoids the warning by making that case impossible to enter.
[ I have mangled this original patch to remove the check for tmpl, we
should inconditionally jump back to the repeat label in case we hit NF_REPEAT instead. I have also moved the comment that explains this where it belongs. --pablo ]
--- net/netfilter/nf_conntrack_core.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
net/netfilter/nf_conntrack_core.c +8 -10
@@ -1337,6 +1337,12 @@ nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum,NF_CT_STAT_INC_ATOMIC (net, invalid);if (ret == -NF_DROP )NF_CT_STAT_INC_ATOMIC (net, drop); +/* Special case: TCP tracker reports an attempt to reopen a +* closed/aborted connection. We have to go back and create a +* fresh conntrack. +*/ +if (ret == -NF_REPEAT ) + goto repeat; ret = -ret; goto out; }
@@ -1344,16 +1350,8 @@ nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum,if (set_reply && !test_and_set_bit (IPS_SEEN_REPLY_BIT , &ct->status))nf_conntrack_event_cache (IPCT_REPLY , ct); out: -if (tmpl) { -/* Special case: TCP tracker reports an attempt to reopen a -* closed/aborted connection. We have to go back and create a -* fresh conntrack. -*/ -if (ret ==NF_REPEAT ) - goto repeat; -else -nf_ct_put (tmpl); - } +if (tmpl) +nf_ct_put (tmpl);return ret; }
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 16/39 netfilter: ipset: Remove extra whitespaces in ip_set.h
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
Remove unnecessary whitespaces.
Ported from a patch proposed by Sergey Popovich <[email protected]>.
--- include/linux/netfilter/ipset/ip_set.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
include/linux/netfilter/ipset/ip_set.h +7 -6
@@ -336,14 +336,15 @@ ip_set_update_counter(struct ip_set_counter *counter,static inline void ip_set_get_skbinfo (struct ip_set_skbinfo *skbinfo, -const struct ip_set_ext *ext, -struct ip_set_ext *mext,u32 flags) +const struct ip_set_ext *ext, +struct ip_set_ext *mext,u32 flags) { - mext->skbmark = skbinfo->skbmark; - mext->skbmarkmask = skbinfo->skbmarkmask; - mext->skbprio = skbinfo->skbprio; - mext->skbqueue = skbinfo->skbqueue; + mext->skbmark = skbinfo->skbmark; + mext->skbmarkmask = skbinfo->skbmarkmask; + mext->skbprio = skbinfo->skbprio; + mext->skbqueue = skbinfo->skbqueue; } +static inline bool ip_set_put_skbinfo (struct sk_buff *skb,struct ip_set_skbinfo *skbinfo) {
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 17/39 netfilter: ipset: Mark some helper args as const.
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
Mark some of the helpers arguments as const.
Ported from a patch proposed by Sergey Popovich <[email protected]>.
--- include/linux/netfilter/ipset/ip_set.h | 4 ++-- include/linux/netfilter/ipset/ip_set_comment.h | 2 +- include/linux/netfilter/ipset/ip_set_timeout.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-)
include/linux/netfilter/ipset/ip_set.h +2 -2
@@ -346,7 +346,7 @@ ip_set_get_skbinfo(struct ip_set_skbinfo *skbinfo, }static inline bool -ip_set_put_skbinfo (struct sk_buff *skb,struct ip_set_skbinfo *skbinfo) +ip_set_put_skbinfo (struct sk_buff *skb,const struct ip_set_skbinfo *skbinfo) {/* Send nonzero parameters only */ return ((skbinfo->skbmark || skbinfo->skbmarkmask) &&
@@ -373,7 +373,7 @@ ip_set_init_skbinfo(struct ip_set_skbinfo *skbinfo, }static inline bool -ip_set_put_counter (struct sk_buff *skb,struct ip_set_counter *counter) +ip_set_put_counter (struct sk_buff *skb,const struct ip_set_counter *counter) { return nla_put_net64(skb, IPSET_ATTR_BYTES, cpu_to_be64(ip_set_get_bytes(counter)),
include/linux/netfilter/ipset/ip_set_comment.h +1 -1
@@ -43,7 +43,7 @@ ip_set_init_comment(struct ip_set_comment *comment,/* Used only when dumping a set, protected by rcu_read_lock_bh() */ static inline int -ip_set_put_comment (struct sk_buff *skb,struct ip_set_comment *comment) +ip_set_put_comment (struct sk_buff *skb,const struct ip_set_comment *comment) {struct ip_set_comment_rcu *c =rcu_dereference_bh (comment->c);
include/linux/netfilter/ipset/ip_set_timeout.h +2 -2
@@ -40,7 +40,7 @@ ip_set_timeout_uget(struct nlattr *tb) }static inline bool -ip_set_timeout_expired (unsigned long *t) +ip_set_timeout_expired (const unsigned long *t) {return *t !=IPSET_ELEM_PERMANENT &&time_is_before_jiffies (*t); }
@@ -63,7 +63,7 @@ ip_set_timeout_set(unsigned long *timeout, u32 value) }static inline u32 -ip_set_timeout_get (unsigned long *timeout) +ip_set_timeout_get (const unsigned long *timeout) {return *timeout ==IPSET_ELEM_PERMANENT ?0 :jiffies_to_msecs (*timeout - jiffies)/MSEC_PER_SEC ;
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 18/39 netfilter: ipset: Headers file cleanup
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
Group counter helper functions together.
Ported from a patch proposed by Sergey Popovich <[email protected]>.
--- include/linux/netfilter/ipset/ip_set.h | 42 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-)
include/linux/netfilter/ipset/ip_set.h +21 -21
@@ -334,6 +334,27 @@ ip_set_update_counter(struct ip_set_counter *counter, } } +static inline bool +ip_set_put_counter (struct sk_buff *skb,const struct ip_set_counter *counter) +{ +return nla_put_net64 (skb,IPSET_ATTR_BYTES , +cpu_to_be64 (ip_set_get_bytes (counter)), +IPSET_ATTR_PAD ) || +nla_put_net64 (skb,IPSET_ATTR_PACKETS , +cpu_to_be64 (ip_set_get_packets (counter)), +IPSET_ATTR_PAD ); +} + +static inline void +ip_set_init_counter (struct ip_set_counter *counter, +const struct ip_set_ext *ext) +{ +if (ext->bytes !=ULLONG_MAX ) +atomic64_set (&(counter)->bytes, (long long )(ext->bytes)); +if (ext->packets !=ULLONG_MAX ) +atomic64_set (&(counter)->packets, (long long )(ext->packets)); +} + static inline void ip_set_get_skbinfo(struct ip_set_skbinfo *skbinfo, const struct ip_set_ext *ext,
@@ -372,27 +393,6 @@ ip_set_init_skbinfo(struct ip_set_skbinfo *skbinfo, skbinfo->skbqueue = ext->skbqueue; } -static inline bool -ip_set_put_counter (struct sk_buff *skb,const struct ip_set_counter *counter) -{ -return nla_put_net64 (skb,IPSET_ATTR_BYTES , -cpu_to_be64 (ip_set_get_bytes (counter)), -IPSET_ATTR_PAD ) || -nla_put_net64 (skb,IPSET_ATTR_PACKETS , -cpu_to_be64 (ip_set_get_packets (counter)), -IPSET_ATTR_PAD ); -} - -static inline void -ip_set_init_counter (struct ip_set_counter *counter, -const struct ip_set_ext *ext) -{ -if (ext->bytes !=ULLONG_MAX ) -atomic64_set (&(counter)->bytes, (long long )(ext->bytes)); -if (ext->packets !=ULLONG_MAX ) -atomic64_set (&(counter)->packets, (long long )(ext->packets)); -} -/* Netlink CB args */ enum {IPSET_CB_NET =0 ,/* net namespace */
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 19/39 netfilter: ipset: Improve skbinfo get/init helpers
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
Use struct ip_set_skbinfo in struct ip_set_ext instead of open coded fields and assign structure members in get/init helpers instead of copying members one by one. Explicitly note that struct ip_set_skbinfo must be padded to prevent non-aligned access in the extension blob.
Ported from a patch proposed by Sergey Popovich <[email protected]>.
--- include/linux/netfilter/ipset/ip_set.h | 30 +++++++++++------------------- net/netfilter/ipset/ip_set_core.c | 12 ++++++------ net/netfilter/xt_set.c | 12 +++++++----- 3 files changed, 24 insertions(+), 30 deletions(-)
include/linux/netfilter/ipset/ip_set.h +11 -19
@@ -92,17 +92,6 @@ struct ip_set_ext_type {extern const struct ip_set_ext_type ip_set_extensions[]; -struct ip_set_ext { -u64 packets; -u64 bytes; -u32 timeout; -u32 skbmark; -u32 skbmarkmask; -u32 skbprio; -u16 skbqueue; -char *comment; -}; -struct ip_set_counter {atomic64_t bytes;atomic64_t packets;
@@ -122,6 +111,15 @@ struct ip_set_skbinfo {u32 skbmarkmask;u32 skbprio;u16 skbqueue; +u16 __pad; +}; + +struct ip_set_ext { +struct ip_set_skbinfo skbinfo; +u64 packets; +u64 bytes; +char *comment; +u32 timeout; };struct ip_set ;
@@ -360,10 +358,7 @@ ip_set_get_skbinfo(struct ip_set_skbinfo *skbinfo,const struct ip_set_ext *ext, struct ip_set_ext *mext, u32 flags) { - mext->skbmark = skbinfo->skbmark; - mext->skbmarkmask = skbinfo->skbmarkmask; - mext->skbprio = skbinfo->skbprio; - mext->skbqueue = skbinfo->skbqueue; + mext->skbinfo = *skbinfo; } static inline bool
@@ -387,10 +382,7 @@ static inline void ip_set_init_skbinfo(struct ip_set_skbinfo *skbinfo, const struct ip_set_ext *ext) { - skbinfo->skbmark = ext->skbmark; - skbinfo->skbmarkmask = ext->skbmarkmask; - skbinfo->skbprio = ext->skbprio; - skbinfo->skbqueue = ext->skbqueue; + *skbinfo = ext->skbinfo; }/* Netlink CB args */
net/netfilter/ipset/ip_set_core.c +6 -6
@@ -426,20 +426,20 @@ ip_set_get_extensions(struct ip_set *set, struct nlattr *tb[],if (!SET_WITH_SKBINFO (set))return -IPSET_ERR_SKBINFO ; fullmark =be64_to_cpu (nla_get_be64 (tb[IPSET_ATTR_SKBMARK ])); - ext->skbmark = fullmark >>32 ; - ext->skbmarkmask = fullmark &0xffffffff ; + ext->skbinfo.skbmark = fullmark >>32 ; + ext->skbinfo.skbmarkmask = fullmark &0xffffffff ; }if (tb[IPSET_ATTR_SKBPRIO ]) {if (!SET_WITH_SKBINFO (set))return -IPSET_ERR_SKBINFO ; - ext->skbprio =be32_to_cpu (nla_get_be32 ( - tb[IPSET_ATTR_SKBPRIO ])); + ext->skbinfo.skbprio = +be32_to_cpu (nla_get_be32 (tb[IPSET_ATTR_SKBPRIO ])); }if (tb[IPSET_ATTR_SKBQUEUE ]) {if (!SET_WITH_SKBINFO (set))return -IPSET_ERR_SKBINFO ; - ext->skbqueue =be16_to_cpu (nla_get_be16 ( - tb[IPSET_ATTR_SKBQUEUE ])); + ext->skbinfo.skbqueue = +be16_to_cpu (nla_get_be16 (tb[IPSET_ATTR_SKBQUEUE ])); }return 0 ; }
net/netfilter/xt_set.c +7 -5
@@ -423,6 +423,8 @@ set_target_v2(struct sk_buff *skb, const struct xt_action_param *par)/* Revision 3 target */ +#define MOPT (opt, member) ((opt).ext.skbinfo.member) +static unsigned int set_target_v3 (struct sk_buff *skb,const struct xt_action_param *par) {
@@ -453,14 +455,14 @@ set_target_v3(struct sk_buff *skb, const struct xt_action_param *par)if (!ret)return XT_CONTINUE ;if (map_opt.cmdflags &IPSET_FLAG_MAP_SKBMARK ) - skb->mark = (skb->mark & ~(map_opt.ext.skbmarkmask)) - ^ (map_opt.ext.skbmark); + skb->mark = (skb->mark & ~MOPT (map_opt,skbmarkmask)) + ^MOPT (map_opt, skbmark);if (map_opt.cmdflags &IPSET_FLAG_MAP_SKBPRIO ) - skb->priority = map_opt.ext.skbprio; + skb->priority =MOPT (map_opt, skbprio);if ((map_opt.cmdflags &IPSET_FLAG_MAP_SKBQUEUE ) && skb->dev && - skb->dev->real_num_tx_queues > map_opt.ext.skbqueue) -skb_set_queue_mapping (skb, map_opt.ext.skbqueue); + skb->dev->real_num_tx_queues >MOPT (map_opt, skbqueue)) +skb_set_queue_mapping (skb,MOPT (map_opt, skbqueue)); }return XT_CONTINUE ; }
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 20/39 netfilter: ipset: Use kmalloc() in comment extension helper
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
Allocate memory with kmalloc() rather than kzalloc(): the string is immediately initialized so it is unnecessary to zero out the allocated memory area.
Ported from a patch proposed by Sergey Popovich <[email protected]>.
--- include/linux/netfilter/ipset/ip_set_comment.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/netfilter/ipset/ip_set_comment.h +1 -1
@@ -34,7 +34,7 @@ ip_set_init_comment(struct ip_set_comment *comment,return ;if (unlikely (len >IPSET_MAX_COMMENT_SIZE )) len =IPSET_MAX_COMMENT_SIZE ; - c =kzalloc (sizeof (*c) + len +1 ,GFP_ATOMIC ); + c =kmalloc (sizeof (*c) + len +1 ,GFP_ATOMIC );if (unlikely (!c))return ;strlcpy (c->str, ext->comment, len +1 );
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 21/39 netfilter: ipset: Split extensions into separate files
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
Cleanup to separate all extensions into individual files.
Ported from a patch proposed by Sergey Popovich <[email protected]>.
--- include/linux/netfilter/ipset/ip_set.h | 95 +------------------------- include/linux/netfilter/ipset/ip_set_counter.h | 75 ++++++++++++++++++++ include/linux/netfilter/ipset/ip_set_skbinfo.h | 46 +++++++++++++ 3 files changed, 123 insertions(+), 93 deletions(-) create mode 100644 include/linux/netfilter/ipset/ip_set_counter.h create mode 100644 include/linux/netfilter/ipset/ip_set_skbinfo.h
include/linux/netfilter/ipset/ip_set.h +2 -93
@@ -292,99 +292,6 @@ ip_set_put_flags(struct sk_buff *skb, struct ip_set *set)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); -} - -static inline void -ip_set_add_packets (u64 packets,struct ip_set_counter *counter) -{ -atomic64_add ((long long )packets, &(counter)->packets); -} - -static inline u64 -ip_set_get_bytes (const struct ip_set_counter *counter) -{ -return (u64 )atomic64_read (&(counter)->bytes); -} - -static inline u64 -ip_set_get_packets (const struct ip_set_counter *counter) -{ -return (u64 )atomic64_read (&(counter)->packets); -} - -static inline void -ip_set_update_counter (struct ip_set_counter *counter, -const struct ip_set_ext *ext, -struct ip_set_ext *mext,u32 flags) -{ -if (ext->packets !=ULLONG_MAX && - !(flags &IPSET_FLAG_SKIP_COUNTER_UPDATE )) { -ip_set_add_bytes (ext->bytes, counter); -ip_set_add_packets (ext->packets, counter); - } -if (flags &IPSET_FLAG_MATCH_COUNTERS ) { - mext->packets =ip_set_get_packets (counter); - mext->bytes =ip_set_get_bytes (counter); - } -} - -static inline bool -ip_set_put_counter (struct sk_buff *skb,const struct ip_set_counter *counter) -{ -return nla_put_net64 (skb,IPSET_ATTR_BYTES , -cpu_to_be64 (ip_set_get_bytes (counter)), -IPSET_ATTR_PAD ) || -nla_put_net64 (skb,IPSET_ATTR_PACKETS , -cpu_to_be64 (ip_set_get_packets (counter)), -IPSET_ATTR_PAD ); -} - -static inline void -ip_set_init_counter (struct ip_set_counter *counter, -const struct ip_set_ext *ext) -{ -if (ext->bytes !=ULLONG_MAX ) -atomic64_set (&(counter)->bytes, (long long )(ext->bytes)); -if (ext->packets !=ULLONG_MAX ) -atomic64_set (&(counter)->packets, (long long )(ext->packets)); -} - -static inline void -ip_set_get_skbinfo (struct ip_set_skbinfo *skbinfo, -const struct ip_set_ext *ext, -struct ip_set_ext *mext,u32 flags) -{ - mext->skbinfo = *skbinfo; -} - -static inline bool -ip_set_put_skbinfo (struct sk_buff *skb,const struct ip_set_skbinfo *skbinfo) -{ -/* Send nonzero parameters only */ -return ((skbinfo->skbmark || skbinfo->skbmarkmask) && -nla_put_net64 (skb,IPSET_ATTR_SKBMARK , -cpu_to_be64 ((u64 )skbinfo->skbmark <<32 | - skbinfo->skbmarkmask), -IPSET_ATTR_PAD )) || - (skbinfo->skbprio && -nla_put_net32 (skb,IPSET_ATTR_SKBPRIO , -cpu_to_be32 (skbinfo->skbprio))) || - (skbinfo->skbqueue && -nla_put_net16 (skb,IPSET_ATTR_SKBQUEUE , -cpu_to_be16 (skbinfo->skbqueue))); -} - -static inline void -ip_set_init_skbinfo (struct ip_set_skbinfo *skbinfo, -const struct ip_set_ext *ext) -{ - *skbinfo = ext->skbinfo; -} -/* Netlink CB args */ enum {IPSET_CB_NET =0 ,/* net namespace */
@@ -539,6 +446,8 @@ bitmap_bytes(u32 a, u32 b)#include <linux/netfilter/ipset/ip_set_timeout.h> #include <linux/netfilter/ipset/ip_set_comment.h> +#include <linux/netfilter/ipset/ip_set_counter.h> +#include <linux/netfilter/ipset/ip_set_skbinfo.h> int ip_set_put_extensions(struct sk_buff *skb, const struct ip_set *set,
include/linux/netfilter/ipset/ip_set_counter.h new file +75 -0
75 lines not on this page · raw message
include/linux/netfilter/ipset/ip_set_skbinfo.h new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 22/39 netfilter: ipset: Separate memsize calculation code into dedicated function
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
Hash types already has it's memsize calculation code in separate functions. Clean up and do the same for *bitmap* and *list* sets.
Ported from a patch proposed by Sergey Popovich <[email protected]>.
--- net/netfilter/ipset/ip_set_bitmap_gen.h | 11 ++++++++++- net/netfilter/ipset/ip_set_list_set.c | 23 +++++++++++++++++------ 2 files changed, 27 insertions(+), 7 deletions(-)
net/netfilter/ipset/ip_set_bitmap_gen.h +10 -1
@@ -22,6 +22,7 @@#define mtype_kadt IPSET_TOKEN(MTYPE, _kadt)#define mtype_uadt IPSET_TOKEN(MTYPE, _uadt)#define mtype_destroy IPSET_TOKEN(MTYPE, _destroy) +#define mtype_memsize IPSET_TOKEN(MTYPE, _memsize)#define mtype_flush IPSET_TOKEN(MTYPE, _flush)#define mtype_head IPSET_TOKEN(MTYPE, _head)#define mtype_same_set IPSET_TOKEN(MTYPE, _same_set)
@@ -84,12 +85,20 @@ mtype_flush(struct ip_set *set)memset (map->members,0 , map->memsize); } +/* Calculate the actual memory size of the set data */ +static size_t +mtype_memsize (const struct mtype *map,size_t dsize) +{ +return sizeof (*map) + map->memsize + + map->elements * dsize; +} +static int mtype_head (struct ip_set *set,struct sk_buff *skb) {const struct mtype *map = set->data;struct nlattr *nested; -size_t memsize =sizeof (*map) + map->memsize; +size_t memsize =mtype_memsize (map, set->dsize); nested =ipset_nest_start (skb,IPSET_ATTR_DATA );if (!nested)
net/netfilter/ipset/ip_set_list_set.c +17 -6
@@ -441,12 +441,12 @@ list_set_destroy(struct ip_set *set) set->data =NULL ; } -static int -list_set_head (struct ip_set *set,struct sk_buff *skb) +/* Calculate the actual memory size of the set data */ +static size_t +list_set_memsize (const struct list_set *map,size_t dsize) { -const struct list_set *map = set->data; -struct nlattr *nested;struct set_elem *e; +size_t memsize;u32 n =0 ;rcu_read_lock ();
@@ -454,13 +454,24 @@ list_set_head(struct ip_set *set, struct sk_buff *skb) n++;rcu_read_unlock (); + memsize =sizeof (*map) + n * dsize; + +return memsize; +} + +static int +list_set_head (struct ip_set *set,struct sk_buff *skb) +{ +const struct list_set *map = set->data; +struct nlattr *nested; +size_t memsize =list_set_memsize (map, set->dsize); + nested =ipset_nest_start (skb,IPSET_ATTR_DATA );if (!nested) goto nla_put_failure;if (nla_put_net32 (skb,IPSET_ATTR_SIZE ,htonl (map->size)) ||nla_put_net32 (skb,IPSET_ATTR_REFERENCES ,htonl (set->ref)) || -nla_put_net32 (skb,IPSET_ATTR_MEMSIZE , -htonl (sizeof (*map) + n * set->dsize))) +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;
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 23/39 netfilter: ipset: Regroup ip_set_put_extensions and add extern
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
Cleanup: group ip_set_put_extensions and ip_set_get_extensions together and add missing extern.
--- include/linux/netfilter/ipset/ip_set.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
include/linux/netfilter/ipset/ip_set.h +2 -4
@@ -331,6 +331,8 @@ extern size_t ip_set_elem_len(struct ip_set *set, struct nlattr *tb[], size_t len, size_t align);extern int ip_set_get_extensions (struct ip_set *set,struct nlattr *tb[],struct ip_set_ext *ext); +extern int ip_set_put_extensions (struct sk_buff *skb,const struct ip_set *set, +const void *e,bool active);static inline int ip_set_get_hostipaddr4 (struct nlattr *nla,u32 *ipaddr)
@@ -449,10 +451,6 @@ bitmap_bytes(u32 a, u32 b)#include <linux/netfilter/ipset/ip_set_counter.h> #include <linux/netfilter/ipset/ip_set_skbinfo.h> -int -ip_set_put_extensions (struct sk_buff *skb,const struct ip_set *set, -const void *e,bool active); -#define IP_SET_INIT_KEXT (skb, opt, set) \ { .bytes = (skb)->len, .packets = 1, \ .timeout = ip_set_adt_opt_timeout(opt, set) }
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 24/39 netfilter: ipset: Add element count to hash headers
In reply to Pablo Neira AyusoFrom: Eric B Munson <[email protected]>
It would be useful for userspace to query the size of an ipset hash, however, this data is not exposed to userspace outside of counting the number of member entries. This patch uses the attribute IPSET_ATTR_ELEMENTS to indicate the size in the the header that is exported to userspace. This field is then printed by the userspace tool for hashes.
--- net/netfilter/ipset/ip_set_hash_gen.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/ipset/ip_set_hash_gen.h +2 -1
@@ -1083,7 +1083,8 @@ 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)) || -nla_put_net32 (skb,IPSET_ATTR_MEMSIZE ,htonl (memsize))) +nla_put_net32 (skb,IPSET_ATTR_MEMSIZE ,htonl (memsize)) || +nla_put_net32 (skb,IPSET_ATTR_ELEMENTS ,htonl (h->elements))) goto nla_put_failure;if (unlikely (ip_set_put_flags (skb, set))) goto nla_put_failure;
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 25/39 netfilter: ipset: Add element count to all set types header
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
It is better to list the set elements for all set types, thus the header information is uniform. Element counts are therefore added to the bitmap and list types.
--- include/linux/netfilter/ipset/ip_set.h | 2 ++ include/linux/netfilter/ipset/ip_set_bitmap.h | 2 +- net/netfilter/ipset/ip_set_bitmap_gen.h | 10 +++++++++- net/netfilter/ipset/ip_set_hash_gen.h | 21 ++++++++++----------- net/netfilter/ipset/ip_set_list_set.c | 6 +++++- 5 files changed, 27 insertions(+), 14 deletions(-)
include/linux/netfilter/ipset/ip_set.h +2 -0
@@ -250,6 +250,8 @@ struct ip_set {u8 flags;/* Default timeout value, if enabled */ u32 timeout; +/* Number of elements (vs timeout) */ +u32 elements;/* Element data size */ size_t dsize;/* Offsets to extensions in elements */
include/linux/netfilter/ipset/ip_set_bitmap.h +1 -1
@@ -6,8 +6,8 @@#define IPSET_BITMAP_MAX_RANGE 0x0000FFFFenum { +IPSET_ADD_STORE_PLAIN_TIMEOUT =-1 ,IPSET_ADD_FAILED =1 , -IPSET_ADD_STORE_PLAIN_TIMEOUT ,IPSET_ADD_START_STORED_TIMEOUT , };
net/netfilter/ipset/ip_set_bitmap_gen.h +9 -1
@@ -83,6 +83,7 @@ mtype_flush(struct ip_set *set)if (set->extensions &IPSET_EXT_DESTROY )mtype_ext_cleanup (set);memset (map->members,0 , map->memsize); + set->elements =0 ; }/* Calculate the actual memory size of the set data */
@@ -105,7 +106,8 @@ mtype_head(struct ip_set *set, struct sk_buff *skb) goto nla_put_failure;if (mtype_do_head (skb, map) ||nla_put_net32 (skb,IPSET_ATTR_REFERENCES ,htonl (set->ref)) || -nla_put_net32 (skb,IPSET_ATTR_MEMSIZE ,htonl (memsize))) +nla_put_net32 (skb,IPSET_ATTR_MEMSIZE ,htonl (memsize)) || +nla_put_net32 (skb,IPSET_ATTR_ELEMENTS ,htonl (set->elements))) goto nla_put_failure;if (unlikely (ip_set_put_flags (skb, set))) goto nla_put_failure;
@@ -149,6 +151,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,if (ret ==IPSET_ADD_FAILED ) {if (SET_WITH_TIMEOUT (set) &&ip_set_timeout_expired (ext_timeout (x, set))) { + set->elements--; ret =0 ; }else if (!(flags &IPSET_FLAG_EXIST )) {set_bit (e->id, map->members);
@@ -157,6 +160,8 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,/* Element is re-added, cleanup extensions */ ip_set_ext_destroy (set, x); } +if (ret >0 ) + set->elements--;if (SET_WITH_TIMEOUT (set)) #ifdef IP_SET_BITMAP_STORED_TIMEOUT
@@ -174,6 +179,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,/* Activate element */ set_bit (e->id, map->members); + set->elements++;return 0 ; }
@@ -190,6 +196,7 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext,return -IPSET_ERR_EXIST ;ip_set_ext_destroy (set, x); + set->elements--;if (SET_WITH_TIMEOUT (set) &&ip_set_timeout_expired (ext_timeout (x, set)))return -IPSET_ERR_EXIST ;
@@ -285,6 +292,7 @@ mtype_gc(unsigned long ul_set)if (ip_set_timeout_expired (ext_timeout (x, set))) {clear_bit (id, map->members);ip_set_ext_destroy (set, x); + set->elements--; } }spin_unlock_bh (&set->lock);
net/netfilter/ipset/ip_set_hash_gen.h +10 -11
@@ -275,7 +275,6 @@ htable_bits(u32 hashsize)struct htype {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 */ #ifdef IP_SET_HASH_WITH_MARKMASK u32 markmask;/* markmask value for mark mask to store */
@@ -400,7 +399,7 @@ mtype_flush(struct ip_set *set)#ifdef IP_SET_HASH_WITH_NETS memset (h->nets,0 ,sizeof (struct net_prefixes ) *NLEN (set->family));#endif - h->elements =0 ; + set->elements =0 ; }/* Destroy the hashtable part of the set */
@@ -506,7 +505,7 @@ mtype_expire(struct ip_set *set, struct htype *h, u8 nets_length, size_t dsize) nets_length, k);#endif ip_set_ext_destroy (set, data); - h->elements--; + set->elements--; d++; } }
@@ -715,11 +714,11 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,bool deleted = false, forceadd = false, reuse = false;u32 key, multi =0 ; -if (h->elements >= h->maxelem) { +if (set->elements >= h->maxelem) {if (SET_WITH_TIMEOUT (set))/* FIXME: when set is full, we slow down here */ mtype_expire (set, h,NLEN (set->family), set->dsize); -if (h->elements >= h->maxelem &&SET_WITH_FORCEADD (set)) +if (set->elements >= h->maxelem &&SET_WITH_FORCEADD (set)) forceadd = true; }
@@ -732,7 +731,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,pr_warn ("Set %s is full, maxelem %u reached\n" , set->name, h->maxelem);return -IPSET_ERR_HASH_FULL ; - }else if (h->elements >= h->maxelem) { + }else if (set->elements >= h->maxelem) { goto set_full; } old =NULL ;
@@ -781,11 +780,11 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext, NLEN(set->family), i);#endif ip_set_ext_destroy (set, data); - h->elements--; + set->elements--; } goto copy_data; } -if (h->elements >= h->maxelem) +if (set->elements >= h->maxelem) goto set_full;/* Create a new slot */ if (n->pos >= n->size) {
@@ -810,7 +809,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext, j = n->pos++; data =ahash_data (n, j, set->dsize); copy_data: - h->elements++; + set->elements++;#ifdef IP_SET_HASH_WITH_NETS for (i =0 ; i <IPSET_NET_COUNT ; i++) mtype_add_cidr(h, NCIDR_PUT(DCIDR_GET(d->cidr, i)),
@@ -883,7 +882,7 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext,smp_mb__after_atomic ();if (i +1 == n->pos) n->pos--; - h->elements--; + set->elements--;#ifdef IP_SET_HASH_WITH_NETS for (j =0 ; j <IPSET_NET_COUNT ; j++) mtype_del_cidr(h, NCIDR_PUT(DCIDR_GET(d->cidr, j)),
@@ -1084,7 +1083,7 @@ mtype_head(struct ip_set *set, struct sk_buff *skb)#endif if (nla_put_net32 (skb,IPSET_ATTR_REFERENCES ,htonl (set->ref)) ||nla_put_net32 (skb,IPSET_ATTR_MEMSIZE ,htonl (memsize)) || -nla_put_net32 (skb,IPSET_ATTR_ELEMENTS ,htonl (h->elements))) +nla_put_net32 (skb,IPSET_ATTR_ELEMENTS ,htonl (set->elements))) goto nla_put_failure;if (unlikely (ip_set_put_flags (skb, set))) goto nla_put_failure;
net/netfilter/ipset/ip_set_list_set.c +5 -1
@@ -166,6 +166,7 @@ __list_set_del_rcu(struct rcu_head * rcu)static inline void list_set_del (struct ip_set *set,struct set_elem *e) { + set->elements--;list_del_rcu (&e->list);call_rcu (&e->rcu, __list_set_del_rcu); }
@@ -309,6 +310,7 @@ list_set_uadd(struct ip_set *set, void *value, const struct ip_set_ext *ext,list_add_rcu (&e->list, &prev->list); else list_add_tail_rcu(&e->list, &map->members); + set->elements++;return 0 ; }
@@ -419,6 +421,7 @@ list_set_flush(struct ip_set *set)list_for_each_entry_safe (e, n, &map->members, list)list_set_del (set, e); + set->elements =0 ; } static void
@@ -471,7 +474,8 @@ list_set_head(struct ip_set *set, struct sk_buff *skb) goto nla_put_failure;if (nla_put_net32 (skb,IPSET_ATTR_SIZE ,htonl (map->size)) ||nla_put_net32 (skb,IPSET_ATTR_REFERENCES ,htonl (set->ref)) || -nla_put_net32 (skb,IPSET_ATTR_MEMSIZE ,htonl (memsize))) +nla_put_net32 (skb,IPSET_ATTR_MEMSIZE ,htonl (memsize)) || +nla_put_net32 (skb,IPSET_ATTR_ELEMENTS ,htonl (set->elements))) goto nla_put_failure;if (unlikely (ip_set_put_flags (skb, set))) goto nla_put_failure;
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 26/39 netfilter: ipset: Count non-static extension memory for userspace
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
Non-static (i.e. comment) extension was not counted into the memory size. A new internal counter is introduced for this. In the case of the hash types the sizes of the arrays are counted there as well so that we can avoid to scan the whole set when just the header data is requested.
--- include/linux/netfilter/ipset/ip_set.h | 8 ++++++-- include/linux/netfilter/ipset/ip_set_comment.h | 7 +++++-- net/netfilter/ipset/ip_set_bitmap_gen.h | 5 +++-- net/netfilter/ipset/ip_set_core.c | 2 +- net/netfilter/ipset/ip_set_hash_gen.h | 26 ++++++++++++++------------ net/netfilter/ipset/ip_set_list_set.c | 5 +++-- 6 files changed, 32 insertions(+), 21 deletions(-)
include/linux/netfilter/ipset/ip_set.h +6 -2
@@ -79,10 +79,12 @@ enum ip_set_ext_id { IPSET_EXT_ID_MAX, }; +struct ip_set ; +/* Extension type */ struct ip_set_ext_type {/* Destroy extension private data (can be NULL) */ -void (*destroy)(void *ext); +void (*destroy)(struct ip_set *set,void *ext);enum ip_set_extension type;enum ipset_cadt_flags flag;/* Size and minimal alignment */
@@ -252,6 +254,8 @@ struct ip_set {u32 timeout;/* Number of elements (vs timeout) */ u32 elements; +/* Size of the dynamic extensions (vs timeout) */ +size_t ext_size;/* Element data size */ size_t dsize;/* Offsets to extensions in elements */
@@ -268,7 +272,7 @@ ip_set_ext_destroy(struct ip_set *set, void *data)*/ if (SET_WITH_COMMENT (set)) ip_set_extensions[IPSET_EXT_ID_COMMENT ].destroy ( -ext_comment (data, set)); + set,ext_comment (data, set)); } static inline int
include/linux/netfilter/ipset/ip_set_comment.h +5 -2
@@ -20,13 +20,14 @@ ip_set_comment_uget(struct nlattr *tb)* The kadt functions don't use the comment extensions in any way. */ static inline void -ip_set_init_comment (struct ip_set_comment *comment, +ip_set_init_comment (struct ip_set *set,struct ip_set_comment *comment,const struct ip_set_ext *ext) {struct ip_set_comment_rcu *c =rcu_dereference_protected (comment->c,1 );size_t len = ext->comment ?strlen (ext->comment) :0 ;if (unlikely (c)) { + set->ext_size -=sizeof (*c) +strlen (c->str) +1 ;kfree_rcu (c, rcu);rcu_assign_pointer (comment->c,NULL ); }
@@ -38,6 +39,7 @@ ip_set_init_comment(struct ip_set_comment *comment,if (unlikely (!c))return ;strlcpy (c->str, ext->comment, len +1 ); + set->ext_size +=sizeof (*c) +strlen (c->str) +1 ;rcu_assign_pointer (comment->c, c); }
@@ -58,13 +60,14 @@ ip_set_put_comment(struct sk_buff *skb, const struct ip_set_comment *comment)* of the set data anymore. */ static inline void -ip_set_comment_free (struct ip_set_comment *comment) +ip_set_comment_free (struct ip_set *set,struct ip_set_comment *comment) {struct ip_set_comment_rcu *c; c =rcu_dereference_protected (comment->c,1 );if (unlikely (!c))return ; + set->ext_size -=sizeof (*c) +strlen (c->str) +1 ;kfree_rcu (c, rcu);rcu_assign_pointer (comment->c,NULL ); }
net/netfilter/ipset/ip_set_bitmap_gen.h +3 -2
@@ -84,6 +84,7 @@ mtype_flush(struct ip_set *set)mtype_ext_cleanup (set);memset (map->members,0 , map->memsize); set->elements =0 ; + set->ext_size =0 ; }/* Calculate the actual memory size of the set data */
@@ -99,7 +100,7 @@ mtype_head(struct ip_set *set, struct sk_buff *skb) {const struct mtype *map = set->data;struct nlattr *nested; -size_t memsize =mtype_memsize (map, set->dsize); +size_t memsize =mtype_memsize (map, set->dsize) + set->ext_size; nested =ipset_nest_start (skb,IPSET_ATTR_DATA );if (!nested)
@@ -173,7 +174,7 @@ 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); +ip_set_init_comment (set,ext_comment (x, set), ext);if (SET_WITH_SKBINFO (set))ip_set_init_skbinfo (ext_skbinfo (x, set), ext);
net/netfilter/ipset/ip_set_core.c +1 -1
@@ -324,7 +324,7 @@ ip_set_get_ipaddr6(struct nlattr *nla, union nf_inet_addr *ipaddr) }EXPORT_SYMBOL_GPL (ip_set_get_ipaddr6); -typedef void (*destroyer )(void *); +typedef void (*destroyer )(struct ip_set *,void *);/* ipset data extension types, in size order */ const struct ip_set_ext_type ip_set_extensions[] = {
net/netfilter/ipset/ip_set_hash_gen.h +14 -12
@@ -343,21 +343,13 @@ mtype_del_cidr(struct htype *h, u8 cidr, u8 nets_length, u8 n)/* Calculate the actual memory size of the set data */ static size_t mtype_ahash_memsize (const struct htype *h,const struct htable *t, -u8 nets_length,size_t dsize) +u8 nets_length) { -u32 i; -struct hbucket *n;size_t memsize =sizeof (*h) +sizeof (*t);#ifdef IP_SET_HASH_WITH_NETS memsize +=sizeof (struct net_prefixes ) * nets_length;#endif -for (i =0 ; i <jhash_size (t->htable_bits); i++) { - n =rcu_dereference_bh (hbucket (t, i)); -if (!n) -continue ; - memsize +=sizeof (struct hbucket ) + n->size * dsize; - }return memsize; }
@@ -400,6 +392,7 @@ mtype_flush(struct ip_set *set)memset (h->nets,0 ,sizeof (struct net_prefixes ) *NLEN (set->family));#endif set->elements =0 ; + set->ext_size =0 ; }/* Destroy the hashtable part of the set */
@@ -531,6 +524,7 @@ mtype_expire(struct ip_set *set, struct htype *h, u8 nets_length, size_t dsize) d++; } tmp->pos = d; + set->ext_size -=AHASH_INIT_SIZE * dsize;rcu_assign_pointer (hbucket (t, i), tmp);kfree_rcu (n, rcu); }
@@ -562,7 +556,7 @@ mtype_resize(struct ip_set *set, bool retried)struct htype *h = set->data;struct htable *t, *orig;u8 htable_bits; -size_t dsize = set->dsize; +size_t extsize, dsize = set->dsize;#ifdef IP_SET_HASH_WITH_NETS u8 flags;struct mtype_elem *tmp;
@@ -605,6 +599,7 @@ mtype_resize(struct ip_set *set, bool retried)/* There can't be another parallel resizing, but dumping is possible */ atomic_set (&orig->ref,1 );atomic_inc (&orig->uref); + extsize =0 ;pr_debug ("attempt to resize set %s from %u to %u, t %p\n" , set->name, orig->htable_bits, htable_bits, orig);for (i =0 ; i <jhash_size (orig->htable_bits); i++) {
@@ -635,6 +630,7 @@ mtype_resize(struct ip_set *set, bool retried) goto cleanup; } m->size =AHASH_INIT_SIZE ; + extsize =sizeof (*m) +AHASH_INIT_SIZE * dsize;RCU_INIT_POINTER (hbucket (t, key), m); }else if (m->pos >= m->size) {struct hbucket *ht;
@@ -654,6 +650,7 @@ mtype_resize(struct ip_set *set, bool retried)memcpy (ht, m,sizeof (struct hbucket ) + m->size * dsize); ht->size = m->size +AHASH_INIT_SIZE ; + extsize +=AHASH_INIT_SIZE * dsize;kfree (m); m = ht;RCU_INIT_POINTER (hbucket (t, key), ht);
@@ -667,6 +664,7 @@ mtype_resize(struct ip_set *set, bool retried) } }rcu_assign_pointer (h->table, t); + set->ext_size = extsize;spin_unlock_bh (&set->lock);
@@ -740,6 +738,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,if (!n)return -ENOMEM ; n->size =AHASH_INIT_SIZE ; + set->ext_size +=sizeof (*n) +AHASH_INIT_SIZE * set->dsize; goto copy_elem; }for (i =0 ; i < n->pos; i++) {
@@ -803,6 +802,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,memcpy (n, old,sizeof (struct hbucket ) + old->size * set->dsize); n->size = old->size +AHASH_INIT_SIZE ; + set->ext_size +=AHASH_INIT_SIZE * set->dsize; } copy_elem:
@@ -823,7 +823,7 @@ 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 (data, set), ext);if (SET_WITH_COMMENT (set)) -ip_set_init_comment (ext_comment (data, set), ext); +ip_set_init_comment (set,ext_comment (data, set), ext);if (SET_WITH_SKBINFO (set))ip_set_init_skbinfo (ext_skbinfo (data, set), ext);/* Must come last for the case when timed out entry is reused */
@@ -895,6 +895,7 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext, k++; }if (n->pos ==0 && k ==0 ) { + set->ext_size -=sizeof (*n) + n->size * dsize;rcu_assign_pointer (hbucket (t, key),NULL );kfree_rcu (n, rcu); }else if (k >=AHASH_INIT_SIZE ) {
@@ -913,6 +914,7 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext, k++; } tmp->pos = k; + set->ext_size -=AHASH_INIT_SIZE * dsize;rcu_assign_pointer (hbucket (t, key), tmp);kfree_rcu (n, rcu); }
@@ -1061,7 +1063,7 @@ mtype_head(struct ip_set *set, struct sk_buff *skb)rcu_read_lock_bh (); t =rcu_dereference_bh_nfnl (h->table); - memsize =mtype_ahash_memsize (h, t,NLEN (set->family), set->dsize); + memsize =mtype_ahash_memsize (h, t,NLEN (set->family)) + set->ext_size; htable_bits = t->htable_bits;rcu_read_unlock_bh ();
net/netfilter/ipset/ip_set_list_set.c +3 -2
@@ -228,7 +228,7 @@ list_set_init_extensions(struct ip_set *set, const struct ip_set_ext *ext,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); +ip_set_init_comment (set,ext_comment (e, set), ext);if (SET_WITH_SKBINFO (set))ip_set_init_skbinfo (ext_skbinfo (e, set), ext);/* Update timeout last */
@@ -422,6 +422,7 @@ list_set_flush(struct ip_set *set)list_for_each_entry_safe (e, n, &map->members, list)list_set_del (set, e); set->elements =0 ; + set->ext_size =0 ; } static void
@@ -467,7 +468,7 @@ list_set_head(struct ip_set *set, struct sk_buff *skb) {const struct list_set *map = set->data;struct nlattr *nested; -size_t memsize =list_set_memsize (map, set->dsize); +size_t memsize =list_set_memsize (map, set->dsize) + set->ext_size; nested =ipset_nest_start (skb,IPSET_ATTR_DATA );if (!nested)
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 27/39 netfilter: ipset: Remove redundant mtype_expire() arguments
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
Remove redundant parameters nets_length and dsize, because they can be get from other parameters.
Ported from a patch proposed by Sergey Popovich <[email protected]>.
--- net/netfilter/ipset/ip_set_hash_gen.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
net/netfilter/ipset/ip_set_hash_gen.h +5 -4
@@ -465,14 +465,15 @@ mtype_same_set(const struct ip_set *a, const struct ip_set *b)/* Delete expired elements from the hashtable */ static void -mtype_expire (struct ip_set *set,struct htype *h,u8 nets_length,size_t dsize) +mtype_expire (struct ip_set *set,struct htype *h) {struct htable *t;struct hbucket *n, *tmp;struct mtype_elem *data;u32 i, j, d; +size_t dsize = set->dsize;#ifdef IP_SET_HASH_WITH_NETS -u8 k; +u8 k, nets_length =NLEN (set->family);#endif t =ipset_dereference_protected (h->table, set);
@@ -539,7 +540,7 @@ mtype_gc(unsigned long ul_set)pr_debug ("called\n" );spin_lock_bh (&set->lock); -mtype_expire (set, h,NLEN (set->family), set->dsize); +mtype_expire (set, h);spin_unlock_bh (&set->lock); h->gc.expires = jiffies +IPSET_GC_PERIOD (set->timeout) *HZ ;
@@ -715,7 +716,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,if (set->elements >= h->maxelem) {if (SET_WITH_TIMEOUT (set))/* FIXME: when set is full, we slow down here */ -mtype_expire (set, h,NLEN (set->family), set->dsize); +mtype_expire (set, h);if (set->elements >= h->maxelem &&SET_WITH_FORCEADD (set)) forceadd = true; }
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 28/39 netfilter: ipset: Simplify mtype_expire() for hash types
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
Remove one leve of intendation by using continue while iterating over elements in bucket.
Ported from a patch proposed by Sergey Popovich <[email protected]>.
--- net/netfilter/ipset/ip_set_hash_gen.h | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
net/netfilter/ipset/ip_set_hash_gen.h +12 -13
@@ -487,21 +487,20 @@ mtype_expire(struct ip_set *set, struct htype *h)continue ; } data =ahash_data (n, j, dsize); -if (ip_set_timeout_expired (ext_timeout (data, set))) { -pr_debug ("expired %u/%u\n" , i, j); -clear_bit (j, n->used); -smp_mb__after_atomic (); +if (!ip_set_timeout_expired (ext_timeout (data, set))) +continue ; +pr_debug ("expired %u/%u\n" , i, j); +clear_bit (j, n->used); +smp_mb__after_atomic ();#ifdef IP_SET_HASH_WITH_NETS -for (k =0 ; k <IPSET_NET_COUNT ; k++) -mtype_del_cidr (h, -NCIDR_PUT (DCIDR_GET (data->cidr, - k)), - nets_length, k); +for (k =0 ; k <IPSET_NET_COUNT ; k++) +mtype_del_cidr (h, +NCIDR_PUT (DCIDR_GET (data->cidr, k)), + nets_length, k);#endif -ip_set_ext_destroy (set, data); - set->elements--; - d++; - } +ip_set_ext_destroy (set, data); + set->elements--; + d++; }if (d >=AHASH_INIT_SIZE ) {if (d >= n->size) {
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 29/39 netfilter: ipset: Make NLEN compile time constant for hash types
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
Hash types define HOST_MASK before inclusion of ip_set_hash_gen.h and the only place where NLEN needed to be calculated at runtime is *_create() method.
Ported from a patch proposed by Sergey Popovich <[email protected]>.
--- net/netfilter/ipset/ip_set_hash_gen.h | 51 ++++++++++++++++------------------- 1 file changed, 23 insertions(+), 28 deletions(-)
net/netfilter/ipset/ip_set_hash_gen.h +23 -28
@@ -150,20 +150,18 @@ htable_bits(u32 hashsize)#define INIT_CIDR (cidr, host_mask) \ DCIDR_PUT(((cidr) ? NCIDR_GET(cidr) : host_mask)) -#define SET_HOST_MASK (family) (family == AF_INET ? 32 : 128) -#ifdef IP_SET_HASH_WITH_NET0 -/* cidr from 0 to SET_HOST_MASK() value and c = cidr + 1 */ -#define NLEN (family) (SET_HOST_MASK(family) + 1) +/* cidr from 0 to HOST_MASK value and c = cidr + 1 */ +#define NLEN (HOST_MASK + 1)#define CIDR_POS (c) ((c) - 1)#else -/* cidr from 1 to SET_HOST_MASK() value and c = cidr + 1 */ -#define NLEN (family) SET_HOST_MASK(family) +/* cidr from 1 to HOST_MASK value and c = cidr + 1 */ +#define NLEN HOST_MASK#define CIDR_POS (c) ((c) - 2)#endif #else -#define NLEN (family) 0 +#define NLEN 0#endif /* IP_SET_HASH_WITH_NETS */ #endif /* _IP_SET_HASH_GEN_H */
@@ -298,12 +296,12 @@ struct htype {* sized networks. cidr == real cidr + 1 to support /0. */ static void -mtype_add_cidr (struct htype *h,u8 cidr,u8 nets_length,u8 n) +mtype_add_cidr (struct htype *h,u8 cidr,u8 n) {int i, j;/* Add in increasing prefix order, so larger cidr first */ -for (i =0 , j =-1 ; i < nets_length && h->nets[i].cidr[n]; i++) { +for (i =0 , j =-1 ; i <NLEN && h->nets[i].cidr[n]; i++) {if (j !=-1 ) {continue ; }else if (h->nets[i].cidr[n] < cidr) {
@@ -322,11 +320,11 @@ mtype_add_cidr(struct htype *h, u8 cidr, u8 nets_length, u8 n) }static void -mtype_del_cidr (struct htype *h,u8 cidr,u8 nets_length,u8 n) +mtype_del_cidr (struct htype *h,u8 cidr,u8 n) { -u8 i, j, net_end = nets_length -1 ; +u8 i, j, net_end =NLEN -1 ; -for (i =0 ; i < nets_length; i++) { +for (i =0 ; i <NLEN ; i++) {if (h->nets[i].cidr[n] != cidr)continue ; h->nets[CIDR_POS (cidr)].nets[n]--;
@@ -342,13 +340,12 @@ mtype_del_cidr(struct htype *h, u8 cidr, u8 nets_length, u8 n)/* Calculate the actual memory size of the set data */ static size_t -mtype_ahash_memsize (const struct htype *h,const struct htable *t, -u8 nets_length) +mtype_ahash_memsize (const struct htype *h,const struct htable *t) {size_t memsize =sizeof (*h) +sizeof (*t);#ifdef IP_SET_HASH_WITH_NETS - memsize +=sizeof (struct net_prefixes ) * nets_length; + memsize +=sizeof (struct net_prefixes ) *NLEN ;#endif return memsize;
@@ -389,7 +386,7 @@ mtype_flush(struct ip_set *set)kfree_rcu (n, rcu); }#ifdef IP_SET_HASH_WITH_NETS -memset (h->nets,0 ,sizeof (struct net_prefixes ) *NLEN (set->family)); +memset (h->nets,0 ,sizeof (struct net_prefixes ) *NLEN );#endif set->elements =0 ; set->ext_size =0 ;
@@ -473,7 +470,7 @@ mtype_expire(struct ip_set *set, struct htype *h)u32 i, j, d;size_t dsize = set->dsize;#ifdef IP_SET_HASH_WITH_NETS -u8 k, nets_length =NLEN (set->family); +u8 k;#endif t =ipset_dereference_protected (h->table, set);
@@ -496,7 +493,7 @@ mtype_expire(struct ip_set *set, struct htype *h)for (k =0 ; k <IPSET_NET_COUNT ; k++)mtype_del_cidr (h,NCIDR_PUT (DCIDR_GET (data->cidr, k)), - nets_length, k); + k);#endif ip_set_ext_destroy (set, data); set->elements--;
@@ -776,7 +773,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,for (i =0 ; i <IPSET_NET_COUNT ; i++)mtype_del_cidr (h,NCIDR_PUT (DCIDR_GET (data->cidr, i)), -NLEN (set->family), i); + i);#endif ip_set_ext_destroy (set, data); set->elements--;
@@ -812,8 +809,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext, set->elements++;#ifdef IP_SET_HASH_WITH_NETS for (i =0 ; i <IPSET_NET_COUNT ; i++) -mtype_add_cidr (h,NCIDR_PUT (DCIDR_GET (d->cidr, i)), -NLEN (set->family), i); +mtype_add_cidr (h,NCIDR_PUT (DCIDR_GET (d->cidr, i)), i);#endif memcpy (data, d,sizeof (struct mtype_elem )); overwrite_extensions:
@@ -886,7 +882,7 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext,#ifdef IP_SET_HASH_WITH_NETS for (j =0 ; j <IPSET_NET_COUNT ; j++)mtype_del_cidr (h,NCIDR_PUT (DCIDR_GET (d->cidr, j)), -NLEN (set->family), j); + j);#endif ip_set_ext_destroy (set, data);
@@ -958,14 +954,13 @@ mtype_test_cidrs(struct ip_set *set, struct mtype_elem *d,int i, j =0 ;#endif u32 key, multi =0 ; -u8 nets_length =NLEN (set->family);pr_debug ("test by nets\n" ); -for (; j < nets_length && h->nets[j].cidr[0 ] && !multi; j++) { +for (; j <NLEN && h->nets[j].cidr[0 ] && !multi; j++) {#if IPSET_NET_COUNT ==2 mtype_data_reset_elem (d, &orig);mtype_data_netmask (d,NCIDR_GET (h->nets[j].cidr[0 ]), false); -for (k =0 ; k < nets_length && h->nets[k].cidr[1 ] && !multi; +for (k =0 ; k <NLEN && h->nets[k].cidr[1 ] && !multi; k++) {mtype_data_netmask (d,NCIDR_GET (h->nets[k].cidr[1 ]), true);
@@ -1022,7 +1017,7 @@ mtype_test(struct ip_set *set, void *value, const struct ip_set_ext *ext,* try all possible network sizes */ for (i =0 ; i <IPSET_NET_COUNT ; i++) -if (DCIDR_GET (d->cidr, i) !=SET_HOST_MASK (set->family)) +if (DCIDR_GET (d->cidr, i) !=HOST_MASK )break ;if (i ==IPSET_NET_COUNT ) { ret =mtype_test_cidrs (set, d, ext, mext, flags);
@@ -1063,7 +1058,7 @@ mtype_head(struct ip_set *set, struct sk_buff *skb)rcu_read_lock_bh (); t =rcu_dereference_bh_nfnl (h->table); - memsize =mtype_ahash_memsize (h, t,NLEN (set->family)) + set->ext_size; + memsize =mtype_ahash_memsize (h, t) + set->ext_size; htable_bits = t->htable_bits;rcu_read_unlock_bh ();
@@ -1295,7 +1290,7 @@ IPSET_TOKEN(HTYPE, _create)(struct net *net, struct ip_set *set, hsize =sizeof (*h);#ifdef IP_SET_HASH_WITH_NETS - hsize +=sizeof (struct net_prefixes ) *NLEN (set->family); + hsize +=sizeof (struct net_prefixes ) *NLEN ;#endif h =kzalloc (hsize,GFP_KERNEL );if (!h)
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 30/39 netfilter: ipset: Make sure element data size is a multiple of u32
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
Data for hashing required to be array of u32. Make sure that element data always multiple of u32.
Ported from a patch proposed by Sergey Popovich <[email protected]>.
--- net/netfilter/ipset/ip_set_hash_gen.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
net/netfilter/ipset/ip_set_hash_gen.h +8 -2
@@ -260,8 +260,14 @@ htable_bits(u32 hashsize)#endif #define HKEY (data, initval, htable_bits) \ -(jhash2((u32 *)(data), HKEY_DATALEN / sizeof(u32), initval) \ - & jhash_mask(htable_bits)) +({ \ + const u32 *__k = (const u32 *)data; \ + u32 __l = HKEY_DATALEN / sizeof(u32); \ + \ + BUILD_BUG_ON(HKEY_DATALEN % sizeof(u32) != 0); \ + \ + jhash2(__k, __l, initval) & jhash_mask(htable_bits); \ +})#ifndef htype#ifndef HTYPE
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 31/39 netfilter: ipset: Optimize hash creation routine
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
Exit as easly as possible on error and use RCU_INIT_POINTER() as set is not seen at creation time.
--- net/netfilter/ipset/ip_set_hash_gen.h | 63 ++++++++++++++++------------------- 1 file changed, 29 insertions(+), 34 deletions(-)
net/netfilter/ipset/ip_set_hash_gen.h +29 -34
@@ -1241,41 +1241,35 @@ IPSET_TOKEN(HTYPE, _create)(struct net *net, struct ip_set *set,struct htype *h;struct htable *t; +pr_debug ("Create set %s with family %s\n" , + set->name, set->family ==NFPROTO_IPV4 ?"inet" :"inet6" ); +#ifndef IP_SET_PROTO_UNDEF if (!(set->family ==NFPROTO_IPV4 || set->family ==NFPROTO_IPV6 ))return -IPSET_ERR_INVALID_FAMILY ;#endif -#ifdef IP_SET_HASH_WITH_MARKMASK - markmask =0xffffffff ; -#endif -#ifdef IP_SET_HASH_WITH_NETMASK - netmask = set->family ==NFPROTO_IPV4 ?32 :128 ; -pr_debug ("Create set %s with family %s\n" , - set->name, set->family ==NFPROTO_IPV4 ?"inet" :"inet6" ); -#endif -if (unlikely (!ip_set_optattr_netorder (tb,IPSET_ATTR_HASHSIZE ) || !ip_set_optattr_netorder (tb,IPSET_ATTR_MAXELEM ) || !ip_set_optattr_netorder (tb,IPSET_ATTR_TIMEOUT ) || !ip_set_optattr_netorder (tb,IPSET_ATTR_CADT_FLAGS )))return -IPSET_ERR_PROTOCOL ; +#ifdef IP_SET_HASH_WITH_MARKMASK /* Separated condition in order to avoid directive in argument list */ if (unlikely (!ip_set_optattr_netorder (tb,IPSET_ATTR_MARKMASK )))return -IPSET_ERR_PROTOCOL ; -#endif -if (tb[IPSET_ATTR_HASHSIZE ]) { - hashsize =ip_set_get_h32 (tb[IPSET_ATTR_HASHSIZE ]); -if (hashsize <IPSET_MIMINAL_HASHSIZE ) - hashsize =IPSET_MIMINAL_HASHSIZE ; + markmask =0xffffffff ; +if (tb[IPSET_ATTR_MARKMASK ]) { + markmask =ntohl (nla_get_be32 (tb[IPSET_ATTR_MARKMASK ])); +if (markmask ==0 ) +return -IPSET_ERR_INVALID_MARKMASK ; } - -if (tb[IPSET_ATTR_MAXELEM ]) - maxelem =ip_set_get_h32 (tb[IPSET_ATTR_MAXELEM ]); +#endif #ifdef IP_SET_HASH_WITH_NETMASK + netmask = set->family ==NFPROTO_IPV4 ?32 :128 ;if (tb[IPSET_ATTR_NETMASK ]) { netmask =nla_get_u8 (tb[IPSET_ATTR_NETMASK ]);
@@ -1285,14 +1279,15 @@ IPSET_TOKEN(HTYPE, _create)(struct net *net, struct ip_set *set, return -IPSET_ERR_INVALID_NETMASK; }#endif -#ifdef IP_SET_HASH_WITH_MARKMASK -if (tb[IPSET_ATTR_MARKMASK ]) { - markmask =ntohl (nla_get_be32 (tb[IPSET_ATTR_MARKMASK ])); -if (markmask ==0 ) -return -IPSET_ERR_INVALID_MARKMASK ; +if (tb[IPSET_ATTR_HASHSIZE ]) { + hashsize =ip_set_get_h32 (tb[IPSET_ATTR_HASHSIZE ]); +if (hashsize <IPSET_MIMINAL_HASHSIZE ) + hashsize =IPSET_MIMINAL_HASHSIZE ; } -#endif + +if (tb[IPSET_ATTR_MAXELEM ]) + maxelem =ip_set_get_h32 (tb[IPSET_ATTR_MAXELEM ]); hsize =sizeof (*h);#ifdef IP_SET_HASH_WITH_NETS
@@ -1302,16 +1297,6 @@ IPSET_TOKEN(HTYPE, _create)(struct net *net, struct ip_set *set,if (!h)return -ENOMEM ; - h->maxelem = maxelem; -#ifdef IP_SET_HASH_WITH_NETMASK - h->netmask = netmask; -#endif -#ifdef IP_SET_HASH_WITH_MARKMASK - h->markmask = markmask; -#endif -get_random_bytes (&h->initval,sizeof (h->initval)); - set->timeout =IPSET_NO_TIMEOUT ; - hbits =htable_bits (hashsize); hsize =htable_size (hbits);if (hsize ==0 ) {
@@ -1323,8 +1308,17 @@ IPSET_TOKEN(HTYPE, _create)(struct net *net, struct ip_set *set,kfree (h);return -ENOMEM ; } + h->maxelem = maxelem; +#ifdef IP_SET_HASH_WITH_NETMASK + h->netmask = netmask; +#endif +#ifdef IP_SET_HASH_WITH_MARKMASK + h->markmask = markmask; +#endif +get_random_bytes (&h->initval,sizeof (h->initval)); + t->htable_bits = hbits; -rcu_assign_pointer (h->table, t); +RCU_INIT_POINTER (h->table, t); set->data = h;#ifndef IP_SET_PROTO_UNDEF
@@ -1342,6 +1336,7 @@ IPSET_TOKEN(HTYPE, _create)(struct net *net, struct ip_set *set, __alignof__(struct IPSET_TOKEN(HTYPE, 6_elem))); }#endif + set->timeout =IPSET_NO_TIMEOUT ;if (tb[IPSET_ATTR_TIMEOUT ]) { set->timeout =ip_set_timeout_uget (tb[IPSET_ATTR_TIMEOUT ]);#ifndef IP_SET_PROTO_UNDEF
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 32/39 netfilter: ipset: Make struct htype per ipset family
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
Before this patch struct htype created at the first source of ip_set_hash_gen.h and it is common for both IPv4 and IPv6 set variants.
Make struct htype per ipset family and use NLEN to make nets array fixed size to simplify struct htype allocation.
Ported from a patch proposed by Sergey Popovich <[email protected]>.
--- net/netfilter/ipset/ip_set_hash_gen.h | 51 +++++++++++----------------- net/netfilter/ipset/ip_set_hash_ip.c | 10 +++--- net/netfilter/ipset/ip_set_hash_ipmark.c | 10 +++--- net/netfilter/ipset/ip_set_hash_ipport.c | 6 ++-- net/netfilter/ipset/ip_set_hash_ipportip.c | 6 ++-- net/netfilter/ipset/ip_set_hash_ipportnet.c | 10 +++--- net/netfilter/ipset/ip_set_hash_net.c | 8 ++--- net/netfilter/ipset/ip_set_hash_netiface.c | 8 ++--- net/netfilter/ipset/ip_set_hash_netnet.c | 8 ++--- net/netfilter/ipset/ip_set_hash_netport.c | 10 +++--- net/netfilter/ipset/ip_set_hash_netportnet.c | 10 +++--- 11 files changed, 63 insertions(+), 74 deletions(-)
net/netfilter/ipset/ip_set_hash_gen.h +20 -31
@@ -166,6 +166,18 @@ htable_bits(u32 hashsize)#endif /* _IP_SET_HASH_GEN_H */ +#ifndef MTYPE +#error "MTYPE is not defined!" +#endif + +#ifndef HTYPE +#error "HTYPE is not defined!" +#endif + +#ifndef HOST_MASK +#error "HOST_MASK is not defined!" +#endif +/* Family dependent templates */ #undef ahash_data
@@ -189,7 +201,6 @@ htable_bits(u32 hashsize)#undef mtype_same_set#undef mtype_kadt#undef mtype_uadt -#undef mtype#undef mtype_add#undef mtype_del
@@ -205,6 +216,7 @@ htable_bits(u32 hashsize)#undef mtype_variant#undef mtype_data_match +#undef htype#undef HKEY#define mtype_data_equal IPSET_TOKEN(MTYPE, _data_equal)
@@ -231,7 +243,6 @@ htable_bits(u32 hashsize)#define mtype_same_set IPSET_TOKEN(MTYPE, _same_set)#define mtype_kadt IPSET_TOKEN(MTYPE, _kadt)#define mtype_uadt IPSET_TOKEN(MTYPE, _uadt) -#define mtype MTYPE#define mtype_add IPSET_TOKEN(MTYPE, _add)#define mtype_del IPSET_TOKEN(MTYPE, _del)
@@ -247,18 +258,12 @@ htable_bits(u32 hashsize)#define mtype_variant IPSET_TOKEN(MTYPE, _variant)#define mtype_data_match IPSET_TOKEN(MTYPE, _data_match) -#ifndef MTYPE -#error "MTYPE is not defined!" -#endif - -#ifndef HOST_MASK -#error "HOST_MASK is not defined!" -#endif -#ifndef HKEY_DATALEN #define HKEY_DATALEN sizeof(struct mtype_elem)#endif +#define htype MTYPE +#define HKEY (data, initval, htable_bits) \ ({ \ const u32 *__k = (const u32 *)data; \
@@ -269,33 +274,26 @@ htable_bits(u32 hashsize)jhash2 (__k, __l, initval) &jhash_mask (htable_bits); \ }) -#ifndef htype -#ifndef HTYPE -#error "HTYPE is not defined!" -#endif /* HTYPE */ -#define htype HTYPE -/* The generic hash structure */ struct htype {struct htable __rcu *table;/* the hash table */ +struct timer_list gc;/* garbage collection when timeout enabled */ u32 maxelem;/* max elements in the hash */ u32 initval;/* random jhash init value */ #ifdef IP_SET_HASH_WITH_MARKMASK u32 markmask;/* markmask value for mark mask to store */ #endif -struct timer_list gc;/* garbage collection when timeout enabled */ -struct mtype_elem next;/* temporary storage for uadd */ #ifdef IP_SET_HASH_WITH_MULTI u8 ahash_max;/* max elements in an array block */ #endif #ifdef IP_SET_HASH_WITH_NETMASK u8 netmask;/* netmask value for subnets to store */ #endif +struct mtype_elem next;/* temporary storage for uadd */ #ifdef IP_SET_HASH_WITH_NETS -struct net_prefixes nets[0 ];/* book-keeping of prefixes */ +struct net_prefixes nets[NLEN ];/* book-keeping of prefixes */ #endif }; -#endif /* htype */ #ifdef IP_SET_HASH_WITH_NETS /* Network cidr size book keeping when the hash stores different
@@ -348,13 +346,7 @@ mtype_del_cidr(struct htype *h, u8 cidr, u8 n)static size_t mtype_ahash_memsize (const struct htype *h,const struct htable *t) { -size_t memsize =sizeof (*h) +sizeof (*t); - -#ifdef IP_SET_HASH_WITH_NETS - memsize +=sizeof (struct net_prefixes ) *NLEN ; -#endif - -return memsize; +return sizeof (*h) +sizeof (*t); }/* Get the ith element from the array block n */
@@ -392,7 +384,7 @@ mtype_flush(struct ip_set *set)kfree_rcu (n, rcu); }#ifdef IP_SET_HASH_WITH_NETS -memset (h->nets,0 ,sizeof (struct net_prefixes ) *NLEN ); +memset (h->nets,0 ,sizeof (h->nets));#endif set->elements =0 ; set->ext_size =0 ;
@@ -1290,9 +1282,6 @@ IPSET_TOKEN(HTYPE, _create)(struct net *net, struct ip_set *set, maxelem =ip_set_get_h32 (tb[IPSET_ATTR_MAXELEM ]); hsize =sizeof (*h); -#ifdef IP_SET_HASH_WITH_NETS - hsize +=sizeof (struct net_prefixes ) *NLEN ; -#endif h =kzalloc (hsize,GFP_KERNEL );if (!h)return -ENOMEM ;
net/netfilter/ipset/ip_set_hash_ip.c +5 -5
@@ -82,7 +82,7 @@ hash_ip4_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_ip *h = set->data; + const struct hash_ip4 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ip4_elem e = {0 };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);
@@ -101,7 +101,7 @@ static int hash_ip4_uadt(struct ip_set *set, struct nlattr *tb[], enum ipset_adt adt, u32 *lineno, u32 flags, bool retried) { - const struct hash_ip *h = set->data; + const struct hash_ip4 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ip4_elem e = {0 };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);
@@ -199,7 +199,7 @@ hash_ip6_data_list(struct sk_buff *skb, const struct hash_ip6_elem *e) }static inline void -hash_ip6_data_next (struct hash_ip4_elem *next,const struct hash_ip6_elem *e) +hash_ip6_data_next (struct hash_ip6_elem *next,const struct hash_ip6_elem *e) { }
@@ -217,7 +217,7 @@ hash_ip6_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_ip *h = set->data; + const struct hash_ip6 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ip6_elem e = { { .all = {0 } } };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);
@@ -234,7 +234,7 @@ static int hash_ip6_uadt(struct ip_set *set, struct nlattr *tb[], enum ipset_adt adt, u32 *lineno, u32 flags, bool retried) { - const struct hash_ip *h = set->data; + const struct hash_ip6 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ip6_elem e = { { .all = {0 } } };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);
net/netfilter/ipset/ip_set_hash_ipmark.c +5 -5
@@ -85,7 +85,7 @@ hash_ipmark4_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_ipmark *h = set->data; + const struct hash_ipmark4 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipmark4_elem e = { };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);
@@ -101,7 +101,7 @@ static int hash_ipmark4_uadt(struct ip_set *set, struct nlattr *tb[], enum ipset_adt adt, u32 *lineno, u32 flags, bool retried) { - const struct hash_ipmark *h = set->data; + const struct hash_ipmark4 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipmark4_elem e = { };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);
@@ -193,7 +193,7 @@ hash_ipmark6_data_list(struct sk_buff *skb, }static inline void -hash_ipmark6_data_next (struct hash_ipmark4_elem *next, +hash_ipmark6_data_next (struct hash_ipmark6_elem *next,const struct hash_ipmark6_elem *d) { }
@@ -211,7 +211,7 @@ hash_ipmark6_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_ipmark *h = set->data; + const struct hash_ipmark6 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipmark6_elem e = { };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);
@@ -227,7 +227,7 @@ static int hash_ipmark6_uadt(struct ip_set *set, struct nlattr *tb[], enum ipset_adt adt, u32 *lineno, u32 flags, bool retried) { - const struct hash_ipmark *h = set->data; + const struct hash_ipmark6 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipmark6_elem e = { };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);
net/netfilter/ipset/ip_set_hash_ipport.c +3 -3
@@ -108,7 +108,7 @@ static int hash_ipport4_uadt(struct ip_set *set, struct nlattr *tb[], enum ipset_adt adt, u32 *lineno, u32 flags, bool retried) { - const struct hash_ipport *h = set->data; + const struct hash_ipport4 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipport4_elem e = { .ip =0 };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);
@@ -231,7 +231,7 @@ hash_ipport6_data_list(struct sk_buff *skb, }static inline void -hash_ipport6_data_next (struct hash_ipport4_elem *next, +hash_ipport6_data_next (struct hash_ipport6_elem *next,const struct hash_ipport6_elem *d) { next->port = d->port;
@@ -266,7 +266,7 @@ static int hash_ipport6_uadt(struct ip_set *set, struct nlattr *tb[], enum ipset_adt adt, u32 *lineno, u32 flags, bool retried) { - const struct hash_ipport *h = set->data; + const struct hash_ipport6 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipport6_elem e = { .ip = { .all = {0 } } };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);
net/netfilter/ipset/ip_set_hash_ipportip.c +3 -3
@@ -111,7 +111,7 @@ static int hash_ipportip4_uadt(struct ip_set *set, struct nlattr *tb[], enum ipset_adt adt, u32 *lineno, u32 flags, bool retried) { - const struct hash_ipportip *h = set->data; + const struct hash_ipportip4 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipportip4_elem e = { .ip =0 };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);
@@ -241,7 +241,7 @@ hash_ipportip6_data_list(struct sk_buff *skb, }static inline void -hash_ipportip6_data_next (struct hash_ipportip4_elem *next, +hash_ipportip6_data_next (struct hash_ipportip6_elem *next,const struct hash_ipportip6_elem *d) { next->port = d->port;
@@ -277,7 +277,7 @@ static int hash_ipportip6_uadt(struct ip_set *set, struct nlattr *tb[], enum ipset_adt adt, u32 *lineno, u32 flags, bool retried) { - const struct hash_ipportip *h = set->data; + const struct hash_ipportip6 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipportip6_elem e = { .ip = { .all = {0 } } };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);
net/netfilter/ipset/ip_set_hash_ipportnet.c +5 -5
@@ -138,7 +138,7 @@ hash_ipportnet4_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_ipportnet *h = set->data; + const struct hash_ipportnet4 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; struct hash_ipportnet4_elem e = { .cidr = INIT_CIDR(h->nets[0].cidr[0], HOST_MASK),
@@ -163,7 +163,7 @@ static int hash_ipportnet4_uadt(struct ip_set *set, struct nlattr *tb[], enum ipset_adt adt, u32 *lineno, u32 flags, bool retried) { - const struct hash_ipportnet *h = set->data; + const struct hash_ipportnet4 *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 (set);
@@ -370,7 +370,7 @@ hash_ipportnet6_data_list(struct sk_buff *skb, }static inline void -hash_ipportnet6_data_next (struct hash_ipportnet4_elem *next, +hash_ipportnet6_data_next (struct hash_ipportnet6_elem *next,const struct hash_ipportnet6_elem *d) { next->port = d->port;
@@ -389,7 +389,7 @@ hash_ipportnet6_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_ipportnet *h = set->data; + const struct hash_ipportnet6 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; struct hash_ipportnet6_elem e = { .cidr = INIT_CIDR(h->nets[0].cidr[0], HOST_MASK),
@@ -414,7 +414,7 @@ static int hash_ipportnet6_uadt(struct ip_set *set, struct nlattr *tb[], enum ipset_adt adt, u32 *lineno, u32 flags, bool retried) { - const struct hash_ipportnet *h = set->data; + const struct hash_ipportnet6 *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 (set);
net/netfilter/ipset/ip_set_hash_net.c +4 -4
@@ -117,7 +117,7 @@ hash_net4_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_net *h = set->data; + const struct hash_net4 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; struct hash_net4_elem e = { .cidr = INIT_CIDR(h->nets[0].cidr[0], HOST_MASK),
@@ -139,7 +139,7 @@ static int hash_net4_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; + const struct hash_net4 *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 (set);
@@ -268,7 +268,7 @@ hash_net6_data_list(struct sk_buff *skb, const struct hash_net6_elem *data) }static inline void -hash_net6_data_next (struct hash_net4_elem *next, +hash_net6_data_next (struct hash_net6_elem *next,const struct hash_net6_elem *d) { }
@@ -286,7 +286,7 @@ hash_net6_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_net *h = set->data; + const struct hash_net6 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; struct hash_net6_elem e = { .cidr = INIT_CIDR(h->nets[0].cidr[0], HOST_MASK),
net/netfilter/ipset/ip_set_hash_netiface.c +4 -4
@@ -156,7 +156,7 @@ hash_netiface4_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) { - struct hash_netiface *h = set->data; + struct hash_netiface4 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; struct hash_netiface4_elem e = { .cidr = INIT_CIDR(h->nets[0].cidr[0], HOST_MASK),
@@ -196,7 +196,7 @@ static int hash_netiface4_uadt(struct ip_set *set, struct nlattr *tb[], enum ipset_adt adt, u32 *lineno, u32 flags, bool retried) { - struct hash_netiface *h = set->data; + struct hash_netiface4 *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 (set);
@@ -348,7 +348,7 @@ hash_netiface6_data_list(struct sk_buff *skb, }static inline void -hash_netiface6_data_next (struct hash_netiface4_elem *next, +hash_netiface6_data_next (struct hash_netiface6_elem *next,const struct hash_netiface6_elem *d) { }
@@ -367,7 +367,7 @@ hash_netiface6_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) { - struct hash_netiface *h = set->data; + struct hash_netiface6 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; struct hash_netiface6_elem e = { .cidr = INIT_CIDR(h->nets[0].cidr[0], HOST_MASK),
net/netfilter/ipset/ip_set_hash_netnet.c +4 -4
@@ -143,7 +143,7 @@ hash_netnet4_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_netnet *h = set->data; + const struct hash_netnet4 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netnet4_elem e = { };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);
@@ -165,7 +165,7 @@ static int hash_netnet4_uadt(struct ip_set *set, struct nlattr *tb[], enum ipset_adt adt, u32 *lineno, u32 flags, bool retried) { - const struct hash_netnet *h = set->data; + const struct hash_netnet4 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netnet4_elem e = { };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);
@@ -352,7 +352,7 @@ hash_netnet6_data_list(struct sk_buff *skb, }static inline void -hash_netnet6_data_next (struct hash_netnet4_elem *next, +hash_netnet6_data_next (struct hash_netnet6_elem *next,const struct hash_netnet6_elem *d) { }
@@ -377,7 +377,7 @@ hash_netnet6_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_netnet *h = set->data; + const struct hash_netnet6 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netnet6_elem e = { };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);
net/netfilter/ipset/ip_set_hash_netport.c +5 -5
@@ -133,7 +133,7 @@ hash_netport4_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_netport *h = set->data; + const struct hash_netport4 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; struct hash_netport4_elem e = { .cidr = INIT_CIDR(h->nets[0].cidr[0], HOST_MASK),
@@ -157,7 +157,7 @@ static int hash_netport4_uadt(struct ip_set *set, struct nlattr *tb[], enum ipset_adt adt, u32 *lineno, u32 flags, bool retried) { - const struct hash_netport *h = set->data; + const struct hash_netport4 *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 (set);
@@ -329,7 +329,7 @@ hash_netport6_data_list(struct sk_buff *skb, }static inline void -hash_netport6_data_next (struct hash_netport4_elem *next, +hash_netport6_data_next (struct hash_netport6_elem *next,const struct hash_netport6_elem *d) { next->port = d->port;
@@ -348,7 +348,7 @@ hash_netport6_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_netport *h = set->data; + const struct hash_netport6 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; struct hash_netport6_elem e = { .cidr = INIT_CIDR(h->nets[0].cidr[0], HOST_MASK),
@@ -372,7 +372,7 @@ static int hash_netport6_uadt(struct ip_set *set, struct nlattr *tb[], enum ipset_adt adt, u32 *lineno, u32 flags, bool retried) { - const struct hash_netport *h = set->data; + const struct hash_netport6 *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 (set);
net/netfilter/ipset/ip_set_hash_netportnet.c +5 -5
@@ -154,7 +154,7 @@ hash_netportnet4_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_netportnet *h = set->data; + const struct hash_netportnet4 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netportnet4_elem e = { };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);
@@ -180,7 +180,7 @@ static int hash_netportnet4_uadt(struct ip_set *set, struct nlattr *tb[], enum ipset_adt adt, u32 *lineno, u32 flags, bool retried) { - const struct hash_netportnet *h = set->data; + const struct hash_netportnet4 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netportnet4_elem e = { };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);
@@ -406,7 +406,7 @@ hash_netportnet6_data_list(struct sk_buff *skb, }static inline void -hash_netportnet6_data_next (struct hash_netportnet4_elem *next, +hash_netportnet6_data_next (struct hash_netportnet6_elem *next,const struct hash_netportnet6_elem *d) { next->port = d->port;
@@ -432,7 +432,7 @@ hash_netportnet6_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_netportnet *h = set->data; + const struct hash_netportnet6 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netportnet6_elem e = { };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set);
@@ -458,7 +458,7 @@ static int hash_netportnet6_uadt(struct ip_set *set, struct nlattr *tb[], enum ipset_adt adt, u32 *lineno, u32 flags, bool retried) { - const struct hash_netportnet *h = set->data; + const struct hash_netportnet6 *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netportnet6_elem e = { };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 33/39 netfilter: ipset: Collapse same condition body to a single one
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
The set full case (with net_ratelimit()-ed pr_warn()) is already handled, simply jump there.
--- net/netfilter/ipset/ip_set_hash_gen.h | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
net/netfilter/ipset/ip_set_hash_gen.h +1 -7
@@ -719,14 +719,8 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext, key =HKEY (value, h->initval, t->htable_bits); n =__ipset_dereference_protected (hbucket (t, key),1 );if (!n) { -if (forceadd) { -if (net_ratelimit ()) -pr_warn ("Set %s is full, maxelem %u reached\n" , - set->name, h->maxelem); -return -IPSET_ERR_HASH_FULL ; - }else if (set->elements >= h->maxelem) { +if (forceadd || set->elements >= h->maxelem) goto set_full; - } old =NULL ; n =kzalloc (sizeof (*n) +AHASH_INIT_SIZE * set->dsize,GFP_ATOMIC );
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 34/39 netfilter: ipset: Fix reported memory size for hash:* types
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
The calculation of the full allocated memory did not take into account the size of the base hash bucket structure at some places.
--- net/netfilter/ipset/ip_set_hash_gen.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
net/netfilter/ipset/ip_set_hash_gen.h +9 -7
@@ -85,6 +85,8 @@ struct htable { };#define hbucket (h, i) ((h)->bucket[i]) +#define ext_size (n, dsize) \ + (sizeof(struct hbucket) + (n) * (dsize))#ifndef IPSET_NET_COUNT #define IPSET_NET_COUNT 1
@@ -519,7 +521,7 @@ mtype_expire(struct ip_set *set, struct htype *h) d++; } tmp->pos = d; - set->ext_size -=AHASH_INIT_SIZE * dsize; + set->ext_size -=ext_size (AHASH_INIT_SIZE , dsize);rcu_assign_pointer (hbucket (t, i), tmp);kfree_rcu (n, rcu); }
@@ -625,7 +627,7 @@ mtype_resize(struct ip_set *set, bool retried) goto cleanup; } m->size =AHASH_INIT_SIZE ; - extsize =sizeof (*m) +AHASH_INIT_SIZE * dsize; + extsize =ext_size (AHASH_INIT_SIZE , dsize);RCU_INIT_POINTER (hbucket (t, key), m); }else if (m->pos >= m->size) {struct hbucket *ht;
@@ -645,7 +647,7 @@ mtype_resize(struct ip_set *set, bool retried)memcpy (ht, m,sizeof (struct hbucket ) + m->size * dsize); ht->size = m->size +AHASH_INIT_SIZE ; - extsize +=AHASH_INIT_SIZE * dsize; + extsize +=ext_size (AHASH_INIT_SIZE , dsize);kfree (m); m = ht;RCU_INIT_POINTER (hbucket (t, key), ht);
@@ -727,7 +729,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,if (!n)return -ENOMEM ; n->size =AHASH_INIT_SIZE ; - set->ext_size +=sizeof (*n) +AHASH_INIT_SIZE * set->dsize; + set->ext_size +=ext_size (AHASH_INIT_SIZE , set->dsize); goto copy_elem; }for (i =0 ; i < n->pos; i++) {
@@ -791,7 +793,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,memcpy (n, old,sizeof (struct hbucket ) + old->size * set->dsize); n->size = old->size +AHASH_INIT_SIZE ; - set->ext_size +=AHASH_INIT_SIZE * set->dsize; + set->ext_size +=ext_size (AHASH_INIT_SIZE , set->dsize); } copy_elem:
@@ -883,7 +885,7 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext, k++; }if (n->pos ==0 && k ==0 ) { - set->ext_size -=sizeof (*n) + n->size * dsize; + set->ext_size -=ext_size (n->size, dsize);rcu_assign_pointer (hbucket (t, key),NULL );kfree_rcu (n, rcu); }else if (k >=AHASH_INIT_SIZE ) {
@@ -902,7 +904,7 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext, k++; } tmp->pos = k; - set->ext_size -=AHASH_INIT_SIZE * dsize; + set->ext_size -=ext_size (AHASH_INIT_SIZE , dsize);rcu_assign_pointer (hbucket (t, key), tmp);kfree_rcu (n, rcu); }
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 35/39 netfilter: ipset: hash:ipmac type support added to ipset
In reply to Pablo Neira AyusoFrom: Tomasz Chilinski <[email protected]>
Introduce the hash:ipmac type.
--- net/netfilter/ipset/Kconfig | 9 + net/netfilter/ipset/Makefile | 1 + net/netfilter/ipset/ip_set_hash_ipmac.c | 315 ++++++++++++++++++++++++++++++++ 3 files changed, 325 insertions(+) create mode 100644 net/netfilter/ipset/ip_set_hash_ipmac.c
net/netfilter/ipset/Kconfig +9 -0
@@ -99,6 +99,15 @@ config IP_SET_HASH_IPPORTNET To compile it as a module, choose M here. If unsure, say N. +config IP_SET_HASH_IPMAC + tristate "hash:ip,mac set support" + depends on IP_SET + help + This option adds the hash:ip,mac set type support, by which + one can store IPv4/IPv6 address and MAC (ethernet address) pairs in a set. + + To compile it as a module, choose M here. If unsure, say N. + config IP_SET_HASH_MAC tristate "hash:mac set support" depends on IP_SET
net/netfilter/ipset/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-$(CONFIG_IP_SET_BITMAP_PORT) += ip_set_bitmap_port.o # hash types obj-$(CONFIG_IP_SET_HASH_IP) += ip_set_hash_ip.o +obj-$(CONFIG_IP_SET_HASH_IPMAC) += ip_set_hash_ipmac.o obj-$(CONFIG_IP_SET_HASH_IPMARK) += ip_set_hash_ipmark.o obj-$(CONFIG_IP_SET_HASH_IPPORT) += ip_set_hash_ipport.o obj-$(CONFIG_IP_SET_HASH_IPPORTIP) += ip_set_hash_ipportip.o
net/netfilter/ipset/ip_set_hash_ipmac.c new file +315 -0
315 lines not on this page · raw message
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 36/39 netfilter: ipset: use setup_timer() and mod_timer().
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
Use setup_timer() and instead of init_timer(), being the preferred way of setting up a timer.
Also, quoting the mod_timer() function comment:
-> mod_timer() is a more efficient way to update the expire field of an
active timer (if the timer is inactive it will be activated).
Use setup_timer() and mod_timer() to setup and arm a timer, making the code compact and easier to read.
--- net/netfilter/ipset/ip_set_bitmap_gen.h | 7 ++----- net/netfilter/ipset/ip_set_hash_gen.h | 7 ++----- net/netfilter/ipset/ip_set_list_set.c | 7 ++----- 3 files changed, 6 insertions(+), 15 deletions(-)
net/netfilter/ipset/ip_set_bitmap_gen.h +2 -5
@@ -41,11 +41,8 @@ mtype_gc_init(struct ip_set *set, void (*gc)(unsigned long ul_set)) {struct mtype *map = set->data; -init_timer (&map->gc); - map->gc.data = (unsigned long )set; - map->gc.function = gc; - map->gc.expires = jiffies +IPSET_GC_PERIOD (set->timeout) *HZ ; -add_timer (&map->gc); +setup_timer (&map->gc, gc, (unsigned long )set); +mod_timer (&map->gc, jiffies +IPSET_GC_PERIOD (set->timeout) *HZ ); } static void
net/netfilter/ipset/ip_set_hash_gen.h +2 -5
@@ -433,11 +433,8 @@ mtype_gc_init(struct ip_set *set, void (*gc)(unsigned long ul_set)) {struct htype *h = set->data; -init_timer (&h->gc); - h->gc.data = (unsigned long )set; - h->gc.function = gc; - h->gc.expires = jiffies +IPSET_GC_PERIOD (set->timeout) *HZ ; -add_timer (&h->gc); +setup_timer (&h->gc, gc, (unsigned long )set); +mod_timer (&h->gc, jiffies +IPSET_GC_PERIOD (set->timeout) *HZ );pr_debug ("gc initialized, run in every %u\n" ,IPSET_GC_PERIOD (set->timeout)); }
net/netfilter/ipset/ip_set_list_set.c +2 -5
@@ -586,11 +586,8 @@ list_set_gc_init(struct ip_set *set, void (*gc)(unsigned long ul_set)) {struct list_set *map = set->data; -init_timer (&map->gc); - map->gc.data = (unsigned long )set; - map->gc.function = gc; - map->gc.expires = jiffies +IPSET_GC_PERIOD (set->timeout) *HZ ; -add_timer (&map->gc); +setup_timer (&map->gc, gc, (unsigned long )set); +mod_timer (&map->gc, jiffies +IPSET_GC_PERIOD (set->timeout) *HZ ); }/* Create list:set type of sets */
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 37/39 netfilter: ipset: hash: fix boolreturn.cocci warnings
In reply to Pablo Neira AyusoFrom: kbuild test robot <[email protected]>
net/netfilter/ipset/ip_set_hash_ipmac.c:70:8-9: WARNING: return of 0/1 in function 'hash_ipmac4_data_list' with return type bool net/netfilter/ipset/ip_set_hash_ipmac.c:178:8-9: WARNING: return of 0/1 in function 'hash_ipmac6_data_list' with return type bool
Return statements in functions returning bool should use true/false instead of 1/0.
Generated by: scripts/coccinelle/misc/boolreturn.cocci
--- net/netfilter/ipset/ip_set_hash_ipmac.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/netfilter/ipset/ip_set_hash_ipmac.c +4 -4
@@ -67,10 +67,10 @@ hash_ipmac4_data_list(struct sk_buff *skb, const struct hash_ipmac4_elem *e)if (nla_put_ipaddr4 (skb,IPSET_ATTR_IP , e->ip) ||nla_put (skb,IPSET_ATTR_ETHER ,ETH_ALEN , e->ether)) goto nla_put_failure; -return 0 ; +return false; nla_put_failure: -return 1 ; +return true; } static inline void
@@ -175,10 +175,10 @@ hash_ipmac6_data_list(struct sk_buff *skb, const struct hash_ipmac6_elem *e)if (nla_put_ipaddr6 (skb,IPSET_ATTR_IP , &e->ip.in6) ||nla_put (skb,IPSET_ATTR_ETHER ,ETH_ALEN , e->ether)) goto nla_put_failure; -return 0 ; +return false; nla_put_failure: -return 1 ; +return true; } static inline void
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 38/39 netfilter: conntrack: remove unused netns_ct member
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
since 23014011ba420 ('netfilter: conntrack: support a fixed size of 128 distinct labels') this isn't needed anymore.
--- include/net/netns/conntrack.h | 1 - 1 file changed, 1 deletion(-)
include/net/netns/conntrack.h +0 -1
@@ -91,7 +91,6 @@ struct netns_ct {struct nf_ip_net nf_ct_proto;#if defined(CONFIG_NF_CONNTRACK_LABELS )unsigned int labels_used; -u8 label_words; #endif };#endif
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 39/39 netfilter: x_tables: simplify IS_ERR_OR_NULL to NULL test
In reply to Pablo Neira AyusoFrom: Julia Lawall <[email protected]>
Since commit 7926dbfa4bc1 ("netfilter: don't use mutex_lock_interruptible()"), the function xt_find_table_lock can only return NULL on an error. Simplify the call sites and update the comment before the function.
The semantic patch that change the code is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@@
expression t,e;
@@
t = \(xt_find_table_lock(...)\|
try_then_request_module(xt_find_table_lock(...),...)\)
... when != t=e
- ! IS_ERR_OR_NULL(t)
+ t
@@
expression t,e;
@@
t = \(xt_find_table_lock(...)\|
try_then_request_module(xt_find_table_lock(...),...)\)
... when != t=e
- IS_ERR_OR_NULL(t)
+ !t
@@
expression t,e,e1;
@@
t = \(xt_find_table_lock(...)\|
try_then_request_module(xt_find_table_lock(...),...)\)
... when != t=e
?- t ? PTR_ERR(t) : e1
+ e1
... when any
// </smpl>
--- net/ipv4/netfilter/arp_tables.c | 20 ++++++++++---------- net/ipv4/netfilter/ip_tables.c | 20 ++++++++++---------- net/ipv6/netfilter/ip6_tables.c | 20 ++++++++++---------- net/netfilter/x_tables.c | 2 +- 4 files changed, 31 insertions(+), 31 deletions(-)
net/ipv4/netfilter/arp_tables.c +10 -10
@@ -805,7 +805,7 @@ static int get_info(struct net *net, void __user *user,#endif t =try_then_request_module (xt_find_table_lock (net,NFPROTO_ARP , name),"arptable_%s" , name); -if (!IS_ERR_OR_NULL (t)) { +if (t) {struct arpt_getinfo info;const struct xt_table_info *private = t->private;#ifdef CONFIG_COMPAT
@@ -834,7 +834,7 @@ static int get_info(struct net *net, void __user *user,xt_table_unlock (t);module_put (t->me); }else - ret = t ?PTR_ERR (t) : -ENOENT ; + ret = -ENOENT ;#ifdef CONFIG_COMPAT if (compat)xt_compat_unlock (NFPROTO_ARP );
@@ -859,7 +859,7 @@ static int get_entries(struct net *net, struct arpt_get_entries __user *uptr, get.name[sizeof (get.name) -1 ] ='\0' ; t =xt_find_table_lock (net,NFPROTO_ARP , get.name); -if (!IS_ERR_OR_NULL (t)) { +if (t) {const struct xt_table_info *private = t->private;if (get.size == private->size)
@@ -871,7 +871,7 @@ static int get_entries(struct net *net, struct arpt_get_entries __user *uptr,module_put (t->me);xt_table_unlock (t); }else - ret = t ?PTR_ERR (t) : -ENOENT ; + ret = -ENOENT ;return ret; }
@@ -898,8 +898,8 @@ static int __do_replace(struct net *net, const char *name, t =try_then_request_module (xt_find_table_lock (net,NFPROTO_ARP , name),"arptable_%s" , name); -if (IS_ERR_OR_NULL (t)) { - ret = t ?PTR_ERR (t) : -ENOENT ; +if (!t) { + ret = -ENOENT ; goto free_newinfo_counters_untrans; }
@@ -1014,8 +1014,8 @@ static int do_add_counters(struct net *net, const void __user *user,return PTR_ERR (paddc); t =xt_find_table_lock (net,NFPROTO_ARP , tmp.name); -if (IS_ERR_OR_NULL (t)) { - ret = t ?PTR_ERR (t) : -ENOENT ; +if (!t) { + ret = -ENOENT ; goto free; }
@@ -1404,7 +1404,7 @@ static int compat_get_entries(struct net *net,xt_compat_lock (NFPROTO_ARP ); t =xt_find_table_lock (net,NFPROTO_ARP , get.name); -if (!IS_ERR_OR_NULL (t)) { +if (t) {const struct xt_table_info *private = t->private;struct xt_table_info info;
@@ -1419,7 +1419,7 @@ static int compat_get_entries(struct net *net,module_put (t->me);xt_table_unlock (t); }else - ret = t ?PTR_ERR (t) : -ENOENT ; + ret = -ENOENT ;xt_compat_unlock (NFPROTO_ARP );return ret;
net/ipv4/netfilter/ip_tables.c +10 -10
@@ -973,7 +973,7 @@ static int get_info(struct net *net, void __user *user,#endif t =try_then_request_module (xt_find_table_lock (net,AF_INET , name),"iptable_%s" , name); -if (!IS_ERR_OR_NULL (t)) { +if (t) {struct ipt_getinfo info;const struct xt_table_info *private = t->private;#ifdef CONFIG_COMPAT
@@ -1003,7 +1003,7 @@ static int get_info(struct net *net, void __user *user,xt_table_unlock (t);module_put (t->me); }else - ret = t ?PTR_ERR (t) : -ENOENT ; + ret = -ENOENT ;#ifdef CONFIG_COMPAT if (compat)xt_compat_unlock (AF_INET );
@@ -1028,7 +1028,7 @@ get_entries(struct net *net, struct ipt_get_entries __user *uptr, get.name[sizeof (get.name) -1 ] ='\0' ; t =xt_find_table_lock (net,AF_INET , get.name); -if (!IS_ERR_OR_NULL (t)) { +if (t) {const struct xt_table_info *private = t->private;if (get.size == private->size) ret = copy_entries_to_user(private->size,
@@ -1039,7 +1039,7 @@ get_entries(struct net *net, struct ipt_get_entries __user *uptr,module_put (t->me);xt_table_unlock (t); }else - ret = t ?PTR_ERR (t) : -ENOENT ; + ret = -ENOENT ;return ret; }
@@ -1064,8 +1064,8 @@ __do_replace(struct net *net, const char *name, unsigned int valid_hooks, t =try_then_request_module (xt_find_table_lock (net,AF_INET , name),"iptable_%s" , name); -if (IS_ERR_OR_NULL (t)) { - ret = t ?PTR_ERR (t) : -ENOENT ; +if (!t) { + ret = -ENOENT ; goto free_newinfo_counters_untrans; }
@@ -1180,8 +1180,8 @@ do_add_counters(struct net *net, const void __user *user,return PTR_ERR (paddc); t =xt_find_table_lock (net,AF_INET , tmp.name); -if (IS_ERR_OR_NULL (t)) { - ret = t ?PTR_ERR (t) : -ENOENT ; +if (!t) { + ret = -ENOENT ; goto free; }
@@ -1626,7 +1626,7 @@ compat_get_entries(struct net *net, struct compat_ipt_get_entries __user *uptr,xt_compat_lock (AF_INET ); t =xt_find_table_lock (net,AF_INET , get.name); -if (!IS_ERR_OR_NULL (t)) { +if (t) {const struct xt_table_info *private = t->private;struct xt_table_info info; ret =compat_table_info (private, &info);
@@ -1640,7 +1640,7 @@ compat_get_entries(struct net *net, struct compat_ipt_get_entries __user *uptr,module_put (t->me);xt_table_unlock (t); }else - ret = t ?PTR_ERR (t) : -ENOENT ; + ret = -ENOENT ;xt_compat_unlock (AF_INET );return ret;
net/ipv6/netfilter/ip6_tables.c +10 -10
@@ -1003,7 +1003,7 @@ static int get_info(struct net *net, void __user *user,#endif t =try_then_request_module (xt_find_table_lock (net,AF_INET6 , name),"ip6table_%s" , name); -if (!IS_ERR_OR_NULL (t)) { +if (t) {struct ip6t_getinfo info;const struct xt_table_info *private = t->private;#ifdef CONFIG_COMPAT
@@ -1033,7 +1033,7 @@ static int get_info(struct net *net, void __user *user,xt_table_unlock (t);module_put (t->me); }else - ret = t ?PTR_ERR (t) : -ENOENT ; + ret = -ENOENT ;#ifdef CONFIG_COMPAT if (compat)xt_compat_unlock (AF_INET6 );
@@ -1059,7 +1059,7 @@ get_entries(struct net *net, struct ip6t_get_entries __user *uptr, get.name[sizeof (get.name) -1 ] ='\0' ; t =xt_find_table_lock (net,AF_INET6 , get.name); -if (!IS_ERR_OR_NULL (t)) { +if (t) {struct xt_table_info *private = t->private;if (get.size == private->size) ret = copy_entries_to_user(private->size,
@@ -1070,7 +1070,7 @@ get_entries(struct net *net, struct ip6t_get_entries __user *uptr,module_put (t->me);xt_table_unlock (t); }else - ret = t ?PTR_ERR (t) : -ENOENT ; + ret = -ENOENT ;return ret; }
@@ -1095,8 +1095,8 @@ __do_replace(struct net *net, const char *name, unsigned int valid_hooks, t =try_then_request_module (xt_find_table_lock (net,AF_INET6 , name),"ip6table_%s" , name); -if (IS_ERR_OR_NULL (t)) { - ret = t ?PTR_ERR (t) : -ENOENT ; +if (!t) { + ret = -ENOENT ; goto free_newinfo_counters_untrans; }
@@ -1210,8 +1210,8 @@ do_add_counters(struct net *net, const void __user *user, unsigned int len,if (IS_ERR (paddc))return PTR_ERR (paddc); t =xt_find_table_lock (net,AF_INET6 , tmp.name); -if (IS_ERR_OR_NULL (t)) { - ret = t ?PTR_ERR (t) : -ENOENT ; +if (!t) { + ret = -ENOENT ; goto free; }
@@ -1647,7 +1647,7 @@ compat_get_entries(struct net *net, struct compat_ip6t_get_entries __user *uptr,xt_compat_lock (AF_INET6 ); t =xt_find_table_lock (net,AF_INET6 , get.name); -if (!IS_ERR_OR_NULL (t)) { +if (t) {const struct xt_table_info *private = t->private;struct xt_table_info info; ret =compat_table_info (private, &info);
@@ -1661,7 +1661,7 @@ compat_get_entries(struct net *net, struct compat_ip6t_get_entries __user *uptr,module_put (t->me);xt_table_unlock (t); }else - ret = t ?PTR_ERR (t) : -ENOENT ; + ret = -ENOENT ;xt_compat_unlock (AF_INET6 );return ret;
net/netfilter/x_tables.c +1 -1
@@ -982,7 +982,7 @@ void xt_free_table_info(struct xt_table_info *info) }EXPORT_SYMBOL (xt_free_table_info); -/* Find table by name, grabs mutex & ref. Returns ERR_PTR() on error. */ +/* Find table by name, grabs mutex & ref. Returns NULL on error. */ struct xt_table *xt_find_table_lock (struct net *net,u_int8_t af,const char *name) {
Signature · 1 line
2.1.4
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Sun, 13 Nov 2016 23:24:54 +0100
Quoted 6 lines
The following patchset contains a second batch of Netfilter updates for your net-next tree. This includes a rework of the core hook infrastructure that improves Netfilter performance by ~15% according to synthetic benchmarks. Then, a large batch with ipset updates, including a new hash:ipmac set type, via Jozsef Kadlecsik. This also includes a couple of assorted updates.
Looks great, pulled, thanks!
RE: [PATCH 20/39] netfilter: ipset: Use kmalloc() in comment extension helper
In reply to Pablo Neira AyusoFrom: Pablo Neira Ayuso
Quoted 19 lines
Sent: 13 November 2016 22:25
Allocate memory withkmalloc()rather thankzalloc(): the string is immediately initialized so it is unnecessary to zero out the allocated memory area.Ported from a patch proposed by Sergey Popovich <[email protected]>.
Suggested-by Sergey Popovich <[email protected]>Signed-off-by Jozsef Kadlecsik <[email protected]>--- include/linux/netfilter/ipset/ip_set_comment.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/netfilter/ipset/ip_set_comment.h +0
-0
include/linux/netfilter/ipset/ip_set_comment.h ip_set_init_comment(struct ip_set_comment *comment, · line 40
Quoted 8 lines
include/linux/netfilter/ipset/ip_set_comment.h +1
-1@@ -34,7 +34,7 @@ ip_set_init_comment(struct ip_set_comment *comment,return ;if (unlikely (len >IPSET_MAX_COMMENT_SIZE )) len =IPSET_MAX_COMMENT_SIZE ; - c =kzalloc (sizeof (*c) + len +1 ,GFP_ATOMIC ); + c =kmalloc (sizeof (*c) + len +1 ,GFP_ATOMIC );if (unlikely (!c))return ;strlcpy (c->str, ext->comment, len +1 );
I think I'd do a memcpy() and zero the last byte.
Note that any other parts of 'c->' are no longer zeroed by this code fragment.
David