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

Showing the changes to include/linux (2 of 4 files). Show all

Unified · Split

2 files
  1. include/linux/netfilter/nf_conntrack_common.h +20 −0
  2. include/linux/skbuff.h +15 −17
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 {

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