diff options
-rw-r--r-- | net/core/netfilter.c | 72 | ||||
-rw-r--r-- | net/ipv4/Makefile | 2 | ||||
-rw-r--r-- | net/ipv4/netfilter.c | 79 | ||||
-rw-r--r-- | net/ipv6/Makefile | 2 | ||||
-rw-r--r-- | net/ipv6/ip6_output.c | 32 | ||||
-rw-r--r-- | net/ipv6/ipv6_syms.c | 3 | ||||
-rw-r--r-- | net/ipv6/netfilter.c | 43 |
7 files changed, 124 insertions, 109 deletions
diff --git a/net/core/netfilter.c b/net/core/netfilter.c index bbf9081a6804..9849357f6129 100644 --- a/net/core/netfilter.c +++ b/net/core/netfilter.c | |||
@@ -22,12 +22,7 @@ | |||
22 | #include <linux/if.h> | 22 | #include <linux/if.h> |
23 | #include <linux/netdevice.h> | 23 | #include <linux/netdevice.h> |
24 | #include <linux/inetdevice.h> | 24 | #include <linux/inetdevice.h> |
25 | #include <linux/tcp.h> | ||
26 | #include <linux/udp.h> | ||
27 | #include <linux/icmp.h> | ||
28 | #include <net/sock.h> | 25 | #include <net/sock.h> |
29 | #include <net/route.h> | ||
30 | #include <linux/ip.h> | ||
31 | 26 | ||
32 | /* In this code, we can be waiting indefinitely for userspace to | 27 | /* In this code, we can be waiting indefinitely for userspace to |
33 | * service a packet if a hook returns NF_QUEUE. We could keep a count | 28 | * service a packet if a hook returns NF_QUEUE. We could keep a count |
@@ -447,73 +442,6 @@ void nf_reinject(struct sk_buff *skb, struct nf_info *info, | |||
447 | return; | 442 | return; |
448 | } | 443 | } |
449 | 444 | ||
450 | #ifdef CONFIG_INET | ||
451 | /* route_me_harder function, used by iptable_nat, iptable_mangle + ip_queue */ | ||
452 | int ip_route_me_harder(struct sk_buff **pskb) | ||
453 | { | ||
454 | struct iphdr *iph = (*pskb)->nh.iph; | ||
455 | struct rtable *rt; | ||
456 | struct flowi fl = {}; | ||
457 | struct dst_entry *odst; | ||
458 | unsigned int hh_len; | ||
459 | |||
460 | /* some non-standard hacks like ipt_REJECT.c:send_reset() can cause | ||
461 | * packets with foreign saddr to appear on the NF_IP_LOCAL_OUT hook. | ||
462 | */ | ||
463 | if (inet_addr_type(iph->saddr) == RTN_LOCAL) { | ||
464 | fl.nl_u.ip4_u.daddr = iph->daddr; | ||
465 | fl.nl_u.ip4_u.saddr = iph->saddr; | ||
466 | fl.nl_u.ip4_u.tos = RT_TOS(iph->tos); | ||
467 | fl.oif = (*pskb)->sk ? (*pskb)->sk->sk_bound_dev_if : 0; | ||
468 | #ifdef CONFIG_IP_ROUTE_FWMARK | ||
469 | fl.nl_u.ip4_u.fwmark = (*pskb)->nfmark; | ||
470 | #endif | ||
471 | fl.proto = iph->protocol; | ||
472 | if (ip_route_output_key(&rt, &fl) != 0) | ||
473 | return -1; | ||
474 | |||
475 | /* Drop old route. */ | ||
476 | dst_release((*pskb)->dst); | ||
477 | (*pskb)->dst = &rt->u.dst; | ||
478 | } else { | ||
479 | /* non-local src, find valid iif to satisfy | ||
480 | * rp-filter when calling ip_route_input. */ | ||
481 | fl.nl_u.ip4_u.daddr = iph->saddr; | ||
482 | if (ip_route_output_key(&rt, &fl) != 0) | ||
483 | return -1; | ||
484 | |||
485 | odst = (*pskb)->dst; | ||
486 | if (ip_route_input(*pskb, iph->daddr, iph->saddr, | ||
487 | RT_TOS(iph->tos), rt->u.dst.dev) != 0) { | ||
488 | dst_release(&rt->u.dst); | ||
489 | return -1; | ||
490 | } | ||
491 | dst_release(&rt->u.dst); | ||
492 | dst_release(odst); | ||
493 | } | ||
494 | |||
495 | if ((*pskb)->dst->error) | ||
496 | return -1; | ||
497 | |||
498 | /* Change in oif may mean change in hh_len. */ | ||
499 | hh_len = (*pskb)->dst->dev->hard_header_len; | ||
500 | if (skb_headroom(*pskb) < hh_len) { | ||
501 | struct sk_buff *nskb; | ||
502 | |||
503 | nskb = skb_realloc_headroom(*pskb, hh_len); | ||
504 | if (!nskb) | ||
505 | return -1; | ||
506 | if ((*pskb)->sk) | ||
507 | skb_set_owner_w(nskb, (*pskb)->sk); | ||
508 | kfree_skb(*pskb); | ||
509 | *pskb = nskb; | ||
510 | } | ||
511 | |||
512 | return 0; | ||
513 | } | ||
514 | EXPORT_SYMBOL(ip_route_me_harder); | ||
515 | #endif /*CONFIG_INET*/ | ||
516 | |||
517 | int skb_make_writable(struct sk_buff **pskb, unsigned int writable_len) | 445 | int skb_make_writable(struct sk_buff **pskb, unsigned int writable_len) |
518 | { | 446 | { |
519 | struct sk_buff *nskb; | 447 | struct sk_buff *nskb; |
diff --git a/net/ipv4/Makefile b/net/ipv4/Makefile index 55dc6cca1e7b..61c7386bcd2e 100644 --- a/net/ipv4/Makefile +++ b/net/ipv4/Makefile | |||
@@ -8,7 +8,7 @@ obj-y := route.o inetpeer.o protocol.o \ | |||
8 | tcp.o tcp_input.o tcp_output.o tcp_timer.o tcp_ipv4.o \ | 8 | tcp.o tcp_input.o tcp_output.o tcp_timer.o tcp_ipv4.o \ |
9 | tcp_minisocks.o tcp_cong.o \ | 9 | tcp_minisocks.o tcp_cong.o \ |
10 | datagram.o raw.o udp.o arp.o icmp.o devinet.o af_inet.o igmp.o \ | 10 | datagram.o raw.o udp.o arp.o icmp.o devinet.o af_inet.o igmp.o \ |
11 | sysctl_net_ipv4.o fib_frontend.o fib_semantics.o | 11 | sysctl_net_ipv4.o fib_frontend.o fib_semantics.o netfilter.o |
12 | 12 | ||
13 | obj-$(CONFIG_IP_FIB_HASH) += fib_hash.o | 13 | obj-$(CONFIG_IP_FIB_HASH) += fib_hash.o |
14 | obj-$(CONFIG_IP_FIB_TRIE) += fib_trie.o | 14 | obj-$(CONFIG_IP_FIB_TRIE) += fib_trie.o |
diff --git a/net/ipv4/netfilter.c b/net/ipv4/netfilter.c new file mode 100644 index 000000000000..6594d1c9697e --- /dev/null +++ b/net/ipv4/netfilter.c | |||
@@ -0,0 +1,79 @@ | |||
1 | #include <linux/config.h> | ||
2 | |||
3 | #ifdef CONFIG_NETFILTER | ||
4 | |||
5 | /* IPv4 specific functions of netfilter core */ | ||
6 | #include <linux/kernel.h> | ||
7 | #include <linux/netfilter.h> | ||
8 | |||
9 | #include <linux/tcp.h> | ||
10 | #include <linux/udp.h> | ||
11 | #include <linux/icmp.h> | ||
12 | #include <net/route.h> | ||
13 | #include <linux/ip.h> | ||
14 | |||
15 | /* route_me_harder function, used by iptable_nat, iptable_mangle + ip_queue */ | ||
16 | int ip_route_me_harder(struct sk_buff **pskb) | ||
17 | { | ||
18 | struct iphdr *iph = (*pskb)->nh.iph; | ||
19 | struct rtable *rt; | ||
20 | struct flowi fl = {}; | ||
21 | struct dst_entry *odst; | ||
22 | unsigned int hh_len; | ||
23 | |||
24 | /* some non-standard hacks like ipt_REJECT.c:send_reset() can cause | ||
25 | * packets with foreign saddr to appear on the NF_IP_LOCAL_OUT hook. | ||
26 | */ | ||
27 | if (inet_addr_type(iph->saddr) == RTN_LOCAL) { | ||
28 | fl.nl_u.ip4_u.daddr = iph->daddr; | ||
29 | fl.nl_u.ip4_u.saddr = iph->saddr; | ||
30 | fl.nl_u.ip4_u.tos = RT_TOS(iph->tos); | ||
31 | fl.oif = (*pskb)->sk ? (*pskb)->sk->sk_bound_dev_if : 0; | ||
32 | #ifdef CONFIG_IP_ROUTE_FWMARK | ||
33 | fl.nl_u.ip4_u.fwmark = (*pskb)->nfmark; | ||
34 | #endif | ||
35 | fl.proto = iph->protocol; | ||
36 | if (ip_route_output_key(&rt, &fl) != 0) | ||
37 | return -1; | ||
38 | |||
39 | /* Drop old route. */ | ||
40 | dst_release((*pskb)->dst); | ||
41 | (*pskb)->dst = &rt->u.dst; | ||
42 | } else { | ||
43 | /* non-local src, find valid iif to satisfy | ||
44 | * rp-filter when calling ip_route_input. */ | ||
45 | fl.nl_u.ip4_u.daddr = iph->saddr; | ||
46 | if (ip_route_output_key(&rt, &fl) != 0) | ||
47 | return -1; | ||
48 | |||
49 | odst = (*pskb)->dst; | ||
50 | if (ip_route_input(*pskb, iph->daddr, iph->saddr, | ||
51 | RT_TOS(iph->tos), rt->u.dst.dev) != 0) { | ||
52 | dst_release(&rt->u.dst); | ||
53 | return -1; | ||
54 | } | ||
55 | dst_release(&rt->u.dst); | ||
56 | dst_release(odst); | ||
57 | } | ||
58 | |||
59 | if ((*pskb)->dst->error) | ||
60 | return -1; | ||
61 | |||
62 | /* Change in oif may mean change in hh_len. */ | ||
63 | hh_len = (*pskb)->dst->dev->hard_header_len; | ||
64 | if (skb_headroom(*pskb) < hh_len) { | ||
65 | struct sk_buff *nskb; | ||
66 | |||
67 | nskb = skb_realloc_headroom(*pskb, hh_len); | ||
68 | if (!nskb) | ||
69 | return -1; | ||
70 | if ((*pskb)->sk) | ||
71 | skb_set_owner_w(nskb, (*pskb)->sk); | ||
72 | kfree_skb(*pskb); | ||
73 | *pskb = nskb; | ||
74 | } | ||
75 | |||
76 | return 0; | ||
77 | } | ||
78 | EXPORT_SYMBOL(ip_route_me_harder); | ||
79 | #endif /* CONFIG_NETFILTER */ | ||
diff --git a/net/ipv6/Makefile b/net/ipv6/Makefile index b39e04940590..5bccea2d81b4 100644 --- a/net/ipv6/Makefile +++ b/net/ipv6/Makefile | |||
@@ -8,7 +8,7 @@ ipv6-objs := af_inet6.o anycast.o ip6_output.o ip6_input.o addrconf.o sit.o \ | |||
8 | route.o ip6_fib.o ipv6_sockglue.o ndisc.o udp.o raw.o \ | 8 | route.o ip6_fib.o ipv6_sockglue.o ndisc.o udp.o raw.o \ |
9 | protocol.o icmp.o mcast.o reassembly.o tcp_ipv6.o \ | 9 | protocol.o icmp.o mcast.o reassembly.o tcp_ipv6.o \ |
10 | exthdrs.o sysctl_net_ipv6.o datagram.o proc.o \ | 10 | exthdrs.o sysctl_net_ipv6.o datagram.o proc.o \ |
11 | ip6_flowlabel.o ipv6_syms.o | 11 | ip6_flowlabel.o ipv6_syms.o netfilter.o |
12 | 12 | ||
13 | ipv6-$(CONFIG_XFRM) += xfrm6_policy.o xfrm6_state.o xfrm6_input.o \ | 13 | ipv6-$(CONFIG_XFRM) += xfrm6_policy.o xfrm6_state.o xfrm6_input.o \ |
14 | xfrm6_output.o | 14 | xfrm6_output.o |
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 590d2b797197..a7fcbcc83576 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c | |||
@@ -153,38 +153,6 @@ int ip6_output(struct sk_buff *skb) | |||
153 | return ip6_output2(skb); | 153 | return ip6_output2(skb); |
154 | } | 154 | } |
155 | 155 | ||
156 | #ifdef CONFIG_NETFILTER | ||
157 | int ip6_route_me_harder(struct sk_buff *skb) | ||
158 | { | ||
159 | struct ipv6hdr *iph = skb->nh.ipv6h; | ||
160 | struct dst_entry *dst; | ||
161 | struct flowi fl = { | ||
162 | .oif = skb->sk ? skb->sk->sk_bound_dev_if : 0, | ||
163 | .nl_u = | ||
164 | { .ip6_u = | ||
165 | { .daddr = iph->daddr, | ||
166 | .saddr = iph->saddr, } }, | ||
167 | .proto = iph->nexthdr, | ||
168 | }; | ||
169 | |||
170 | dst = ip6_route_output(skb->sk, &fl); | ||
171 | |||
172 | if (dst->error) { | ||
173 | IP6_INC_STATS(IPSTATS_MIB_OUTNOROUTES); | ||
174 | LIMIT_NETDEBUG( | ||
175 | printk(KERN_DEBUG "ip6_route_me_harder: No more route.\n")); | ||
176 | dst_release(dst); | ||
177 | return -EINVAL; | ||
178 | } | ||
179 | |||
180 | /* Drop old route. */ | ||
181 | dst_release(skb->dst); | ||
182 | |||
183 | skb->dst = dst; | ||
184 | return 0; | ||
185 | } | ||
186 | #endif | ||
187 | |||
188 | /* | 156 | /* |
189 | * xmit an sk_buff (used by TCP) | 157 | * xmit an sk_buff (used by TCP) |
190 | */ | 158 | */ |
diff --git a/net/ipv6/ipv6_syms.c b/net/ipv6/ipv6_syms.c index 5ade5a5d1990..37a4a99c9fe9 100644 --- a/net/ipv6/ipv6_syms.c +++ b/net/ipv6/ipv6_syms.c | |||
@@ -15,9 +15,6 @@ EXPORT_SYMBOL(ndisc_mc_map); | |||
15 | EXPORT_SYMBOL(register_inet6addr_notifier); | 15 | EXPORT_SYMBOL(register_inet6addr_notifier); |
16 | EXPORT_SYMBOL(unregister_inet6addr_notifier); | 16 | EXPORT_SYMBOL(unregister_inet6addr_notifier); |
17 | EXPORT_SYMBOL(ip6_route_output); | 17 | EXPORT_SYMBOL(ip6_route_output); |
18 | #ifdef CONFIG_NETFILTER | ||
19 | EXPORT_SYMBOL(ip6_route_me_harder); | ||
20 | #endif | ||
21 | EXPORT_SYMBOL(addrconf_lock); | 18 | EXPORT_SYMBOL(addrconf_lock); |
22 | EXPORT_SYMBOL(ipv6_setsockopt); | 19 | EXPORT_SYMBOL(ipv6_setsockopt); |
23 | EXPORT_SYMBOL(ipv6_getsockopt); | 20 | EXPORT_SYMBOL(ipv6_getsockopt); |
diff --git a/net/ipv6/netfilter.c b/net/ipv6/netfilter.c new file mode 100644 index 000000000000..5656d0959aba --- /dev/null +++ b/net/ipv6/netfilter.c | |||
@@ -0,0 +1,43 @@ | |||
1 | #include <linux/config.h> | ||
2 | #include <linux/init.h> | ||
3 | |||
4 | #ifdef CONFIG_NETFILTER | ||
5 | |||
6 | #include <linux/kernel.h> | ||
7 | #include <linux/ipv6.h> | ||
8 | #include <net/dst.h> | ||
9 | #include <net/ipv6.h> | ||
10 | #include <net/ip6_route.h> | ||
11 | |||
12 | int ip6_route_me_harder(struct sk_buff *skb) | ||
13 | { | ||
14 | struct ipv6hdr *iph = skb->nh.ipv6h; | ||
15 | struct dst_entry *dst; | ||
16 | struct flowi fl = { | ||
17 | .oif = skb->sk ? skb->sk->sk_bound_dev_if : 0, | ||
18 | .nl_u = | ||
19 | { .ip6_u = | ||
20 | { .daddr = iph->daddr, | ||
21 | .saddr = iph->saddr, } }, | ||
22 | .proto = iph->nexthdr, | ||
23 | }; | ||
24 | |||
25 | dst = ip6_route_output(skb->sk, &fl); | ||
26 | |||
27 | if (dst->error) { | ||
28 | IP6_INC_STATS(IPSTATS_MIB_OUTNOROUTES); | ||
29 | LIMIT_NETDEBUG( | ||
30 | printk(KERN_DEBUG "ip6_route_me_harder: No more route.\n")); | ||
31 | dst_release(dst); | ||
32 | return -EINVAL; | ||
33 | } | ||
34 | |||
35 | /* Drop old route. */ | ||
36 | dst_release(skb->dst); | ||
37 | |||
38 | skb->dst = dst; | ||
39 | return 0; | ||
40 | } | ||
41 | EXPORT_SYMBOL(ip6_route_me_harder); | ||
42 | |||
43 | #endif /* CONFIG_NETFILTER */ | ||