[PATCH] neofb: avoid resetting display config on unblank
[deliverable/linux.git] / net / ipv4 / netfilter.c
CommitLineData
2cc7d573 1/* IPv4 specific functions of netfilter core */
020b4c12
HW
2#include <linux/kernel.h>
3#include <linux/netfilter.h>
2cc7d573 4#include <linux/netfilter_ipv4.h>
3e3850e9 5#include <linux/ip.h>
020b4c12 6#include <net/route.h>
3e3850e9
PM
7#include <net/xfrm.h>
8#include <net/ip.h>
020b4c12
HW
9
10/* route_me_harder function, used by iptable_nat, iptable_mangle + ip_queue */
11int ip_route_me_harder(struct sk_buff **pskb)
12{
13 struct iphdr *iph = (*pskb)->nh.iph;
14 struct rtable *rt;
15 struct flowi fl = {};
16 struct dst_entry *odst;
17 unsigned int hh_len;
18
19 /* some non-standard hacks like ipt_REJECT.c:send_reset() can cause
20 * packets with foreign saddr to appear on the NF_IP_LOCAL_OUT hook.
21 */
22 if (inet_addr_type(iph->saddr) == RTN_LOCAL) {
23 fl.nl_u.ip4_u.daddr = iph->daddr;
24 fl.nl_u.ip4_u.saddr = iph->saddr;
25 fl.nl_u.ip4_u.tos = RT_TOS(iph->tos);
26 fl.oif = (*pskb)->sk ? (*pskb)->sk->sk_bound_dev_if : 0;
27#ifdef CONFIG_IP_ROUTE_FWMARK
28 fl.nl_u.ip4_u.fwmark = (*pskb)->nfmark;
29#endif
020b4c12
HW
30 if (ip_route_output_key(&rt, &fl) != 0)
31 return -1;
32
33 /* Drop old route. */
34 dst_release((*pskb)->dst);
35 (*pskb)->dst = &rt->u.dst;
36 } else {
37 /* non-local src, find valid iif to satisfy
38 * rp-filter when calling ip_route_input. */
39 fl.nl_u.ip4_u.daddr = iph->saddr;
40 if (ip_route_output_key(&rt, &fl) != 0)
41 return -1;
42
43 odst = (*pskb)->dst;
44 if (ip_route_input(*pskb, iph->daddr, iph->saddr,
45 RT_TOS(iph->tos), rt->u.dst.dev) != 0) {
46 dst_release(&rt->u.dst);
47 return -1;
48 }
49 dst_release(&rt->u.dst);
50 dst_release(odst);
51 }
52
53 if ((*pskb)->dst->error)
54 return -1;
55
3e3850e9
PM
56#ifdef CONFIG_XFRM
57 if (!(IPCB(*pskb)->flags & IPSKB_XFRM_TRANSFORMED) &&
58 xfrm_decode_session(*pskb, &fl, AF_INET) == 0)
59 if (xfrm_lookup(&(*pskb)->dst, &fl, (*pskb)->sk, 0))
60 return -1;
61#endif
62
020b4c12
HW
63 /* Change in oif may mean change in hh_len. */
64 hh_len = (*pskb)->dst->dev->hard_header_len;
65 if (skb_headroom(*pskb) < hh_len) {
66 struct sk_buff *nskb;
67
68 nskb = skb_realloc_headroom(*pskb, hh_len);
69 if (!nskb)
70 return -1;
71 if ((*pskb)->sk)
72 skb_set_owner_w(nskb, (*pskb)->sk);
73 kfree_skb(*pskb);
74 *pskb = nskb;
75 }
76
77 return 0;
78}
79EXPORT_SYMBOL(ip_route_me_harder);
2cc7d573 80
eb9c7ebe
PM
81void (*ip_nat_decode_session)(struct sk_buff *, struct flowi *);
82EXPORT_SYMBOL(ip_nat_decode_session);
83
2cc7d573
HW
84/*
85 * Extra routing may needed on local out, as the QUEUE target never
86 * returns control to the table.
87 */
88
89struct ip_rt_info {
90 u_int32_t daddr;
91 u_int32_t saddr;
92 u_int8_t tos;
93};
94
95static void queue_save(const struct sk_buff *skb, struct nf_info *info)
96{
97 struct ip_rt_info *rt_info = nf_info_reroute(info);
98
99 if (info->hook == NF_IP_LOCAL_OUT) {
100 const struct iphdr *iph = skb->nh.iph;
101
102 rt_info->tos = iph->tos;
103 rt_info->daddr = iph->daddr;
104 rt_info->saddr = iph->saddr;
105 }
106}
107
108static int queue_reroute(struct sk_buff **pskb, const struct nf_info *info)
109{
110 const struct ip_rt_info *rt_info = nf_info_reroute(info);
111
112 if (info->hook == NF_IP_LOCAL_OUT) {
113 struct iphdr *iph = (*pskb)->nh.iph;
114
115 if (!(iph->tos == rt_info->tos
116 && iph->daddr == rt_info->daddr
117 && iph->saddr == rt_info->saddr))
118 return ip_route_me_harder(pskb);
119 }
120 return 0;
121}
122
123static struct nf_queue_rerouter ip_reroute = {
124 .rer_size = sizeof(struct ip_rt_info),
125 .save = queue_save,
126 .reroute = queue_reroute,
127};
128
129static int init(void)
130{
131 return nf_register_queue_rerouter(PF_INET, &ip_reroute);
132}
133
134static void fini(void)
135{
136 nf_unregister_queue_rerouter(PF_INET);
137}
138
139module_init(init);
140module_exit(fini);
This page took 0.079973 seconds and 5 git commands to generate.