History

netfilter: nat: remove module dependency on ipv6 core

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.

Florian Westphal committed 7 years ago

Commit 96058721 parent a46c52d4 files · +45 −3Browse files

Unified · Split

4 files
  1. include/linux/netfilter_ipv6.h +6 −0
  2. net/ipv6/netfilter.c +4 −0
  3. net/ipv6/netfilter/nf_nat_l3proto_ipv6.c +16 −1
  4. net/ipv6/netfilter/nf_nat_masquerade_ipv6.c +19 −2
include/linux/netfilter_ipv6.h+6−0
@@ -33,6 +33,12 @@ struct nf_ipv6_ops { · 32 unmodified lines
3333 int (*route)(struct net *net, struct dst_entry **dst, struct flowi *fl,
3434 bool strict);
3535 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
3642 };
3743
3844 #ifdef CONFIG_NETFILTER
net/ipv6/netfilter.c+4−0
@@ -112,6 +112,10 @@ static const struct nf_ipv6_ops ipv6ops = { · 111 unmodified lines
112112 .fragment = ip6_fragment,
113113 .route = nf_ip6_route,
114114 .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
115119 };
116120
117121 int __init ipv6_netfilter_init(void)
net/ipv6/netfilter/nf_nat_l3proto_ipv6.c+16−1
@@ -17,6 +17,7 @@ · 16 unmodified lines
1717 #include <net/checksum.h>
1818 #include <net/ip6_checksum.h>
1919 #include <net/ip6_route.h>
20+#include <net/xfrm.h>
2021 #include <net/ipv6.h>
2122
2223 #include <net/netfilter/nf_conntrack_core.h>
@@ -317,6 +318,20 @@ nf_nat_ipv6_out(void *priv, struct sk_buff *skb, · 294 unmodified lines
317318 return ret;
318319 }
319320
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+
320335 static unsigned int
321336 nf_nat_ipv6_local_fn(void *priv, struct sk_buff *skb,
322337 const struct nf_hook_state *state)
@@ -333,7 +348,7 @@ nf_nat_ipv6_local_fn(void *priv, struct sk_buff *skb, · 10 unmodified lines
333348
334349 if (!nf_inet_addr_cmp(&ct->tuplehash[dir].tuple.dst.u3,
335350 &ct->tuplehash[!dir].tuple.src.u3)) {
336− err = ip6_route_me_harder(state->net, skb);
351+ err = nat_route_me_harder(state->net, skb);
337352 if (err < 0)
338353 ret = NF_DROP_ERR(err);
339354 }
net/ipv6/netfilter/nf_nat_masquerade_ipv6.c+19−2
@@ -24,6 +24,23 @@ · 23 unmodified lines
2424
2525 static atomic_t v6_worker_count;
2626
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+
2744 unsigned int
2845 nf_nat_masquerade_ipv6(struct sk_buff *skb, const struct nf_nat_range2 *range,
2946 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
3855 WARN_ON(!(ct && (ctinfo == IP_CT_NEW || ctinfo == IP_CT_RELATED ||
3956 ctinfo == IP_CT_RELATED_REPLY)));
4057
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)
4360 return NF_DROP;
4461
4562 nat = nf_ct_nat_ext_add(ct);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t