From 808dacb17308c7a1e00a2e6504cbe6468a25f0d1 Mon Sep 17 00:00:00 2001 From: Daniel Mack Date: Wed, 16 Sep 2015 14:40:26 +0200 Subject: [PATCH RFC 1/4] netfilter: add socket to struct nft_pktinfo The high-level netfilter hook API already enables users to pass a socket, but that information is lost when the chains are walked. In order to let internal eval callbacks use the passed filter rather than skb->sk, add a pointer of type 'struct sock' to 'struct nft_pktinfo' and set that field via nft_set_pktinfo(). This allows us to run filter chains from situations where skb->sk is unset. Fall back to skb->sk in case state->sk is NULL, so filter callbacks can be written in a generic way. Signed-off-by: Daniel Mack --- include/net/netfilter/nf_tables.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h index aa8bee7..05e97ed 100644 --- a/include/net/netfilter/nf_tables.h +++ b/include/net/netfilter/nf_tables.h @@ -13,6 +13,7 @@ #define NFT_JUMP_STACK_SIZE 16 struct nft_pktinfo { + struct sock *sk; struct sk_buff *skb; const struct net_device *in; const struct net_device *out; @@ -29,6 +30,7 @@ static inline void nft_set_pktinfo(struct nft_pktinfo *pkt, struct sk_buff *skb, const struct nf_hook_state *state) { + pkt->sk = state->sk ?: skb->sk; pkt->skb = skb; pkt->in = pkt->xt.in = state->in; pkt->out = pkt->xt.out = state->out; -- 2.5.0