Skip to content

Commit 020b4c1

Browse files
laf0rgeDavid S. Miller
authored andcommitted
[NETFILTER]: Move ipv4 specific code from net/core/netfilter.c to net/ipv4/netfilter.c
Netfilter cleanup - Move ipv4 code from net/core/netfilter.c to net/ipv4/netfilter.c - Move ipv6 netfilter code from net/ipv6/ip6_output.c to net/ipv6/netfilter.c Signed-off-by: Harald Welte <laforge@netfilter.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 089af26 commit 020b4c1

7 files changed

Lines changed: 124 additions & 109 deletions

File tree

‎net/core/netfilter.c‎

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@
2222
#include <linux/if.h>
2323
#include <linux/netdevice.h>
2424
#include <linux/inetdevice.h>
25-
#include <linux/tcp.h>
26-
#include <linux/udp.h>
27-
#include <linux/icmp.h>
2825
#include <net/sock.h>
29-
#include <net/route.h>
30-
#include <linux/ip.h>
3126

3227
/* In this code, we can be waiting indefinitely for userspace to
3328
* 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,
447442
return;
448443
}
449444

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-
517445
int skb_make_writable(struct sk_buff **pskb, unsigned int writable_len)
518446
{
519447
struct sk_buff *nskb;

‎net/ipv4/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ obj-y := route.o inetpeer.o protocol.o \
88
tcp.o tcp_input.o tcp_output.o tcp_timer.o tcp_ipv4.o \
99
tcp_minisocks.o tcp_cong.o \
1010
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
1212

1313
obj-$(CONFIG_IP_FIB_HASH) += fib_hash.o
1414
obj-$(CONFIG_IP_FIB_TRIE) += fib_trie.o

‎net/ipv4/netfilter.c‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 */

‎net/ipv6/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ipv6-objs := af_inet6.o anycast.o ip6_output.o ip6_input.o addrconf.o sit.o \
88
route.o ip6_fib.o ipv6_sockglue.o ndisc.o udp.o raw.o \
99
protocol.o icmp.o mcast.o reassembly.o tcp_ipv6.o \
1010
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
1212

1313
ipv6-$(CONFIG_XFRM) += xfrm6_policy.o xfrm6_state.o xfrm6_input.o \
1414
xfrm6_output.o

‎net/ipv6/ip6_output.c‎

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -153,38 +153,6 @@ int ip6_output(struct sk_buff *skb)
153153
return ip6_output2(skb);
154154
}
155155

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-
188156
/*
189157
* xmit an sk_buff (used by TCP)
190158
*/

‎net/ipv6/ipv6_syms.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ EXPORT_SYMBOL(ndisc_mc_map);
1515
EXPORT_SYMBOL(register_inet6addr_notifier);
1616
EXPORT_SYMBOL(unregister_inet6addr_notifier);
1717
EXPORT_SYMBOL(ip6_route_output);
18-
#ifdef CONFIG_NETFILTER
19-
EXPORT_SYMBOL(ip6_route_me_harder);
20-
#endif
2118
EXPORT_SYMBOL(addrconf_lock);
2219
EXPORT_SYMBOL(ipv6_setsockopt);
2320
EXPORT_SYMBOL(ipv6_getsockopt);

‎net/ipv6/netfilter.c‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 */

0 commit comments

Comments
 (0)