netfilter: move route indirection to struct nf_ipv6_ops
We cannot make a direct call to nf_ip6_route() because that would result in autoloading the 'ipv6' module because of symbol dependencies. Therefore, define route indirection in nf_ipv6_ops where this really belongs to. For IPv4, we can indeed make a direct function call, which is faster, given IPv4 is built-in in the networking code by default. Still, CONFIG_INET=n and CONFIG_NETFILTER=y is possible, so define empty inline stub for IPv4 in such case. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
This commit is contained in:
Родитель
7db9a51e0f
Коммит
3f87c08c61
|
@ -311,8 +311,6 @@ struct nf_queue_entry;
|
||||||
|
|
||||||
struct nf_afinfo {
|
struct nf_afinfo {
|
||||||
unsigned short family;
|
unsigned short family;
|
||||||
int (*route)(struct net *net, struct dst_entry **dst,
|
|
||||||
struct flowi *fl, bool strict);
|
|
||||||
int (*reroute)(struct net *net, struct sk_buff *skb,
|
int (*reroute)(struct net *net, struct sk_buff *skb,
|
||||||
const struct nf_queue_entry *entry);
|
const struct nf_queue_entry *entry);
|
||||||
int route_key_size;
|
int route_key_size;
|
||||||
|
@ -331,6 +329,8 @@ __sum16 nf_checksum(struct sk_buff *skb, unsigned int hook,
|
||||||
__sum16 nf_checksum_partial(struct sk_buff *skb, unsigned int hook,
|
__sum16 nf_checksum_partial(struct sk_buff *skb, unsigned int hook,
|
||||||
unsigned int dataoff, unsigned int len,
|
unsigned int dataoff, unsigned int len,
|
||||||
u_int8_t protocol, unsigned short family);
|
u_int8_t protocol, unsigned short family);
|
||||||
|
int nf_route(struct net *net, struct dst_entry **dst, struct flowi *fl,
|
||||||
|
bool strict, unsigned short family);
|
||||||
|
|
||||||
int nf_register_afinfo(const struct nf_afinfo *afinfo);
|
int nf_register_afinfo(const struct nf_afinfo *afinfo);
|
||||||
void nf_unregister_afinfo(const struct nf_afinfo *afinfo);
|
void nf_unregister_afinfo(const struct nf_afinfo *afinfo);
|
||||||
|
|
|
@ -24,6 +24,8 @@ __sum16 nf_ip_checksum(struct sk_buff *skb, unsigned int hook,
|
||||||
__sum16 nf_ip_checksum_partial(struct sk_buff *skb, unsigned int hook,
|
__sum16 nf_ip_checksum_partial(struct sk_buff *skb, unsigned int hook,
|
||||||
unsigned int dataoff, unsigned int len,
|
unsigned int dataoff, unsigned int len,
|
||||||
u_int8_t protocol);
|
u_int8_t protocol);
|
||||||
|
int nf_ip_route(struct net *net, struct dst_entry **dst, struct flowi *fl,
|
||||||
|
bool strict);
|
||||||
#else
|
#else
|
||||||
static inline __sum16 nf_ip_checksum(struct sk_buff *skb, unsigned int hook,
|
static inline __sum16 nf_ip_checksum(struct sk_buff *skb, unsigned int hook,
|
||||||
unsigned int dataoff, u_int8_t protocol)
|
unsigned int dataoff, u_int8_t protocol)
|
||||||
|
@ -38,6 +40,11 @@ static inline __sum16 nf_ip_checksum_partial(struct sk_buff *skb,
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
static inline int nf_ip_route(struct net *net, struct dst_entry **dst,
|
||||||
|
struct flowi *fl, bool strict)
|
||||||
|
{
|
||||||
|
return -EOPNOTSUPP;
|
||||||
|
}
|
||||||
#endif /* CONFIG_INET */
|
#endif /* CONFIG_INET */
|
||||||
|
|
||||||
#endif /*__LINUX_IP_NETFILTER_H*/
|
#endif /*__LINUX_IP_NETFILTER_H*/
|
||||||
|
|
|
@ -33,6 +33,8 @@ struct nf_ipv6_ops {
|
||||||
__sum16 (*checksum_partial)(struct sk_buff *skb, unsigned int hook,
|
__sum16 (*checksum_partial)(struct sk_buff *skb, unsigned int hook,
|
||||||
unsigned int dataoff, unsigned int len,
|
unsigned int dataoff, unsigned int len,
|
||||||
u_int8_t protocol);
|
u_int8_t protocol);
|
||||||
|
int (*route)(struct net *net, struct dst_entry **dst, struct flowi *fl,
|
||||||
|
bool strict);
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef CONFIG_NETFILTER
|
#ifdef CONFIG_NETFILTER
|
||||||
|
|
|
@ -101,15 +101,8 @@ static int nf_br_reroute(struct net *net, struct sk_buff *skb,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nf_br_route(struct net *net, struct dst_entry **dst,
|
|
||||||
struct flowi *fl, bool strict __always_unused)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct nf_afinfo nf_br_afinfo = {
|
static const struct nf_afinfo nf_br_afinfo = {
|
||||||
.family = AF_BRIDGE,
|
.family = AF_BRIDGE,
|
||||||
.route = nf_br_route,
|
|
||||||
.reroute = nf_br_reroute,
|
.reroute = nf_br_reroute,
|
||||||
.route_key_size = 0,
|
.route_key_size = 0,
|
||||||
};
|
};
|
||||||
|
|
|
@ -150,8 +150,8 @@ __sum16 nf_ip_checksum_partial(struct sk_buff *skb, unsigned int hook,
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(nf_ip_checksum_partial);
|
EXPORT_SYMBOL_GPL(nf_ip_checksum_partial);
|
||||||
|
|
||||||
static int nf_ip_route(struct net *net, struct dst_entry **dst,
|
int nf_ip_route(struct net *net, struct dst_entry **dst, struct flowi *fl,
|
||||||
struct flowi *fl, bool strict __always_unused)
|
bool strict __always_unused)
|
||||||
{
|
{
|
||||||
struct rtable *rt = ip_route_output_key(net, &fl->u.ip4);
|
struct rtable *rt = ip_route_output_key(net, &fl->u.ip4);
|
||||||
if (IS_ERR(rt))
|
if (IS_ERR(rt))
|
||||||
|
@ -159,10 +159,10 @@ static int nf_ip_route(struct net *net, struct dst_entry **dst,
|
||||||
*dst = &rt->dst;
|
*dst = &rt->dst;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(nf_ip_route);
|
||||||
|
|
||||||
static const struct nf_afinfo nf_ip_afinfo = {
|
static const struct nf_afinfo nf_ip_afinfo = {
|
||||||
.family = AF_INET,
|
.family = AF_INET,
|
||||||
.route = nf_ip_route,
|
|
||||||
.reroute = nf_ip_reroute,
|
.reroute = nf_ip_reroute,
|
||||||
.route_key_size = sizeof(struct ip_rt_info),
|
.route_key_size = sizeof(struct ip_rt_info),
|
||||||
};
|
};
|
||||||
|
|
|
@ -170,11 +170,11 @@ static const struct nf_ipv6_ops ipv6ops = {
|
||||||
.fragment = ip6_fragment,
|
.fragment = ip6_fragment,
|
||||||
.checksum = nf_ip6_checksum,
|
.checksum = nf_ip6_checksum,
|
||||||
.checksum_partial = nf_ip6_checksum_partial,
|
.checksum_partial = nf_ip6_checksum_partial,
|
||||||
|
.route = nf_ip6_route,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct nf_afinfo nf_ip6_afinfo = {
|
static const struct nf_afinfo nf_ip6_afinfo = {
|
||||||
.family = AF_INET6,
|
.family = AF_INET6,
|
||||||
.route = nf_ip6_route,
|
|
||||||
.reroute = nf_ip6_reroute,
|
.reroute = nf_ip6_reroute,
|
||||||
.route_key_size = sizeof(struct ip6_rt_info),
|
.route_key_size = sizeof(struct ip6_rt_info),
|
||||||
};
|
};
|
||||||
|
|
|
@ -60,7 +60,6 @@ static u32 __nft_fib6_eval_type(const struct nft_fib *priv,
|
||||||
{
|
{
|
||||||
const struct net_device *dev = NULL;
|
const struct net_device *dev = NULL;
|
||||||
const struct nf_ipv6_ops *v6ops;
|
const struct nf_ipv6_ops *v6ops;
|
||||||
const struct nf_afinfo *afinfo;
|
|
||||||
int route_err, addrtype;
|
int route_err, addrtype;
|
||||||
struct rt6_info *rt;
|
struct rt6_info *rt;
|
||||||
struct flowi6 fl6 = {
|
struct flowi6 fl6 = {
|
||||||
|
@ -69,8 +68,8 @@ static u32 __nft_fib6_eval_type(const struct nft_fib *priv,
|
||||||
};
|
};
|
||||||
u32 ret = 0;
|
u32 ret = 0;
|
||||||
|
|
||||||
afinfo = nf_get_afinfo(NFPROTO_IPV6);
|
v6ops = nf_get_ipv6_ops();
|
||||||
if (!afinfo)
|
if (!v6ops)
|
||||||
return RTN_UNREACHABLE;
|
return RTN_UNREACHABLE;
|
||||||
|
|
||||||
if (priv->flags & NFTA_FIB_F_IIF)
|
if (priv->flags & NFTA_FIB_F_IIF)
|
||||||
|
@ -80,11 +79,10 @@ static u32 __nft_fib6_eval_type(const struct nft_fib *priv,
|
||||||
|
|
||||||
nft_fib6_flowi_init(&fl6, priv, pkt, dev, iph);
|
nft_fib6_flowi_init(&fl6, priv, pkt, dev, iph);
|
||||||
|
|
||||||
v6ops = nf_get_ipv6_ops();
|
if (dev && v6ops->chk_addr(nft_net(pkt), &fl6.daddr, dev, true))
|
||||||
if (dev && v6ops && v6ops->chk_addr(nft_net(pkt), &fl6.daddr, dev, true))
|
|
||||||
ret = RTN_LOCAL;
|
ret = RTN_LOCAL;
|
||||||
|
|
||||||
route_err = afinfo->route(nft_net(pkt), (struct dst_entry **)&rt,
|
route_err = v6ops->route(nft_net(pkt), (struct dst_entry **)&rt,
|
||||||
flowi6_to_flowi(&fl6), false);
|
flowi6_to_flowi(&fl6), false);
|
||||||
if (route_err)
|
if (route_err)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <linux/skbuff.h>
|
#include <linux/skbuff.h>
|
||||||
#include <net/route.h>
|
#include <net/route.h>
|
||||||
#include <net/ip6_route.h>
|
#include <net/ip6_route.h>
|
||||||
|
#include <linux/netfilter_ipv6.h>
|
||||||
|
|
||||||
#include <net/netfilter/nf_conntrack.h>
|
#include <net/netfilter/nf_conntrack.h>
|
||||||
#include <net/netfilter/nf_conntrack_core.h>
|
#include <net/netfilter/nf_conntrack_core.h>
|
||||||
|
@ -721,14 +722,8 @@ static int callforward_do_filter(struct net *net,
|
||||||
const union nf_inet_addr *dst,
|
const union nf_inet_addr *dst,
|
||||||
u_int8_t family)
|
u_int8_t family)
|
||||||
{
|
{
|
||||||
const struct nf_afinfo *afinfo;
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
/* rcu_read_lock()ed by nf_hook_thresh */
|
|
||||||
afinfo = nf_get_afinfo(family);
|
|
||||||
if (!afinfo)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
switch (family) {
|
switch (family) {
|
||||||
case AF_INET: {
|
case AF_INET: {
|
||||||
struct flowi4 fl1, fl2;
|
struct flowi4 fl1, fl2;
|
||||||
|
@ -739,9 +734,9 @@ static int callforward_do_filter(struct net *net,
|
||||||
|
|
||||||
memset(&fl2, 0, sizeof(fl2));
|
memset(&fl2, 0, sizeof(fl2));
|
||||||
fl2.daddr = dst->ip;
|
fl2.daddr = dst->ip;
|
||||||
if (!afinfo->route(net, (struct dst_entry **)&rt1,
|
if (!nf_ip_route(net, (struct dst_entry **)&rt1,
|
||||||
flowi4_to_flowi(&fl1), false)) {
|
flowi4_to_flowi(&fl1), false)) {
|
||||||
if (!afinfo->route(net, (struct dst_entry **)&rt2,
|
if (!nf_ip_route(net, (struct dst_entry **)&rt2,
|
||||||
flowi4_to_flowi(&fl2), false)) {
|
flowi4_to_flowi(&fl2), false)) {
|
||||||
if (rt_nexthop(rt1, fl1.daddr) ==
|
if (rt_nexthop(rt1, fl1.daddr) ==
|
||||||
rt_nexthop(rt2, fl2.daddr) &&
|
rt_nexthop(rt2, fl2.daddr) &&
|
||||||
|
@ -755,17 +750,22 @@ static int callforward_do_filter(struct net *net,
|
||||||
}
|
}
|
||||||
#if IS_ENABLED(CONFIG_NF_CONNTRACK_IPV6)
|
#if IS_ENABLED(CONFIG_NF_CONNTRACK_IPV6)
|
||||||
case AF_INET6: {
|
case AF_INET6: {
|
||||||
struct flowi6 fl1, fl2;
|
const struct nf_ipv6_ops *v6ops;
|
||||||
struct rt6_info *rt1, *rt2;
|
struct rt6_info *rt1, *rt2;
|
||||||
|
struct flowi6 fl1, fl2;
|
||||||
|
|
||||||
|
v6ops = nf_get_ipv6_ops();
|
||||||
|
if (!v6ops)
|
||||||
|
return 0;
|
||||||
|
|
||||||
memset(&fl1, 0, sizeof(fl1));
|
memset(&fl1, 0, sizeof(fl1));
|
||||||
fl1.daddr = src->in6;
|
fl1.daddr = src->in6;
|
||||||
|
|
||||||
memset(&fl2, 0, sizeof(fl2));
|
memset(&fl2, 0, sizeof(fl2));
|
||||||
fl2.daddr = dst->in6;
|
fl2.daddr = dst->in6;
|
||||||
if (!afinfo->route(net, (struct dst_entry **)&rt1,
|
if (!v6ops->route(net, (struct dst_entry **)&rt1,
|
||||||
flowi6_to_flowi(&fl1), false)) {
|
flowi6_to_flowi(&fl1), false)) {
|
||||||
if (!afinfo->route(net, (struct dst_entry **)&rt2,
|
if (!v6ops->route(net, (struct dst_entry **)&rt2,
|
||||||
flowi6_to_flowi(&fl2), false)) {
|
flowi6_to_flowi(&fl2), false)) {
|
||||||
if (ipv6_addr_equal(rt6_nexthop(rt1, &fl1.daddr),
|
if (ipv6_addr_equal(rt6_nexthop(rt1, &fl1.daddr),
|
||||||
rt6_nexthop(rt2, &fl2.daddr)) &&
|
rt6_nexthop(rt2, &fl2.daddr)) &&
|
||||||
|
|
|
@ -27,7 +27,7 @@ static u16 get_tcpmss(const struct nft_pktinfo *pkt, const struct dst_entry *skb
|
||||||
{
|
{
|
||||||
u32 minlen = sizeof(struct ipv6hdr), mtu = dst_mtu(skbdst);
|
u32 minlen = sizeof(struct ipv6hdr), mtu = dst_mtu(skbdst);
|
||||||
const struct sk_buff *skb = pkt->skb;
|
const struct sk_buff *skb = pkt->skb;
|
||||||
const struct nf_afinfo *ai;
|
struct dst_entry *dst = NULL;
|
||||||
struct flowi fl;
|
struct flowi fl;
|
||||||
|
|
||||||
memset(&fl, 0, sizeof(fl));
|
memset(&fl, 0, sizeof(fl));
|
||||||
|
@ -43,16 +43,11 @@ static u16 get_tcpmss(const struct nft_pktinfo *pkt, const struct dst_entry *skb
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ai = nf_get_afinfo(nft_pf(pkt));
|
nf_route(nft_net(pkt), &dst, &fl, false, nft_pf(pkt));
|
||||||
if (ai) {
|
|
||||||
struct dst_entry *dst = NULL;
|
|
||||||
|
|
||||||
ai->route(nft_net(pkt), &dst, &fl, false);
|
|
||||||
if (dst) {
|
if (dst) {
|
||||||
mtu = min(mtu, dst_mtu(dst));
|
mtu = min(mtu, dst_mtu(dst));
|
||||||
dst_release(dst);
|
dst_release(dst);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (mtu <= minlen || mtu > 0xffff)
|
if (mtu <= minlen || mtu > 0xffff)
|
||||||
return TCP_MSS_DEFAULT;
|
return TCP_MSS_DEFAULT;
|
||||||
|
|
|
@ -48,3 +48,24 @@ __sum16 nf_checksum_partial(struct sk_buff *skb, unsigned int hook,
|
||||||
return csum;
|
return csum;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(nf_checksum_partial);
|
EXPORT_SYMBOL_GPL(nf_checksum_partial);
|
||||||
|
|
||||||
|
int nf_route(struct net *net, struct dst_entry **dst, struct flowi *fl,
|
||||||
|
bool strict, unsigned short family)
|
||||||
|
{
|
||||||
|
const struct nf_ipv6_ops *v6ops;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
switch (family) {
|
||||||
|
case AF_INET:
|
||||||
|
ret = nf_ip_route(net, dst, fl, strict);
|
||||||
|
break;
|
||||||
|
case AF_INET6:
|
||||||
|
v6ops = rcu_dereference(nf_ipv6_ops);
|
||||||
|
if (v6ops)
|
||||||
|
ret = v6ops->route(net, dst, fl, strict);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(nf_route);
|
||||||
|
|
|
@ -48,7 +48,6 @@ static u_int32_t tcpmss_reverse_mtu(struct net *net,
|
||||||
unsigned int family)
|
unsigned int family)
|
||||||
{
|
{
|
||||||
struct flowi fl;
|
struct flowi fl;
|
||||||
const struct nf_afinfo *ai;
|
|
||||||
struct rtable *rt = NULL;
|
struct rtable *rt = NULL;
|
||||||
u_int32_t mtu = ~0U;
|
u_int32_t mtu = ~0U;
|
||||||
|
|
||||||
|
@ -62,10 +61,8 @@ static u_int32_t tcpmss_reverse_mtu(struct net *net,
|
||||||
memset(fl6, 0, sizeof(*fl6));
|
memset(fl6, 0, sizeof(*fl6));
|
||||||
fl6->daddr = ipv6_hdr(skb)->saddr;
|
fl6->daddr = ipv6_hdr(skb)->saddr;
|
||||||
}
|
}
|
||||||
ai = nf_get_afinfo(family);
|
|
||||||
if (ai != NULL)
|
|
||||||
ai->route(net, (struct dst_entry **)&rt, &fl, false);
|
|
||||||
|
|
||||||
|
nf_route(net, (struct dst_entry **)&rt, &fl, false, family);
|
||||||
if (rt != NULL) {
|
if (rt != NULL) {
|
||||||
mtu = dst_mtu(&rt->dst);
|
mtu = dst_mtu(&rt->dst);
|
||||||
dst_release(&rt->dst);
|
dst_release(&rt->dst);
|
||||||
|
|
|
@ -36,7 +36,7 @@ MODULE_ALIAS("ip6t_addrtype");
|
||||||
static u32 match_lookup_rt6(struct net *net, const struct net_device *dev,
|
static u32 match_lookup_rt6(struct net *net, const struct net_device *dev,
|
||||||
const struct in6_addr *addr, u16 mask)
|
const struct in6_addr *addr, u16 mask)
|
||||||
{
|
{
|
||||||
const struct nf_afinfo *afinfo;
|
const struct nf_ipv6_ops *v6ops;
|
||||||
struct flowi6 flow;
|
struct flowi6 flow;
|
||||||
struct rt6_info *rt;
|
struct rt6_info *rt;
|
||||||
u32 ret = 0;
|
u32 ret = 0;
|
||||||
|
@ -47,16 +47,13 @@ static u32 match_lookup_rt6(struct net *net, const struct net_device *dev,
|
||||||
if (dev)
|
if (dev)
|
||||||
flow.flowi6_oif = dev->ifindex;
|
flow.flowi6_oif = dev->ifindex;
|
||||||
|
|
||||||
afinfo = nf_get_afinfo(NFPROTO_IPV6);
|
|
||||||
if (afinfo != NULL) {
|
|
||||||
const struct nf_ipv6_ops *v6ops;
|
|
||||||
|
|
||||||
if (dev && (mask & XT_ADDRTYPE_LOCAL)) {
|
|
||||||
v6ops = nf_get_ipv6_ops();
|
v6ops = nf_get_ipv6_ops();
|
||||||
if (v6ops && v6ops->chk_addr(net, addr, dev, true))
|
if (v6ops) {
|
||||||
|
if (dev && (mask & XT_ADDRTYPE_LOCAL)) {
|
||||||
|
if (v6ops->chk_addr(net, addr, dev, true))
|
||||||
ret = XT_ADDRTYPE_LOCAL;
|
ret = XT_ADDRTYPE_LOCAL;
|
||||||
}
|
}
|
||||||
route_err = afinfo->route(net, (struct dst_entry **)&rt,
|
route_err = v6ops->route(net, (struct dst_entry **)&rt,
|
||||||
flowi6_to_flowi(&flow), false);
|
flowi6_to_flowi(&flow), false);
|
||||||
} else {
|
} else {
|
||||||
route_err = 1;
|
route_err = 1;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче