Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netfilter: nf_conntrack_extend: introduce __nf_ct_ext_exist()

some users of nf_ct_ext_exist() know ct->ext isn't NULL. For these users, the
check for ct->ext isn't necessary, the function __nf_ct_ext_exist() can be
used instead.

the type of the return value of nf_ct_ext_exist() is changed to bool.

Signed-off-by: Changli Gao <xiaosuo@gmail.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>

authored by

Changli Gao and committed by
Patrick McHardy
ee92d378 24b36f01

+19 -12
+7 -2
include/net/netfilter/nf_conntrack_extend.h
··· 28 28 char data[0]; 29 29 }; 30 30 31 - static inline int nf_ct_ext_exist(const struct nf_conn *ct, u8 id) 31 + static inline bool __nf_ct_ext_exist(const struct nf_ct_ext *ext, u8 id) 32 32 { 33 - return (ct->ext && ct->ext->offset[id]); 33 + return !!ext->offset[id]; 34 + } 35 + 36 + static inline bool nf_ct_ext_exist(const struct nf_conn *ct, u8 id) 37 + { 38 + return (ct->ext && __nf_ct_ext_exist(ct->ext, id)); 34 39 } 35 40 36 41 static inline void *__nf_ct_ext_find(const struct nf_conn *ct, u8 id)
+12 -10
net/netfilter/nf_conntrack_extend.c
··· 23 23 { 24 24 unsigned int i; 25 25 struct nf_ct_ext_type *t; 26 + struct nf_ct_ext *ext = ct->ext; 26 27 27 28 for (i = 0; i < NF_CT_EXT_NUM; i++) { 28 - if (!nf_ct_ext_exist(ct, i)) 29 + if (!__nf_ct_ext_exist(ext, i)) 29 30 continue; 30 31 31 32 rcu_read_lock(); ··· 74 73 75 74 void *__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp) 76 75 { 77 - struct nf_ct_ext *new; 76 + struct nf_ct_ext *old, *new; 78 77 int i, newlen, newoff; 79 78 struct nf_ct_ext_type *t; 80 79 81 80 /* Conntrack must not be confirmed to avoid races on reallocation. */ 82 81 NF_CT_ASSERT(!nf_ct_is_confirmed(ct)); 83 82 84 - if (!ct->ext) 83 + old = ct->ext; 84 + if (!old) 85 85 return nf_ct_ext_create(&ct->ext, id, gfp); 86 86 87 - if (nf_ct_ext_exist(ct, id)) 87 + if (__nf_ct_ext_exist(old, id)) 88 88 return NULL; 89 89 90 90 rcu_read_lock(); 91 91 t = rcu_dereference(nf_ct_ext_types[id]); 92 92 BUG_ON(t == NULL); 93 93 94 - newoff = ALIGN(ct->ext->len, t->align); 94 + newoff = ALIGN(old->len, t->align); 95 95 newlen = newoff + t->len; 96 96 rcu_read_unlock(); 97 97 98 - new = __krealloc(ct->ext, newlen, gfp); 98 + new = __krealloc(old, newlen, gfp); 99 99 if (!new) 100 100 return NULL; 101 101 102 - if (new != ct->ext) { 102 + if (new != old) { 103 103 for (i = 0; i < NF_CT_EXT_NUM; i++) { 104 - if (!nf_ct_ext_exist(ct, i)) 104 + if (!__nf_ct_ext_exist(old, i)) 105 105 continue; 106 106 107 107 rcu_read_lock(); 108 108 t = rcu_dereference(nf_ct_ext_types[i]); 109 109 if (t && t->move) 110 110 t->move((void *)new + new->offset[i], 111 - (void *)ct->ext + ct->ext->offset[i]); 111 + (void *)old + old->offset[i]); 112 112 rcu_read_unlock(); 113 113 } 114 - call_rcu(&ct->ext->rcu, __nf_ct_ext_free_rcu); 114 + call_rcu(&old->rcu, __nf_ct_ext_free_rcu); 115 115 ct->ext = new; 116 116 } 117 117