History

netfilter: conntrack: move code to linux/nf_conntrack_common.h.

Move some `struct nf_conntrack` code from linux/skbuff.h to linux/nf_conntrack_common.h. Together with a couple of helpers for getting and setting skb->_nfct, it allows us to remove CONFIG_NF_CONNTRACK checks from net/netfilter/nf_conntrack.h.

Jeremy Sowden committed 7 years ago

Commit 261db6c1 parent f1815654 files · +40 −37Browse files

Unified · Split

4 files
  1. include/linux/netfilter/nf_conntrack_common.h +20 −0
  2. include/linux/skbuff.h +15 −17
  3. include/net/netfilter/nf_conntrack.h +5 −19
  4. net/netfilter/nf_conntrack_standalone.c +0 −1
include/linux/netfilter/nf_conntrack_common.h+20−0
@@ -2,6 +2,7 @@ · 1 unmodified line
22 #ifndef _NF_CONNTRACK_COMMON_H
33 #define _NF_CONNTRACK_COMMON_H
44
5+#include <linux/atomic.h>
56 #include <uapi/linux/netfilter/nf_conntrack_common.h>
67
78 struct ip_conntrack_stat {
@@ -19,4 +20,23 @@ struct ip_conntrack_stat { · 11 unmodified lines
1920 unsigned int search_restart;
2021 };
2122
23+#define NFCT_INFOMASK 7UL
24+#define NFCT_PTRMASK ~(NFCT_INFOMASK)
25+
26+struct nf_conntrack {
27+ atomic_t use;
28+};
29+
30+void nf_conntrack_destroy(struct nf_conntrack *nfct);
31+static inline void nf_conntrack_put(struct nf_conntrack *nfct)
32+{
33+ if (nfct && atomic_dec_and_test(&nfct->use))
34+ nf_conntrack_destroy(nfct);
35+}
36+static inline void nf_conntrack_get(struct nf_conntrack *nfct)
37+{
38+ if (nfct)
39+ atomic_inc(&nfct->use);
40+}
41+
2242 #endif /* _NF_CONNTRACK_COMMON_H */
include/linux/skbuff.h+15−17
@@ -37,6 +37,9 @@ · 36 unmodified lines
3737 #include <linux/in6.h>
3838 #include <linux/if_packet.h>
3939 #include <net/flow.h>
40+#if IS_ENABLED(CONFIG_NF_CONNTRACK)
41+#include <linux/netfilter/nf_conntrack_common.h>
42+#endif
4043
4144 /* The interface for checksum offload between the stack and networking drivers
4245 * is as follows...
@@ -244,12 +247,6 @@ struct bpf_prog; · 201 unmodified lines
244247 union bpf_attr;
245248 struct skb_ext;
246249
247−#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
248−struct nf_conntrack {
249− atomic_t use;
250−};
251−#endif
252−
253250 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
254251 struct nf_bridge_info {
255252 enum {
@@ -914,7 +911,6 @@ static inline bool skb_pfmemalloc(const struct sk_buff *skb) · 658 unmodified lines
914911 #define SKB_DST_NOREF 1UL
915912 #define SKB_DST_PTRMASK ~(SKB_DST_NOREF)
916913
917−#define SKB_NFCT_PTRMASK ~(7UL)
918914 /**
919915 * skb_dst - returns skb dst_entry
920916 * @skb: buffer
@@ -4040,25 +4036,27 @@ static inline void skb_remcsum_process(struct sk_buff *skb, void *ptr, · 3119 unmodified lines
40404036 static inline struct nf_conntrack *skb_nfct(const struct sk_buff *skb)
40414037 {
40424038 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
4043− return (void *)(skb->_nfct & SKB_NFCT_PTRMASK);
4039+ return (void *)(skb->_nfct & NFCT_PTRMASK);
40444040 #else
40454041 return NULL;
40464042 #endif
40474043 }
40484044
4049−#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
4050−void nf_conntrack_destroy(struct nf_conntrack *nfct);
4051−static inline void nf_conntrack_put(struct nf_conntrack *nfct)
4045+static inline unsigned long skb_get_nfct(const struct sk_buff *skb)
40524046 {
4053− if (nfct && atomic_dec_and_test(&nfct->use))
4054− nf_conntrack_destroy(nfct);
4047+#if IS_ENABLED(CONFIG_NF_CONNTRACK)
4048+ return skb->_nfct;
4049+#else
4050+ return 0UL;
4051+#endif
40554052 }
4056−static inline void nf_conntrack_get(struct nf_conntrack *nfct)
4053+
4054+static inline void skb_set_nfct(struct sk_buff *skb, unsigned long nfct)
40574055 {
4058− if (nfct)
4059− atomic_inc(&nfct->use);
4060−}
4056+#if IS_ENABLED(CONFIG_NF_CONNTRACK)
4057+ skb->_nfct = nfct;
40614058 #endif
4059+}
40624060
40634061 #ifdef CONFIG_SKB_EXTENSIONS
40644062 enum skb_ext_id {
include/net/netfilter/nf_conntrack.h+5−19
@@ -13,12 +13,10 @@ · 12 unmodified lines
1313 #ifndef _NF_CONNTRACK_H
1414 #define _NF_CONNTRACK_H
1515
16−#include <linux/netfilter/nf_conntrack_common.h>
17−
1816 #include <linux/bitops.h>
1917 #include <linux/compiler.h>
20−#include <linux/atomic.h>
2118
19+#include <linux/netfilter/nf_conntrack_common.h>
2220 #include <linux/netfilter/nf_conntrack_tcp.h>
2321 #include <linux/netfilter/nf_conntrack_dccp.h>
2422 #include <linux/netfilter/nf_conntrack_sctp.h>
@@ -58,7 +56,6 @@ struct nf_conntrack_net { · 33 unmodified lines
5856 #include <net/netfilter/ipv6/nf_conntrack_ipv6.h>
5957
6058 struct nf_conn {
61−#if IS_ENABLED(CONFIG_NF_CONNTRACK)
6259 /* Usage count in here is 1 for hash table, 1 per skb,
6360 * plus 1 for any connection(s) we are `master' for
6461 *
@@ -68,7 +65,6 @@ struct nf_conn { · 3 unmodified lines
6865 * beware nf_ct_get() is different and don't inc refcnt.
6966 */
7067 struct nf_conntrack ct_general;
71−#endif
7268
7369 spinlock_t lock;
7470 /* jiffies32 when this ct is considered dead */
@@ -149,18 +145,14 @@ void nf_conntrack_alter_reply(struct nf_conn *ct, · 74 unmodified lines
149145 int nf_conntrack_tuple_taken(const struct nf_conntrack_tuple *tuple,
150146 const struct nf_conn *ignored_conntrack);
151147
152−#if IS_ENABLED(CONFIG_NF_CONNTRACK)
153−
154−#define NFCT_INFOMASK 7UL
155−#define NFCT_PTRMASK ~(NFCT_INFOMASK)
156−
157148 /* Return conntrack_info and tuple hash for given skb. */
158149 static inline struct nf_conn *
159150 nf_ct_get(const struct sk_buff *skb, enum ip_conntrack_info *ctinfo)
160151 {
161− *ctinfo = skb->_nfct & NFCT_INFOMASK;
152+ unsigned long nfct = skb_get_nfct(skb);
162153
163− return (struct nf_conn *)(skb->_nfct & NFCT_PTRMASK);
154+ *ctinfo = nfct & NFCT_INFOMASK;
155+ return (struct nf_conn *)(nfct & NFCT_PTRMASK);
164156 }
165157
166158 /* decrement reference count on a conntrack */
@@ -170,8 +162,6 @@ static inline void nf_ct_put(struct nf_conn *ct) · 3 unmodified lines
170162 nf_conntrack_put(&ct->ct_general);
171163 }
172164
173−#endif
174−
175165 /* Protocol module loading */
176166 int nf_ct_l3proto_try_module_get(unsigned short l3proto);
177167 void nf_ct_l3proto_module_put(unsigned short l3proto);
@@ -323,16 +313,12 @@ void nf_ct_tmpl_free(struct nf_conn *tmpl); · 145 unmodified lines
323313
324314 u32 nf_ct_get_id(const struct nf_conn *ct);
325315
326−#if IS_ENABLED(CONFIG_NF_CONNTRACK)
327−
328316 static inline void
329317 nf_ct_set(struct sk_buff *skb, struct nf_conn *ct, enum ip_conntrack_info info)
330318 {
331− skb->_nfct = (unsigned long)ct | info;
319+ skb_set_nfct(skb, (unsigned long)ct | info);
332320 }
333321
334−#endif
335−
336322 #define NF_CT_STAT_INC(net, count) __this_cpu_inc((net)->ct.stat->count)
337323 #define NF_CT_STAT_INC_ATOMIC(net, count) this_cpu_inc((net)->ct.stat->count)
338324 #define NF_CT_STAT_ADD_ATOMIC(net, count, v) this_cpu_add((net)->ct.stat->count, (v))
net/netfilter/nf_conntrack_standalone.c+0−1
@@ -1167,7 +1167,6 @@ static int __init nf_conntrack_standalone_init(void) · 1166 unmodified lines
11671167 if (ret < 0)
11681168 goto out_start;
11691169
1170− BUILD_BUG_ON(SKB_NFCT_PTRMASK != NFCT_PTRMASK);
11711170 BUILD_BUG_ON(NFCT_INFOMASK <= IP_CT_NUMBER);
11721171
11731172 #ifdef CONFIG_SYSCTL

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t