Skip to content

Commit 1c984f8

Browse files
committed
netfilter: Add socket pointer to nf_hook_state.
It is currently always set to NULL, but nf_queue is adjusted to be prepared for it being set to a real socket by taking and releasing a reference to that socket when necessary. Signed-off-by: David S. Miller <[email protected]>
1 parent 107a9f4 commit 1c984f8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

include/linux/netfilter.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,15 @@ struct sk_buff;
4545

4646
struct nf_hook_ops;
4747

48+
struct sock;
49+
4850
struct nf_hook_state {
4951
unsigned int hook;
5052
int thresh;
5153
u_int8_t pf;
5254
struct net_device *in;
5355
struct net_device *out;
56+
struct sock *sk;
5457
int (*okfn)(struct sk_buff *);
5558
};
5659

@@ -59,13 +62,15 @@ static inline void nf_hook_state_init(struct nf_hook_state *p,
5962
int thresh, u_int8_t pf,
6063
struct net_device *indev,
6164
struct net_device *outdev,
65+
struct sock *sk,
6266
int (*okfn)(struct sk_buff *))
6367
{
6468
p->hook = hook;
6569
p->thresh = thresh;
6670
p->pf = pf;
6771
p->in = indev;
6872
p->out = outdev;
73+
p->sk = sk;
6974
p->okfn = okfn;
7075
}
7176

@@ -160,7 +165,7 @@ static inline int nf_hook_thresh(u_int8_t pf, unsigned int hook,
160165
struct nf_hook_state state;
161166

162167
nf_hook_state_init(&state, hook, thresh, pf,
163-
indev, outdev, okfn);
168+
indev, outdev, NULL, okfn);
164169
return nf_hook_slow(skb, &state);
165170
}
166171
return 1;

net/netfilter/nf_queue.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ void nf_queue_entry_release_refs(struct nf_queue_entry *entry)
5454
dev_put(state->in);
5555
if (state->out)
5656
dev_put(state->out);
57+
if (state->sk)
58+
sock_put(state->sk);
5759
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
5860
if (entry->skb->nf_bridge) {
5961
struct nf_bridge_info *nf_bridge = entry->skb->nf_bridge;
@@ -81,6 +83,8 @@ bool nf_queue_entry_get_refs(struct nf_queue_entry *entry)
8183
dev_hold(state->in);
8284
if (state->out)
8385
dev_hold(state->out);
86+
if (state->sk)
87+
sock_hold(state->sk);
8488
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
8589
if (entry->skb->nf_bridge) {
8690
struct nf_bridge_info *nf_bridge = entry->skb->nf_bridge;

0 commit comments

Comments
 (0)