Skip to content

Commit

Permalink
netfilter: Add socket pointer to nf_hook_state.
Browse files Browse the repository at this point in the history
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 <davem@davemloft.net>
  • Loading branch information
David Miller committed Apr 7, 2015
1 parent 107a9f4 commit 1c984f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion include/linux/netfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ struct sk_buff;

struct nf_hook_ops;

struct sock;

struct nf_hook_state {
unsigned int hook;
int thresh;
u_int8_t pf;
struct net_device *in;
struct net_device *out;
struct sock *sk;
int (*okfn)(struct sk_buff *);
};

Expand All @@ -59,13 +62,15 @@ static inline void nf_hook_state_init(struct nf_hook_state *p,
int thresh, u_int8_t pf,
struct net_device *indev,
struct net_device *outdev,
struct sock *sk,
int (*okfn)(struct sk_buff *))
{
p->hook = hook;
p->thresh = thresh;
p->pf = pf;
p->in = indev;
p->out = outdev;
p->sk = sk;
p->okfn = okfn;
}

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

nf_hook_state_init(&state, hook, thresh, pf,
indev, outdev, okfn);
indev, outdev, NULL, okfn);
return nf_hook_slow(skb, &state);
}
return 1;
Expand Down
4 changes: 4 additions & 0 deletions net/netfilter/nf_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ void nf_queue_entry_release_refs(struct nf_queue_entry *entry)
dev_put(state->in);
if (state->out)
dev_put(state->out);
if (state->sk)
sock_put(state->sk);
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
if (entry->skb->nf_bridge) {
struct nf_bridge_info *nf_bridge = entry->skb->nf_bridge;
Expand Down Expand Up @@ -81,6 +83,8 @@ bool nf_queue_entry_get_refs(struct nf_queue_entry *entry)
dev_hold(state->in);
if (state->out)
dev_hold(state->out);
if (state->sk)
sock_hold(state->sk);
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
if (entry->skb->nf_bridge) {
struct nf_bridge_info *nf_bridge = entry->skb->nf_bridge;
Expand Down

0 comments on commit 1c984f8

Please sign in to comment.