Skip to content

Commit 2c8d7ca

Browse files
Noriaki TAKAMIYADavid S. Miller
authored andcommitted
[IPV6] MIP6: Add routing header type 2 transformation.
Add routing header type 2 transformation for Mobile IPv6. Based on MIPL2 kernel patch. Signed-off-by: Noriaki TAKAMIYA <takamiya@po.ntts.co.jp> Signed-off-by: Masahide NAKAMURA <nakam@linux-ipv6.org> Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 27637df commit 2c8d7ca

4 files changed

Lines changed: 223 additions & 0 deletions

File tree

‎include/net/mip6.h‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
* YOSHIFUJI Hideaki @USAGI
24+
*/
25+
#ifndef _NET_MIP6_H
26+
#define _NET_MIP6_H
27+
28+
extern int mip6_init(void);
29+
extern void mip6_fini(void);
30+
31+
#endif

‎net/ipv6/Makefile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ ipv6-$(CONFIG_XFRM) += xfrm6_policy.o xfrm6_state.o xfrm6_input.o \
1414
xfrm6_output.o
1515
ipv6-$(CONFIG_NETFILTER) += netfilter.o
1616
ipv6-$(CONFIG_IPV6_MULTIPLE_TABLES) += fib6_rules.o
17+
ipv6-$(CONFIG_IPV6_MIP6) += mip6.o
18+
1719
ipv6-objs += $(ipv6-y)
1820

1921
obj-$(CONFIG_INET6_AH) += ah6.o

‎net/ipv6/af_inet6.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
#ifdef CONFIG_IPV6_TUNNEL
6060
#include <net/ip6_tunnel.h>
6161
#endif
62+
#ifdef CONFIG_IPV6_MIP6
63+
#include <net/mip6.h>
64+
#endif
6265

6366
#include <asm/uaccess.h>
6467
#include <asm/system.h>
@@ -857,6 +860,9 @@ static int __init inet6_init(void)
857860
ipv6_frag_init();
858861
ipv6_nodata_init();
859862
ipv6_destopt_init();
863+
#ifdef CONFIG_IPV6_MIP6
864+
mip6_init();
865+
#endif
860866

861867
/* Init v6 transport protocols. */
862868
udpv6_init();
@@ -919,6 +925,9 @@ static void __exit inet6_exit(void)
919925
udp6_proc_exit();
920926
tcp6_proc_exit();
921927
raw6_proc_exit();
928+
#endif
929+
#ifdef CONFIG_IPV6_MIP6
930+
mip6_fini();
922931
#endif
923932
/* Cleanup code parts. */
924933
sit_cleanup();

‎net/ipv6/mip6.c‎

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
33+
static xfrm_address_t *mip6_xfrm_addr(struct xfrm_state *x, xfrm_address_t *addr)
34+
{
35+
return x->coaddr;
36+
}
37+
38+
static 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+
*/
52+
static 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+
79+
static 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+
123+
static 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+
*/
145+
static void mip6_rthdr_destroy(struct xfrm_state *x)
146+
{
147+
}
148+
149+
static 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+
163+
int __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+
177+
void __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+
}

0 commit comments

Comments
 (0)