nf_nat_ipv6 calls two ipv6 core functions, so add those to v6ops to avoid the module dependency. This is a prerequisite for merging ipv4 and ipv6 nat implementations. Add wrappers to avoid the indirection if ipv6 is builtin.
Unified · Split
| @@ -33,6 +33,12 @@ struct nf_ipv6_ops { · 32 unmodified lines | ||
| 33 | 33 | int (*route)(struct net *net, struct dst_entry **dst, struct flowi *fl, |
| 34 | 34 | bool strict); |
| 35 | 35 | int (*reroute)(struct sk_buff *skb, const struct nf_queue_entry *entry); |
| 36 | +#if IS_MODULE(CONFIG_IPV6) | |
| 37 | + int (*route_me_harder)(struct net *net, struct sk_buff *skb); | |
| 38 | + int (*dev_get_saddr)(struct net *net, const struct net_device *dev, | |
| 39 | + const struct in6_addr *daddr, unsigned int srcprefs, | |
| 40 | + struct in6_addr *saddr); | |
| 41 | +#endif | |
| 36 | 42 | }; |
| 37 | 43 | |
| 38 | 44 | #ifdef CONFIG_NETFILTER |
| @@ -112,6 +112,10 @@ static const struct nf_ipv6_ops ipv6ops = { · 111 unmodified lines | ||
| 112 | 112 | .fragment = ip6_fragment, |
| 113 | 113 | .route = nf_ip6_route, |
| 114 | 114 | .reroute = nf_ip6_reroute, |
| 115 | +#if IS_MODULE(CONFIG_IPV6) | |
| 116 | + .route_me_harder = ip6_route_me_harder, | |
| 117 | + .dev_get_saddr = ipv6_dev_get_saddr, | |
| 118 | +#endif | |
| 115 | 119 | }; |
| 116 | 120 | |
| 117 | 121 | int __init ipv6_netfilter_init(void) |
| @@ -17,6 +17,7 @@ · 16 unmodified lines | ||
| 17 | 17 | #include <net/checksum.h> |
| 18 | 18 | #include <net/ip6_checksum.h> |
| 19 | 19 | #include <net/ip6_route.h> |
| 20 | +#include <net/xfrm.h> | |
| 20 | 21 | #include <net/ipv6.h> |
| 21 | 22 | |
| 22 | 23 | #include <net/netfilter/nf_conntrack_core.h> |
| @@ -317,6 +318,20 @@ nf_nat_ipv6_out(void *priv, struct sk_buff *skb, · 294 unmodified lines | ||
| 317 | 318 | return ret; |
| 318 | 319 | } |
| 319 | 320 | |
| 321 | +static int nat_route_me_harder(struct net *net, struct sk_buff *skb) | |
| 322 | +{ | |
| 323 | +#ifdef CONFIG_IPV6_MODULE | |
| 324 | + const struct nf_ipv6_ops *v6_ops = nf_get_ipv6_ops(); | |
| 325 | + | |
| 326 | + if (!v6_ops) | |
| 327 | + return -EHOSTUNREACH; | |
| 328 | + | |
| 329 | + return v6_ops->route_me_harder(net, skb); | |
| 330 | +#else | |
| 331 | + return ip6_route_me_harder(net, skb); | |
| 332 | +#endif | |
| 333 | +} | |
| 334 | + | |
| 320 | 335 | static unsigned int |
| 321 | 336 | nf_nat_ipv6_local_fn(void *priv, struct sk_buff *skb, |
| 322 | 337 | const struct nf_hook_state *state) |
| @@ -333,7 +348,7 @@ nf_nat_ipv6_local_fn(void *priv, struct sk_buff *skb, · 10 unmodified lines | ||
| 333 | 348 | |
| 334 | 349 | if (!nf_inet_addr_cmp(&ct->tuplehash[dir].tuple.dst.u3, |
| 335 | 350 | &ct->tuplehash[!dir].tuple.src.u3)) { |
| 336 | − err = ip6_route_me_harder(state->net, skb); | |
| 351 | + err = nat_route_me_harder(state->net, skb); | |
| 337 | 352 | if (err < 0) |
| 338 | 353 | ret = NF_DROP_ERR(err); |
| 339 | 354 | } |
| @@ -24,6 +24,23 @@ · 23 unmodified lines | ||
| 24 | 24 | |
| 25 | 25 | static atomic_t v6_worker_count; |
| 26 | 26 | |
| 27 | +static int | |
| 28 | +nat_ipv6_dev_get_saddr(struct net *net, const struct net_device *dev, | |
| 29 | + const struct in6_addr *daddr, unsigned int srcprefs, | |
| 30 | + struct in6_addr *saddr) | |
| 31 | +{ | |
| 32 | +#ifdef CONFIG_IPV6_MODULE | |
| 33 | + const struct nf_ipv6_ops *v6_ops = nf_get_ipv6_ops(); | |
| 34 | + | |
| 35 | + if (!v6_ops) | |
| 36 | + return -EHOSTUNREACH; | |
| 37 | + | |
| 38 | + return v6_ops->dev_get_saddr(net, dev, daddr, srcprefs, saddr); | |
| 39 | +#else | |
| 40 | + return ipv6_dev_get_saddr(net, dev, daddr, srcprefs, saddr); | |
| 41 | +#endif | |
| 42 | +} | |
| 43 | + | |
| 27 | 44 | unsigned int |
| 28 | 45 | nf_nat_masquerade_ipv6(struct sk_buff *skb, const struct nf_nat_range2 *range, |
| 29 | 46 | const struct net_device *out) |
| @@ -38,8 +55,8 @@ nf_nat_masquerade_ipv6(struct sk_buff *skb, const struct nf_nat_range2 *range, · 8 unmodified lines | ||
| 38 | 55 | WARN_ON(!(ct && (ctinfo == IP_CT_NEW || ctinfo == IP_CT_RELATED || |
| 39 | 56 | ctinfo == IP_CT_RELATED_REPLY))); |
| 40 | 57 | |
| 41 | − if (ipv6_dev_get_saddr(nf_ct_net(ct), out, | |
| 42 | − &ipv6_hdr(skb)->daddr, 0, &src) < 0) | |
| 58 | + if (nat_ipv6_dev_get_saddr(nf_ct_net(ct), out, | |
| 59 | + &ipv6_hdr(skb)->daddr, 0, &src) < 0) | |
| 43 | 60 | return NF_DROP; |
| 44 | 61 | |
| 45 | 62 | nat = nf_ct_nat_ext_add(ct); |