aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/ipv6/Makefile2
-rw-r--r--net/ipv6/af_inet6.c9
-rw-r--r--net/ipv6/mip6.c181
3 files changed, 192 insertions, 0 deletions
diff --git a/net/ipv6/Makefile b/net/ipv6/Makefile
index 87e912e31922..0213c6612b58 100644
--- a/net/ipv6/Makefile
+++ b/net/ipv6/Makefile
@@ -14,6 +14,8 @@ ipv6-$(CONFIG_XFRM) += xfrm6_policy.o xfrm6_state.o xfrm6_input.o \
14 xfrm6_output.o 14 xfrm6_output.o
15ipv6-$(CONFIG_NETFILTER) += netfilter.o 15ipv6-$(CONFIG_NETFILTER) += netfilter.o
16ipv6-$(CONFIG_IPV6_MULTIPLE_TABLES) += fib6_rules.o 16ipv6-$(CONFIG_IPV6_MULTIPLE_TABLES) += fib6_rules.o
17ipv6-$(CONFIG_IPV6_MIP6) += mip6.o
18
17ipv6-objs += $(ipv6-y) 19ipv6-objs += $(ipv6-y)
18 20
19obj-$(CONFIG_INET6_AH) += ah6.o 21obj-$(CONFIG_INET6_AH) += ah6.o
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index 57ee5ddea96f..fc9c8a99bea6 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -59,6 +59,9 @@
59#ifdef CONFIG_IPV6_TUNNEL 59#ifdef CONFIG_IPV6_TUNNEL
60#include <net/ip6_tunnel.h> 60#include <net/ip6_tunnel.h>
61#endif 61#endif
62#ifdef CONFIG_IPV6_MIP6
63#include <net/mip6.h>
64#endif
62 65
63#include <asm/uaccess.h> 66#include <asm/uaccess.h>
64#include <asm/system.h> 67#include <asm/system.h>
@@ -857,6 +860,9 @@ static int __init inet6_init(void)
857 ipv6_frag_init(); 860 ipv6_frag_init();
858 ipv6_nodata_init(); 861 ipv6_nodata_init();
859 ipv6_destopt_init(); 862 ipv6_destopt_init();
863#ifdef CONFIG_IPV6_MIP6
864 mip6_init();
865#endif
860 866
861 /* Init v6 transport protocols. */ 867 /* Init v6 transport protocols. */
862 udpv6_init(); 868 udpv6_init();
@@ -920,6 +926,9 @@ static void __exit inet6_exit(void)
920 tcp6_proc_exit(); 926 tcp6_proc_exit();
921 raw6_proc_exit(); 927 raw6_proc_exit();
922#endif 928#endif
929#ifdef CONFIG_IPV6_MIP6
930 mip6_fini();
931#endif
923 /* Cleanup code parts. */ 932 /* Cleanup code parts. */
924 sit_cleanup(); 933 sit_cleanup();
925 ip6_flowlabel_cleanup(); 934 ip6_flowlabel_cleanup();
diff --git a/net/ipv6/mip6.c b/net/ipv6/mip6.c
new file mode 100644
index 000000000000..63e548b6f81e
--- /dev/null
+++ b/net/ipv6/mip6.c
@@ -0,0 +1,181 @@
1/*
2 * Copyright (C)2003-2006 Helsinki University of Technology
3 * Copyright (C)2003-2006 USAGI/WIDE Project
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19/*
20 * Authors:
21 * Noriaki TAKAMIYA @USAGI
22 * Masahide NAKAMURA @USAGI
23 */
24
25#include <linux/config.h>
26#include <linux/module.h>
27#include <linux/skbuff.h>
28#include <linux/ipv6.h>
29#include <net/ipv6.h>
30#include <net/xfrm.h>
31#include <net/mip6.h>
32
33static xfrm_address_t *mip6_xfrm_addr(struct xfrm_state *x, xfrm_address_t *addr)
34{
35 return x->coaddr;
36}
37
38static int mip6_rthdr_input(struct xfrm_state *x, struct sk_buff *skb)
39{
40 struct rt2_hdr *rt2 = (struct rt2_hdr *)skb->data;
41
42 if (!ipv6_addr_equal(&rt2->addr, (struct in6_addr *)x->coaddr) &&
43 !ipv6_addr_any((struct in6_addr *)x->coaddr))
44 return -ENOENT;
45
46 return rt2->rt_hdr.nexthdr;
47}
48
49/* Routing Header type 2 is inserted.
50 * IP Header's dst address is replaced with Routing Header's Home Address.
51 */
52static int mip6_rthdr_output(struct xfrm_state *x, struct sk_buff *skb)
53{
54 struct ipv6hdr *iph;
55 struct rt2_hdr *rt2;
56 u8 nexthdr;
57
58 iph = (struct ipv6hdr *)skb->data;
59 iph->payload_len = htons(skb->len - sizeof(*iph));
60
61 nexthdr = *skb->nh.raw;
62 *skb->nh.raw = IPPROTO_ROUTING;
63
64 rt2 = (struct rt2_hdr *)skb->h.raw;
65 rt2->rt_hdr.nexthdr = nexthdr;
66 rt2->rt_hdr.hdrlen = (x->props.header_len >> 3) - 1;
67 rt2->rt_hdr.type = IPV6_SRCRT_TYPE_2;
68 rt2->rt_hdr.segments_left = 1;
69 memset(&rt2->reserved, 0, sizeof(rt2->reserved));
70
71 BUG_TRAP(rt2->rt_hdr.hdrlen == 2);
72
73 memcpy(&rt2->addr, &iph->daddr, sizeof(rt2->addr));
74 memcpy(&iph->daddr, x->coaddr, sizeof(iph->daddr));
75
76 return 0;
77}
78
79static int mip6_rthdr_offset(struct xfrm_state *x, struct sk_buff *skb,
80 u8 **nexthdr)
81{
82 u16 offset = sizeof(struct ipv6hdr);
83 struct ipv6_opt_hdr *exthdr = (struct ipv6_opt_hdr*)(skb->nh.ipv6h + 1);
84 unsigned int packet_len = skb->tail - skb->nh.raw;
85 int found_rhdr = 0;
86
87 *nexthdr = &skb->nh.ipv6h->nexthdr;
88
89 while (offset + 1 <= packet_len) {
90
91 switch (**nexthdr) {
92 case NEXTHDR_HOP:
93 break;
94 case NEXTHDR_ROUTING:
95 if (offset + 3 <= packet_len) {
96 struct ipv6_rt_hdr *rt;
97 rt = (struct ipv6_rt_hdr *)(skb->nh.raw + offset);
98 if (rt->type != 0)
99 return offset;
100 }
101 found_rhdr = 1;
102 break;
103 case NEXTHDR_DEST:
104 if (ipv6_find_tlv(skb, offset, IPV6_TLV_HAO) >= 0)
105 return offset;
106
107 if (found_rhdr)
108 return offset;
109
110 break;
111 default:
112 return offset;
113 }
114
115 offset += ipv6_optlen(exthdr);
116 *nexthdr = &exthdr->nexthdr;
117 exthdr = (struct ipv6_opt_hdr*)(skb->nh.raw + offset);
118 }
119
120 return offset;
121}
122
123static int mip6_rthdr_init_state(struct xfrm_state *x)
124{
125 if (x->id.spi) {
126 printk(KERN_INFO "%s: spi is not 0: %u\n", __FUNCTION__,
127 x->id.spi);
128 return -EINVAL;
129 }
130 if (x->props.mode != XFRM_MODE_ROUTEOPTIMIZATION) {
131 printk(KERN_INFO "%s: state's mode is not %u: %u\n",
132 __FUNCTION__, XFRM_MODE_ROUTEOPTIMIZATION, x->props.mode);
133 return -EINVAL;
134 }
135
136 x->props.header_len = sizeof(struct rt2_hdr);
137
138 return 0;
139}
140
141/*
142 * Do nothing about destroying since it has no specific operation for routing
143 * header type 2 unlike IPsec protocols.
144 */
145static void mip6_rthdr_destroy(struct xfrm_state *x)
146{
147}
148
149static struct xfrm_type mip6_rthdr_type =
150{
151 .description = "MIP6RT",
152 .owner = THIS_MODULE,
153 .proto = IPPROTO_ROUTING,
154 .flags = XFRM_TYPE_NON_FRAGMENT,
155 .init_state = mip6_rthdr_init_state,
156 .destructor = mip6_rthdr_destroy,
157 .input = mip6_rthdr_input,
158 .output = mip6_rthdr_output,
159 .hdr_offset = mip6_rthdr_offset,
160 .remote_addr = mip6_xfrm_addr,
161};
162
163int __init mip6_init(void)
164{
165 printk(KERN_INFO "Mobile IPv6\n");
166
167 if (xfrm_register_type(&mip6_rthdr_type, AF_INET6) < 0) {
168 printk(KERN_INFO "%s: can't add xfrm type(rthdr)\n", __FUNCTION__);
169 goto mip6_rthdr_xfrm_fail;
170 }
171 return 0;
172
173 mip6_rthdr_xfrm_fail:
174 return -EAGAIN;
175}
176
177void __exit mip6_fini(void)
178{
179 if (xfrm_unregister_type(&mip6_rthdr_type, AF_INET6) < 0)
180 printk(KERN_INFO "%s: can't remove xfrm type(rthdr)\n", __FUNCTION__);
181}