netfilter: Pass net to nf_dup_ipv4 and nf_dup_ipv6
This allows them to stop guessing the network namespace with pick_net. Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
This commit is contained in:
committed by
Pablo Neira Ayuso
parent
88182a0e0c
commit
206e8c0075
@ -1,7 +1,7 @@
|
|||||||
#ifndef _NF_DUP_IPV4_H_
|
#ifndef _NF_DUP_IPV4_H_
|
||||||
#define _NF_DUP_IPV4_H_
|
#define _NF_DUP_IPV4_H_
|
||||||
|
|
||||||
void nf_dup_ipv4(struct sk_buff *skb, unsigned int hooknum,
|
void nf_dup_ipv4(struct net *net, struct sk_buff *skb, unsigned int hooknum,
|
||||||
const struct in_addr *gw, int oif);
|
const struct in_addr *gw, int oif);
|
||||||
|
|
||||||
#endif /* _NF_DUP_IPV4_H_ */
|
#endif /* _NF_DUP_IPV4_H_ */
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef _NF_DUP_IPV6_H_
|
#ifndef _NF_DUP_IPV6_H_
|
||||||
#define _NF_DUP_IPV6_H_
|
#define _NF_DUP_IPV6_H_
|
||||||
|
|
||||||
void nf_dup_ipv6(struct sk_buff *skb, unsigned int hooknum,
|
void nf_dup_ipv6(struct net *net, struct sk_buff *skb, unsigned int hooknum,
|
||||||
const struct in6_addr *gw, int oif);
|
const struct in6_addr *gw, int oif);
|
||||||
|
|
||||||
#endif /* _NF_DUP_IPV6_H_ */
|
#endif /* _NF_DUP_IPV6_H_ */
|
||||||
|
@ -23,25 +23,10 @@
|
|||||||
#include <net/netfilter/nf_conntrack.h>
|
#include <net/netfilter/nf_conntrack.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static struct net *pick_net(struct sk_buff *skb)
|
static bool nf_dup_ipv4_route(struct net *net, struct sk_buff *skb,
|
||||||
{
|
const struct in_addr *gw, int oif)
|
||||||
#ifdef CONFIG_NET_NS
|
|
||||||
const struct dst_entry *dst;
|
|
||||||
|
|
||||||
if (skb->dev != NULL)
|
|
||||||
return dev_net(skb->dev);
|
|
||||||
dst = skb_dst(skb);
|
|
||||||
if (dst != NULL && dst->dev != NULL)
|
|
||||||
return dev_net(dst->dev);
|
|
||||||
#endif
|
|
||||||
return &init_net;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool nf_dup_ipv4_route(struct sk_buff *skb, const struct in_addr *gw,
|
|
||||||
int oif)
|
|
||||||
{
|
{
|
||||||
const struct iphdr *iph = ip_hdr(skb);
|
const struct iphdr *iph = ip_hdr(skb);
|
||||||
struct net *net = pick_net(skb);
|
|
||||||
struct rtable *rt;
|
struct rtable *rt;
|
||||||
struct flowi4 fl4;
|
struct flowi4 fl4;
|
||||||
|
|
||||||
@ -65,7 +50,7 @@ static bool nf_dup_ipv4_route(struct sk_buff *skb, const struct in_addr *gw,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nf_dup_ipv4(struct sk_buff *skb, unsigned int hooknum,
|
void nf_dup_ipv4(struct net *net, struct sk_buff *skb, unsigned int hooknum,
|
||||||
const struct in_addr *gw, int oif)
|
const struct in_addr *gw, int oif)
|
||||||
{
|
{
|
||||||
struct iphdr *iph;
|
struct iphdr *iph;
|
||||||
@ -105,7 +90,7 @@ void nf_dup_ipv4(struct sk_buff *skb, unsigned int hooknum,
|
|||||||
--iph->ttl;
|
--iph->ttl;
|
||||||
ip_send_check(iph);
|
ip_send_check(iph);
|
||||||
|
|
||||||
if (nf_dup_ipv4_route(skb, gw, oif)) {
|
if (nf_dup_ipv4_route(net, skb, gw, oif)) {
|
||||||
__this_cpu_write(nf_skb_duplicated, true);
|
__this_cpu_write(nf_skb_duplicated, true);
|
||||||
ip_local_out(skb);
|
ip_local_out(skb);
|
||||||
__this_cpu_write(nf_skb_duplicated, false);
|
__this_cpu_write(nf_skb_duplicated, false);
|
||||||
|
@ -30,7 +30,7 @@ static void nft_dup_ipv4_eval(const struct nft_expr *expr,
|
|||||||
};
|
};
|
||||||
int oif = regs->data[priv->sreg_dev];
|
int oif = regs->data[priv->sreg_dev];
|
||||||
|
|
||||||
nf_dup_ipv4(pkt->skb, pkt->hook, &gw, oif);
|
nf_dup_ipv4(pkt->net, pkt->skb, pkt->hook, &gw, oif);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nft_dup_ipv4_init(const struct nft_ctx *ctx,
|
static int nft_dup_ipv4_init(const struct nft_ctx *ctx,
|
||||||
|
@ -19,25 +19,10 @@
|
|||||||
#include <net/netfilter/nf_conntrack.h>
|
#include <net/netfilter/nf_conntrack.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static struct net *pick_net(struct sk_buff *skb)
|
static bool nf_dup_ipv6_route(struct net *net, struct sk_buff *skb,
|
||||||
{
|
const struct in6_addr *gw, int oif)
|
||||||
#ifdef CONFIG_NET_NS
|
|
||||||
const struct dst_entry *dst;
|
|
||||||
|
|
||||||
if (skb->dev != NULL)
|
|
||||||
return dev_net(skb->dev);
|
|
||||||
dst = skb_dst(skb);
|
|
||||||
if (dst != NULL && dst->dev != NULL)
|
|
||||||
return dev_net(dst->dev);
|
|
||||||
#endif
|
|
||||||
return &init_net;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool nf_dup_ipv6_route(struct sk_buff *skb, const struct in6_addr *gw,
|
|
||||||
int oif)
|
|
||||||
{
|
{
|
||||||
const struct ipv6hdr *iph = ipv6_hdr(skb);
|
const struct ipv6hdr *iph = ipv6_hdr(skb);
|
||||||
struct net *net = pick_net(skb);
|
|
||||||
struct dst_entry *dst;
|
struct dst_entry *dst;
|
||||||
struct flowi6 fl6;
|
struct flowi6 fl6;
|
||||||
|
|
||||||
@ -61,7 +46,7 @@ static bool nf_dup_ipv6_route(struct sk_buff *skb, const struct in6_addr *gw,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nf_dup_ipv6(struct sk_buff *skb, unsigned int hooknum,
|
void nf_dup_ipv6(struct net *net, struct sk_buff *skb, unsigned int hooknum,
|
||||||
const struct in6_addr *gw, int oif)
|
const struct in6_addr *gw, int oif)
|
||||||
{
|
{
|
||||||
if (this_cpu_read(nf_skb_duplicated))
|
if (this_cpu_read(nf_skb_duplicated))
|
||||||
@ -81,7 +66,7 @@ void nf_dup_ipv6(struct sk_buff *skb, unsigned int hooknum,
|
|||||||
struct ipv6hdr *iph = ipv6_hdr(skb);
|
struct ipv6hdr *iph = ipv6_hdr(skb);
|
||||||
--iph->hop_limit;
|
--iph->hop_limit;
|
||||||
}
|
}
|
||||||
if (nf_dup_ipv6_route(skb, gw, oif)) {
|
if (nf_dup_ipv6_route(net, skb, gw, oif)) {
|
||||||
__this_cpu_write(nf_skb_duplicated, true);
|
__this_cpu_write(nf_skb_duplicated, true);
|
||||||
ip6_local_out(skb);
|
ip6_local_out(skb);
|
||||||
__this_cpu_write(nf_skb_duplicated, false);
|
__this_cpu_write(nf_skb_duplicated, false);
|
||||||
|
@ -28,7 +28,7 @@ static void nft_dup_ipv6_eval(const struct nft_expr *expr,
|
|||||||
struct in6_addr *gw = (struct in6_addr *)®s->data[priv->sreg_addr];
|
struct in6_addr *gw = (struct in6_addr *)®s->data[priv->sreg_addr];
|
||||||
int oif = regs->data[priv->sreg_dev];
|
int oif = regs->data[priv->sreg_dev];
|
||||||
|
|
||||||
nf_dup_ipv6(pkt->skb, pkt->hook, gw, oif);
|
nf_dup_ipv6(pkt->net, pkt->skb, pkt->hook, gw, oif);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nft_dup_ipv6_init(const struct nft_ctx *ctx,
|
static int nft_dup_ipv6_init(const struct nft_ctx *ctx,
|
||||||
|
@ -32,7 +32,7 @@ tee_tg4(struct sk_buff *skb, const struct xt_action_param *par)
|
|||||||
{
|
{
|
||||||
const struct xt_tee_tginfo *info = par->targinfo;
|
const struct xt_tee_tginfo *info = par->targinfo;
|
||||||
|
|
||||||
nf_dup_ipv4(skb, par->hooknum, &info->gw.in, info->priv->oif);
|
nf_dup_ipv4(par->net, skb, par->hooknum, &info->gw.in, info->priv->oif);
|
||||||
|
|
||||||
return XT_CONTINUE;
|
return XT_CONTINUE;
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ tee_tg6(struct sk_buff *skb, const struct xt_action_param *par)
|
|||||||
{
|
{
|
||||||
const struct xt_tee_tginfo *info = par->targinfo;
|
const struct xt_tee_tginfo *info = par->targinfo;
|
||||||
|
|
||||||
nf_dup_ipv6(skb, par->hooknum, &info->gw.in6, info->priv->oif);
|
nf_dup_ipv6(par->net, skb, par->hooknum, &info->gw.in6, info->priv->oif);
|
||||||
|
|
||||||
return XT_CONTINUE;
|
return XT_CONTINUE;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user