mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-25 06:30:54 +07:00
Merge branch 'nf-hook-compress'
netfilter: Compress hook function signatures. Currently netfilter hooks have a function signature that is huge and has many arguments. This propagates from the hook entry points down into the individual hook implementations themselves. This means that if, for example, we want to change the type of one of these arguments then we have to touch hundreds of locations. The main initial motivation behind this is that we'd like to change the signature of "okfn" so that a socket pointer can be passed in (and reference counted properly) for the sake of using the proper socket context in the case of tunnels whilst not releasing the top level user socket from skb->sk (and thus releasing it's socket memory quota usage) in order to accomodate this. This also makes it clear who actually uses 'okfn', nf_queue(). It is absolutely critical to make this obvious because any user of 'okfn' down in these hook chains have the be strictly audited for escapability. Specifically, escapability of references to objects outside of the packet processing path. And that's exactly what nf_queue() does via it's packet reinjection framework. In fact this points out a bug in Jiri's original attempt to push the socket pointer down through netfilter's okfn. It didn't grab and drop a reference to the socket in net/netfilter/nf_queue.c as needed. Furthermore, so many code paths are simplified, and should in fact be more efficient because we aren't passing in arguments that often are simply not used by the netfilter hook at all. Further simplifications are probably possible, but this series takes care of the main cases. Unfortunately I couldn't convert ebt_do_table() because ebtables is complete and utter crap and uses ebt_do_table() outside of the hook call chains. But that should not be news to anyone. Signed-off-by: David S. Miller <davem@davemloft.net> Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
This commit is contained in:
commit
5888b93b75
@ -44,11 +44,19 @@ int netfilter_init(void);
|
||||
struct sk_buff;
|
||||
|
||||
struct nf_hook_ops;
|
||||
|
||||
struct nf_hook_state {
|
||||
unsigned int hook;
|
||||
int thresh;
|
||||
u_int8_t pf;
|
||||
struct net_device *in;
|
||||
struct net_device *out;
|
||||
int (*okfn)(struct sk_buff *);
|
||||
};
|
||||
|
||||
typedef unsigned int nf_hookfn(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *));
|
||||
const struct nf_hook_state *state);
|
||||
|
||||
struct nf_hook_ops {
|
||||
struct list_head list;
|
||||
@ -118,9 +126,7 @@ static inline bool nf_hooks_active(u_int8_t pf, unsigned int hook)
|
||||
}
|
||||
#endif
|
||||
|
||||
int nf_hook_slow(u_int8_t pf, unsigned int hook, struct sk_buff *skb,
|
||||
struct net_device *indev, struct net_device *outdev,
|
||||
int (*okfn)(struct sk_buff *), int thresh);
|
||||
int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state);
|
||||
|
||||
/**
|
||||
* nf_hook_thresh - call a netfilter hook
|
||||
@ -135,8 +141,18 @@ static inline int nf_hook_thresh(u_int8_t pf, unsigned int hook,
|
||||
struct net_device *outdev,
|
||||
int (*okfn)(struct sk_buff *), int thresh)
|
||||
{
|
||||
if (nf_hooks_active(pf, hook))
|
||||
return nf_hook_slow(pf, hook, skb, indev, outdev, okfn, thresh);
|
||||
if (nf_hooks_active(pf, hook)) {
|
||||
struct nf_hook_state state = {
|
||||
.hook = hook,
|
||||
.thresh = thresh,
|
||||
.pf = pf,
|
||||
.in = indev,
|
||||
.out = outdev,
|
||||
.okfn = okfn
|
||||
};
|
||||
|
||||
return nf_hook_slow(skb, &state);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -54,8 +54,7 @@ extern struct xt_table *arpt_register_table(struct net *net,
|
||||
extern void arpt_unregister_table(struct xt_table *table);
|
||||
extern unsigned int arpt_do_table(struct sk_buff *skb,
|
||||
unsigned int hook,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct xt_table *table);
|
||||
|
||||
#ifdef CONFIG_COMPAT
|
||||
|
@ -65,8 +65,7 @@ struct ipt_error {
|
||||
extern void *ipt_alloc_initial_table(const struct xt_table *);
|
||||
extern unsigned int ipt_do_table(struct sk_buff *skb,
|
||||
unsigned int hook,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct xt_table *table);
|
||||
|
||||
#ifdef CONFIG_COMPAT
|
||||
|
@ -31,8 +31,7 @@ extern struct xt_table *ip6t_register_table(struct net *net,
|
||||
extern void ip6t_unregister_table(struct net *net, struct xt_table *table);
|
||||
extern unsigned int ip6t_do_table(struct sk_buff *skb,
|
||||
unsigned int hook,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct xt_table *table);
|
||||
|
||||
/* Check for an extension */
|
||||
|
@ -44,40 +44,32 @@ int nf_nat_icmp_reply_translation(struct sk_buff *skb, struct nf_conn *ct,
|
||||
unsigned int hooknum);
|
||||
|
||||
unsigned int nf_nat_ipv4_in(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
unsigned int (*do_chain)(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct nf_conn *ct));
|
||||
|
||||
unsigned int nf_nat_ipv4_out(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
unsigned int (*do_chain)(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct nf_conn *ct));
|
||||
|
||||
unsigned int nf_nat_ipv4_local_fn(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
unsigned int (*do_chain)(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct nf_conn *ct));
|
||||
|
||||
unsigned int nf_nat_ipv4_fn(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
unsigned int (*do_chain)(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct nf_conn *ct));
|
||||
|
||||
int nf_nat_icmpv6_reply_translation(struct sk_buff *skb, struct nf_conn *ct,
|
||||
@ -85,40 +77,32 @@ int nf_nat_icmpv6_reply_translation(struct sk_buff *skb, struct nf_conn *ct,
|
||||
unsigned int hooknum, unsigned int hdrlen);
|
||||
|
||||
unsigned int nf_nat_ipv6_in(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
unsigned int (*do_chain)(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct nf_conn *ct));
|
||||
|
||||
unsigned int nf_nat_ipv6_out(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
unsigned int (*do_chain)(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct nf_conn *ct));
|
||||
|
||||
unsigned int nf_nat_ipv6_local_fn(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
unsigned int (*do_chain)(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct nf_conn *ct));
|
||||
|
||||
unsigned int nf_nat_ipv6_fn(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
unsigned int (*do_chain)(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct nf_conn *ct));
|
||||
|
||||
#endif /* _NF_NAT_L3PROTO_H */
|
||||
|
@ -12,12 +12,8 @@ struct nf_queue_entry {
|
||||
unsigned int id;
|
||||
|
||||
struct nf_hook_ops *elem;
|
||||
u_int8_t pf;
|
||||
struct nf_hook_state state;
|
||||
u16 size; /* sizeof(entry) + saved route keys */
|
||||
unsigned int hook;
|
||||
struct net_device *indev;
|
||||
struct net_device *outdev;
|
||||
int (*okfn)(struct sk_buff *);
|
||||
|
||||
/* extra space to store route keys */
|
||||
};
|
||||
|
@ -26,12 +26,11 @@ struct nft_pktinfo {
|
||||
static inline void nft_set_pktinfo(struct nft_pktinfo *pkt,
|
||||
const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out)
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
pkt->skb = skb;
|
||||
pkt->in = pkt->xt.in = in;
|
||||
pkt->out = pkt->xt.out = out;
|
||||
pkt->in = pkt->xt.in = state->in;
|
||||
pkt->out = pkt->xt.out = state->out;
|
||||
pkt->ops = ops;
|
||||
pkt->xt.hooknum = ops->hooknum;
|
||||
pkt->xt.family = ops->pf;
|
||||
|
@ -8,12 +8,11 @@ static inline void
|
||||
nft_set_pktinfo_ipv4(struct nft_pktinfo *pkt,
|
||||
const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out)
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
struct iphdr *ip;
|
||||
|
||||
nft_set_pktinfo(pkt, ops, skb, in, out);
|
||||
nft_set_pktinfo(pkt, ops, skb, state);
|
||||
|
||||
ip = ip_hdr(pkt->skb);
|
||||
pkt->tprot = ip->protocol;
|
||||
|
@ -8,13 +8,12 @@ static inline int
|
||||
nft_set_pktinfo_ipv6(struct nft_pktinfo *pkt,
|
||||
const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out)
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
int protohdr, thoff = 0;
|
||||
unsigned short frag_off;
|
||||
|
||||
nft_set_pktinfo(pkt, ops, skb, in, out);
|
||||
nft_set_pktinfo(pkt, ops, skb, state);
|
||||
|
||||
protohdr = ipv6_find_hdr(pkt->skb, &thoff, -1, &frag_off, NULL);
|
||||
/* If malformed, drop it */
|
||||
|
@ -562,9 +562,7 @@ static int check_hbh_len(struct sk_buff *skb)
|
||||
* to ip6tables, which doesn't support NAT, so things are fairly simple. */
|
||||
static unsigned int br_nf_pre_routing_ipv6(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
const struct ipv6hdr *hdr;
|
||||
u32 pkt_len;
|
||||
@ -612,9 +610,7 @@ static unsigned int br_nf_pre_routing_ipv6(const struct nf_hook_ops *ops,
|
||||
* address to be able to detect DNAT afterwards. */
|
||||
static unsigned int br_nf_pre_routing(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
struct net_bridge_port *p;
|
||||
struct net_bridge *br;
|
||||
@ -623,7 +619,7 @@ static unsigned int br_nf_pre_routing(const struct nf_hook_ops *ops,
|
||||
if (unlikely(!pskb_may_pull(skb, len)))
|
||||
return NF_DROP;
|
||||
|
||||
p = br_port_get_rcu(in);
|
||||
p = br_port_get_rcu(state->in);
|
||||
if (p == NULL)
|
||||
return NF_DROP;
|
||||
br = p->br;
|
||||
@ -633,7 +629,7 @@ static unsigned int br_nf_pre_routing(const struct nf_hook_ops *ops,
|
||||
return NF_ACCEPT;
|
||||
|
||||
nf_bridge_pull_encap_header_rcsum(skb);
|
||||
return br_nf_pre_routing_ipv6(ops, skb, in, out, okfn);
|
||||
return br_nf_pre_routing_ipv6(ops, skb, state);
|
||||
}
|
||||
|
||||
if (!brnf_call_iptables && !br->nf_call_iptables)
|
||||
@ -671,9 +667,7 @@ static unsigned int br_nf_pre_routing(const struct nf_hook_ops *ops,
|
||||
* prevent this from happening. */
|
||||
static unsigned int br_nf_local_in(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
br_drop_fake_rtable(skb);
|
||||
return NF_ACCEPT;
|
||||
@ -710,9 +704,7 @@ static int br_nf_forward_finish(struct sk_buff *skb)
|
||||
* bridge ports. */
|
||||
static unsigned int br_nf_forward_ip(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
struct nf_bridge_info *nf_bridge;
|
||||
struct net_device *parent;
|
||||
@ -726,7 +718,7 @@ static unsigned int br_nf_forward_ip(const struct nf_hook_ops *ops,
|
||||
if (!nf_bridge_unshare(skb))
|
||||
return NF_DROP;
|
||||
|
||||
parent = bridge_parent(out);
|
||||
parent = bridge_parent(state->out);
|
||||
if (!parent)
|
||||
return NF_DROP;
|
||||
|
||||
@ -754,23 +746,21 @@ static unsigned int br_nf_forward_ip(const struct nf_hook_ops *ops,
|
||||
else
|
||||
skb->protocol = htons(ETH_P_IPV6);
|
||||
|
||||
NF_HOOK(pf, NF_INET_FORWARD, skb, brnf_get_logical_dev(skb, in), parent,
|
||||
br_nf_forward_finish);
|
||||
NF_HOOK(pf, NF_INET_FORWARD, skb, brnf_get_logical_dev(skb, state->in),
|
||||
parent, br_nf_forward_finish);
|
||||
|
||||
return NF_STOLEN;
|
||||
}
|
||||
|
||||
static unsigned int br_nf_forward_arp(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
struct net_bridge_port *p;
|
||||
struct net_bridge *br;
|
||||
struct net_device **d = (struct net_device **)(skb->cb);
|
||||
|
||||
p = br_port_get_rcu(out);
|
||||
p = br_port_get_rcu(state->out);
|
||||
if (p == NULL)
|
||||
return NF_ACCEPT;
|
||||
br = p->br;
|
||||
@ -789,9 +779,9 @@ static unsigned int br_nf_forward_arp(const struct nf_hook_ops *ops,
|
||||
nf_bridge_push_encap_header(skb);
|
||||
return NF_ACCEPT;
|
||||
}
|
||||
*d = (struct net_device *)in;
|
||||
NF_HOOK(NFPROTO_ARP, NF_ARP_FORWARD, skb, (struct net_device *)in,
|
||||
(struct net_device *)out, br_nf_forward_finish);
|
||||
*d = state->in;
|
||||
NF_HOOK(NFPROTO_ARP, NF_ARP_FORWARD, skb, state->in,
|
||||
state->out, br_nf_forward_finish);
|
||||
|
||||
return NF_STOLEN;
|
||||
}
|
||||
@ -859,9 +849,7 @@ static int br_nf_dev_queue_xmit(struct sk_buff *skb)
|
||||
/* PF_BRIDGE/POST_ROUTING ********************************************/
|
||||
static unsigned int br_nf_post_routing(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
struct nf_bridge_info *nf_bridge = skb->nf_bridge;
|
||||
struct net_device *realoutdev = bridge_parent(skb->dev);
|
||||
@ -910,9 +898,7 @@ static unsigned int br_nf_post_routing(const struct nf_hook_ops *ops,
|
||||
* for the second time. */
|
||||
static unsigned int ip_sabotage_in(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
if (skb->nf_bridge &&
|
||||
!(skb->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)) {
|
||||
|
@ -58,20 +58,18 @@ static const struct ebt_table frame_filter = {
|
||||
|
||||
static unsigned int
|
||||
ebt_in_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return ebt_do_table(ops->hooknum, skb, in, out,
|
||||
dev_net(in)->xt.frame_filter);
|
||||
return ebt_do_table(ops->hooknum, skb, state->in, state->out,
|
||||
dev_net(state->in)->xt.frame_filter);
|
||||
}
|
||||
|
||||
static unsigned int
|
||||
ebt_out_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return ebt_do_table(ops->hooknum, skb, in, out,
|
||||
dev_net(out)->xt.frame_filter);
|
||||
return ebt_do_table(ops->hooknum, skb, state->in, state->out,
|
||||
dev_net(state->out)->xt.frame_filter);
|
||||
}
|
||||
|
||||
static struct nf_hook_ops ebt_ops_filter[] __read_mostly = {
|
||||
|
@ -58,20 +58,18 @@ static struct ebt_table frame_nat = {
|
||||
|
||||
static unsigned int
|
||||
ebt_nat_in(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return ebt_do_table(ops->hooknum, skb, in, out,
|
||||
dev_net(in)->xt.frame_nat);
|
||||
return ebt_do_table(ops->hooknum, skb, state->in, state->out,
|
||||
dev_net(state->in)->xt.frame_nat);
|
||||
}
|
||||
|
||||
static unsigned int
|
||||
ebt_nat_out(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return ebt_do_table(ops->hooknum, skb, in, out,
|
||||
dev_net(out)->xt.frame_nat);
|
||||
return ebt_do_table(ops->hooknum, skb, state->in, state->out,
|
||||
dev_net(state->out)->xt.frame_nat);
|
||||
}
|
||||
|
||||
static struct nf_hook_ops ebt_ops_nat[] __read_mostly = {
|
||||
|
@ -67,47 +67,43 @@ EXPORT_SYMBOL_GPL(nft_bridge_ip6hdr_validate);
|
||||
static inline void nft_bridge_set_pktinfo_ipv4(struct nft_pktinfo *pkt,
|
||||
const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out)
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
if (nft_bridge_iphdr_validate(skb))
|
||||
nft_set_pktinfo_ipv4(pkt, ops, skb, in, out);
|
||||
nft_set_pktinfo_ipv4(pkt, ops, skb, state);
|
||||
else
|
||||
nft_set_pktinfo(pkt, ops, skb, in, out);
|
||||
nft_set_pktinfo(pkt, ops, skb, state);
|
||||
}
|
||||
|
||||
static inline void nft_bridge_set_pktinfo_ipv6(struct nft_pktinfo *pkt,
|
||||
const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out)
|
||||
const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
#if IS_ENABLED(CONFIG_IPV6)
|
||||
if (nft_bridge_ip6hdr_validate(skb) &&
|
||||
nft_set_pktinfo_ipv6(pkt, ops, skb, in, out) == 0)
|
||||
nft_set_pktinfo_ipv6(pkt, ops, skb, state) == 0)
|
||||
return;
|
||||
#endif
|
||||
nft_set_pktinfo(pkt, ops, skb, in, out);
|
||||
nft_set_pktinfo(pkt, ops, skb, state);
|
||||
}
|
||||
|
||||
static unsigned int
|
||||
nft_do_chain_bridge(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
struct nft_pktinfo pkt;
|
||||
|
||||
switch (eth_hdr(skb)->h_proto) {
|
||||
case htons(ETH_P_IP):
|
||||
nft_bridge_set_pktinfo_ipv4(&pkt, ops, skb, in, out);
|
||||
nft_bridge_set_pktinfo_ipv4(&pkt, ops, skb, state);
|
||||
break;
|
||||
case htons(ETH_P_IPV6):
|
||||
nft_bridge_set_pktinfo_ipv6(&pkt, ops, skb, in, out);
|
||||
nft_bridge_set_pktinfo_ipv6(&pkt, ops, skb, state);
|
||||
break;
|
||||
default:
|
||||
nft_set_pktinfo(&pkt, ops, skb, in, out);
|
||||
nft_set_pktinfo(&pkt, ops, skb, state);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -89,9 +89,7 @@ static void dnrmg_send_peer(struct sk_buff *skb)
|
||||
|
||||
static unsigned int dnrmg_hook(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
dnrmg_send_peer(skb);
|
||||
return NF_ACCEPT;
|
||||
|
@ -94,7 +94,7 @@ static void nf_ip_saveroute(const struct sk_buff *skb,
|
||||
{
|
||||
struct ip_rt_info *rt_info = nf_queue_entry_reroute(entry);
|
||||
|
||||
if (entry->hook == NF_INET_LOCAL_OUT) {
|
||||
if (entry->state.hook == NF_INET_LOCAL_OUT) {
|
||||
const struct iphdr *iph = ip_hdr(skb);
|
||||
|
||||
rt_info->tos = iph->tos;
|
||||
@ -109,7 +109,7 @@ static int nf_ip_reroute(struct sk_buff *skb,
|
||||
{
|
||||
const struct ip_rt_info *rt_info = nf_queue_entry_reroute(entry);
|
||||
|
||||
if (entry->hook == NF_INET_LOCAL_OUT) {
|
||||
if (entry->state.hook == NF_INET_LOCAL_OUT) {
|
||||
const struct iphdr *iph = ip_hdr(skb);
|
||||
|
||||
if (!(iph->tos == rt_info->tos &&
|
||||
|
@ -248,8 +248,7 @@ struct arpt_entry *arpt_next_entry(const struct arpt_entry *entry)
|
||||
|
||||
unsigned int arpt_do_table(struct sk_buff *skb,
|
||||
unsigned int hook,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct xt_table *table)
|
||||
{
|
||||
static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long))));
|
||||
@ -265,8 +264,8 @@ unsigned int arpt_do_table(struct sk_buff *skb,
|
||||
if (!pskb_may_pull(skb, arp_hdr_len(skb->dev)))
|
||||
return NF_DROP;
|
||||
|
||||
indev = in ? in->name : nulldevname;
|
||||
outdev = out ? out->name : nulldevname;
|
||||
indev = state->in ? state->in->name : nulldevname;
|
||||
outdev = state->out ? state->out->name : nulldevname;
|
||||
|
||||
local_bh_disable();
|
||||
addend = xt_write_recseq_begin();
|
||||
@ -281,8 +280,8 @@ unsigned int arpt_do_table(struct sk_buff *skb,
|
||||
e = get_entry(table_base, private->hook_entry[hook]);
|
||||
back = get_entry(table_base, private->underflow[hook]);
|
||||
|
||||
acpar.in = in;
|
||||
acpar.out = out;
|
||||
acpar.in = state->in;
|
||||
acpar.out = state->out;
|
||||
acpar.hooknum = hook;
|
||||
acpar.family = NFPROTO_ARP;
|
||||
acpar.hotdrop = false;
|
||||
|
@ -28,12 +28,11 @@ static const struct xt_table packet_filter = {
|
||||
/* The work comes in here from netfilter.c */
|
||||
static unsigned int
|
||||
arptable_filter_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
const struct net *net = dev_net((in != NULL) ? in : out);
|
||||
const struct net *net = dev_net(state->in ? state->in : state->out);
|
||||
|
||||
return arpt_do_table(skb, ops->hooknum, in, out,
|
||||
return arpt_do_table(skb, ops->hooknum, state,
|
||||
net->ipv4.arptable_filter);
|
||||
}
|
||||
|
||||
|
@ -288,8 +288,7 @@ struct ipt_entry *ipt_next_entry(const struct ipt_entry *entry)
|
||||
unsigned int
|
||||
ipt_do_table(struct sk_buff *skb,
|
||||
unsigned int hook,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct xt_table *table)
|
||||
{
|
||||
static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long))));
|
||||
@ -306,8 +305,8 @@ ipt_do_table(struct sk_buff *skb,
|
||||
|
||||
/* Initialization */
|
||||
ip = ip_hdr(skb);
|
||||
indev = in ? in->name : nulldevname;
|
||||
outdev = out ? out->name : nulldevname;
|
||||
indev = state->in ? state->in->name : nulldevname;
|
||||
outdev = state->out ? state->out->name : nulldevname;
|
||||
/* We handle fragments by dealing with the first fragment as
|
||||
* if it was a normal packet. All other fragments are treated
|
||||
* normally, except that they will NEVER match rules that ask
|
||||
@ -317,8 +316,8 @@ ipt_do_table(struct sk_buff *skb,
|
||||
acpar.fragoff = ntohs(ip->frag_off) & IP_OFFSET;
|
||||
acpar.thoff = ip_hdrlen(skb);
|
||||
acpar.hotdrop = false;
|
||||
acpar.in = in;
|
||||
acpar.out = out;
|
||||
acpar.in = state->in;
|
||||
acpar.out = state->out;
|
||||
acpar.family = NFPROTO_IPV4;
|
||||
acpar.hooknum = hook;
|
||||
|
||||
@ -370,7 +369,7 @@ ipt_do_table(struct sk_buff *skb,
|
||||
#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
|
||||
/* The packet is traced: log it */
|
||||
if (unlikely(skb->nf_trace))
|
||||
trace_packet(skb, hook, in, out,
|
||||
trace_packet(skb, hook, state->in, state->out,
|
||||
table->name, private, e);
|
||||
#endif
|
||||
/* Standard target? */
|
||||
|
@ -504,14 +504,12 @@ static void arp_print(struct arp_payload *payload)
|
||||
static unsigned int
|
||||
arp_mangle(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
struct arphdr *arp = arp_hdr(skb);
|
||||
struct arp_payload *payload;
|
||||
struct clusterip_config *c;
|
||||
struct net *net = dev_net(in ? in : out);
|
||||
struct net *net = dev_net(state->in ? state->in : state->out);
|
||||
|
||||
/* we don't care about non-ethernet and non-ipv4 ARP */
|
||||
if (arp->ar_hrd != htons(ARPHRD_ETHER) ||
|
||||
@ -536,10 +534,10 @@ arp_mangle(const struct nf_hook_ops *ops,
|
||||
* addresses on different interfacs. However, in the CLUSTERIP case
|
||||
* this wouldn't work, since we didn't subscribe the mcast group on
|
||||
* other interfaces */
|
||||
if (c->dev != out) {
|
||||
if (c->dev != state->out) {
|
||||
pr_debug("not mangling arp reply on different "
|
||||
"interface: cip'%s'-skb'%s'\n",
|
||||
c->dev->name, out->name);
|
||||
c->dev->name, state->out->name);
|
||||
clusterip_config_put(c);
|
||||
return NF_ACCEPT;
|
||||
}
|
||||
|
@ -300,11 +300,9 @@ synproxy_tg4(struct sk_buff *skb, const struct xt_action_param *par)
|
||||
|
||||
static unsigned int ipv4_synproxy_hook(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *nhs)
|
||||
{
|
||||
struct synproxy_net *snet = synproxy_pernet(dev_net(in ? : out));
|
||||
struct synproxy_net *snet = synproxy_pernet(dev_net(nhs->in ? : nhs->out));
|
||||
enum ip_conntrack_info ctinfo;
|
||||
struct nf_conn *ct;
|
||||
struct nf_conn_synproxy *synproxy;
|
||||
|
@ -34,8 +34,7 @@ static const struct xt_table packet_filter = {
|
||||
|
||||
static unsigned int
|
||||
iptable_filter_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
const struct net *net;
|
||||
|
||||
@ -45,9 +44,8 @@ iptable_filter_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
/* root is playing with raw sockets. */
|
||||
return NF_ACCEPT;
|
||||
|
||||
net = dev_net((in != NULL) ? in : out);
|
||||
return ipt_do_table(skb, ops->hooknum, in, out,
|
||||
net->ipv4.iptable_filter);
|
||||
net = dev_net(state->in ? state->in : state->out);
|
||||
return ipt_do_table(skb, ops->hooknum, state, net->ipv4.iptable_filter);
|
||||
}
|
||||
|
||||
static struct nf_hook_ops *filter_ops __read_mostly;
|
||||
|
@ -37,8 +37,9 @@ static const struct xt_table packet_mangler = {
|
||||
};
|
||||
|
||||
static unsigned int
|
||||
ipt_mangle_out(struct sk_buff *skb, const struct net_device *out)
|
||||
ipt_mangle_out(struct sk_buff *skb, const struct nf_hook_state *state)
|
||||
{
|
||||
struct net_device *out = state->out;
|
||||
unsigned int ret;
|
||||
const struct iphdr *iph;
|
||||
u_int8_t tos;
|
||||
@ -58,7 +59,7 @@ ipt_mangle_out(struct sk_buff *skb, const struct net_device *out)
|
||||
daddr = iph->daddr;
|
||||
tos = iph->tos;
|
||||
|
||||
ret = ipt_do_table(skb, NF_INET_LOCAL_OUT, NULL, out,
|
||||
ret = ipt_do_table(skb, NF_INET_LOCAL_OUT, state,
|
||||
dev_net(out)->ipv4.iptable_mangle);
|
||||
/* Reroute for ANY change. */
|
||||
if (ret != NF_DROP && ret != NF_STOLEN) {
|
||||
@ -81,18 +82,16 @@ ipt_mangle_out(struct sk_buff *skb, const struct net_device *out)
|
||||
static unsigned int
|
||||
iptable_mangle_hook(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
if (ops->hooknum == NF_INET_LOCAL_OUT)
|
||||
return ipt_mangle_out(skb, out);
|
||||
return ipt_mangle_out(skb, state);
|
||||
if (ops->hooknum == NF_INET_POST_ROUTING)
|
||||
return ipt_do_table(skb, ops->hooknum, in, out,
|
||||
dev_net(out)->ipv4.iptable_mangle);
|
||||
return ipt_do_table(skb, ops->hooknum, state,
|
||||
dev_net(state->out)->ipv4.iptable_mangle);
|
||||
/* PREROUTING/INPUT/FORWARD: */
|
||||
return ipt_do_table(skb, ops->hooknum, in, out,
|
||||
dev_net(in)->ipv4.iptable_mangle);
|
||||
return ipt_do_table(skb, ops->hooknum, state,
|
||||
dev_net(state->in)->ipv4.iptable_mangle);
|
||||
}
|
||||
|
||||
static struct nf_hook_ops *mangle_ops __read_mostly;
|
||||
|
@ -30,49 +30,40 @@ static const struct xt_table nf_nat_ipv4_table = {
|
||||
|
||||
static unsigned int iptable_nat_do_chain(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct nf_conn *ct)
|
||||
{
|
||||
struct net *net = nf_ct_net(ct);
|
||||
|
||||
return ipt_do_table(skb, ops->hooknum, in, out, net->ipv4.nat_table);
|
||||
return ipt_do_table(skb, ops->hooknum, state, net->ipv4.nat_table);
|
||||
}
|
||||
|
||||
static unsigned int iptable_nat_ipv4_fn(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return nf_nat_ipv4_fn(ops, skb, in, out, iptable_nat_do_chain);
|
||||
return nf_nat_ipv4_fn(ops, skb, state, iptable_nat_do_chain);
|
||||
}
|
||||
|
||||
static unsigned int iptable_nat_ipv4_in(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return nf_nat_ipv4_in(ops, skb, in, out, iptable_nat_do_chain);
|
||||
return nf_nat_ipv4_in(ops, skb, state, iptable_nat_do_chain);
|
||||
}
|
||||
|
||||
static unsigned int iptable_nat_ipv4_out(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return nf_nat_ipv4_out(ops, skb, in, out, iptable_nat_do_chain);
|
||||
return nf_nat_ipv4_out(ops, skb, state, iptable_nat_do_chain);
|
||||
}
|
||||
|
||||
static unsigned int iptable_nat_ipv4_local_fn(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return nf_nat_ipv4_local_fn(ops, skb, in, out, iptable_nat_do_chain);
|
||||
return nf_nat_ipv4_local_fn(ops, skb, state, iptable_nat_do_chain);
|
||||
}
|
||||
|
||||
static struct nf_hook_ops nf_nat_ipv4_ops[] __read_mostly = {
|
||||
|
@ -21,8 +21,7 @@ static const struct xt_table packet_raw = {
|
||||
/* The work comes in here from netfilter.c. */
|
||||
static unsigned int
|
||||
iptable_raw_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
const struct net *net;
|
||||
|
||||
@ -32,8 +31,8 @@ iptable_raw_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
/* root is playing with raw sockets. */
|
||||
return NF_ACCEPT;
|
||||
|
||||
net = dev_net((in != NULL) ? in : out);
|
||||
return ipt_do_table(skb, ops->hooknum, in, out, net->ipv4.iptable_raw);
|
||||
net = dev_net(state->in ? state->in : state->out);
|
||||
return ipt_do_table(skb, ops->hooknum, state, net->ipv4.iptable_raw);
|
||||
}
|
||||
|
||||
static struct nf_hook_ops *rawtable_ops __read_mostly;
|
||||
|
@ -38,9 +38,7 @@ static const struct xt_table security_table = {
|
||||
|
||||
static unsigned int
|
||||
iptable_security_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
const struct net *net;
|
||||
|
||||
@ -50,8 +48,8 @@ iptable_security_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
/* Somebody is playing with raw sockets. */
|
||||
return NF_ACCEPT;
|
||||
|
||||
net = dev_net((in != NULL) ? in : out);
|
||||
return ipt_do_table(skb, ops->hooknum, in, out,
|
||||
net = dev_net(state->in ? state->in : state->out);
|
||||
return ipt_do_table(skb, ops->hooknum, state,
|
||||
net->ipv4.iptable_security);
|
||||
}
|
||||
|
||||
|
@ -94,9 +94,7 @@ static int ipv4_get_l4proto(const struct sk_buff *skb, unsigned int nhoff,
|
||||
|
||||
static unsigned int ipv4_helper(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
struct nf_conn *ct;
|
||||
enum ip_conntrack_info ctinfo;
|
||||
@ -123,9 +121,7 @@ static unsigned int ipv4_helper(const struct nf_hook_ops *ops,
|
||||
|
||||
static unsigned int ipv4_confirm(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
struct nf_conn *ct;
|
||||
enum ip_conntrack_info ctinfo;
|
||||
@ -149,24 +145,20 @@ static unsigned int ipv4_confirm(const struct nf_hook_ops *ops,
|
||||
|
||||
static unsigned int ipv4_conntrack_in(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return nf_conntrack_in(dev_net(in), PF_INET, ops->hooknum, skb);
|
||||
return nf_conntrack_in(dev_net(state->in), PF_INET, ops->hooknum, skb);
|
||||
}
|
||||
|
||||
static unsigned int ipv4_conntrack_local(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
/* root is playing with raw sockets. */
|
||||
if (skb->len < sizeof(struct iphdr) ||
|
||||
ip_hdrlen(skb) < sizeof(struct iphdr))
|
||||
return NF_ACCEPT;
|
||||
return nf_conntrack_in(dev_net(out), PF_INET, ops->hooknum, skb);
|
||||
return nf_conntrack_in(dev_net(state->out), PF_INET, ops->hooknum, skb);
|
||||
}
|
||||
|
||||
/* Connection tracking may drop packets, but never alters them, so
|
||||
|
@ -63,9 +63,7 @@ static enum ip_defrag_users nf_ct_defrag_user(unsigned int hooknum,
|
||||
|
||||
static unsigned int ipv4_conntrack_defrag(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
struct sock *sk = skb->sk;
|
||||
struct inet_sock *inet = inet_sk(skb->sk);
|
||||
|
@ -256,11 +256,10 @@ EXPORT_SYMBOL_GPL(nf_nat_icmp_reply_translation);
|
||||
|
||||
unsigned int
|
||||
nf_nat_ipv4_fn(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
unsigned int (*do_chain)(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct nf_conn *ct))
|
||||
{
|
||||
struct nf_conn *ct;
|
||||
@ -309,7 +308,7 @@ nf_nat_ipv4_fn(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
if (!nf_nat_initialized(ct, maniptype)) {
|
||||
unsigned int ret;
|
||||
|
||||
ret = do_chain(ops, skb, in, out, ct);
|
||||
ret = do_chain(ops, skb, state, ct);
|
||||
if (ret != NF_ACCEPT)
|
||||
return ret;
|
||||
|
||||
@ -323,7 +322,8 @@ nf_nat_ipv4_fn(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
pr_debug("Already setup manip %s for ct %p\n",
|
||||
maniptype == NF_NAT_MANIP_SRC ? "SRC" : "DST",
|
||||
ct);
|
||||
if (nf_nat_oif_changed(ops->hooknum, ctinfo, nat, out))
|
||||
if (nf_nat_oif_changed(ops->hooknum, ctinfo, nat,
|
||||
state->out))
|
||||
goto oif_changed;
|
||||
}
|
||||
break;
|
||||
@ -332,7 +332,7 @@ nf_nat_ipv4_fn(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
/* ESTABLISHED */
|
||||
NF_CT_ASSERT(ctinfo == IP_CT_ESTABLISHED ||
|
||||
ctinfo == IP_CT_ESTABLISHED_REPLY);
|
||||
if (nf_nat_oif_changed(ops->hooknum, ctinfo, nat, out))
|
||||
if (nf_nat_oif_changed(ops->hooknum, ctinfo, nat, state->out))
|
||||
goto oif_changed;
|
||||
}
|
||||
|
||||
@ -346,17 +346,16 @@ EXPORT_SYMBOL_GPL(nf_nat_ipv4_fn);
|
||||
|
||||
unsigned int
|
||||
nf_nat_ipv4_in(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
unsigned int (*do_chain)(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct nf_conn *ct))
|
||||
{
|
||||
unsigned int ret;
|
||||
__be32 daddr = ip_hdr(skb)->daddr;
|
||||
|
||||
ret = nf_nat_ipv4_fn(ops, skb, in, out, do_chain);
|
||||
ret = nf_nat_ipv4_fn(ops, skb, state, do_chain);
|
||||
if (ret != NF_DROP && ret != NF_STOLEN &&
|
||||
daddr != ip_hdr(skb)->daddr)
|
||||
skb_dst_drop(skb);
|
||||
@ -367,11 +366,10 @@ EXPORT_SYMBOL_GPL(nf_nat_ipv4_in);
|
||||
|
||||
unsigned int
|
||||
nf_nat_ipv4_out(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
unsigned int (*do_chain)(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct nf_conn *ct))
|
||||
{
|
||||
#ifdef CONFIG_XFRM
|
||||
@ -386,7 +384,7 @@ nf_nat_ipv4_out(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
ip_hdrlen(skb) < sizeof(struct iphdr))
|
||||
return NF_ACCEPT;
|
||||
|
||||
ret = nf_nat_ipv4_fn(ops, skb, in, out, do_chain);
|
||||
ret = nf_nat_ipv4_fn(ops, skb, state, do_chain);
|
||||
#ifdef CONFIG_XFRM
|
||||
if (ret != NF_DROP && ret != NF_STOLEN &&
|
||||
!(IPCB(skb)->flags & IPSKB_XFRM_TRANSFORMED) &&
|
||||
@ -410,11 +408,10 @@ EXPORT_SYMBOL_GPL(nf_nat_ipv4_out);
|
||||
|
||||
unsigned int
|
||||
nf_nat_ipv4_local_fn(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
unsigned int (*do_chain)(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct nf_conn *ct))
|
||||
{
|
||||
const struct nf_conn *ct;
|
||||
@ -427,7 +424,7 @@ nf_nat_ipv4_local_fn(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
ip_hdrlen(skb) < sizeof(struct iphdr))
|
||||
return NF_ACCEPT;
|
||||
|
||||
ret = nf_nat_ipv4_fn(ops, skb, in, out, do_chain);
|
||||
ret = nf_nat_ipv4_fn(ops, skb, state, do_chain);
|
||||
if (ret != NF_DROP && ret != NF_STOLEN &&
|
||||
(ct = nf_ct_get(skb, &ctinfo)) != NULL) {
|
||||
enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
|
||||
|
@ -17,13 +17,11 @@
|
||||
static unsigned int
|
||||
nft_do_chain_arp(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
struct nft_pktinfo pkt;
|
||||
|
||||
nft_set_pktinfo(&pkt, ops, skb, in, out);
|
||||
nft_set_pktinfo(&pkt, ops, skb, state);
|
||||
|
||||
return nft_do_chain(&pkt, ops);
|
||||
}
|
||||
|
@ -20,22 +20,18 @@
|
||||
|
||||
static unsigned int nft_do_chain_ipv4(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
struct nft_pktinfo pkt;
|
||||
|
||||
nft_set_pktinfo_ipv4(&pkt, ops, skb, in, out);
|
||||
nft_set_pktinfo_ipv4(&pkt, ops, skb, state);
|
||||
|
||||
return nft_do_chain(&pkt, ops);
|
||||
}
|
||||
|
||||
static unsigned int nft_ipv4_output(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
if (unlikely(skb->len < sizeof(struct iphdr) ||
|
||||
ip_hdr(skb)->ihl < sizeof(struct iphdr) / 4)) {
|
||||
@ -45,7 +41,7 @@ static unsigned int nft_ipv4_output(const struct nf_hook_ops *ops,
|
||||
return NF_ACCEPT;
|
||||
}
|
||||
|
||||
return nft_do_chain_ipv4(ops, skb, in, out, okfn);
|
||||
return nft_do_chain_ipv4(ops, skb, state);
|
||||
}
|
||||
|
||||
struct nft_af_info nft_af_ipv4 __read_mostly = {
|
||||
|
@ -28,51 +28,42 @@
|
||||
|
||||
static unsigned int nft_nat_do_chain(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct nf_conn *ct)
|
||||
{
|
||||
struct nft_pktinfo pkt;
|
||||
|
||||
nft_set_pktinfo_ipv4(&pkt, ops, skb, in, out);
|
||||
nft_set_pktinfo_ipv4(&pkt, ops, skb, state);
|
||||
|
||||
return nft_do_chain(&pkt, ops);
|
||||
}
|
||||
|
||||
static unsigned int nft_nat_ipv4_fn(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return nf_nat_ipv4_fn(ops, skb, in, out, nft_nat_do_chain);
|
||||
return nf_nat_ipv4_fn(ops, skb, state, nft_nat_do_chain);
|
||||
}
|
||||
|
||||
static unsigned int nft_nat_ipv4_in(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return nf_nat_ipv4_in(ops, skb, in, out, nft_nat_do_chain);
|
||||
return nf_nat_ipv4_in(ops, skb, state, nft_nat_do_chain);
|
||||
}
|
||||
|
||||
static unsigned int nft_nat_ipv4_out(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return nf_nat_ipv4_out(ops, skb, in, out, nft_nat_do_chain);
|
||||
return nf_nat_ipv4_out(ops, skb, state, nft_nat_do_chain);
|
||||
}
|
||||
|
||||
static unsigned int nft_nat_ipv4_local_fn(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return nf_nat_ipv4_local_fn(ops, skb, in, out, nft_nat_do_chain);
|
||||
return nf_nat_ipv4_local_fn(ops, skb, state, nft_nat_do_chain);
|
||||
}
|
||||
|
||||
static const struct nf_chain_type nft_chain_nat_ipv4 = {
|
||||
|
@ -23,9 +23,7 @@
|
||||
|
||||
static unsigned int nf_route_table_hook(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
unsigned int ret;
|
||||
struct nft_pktinfo pkt;
|
||||
@ -39,7 +37,7 @@ static unsigned int nf_route_table_hook(const struct nf_hook_ops *ops,
|
||||
ip_hdrlen(skb) < sizeof(struct iphdr))
|
||||
return NF_ACCEPT;
|
||||
|
||||
nft_set_pktinfo_ipv4(&pkt, ops, skb, in, out);
|
||||
nft_set_pktinfo_ipv4(&pkt, ops, skb, state);
|
||||
|
||||
mark = skb->mark;
|
||||
iph = ip_hdr(skb);
|
||||
|
@ -84,7 +84,7 @@ static void nf_ip6_saveroute(const struct sk_buff *skb,
|
||||
{
|
||||
struct ip6_rt_info *rt_info = nf_queue_entry_reroute(entry);
|
||||
|
||||
if (entry->hook == NF_INET_LOCAL_OUT) {
|
||||
if (entry->state.hook == NF_INET_LOCAL_OUT) {
|
||||
const struct ipv6hdr *iph = ipv6_hdr(skb);
|
||||
|
||||
rt_info->daddr = iph->daddr;
|
||||
@ -98,7 +98,7 @@ static int nf_ip6_reroute(struct sk_buff *skb,
|
||||
{
|
||||
struct ip6_rt_info *rt_info = nf_queue_entry_reroute(entry);
|
||||
|
||||
if (entry->hook == NF_INET_LOCAL_OUT) {
|
||||
if (entry->state.hook == NF_INET_LOCAL_OUT) {
|
||||
const struct ipv6hdr *iph = ipv6_hdr(skb);
|
||||
if (!ipv6_addr_equal(&iph->daddr, &rt_info->daddr) ||
|
||||
!ipv6_addr_equal(&iph->saddr, &rt_info->saddr) ||
|
||||
|
@ -317,8 +317,7 @@ ip6t_next_entry(const struct ip6t_entry *entry)
|
||||
unsigned int
|
||||
ip6t_do_table(struct sk_buff *skb,
|
||||
unsigned int hook,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct xt_table *table)
|
||||
{
|
||||
static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long))));
|
||||
@ -333,8 +332,8 @@ ip6t_do_table(struct sk_buff *skb,
|
||||
unsigned int addend;
|
||||
|
||||
/* Initialization */
|
||||
indev = in ? in->name : nulldevname;
|
||||
outdev = out ? out->name : nulldevname;
|
||||
indev = state->in ? state->in->name : nulldevname;
|
||||
outdev = state->out ? state->out->name : nulldevname;
|
||||
/* We handle fragments by dealing with the first fragment as
|
||||
* if it was a normal packet. All other fragments are treated
|
||||
* normally, except that they will NEVER match rules that ask
|
||||
@ -342,8 +341,8 @@ ip6t_do_table(struct sk_buff *skb,
|
||||
* rule is also a fragment-specific rule, non-fragments won't
|
||||
* match it. */
|
||||
acpar.hotdrop = false;
|
||||
acpar.in = in;
|
||||
acpar.out = out;
|
||||
acpar.in = state->in;
|
||||
acpar.out = state->out;
|
||||
acpar.family = NFPROTO_IPV6;
|
||||
acpar.hooknum = hook;
|
||||
|
||||
@ -393,7 +392,7 @@ ip6t_do_table(struct sk_buff *skb,
|
||||
#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
|
||||
/* The packet is traced: log it */
|
||||
if (unlikely(skb->nf_trace))
|
||||
trace_packet(skb, hook, in, out,
|
||||
trace_packet(skb, hook, state->in, state->out,
|
||||
table->name, private, e);
|
||||
#endif
|
||||
/* Standard target? */
|
||||
|
@ -315,11 +315,9 @@ synproxy_tg6(struct sk_buff *skb, const struct xt_action_param *par)
|
||||
|
||||
static unsigned int ipv6_synproxy_hook(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *nhs)
|
||||
{
|
||||
struct synproxy_net *snet = synproxy_pernet(dev_net(in ? : out));
|
||||
struct synproxy_net *snet = synproxy_pernet(dev_net(nhs->in ? : nhs->out));
|
||||
enum ip_conntrack_info ctinfo;
|
||||
struct nf_conn *ct;
|
||||
struct nf_conn_synproxy *synproxy;
|
||||
|
@ -33,13 +33,11 @@ static const struct xt_table packet_filter = {
|
||||
/* The work comes in here from netfilter.c. */
|
||||
static unsigned int
|
||||
ip6table_filter_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
const struct net *net = dev_net((in != NULL) ? in : out);
|
||||
const struct net *net = dev_net(state->in ? state->in : state->out);
|
||||
|
||||
return ip6t_do_table(skb, ops->hooknum, in, out,
|
||||
net->ipv6.ip6table_filter);
|
||||
return ip6t_do_table(skb, ops->hooknum, state, net->ipv6.ip6table_filter);
|
||||
}
|
||||
|
||||
static struct nf_hook_ops *filter_ops __read_mostly;
|
||||
|
@ -32,7 +32,7 @@ static const struct xt_table packet_mangler = {
|
||||
};
|
||||
|
||||
static unsigned int
|
||||
ip6t_mangle_out(struct sk_buff *skb, const struct net_device *out)
|
||||
ip6t_mangle_out(struct sk_buff *skb, const struct nf_hook_state *state)
|
||||
{
|
||||
unsigned int ret;
|
||||
struct in6_addr saddr, daddr;
|
||||
@ -57,8 +57,8 @@ ip6t_mangle_out(struct sk_buff *skb, const struct net_device *out)
|
||||
/* flowlabel and prio (includes version, which shouldn't change either */
|
||||
flowlabel = *((u_int32_t *)ipv6_hdr(skb));
|
||||
|
||||
ret = ip6t_do_table(skb, NF_INET_LOCAL_OUT, NULL, out,
|
||||
dev_net(out)->ipv6.ip6table_mangle);
|
||||
ret = ip6t_do_table(skb, NF_INET_LOCAL_OUT, state,
|
||||
dev_net(state->out)->ipv6.ip6table_mangle);
|
||||
|
||||
if (ret != NF_DROP && ret != NF_STOLEN &&
|
||||
(!ipv6_addr_equal(&ipv6_hdr(skb)->saddr, &saddr) ||
|
||||
@ -77,17 +77,16 @@ ip6t_mangle_out(struct sk_buff *skb, const struct net_device *out)
|
||||
/* The work comes in here from netfilter.c. */
|
||||
static unsigned int
|
||||
ip6table_mangle_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
if (ops->hooknum == NF_INET_LOCAL_OUT)
|
||||
return ip6t_mangle_out(skb, out);
|
||||
return ip6t_mangle_out(skb, state);
|
||||
if (ops->hooknum == NF_INET_POST_ROUTING)
|
||||
return ip6t_do_table(skb, ops->hooknum, in, out,
|
||||
dev_net(out)->ipv6.ip6table_mangle);
|
||||
return ip6t_do_table(skb, ops->hooknum, state,
|
||||
dev_net(state->out)->ipv6.ip6table_mangle);
|
||||
/* INPUT/FORWARD */
|
||||
return ip6t_do_table(skb, ops->hooknum, in, out,
|
||||
dev_net(in)->ipv6.ip6table_mangle);
|
||||
return ip6t_do_table(skb, ops->hooknum, state,
|
||||
dev_net(state->in)->ipv6.ip6table_mangle);
|
||||
}
|
||||
|
||||
static struct nf_hook_ops *mangle_ops __read_mostly;
|
||||
|
@ -32,49 +32,40 @@ static const struct xt_table nf_nat_ipv6_table = {
|
||||
|
||||
static unsigned int ip6table_nat_do_chain(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct nf_conn *ct)
|
||||
{
|
||||
struct net *net = nf_ct_net(ct);
|
||||
|
||||
return ip6t_do_table(skb, ops->hooknum, in, out, net->ipv6.ip6table_nat);
|
||||
return ip6t_do_table(skb, ops->hooknum, state, net->ipv6.ip6table_nat);
|
||||
}
|
||||
|
||||
static unsigned int ip6table_nat_fn(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return nf_nat_ipv6_fn(ops, skb, in, out, ip6table_nat_do_chain);
|
||||
return nf_nat_ipv6_fn(ops, skb, state, ip6table_nat_do_chain);
|
||||
}
|
||||
|
||||
static unsigned int ip6table_nat_in(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return nf_nat_ipv6_in(ops, skb, in, out, ip6table_nat_do_chain);
|
||||
return nf_nat_ipv6_in(ops, skb, state, ip6table_nat_do_chain);
|
||||
}
|
||||
|
||||
static unsigned int ip6table_nat_out(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return nf_nat_ipv6_out(ops, skb, in, out, ip6table_nat_do_chain);
|
||||
return nf_nat_ipv6_out(ops, skb, state, ip6table_nat_do_chain);
|
||||
}
|
||||
|
||||
static unsigned int ip6table_nat_local_fn(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return nf_nat_ipv6_local_fn(ops, skb, in, out, ip6table_nat_do_chain);
|
||||
return nf_nat_ipv6_local_fn(ops, skb, state, ip6table_nat_do_chain);
|
||||
}
|
||||
|
||||
static struct nf_hook_ops nf_nat_ipv6_ops[] __read_mostly = {
|
||||
|
@ -20,13 +20,11 @@ static const struct xt_table packet_raw = {
|
||||
/* The work comes in here from netfilter.c. */
|
||||
static unsigned int
|
||||
ip6table_raw_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
const struct net *net = dev_net((in != NULL) ? in : out);
|
||||
const struct net *net = dev_net(state->in ? state->in : state->out);
|
||||
|
||||
return ip6t_do_table(skb, ops->hooknum, in, out,
|
||||
net->ipv6.ip6table_raw);
|
||||
return ip6t_do_table(skb, ops->hooknum, state, net->ipv6.ip6table_raw);
|
||||
}
|
||||
|
||||
static struct nf_hook_ops *rawtable_ops __read_mostly;
|
||||
|
@ -37,13 +37,11 @@ static const struct xt_table security_table = {
|
||||
|
||||
static unsigned int
|
||||
ip6table_security_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
const struct net *net = dev_net((in != NULL) ? in : out);
|
||||
const struct net *net = dev_net(state->in ? state->in : state->out);
|
||||
|
||||
return ip6t_do_table(skb, ops->hooknum, in, out,
|
||||
return ip6t_do_table(skb, ops->hooknum, state,
|
||||
net->ipv6.ip6table_security);
|
||||
}
|
||||
|
||||
|
@ -97,9 +97,7 @@ static int ipv6_get_l4proto(const struct sk_buff *skb, unsigned int nhoff,
|
||||
|
||||
static unsigned int ipv6_helper(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
struct nf_conn *ct;
|
||||
const struct nf_conn_help *help;
|
||||
@ -135,9 +133,7 @@ static unsigned int ipv6_helper(const struct nf_hook_ops *ops,
|
||||
|
||||
static unsigned int ipv6_confirm(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
struct nf_conn *ct;
|
||||
enum ip_conntrack_info ctinfo;
|
||||
@ -171,25 +167,21 @@ static unsigned int ipv6_confirm(const struct nf_hook_ops *ops,
|
||||
|
||||
static unsigned int ipv6_conntrack_in(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return nf_conntrack_in(dev_net(in), PF_INET6, ops->hooknum, skb);
|
||||
return nf_conntrack_in(dev_net(state->in), PF_INET6, ops->hooknum, skb);
|
||||
}
|
||||
|
||||
static unsigned int ipv6_conntrack_local(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
/* root is playing with raw sockets. */
|
||||
if (skb->len < sizeof(struct ipv6hdr)) {
|
||||
net_notice_ratelimited("ipv6_conntrack_local: packet too short\n");
|
||||
return NF_ACCEPT;
|
||||
}
|
||||
return nf_conntrack_in(dev_net(out), PF_INET6, ops->hooknum, skb);
|
||||
return nf_conntrack_in(dev_net(state->out), PF_INET6, ops->hooknum, skb);
|
||||
}
|
||||
|
||||
static struct nf_hook_ops ipv6_conntrack_ops[] __read_mostly = {
|
||||
|
@ -54,9 +54,7 @@ static enum ip6_defrag_users nf_ct6_defrag_user(unsigned int hooknum,
|
||||
|
||||
static unsigned int ipv6_defrag(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
struct sk_buff *reasm;
|
||||
|
||||
@ -78,8 +76,8 @@ static unsigned int ipv6_defrag(const struct nf_hook_ops *ops,
|
||||
nf_ct_frag6_consume_orig(reasm);
|
||||
|
||||
NF_HOOK_THRESH(NFPROTO_IPV6, ops->hooknum, reasm,
|
||||
(struct net_device *) in, (struct net_device *) out,
|
||||
okfn, NF_IP6_PRI_CONNTRACK_DEFRAG + 1);
|
||||
state->in, state->out,
|
||||
state->okfn, NF_IP6_PRI_CONNTRACK_DEFRAG + 1);
|
||||
|
||||
return NF_STOLEN;
|
||||
}
|
||||
|
@ -263,11 +263,10 @@ EXPORT_SYMBOL_GPL(nf_nat_icmpv6_reply_translation);
|
||||
|
||||
unsigned int
|
||||
nf_nat_ipv6_fn(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
unsigned int (*do_chain)(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct nf_conn *ct))
|
||||
{
|
||||
struct nf_conn *ct;
|
||||
@ -318,7 +317,7 @@ nf_nat_ipv6_fn(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
if (!nf_nat_initialized(ct, maniptype)) {
|
||||
unsigned int ret;
|
||||
|
||||
ret = do_chain(ops, skb, in, out, ct);
|
||||
ret = do_chain(ops, skb, state, ct);
|
||||
if (ret != NF_ACCEPT)
|
||||
return ret;
|
||||
|
||||
@ -332,7 +331,7 @@ nf_nat_ipv6_fn(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
pr_debug("Already setup manip %s for ct %p\n",
|
||||
maniptype == NF_NAT_MANIP_SRC ? "SRC" : "DST",
|
||||
ct);
|
||||
if (nf_nat_oif_changed(ops->hooknum, ctinfo, nat, out))
|
||||
if (nf_nat_oif_changed(ops->hooknum, ctinfo, nat, state->out))
|
||||
goto oif_changed;
|
||||
}
|
||||
break;
|
||||
@ -341,7 +340,7 @@ nf_nat_ipv6_fn(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
/* ESTABLISHED */
|
||||
NF_CT_ASSERT(ctinfo == IP_CT_ESTABLISHED ||
|
||||
ctinfo == IP_CT_ESTABLISHED_REPLY);
|
||||
if (nf_nat_oif_changed(ops->hooknum, ctinfo, nat, out))
|
||||
if (nf_nat_oif_changed(ops->hooknum, ctinfo, nat, state->out))
|
||||
goto oif_changed;
|
||||
}
|
||||
|
||||
@ -355,17 +354,16 @@ EXPORT_SYMBOL_GPL(nf_nat_ipv6_fn);
|
||||
|
||||
unsigned int
|
||||
nf_nat_ipv6_in(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
unsigned int (*do_chain)(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct nf_conn *ct))
|
||||
{
|
||||
unsigned int ret;
|
||||
struct in6_addr daddr = ipv6_hdr(skb)->daddr;
|
||||
|
||||
ret = nf_nat_ipv6_fn(ops, skb, in, out, do_chain);
|
||||
ret = nf_nat_ipv6_fn(ops, skb, state, do_chain);
|
||||
if (ret != NF_DROP && ret != NF_STOLEN &&
|
||||
ipv6_addr_cmp(&daddr, &ipv6_hdr(skb)->daddr))
|
||||
skb_dst_drop(skb);
|
||||
@ -376,11 +374,10 @@ EXPORT_SYMBOL_GPL(nf_nat_ipv6_in);
|
||||
|
||||
unsigned int
|
||||
nf_nat_ipv6_out(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
unsigned int (*do_chain)(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct nf_conn *ct))
|
||||
{
|
||||
#ifdef CONFIG_XFRM
|
||||
@ -394,7 +391,7 @@ nf_nat_ipv6_out(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
if (skb->len < sizeof(struct ipv6hdr))
|
||||
return NF_ACCEPT;
|
||||
|
||||
ret = nf_nat_ipv6_fn(ops, skb, in, out, do_chain);
|
||||
ret = nf_nat_ipv6_fn(ops, skb, state, do_chain);
|
||||
#ifdef CONFIG_XFRM
|
||||
if (ret != NF_DROP && ret != NF_STOLEN &&
|
||||
!(IP6CB(skb)->flags & IP6SKB_XFRM_TRANSFORMED) &&
|
||||
@ -418,11 +415,10 @@ EXPORT_SYMBOL_GPL(nf_nat_ipv6_out);
|
||||
|
||||
unsigned int
|
||||
nf_nat_ipv6_local_fn(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
unsigned int (*do_chain)(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct nf_conn *ct))
|
||||
{
|
||||
const struct nf_conn *ct;
|
||||
@ -434,7 +430,7 @@ nf_nat_ipv6_local_fn(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
if (skb->len < sizeof(struct ipv6hdr))
|
||||
return NF_ACCEPT;
|
||||
|
||||
ret = nf_nat_ipv6_fn(ops, skb, in, out, do_chain);
|
||||
ret = nf_nat_ipv6_fn(ops, skb, state, do_chain);
|
||||
if (ret != NF_DROP && ret != NF_STOLEN &&
|
||||
(ct = nf_ct_get(skb, &ctinfo)) != NULL) {
|
||||
enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
|
||||
|
@ -18,14 +18,12 @@
|
||||
|
||||
static unsigned int nft_do_chain_ipv6(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
struct nft_pktinfo pkt;
|
||||
|
||||
/* malformed packet, drop it */
|
||||
if (nft_set_pktinfo_ipv6(&pkt, ops, skb, in, out) < 0)
|
||||
if (nft_set_pktinfo_ipv6(&pkt, ops, skb, state) < 0)
|
||||
return NF_DROP;
|
||||
|
||||
return nft_do_chain(&pkt, ops);
|
||||
@ -33,9 +31,7 @@ static unsigned int nft_do_chain_ipv6(const struct nf_hook_ops *ops,
|
||||
|
||||
static unsigned int nft_ipv6_output(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
if (unlikely(skb->len < sizeof(struct ipv6hdr))) {
|
||||
if (net_ratelimit())
|
||||
@ -44,7 +40,7 @@ static unsigned int nft_ipv6_output(const struct nf_hook_ops *ops,
|
||||
return NF_ACCEPT;
|
||||
}
|
||||
|
||||
return nft_do_chain_ipv6(ops, skb, in, out, okfn);
|
||||
return nft_do_chain_ipv6(ops, skb, state);
|
||||
}
|
||||
|
||||
struct nft_af_info nft_af_ipv6 __read_mostly = {
|
||||
|
@ -26,51 +26,42 @@
|
||||
|
||||
static unsigned int nft_nat_do_chain(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
const struct nf_hook_state *state,
|
||||
struct nf_conn *ct)
|
||||
{
|
||||
struct nft_pktinfo pkt;
|
||||
|
||||
nft_set_pktinfo_ipv6(&pkt, ops, skb, in, out);
|
||||
nft_set_pktinfo_ipv6(&pkt, ops, skb, state);
|
||||
|
||||
return nft_do_chain(&pkt, ops);
|
||||
}
|
||||
|
||||
static unsigned int nft_nat_ipv6_fn(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return nf_nat_ipv6_fn(ops, skb, in, out, nft_nat_do_chain);
|
||||
return nf_nat_ipv6_fn(ops, skb, state, nft_nat_do_chain);
|
||||
}
|
||||
|
||||
static unsigned int nft_nat_ipv6_in(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return nf_nat_ipv6_in(ops, skb, in, out, nft_nat_do_chain);
|
||||
return nf_nat_ipv6_in(ops, skb, state, nft_nat_do_chain);
|
||||
}
|
||||
|
||||
static unsigned int nft_nat_ipv6_out(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return nf_nat_ipv6_out(ops, skb, in, out, nft_nat_do_chain);
|
||||
return nf_nat_ipv6_out(ops, skb, state, nft_nat_do_chain);
|
||||
}
|
||||
|
||||
static unsigned int nft_nat_ipv6_local_fn(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return nf_nat_ipv6_local_fn(ops, skb, in, out, nft_nat_do_chain);
|
||||
return nf_nat_ipv6_local_fn(ops, skb, state, nft_nat_do_chain);
|
||||
}
|
||||
|
||||
static const struct nf_chain_type nft_chain_nat_ipv6 = {
|
||||
|
@ -24,9 +24,7 @@
|
||||
|
||||
static unsigned int nf_route_table_hook(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
unsigned int ret;
|
||||
struct nft_pktinfo pkt;
|
||||
@ -35,7 +33,7 @@ static unsigned int nf_route_table_hook(const struct nf_hook_ops *ops,
|
||||
u32 mark, flowlabel;
|
||||
|
||||
/* malformed packet, drop it */
|
||||
if (nft_set_pktinfo_ipv6(&pkt, ops, skb, in, out) < 0)
|
||||
if (nft_set_pktinfo_ipv6(&pkt, ops, skb, state) < 0)
|
||||
return NF_DROP;
|
||||
|
||||
/* save source/dest address, mark, hoplimit, flowlabel, priority */
|
||||
|
@ -120,12 +120,8 @@ EXPORT_SYMBOL(nf_unregister_hooks);
|
||||
|
||||
unsigned int nf_iterate(struct list_head *head,
|
||||
struct sk_buff *skb,
|
||||
unsigned int hook,
|
||||
const struct net_device *indev,
|
||||
const struct net_device *outdev,
|
||||
struct nf_hook_ops **elemp,
|
||||
int (*okfn)(struct sk_buff *),
|
||||
int hook_thresh)
|
||||
struct nf_hook_state *state,
|
||||
struct nf_hook_ops **elemp)
|
||||
{
|
||||
unsigned int verdict;
|
||||
|
||||
@ -134,19 +130,19 @@ unsigned int nf_iterate(struct list_head *head,
|
||||
* function because of risk of continuing from deleted element.
|
||||
*/
|
||||
list_for_each_entry_continue_rcu((*elemp), head, list) {
|
||||
if (hook_thresh > (*elemp)->priority)
|
||||
if (state->thresh > (*elemp)->priority)
|
||||
continue;
|
||||
|
||||
/* Optimization: we don't need to hold module
|
||||
reference here, since function can't sleep. --RR */
|
||||
repeat:
|
||||
verdict = (*elemp)->hook(*elemp, skb, indev, outdev, okfn);
|
||||
verdict = (*elemp)->hook(*elemp, skb, state);
|
||||
if (verdict != NF_ACCEPT) {
|
||||
#ifdef CONFIG_NETFILTER_DEBUG
|
||||
if (unlikely((verdict & NF_VERDICT_MASK)
|
||||
> NF_MAX_VERDICT)) {
|
||||
NFDEBUG("Evil return from %p(%u).\n",
|
||||
(*elemp)->hook, hook);
|
||||
(*elemp)->hook, state->hook);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
@ -161,11 +157,7 @@ unsigned int nf_iterate(struct list_head *head,
|
||||
|
||||
/* Returns 1 if okfn() needs to be executed by the caller,
|
||||
* -EPERM for NF_DROP, 0 otherwise. */
|
||||
int nf_hook_slow(u_int8_t pf, unsigned int hook, struct sk_buff *skb,
|
||||
struct net_device *indev,
|
||||
struct net_device *outdev,
|
||||
int (*okfn)(struct sk_buff *),
|
||||
int hook_thresh)
|
||||
int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state)
|
||||
{
|
||||
struct nf_hook_ops *elem;
|
||||
unsigned int verdict;
|
||||
@ -174,10 +166,11 @@ int nf_hook_slow(u_int8_t pf, unsigned int hook, struct sk_buff *skb,
|
||||
/* We may already have this, but read-locks nest anyway */
|
||||
rcu_read_lock();
|
||||
|
||||
elem = list_entry_rcu(&nf_hooks[pf][hook], struct nf_hook_ops, list);
|
||||
elem = list_entry_rcu(&nf_hooks[state->pf][state->hook],
|
||||
struct nf_hook_ops, list);
|
||||
next_hook:
|
||||
verdict = nf_iterate(&nf_hooks[pf][hook], skb, hook, indev,
|
||||
outdev, &elem, okfn, hook_thresh);
|
||||
verdict = nf_iterate(&nf_hooks[state->pf][state->hook], skb, state,
|
||||
&elem);
|
||||
if (verdict == NF_ACCEPT || verdict == NF_STOP) {
|
||||
ret = 1;
|
||||
} else if ((verdict & NF_VERDICT_MASK) == NF_DROP) {
|
||||
@ -186,8 +179,8 @@ int nf_hook_slow(u_int8_t pf, unsigned int hook, struct sk_buff *skb,
|
||||
if (ret == 0)
|
||||
ret = -EPERM;
|
||||
} else if ((verdict & NF_VERDICT_MASK) == NF_QUEUE) {
|
||||
int err = nf_queue(skb, elem, pf, hook, indev, outdev, okfn,
|
||||
verdict >> NF_VERDICT_QBITS);
|
||||
int err = nf_queue(skb, elem, state,
|
||||
verdict >> NF_VERDICT_QBITS);
|
||||
if (err < 0) {
|
||||
if (err == -ECANCELED)
|
||||
goto next_hook;
|
||||
|
@ -1272,8 +1272,7 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb, int af)
|
||||
*/
|
||||
static unsigned int
|
||||
ip_vs_reply4(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return ip_vs_out(ops->hooknum, skb, AF_INET);
|
||||
}
|
||||
@ -1284,8 +1283,7 @@ ip_vs_reply4(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
*/
|
||||
static unsigned int
|
||||
ip_vs_local_reply4(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return ip_vs_out(ops->hooknum, skb, AF_INET);
|
||||
}
|
||||
@ -1299,8 +1297,7 @@ ip_vs_local_reply4(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
*/
|
||||
static unsigned int
|
||||
ip_vs_reply6(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return ip_vs_out(ops->hooknum, skb, AF_INET6);
|
||||
}
|
||||
@ -1311,8 +1308,7 @@ ip_vs_reply6(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
*/
|
||||
static unsigned int
|
||||
ip_vs_local_reply6(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return ip_vs_out(ops->hooknum, skb, AF_INET6);
|
||||
}
|
||||
@ -1769,9 +1765,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
|
||||
*/
|
||||
static unsigned int
|
||||
ip_vs_remote_request4(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return ip_vs_in(ops->hooknum, skb, AF_INET);
|
||||
}
|
||||
@ -1782,8 +1776,7 @@ ip_vs_remote_request4(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
*/
|
||||
static unsigned int
|
||||
ip_vs_local_request4(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return ip_vs_in(ops->hooknum, skb, AF_INET);
|
||||
}
|
||||
@ -1796,9 +1789,7 @@ ip_vs_local_request4(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
*/
|
||||
static unsigned int
|
||||
ip_vs_remote_request6(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return ip_vs_in(ops->hooknum, skb, AF_INET6);
|
||||
}
|
||||
@ -1809,8 +1800,7 @@ ip_vs_remote_request6(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
*/
|
||||
static unsigned int
|
||||
ip_vs_local_request6(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return ip_vs_in(ops->hooknum, skb, AF_INET6);
|
||||
}
|
||||
@ -1829,8 +1819,7 @@ ip_vs_local_request6(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
*/
|
||||
static unsigned int
|
||||
ip_vs_forward_icmp(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
int r;
|
||||
struct net *net;
|
||||
@ -1851,8 +1840,7 @@ ip_vs_forward_icmp(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
#ifdef CONFIG_IP_VS_IPV6
|
||||
static unsigned int
|
||||
ip_vs_forward_icmp_v6(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
||||
const struct net_device *in, const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
int r;
|
||||
struct net *net;
|
||||
|
@ -14,16 +14,11 @@
|
||||
|
||||
/* core.c */
|
||||
unsigned int nf_iterate(struct list_head *head, struct sk_buff *skb,
|
||||
unsigned int hook, const struct net_device *indev,
|
||||
const struct net_device *outdev,
|
||||
struct nf_hook_ops **elemp,
|
||||
int (*okfn)(struct sk_buff *), int hook_thresh);
|
||||
struct nf_hook_state *state, struct nf_hook_ops **elemp);
|
||||
|
||||
/* nf_queue.c */
|
||||
int nf_queue(struct sk_buff *skb, struct nf_hook_ops *elem, u_int8_t pf,
|
||||
unsigned int hook, struct net_device *indev,
|
||||
struct net_device *outdev, int (*okfn)(struct sk_buff *),
|
||||
unsigned int queuenum);
|
||||
int nf_queue(struct sk_buff *skb, struct nf_hook_ops *elem,
|
||||
struct nf_hook_state *state, unsigned int queuenum);
|
||||
int __init netfilter_queue_init(void);
|
||||
|
||||
/* nf_log.c */
|
||||
|
@ -47,11 +47,13 @@ EXPORT_SYMBOL(nf_unregister_queue_handler);
|
||||
|
||||
void nf_queue_entry_release_refs(struct nf_queue_entry *entry)
|
||||
{
|
||||
struct nf_hook_state *state = &entry->state;
|
||||
|
||||
/* Release those devices we held, or Alexey will kill me. */
|
||||
if (entry->indev)
|
||||
dev_put(entry->indev);
|
||||
if (entry->outdev)
|
||||
dev_put(entry->outdev);
|
||||
if (state->in)
|
||||
dev_put(state->in);
|
||||
if (state->out)
|
||||
dev_put(state->out);
|
||||
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
|
||||
if (entry->skb->nf_bridge) {
|
||||
struct nf_bridge_info *nf_bridge = entry->skb->nf_bridge;
|
||||
@ -70,13 +72,15 @@ EXPORT_SYMBOL_GPL(nf_queue_entry_release_refs);
|
||||
/* Bump dev refs so they don't vanish while packet is out */
|
||||
bool nf_queue_entry_get_refs(struct nf_queue_entry *entry)
|
||||
{
|
||||
struct nf_hook_state *state = &entry->state;
|
||||
|
||||
if (!try_module_get(entry->elem->owner))
|
||||
return false;
|
||||
|
||||
if (entry->indev)
|
||||
dev_hold(entry->indev);
|
||||
if (entry->outdev)
|
||||
dev_hold(entry->outdev);
|
||||
if (state->in)
|
||||
dev_hold(state->in);
|
||||
if (state->out)
|
||||
dev_hold(state->out);
|
||||
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
|
||||
if (entry->skb->nf_bridge) {
|
||||
struct nf_bridge_info *nf_bridge = entry->skb->nf_bridge;
|
||||
@ -100,12 +104,9 @@ EXPORT_SYMBOL_GPL(nf_queue_entry_get_refs);
|
||||
* through nf_reinject().
|
||||
*/
|
||||
int nf_queue(struct sk_buff *skb,
|
||||
struct nf_hook_ops *elem,
|
||||
u_int8_t pf, unsigned int hook,
|
||||
struct net_device *indev,
|
||||
struct net_device *outdev,
|
||||
int (*okfn)(struct sk_buff *),
|
||||
unsigned int queuenum)
|
||||
struct nf_hook_ops *elem,
|
||||
struct nf_hook_state *state,
|
||||
unsigned int queuenum)
|
||||
{
|
||||
int status = -ENOENT;
|
||||
struct nf_queue_entry *entry = NULL;
|
||||
@ -121,7 +122,7 @@ int nf_queue(struct sk_buff *skb,
|
||||
goto err_unlock;
|
||||
}
|
||||
|
||||
afinfo = nf_get_afinfo(pf);
|
||||
afinfo = nf_get_afinfo(state->pf);
|
||||
if (!afinfo)
|
||||
goto err_unlock;
|
||||
|
||||
@ -134,11 +135,7 @@ int nf_queue(struct sk_buff *skb,
|
||||
*entry = (struct nf_queue_entry) {
|
||||
.skb = skb,
|
||||
.elem = elem,
|
||||
.pf = pf,
|
||||
.hook = hook,
|
||||
.indev = indev,
|
||||
.outdev = outdev,
|
||||
.okfn = okfn,
|
||||
.state = *state,
|
||||
.size = sizeof(*entry) + afinfo->route_key_size,
|
||||
};
|
||||
|
||||
@ -184,30 +181,29 @@ void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict)
|
||||
}
|
||||
|
||||
if (verdict == NF_ACCEPT) {
|
||||
afinfo = nf_get_afinfo(entry->pf);
|
||||
afinfo = nf_get_afinfo(entry->state.pf);
|
||||
if (!afinfo || afinfo->reroute(skb, entry) < 0)
|
||||
verdict = NF_DROP;
|
||||
}
|
||||
|
||||
entry->state.thresh = INT_MIN;
|
||||
|
||||
if (verdict == NF_ACCEPT) {
|
||||
next_hook:
|
||||
verdict = nf_iterate(&nf_hooks[entry->pf][entry->hook],
|
||||
skb, entry->hook,
|
||||
entry->indev, entry->outdev, &elem,
|
||||
entry->okfn, INT_MIN);
|
||||
verdict = nf_iterate(&nf_hooks[entry->state.pf][entry->state.hook],
|
||||
skb, &entry->state, &elem);
|
||||
}
|
||||
|
||||
switch (verdict & NF_VERDICT_MASK) {
|
||||
case NF_ACCEPT:
|
||||
case NF_STOP:
|
||||
local_bh_disable();
|
||||
entry->okfn(skb);
|
||||
entry->state.okfn(skb);
|
||||
local_bh_enable();
|
||||
break;
|
||||
case NF_QUEUE:
|
||||
err = nf_queue(skb, elem, entry->pf, entry->hook,
|
||||
entry->indev, entry->outdev, entry->okfn,
|
||||
verdict >> NF_VERDICT_QBITS);
|
||||
err = nf_queue(skb, elem, &entry->state,
|
||||
verdict >> NF_VERDICT_QBITS);
|
||||
if (err < 0) {
|
||||
if (err == -ECANCELED)
|
||||
goto next_hook;
|
||||
|
@ -314,13 +314,13 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
|
||||
if (entskb->tstamp.tv64)
|
||||
size += nla_total_size(sizeof(struct nfqnl_msg_packet_timestamp));
|
||||
|
||||
if (entry->hook <= NF_INET_FORWARD ||
|
||||
(entry->hook == NF_INET_POST_ROUTING && entskb->sk == NULL))
|
||||
if (entry->state.hook <= NF_INET_FORWARD ||
|
||||
(entry->state.hook == NF_INET_POST_ROUTING && entskb->sk == NULL))
|
||||
csum_verify = !skb_csum_unnecessary(entskb);
|
||||
else
|
||||
csum_verify = false;
|
||||
|
||||
outdev = entry->outdev;
|
||||
outdev = entry->state.out;
|
||||
|
||||
switch ((enum nfqnl_config_mode)ACCESS_ONCE(queue->copy_mode)) {
|
||||
case NFQNL_COPY_META:
|
||||
@ -368,23 +368,23 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
|
||||
return NULL;
|
||||
}
|
||||
nfmsg = nlmsg_data(nlh);
|
||||
nfmsg->nfgen_family = entry->pf;
|
||||
nfmsg->nfgen_family = entry->state.pf;
|
||||
nfmsg->version = NFNETLINK_V0;
|
||||
nfmsg->res_id = htons(queue->queue_num);
|
||||
|
||||
nla = __nla_reserve(skb, NFQA_PACKET_HDR, sizeof(*pmsg));
|
||||
pmsg = nla_data(nla);
|
||||
pmsg->hw_protocol = entskb->protocol;
|
||||
pmsg->hook = entry->hook;
|
||||
pmsg->hook = entry->state.hook;
|
||||
*packet_id_ptr = &pmsg->packet_id;
|
||||
|
||||
indev = entry->indev;
|
||||
indev = entry->state.in;
|
||||
if (indev) {
|
||||
#if !IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
|
||||
if (nla_put_be32(skb, NFQA_IFINDEX_INDEV, htonl(indev->ifindex)))
|
||||
goto nla_put_failure;
|
||||
#else
|
||||
if (entry->pf == PF_BRIDGE) {
|
||||
if (entry->state.pf == PF_BRIDGE) {
|
||||
/* Case 1: indev is physical input device, we need to
|
||||
* look for bridge group (when called from
|
||||
* netfilter_bridge) */
|
||||
@ -414,7 +414,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
|
||||
if (nla_put_be32(skb, NFQA_IFINDEX_OUTDEV, htonl(outdev->ifindex)))
|
||||
goto nla_put_failure;
|
||||
#else
|
||||
if (entry->pf == PF_BRIDGE) {
|
||||
if (entry->state.pf == PF_BRIDGE) {
|
||||
/* Case 1: outdev is physical output device, we need to
|
||||
* look for bridge group (when called from
|
||||
* netfilter_bridge) */
|
||||
@ -633,8 +633,8 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
|
||||
struct nfqnl_instance *queue;
|
||||
struct sk_buff *skb, *segs;
|
||||
int err = -ENOBUFS;
|
||||
struct net *net = dev_net(entry->indev ?
|
||||
entry->indev : entry->outdev);
|
||||
struct net *net = dev_net(entry->state.in ?
|
||||
entry->state.in : entry->state.out);
|
||||
struct nfnl_queue_net *q = nfnl_queue_pernet(net);
|
||||
|
||||
/* rcu_read_lock()ed by nf_hook_slow() */
|
||||
@ -647,7 +647,7 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
|
||||
|
||||
skb = entry->skb;
|
||||
|
||||
switch (entry->pf) {
|
||||
switch (entry->state.pf) {
|
||||
case NFPROTO_IPV4:
|
||||
skb->protocol = htons(ETH_P_IP);
|
||||
break;
|
||||
@ -757,11 +757,11 @@ nfqnl_set_mode(struct nfqnl_instance *queue,
|
||||
static int
|
||||
dev_cmp(struct nf_queue_entry *entry, unsigned long ifindex)
|
||||
{
|
||||
if (entry->indev)
|
||||
if (entry->indev->ifindex == ifindex)
|
||||
if (entry->state.in)
|
||||
if (entry->state.in->ifindex == ifindex)
|
||||
return 1;
|
||||
if (entry->outdev)
|
||||
if (entry->outdev->ifindex == ifindex)
|
||||
if (entry->state.out)
|
||||
if (entry->state.out->ifindex == ifindex)
|
||||
return 1;
|
||||
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
|
||||
if (entry->skb->nf_bridge) {
|
||||
|
@ -4852,21 +4852,17 @@ static unsigned int selinux_ip_forward(struct sk_buff *skb,
|
||||
|
||||
static unsigned int selinux_ipv4_forward(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return selinux_ip_forward(skb, in, PF_INET);
|
||||
return selinux_ip_forward(skb, state->in, PF_INET);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
|
||||
static unsigned int selinux_ipv6_forward(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return selinux_ip_forward(skb, in, PF_INET6);
|
||||
return selinux_ip_forward(skb, state->in, PF_INET6);
|
||||
}
|
||||
#endif /* IPV6 */
|
||||
|
||||
@ -4914,9 +4910,7 @@ static unsigned int selinux_ip_output(struct sk_buff *skb,
|
||||
|
||||
static unsigned int selinux_ipv4_output(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return selinux_ip_output(skb, PF_INET);
|
||||
}
|
||||
@ -5091,21 +5085,17 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb,
|
||||
|
||||
static unsigned int selinux_ipv4_postroute(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return selinux_ip_postroute(skb, out, PF_INET);
|
||||
return selinux_ip_postroute(skb, state->out, PF_INET);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
|
||||
static unsigned int selinux_ipv6_postroute(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
return selinux_ip_postroute(skb, out, PF_INET6);
|
||||
return selinux_ip_postroute(skb, state->out, PF_INET6);
|
||||
}
|
||||
#endif /* IPV6 */
|
||||
|
||||
|
@ -23,9 +23,7 @@
|
||||
|
||||
static unsigned int smack_ipv6_output(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
struct socket_smack *ssp;
|
||||
struct smack_known *skp;
|
||||
@ -42,9 +40,7 @@ static unsigned int smack_ipv6_output(const struct nf_hook_ops *ops,
|
||||
|
||||
static unsigned int smack_ipv4_output(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
const struct nf_hook_state *state)
|
||||
{
|
||||
struct socket_smack *ssp;
|
||||
struct smack_known *skp;
|
||||
|
Loading…
Reference in New Issue
Block a user