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