]> bbs.cooldavid.org Git - net-next-2.6.git/blame - net/ipv6/netfilter.c
[DCCP]: Finish the TIMEWAIT minisock support
[net-next-2.6.git] / net / ipv6 / netfilter.c
CommitLineData
020b4c12
HW
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>
2cc7d573
HW
8#include <linux/netfilter.h>
9#include <linux/netfilter_ipv6.h>
020b4c12
HW
10#include <net/dst.h>
11#include <net/ipv6.h>
12#include <net/ip6_route.h>
13
14int ip6_route_me_harder(struct sk_buff *skb)
15{
16 struct ipv6hdr *iph = skb->nh.ipv6h;
17 struct dst_entry *dst;
18 struct flowi fl = {
19 .oif = skb->sk ? skb->sk->sk_bound_dev_if : 0,
20 .nl_u =
21 { .ip6_u =
22 { .daddr = iph->daddr,
23 .saddr = iph->saddr, } },
24 .proto = iph->nexthdr,
25 };
26
27 dst = ip6_route_output(skb->sk, &fl);
28
29 if (dst->error) {
30 IP6_INC_STATS(IPSTATS_MIB_OUTNOROUTES);
31 LIMIT_NETDEBUG(
32 printk(KERN_DEBUG "ip6_route_me_harder: No more route.\n"));
33 dst_release(dst);
34 return -EINVAL;
35 }
36
37 /* Drop old route. */
38 dst_release(skb->dst);
39
40 skb->dst = dst;
41 return 0;
42}
43EXPORT_SYMBOL(ip6_route_me_harder);
44
2cc7d573
HW
45/*
46 * Extra routing may needed on local out, as the QUEUE target never
47 * returns control to the table.
48 */
49
50struct ip6_rt_info {
51 struct in6_addr daddr;
52 struct in6_addr saddr;
53};
54
55static void save(const struct sk_buff *skb, struct nf_info *info)
56{
57 struct ip6_rt_info *rt_info = nf_info_reroute(info);
58
59 if (info->hook == NF_IP6_LOCAL_OUT) {
60 struct ipv6hdr *iph = skb->nh.ipv6h;
61
62 rt_info->daddr = iph->daddr;
63 rt_info->saddr = iph->saddr;
64 }
65}
66
67static int reroute(struct sk_buff **pskb, const struct nf_info *info)
68{
69 struct ip6_rt_info *rt_info = nf_info_reroute(info);
70
71 if (info->hook == NF_IP6_LOCAL_OUT) {
72 struct ipv6hdr *iph = (*pskb)->nh.ipv6h;
73 if (!ipv6_addr_equal(&iph->daddr, &rt_info->daddr) ||
74 !ipv6_addr_equal(&iph->saddr, &rt_info->saddr))
75 return ip6_route_me_harder(*pskb);
76 }
77 return 0;
78}
79
80static struct nf_queue_rerouter ip6_reroute = {
81 .rer_size = sizeof(struct ip6_rt_info),
82 .save = &save,
83 .reroute = &reroute,
84};
85
86int __init ipv6_netfilter_init(void)
87{
88 return nf_register_queue_rerouter(PF_INET6, &ip6_reroute);
89}
90
91void ipv6_netfilter_fini(void)
92{
93 nf_unregister_queue_rerouter(PF_INET6);
94}
95
96#else /* CONFIG_NETFILTER */
97int __init ipv6_netfilter_init(void)
98{
99 return 0;
100}
101
102void ipv6_netfilter_fini(void)
103{
104}
020b4c12 105#endif /* CONFIG_NETFILTER */