]> bbs.cooldavid.org Git - net-next-2.6.git/blame - net/ipv6/netfilter.c
[NETFILTER]: nf_queue: remove unused data pointer
[net-next-2.6.git] / net / ipv6 / netfilter.c
CommitLineData
020b4c12 1#include <linux/kernel.h>
bb94aa16 2#include <linux/init.h>
020b4c12 3#include <linux/ipv6.h>
2cc7d573
HW
4#include <linux/netfilter.h>
5#include <linux/netfilter_ipv6.h>
020b4c12
HW
6#include <net/dst.h>
7#include <net/ipv6.h>
8#include <net/ip6_route.h>
3e3850e9 9#include <net/xfrm.h>
503e4faa 10#include <net/ip6_checksum.h>
020b4c12
HW
11
12int ip6_route_me_harder(struct sk_buff *skb)
13{
0660e03f 14 struct ipv6hdr *iph = ipv6_hdr(skb);
020b4c12
HW
15 struct dst_entry *dst;
16 struct flowi fl = {
17 .oif = skb->sk ? skb->sk->sk_bound_dev_if : 0,
bc5f7743 18 .mark = skb->mark,
020b4c12
HW
19 .nl_u =
20 { .ip6_u =
21 { .daddr = iph->daddr,
22 .saddr = iph->saddr, } },
020b4c12
HW
23 };
24
25 dst = ip6_route_output(skb->sk, &fl);
26
3e3850e9
PM
27#ifdef CONFIG_XFRM
28 if (!(IP6CB(skb)->flags & IP6SKB_XFRM_TRANSFORMED) &&
29 xfrm_decode_session(skb, &fl, AF_INET6) == 0)
30 if (xfrm_lookup(&skb->dst, &fl, skb->sk, 0))
31 return -1;
32#endif
33
020b4c12 34 if (dst->error) {
a11d206d 35 IP6_INC_STATS(ip6_dst_idev(dst), IPSTATS_MIB_OUTNOROUTES);
64ce2073 36 LIMIT_NETDEBUG(KERN_DEBUG "ip6_route_me_harder: No more route.\n");
020b4c12
HW
37 dst_release(dst);
38 return -EINVAL;
39 }
40
41 /* Drop old route. */
42 dst_release(skb->dst);
43
44 skb->dst = dst;
45 return 0;
46}
47EXPORT_SYMBOL(ip6_route_me_harder);
48
2cc7d573
HW
49/*
50 * Extra routing may needed on local out, as the QUEUE target never
51 * returns control to the table.
52 */
53
54struct ip6_rt_info {
55 struct in6_addr daddr;
56 struct in6_addr saddr;
57};
58
bce8032e 59static void nf_ip6_saveroute(const struct sk_buff *skb, struct nf_info *info)
2cc7d573
HW
60{
61 struct ip6_rt_info *rt_info = nf_info_reroute(info);
62
6e23ae2a 63 if (info->hook == NF_INET_LOCAL_OUT) {
0660e03f 64 struct ipv6hdr *iph = ipv6_hdr(skb);
2cc7d573
HW
65
66 rt_info->daddr = iph->daddr;
67 rt_info->saddr = iph->saddr;
68 }
69}
70
3db05fea 71static int nf_ip6_reroute(struct sk_buff *skb, const struct nf_info *info)
2cc7d573
HW
72{
73 struct ip6_rt_info *rt_info = nf_info_reroute(info);
74
6e23ae2a 75 if (info->hook == NF_INET_LOCAL_OUT) {
3db05fea 76 struct ipv6hdr *iph = ipv6_hdr(skb);
2cc7d573
HW
77 if (!ipv6_addr_equal(&iph->daddr, &rt_info->daddr) ||
78 !ipv6_addr_equal(&iph->saddr, &rt_info->saddr))
3db05fea 79 return ip6_route_me_harder(skb);
2cc7d573
HW
80 }
81 return 0;
82}
83
1841a4c7
PM
84static int nf_ip6_route(struct dst_entry **dst, struct flowi *fl)
85{
86 *dst = ip6_route_output(NULL, fl);
87 return (*dst)->error;
88}
89
b51655b9 90__sum16 nf_ip6_checksum(struct sk_buff *skb, unsigned int hook,
422c346f
PM
91 unsigned int dataoff, u_int8_t protocol)
92{
0660e03f 93 struct ipv6hdr *ip6h = ipv6_hdr(skb);
b51655b9 94 __sum16 csum = 0;
422c346f
PM
95
96 switch (skb->ip_summed) {
84fa7933 97 case CHECKSUM_COMPLETE:
6e23ae2a 98 if (hook != NF_INET_PRE_ROUTING && hook != NF_INET_LOCAL_IN)
422c346f
PM
99 break;
100 if (!csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
1ab1457c 101 skb->len - dataoff, protocol,
422c346f
PM
102 csum_sub(skb->csum,
103 skb_checksum(skb, 0,
104 dataoff, 0)))) {
105 skb->ip_summed = CHECKSUM_UNNECESSARY;
106 break;
107 }
108 /* fall through */
109 case CHECKSUM_NONE:
868c86bc
AV
110 skb->csum = ~csum_unfold(
111 csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
422c346f
PM
112 skb->len - dataoff,
113 protocol,
114 csum_sub(0,
115 skb_checksum(skb, 0,
1ab1457c 116 dataoff, 0))));
422c346f
PM
117 csum = __skb_checksum_complete(skb);
118 }
119 return csum;
120}
121
122EXPORT_SYMBOL(nf_ip6_checksum);
123
bce8032e
PM
124static struct nf_afinfo nf_ip6_afinfo = {
125 .family = AF_INET6,
422c346f 126 .checksum = nf_ip6_checksum,
1841a4c7 127 .route = nf_ip6_route,
bce8032e
PM
128 .saveroute = nf_ip6_saveroute,
129 .reroute = nf_ip6_reroute,
130 .route_key_size = sizeof(struct ip6_rt_info),
2cc7d573
HW
131};
132
133int __init ipv6_netfilter_init(void)
134{
bce8032e 135 return nf_register_afinfo(&nf_ip6_afinfo);
2cc7d573
HW
136}
137
5bf887f2
DM
138/* This can be called from inet6_init() on errors, so it cannot
139 * be marked __exit. -DaveM
140 */
141void ipv6_netfilter_fini(void)
2cc7d573 142{
bce8032e 143 nf_unregister_afinfo(&nf_ip6_afinfo);
2cc7d573 144}