ipset: remove static inline functions
Subsystems (2)
cover ipset: remove static inline functions
In his feedback on an earlier patch series [0], Pablo suggested reducing the number of ipset static inline functions.
0 - https://lore.kernel.org/netfilter-devel/20190808112355.w3ax3twuf6b7pwc7@salvia/
This series:
* removes inline from static functions in .c files;
* moves some static functions out of headers and removes inline from them if they are only called from one .c file,
* moves some static functions out of headers, removes inline from them and makes them extern if they are too big.
The changes reduced the size of the ipset modules by c. 13kB, when compiled with GCC 9 on x86-64.
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.
include/linux/netfilter/ipset/ip_set.h | 196 +--------------- include/linux/netfilter/ipset/ip_set_bitmap.h | 14 -- .../linux/netfilter/ipset/ip_set_getport.h | 3 - 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 +- 23 files changed, 376 insertions(+), 372 deletions(-)
Signature · 1 line
2.23.0
PATCH 1/7 netfilter: ipset: add a coding-style fix to ip_set_ext_destroy.
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.23.0
PATCH 2/7 netfilter: ipset: remove inline from static functions in .c files.
In reply to Jeremy SowdenThe 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.23.0
PATCH 3/7 netfilter: ipset: move ip_set_comment functions from ip_set.h to ip_set_core.c.
In reply to Jeremy SowdenMost 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.23.0
PATCH 4/7 netfilter: ipset: move functions to ip_set_core.c.
In reply to Jeremy SowdenSeveral 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,86 +508,9 @@ 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)
@@ -598,31 +521,6 @@ ip_set_init_counter(struct ip_set_counter *counter,atomic64_set (&(counter)->packets, (long long )(ext->packets)); } -static inline void -ip_set_get_skbinfo (struct ip_set_skbinfo *skbinfo, -const struct ip_set_ext *ext, -struct ip_set_ext *mext,u32 flags) -{ - mext->skbinfo = *skbinfo; -} - -static inline bool -ip_set_put_skbinfo (struct sk_buff *skb,const struct ip_set_skbinfo *skbinfo) -{ -/* Send nonzero parameters only */ -return ((skbinfo->skbmark || skbinfo->skbmarkmask) && -nla_put_net64 (skb,IPSET_ATTR_SKBMARK , -cpu_to_be64 ((u64 )skbinfo->skbmark <<32 | - skbinfo->skbmarkmask), -IPSET_ATTR_PAD )) || - (skbinfo->skbprio && -nla_put_net32 (skb,IPSET_ATTR_SKBPRIO , -cpu_to_be32 (skbinfo->skbprio))) || - (skbinfo->skbqueue && -nla_put_net16 (skb,IPSET_ATTR_SKBQUEUE , -cpu_to_be16 (skbinfo->skbqueue))); -} -static inline void ip_set_init_skbinfo (struct ip_set_skbinfo *skbinfo,const struct ip_set_ext *ext)
net/netfilter/ipset/ip_set_core.c +102 -0
120 lines not on this page · raw message
Signature · 1 line
2.23.0
PATCH 5/7 netfilter: ipset: make ip_set_put_flags extern.
In reply to Jeremy Sowdenip_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.23.0
PATCH 6/7 netfilter: ipset: move function to ip_set_bitmap_ip.c.
In reply to Jeremy SowdenOne 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.23.0
PATCH 7/7 netfilter: ipset: move ip_set_get_ip_port() to ip_set_bitmap_port.c.
In reply to Jeremy Sowdenip_set_get_ip_port() is only used in ip_set_bitmap_port.c. Move it there and make it static.
--- .../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.23.0
Hi Jeremy, Pablo,
Quoted 7 lines · Jeremy Sowden
In his feedback on an earlier patch series [0], Pablo suggested reducing the number of ipset static inline functions.
0 - https://lore.kernel.org/netfilter-devel/20190808112355.w3ax3twuf6b7pwc7@salvia/
This series:
Quoted 8 lines
* removes inline from static functions in .c files;
* moves some static functions out of headers and removes inline from them if they are only called from one .c file,
* moves some static functions out of headers, removes inline from them and makes them extern if they are too big.The changes reduced the size of the ipset modules by c. 13kB, when compiled with GCC 9 on x86-64.
I have reviewed all of the patches and they are all right. Pablo, could you queue them for nf-next? I applied the patches in the ipset git tree.
Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics
H-1525 Budapest 114, POB. 49, Hungary
Quoted 17 lines · Kadlecsik József
Hi Jeremy, Pablo,
Quoted 13 lines · Jeremy Sowden
In his feedback on an earlier patch series [0], Pablo suggested reducing the number of ipset static inline functions.
0 - https://lore.kernel.org/netfilter-devel/20190808112355.w3ax3twuf6b7pwc7@salvia/
This series:
* removes inline from static functions in .c files;
* moves some static functions out of headers and removes inline from them if they are only called from one .c file,
* moves some static functions out of headers, removes inline from them and makes them extern if they are too big.
Quoted 5 lines
Quoted 2 lines
The changes reduced the size of the ipset modules by c. 13kB, when compiled with GCC 9 on x86-64.
I have reviewed all of the patches and they are all right. Pablo, could you queue them for nf-next? I applied the patches in the ipset git tree.
Sure.
Quoted 1 line
Acked-by Jozsef Kadlecsik <[email protected]>
Applied, thanks a lot Jozsef.