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.
Showing the changes to include/linux (2 of 4 files). Show all
Unified · Split
| @@ -2,6 +2,7 @@ · 1 unmodified line | ||
| 2 | 2 | #ifndef _NF_CONNTRACK_COMMON_H |
| 3 | 3 | #define _NF_CONNTRACK_COMMON_H |
| 4 | 4 | |
| 5 | +#include <linux/atomic.h> | |
| 5 | 6 | #include <uapi/linux/netfilter/nf_conntrack_common.h> |
| 6 | 7 | |
| 7 | 8 | struct ip_conntrack_stat { |
| @@ -19,4 +20,23 @@ struct ip_conntrack_stat { · 11 unmodified lines | ||
| 19 | 20 | unsigned int search_restart; |
| 20 | 21 | }; |
| 21 | 22 | |
| 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 | + | |
| 22 | 42 | #endif /* _NF_CONNTRACK_COMMON_H */ |
| @@ -37,6 +37,9 @@ · 36 unmodified lines | ||
| 37 | 37 | #include <linux/in6.h> |
| 38 | 38 | #include <linux/if_packet.h> |
| 39 | 39 | #include <net/flow.h> |
| 40 | +#if IS_ENABLED(CONFIG_NF_CONNTRACK) | |
| 41 | +#include <linux/netfilter/nf_conntrack_common.h> | |
| 42 | +#endif | |
| 40 | 43 | |
| 41 | 44 | /* The interface for checksum offload between the stack and networking drivers |
| 42 | 45 | * is as follows... |
| @@ -244,12 +247,6 @@ struct bpf_prog; · 201 unmodified lines | ||
| 244 | 247 | union bpf_attr; |
| 245 | 248 | struct skb_ext; |
| 246 | 249 | |
| 247 | −#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) | |
| 248 | −struct nf_conntrack { | |
| 249 | − atomic_t use; | |
| 250 | −}; | |
| 251 | −#endif | |
| 252 | − | |
| 253 | 250 | #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) |
| 254 | 251 | struct nf_bridge_info { |
| 255 | 252 | enum { |
| @@ -914,7 +911,6 @@ static inline bool skb_pfmemalloc(const struct sk_buff *skb) · 658 unmodified lines | ||
| 914 | 911 | #define SKB_DST_NOREF 1UL |
| 915 | 912 | #define SKB_DST_PTRMASK ~(SKB_DST_NOREF) |
| 916 | 913 | |
| 917 | −#define SKB_NFCT_PTRMASK ~(7UL) | |
| 918 | 914 | /** |
| 919 | 915 | * skb_dst - returns skb dst_entry |
| 920 | 916 | * @skb: buffer |
| @@ -4040,25 +4036,27 @@ static inline void skb_remcsum_process(struct sk_buff *skb, void *ptr, · 3119 unmodified lines | ||
| 4040 | 4036 | static inline struct nf_conntrack *skb_nfct(const struct sk_buff *skb) |
| 4041 | 4037 | { |
| 4042 | 4038 | #if IS_ENABLED(CONFIG_NF_CONNTRACK) |
| 4043 | − return (void *)(skb->_nfct & SKB_NFCT_PTRMASK); | |
| 4039 | + return (void *)(skb->_nfct & NFCT_PTRMASK); | |
| 4044 | 4040 | #else |
| 4045 | 4041 | return NULL; |
| 4046 | 4042 | #endif |
| 4047 | 4043 | } |
| 4048 | 4044 | |
| 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) | |
| 4052 | 4046 | { |
| 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 | |
| 4055 | 4052 | } |
| 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) | |
| 4057 | 4055 | { |
| 4058 | − if (nfct) | |
| 4059 | − atomic_inc(&nfct->use); | |
| 4060 | −} | |
| 4056 | +#if IS_ENABLED(CONFIG_NF_CONNTRACK) | |
| 4057 | + skb->_nfct = nfct; | |
| 4061 | 4058 | #endif |
| 4059 | +} | |
| 4062 | 4060 | |
| 4063 | 4061 | #ifdef CONFIG_SKB_EXTENSIONS |
| 4064 | 4062 | enum skb_ext_id { |