Netfilter/IPVS updates for net-next
Subsystems (6)
Pablo Neira Ayuso
maintainercover Netfilter/IPVS updates for net-next
Hi,
The following patchset contains Netfilter/IPVS updates for net-next, more specifically:
* Updates for ipset:
1) Coding style fix for ipset comment extension, from Jeremy Sowden.
2) De-inline many functions in ipset, from Jeremy Sowden.
3) Move ipset function definition from header to source file.
4) Move ip_set_put_flags() to source, export it as a symbol, remove inline.
5) Move range_to_mask() to the source file where this is used.
6) Move ip_set_get_ip_port() to the source file where this is used.
* IPVS selftests and netns improvements:
7) Two patches to speedup ipvs netns dismantle, from Haishuang Yan.
8) Three patches to add selftest script for ipvs, also from Haishuang Yan.
* Conntrack updates and new nf_hook_slow_list() function:
9) Document ct ecache extension, from Florian Westphal.
10) Skip ct extensions from ctnetlink dump, from Florian.
11) Free ct extension immediately, from Florian.
12) Skip access to ecache extension from nf_ct_deliver_cached_events() this is not correct as reported by Syzbot.
13) Add and use nf_hook_slow_list(), from Florian.
* Flowtable infrastructure updates:
14) Move priority to nf_flowtable definition.
15) Dynamic allocation of per-device hooks in flowtables.
16) Allow to include netdevice only once in flowtable definitions.
17) Rise maximum number of devices per flowtable.
* Netfilter hardware offload infrastructure updates:
18) Add nft_flow_block_chain() helper function.
19) Pass callback list to nft_setup_cb_call().
20) Add nft_flow_cls_offload_setup() helper function.
21) Remove rules for the unregistered device via netdevice event.
22) Support for multiple devices in a basechain definition at the ingress hook.
22) Add nft_chain_offload_cmd() helper function.
23) Add nft_flow_block_offload_init() helper function.
24) Rewind in case of failing to bind multiple devices to hook.
25) Typo in IPv6 tproxy module description, from Norman Rasmussen.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Thank you.
----------------------------------------------------------------
The following changes since commit fbe3d0c77c83722d7f1c00924e0ed39df2d1d041:
Merge branch 'create-netdevsim-instances-in-namespace' (2019-10-05 16:34:15 -0700)
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 671312e1a05c579714bc08eb2ac3ad5a2c86a10e:
netfilter: nf_tables_offload: unbind if multi-device binding fails (2019-10-26 12:36:44 +0200)
----------------------------------------------------------------
Florian Westphal (5):
netfilter: ecache: document extension area access rules
netfilter: ctnetlink: don't dump ct extensions of unconfirmed conntracks
netfilter: conntrack: free extension area immediately
netfilter: add and use nf_hook_slow_list()
netfilter: ecache: don't look for ecache extension on dying/unconfirmed conntracks
Haishuang Yan (5):
ipvs: batch __ip_vs_cleanup
ipvs: batch __ip_vs_dev_cleanup
selftests: netfilter: add ipvs test script
selftests: netfilter: add ipvs nat test case
selftests: netfilter: add ipvs tunnel test case
Jeremy Sowden (7):
netfilter: ipset: add a coding-style fix to ip_set_ext_destroy.
netfilter: ipset: remove inline from static functions in .c files.
netfilter: ipset: move ip_set_comment functions from ip_set.h to ip_set_core.c.
netfilter: ipset: move functions to ip_set_core.c.
netfilter: ipset: make ip_set_put_flags extern.
netfilter: ipset: move function to ip_set_bitmap_ip.c.
netfilter: ipset: move ip_set_get_ip_port() to ip_set_bitmap_port.c.
Norman Rasmussen (1):
netfilter: nft_tproxy: Fix typo in IPv6 module description.
Pablo Neira Ayuso (13):
Merge tag 'ipvs-next-for-v5.5' of https://git.kernel.org/.../horms/ipvs-next
netfilter: nf_flow_table: move priority to struct nf_flowtable
netfilter: nf_tables: dynamically allocate hooks per net_device in flowtables
netfilter: nf_tables: allow netdevice to be used only once per flowtable
netfilter: nf_tables: increase maximum devices number per flowtable
netfilter: nf_tables_offload: add nft_flow_block_chain()
netfilter: nf_tables_offload: Pass callback list to nft_setup_cb_call()
netfilter: nf_tables_offload: add nft_flow_cls_offload_setup()
netfilter: nf_tables_offload: remove rules on unregistered device only
netfilter: nf_tables: support for multiple devices per netdev hook
netfilter: nf_tables_offload: add nft_chain_offload_cmd()
netfilter: nf_tables_offload: add nft_flow_block_offload_init()
netfilter: nf_tables_offload: unbind if multi-device binding fails
zhang kai (1):
ipvs: no need to update skb route entry for local destination packets.
include/linux/netfilter.h | 41 +- include/linux/netfilter/ipset/ip_set.h | 196 +-------- include/linux/netfilter/ipset/ip_set_bitmap.h | 14 - include/linux/netfilter/ipset/ip_set_getport.h | 3 - include/net/ip_vs.h | 2 +- include/net/netfilter/nf_conntrack_extend.h | 10 - include/net/netfilter/nf_flow_table.h | 1 + include/net/netfilter/nf_tables.h | 16 +- include/uapi/linux/netfilter/nf_tables.h | 2 + net/ipv6/netfilter/nf_tproxy_ipv6.c | 2 +- net/netfilter/core.c | 20 + net/netfilter/ipset/ip_set_bitmap_gen.h | 2 +- net/netfilter/ipset/ip_set_bitmap_ip.c | 26 +- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 18 +- net/netfilter/ipset/ip_set_bitmap_port.c | 41 +- net/netfilter/ipset/ip_set_core.c | 212 ++++++++- net/netfilter/ipset/ip_set_getport.c | 28 -- net/netfilter/ipset/ip_set_hash_gen.h | 4 +- net/netfilter/ipset/ip_set_hash_ip.c | 10 +- net/netfilter/ipset/ip_set_hash_ipmac.c | 8 +- net/netfilter/ipset/ip_set_hash_ipmark.c | 8 +- net/netfilter/ipset/ip_set_hash_ipport.c | 8 +- net/netfilter/ipset/ip_set_hash_ipportip.c | 8 +- net/netfilter/ipset/ip_set_hash_ipportnet.c | 24 +- net/netfilter/ipset/ip_set_hash_mac.c | 6 +- net/netfilter/ipset/ip_set_hash_net.c | 24 +- net/netfilter/ipset/ip_set_hash_netiface.c | 24 +- net/netfilter/ipset/ip_set_hash_netnet.c | 28 +- net/netfilter/ipset/ip_set_hash_netport.c | 24 +- net/netfilter/ipset/ip_set_hash_netportnet.c | 28 +- net/netfilter/ipset/ip_set_list_set.c | 4 +- net/netfilter/ipvs/ip_vs_core.c | 47 +- net/netfilter/ipvs/ip_vs_ctl.c | 12 +- net/netfilter/ipvs/ip_vs_xmit.c | 18 +- net/netfilter/nf_conntrack_core.c | 2 - net/netfilter/nf_conntrack_ecache.c | 23 +- net/netfilter/nf_conntrack_extend.c | 21 +- net/netfilter/nf_conntrack_netlink.c | 76 ++-- net/netfilter/nf_tables_api.c | 572 +++++++++++++++++-------- net/netfilter/nf_tables_offload.c | 188 +++++--- net/netfilter/nft_chain_filter.c | 45 +- tools/testing/selftests/netfilter/Makefile | 2 +- tools/testing/selftests/netfilter/ipvs.sh | 228 ++++++++++ 43 files changed, 1346 insertions(+), 730 deletions(-) create mode 100755 tools/testing/selftests/netfilter/ipvs.sh
Pablo Neira Ayuso
maintainerPATCH 1/31 netfilter: ipset: add a coding-style fix to ip_set_ext_destroy.
From: Jeremy Sowden <[email protected]>
Use a local variable to hold comment in order to align the arguments of ip_set_comment_free properly.
--- include/linux/netfilter/ipset/ip_set.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
include/linux/netfilter/ipset/ip_set.h +5 -3
@@ -269,9 +269,11 @@ ip_set_ext_destroy(struct ip_set *set, void *data)/* Check that the extension is enabled for the set and * call it's destroy function for its extension part in data. */ -if (SET_WITH_COMMENT (set)) - ip_set_extensions[IPSET_EXT_ID_COMMENT ].destroy ( - set,ext_comment (data, set)); +if (SET_WITH_COMMENT (set)) { +struct ip_set_comment *c =ext_comment (data, set); + + ip_set_extensions[IPSET_EXT_ID_COMMENT ].destroy (set, c); + } } static inline int
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 2/31 netfilter: ipset: remove inline from static functions in .c files.
In reply to Pablo Neira AyusoFrom: Jeremy Sowden <[email protected]>
The inline function-specifier should not be used for static functions defined in .c files since it bloats the kernel. Instead leave the compiler to decide which functions to inline.
While a couple of the files affected (ip_set_*_gen.h) are technically headers, they contain templates for generating the common parts of particular set-types and so we treat them like .c files.
--- net/netfilter/ipset/ip_set_bitmap_gen.h | 2 +- net/netfilter/ipset/ip_set_bitmap_ip.c | 14 +++++++------- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 18 +++++++++--------- net/netfilter/ipset/ip_set_bitmap_port.c | 14 +++++++------- net/netfilter/ipset/ip_set_core.c | 20 ++++++++++---------- net/netfilter/ipset/ip_set_hash_gen.h | 4 ++-- net/netfilter/ipset/ip_set_hash_ip.c | 10 +++++----- net/netfilter/ipset/ip_set_hash_ipmac.c | 8 ++++---- net/netfilter/ipset/ip_set_hash_ipmark.c | 8 ++++---- net/netfilter/ipset/ip_set_hash_ipport.c | 8 ++++---- net/netfilter/ipset/ip_set_hash_ipportip.c | 8 ++++---- net/netfilter/ipset/ip_set_hash_ipportnet.c | 24 ++++++++++++------------ net/netfilter/ipset/ip_set_hash_mac.c | 6 +++--- net/netfilter/ipset/ip_set_hash_net.c | 24 ++++++++++++------------ net/netfilter/ipset/ip_set_hash_netiface.c | 24 ++++++++++++------------ net/netfilter/ipset/ip_set_hash_netnet.c | 28 ++++++++++++++-------------- net/netfilter/ipset/ip_set_hash_netport.c | 24 ++++++++++++------------ net/netfilter/ipset/ip_set_hash_netportnet.c | 28 ++++++++++++++-------------- net/netfilter/ipset/ip_set_list_set.c | 4 ++-- 19 files changed, 138 insertions(+), 138 deletions(-)
net/netfilter/ipset/ip_set_bitmap_gen.h +1 -1
@@ -192,7 +192,7 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext, }#ifndef IP_SET_BITMAP_STORED_TIMEOUT -static inline bool +static bool mtype_is_filled (const struct mtype_elem *x) {return true;
net/netfilter/ipset/ip_set_bitmap_ip.c +7 -7
@@ -55,7 +55,7 @@ struct bitmap_ip_adt_elem {u16 id; }; -static inline u32 +static u32 ip_to_id (const struct bitmap_ip *m,u32 ip) {return ((ip &ip_set_hostmask (m->netmask)) - m->first_ip) / m->hosts;
@@ -63,33 +63,33 @@ ip_to_id(const struct bitmap_ip *m, u32 ip)/* Common functions */ -static inline int +static int bitmap_ip_do_test (const struct bitmap_ip_adt_elem *e,struct bitmap_ip *map,size_t dsize) {return !!test_bit (e->id, map->members); } -static inline int +static int bitmap_ip_gc_test (u16 id,const struct bitmap_ip *map,size_t dsize) {return !!test_bit (id, map->members); } -static inline int +static int bitmap_ip_do_add (const struct bitmap_ip_adt_elem *e,struct bitmap_ip *map,u32 flags,size_t dsize) {return !!test_bit (e->id, map->members); } -static inline int +static int bitmap_ip_do_del (const struct bitmap_ip_adt_elem *e,struct bitmap_ip *map) {return !test_and_clear_bit (e->id, map->members); } -static inline int +static int bitmap_ip_do_list (struct sk_buff *skb,const struct bitmap_ip *map,u32 id,size_t dsize) {
@@ -97,7 +97,7 @@ bitmap_ip_do_list(struct sk_buff *skb, const struct bitmap_ip *map, u32 id, htonl(map->first_ip + id * map->hosts)); } -static inline int +static int bitmap_ip_do_head (struct sk_buff *skb,const struct bitmap_ip *map) { return nla_put_ipaddr4(skb, IPSET_ATTR_IP, htonl(map->first_ip)) ||
net/netfilter/ipset/ip_set_bitmap_ipmac.c +9 -9
@@ -65,7 +65,7 @@ struct bitmap_ipmac_elem {unsigned char filled; }__aligned(__alignof__(u64)) ; -static inline u32 +static u32 ip_to_id (const struct bitmap_ipmac *m,u32 ip) {return ip - m->first_ip;
@@ -79,7 +79,7 @@ ip_to_id(const struct bitmap_ipmac *m, u32 ip)/* Common functions */ -static inline int +static int bitmap_ipmac_do_test (const struct bitmap_ipmac_adt_elem *e,const struct bitmap_ipmac *map,size_t dsize) {
@@ -94,7 +94,7 @@ bitmap_ipmac_do_test(const struct bitmap_ipmac_adt_elem *e,return -EAGAIN ; } -static inline int +static int bitmap_ipmac_gc_test (u16 id,const struct bitmap_ipmac *map,size_t dsize) {const struct bitmap_ipmac_elem *elem;
@@ -106,13 +106,13 @@ bitmap_ipmac_gc_test(u16 id, const struct bitmap_ipmac *map, size_t dsize)return elem->filled ==MAC_FILLED ; } -static inline int +static int bitmap_ipmac_is_filled (const struct bitmap_ipmac_elem *elem) {return elem->filled ==MAC_FILLED ; } -static inline int +static int bitmap_ipmac_add_timeout(unsigned long *timeout, const struct bitmap_ipmac_adt_elem *e, const struct ip_set_ext *ext, struct ip_set *set,
@@ -139,7 +139,7 @@ bitmap_ipmac_add_timeout(unsigned long *timeout,return 0 ; } -static inline int +static int bitmap_ipmac_do_add (const struct bitmap_ipmac_adt_elem *e,struct bitmap_ipmac *map,u32 flags,size_t dsize) {
@@ -177,14 +177,14 @@ bitmap_ipmac_do_add(const struct bitmap_ipmac_adt_elem *e,return IPSET_ADD_STORE_PLAIN_TIMEOUT ; } -static inline int +static int bitmap_ipmac_do_del (const struct bitmap_ipmac_adt_elem *e,struct bitmap_ipmac *map) {return !test_and_clear_bit (e->id, map->members); } -static inline int +static int bitmap_ipmac_do_list (struct sk_buff *skb,const struct bitmap_ipmac *map,u32 id,size_t dsize) {
@@ -197,7 +197,7 @@ bitmap_ipmac_do_list(struct sk_buff *skb, const struct bitmap_ipmac *map, nla_put(skb, IPSET_ATTR_ETHER, ETH_ALEN, elem->ether)); } -static inline int +static int bitmap_ipmac_do_head (struct sk_buff *skb,const struct bitmap_ipmac *map) { return nla_put_ipaddr4(skb, IPSET_ATTR_IP, htonl(map->first_ip)) ||
net/netfilter/ipset/ip_set_bitmap_port.c +7 -7
@@ -46,7 +46,7 @@ struct bitmap_port_adt_elem {u16 id; }; -static inline u16 +static u16 port_to_id (const struct bitmap_port *m,u16 port) {return port - m->first_port;
@@ -54,34 +54,34 @@ port_to_id(const struct bitmap_port *m, u16 port)/* Common functions */ -static inline int +static int bitmap_port_do_test (const struct bitmap_port_adt_elem *e,const struct bitmap_port *map,size_t dsize) {return !!test_bit (e->id, map->members); } -static inline int +static int bitmap_port_gc_test (u16 id,const struct bitmap_port *map,size_t dsize) {return !!test_bit (id, map->members); } -static inline int +static int bitmap_port_do_add (const struct bitmap_port_adt_elem *e,struct bitmap_port *map,u32 flags,size_t dsize) {return !!test_bit (e->id, map->members); } -static inline int +static int bitmap_port_do_del (const struct bitmap_port_adt_elem *e,struct bitmap_port *map) {return !test_and_clear_bit (e->id, map->members); } -static inline int +static int bitmap_port_do_list (struct sk_buff *skb,const struct bitmap_port *map,u32 id,size_t dsize) {
@@ -89,7 +89,7 @@ bitmap_port_do_list(struct sk_buff *skb, const struct bitmap_port *map, u32 id, htons(map->first_port + id)); } -static inline int +static int bitmap_port_do_head (struct sk_buff *skb,const struct bitmap_port *map) { return nla_put_net16(skb, IPSET_ATTR_PORT, htons(map->first_port)) ||
net/netfilter/ipset/ip_set_core.c +10 -10
@@ -35,7 +35,7 @@ struct ip_set_net {static unsigned int ip_set_net_id__read_mostly ; -static inline struct ip_set_net *ip_set_pernet (struct net *net) +static struct ip_set_net *ip_set_pernet (struct net *net) {return net_generic (net, ip_set_net_id); }
@@ -67,13 +67,13 @@ MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_IPSET);* serialized by ip_set_type_mutex. */ -static inline void +static void ip_set_type_lock (void ) {mutex_lock (&ip_set_type_mutex); } -static inline void +static void ip_set_type_unlock (void ) {mutex_unlock (&ip_set_type_mutex);
@@ -277,7 +277,7 @@ ip_set_free(void *members) }EXPORT_SYMBOL_GPL (ip_set_free); -static inline bool +static bool flag_nested (const struct nlattr *nla) {return nla->nla_type &NLA_F_NESTED ;
@@ -356,7 +356,7 @@ const struct ip_set_ext_type ip_set_extensions[] = { };EXPORT_SYMBOL_GPL (ip_set_extensions); -static inline bool +static bool add_extension (enum ip_set_ext_id id,u32 flags,struct nlattr *tb[]) { return ip_set_extensions[id].flag ?
@@ -506,7 +506,7 @@ EXPORT_SYMBOL_GPL(ip_set_match_extensions);* The set behind an index may change by swapping only, from userspace. */ -static inline void +static void __ip_set_get (struct ip_set *set) {write_lock_bh (&ip_set_ref_lock);
@@ -514,7 +514,7 @@ __ip_set_get(struct ip_set *set)write_unlock_bh (&ip_set_ref_lock); } -static inline void +static void __ip_set_put (struct ip_set *set) {write_lock_bh (&ip_set_ref_lock);
@@ -526,7 +526,7 @@ __ip_set_put(struct ip_set *set)/* set->ref can be swapped out by ip_set_swap, netlink events (like dump) need * a separate reference counter */ -static inline void +static void __ip_set_put_netlink (struct ip_set *set) {write_lock_bh (&ip_set_ref_lock);
@@ -541,7 +541,7 @@ __ip_set_put_netlink(struct ip_set *set)* so it can't be destroyed (or changed) under our foot. */ -static inline struct ip_set * +static struct ip_set *ip_set_rcu_get (struct net *net,ip_set_id_t index) {struct ip_set *set;
@@ -670,7 +670,7 @@ EXPORT_SYMBOL_GPL(ip_set_get_byname);* */ -static inline void +static void __ip_set_put_byindex (struct ip_set_net *inst,ip_set_id_t index) {struct ip_set *set;
net/netfilter/ipset/ip_set_hash_gen.h +2 -2
@@ -39,7 +39,7 @@#ifdef IP_SET_HASH_WITH_MULTI #define AHASH_MAX (h) ((h)->ahash_max) -static inline u8 +static u8 tune_ahash_max (u8 curr,u32 multi) {u32 n;
@@ -909,7 +909,7 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext,return ret; } -static inline int +static int mtype_data_match (struct mtype_elem *data,const struct ip_set_ext *ext,struct ip_set_ext *mext,struct ip_set *set,u32 flags) {
net/netfilter/ipset/ip_set_hash_ip.c +5 -5
@@ -44,7 +44,7 @@ struct hash_ip4_elem {/* Common functions */ -static inline bool +static bool hash_ip4_data_equal (const struct hash_ip4_elem *e1,const struct hash_ip4_elem *e2,u32 *multi)
@@ -63,7 +63,7 @@ hash_ip4_data_list(struct sk_buff *skb, const struct hash_ip4_elem *e)return true; } -static inline void +static void hash_ip4_data_next (struct hash_ip4_elem *next,const struct hash_ip4_elem *e) { next->ip = e->ip;
@@ -171,7 +171,7 @@ struct hash_ip6_elem {/* Common functions */ -static inline bool +static bool hash_ip6_data_equal (const struct hash_ip6_elem *ip1,const struct hash_ip6_elem *ip2,u32 *multi)
@@ -179,7 +179,7 @@ hash_ip6_data_equal(const struct hash_ip6_elem *ip1,return ipv6_addr_equal (&ip1->ip.in6, &ip2->ip.in6); } -static inline void +static void hash_ip6_netmask (union nf_inet_addr *ip,u8 prefix) {ip6_netmask (ip, prefix);
@@ -196,7 +196,7 @@ hash_ip6_data_list(struct sk_buff *skb, const struct hash_ip6_elem *e)return true; } -static inline void +static void hash_ip6_data_next (struct hash_ip6_elem *next,const struct hash_ip6_elem *e) { }
net/netfilter/ipset/ip_set_hash_ipmac.c +4 -4
@@ -47,7 +47,7 @@ struct hash_ipmac4_elem {/* Common functions */ -static inline bool +static bool hash_ipmac4_data_equal (const struct hash_ipmac4_elem *e1,const struct hash_ipmac4_elem *e2,u32 *multi)
@@ -67,7 +67,7 @@ hash_ipmac4_data_list(struct sk_buff *skb, const struct hash_ipmac4_elem *e)return true; } -static inline void +static void hash_ipmac4_data_next (struct hash_ipmac4_elem *next,const struct hash_ipmac4_elem *e) {
@@ -154,7 +154,7 @@ struct hash_ipmac6_elem {/* Common functions */ -static inline bool +static bool hash_ipmac6_data_equal (const struct hash_ipmac6_elem *e1,const struct hash_ipmac6_elem *e2,u32 *multi)
@@ -175,7 +175,7 @@ hash_ipmac6_data_list(struct sk_buff *skb, const struct hash_ipmac6_elem *e)return true; } -static inline void +static void hash_ipmac6_data_next (struct hash_ipmac6_elem *next,const struct hash_ipmac6_elem *e) {
net/netfilter/ipset/ip_set_hash_ipmark.c +4 -4
@@ -42,7 +42,7 @@ struct hash_ipmark4_elem {/* Common functions */ -static inline bool +static bool hash_ipmark4_data_equal (const struct hash_ipmark4_elem *ip1,const struct hash_ipmark4_elem *ip2,u32 *multi)
@@ -64,7 +64,7 @@ hash_ipmark4_data_list(struct sk_buff *skb,return true; } -static inline void +static void hash_ipmark4_data_next (struct hash_ipmark4_elem *next,const struct hash_ipmark4_elem *d) {
@@ -165,7 +165,7 @@ struct hash_ipmark6_elem {/* Common functions */ -static inline bool +static bool hash_ipmark6_data_equal (const struct hash_ipmark6_elem *ip1,const struct hash_ipmark6_elem *ip2,u32 *multi)
@@ -187,7 +187,7 @@ hash_ipmark6_data_list(struct sk_buff *skb,return true; } -static inline void +static void hash_ipmark6_data_next (struct hash_ipmark6_elem *next,const struct hash_ipmark6_elem *d) {
net/netfilter/ipset/ip_set_hash_ipport.c +4 -4
@@ -47,7 +47,7 @@ struct hash_ipport4_elem {/* Common functions */ -static inline bool +static bool hash_ipport4_data_equal (const struct hash_ipport4_elem *ip1,const struct hash_ipport4_elem *ip2,u32 *multi)
@@ -71,7 +71,7 @@ hash_ipport4_data_list(struct sk_buff *skb,return true; } -static inline void +static void hash_ipport4_data_next (struct hash_ipport4_elem *next,const struct hash_ipport4_elem *d) {
@@ -202,7 +202,7 @@ struct hash_ipport6_elem {/* Common functions */ -static inline bool +static bool hash_ipport6_data_equal (const struct hash_ipport6_elem *ip1,const struct hash_ipport6_elem *ip2,u32 *multi)
@@ -226,7 +226,7 @@ hash_ipport6_data_list(struct sk_buff *skb,return true; } -static inline void +static void hash_ipport6_data_next (struct hash_ipport6_elem *next,const struct hash_ipport6_elem *d) {
net/netfilter/ipset/ip_set_hash_ipportip.c +4 -4
@@ -46,7 +46,7 @@ struct hash_ipportip4_elem {u8 padding; }; -static inline bool +static bool hash_ipportip4_data_equal (const struct hash_ipportip4_elem *ip1,const struct hash_ipportip4_elem *ip2,u32 *multi)
@@ -72,7 +72,7 @@ hash_ipportip4_data_list(struct sk_buff *skb,return true; } -static inline void +static void hash_ipportip4_data_next (struct hash_ipportip4_elem *next,const struct hash_ipportip4_elem *d) {
@@ -210,7 +210,7 @@ struct hash_ipportip6_elem {/* Common functions */ -static inline bool +static bool hash_ipportip6_data_equal (const struct hash_ipportip6_elem *ip1,const struct hash_ipportip6_elem *ip2,u32 *multi)
@@ -236,7 +236,7 @@ hash_ipportip6_data_list(struct sk_buff *skb,return true; } -static inline void +static void hash_ipportip6_data_next (struct hash_ipportip6_elem *next,const struct hash_ipportip6_elem *d) {
net/netfilter/ipset/ip_set_hash_ipportnet.c +12 -12
@@ -59,7 +59,7 @@ struct hash_ipportnet4_elem {/* Common functions */ -static inline bool +static bool hash_ipportnet4_data_equal (const struct hash_ipportnet4_elem *ip1,const struct hash_ipportnet4_elem *ip2,u32 *multi)
@@ -71,25 +71,25 @@ hash_ipportnet4_data_equal(const struct hash_ipportnet4_elem *ip1, ip1->proto == ip2->proto; } -static inline int +static int hash_ipportnet4_do_data_match (const struct hash_ipportnet4_elem *elem) {return elem->nomatch ? -ENOTEMPTY :1 ; } -static inline void +static void hash_ipportnet4_data_set_flags (struct hash_ipportnet4_elem *elem,u32 flags) { elem->nomatch = !!((flags >>16 ) &IPSET_FLAG_NOMATCH ); } -static inline void +static void hash_ipportnet4_data_reset_flags (struct hash_ipportnet4_elem *elem,u8 *flags) {swap (*flags, elem->nomatch); } -static inline void +static void hash_ipportnet4_data_netmask (struct hash_ipportnet4_elem *elem,u8 cidr) { elem->ip2 &=ip_set_netmask (cidr);
@@ -116,7 +116,7 @@ hash_ipportnet4_data_list(struct sk_buff *skb,return true; } -static inline void +static void hash_ipportnet4_data_next (struct hash_ipportnet4_elem *next,const struct hash_ipportnet4_elem *d) {
@@ -308,7 +308,7 @@ struct hash_ipportnet6_elem {/* Common functions */ -static inline bool +static bool hash_ipportnet6_data_equal (const struct hash_ipportnet6_elem *ip1,const struct hash_ipportnet6_elem *ip2,u32 *multi)
@@ -320,25 +320,25 @@ hash_ipportnet6_data_equal(const struct hash_ipportnet6_elem *ip1, ip1->proto == ip2->proto; } -static inline int +static int hash_ipportnet6_do_data_match (const struct hash_ipportnet6_elem *elem) {return elem->nomatch ? -ENOTEMPTY :1 ; } -static inline void +static void hash_ipportnet6_data_set_flags (struct hash_ipportnet6_elem *elem,u32 flags) { elem->nomatch = !!((flags >>16 ) &IPSET_FLAG_NOMATCH ); } -static inline void +static void hash_ipportnet6_data_reset_flags (struct hash_ipportnet6_elem *elem,u8 *flags) {swap (*flags, elem->nomatch); } -static inline void +static void hash_ipportnet6_data_netmask (struct hash_ipportnet6_elem *elem,u8 cidr) {ip6_netmask (&elem->ip2, cidr);
@@ -365,7 +365,7 @@ hash_ipportnet6_data_list(struct sk_buff *skb,return true; } -static inline void +static void hash_ipportnet6_data_next (struct hash_ipportnet6_elem *next,const struct hash_ipportnet6_elem *d) {
net/netfilter/ipset/ip_set_hash_mac.c +3 -3
@@ -37,7 +37,7 @@ struct hash_mac4_elem {/* Common functions */ -static inline bool +static bool hash_mac4_data_equal (const struct hash_mac4_elem *e1,const struct hash_mac4_elem *e2,u32 *multi)
@@ -45,7 +45,7 @@ hash_mac4_data_equal(const struct hash_mac4_elem *e1,return ether_addr_equal (e1->ether, e2->ether); } -static inline bool +static bool hash_mac4_data_list (struct sk_buff *skb,const struct hash_mac4_elem *e) {if (nla_put (skb,IPSET_ATTR_ETHER ,ETH_ALEN , e->ether))
@@ -56,7 +56,7 @@ hash_mac4_data_list(struct sk_buff *skb, const struct hash_mac4_elem *e)return true; } -static inline void +static void hash_mac4_data_next (struct hash_mac4_elem *next,const struct hash_mac4_elem *e) {
net/netfilter/ipset/ip_set_hash_net.c +12 -12
@@ -47,7 +47,7 @@ struct hash_net4_elem {/* Common functions */ -static inline bool +static bool hash_net4_data_equal (const struct hash_net4_elem *ip1,const struct hash_net4_elem *ip2,u32 *multi)
@@ -56,25 +56,25 @@ hash_net4_data_equal(const struct hash_net4_elem *ip1, ip1->cidr == ip2->cidr; } -static inline int +static int hash_net4_do_data_match (const struct hash_net4_elem *elem) {return elem->nomatch ? -ENOTEMPTY :1 ; } -static inline void +static void hash_net4_data_set_flags (struct hash_net4_elem *elem,u32 flags) { elem->nomatch = (flags >>16 ) &IPSET_FLAG_NOMATCH ; } -static inline void +static void hash_net4_data_reset_flags (struct hash_net4_elem *elem,u8 *flags) {swap (*flags, elem->nomatch); } -static inline void +static void hash_net4_data_netmask (struct hash_net4_elem *elem,u8 cidr) { elem->ip &=ip_set_netmask (cidr);
@@ -97,7 +97,7 @@ hash_net4_data_list(struct sk_buff *skb, const struct hash_net4_elem *data)return true; } -static inline void +static void hash_net4_data_next (struct hash_net4_elem *next,const struct hash_net4_elem *d) {
@@ -212,7 +212,7 @@ struct hash_net6_elem {/* Common functions */ -static inline bool +static bool hash_net6_data_equal (const struct hash_net6_elem *ip1,const struct hash_net6_elem *ip2,u32 *multi)
@@ -221,25 +221,25 @@ hash_net6_data_equal(const struct hash_net6_elem *ip1, ip1->cidr == ip2->cidr; } -static inline int +static int hash_net6_do_data_match (const struct hash_net6_elem *elem) {return elem->nomatch ? -ENOTEMPTY :1 ; } -static inline void +static void hash_net6_data_set_flags (struct hash_net6_elem *elem,u32 flags) { elem->nomatch = (flags >>16 ) &IPSET_FLAG_NOMATCH ; } -static inline void +static void hash_net6_data_reset_flags (struct hash_net6_elem *elem,u8 *flags) {swap (*flags, elem->nomatch); } -static inline void +static void hash_net6_data_netmask (struct hash_net6_elem *elem,u8 cidr) {ip6_netmask (&elem->ip, cidr);
@@ -262,7 +262,7 @@ hash_net6_data_list(struct sk_buff *skb, const struct hash_net6_elem *data)return true; } -static inline void +static void hash_net6_data_next (struct hash_net6_elem *next,const struct hash_net6_elem *d) {
net/netfilter/ipset/ip_set_hash_netiface.c +12 -12
@@ -62,7 +62,7 @@ struct hash_netiface4_elem {/* Common functions */ -static inline bool +static bool hash_netiface4_data_equal (const struct hash_netiface4_elem *ip1,const struct hash_netiface4_elem *ip2,u32 *multi)
@@ -74,25 +74,25 @@ hash_netiface4_data_equal(const struct hash_netiface4_elem *ip1,strcmp (ip1->iface, ip2->iface) ==0 ; } -static inline int +static int hash_netiface4_do_data_match (const struct hash_netiface4_elem *elem) {return elem->nomatch ? -ENOTEMPTY :1 ; } -static inline void +static void hash_netiface4_data_set_flags (struct hash_netiface4_elem *elem,u32 flags) { elem->nomatch = (flags >>16 ) &IPSET_FLAG_NOMATCH ; } -static inline void +static void hash_netiface4_data_reset_flags (struct hash_netiface4_elem *elem,u8 *flags) {swap (*flags, elem->nomatch); } -static inline void +static void hash_netiface4_data_netmask (struct hash_netiface4_elem *elem,u8 cidr) { elem->ip &=ip_set_netmask (cidr);
@@ -119,7 +119,7 @@ hash_netiface4_data_list(struct sk_buff *skb,return true; } -static inline void +static void hash_netiface4_data_next (struct hash_netiface4_elem *next,const struct hash_netiface4_elem *d) {
@@ -285,7 +285,7 @@ struct hash_netiface6_elem {/* Common functions */ -static inline bool +static bool hash_netiface6_data_equal (const struct hash_netiface6_elem *ip1,const struct hash_netiface6_elem *ip2,u32 *multi)
@@ -297,25 +297,25 @@ hash_netiface6_data_equal(const struct hash_netiface6_elem *ip1,strcmp (ip1->iface, ip2->iface) ==0 ; } -static inline int +static int hash_netiface6_do_data_match (const struct hash_netiface6_elem *elem) {return elem->nomatch ? -ENOTEMPTY :1 ; } -static inline void +static void hash_netiface6_data_set_flags (struct hash_netiface6_elem *elem,u32 flags) { elem->nomatch = (flags >>16 ) &IPSET_FLAG_NOMATCH ; } -static inline void +static void hash_netiface6_data_reset_flags (struct hash_netiface6_elem *elem,u8 *flags) {swap (*flags, elem->nomatch); } -static inline void +static void hash_netiface6_data_netmask (struct hash_netiface6_elem *elem,u8 cidr) {ip6_netmask (&elem->ip, cidr);
@@ -342,7 +342,7 @@ hash_netiface6_data_list(struct sk_buff *skb,return true; } -static inline void +static void hash_netiface6_data_next (struct hash_netiface6_elem *next,const struct hash_netiface6_elem *d) {
net/netfilter/ipset/ip_set_hash_netnet.c +14 -14
@@ -52,7 +52,7 @@ struct hash_netnet4_elem {/* Common functions */ -static inline bool +static bool hash_netnet4_data_equal (const struct hash_netnet4_elem *ip1,const struct hash_netnet4_elem *ip2,u32 *multi)
@@ -61,32 +61,32 @@ hash_netnet4_data_equal(const struct hash_netnet4_elem *ip1, ip1->ccmp == ip2->ccmp; } -static inline int +static int hash_netnet4_do_data_match (const struct hash_netnet4_elem *elem) {return elem->nomatch ? -ENOTEMPTY :1 ; } -static inline void +static void hash_netnet4_data_set_flags (struct hash_netnet4_elem *elem,u32 flags) { elem->nomatch = (flags >>16 ) &IPSET_FLAG_NOMATCH ; } -static inline void +static void hash_netnet4_data_reset_flags (struct hash_netnet4_elem *elem,u8 *flags) {swap (*flags, elem->nomatch); } -static inline void +static void hash_netnet4_data_reset_elem (struct hash_netnet4_elem *elem,struct hash_netnet4_elem *orig) { elem->ip[1 ] = orig->ip[1 ]; } -static inline void +static void hash_netnet4_data_netmask (struct hash_netnet4_elem *elem,u8 cidr,bool inner) {if (inner) {
@@ -117,7 +117,7 @@ hash_netnet4_data_list(struct sk_buff *skb,return true; } -static inline void +static void hash_netnet4_data_next (struct hash_netnet4_elem *next,const struct hash_netnet4_elem *d) {
@@ -282,7 +282,7 @@ struct hash_netnet6_elem {/* Common functions */ -static inline bool +static bool hash_netnet6_data_equal (const struct hash_netnet6_elem *ip1,const struct hash_netnet6_elem *ip2,u32 *multi)
@@ -292,32 +292,32 @@ hash_netnet6_data_equal(const struct hash_netnet6_elem *ip1, ip1->ccmp == ip2->ccmp; } -static inline int +static int hash_netnet6_do_data_match (const struct hash_netnet6_elem *elem) {return elem->nomatch ? -ENOTEMPTY :1 ; } -static inline void +static void hash_netnet6_data_set_flags (struct hash_netnet6_elem *elem,u32 flags) { elem->nomatch = (flags >>16 ) &IPSET_FLAG_NOMATCH ; } -static inline void +static void hash_netnet6_data_reset_flags (struct hash_netnet6_elem *elem,u8 *flags) {swap (*flags, elem->nomatch); } -static inline void +static void hash_netnet6_data_reset_elem (struct hash_netnet6_elem *elem,struct hash_netnet6_elem *orig) { elem->ip[1 ] = orig->ip[1 ]; } -static inline void +static void hash_netnet6_data_netmask (struct hash_netnet6_elem *elem,u8 cidr,bool inner) {if (inner) {
@@ -348,7 +348,7 @@ hash_netnet6_data_list(struct sk_buff *skb,return true; } -static inline void +static void hash_netnet6_data_next (struct hash_netnet6_elem *next,const struct hash_netnet6_elem *d) {
net/netfilter/ipset/ip_set_hash_netport.c +12 -12
@@ -57,7 +57,7 @@ struct hash_netport4_elem {/* Common functions */ -static inline bool +static bool hash_netport4_data_equal (const struct hash_netport4_elem *ip1,const struct hash_netport4_elem *ip2,u32 *multi)
@@ -68,25 +68,25 @@ hash_netport4_data_equal(const struct hash_netport4_elem *ip1, ip1->cidr == ip2->cidr; } -static inline int +static int hash_netport4_do_data_match (const struct hash_netport4_elem *elem) {return elem->nomatch ? -ENOTEMPTY :1 ; } -static inline void +static void hash_netport4_data_set_flags (struct hash_netport4_elem *elem,u32 flags) { elem->nomatch = !!((flags >>16 ) &IPSET_FLAG_NOMATCH ); } -static inline void +static void hash_netport4_data_reset_flags (struct hash_netport4_elem *elem,u8 *flags) {swap (*flags, elem->nomatch); } -static inline void +static void hash_netport4_data_netmask (struct hash_netport4_elem *elem,u8 cidr) { elem->ip &=ip_set_netmask (cidr);
@@ -112,7 +112,7 @@ hash_netport4_data_list(struct sk_buff *skb,return true; } -static inline void +static void hash_netport4_data_next (struct hash_netport4_elem *next,const struct hash_netport4_elem *d) {
@@ -270,7 +270,7 @@ struct hash_netport6_elem {/* Common functions */ -static inline bool +static bool hash_netport6_data_equal (const struct hash_netport6_elem *ip1,const struct hash_netport6_elem *ip2,u32 *multi)
@@ -281,25 +281,25 @@ hash_netport6_data_equal(const struct hash_netport6_elem *ip1, ip1->cidr == ip2->cidr; } -static inline int +static int hash_netport6_do_data_match (const struct hash_netport6_elem *elem) {return elem->nomatch ? -ENOTEMPTY :1 ; } -static inline void +static void hash_netport6_data_set_flags (struct hash_netport6_elem *elem,u32 flags) { elem->nomatch = !!((flags >>16 ) &IPSET_FLAG_NOMATCH ); } -static inline void +static void hash_netport6_data_reset_flags (struct hash_netport6_elem *elem,u8 *flags) {swap (*flags, elem->nomatch); } -static inline void +static void hash_netport6_data_netmask (struct hash_netport6_elem *elem,u8 cidr) {ip6_netmask (&elem->ip, cidr);
@@ -325,7 +325,7 @@ hash_netport6_data_list(struct sk_buff *skb,return true; } -static inline void +static void hash_netport6_data_next (struct hash_netport6_elem *next,const struct hash_netport6_elem *d) {
net/netfilter/ipset/ip_set_hash_netportnet.c +14 -14
@@ -56,7 +56,7 @@ struct hash_netportnet4_elem {/* Common functions */ -static inline bool +static bool hash_netportnet4_data_equal (const struct hash_netportnet4_elem *ip1,const struct hash_netportnet4_elem *ip2,u32 *multi)
@@ -67,32 +67,32 @@ hash_netportnet4_data_equal(const struct hash_netportnet4_elem *ip1, ip1->proto == ip2->proto; } -static inline int +static int hash_netportnet4_do_data_match (const struct hash_netportnet4_elem *elem) {return elem->nomatch ? -ENOTEMPTY :1 ; } -static inline void +static void hash_netportnet4_data_set_flags (struct hash_netportnet4_elem *elem,u32 flags) { elem->nomatch = !!((flags >>16 ) &IPSET_FLAG_NOMATCH ); } -static inline void +static void hash_netportnet4_data_reset_flags (struct hash_netportnet4_elem *elem,u8 *flags) {swap (*flags, elem->nomatch); } -static inline void +static void hash_netportnet4_data_reset_elem (struct hash_netportnet4_elem *elem,struct hash_netportnet4_elem *orig) { elem->ip[1 ] = orig->ip[1 ]; } -static inline void +static void hash_netportnet4_data_netmask (struct hash_netportnet4_elem *elem,u8 cidr,bool inner) {
@@ -126,7 +126,7 @@ hash_netportnet4_data_list(struct sk_buff *skb,return true; } -static inline void +static void hash_netportnet4_data_next (struct hash_netportnet4_elem *next,const struct hash_netportnet4_elem *d) {
@@ -331,7 +331,7 @@ struct hash_netportnet6_elem {/* Common functions */ -static inline bool +static bool hash_netportnet6_data_equal (const struct hash_netportnet6_elem *ip1,const struct hash_netportnet6_elem *ip2,u32 *multi)
@@ -343,32 +343,32 @@ hash_netportnet6_data_equal(const struct hash_netportnet6_elem *ip1, ip1->proto == ip2->proto; } -static inline int +static int hash_netportnet6_do_data_match (const struct hash_netportnet6_elem *elem) {return elem->nomatch ? -ENOTEMPTY :1 ; } -static inline void +static void hash_netportnet6_data_set_flags (struct hash_netportnet6_elem *elem,u32 flags) { elem->nomatch = !!((flags >>16 ) &IPSET_FLAG_NOMATCH ); } -static inline void +static void hash_netportnet6_data_reset_flags (struct hash_netportnet6_elem *elem,u8 *flags) {swap (*flags, elem->nomatch); } -static inline void +static void hash_netportnet6_data_reset_elem (struct hash_netportnet6_elem *elem,struct hash_netportnet6_elem *orig) { elem->ip[1 ] = orig->ip[1 ]; } -static inline void +static void hash_netportnet6_data_netmask (struct hash_netportnet6_elem *elem,u8 cidr,bool inner) {
@@ -402,7 +402,7 @@ hash_netportnet6_data_list(struct sk_buff *skb,return true; } -static inline void +static void hash_netportnet6_data_next (struct hash_netportnet6_elem *next,const struct hash_netportnet6_elem *d) {
net/netfilter/ipset/ip_set_list_set.c +2 -2
@@ -149,7 +149,7 @@ __list_set_del_rcu(struct rcu_head * rcu)kfree (e); } -static inline void +static void list_set_del (struct ip_set *set,struct set_elem *e) {struct list_set *map = set->data;
@@ -160,7 +160,7 @@ list_set_del(struct ip_set *set, struct set_elem *e)call_rcu (&e->rcu, __list_set_del_rcu); } -static inline void +static void list_set_replace (struct ip_set *set,struct set_elem *e,struct set_elem *old) {struct list_set *map = set->data;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 3/31 netfilter: ipset: move ip_set_comment functions from ip_set.h to ip_set_core.c.
In reply to Pablo Neira AyusoFrom: Jeremy Sowden <[email protected]>
Most of the functions are only called from within ip_set_core.c.
The exception is ip_set_init_comment. However, this is too complex to be a good candidate for a static inline function. Move it to ip_set_core.c, change its linkage to extern and export it, leaving a declaration in ip_set.h.
ip_set_comment_free is only used as an extension destructor, so change its prototype to match and drop cast.
--- include/linux/netfilter/ipset/ip_set.h | 63 ++------------------------------ net/netfilter/ipset/ip_set_core.c | 66 +++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 62 deletions(-)
include/linux/netfilter/ipset/ip_set.h +2 -61
@@ -521,67 +521,8 @@ ip_set_timeout_get(const unsigned long *timeout)return t ==0 ?1 : t; } -static inline char * -ip_set_comment_uget (struct nlattr *tb) -{ -return nla_data (tb); -} - -/* Called from uadd only, protected by the set spinlock. -* The kadt functions don't use the comment extensions in any way. -*/ -static inline void -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 ); - } -if (!len) -return ; -if (unlikely (len >IPSET_MAX_COMMENT_SIZE )) - len =IPSET_MAX_COMMENT_SIZE ; - c =kmalloc (sizeof (*c) + len +1 ,GFP_ATOMIC ); -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); -} - -/* Used only when dumping a set, protected by rcu_read_lock() */ -static inline int -ip_set_put_comment (struct sk_buff *skb,const struct ip_set_comment *comment) -{ -struct ip_set_comment_rcu *c =rcu_dereference (comment->c); - -if (!c) -return 0 ; -return nla_put_string (skb,IPSET_ATTR_COMMENT , c->str); -} - -/* Called from uadd/udel, flush or the garbage collectors protected -* by the set spinlock. -* Called when the set is destroyed and when there can't be any user -* of the set data anymore. -*/ -static inline void -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 ); -} +void ip_set_init_comment (struct ip_set *set,struct ip_set_comment *comment, +const struct ip_set_ext *ext);static inline void ip_set_add_bytes (u64 bytes,struct ip_set_counter *counter)
net/netfilter/ipset/ip_set_core.c +65 -1
78 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 4/31 netfilter: ipset: move functions to ip_set_core.c.
In reply to Pablo Neira AyusoFrom: Jeremy Sowden <[email protected]>
Several inline functions in ip_set.h are only called in ip_set_core.c:
move them and remove inline function specifier.
--- include/linux/netfilter/ipset/ip_set.h | 102 --------------------------------- net/netfilter/ipset/ip_set_core.c | 102 +++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 102 deletions(-)
include/linux/netfilter/ipset/ip_set.h +0 -102
@@ -508,87 +508,10 @@ ip_set_timeout_set(unsigned long *timeout, u32 value) *timeout = t; } -static inline u32 -ip_set_timeout_get (const unsigned long *timeout) -{ -u32 t; - -if (*timeout ==IPSET_ELEM_PERMANENT ) -return 0 ; - - t =jiffies_to_msecs (*timeout - jiffies)/MSEC_PER_SEC ; -/* Zero value in userspace means no timeout */ -return t ==0 ?1 : t; -} -void ip_set_init_comment (struct ip_set *set,struct ip_set_comment *comment,const struct ip_set_ext *ext);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 bool -ip_set_match_counter (u64 counter,u64 match,u8 op) -{ -switch (op) { -case IPSET_COUNTER_NONE : -return true; -case IPSET_COUNTER_EQ : -return counter == match; -case IPSET_COUNTER_NE : -return counter != match; -case IPSET_COUNTER_LT : -return counter < match; -case IPSET_COUNTER_GT : -return counter > match; - } -return false; -} - -static inline void -ip_set_update_counter (struct ip_set_counter *counter, -const struct ip_set_ext *ext,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); - } -} - -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) {
@@ -599,31 +522,6 @@ ip_set_init_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) -{ - 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) {
net/netfilter/ipset/ip_set_core.c +102 -0
120 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 5/31 netfilter: ipset: make ip_set_put_flags extern.
In reply to Pablo Neira AyusoFrom: Jeremy Sowden <[email protected]>
ip_set_put_flags is rather large for a static inline function in a header-file. Move it to ip_set_core.c and export it.
--- include/linux/netfilter/ipset/ip_set.h | 23 +---------------------- net/netfilter/ipset/ip_set_core.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 22 deletions(-)
include/linux/netfilter/ipset/ip_set.h +1 -22
@@ -276,28 +276,7 @@ ip_set_ext_destroy(struct ip_set *set, void *data) } } -static inline int -ip_set_put_flags (struct sk_buff *skb,struct ip_set *set) -{ -u32 cadt_flags =0 ; - -if (SET_WITH_TIMEOUT (set)) -if (unlikely (nla_put_net32 (skb,IPSET_ATTR_TIMEOUT , -htonl (set->timeout)))) -return -EMSGSIZE ; -if (SET_WITH_COUNTER (set)) - cadt_flags |=IPSET_FLAG_WITH_COUNTERS ; -if (SET_WITH_COMMENT (set)) - cadt_flags |=IPSET_FLAG_WITH_COMMENT ; -if (SET_WITH_SKBINFO (set)) - cadt_flags |=IPSET_FLAG_WITH_SKBINFO ; -if (SET_WITH_FORCEADD (set)) - cadt_flags |=IPSET_FLAG_WITH_FORCEADD ; - -if (!cadt_flags) -return 0 ; -return nla_put_net32 (skb,IPSET_ATTR_CADT_FLAGS ,htonl (cadt_flags)); -} +int ip_set_put_flags (struct sk_buff *skb,struct ip_set *set);/* Netlink CB args */ enum {
net/netfilter/ipset/ip_set_core.c +24 -0
@@ -1418,6 +1418,30 @@ static int ip_set_swap(struct net *net, struct sock *ctnl, struct sk_buff *skb,#define DUMP_TYPE (arg) (((u32)(arg)) & 0x0000FFFF)#define DUMP_FLAGS (arg) (((u32)(arg)) >> 16) +int +ip_set_put_flags (struct sk_buff *skb,struct ip_set *set) +{ +u32 cadt_flags =0 ; + +if (SET_WITH_TIMEOUT (set)) +if (unlikely (nla_put_net32 (skb,IPSET_ATTR_TIMEOUT , +htonl (set->timeout)))) +return -EMSGSIZE ; +if (SET_WITH_COUNTER (set)) + cadt_flags |=IPSET_FLAG_WITH_COUNTERS ; +if (SET_WITH_COMMENT (set)) + cadt_flags |=IPSET_FLAG_WITH_COMMENT ; +if (SET_WITH_SKBINFO (set)) + cadt_flags |=IPSET_FLAG_WITH_SKBINFO ; +if (SET_WITH_FORCEADD (set)) + cadt_flags |=IPSET_FLAG_WITH_FORCEADD ; + +if (!cadt_flags) +return 0 ; +return nla_put_net32 (skb,IPSET_ATTR_CADT_FLAGS ,htonl (cadt_flags)); +} +EXPORT_SYMBOL_GPL (ip_set_put_flags); +static int ip_set_dump_done (struct netlink_callback *cb) {
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 6/31 netfilter: ipset: move function to ip_set_bitmap_ip.c.
In reply to Pablo Neira AyusoFrom: Jeremy Sowden <[email protected]>
One inline function in ip_set_bitmap.h is only called in ip_set_bitmap_ip.c: move it and remove inline function specifier.
--- include/linux/netfilter/ipset/ip_set_bitmap.h | 14 -------------- net/netfilter/ipset/ip_set_bitmap_ip.c | 12 ++++++++++++ 2 files changed, 12 insertions(+), 14 deletions(-)
include/linux/netfilter/ipset/ip_set_bitmap.h +0 -14
@@ -12,18 +12,4 @@ enum { IPSET_ADD_START_STORED_TIMEOUT, }; -/* Common functions */ - -static inline u32 -range_to_mask (u32 from,u32 to,u8 *bits) -{ -u32 mask =0xFFFFFFFE ; - - *bits =32 ; -while (--(*bits) >0 && mask && (to & mask) != from) - mask <<=1 ; - -return mask; -} -#endif /* __IP_SET_BITMAP_H */
net/netfilter/ipset/ip_set_bitmap_ip.c +12 -0
@@ -237,6 +237,18 @@ init_map_ip(struct ip_set *set, struct bitmap_ip *map,return true; } +static u32 +range_to_mask (u32 from,u32 to,u8 *bits) +{ +u32 mask =0xFFFFFFFE ; + + *bits =32 ; +while (--(*bits) >0 && mask && (to & mask) != from) + mask <<=1 ; + +return mask; +} +static int bitmap_ip_create (struct net *net,struct ip_set *set,struct nlattr *tb[],u32 flags)
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 7/31 netfilter: ipset: move ip_set_get_ip_port() to ip_set_bitmap_port.c.
In reply to Pablo Neira AyusoFrom: Jeremy Sowden <[email protected]>
ip_set_get_ip_port() is only used in ip_set_bitmap_port.c. Move it there and make it static.
--- include/linux/netfilter/ipset/ip_set_getport.h | 3 --- net/netfilter/ipset/ip_set_bitmap_port.c | 27 +++++++++++++++++++++++++ net/netfilter/ipset/ip_set_getport.c | 28 -------------------------- 3 files changed, 27 insertions(+), 31 deletions(-)
include/linux/netfilter/ipset/ip_set_getport.h +0 -3
@@ -20,9 +20,6 @@ static inline bool ip_set_get_ip6_port(const struct sk_buff *skb, bool src, }#endif -extern bool ip_set_get_ip_port (const struct sk_buff *skb,u8 pf,bool src, -__be16 *port); -static inline bool ip_set_proto_with_ports (u8 proto) {switch (proto) {
net/netfilter/ipset/ip_set_bitmap_port.c +27 -0
@@ -96,6 +96,33 @@ bitmap_port_do_head(struct sk_buff *skb, const struct bitmap_port *map)nla_put_net16 (skb,IPSET_ATTR_PORT_TO ,htons (map->last_port)); } +static bool +ip_set_get_ip_port (const struct sk_buff *skb,u8 pf,bool src,__be16 *port) +{ +bool ret; +u8 proto; + +switch (pf) { +case NFPROTO_IPV4 : + ret =ip_set_get_ip4_port (skb, src, port, &proto); +break ; +case NFPROTO_IPV6 : + ret =ip_set_get_ip6_port (skb, src, port, &proto); +break ; +default : +return false; + } +if (!ret) +return ret; +switch (proto) { +case IPPROTO_TCP : +case IPPROTO_UDP : +return true; +default : +return false; + } +} + static int bitmap_port_kadt(struct ip_set *set, const struct sk_buff *skb, const struct xt_action_param *par,
net/netfilter/ipset/ip_set_getport.c +0 -28
@@ -148,31 +148,3 @@ ip_set_get_ip6_port(const struct sk_buff *skb, bool src, }EXPORT_SYMBOL_GPL (ip_set_get_ip6_port);#endif - -bool -ip_set_get_ip_port (const struct sk_buff *skb,u8 pf,bool src,__be16 *port) -{ -bool ret; -u8 proto; - -switch (pf) { -case NFPROTO_IPV4 : - ret =ip_set_get_ip4_port (skb, src, port, &proto); -break ; -case NFPROTO_IPV6 : - ret =ip_set_get_ip6_port (skb, src, port, &proto); -break ; -default : -return false; - } -if (!ret) -return ret; -switch (proto) { -case IPPROTO_TCP : -case IPPROTO_UDP : -return true; -default : -return false; - } -} -EXPORT_SYMBOL_GPL (ip_set_get_ip_port);
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 8/31 ipvs: no need to update skb route entry for local destination packets.
In reply to Pablo Neira AyusoFrom: zhang kai <[email protected]>
In the end of function __ip_vs_get_out_rt/__ip_vs_get_out_rt_v6,the 'local' variable is always zero.
--- net/netfilter/ipvs/ip_vs_xmit.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
net/netfilter/ipvs/ip_vs_xmit.c +6 -12
@@ -407,12 +407,9 @@ __ip_vs_get_out_rt(struct netns_ipvs *ipvs, int skb_af, struct sk_buff *skb, goto err_put;skb_dst_drop (skb); -if (noref) { -if (!local) -skb_dst_set_noref (skb, &rt->dst); -else -skb_dst_set (skb,dst_clone (&rt->dst)); - }else +if (noref) +skb_dst_set_noref (skb, &rt->dst); +else skb_dst_set (skb, &rt->dst);return local;
@@ -574,12 +571,9 @@ __ip_vs_get_out_rt_v6(struct netns_ipvs *ipvs, int skb_af, struct sk_buff *skb, goto err_put;skb_dst_drop (skb); -if (noref) { -if (!local) -skb_dst_set_noref (skb, &rt->dst); -else -skb_dst_set (skb,dst_clone (&rt->dst)); - }else +if (noref) +skb_dst_set_noref (skb, &rt->dst); +else skb_dst_set (skb, &rt->dst);return local;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 9/31 ipvs: batch __ip_vs_cleanup
In reply to Pablo Neira AyusoFrom: Haishuang Yan <[email protected]>
It's better to batch __ip_vs_cleanup to speedup ipvs connections dismantle.
--- include/net/ip_vs.h | 2 +- net/netfilter/ipvs/ip_vs_core.c | 28 ++++++++++++++++------------ net/netfilter/ipvs/ip_vs_ctl.c | 12 +++++++++--- 3 files changed, 26 insertions(+), 16 deletions(-)
include/net/ip_vs.h +1 -1
@@ -1324,7 +1324,7 @@ void ip_vs_protocol_net_cleanup(struct netns_ipvs *ipvs);void ip_vs_control_net_cleanup (struct netns_ipvs *ipvs);void ip_vs_estimator_net_cleanup (struct netns_ipvs *ipvs);void ip_vs_sync_net_cleanup (struct netns_ipvs *ipvs); -void ip_vs_service_net_cleanup (struct netns_ipvs *ipvs); +void ip_vs_service_nets_cleanup (struct list_head *net_list);/* IPVS application functions * (from ip_vs_app.c)
net/netfilter/ipvs/ip_vs_core.c +16 -12
@@ -2402,18 +2402,22 @@ static int __net_init __ip_vs_init(struct net *net)return -ENOMEM ; } -static void __net_exit __ip_vs_cleanup(struct net *net) +static void __net_exit __ip_vs_cleanup_batch(struct list_head *net_list) { -struct netns_ipvs *ipvs =net_ipvs (net); - -ip_vs_service_net_cleanup (ipvs);/* ip_vs_flush() with locks */ -ip_vs_conn_net_cleanup (ipvs); -ip_vs_app_net_cleanup (ipvs); -ip_vs_protocol_net_cleanup (ipvs); -ip_vs_control_net_cleanup (ipvs); -ip_vs_estimator_net_cleanup (ipvs); -IP_VS_DBG (2 ,"ipvs netns %d released\n" , ipvs->gen); - net->ipvs =NULL ; +struct netns_ipvs *ipvs; +struct net *net; + +ip_vs_service_nets_cleanup (net_list);/* ip_vs_flush() with locks */ +list_for_each_entry (net, net_list, exit_list) { + ipvs =net_ipvs (net); +ip_vs_conn_net_cleanup (ipvs); +ip_vs_app_net_cleanup (ipvs); +ip_vs_protocol_net_cleanup (ipvs); +ip_vs_control_net_cleanup (ipvs); +ip_vs_estimator_net_cleanup (ipvs); +IP_VS_DBG (2 ,"ipvs netns %d released\n" , ipvs->gen); + net->ipvs =NULL ; + } }static int __net_init __ip_vs_dev_init (struct net *net)
@@ -2442,7 +2446,7 @@ static void __net_exit __ip_vs_dev_cleanup(struct net *net)static struct pernet_operations ipvs_core_ops = { .init = __ip_vs_init, - .exit = __ip_vs_cleanup, + .exit_batch = __ip_vs_cleanup_batch, .id = &ip_vs_net_id, .size =sizeof (struct netns_ipvs ), };
net/netfilter/ipvs/ip_vs_ctl.c +9 -3
@@ -1607,14 +1607,20 @@ static int ip_vs_flush(struct netns_ipvs *ipvs, bool cleanup)/* * Delete service by {netns} in the service table. -* Called by __ip_vs_cleanup() +* Called by __ip_vs_batch_cleanup() */ -void ip_vs_service_net_cleanup (struct netns_ipvs *ipvs) +void ip_vs_service_nets_cleanup (struct list_head *net_list) { +struct netns_ipvs *ipvs; +struct net *net; +EnterFunction (2 );/* Check for "full" addressed entries */ mutex_lock (&__ip_vs_mutex); -ip_vs_flush (ipvs, true); +list_for_each_entry (net, net_list, exit_list) { + ipvs =net_ipvs (net); +ip_vs_flush (ipvs, true); + }mutex_unlock (&__ip_vs_mutex);LeaveFunction (2 ); }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 10/31 ipvs: batch __ip_vs_dev_cleanup
In reply to Pablo Neira AyusoFrom: Haishuang Yan <[email protected]>
It's better to batch __ip_vs_cleanup to speedup ipvs devices dismantle.
--- net/netfilter/ipvs/ip_vs_core.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +12 -7
@@ -2433,14 +2433,19 @@ static int __net_init __ip_vs_dev_init(struct net *net)return ret; } -static void __net_exit __ip_vs_dev_cleanup(struct net *net) +static void __net_exit __ip_vs_dev_cleanup_batch(struct list_head *net_list) { -struct netns_ipvs *ipvs =net_ipvs (net); +struct netns_ipvs *ipvs; +struct net *net; +EnterFunction (2 ); -nf_unregister_net_hooks (net, ip_vs_ops,ARRAY_SIZE (ip_vs_ops)); - ipvs->enable =0 ;/* Disable packet reception */ -smp_wmb (); -ip_vs_sync_net_cleanup (ipvs); +list_for_each_entry (net, net_list, exit_list) { + ipvs =net_ipvs (net); +nf_unregister_net_hooks (net, ip_vs_ops,ARRAY_SIZE (ip_vs_ops)); + ipvs->enable =0 ;/* Disable packet reception */ +smp_wmb (); +ip_vs_sync_net_cleanup (ipvs); + }LeaveFunction (2 ); }
@@ -2453,7 +2458,7 @@ static struct pernet_operations ipvs_core_ops = {static struct pernet_operations ipvs_core_dev_ops = { .init = __ip_vs_dev_init, - .exit = __ip_vs_dev_cleanup, + .exit_batch = __ip_vs_dev_cleanup_batch, };/*
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 11/31 selftests: netfilter: add ipvs test script
In reply to Pablo Neira AyusoFrom: Haishuang Yan <[email protected]>
Test virutal server via directing routing for IPv4.
Tested:
# selftests: netfilter: ipvs.sh
# Testing DR mode...
# ipvs.sh: PASS
ok 6 selftests: netfilter: ipvs.sh
--- tools/testing/selftests/netfilter/Makefile | 2 +- tools/testing/selftests/netfilter/ipvs.sh | 178 +++++++++++++++++++++++++++++ 2 files changed, 179 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/netfilter/ipvs.sh
tools/testing/selftests/netfilter/Makefile +1 -1
@@ -2,6 +2,6 @@ # Makefile for netfilter selftests TEST_PROGS := nft_trans_stress.sh nft_nat.sh bridge_brouter.sh \ - conntrack_icmp_related.sh nft_flowtable.sh + conntrack_icmp_related.sh nft_flowtable.sh ipvs.sh include ../lib.mk
tools/testing/selftests/netfilter/ipvs.sh new file +178 -0
178 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 12/31 selftests: netfilter: add ipvs nat test case
In reply to Pablo Neira AyusoFrom: Haishuang Yan <[email protected]>
Test virtual server via NAT.
Tested:
# selftests: netfilter: ipvs.sh
# Testing DR mode...
# Testing NAT mode...
# ipvs.sh: PASS
--- tools/testing/selftests/netfilter/ipvs.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
tools/testing/selftests/netfilter/ipvs.sh +21 -1
@@ -154,20 +154,40 @@ test_dr() { test_service } +test_nat() { + ip netns exec ns0 ip route add ${vip_v4} via ${gip_v4} dev br0 + + ip netns exec ns1 sysctl -qw net.ipv4.ip_forward=1 + ip netns exec ns1 ipvsadm -A -t ${vip_v4}:${port} -s rr + ip netns exec ns1 ipvsadm -a -m -t ${vip_v4}:${port} -r ${rip_v4}:${port} + ip netns exec ns1 ip addr add ${vip_v4}/32 dev lo:1 + + ip netns exec ns2 ip link del veth20 + ip netns exec ns2 ip route add default via ${dip_v4} dev veth21 + + test_service +} + run_tests() { local errors= echo "Testing DR mode..." + cleanup setup test_dr errors=$(( $errors + $? )) + echo "Testing NAT mode..." + cleanup + setup + test_nat + errors=$(( $errors + $? )) + return $errors } trap cleanup EXIT -cleanup run_tests if [ $? -ne 0 ]; then
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 13/31 selftests: netfilter: add ipvs tunnel test case
In reply to Pablo Neira AyusoFrom: Haishuang Yan <[email protected]>
Test virtual server via ipip tunnel.
Tested:
# selftests: netfilter: ipvs.sh
# Testing DR mode...
# Testing NAT mode...
# Testing Tunnel mode...
# ipvs.sh: PASS
ok 6 selftests: netfilter: ipvs.sh
--- tools/testing/selftests/netfilter/ipvs.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
tools/testing/selftests/netfilter/ipvs.sh +30 -0
@@ -168,6 +168,30 @@ test_nat() { test_service } +test_tun() { + ip netns exec ns0 ip route add ${vip_v4} via ${gip_v4} dev br0 + + ip netns exec ns1 modprobe ipip + ip netns exec ns1 ip link set tunl0 up + ip netns exec ns1 sysctl -qw net.ipv4.ip_forward=0 + ip netns exec ns1 sysctl -qw net.ipv4.conf.all.send_redirects=0 + ip netns exec ns1 sysctl -qw net.ipv4.conf.default.send_redirects=0 + ip netns exec ns1 ipvsadm -A -t ${vip_v4}:${port} -s rr + ip netns exec ns1 ipvsadm -a -i -t ${vip_v4}:${port} -r ${rip_v4}:${port} + ip netns exec ns1 ip addr add ${vip_v4}/32 dev lo:1 + + ip netns exec ns2 modprobe ipip + ip netns exec ns2 ip link set tunl0 up + ip netns exec ns2 sysctl -qw net.ipv4.conf.all.arp_ignore=1 + ip netns exec ns2 sysctl -qw net.ipv4.conf.all.arp_announce=2 + ip netns exec ns2 sysctl -qw net.ipv4.conf.all.rp_filter=0 + ip netns exec ns2 sysctl -qw net.ipv4.conf.tunl0.rp_filter=0 + ip netns exec ns2 sysctl -qw net.ipv4.conf.veth21.rp_filter=0 + ip netns exec ns2 ip addr add ${vip_v4}/32 dev lo:1 + + test_service +} + run_tests() { local errors=
@@ -183,6 +207,12 @@ run_tests() { test_nat errors=$(( $errors + $? )) + echo "Testing Tunnel mode..." + cleanup + setup + test_tun + errors=$(( $errors + $? )) + return $errors }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 14/31 netfilter: ecache: document extension area access rules
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Once ct->ext gets free'd via kfree() rather than kfree_rcu we can't access the extension area anymore without owning the conntrack.
This is a special case:
The worker is walking the pcpu dying list while holding dying list lock:
Neither ct nor ct->ext can be free'd until after the walk has completed.
--- net/netfilter/nf_conntrack_ecache.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
net/netfilter/nf_conntrack_ecache.c +15 -2
@@ -30,6 +30,7 @@static DEFINE_MUTEX (nf_ct_ecache_mutex);#define ECACHE_RETRY_WAIT (HZ/10) +#define ECACHE_STACK_ALLOC (256 / sizeof(void *))enum retry_state {STATE_CONGESTED ,
@@ -39,11 +40,11 @@ enum retry_state {static enum retry_state ecache_work_evict_list (struct ct_pcpu *pcpu) { -struct nf_conn *refs[16 ]; +struct nf_conn *refs[ECACHE_STACK_ALLOC ]; +enum retry_state ret =STATE_DONE ;struct nf_conntrack_tuple_hash *h;struct hlist_nulls_node *n;unsigned int evicted =0 ; -enum retry_state ret =STATE_DONE ;spin_lock (&pcpu->lock);
@@ -54,10 +55,22 @@ static enum retry_state ecache_work_evict_list(struct ct_pcpu *pcpu)if (!nf_ct_is_confirmed (ct))continue ; +/* This ecache access is safe because the ct is on the +* pcpu dying list and we hold the spinlock -- the entry +* cannot be free'd until after the lock is released. +* +* This is true even if ct has a refcount of 0: the +* cpu that is about to free the entry must remove it +* from the dying list and needs the lock to do so. +*/ e =nf_ct_ecache_find (ct);if (!e || e->state !=NFCT_ECACHE_DESTROY_FAIL )continue ; +/* ct is in NFCT_ECACHE_DESTROY_FAIL state, this means +* the worker owns this entry: the ct will remain valid +* until the worker puts its ct reference. +*/ if (nf_conntrack_event (IPCT_DESTROY , ct)) { ret =STATE_CONGESTED ;break ;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 15/31 netfilter: ctnetlink: don't dump ct extensions of unconfirmed conntracks
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
When dumping the unconfirmed lists, the cpu that is processing the ct entry can reallocate ct->ext at any time.
Right now accessing the extensions from another CPU is ok provided we're holding rcu read lock: extension reallocation does use rcu.
Once RCU isn't used anymore this becomes unsafe, so skip extensions for the unconfirmed list.
Dumping the extension area for confirmed or dying conntracks is fine:
no reallocations are allowed and list iteration holds appropriate locks that prevent ct (and this ct->ext) from getting free'd.
v2: fix compiler warnings due to misue of 'const' and missing return
statement (kbuild robot).
--- net/netfilter/nf_conntrack_netlink.c | 76 ++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 26 deletions(-)
net/netfilter/nf_conntrack_netlink.c +50 -26
@@ -506,9 +506,45 @@ static int ctnetlink_dump_use(struct sk_buff *skb, const struct nf_conn *ct)return -1 ; } +/* all these functions access ct->ext. Caller must either hold a reference +* on ct or prevent its deletion by holding either the bucket spinlock or +* pcpu dying list lock. +*/ +static int ctnetlink_dump_extinfo (struct sk_buff *skb, +struct nf_conn *ct,u32 type) +{ +if (ctnetlink_dump_acct (skb, ct, type) <0 || +ctnetlink_dump_timestamp (skb, ct) <0 || +ctnetlink_dump_helpinfo (skb, ct) <0 || +ctnetlink_dump_labels (skb, ct) <0 || +ctnetlink_dump_ct_seq_adj (skb, ct) <0 || +ctnetlink_dump_ct_synproxy (skb, ct) <0 ) +return -1 ; + +return 0 ; +} + +static int ctnetlink_dump_info (struct sk_buff *skb,struct nf_conn *ct) +{ +if (ctnetlink_dump_status (skb, ct) <0 || +ctnetlink_dump_mark (skb, ct) <0 || +ctnetlink_dump_secctx (skb, ct) <0 || +ctnetlink_dump_id (skb, ct) <0 || +ctnetlink_dump_use (skb, ct) <0 || +ctnetlink_dump_master (skb, ct) <0 ) +return -1 ; + +if (!test_bit (IPS_OFFLOAD_BIT , &ct->status) && + (ctnetlink_dump_timeout (skb, ct) <0 || +ctnetlink_dump_protoinfo (skb, ct) <0 )) +return -1 ; + +return 0 ; +} +static int ctnetlink_fill_info (struct sk_buff *skb,u32 portid,u32 seq,u32 type, -struct nf_conn *ct) +struct nf_conn *ct,bool extinfo) {const struct nf_conntrack_zone *zone;struct nlmsghdr *nlh;
@@ -552,23 +588,9 @@ ctnetlink_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type, NF_CT_DEFAULT_ZONE_DIR) < 0) goto nla_put_failure; -if (ctnetlink_dump_status (skb, ct) <0 || -ctnetlink_dump_acct (skb, ct, type) <0 || -ctnetlink_dump_timestamp (skb, ct) <0 || -ctnetlink_dump_helpinfo (skb, ct) <0 || -ctnetlink_dump_mark (skb, ct) <0 || -ctnetlink_dump_secctx (skb, ct) <0 || -ctnetlink_dump_labels (skb, ct) <0 || -ctnetlink_dump_id (skb, ct) <0 || -ctnetlink_dump_use (skb, ct) <0 || -ctnetlink_dump_master (skb, ct) <0 || -ctnetlink_dump_ct_seq_adj (skb, ct) <0 || -ctnetlink_dump_ct_synproxy (skb, ct) <0 ) +if (ctnetlink_dump_info (skb, ct) <0 ) goto nla_put_failure; - -if (!test_bit (IPS_OFFLOAD_BIT , &ct->status) && - (ctnetlink_dump_timeout (skb, ct) <0 || -ctnetlink_dump_protoinfo (skb, ct) <0 )) +if (extinfo &&ctnetlink_dump_extinfo (skb, ct, type) <0 ) goto nla_put_failure;nlmsg_end (skb, nlh);
@@ -953,13 +975,11 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)if (!ctnetlink_filter_match (ct, cb->data))continue ; -rcu_read_lock (); res =ctnetlink_fill_info (skb,NETLINK_CB (cb->skb).portid, cb->nlh->nlmsg_seq,NFNL_MSG_TYPE (cb->nlh->nlmsg_type), - ct); -rcu_read_unlock (); + ct, true);if (res <0 ) {nf_conntrack_get (&ct->ct_general); cb->args[1 ] = (unsigned long )ct;
@@ -1364,10 +1384,8 @@ static int ctnetlink_get_conntrack(struct net *net, struct sock *ctnl,return -ENOMEM ; } -rcu_read_lock (); err =ctnetlink_fill_info (skb2,NETLINK_CB (skb).portid, nlh->nlmsg_seq, -NFNL_MSG_TYPE (nlh->nlmsg_type), ct); -rcu_read_unlock (); +NFNL_MSG_TYPE (nlh->nlmsg_type), ct, true);nf_ct_put (ct);if (err <=0 ) goto free;
@@ -1429,12 +1447,18 @@ ctnetlink_dump_list(struct sk_buff *skb, struct netlink_callback *cb, bool dyingcontinue ; cb->args[1 ] =0 ; } -rcu_read_lock (); + +/* We can't dump extension info for the unconfirmed +* list because unconfirmed conntracks can have +* ct->ext reallocated (and thus freed). +* +* In the dying list case ct->ext can't be free'd +* until after we drop pcpu->lock. +*/ res =ctnetlink_fill_info (skb,NETLINK_CB (cb->skb).portid, cb->nlh->nlmsg_seq,NFNL_MSG_TYPE (cb->nlh->nlmsg_type), - ct); -rcu_read_unlock (); + ct, dying ? true : false);if (res <0 ) {if (!atomic_inc_not_zero (&ct->ct_general.use))continue ;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 16/31 netfilter: conntrack: free extension area immediately
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Instead of waiting for rcu grace period just free it directly.
This is safe because conntrack lookup doesn't consider extensions.
Other accesses happen while ct->ext can't be free'd, either because a ct refcount was taken or because the conntrack hash bucket lock or the dying list spinlock have been taken.
This allows to remove __krealloc in a followup patch, netfilter was the only user.
--- include/net/netfilter/nf_conntrack_extend.h | 10 ---------- net/netfilter/nf_conntrack_core.c | 2 -- net/netfilter/nf_conntrack_extend.c | 21 ++++++++++----------- 3 files changed, 10 insertions(+), 23 deletions(-)
include/net/netfilter/nf_conntrack_extend.h +0 -10
@@ -43,7 +43,6 @@ enum nf_ct_ext_id {/* Extensions: optional stuff which isn't permanently in struct. */ struct nf_ct_ext { -struct rcu_head rcu;u8 offset[NF_CT_EXT_NUM ];u8 len;char data[0 ];
@@ -72,15 +71,6 @@ static inline void *__nf_ct_ext_find(const struct nf_conn *ct, u8 id)/* Destroy all relationships */ void nf_ct_ext_destroy (struct nf_conn *ct); -/* Free operation. If you want to free a object referred from private area, -* please implement __nf_ct_ext_free() and call it. -*/ -static inline void nf_ct_ext_free (struct nf_conn *ct) -{ -if (ct->ext) -kfree_rcu (ct->ext, rcu); -} -/* Add this type, returns pointer to data or NULL. */ void *nf_ct_ext_add (struct nf_conn *ct,enum nf_ct_ext_id id,gfp_t gfp);
net/netfilter/nf_conntrack_core.c +0 -2
@@ -573,7 +573,6 @@ EXPORT_SYMBOL_GPL(nf_ct_tmpl_alloc);void nf_ct_tmpl_free (struct nf_conn *tmpl) {nf_ct_ext_destroy (tmpl); -nf_ct_ext_free (tmpl);if (ARCH_KMALLOC_MINALIGN <=NFCT_INFOMASK )kfree ((char *)tmpl - tmpl->proto.tmpl_padto);
@@ -1417,7 +1416,6 @@ void nf_conntrack_free(struct nf_conn *ct)WARN_ON (atomic_read (&ct->ct_general.use) !=0 );nf_ct_ext_destroy (ct); -nf_ct_ext_free (ct);kmem_cache_free (nf_conntrack_cachep, ct);smp_mb__before_atomic ();atomic_dec (&net->ct.count);
net/netfilter/nf_conntrack_extend.c +10 -11
@@ -34,21 +34,24 @@ void nf_ct_ext_destroy(struct nf_conn *ct) t->destroy (ct);rcu_read_unlock (); } + +kfree (ct->ext); }EXPORT_SYMBOL (nf_ct_ext_destroy);void *nf_ct_ext_add (struct nf_conn *ct,enum nf_ct_ext_id id,gfp_t gfp) {unsigned int newlen, newoff, oldlen, alloc; -struct nf_ct_ext *old, *new;struct nf_ct_ext_type *t; +struct nf_ct_ext *new;/* Conntrack must not be confirmed to avoid races on reallocation. */ WARN_ON (nf_ct_is_confirmed (ct)); - old = ct->ext; -if (old) { +if (ct->ext) { +const struct nf_ct_ext *old = ct->ext; +if (__nf_ct_ext_exist (old, id))return NULL ; oldlen = old->len;
@@ -68,22 +71,18 @@ void *nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp)rcu_read_unlock (); alloc =max (newlen,NF_CT_EXT_PREALLOC ); -kmemleak_not_leak (old); - new =__krealloc (old, alloc, gfp); + new =krealloc (ct->ext, alloc, gfp);if (!new)return NULL ; -if (!old) { +if (!ct->ext)memset (new->offset,0 ,sizeof (new->offset)); - ct->ext = new; - }else if (new != old) { -kfree_rcu (old, rcu); -rcu_assign_pointer (ct->ext, new); - } new->offset[id] = newoff; new->len = newlen;memset ((void *)new + newoff,0 , newlen - newoff); + + ct->ext = new;return (void *)new + newoff; }EXPORT_SYMBOL (nf_ct_ext_add);
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 17/31 netfilter: add and use nf_hook_slow_list()
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
At this time, NF_HOOK_LIST() macro will iterate the list and then calls nf_hook() for each individual skb.
This makes it so the entire list is passed into the netfilter core. The advantage is that we only need to fetch the rule blob once per list instead of per-skb.
NF_HOOK_LIST now only works for ipv4 and ipv6, as those are the only callers.
v2: use skb_list_del_init() instead of list_del (Edward Cree)
--- include/linux/netfilter.h | 41 +++++++++++++++++++++++++++++++---------- net/netfilter/core.c | 20 ++++++++++++++++++++ 2 files changed, 51 insertions(+), 10 deletions(-)
include/linux/netfilter.h +31 -10
@@ -199,6 +199,8 @@ 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,const struct nf_hook_entries *e,unsigned int i); +void nf_hook_slow_list (struct list_head *head,struct nf_hook_state *state, +const struct nf_hook_entries *e);/** * nf_hook - call a netfilter hook *
@@ -311,17 +313,36 @@ NF_HOOK_LIST(uint8_t pf, unsigned int hook, struct net *net, struct sock *sk, struct list_head *head, struct net_device *in, struct net_device *out, int (*okfn)(struct net *, struct sock *, struct sk_buff *)) { - struct sk_buff *skb, *next; -struct list_head sublist; - -INIT_LIST_HEAD (&sublist); -list_for_each_entry_safe (skb, next, head, list) { -list_del (&skb->list); -if (nf_hook (pf, hook, net, sk, skb, in, out, okfn) ==1 ) -list_add_tail (&skb->list, &sublist); + struct nf_hook_entries *hook_head = NULL; + +#ifdef CONFIG_JUMP_LABEL +if (__builtin_constant_p (pf) && +__builtin_constant_p (hook) && + !static_key_false (&nf_hooks_needed[pf][hook])) +return ; +#endif + +rcu_read_lock (); +switch (pf) { +case NFPROTO_IPV4 : + hook_head =rcu_dereference (net->nf.hooks_ipv4[hook]); +break ; +case NFPROTO_IPV6 : + hook_head =rcu_dereference (net->nf.hooks_ipv6[hook]); +break ; +default : +WARN_ON_ONCE (1 ); +break ; } -/* Put passed packets back on main list */ -list_splice (&sublist, head); + +if (hook_head) { +struct nf_hook_state state; + +nf_hook_state_init (&state, hook, pf, in, out, sk, net, okfn); + +nf_hook_slow_list (head, &state, hook_head); + } +rcu_read_unlock (); }/* Call setsockopt() */
net/netfilter/core.c +20 -0
@@ -536,6 +536,26 @@ int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state, }EXPORT_SYMBOL (nf_hook_slow); +void nf_hook_slow_list (struct list_head *head,struct nf_hook_state *state, +const struct nf_hook_entries *e) +{ +struct sk_buff *skb, *next; +struct list_head sublist; +int ret; + +INIT_LIST_HEAD (&sublist); + +list_for_each_entry_safe (skb, next, head, list) { +skb_list_del_init (skb); + ret =nf_hook_slow (skb, state, e,0 ); +if (ret ==1 ) +list_add_tail (&skb->list, &sublist); + } +/* Put passed packets back on main list */ +list_splice (&sublist, head); +} +EXPORT_SYMBOL (nf_hook_slow_list); +/* This needs to be compiled in any case to avoid dependencies between the * nfnetlink_queue code and nf_conntrack. */
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 18/31 netfilter: nft_tproxy: Fix typo in IPv6 module description.
In reply to Pablo Neira AyusoFrom: Norman Rasmussen <[email protected]>
--- net/ipv6/netfilter/nf_tproxy_ipv6.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/netfilter/nf_tproxy_ipv6.c +1 -1
@@ -150,4 +150,4 @@ EXPORT_SYMBOL_GPL(nf_tproxy_get_sock_v6);MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Balazs Scheidler, Krisztian Kovacs" ); -MODULE_DESCRIPTION ("Netfilter IPv4 transparent proxy support" ); +MODULE_DESCRIPTION ("Netfilter IPv6 transparent proxy support" );
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 19/31 netfilter: nf_flow_table: move priority to struct nf_flowtable
In reply to Pablo Neira AyusoHardware offload needs access to the priority field, store this field in the nf_flowtable object.
--- include/net/netfilter/nf_flow_table.h | 1 + include/net/netfilter/nf_tables.h | 2 -- net/netfilter/nf_tables_api.c | 10 +++++----- 3 files changed, 6 insertions(+), 7 deletions(-)
include/net/netfilter/nf_flow_table.h +1 -0
@@ -24,6 +24,7 @@ struct nf_flowtable_type {struct nf_flowtable {struct list_head list;struct rhashtable rhashtable; +int priority;const struct nf_flowtable_type *type;struct delayed_work gc_work; };
include/net/netfilter/nf_tables.h +0 -2
@@ -1155,7 +1155,6 @@ void nft_unregister_obj(struct nft_object_type *obj_type);* @table: the table the flow table is contained in * @name: name of this flow table * @hooknum: hook number -* @priority: hook priority * @ops_len: number of hooks in array * @genmask: generation mask * @use: number of references to this flow table
@@ -1169,7 +1168,6 @@ struct nft_flowtable {struct nft_table *table;char *name;int hooknum; -int priority;int ops_len; u32 genmask:2, use:30;
net/netfilter/nf_tables_api.c +5 -5
@@ -5706,10 +5706,10 @@ static int nf_tables_flowtable_parse_hook(const struct nft_ctx *ctx,if (!ops)return -ENOMEM ; - flowtable->hooknum = hooknum; - flowtable->priority = priority; - flowtable->ops = ops; - flowtable->ops_len = n; + flowtable->hooknum = hooknum; + flowtable->data.priority = priority; + flowtable->ops = ops; + flowtable->ops_len = n;for (i =0 ; i < n; i++) { flowtable->ops[i].pf =NFPROTO_NETDEV ;
@@ -5969,7 +5969,7 @@ static int nf_tables_fill_flowtable_info(struct sk_buff *skb, struct net *net,if (!nest) goto nla_put_failure;if (nla_put_be32 (skb,NFTA_FLOWTABLE_HOOK_NUM ,htonl (flowtable->hooknum)) || -nla_put_be32 (skb,NFTA_FLOWTABLE_HOOK_PRIORITY ,htonl (flowtable->priority))) +nla_put_be32 (skb,NFTA_FLOWTABLE_HOOK_PRIORITY ,htonl (flowtable->data.priority))) goto nla_put_failure; nest_devs =nla_nest_start_noflag (skb,NFTA_FLOWTABLE_HOOK_DEVS );
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 20/31 netfilter: nf_tables: dynamically allocate hooks per net_device in flowtables
In reply to Pablo Neira AyusoUse a list of hooks per device instead an array.
--- include/net/netfilter/nf_tables.h | 8 +- net/netfilter/nf_tables_api.c | 253 +++++++++++++++++++++++--------------- 2 files changed, 158 insertions(+), 103 deletions(-)
include/net/netfilter/nf_tables.h +7 -1
@@ -963,6 +963,12 @@ struct nft_stats {struct u64_stats_sync syncp; }; +struct nft_hook { +struct list_head list; +struct nf_hook_ops ops; +struct rcu_head rcu; +}; +/** * struct nft_base_chain - nf_tables base chain *
@@ -1173,7 +1179,7 @@ struct nft_flowtable { use:30 ;u64 handle;/* runtime data below here */ -struct nf_hook_ops *ops____cacheline_aligned ; +struct list_head hook_list____cacheline_aligned ;struct nf_flowtable data; };
net/netfilter/nf_tables_api.c +151 -102
353 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 21/31 netfilter: nf_tables: allow netdevice to be used only once per flowtable
In reply to Pablo Neira AyusoAllow netdevice only once per flowtable, otherwise hit EEXIST.
--- net/netfilter/nf_tables_api.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
net/netfilter/nf_tables_api.c +17 -0
@@ -1538,6 +1538,19 @@ static struct nft_hook *nft_netdev_hook_alloc(struct net *net,return ERR_PTR (err); } +static bool nft_hook_list_find (struct list_head *hook_list, +const struct nft_hook *this) +{ +struct nft_hook *hook; + +list_for_each_entry (hook, hook_list, list) { +if (this->ops.dev == hook->ops.dev) +return true; + } + +return false; +} +static int nf_tables_parse_netdev_hooks (struct net *net,const struct nlattr *attr,struct list_head *hook_list)
@@ -1557,6 +1570,10 @@ static int nf_tables_parse_netdev_hooks(struct net *net, err =PTR_ERR (hook); goto err_hook; } +if (nft_hook_list_find (hook_list, hook)) { + err = -EEXIST ; + goto err_hook; + }list_add_tail (&hook->list, hook_list); n++;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 22/31 netfilter: nf_tables: increase maximum devices number per flowtable
In reply to Pablo Neira AyusoRise the maximum limit of devices per flowtable up to 256. Rename NFT_FLOWTABLE_DEVICE_MAX to NFT_NETDEVICE_MAX in preparation to reuse the netdev hook parser for ingress basechain.
--- include/net/netfilter/nf_tables.h | 2 +- net/netfilter/nf_tables_api.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
include/net/netfilter/nf_tables.h +1 -1
@@ -1152,7 +1152,7 @@ struct nft_object_ops {int nft_register_obj (struct nft_object_type *obj_type);void nft_unregister_obj (struct nft_object_type *obj_type); -#define NFT_FLOWTABLE_DEVICE_MAX 8 +#define NFT_NETDEVICE_MAX 256/** * struct nft_flowtable - nf_tables flow table
net/netfilter/nf_tables_api.c +1 -1
@@ -1577,7 +1577,7 @@ static int nf_tables_parse_netdev_hooks(struct net *net,list_add_tail (&hook->list, hook_list); n++; -if (n ==NFT_FLOWTABLE_DEVICE_MAX ) { +if (n ==NFT_NETDEVICE_MAX ) { err = -EFBIG ; goto err_hook; }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 23/31 netfilter: nf_tables_offload: add nft_flow_block_chain()
In reply to Pablo Neira AyusoAdd nft_flow_block_chain() helper function to reuse this function from netdev event handler.
--- net/netfilter/nf_tables_offload.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
net/netfilter/nf_tables_offload.c +11 -4
@@ -294,6 +294,16 @@ static int nft_indr_block_offload_cmd(struct nft_base_chain *chain,#define FLOW_SETUP_BLOCK TC_SETUP_BLOCK +static int nft_flow_block_chain (struct nft_base_chain *basechain, +struct net_device *dev, +enum flow_block_command cmd) +{ +if (dev->netdev_ops->ndo_setup_tc) +return nft_block_offload_cmd (basechain, dev, cmd); + +return nft_indr_block_offload_cmd (basechain, dev, cmd); +} +static int nft_flow_offload_chain (struct nft_chain *chain,u8 *ppolicy,enum flow_block_command cmd)
@@ -316,10 +326,7 @@ static int nft_flow_offload_chain(struct nft_chain *chain,if (cmd ==FLOW_BLOCK_BIND && policy ==NF_DROP )return -EOPNOTSUPP ; -if (dev->netdev_ops->ndo_setup_tc) -return nft_block_offload_cmd (basechain, dev, cmd); -else -return nft_indr_block_offload_cmd (basechain, dev, cmd); +return nft_flow_block_chain (basechain, dev, cmd); }int nft_flow_rule_offload_commit (struct net *net)
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 24/31 netfilter: nf_tables_offload: Pass callback list to nft_setup_cb_call()
In reply to Pablo Neira AyusoThis allows to reuse nft_setup_cb_call() from the callback unbind path.
--- net/netfilter/nf_tables_offload.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
net/netfilter/nf_tables_offload.c +5 -4
@@ -132,13 +132,13 @@ static void nft_flow_offload_common_init(struct flow_cls_common_offload *common, common->extack = extack; } -static int nft_setup_cb_call (struct nft_base_chain *basechain, -enum tc_setup_type type,void *type_data) +static int nft_setup_cb_call (enum tc_setup_type type,void *type_data, +struct list_head *cb_list) {struct flow_block_cb *block_cb;int err; -list_for_each_entry (block_cb, &basechain->flow_block.cb_list, list) { +list_for_each_entry (block_cb, cb_list, list) { err = block_cb->cb (type, type_data, block_cb->cb_priv);if (err <0 )return err;
@@ -180,7 +180,8 @@ static int nft_flow_offload_rule(struct nft_chain *chain,if (flow) cls_flow.rule = flow->rule; -return nft_setup_cb_call (basechain,TC_SETUP_CLSFLOWER , &cls_flow); +return nft_setup_cb_call (TC_SETUP_CLSFLOWER , &cls_flow, + &basechain->flow_block.cb_list); } static int nft_flow_offload_bind(struct flow_block_offload *bo,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 25/31 netfilter: nf_tables_offload: add nft_flow_cls_offload_setup()
In reply to Pablo Neira AyusoAdd helper function to set up the flow_cls_offload object.
--- net/netfilter/nf_tables_offload.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-)
net/netfilter/nf_tables_offload.c +24 -13
@@ -155,30 +155,41 @@ int nft_chain_offload_priority(struct nft_base_chain *basechain)return 0 ; } +static void nft_flow_cls_offload_setup (struct flow_cls_offload *cls_flow, +const struct nft_base_chain *basechain, +const struct nft_rule *rule, +const struct nft_flow_rule *flow, +enum flow_cls_command command) +{ +struct netlink_ext_ack extack; +__be16 proto =ETH_P_ALL ; + +memset (cls_flow,0 ,sizeof (*cls_flow)); + +if (flow) + proto = flow->proto; + +nft_flow_offload_common_init (&cls_flow->common, proto, + basechain->ops.priority, &extack); + cls_flow->command = command; + cls_flow->cookie = (unsigned long ) rule; +if (flow) + cls_flow->rule = flow->rule; +} +static int nft_flow_offload_rule (struct nft_chain *chain,struct nft_rule *rule,struct nft_flow_rule *flow,enum flow_cls_command command) { -struct flow_cls_offload cls_flow = {}; +struct flow_cls_offload cls_flow;struct nft_base_chain *basechain; -struct netlink_ext_ack extack; -__be16 proto =ETH_P_ALL ;if (!nft_is_base_chain (chain))return -EOPNOTSUPP ; basechain =nft_base_chain (chain); - -if (flow) - proto = flow->proto; - -nft_flow_offload_common_init (&cls_flow.common, proto, - basechain->ops.priority, &extack); - cls_flow.command = command; - cls_flow.cookie = (unsigned long ) rule; -if (flow) - cls_flow.rule = flow->rule; +nft_flow_cls_offload_setup (&cls_flow, basechain, rule, flow, command);return nft_setup_cb_call (TC_SETUP_CLSFLOWER , &cls_flow, &basechain->flow_block.cb_list);
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 26/31 netfilter: nf_tables_offload: remove rules on unregistered device only
In reply to Pablo Neira AyusoAfter unbinding the list of flow_block callbacks, iterate over it to remove the existing rules in the netdevice that has just been unregistered.
--- net/netfilter/nf_tables_offload.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
net/netfilter/nf_tables_offload.c +13 -13
@@ -206,6 +206,16 @@ static int nft_flow_offload_unbind(struct flow_block_offload *bo, struct nft_base_chain *basechain) {struct flow_block_cb *block_cb, *next; +struct flow_cls_offload cls_flow; +struct nft_chain *chain; +struct nft_rule *rule; + + chain = &basechain->chain; +list_for_each_entry (rule, &chain->rules, list) { +nft_flow_cls_offload_setup (&cls_flow, basechain, rule,NULL , +FLOW_CLS_DESTROY ); +nft_setup_cb_call (TC_SETUP_CLSFLOWER , &cls_flow, &bo->cb_list); + }list_for_each_entry_safe (block_cb, next, &bo->cb_list, list) {list_del (&block_cb->list);
@@ -445,18 +455,6 @@ static void nft_indr_block_cb(struct net_device *dev,mutex_unlock (&net->nft.commit_mutex); } -static void nft_offload_chain_clean (struct nft_chain *chain) -{ -struct nft_rule *rule; - -list_for_each_entry (rule, &chain->rules, list) { -nft_flow_offload_rule (chain, rule, -NULL ,FLOW_CLS_DESTROY ); - } - -nft_flow_offload_chain (chain,NULL ,FLOW_BLOCK_UNBIND ); -} -static int nft_offload_netdev_event (struct notifier_block *this,unsigned long event,void *ptr) {
@@ -467,7 +465,9 @@ static int nft_offload_netdev_event(struct notifier_block *this,mutex_lock (&net->nft.commit_mutex); chain =__nft_offload_get_chain (dev);if (chain) -nft_offload_chain_clean (chain); +nft_flow_block_chain (nft_base_chain (chain), dev, +FLOW_BLOCK_UNBIND ); +mutex_unlock (&net->nft.commit_mutex);return NOTIFY_DONE ;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 27/31 netfilter: nf_tables: support for multiple devices per netdev hook
In reply to Pablo Neira AyusoThis patch allows you to register one netdev basechain to multiple devices. This adds a new NFTA_HOOK_DEVS netlink attribute to specify the list of netdevices. Basechains store a list of hooks.
--- include/net/netfilter/nf_tables.h | 4 +- include/uapi/linux/netfilter/nf_tables.h | 2 + net/netfilter/nf_tables_api.c | 296 ++++++++++++++++++++++++------- net/netfilter/nf_tables_offload.c | 44 +++-- net/netfilter/nft_chain_filter.c | 45 +++-- 5 files changed, 293 insertions(+), 98 deletions(-)
include/net/netfilter/nf_tables.h +2 -2
@@ -973,21 +973,21 @@ struct nft_hook {* struct nft_base_chain - nf_tables base chain * * @ops: netfilter hook ops +* @hook_list: list of netfilter hooks (for NFPROTO_NETDEV family) * @type: chain type * @policy: default policy * @stats: per-cpu chain stats * @chain: the chain -* @dev_name: device name that this base chain is attached to (if any) * @flow_block: flow block (for hardware offload) */ struct nft_base_chain {struct nf_hook_ops ops; +struct list_head hook_list;const struct nft_chain_type *type;u8 policy;u8 flags;struct nft_stats __percpu *stats;struct nft_chain chain; -char dev_name[IFNAMSIZ ];struct flow_block flow_block; };
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -144,12 +144,14 @@ enum nft_list_attributes {* @NFTA_HOOK_HOOKNUM: netfilter hook number (NLA_U32) * @NFTA_HOOK_PRIORITY: netfilter hook priority (NLA_U32) * @NFTA_HOOK_DEV: netdevice name (NLA_STRING) +* @NFTA_HOOK_DEVS: list of netdevices (NLA_NESTED) */ enum nft_hook_attributes {NFTA_HOOK_UNSPEC ,NFTA_HOOK_HOOKNUM ,NFTA_HOOK_PRIORITY ,NFTA_HOOK_DEV , +NFTA_HOOK_DEVS , __NFTA_HOOK_MAX };#define NFTA_HOOK_MAX (__NFTA_HOOK_MAX - 1)
net/netfilter/nf_tables_api.c +232 -64
433 lines not on this page · raw message
net/netfilter/nf_tables_offload.c +31 -13
83 lines not on this page · raw message
net/netfilter/nft_chain_filter.c +26 -19
54 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 28/31 netfilter: ecache: don't look for ecache extension on dying/unconfirmed conntracks
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
syzbot reported following splat:
BUG: KASAN: use-after-free in __nf_ct_ext_exist include/net/netfilter/nf_conntrack_extend.h:53 [inline] BUG: KASAN: use-after-free in nf_ct_deliver_cached_events+0x5c3/0x6d0 net/netfilter/nf_conntrack_ecache.c:205 nf_conntrack_confirm include/net/netfilter/nf_conntrack_core.h:65 [inline] nf_confirm+0x3d8/0x4d0 net/netfilter/nf_conntrack_proto.c:154
[..]
While there is no reproducer yet, the syzbot report contains one interesting bit of information:
Freed by task 27585: [..] kfree+0x10a/0x2c0 mm/slab.c:3757 nf_ct_ext_destroy+0x2ab/0x2e0 net/netfilter/nf_conntrack_extend.c:38 nf_conntrack_free+0x8f/0xe0 net/netfilter/nf_conntrack_core.c:1418 destroy_conntrack+0x1a2/0x270 net/netfilter/nf_conntrack_core.c:626 nf_conntrack_put include/linux/netfilter/nf_conntrack_common.h:31 [inline] nf_ct_resolve_clash net/netfilter/nf_conntrack_core.c:915 [inline] ^^^^^^^^^^^^^^^^^^^ __nf_conntrack_confirm+0x21ca/0x2830 net/netfilter/nf_conntrack_core.c:1038 nf_conntrack_confirm include/net/netfilter/nf_conntrack_core.h:63 [inline] nf_confirm+0x3e7/0x4d0 net/netfilter/nf_conntrack_proto.c:154
This is whats happening:
1. a conntrack entry is about to be confirmed (added to hash table).
2. a clash with existing entry is detected.
3. nf_ct_resolve_clash() puts skb->nfct (the "losing" entry).
4. this entry now has a refcount of 0 and is freed to SLAB_TYPESAFE_BY_RCU kmem cache.
skb->nfct has been replaced by the one found in the hash. Problem is that nf_conntrack_confirm() uses the old ct:
static inline int nf_conntrack_confirm(struct sk_buff *skb) {
struct nf_conn *ct = (struct nf_conn *)skb_nfct(skb); int ret = NF_ACCEPT;
if (ct) {
if (!nf_ct_is_confirmed(ct))
ret = __nf_conntrack_confirm(skb);
if (likely(ret == NF_ACCEPT))
nf_ct_deliver_cached_events(ct); /* This ct has refcount 0! */ }
return ret;
}
As of "netfilter: conntrack: free extension area immediately", we can't access conntrack extensions in this case.
To fix this, make sure we check the dying bit presence before attempting to get the eache extension.
--- net/netfilter/nf_conntrack_ecache.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/netfilter/nf_conntrack_ecache.c +3 -3
@@ -202,15 +202,15 @@ void nf_ct_deliver_cached_events(struct nf_conn *ct)if (notify ==NULL ) goto out_unlock; +if (!nf_ct_is_confirmed (ct) ||nf_ct_is_dying (ct)) + goto out_unlock; + e =nf_ct_ecache_find (ct);if (e ==NULL ) goto out_unlock; events =xchg (&e->cache,0 ); -if (!nf_ct_is_confirmed (ct) ||nf_ct_is_dying (ct)) - goto out_unlock; -/* We make a copy of the missed event cache without taking * the lock, thus we may send missed events twice. However, * this does not harm and it happens very rarely. */
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 29/31 netfilter: nf_tables_offload: add nft_chain_offload_cmd()
In reply to Pablo Neira AyusoThis patch adds the nft_chain_offload_cmd() helper function.
--- net/netfilter/nf_tables_offload.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
net/netfilter/nf_tables_offload.c +15 -5
@@ -316,6 +316,20 @@ static int nft_indr_block_offload_cmd(struct nft_base_chain *chain,#define FLOW_SETUP_BLOCK TC_SETUP_BLOCK +static int nft_chain_offload_cmd (struct nft_base_chain *basechain, +struct net_device *dev, +enum flow_block_command cmd) +{ +int err; + +if (dev->netdev_ops->ndo_setup_tc) + err =nft_block_offload_cmd (basechain, dev, cmd); +else + err =nft_indr_block_offload_cmd (basechain, dev, cmd); + +return err; +} +static int nft_flow_block_chain (struct nft_base_chain *basechain,const struct net_device *this_dev,enum flow_block_command cmd)
@@ -329,11 +343,7 @@ static int nft_flow_block_chain(struct nft_base_chain *basechain,if (this_dev && this_dev != dev)continue ; -if (dev->netdev_ops->ndo_setup_tc) - err =nft_block_offload_cmd (basechain, dev, cmd); -else - err =nft_indr_block_offload_cmd (basechain, dev, cmd); - + err =nft_chain_offload_cmd (basechain, dev, cmd);if (err <0 )return err; }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 30/31 netfilter: nf_tables_offload: add nft_flow_block_offload_init()
In reply to Pablo Neira AyusoThis patch adds the nft_flow_block_offload_init() helper function to initialize the flow_block_offload object.
--- net/netfilter/nf_tables_offload.c | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-)
net/netfilter/nf_tables_offload.c +21 -21
@@ -246,20 +246,30 @@ static int nft_block_setup(struct nft_base_chain *basechain,return err; } +static void nft_flow_block_offload_init (struct flow_block_offload *bo, +struct net *net, +enum flow_block_command cmd, +struct nft_base_chain *basechain, +struct netlink_ext_ack *extack) +{ +memset (bo,0 ,sizeof (*bo)); + bo->net = net; + bo->block = &basechain->flow_block; + bo->command = cmd; + bo->binder_type =FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS ; + bo->extack = extack; +INIT_LIST_HEAD (&bo->cb_list); +} +static int nft_block_offload_cmd (struct nft_base_chain *chain,struct net_device *dev,enum flow_block_command cmd) {struct netlink_ext_ack extack = {}; -struct flow_block_offload bo = {}; +struct flow_block_offload bo;int err; - bo.net =dev_net (dev); - bo.block = &chain->flow_block; - bo.command = cmd; - bo.binder_type =FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS ; - bo.extack = &extack; -INIT_LIST_HEAD (&bo.cb_list); +nft_flow_block_offload_init (&bo,dev_net (dev), cmd, chain, &extack); err = dev->netdev_ops->ndo_setup_tc (dev,TC_SETUP_BLOCK , &bo);if (err <0 )
@@ -275,17 +285,12 @@ static void nft_indr_block_ing_cmd(struct net_device *dev, enum flow_block_command cmd) {struct netlink_ext_ack extack = {}; -struct flow_block_offload bo = {}; +struct flow_block_offload bo;if (!chain)return ; - bo.net =dev_net (dev); - bo.block = &chain->flow_block; - bo.command = cmd; - bo.binder_type =FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS ; - bo.extack = &extack; -INIT_LIST_HEAD (&bo.cb_list); +nft_flow_block_offload_init (&bo,dev_net (dev), cmd, chain, &extack);cb (dev, cb_priv,TC_SETUP_BLOCK , &bo);
@@ -296,15 +301,10 @@ static int nft_indr_block_offload_cmd(struct nft_base_chain *chain, struct net_device *dev, enum flow_block_command cmd) { -struct flow_block_offload bo = {};struct netlink_ext_ack extack = {}; +struct flow_block_offload bo; - bo.net =dev_net (dev); - bo.block = &chain->flow_block; - bo.command = cmd; - bo.binder_type =FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS ; - bo.extack = &extack; -INIT_LIST_HEAD (&bo.cb_list); +nft_flow_block_offload_init (&bo,dev_net (dev), cmd, chain, &extack);flow_indr_block_call (dev, &bo, cmd);
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 31/31 netfilter: nf_tables_offload: unbind if multi-device binding fails
In reply to Pablo Neira Ayusonft_flow_block_chain() needs to unbind in case of error when performing the multi-device binding.
--- net/netfilter/nf_tables_offload.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_offload.c +17 -2
@@ -336,7 +336,7 @@ static int nft_flow_block_chain(struct nft_base_chain *basechain, {struct net_device *dev;struct nft_hook *hook; -int err; +int err, i =0 ;list_for_each_entry (hook, &basechain->hook_list, list) { dev = hook->ops.dev;
@@ -344,11 +344,26 @@ static int nft_flow_block_chain(struct nft_base_chain *basechain,continue ; err =nft_chain_offload_cmd (basechain, dev, cmd); -if (err <0 ) +if (err <0 && cmd ==FLOW_BLOCK_BIND ) { +if (!this_dev) + goto err_flow_block; +return err; + } + i++; }return 0 ; + +err_flow_block: +list_for_each_entry (hook, &basechain->hook_list, list) { +if (i-- <=0 ) +break ; + + dev = hook->ops.dev; +nft_chain_offload_cmd (basechain, dev,FLOW_BLOCK_UNBIND ); + } +return err; } static int nft_flow_offload_chain(struct nft_chain *chain, u8 *ppolicy,
Signature · 1 line
2.11.0
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Sat, 26 Oct 2019 13:47:02 +0200
Quoted 2 lines
The following patchset contains Netfilter/IPVS updates for net-next, more specifically:
...
Quoted 3 lines
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Pulled, thanks Pablo.