1 #include <linux/config.h>
3 #ifdef CONFIG_NETFILTER
5 /* IPv4 specific functions of netfilter core */
6 #include <linux/kernel.h>
7 #include <linux/netfilter.h>
10 #include <linux/udp.h>
11 #include <linux/icmp.h>
12 #include <net/route.h>
15 /* route_me_harder function, used by iptable_nat, iptable_mangle + ip_queue */
16 int ip_route_me_harder(struct sk_buff **pskb)
18 struct iphdr *iph = (*pskb)->nh.iph;
21 struct dst_entry *odst;
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.
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;
35 fl.proto = iph->protocol;
36 if (ip_route_output_key(&rt, &fl) != 0)
40 dst_release((*pskb)->dst);
41 (*pskb)->dst = &rt->u.dst;
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)
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);
55 dst_release(&rt->u.dst);
59 if ((*pskb)->dst->error)
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) {
67 nskb = skb_realloc_headroom(*pskb, hh_len);
71 skb_set_owner_w(nskb, (*pskb)->sk);
78 EXPORT_SYMBOL(ip_route_me_harder);
79 #endif /* CONFIG_NETFILTER */