summaryrefslogtreecommitdiffstats
path: root/net/ipv6/exthdrs.c
blob: b2380fb78fed99cd4cc518f5175a3921ec683102 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
 *	Extension Header handling for IPv6
 *	Linux INET6 implementation
 *
 *	Authors:
 *	Pedro Roque		<roque@di.fc.ul.pt>
 *
 *	$Id: exthdrs.c,v 1.4 1997/03/18 18:24:29 davem Exp $
 *
 *	This program is free software; you can redistribute it and/or
 *      modify it under the terms of the GNU General Public License
 *      as published by the Free Software Foundation; either version
 *      2 of the License, or (at your option) any later version.
 */

#include <linux/errno.h>
#include <linux/types.h>
#include <linux/socket.h>
#include <linux/sockios.h>
#include <linux/sched.h>
#include <linux/net.h>
#include <linux/netdevice.h>
#include <linux/in6.h>
#include <linux/icmpv6.h>

#include <net/sock.h>
#include <net/snmp.h>

#include <net/ipv6.h>
#include <net/protocol.h>
#include <net/transp_v6.h>
#include <net/rawv6.h>
#include <net/ndisc.h>
#include <net/ip6_route.h>
#include <net/addrconf.h>

/*
 *	inbound
 */
#if 0
int ipv6_routing_header(struct sk_buff **skb_ptr, struct device *dev,
			__u8 *nhptr, struct ipv6_options *opt)
{
	struct sk_buff *skb = *skb_ptr;
	struct in6_addr *addr;
	struct in6_addr daddr;
	int addr_type = 0;
	int strict = 0;
	__u32 bit_map;
	int pos;
	int n, i;

	struct ipv6_rt_hdr *hdr = (struct ipv6_rt_hdr *) skb->h.raw;
	struct rt0_hdr *rthdr;

	if (hdr->segments_left == 0) {
		struct ipv6_options *opt;

		opt = (struct ipv6_options *) skb->cb;
		opt->srcrt = hdr;

		skb->h.raw += (hdr->hdrlen + 1) << 3;
		return hdr->nexthdr;		
	}

	if (hdr->type != IPV6_SRCRT_TYPE_0 || hdr->hdrlen & 0x01 ||
	    hdr->hdrlen > 46) {
                /* 
		 *	Discard 
		 */
		
		pos = (__u8 *) hdr - (__u8 *) skb->nh.ipv6h + 2;

		if (hdr->type)
			pos += 2;
		else
			pos += 1;

		icmpv6_send(skb, ICMPV6_PARAMETER_PROB, 0, pos, dev);
		kfree_skb(skb, FREE_READ);
		return 0;	
	}

	/*
	 *	This is the routing header forwarding algorithm from
	 *	RFC 1883, page 17.
	 */

	n = hdr->hdrlen >> 1;

	if (hdr->segments_left > n) {
		pos = (__u8 *) hdr - (__u8 *) skb->nh.ipv6h + 2;

		pos += 3;

		icmpv6_send(skb, ICMPV6_PARAMETER_PROB, 0, pos, dev);
		kfree_skb(skb, FREE_READ);
		return 0;
	}

	i = n - --hdr->segments_left;

	rthdr = (struct rt0_hdr *) hdr;
	addr = rthdr->addr;
	addr += i - 1;

	addr_type = ipv6_addr_type(addr);

	if (addr_type == IPV6_ADDR_MULTICAST) {
		kfree_skb(skb, FREE_READ);
		return 0;
	}

	ipv6_addr_copy(&daddr, addr);
	ipv6_addr_copy(addr, &skb->nh.ipv6h->daddr);
	ipv6_addr_copy(&skb->nh.ipv6h->daddr, &daddr);

	/*
	 *	Check Strick Source Route
	 */

	bit_map = ntohl(rthdr->bitmap);

	if ((bit_map & (1 << i)) == IPV6_SRCRT_STRICT)
		strict = 1;

	ipv6_forward(skb, dev, (strict ? IP6_FW_STRICT : 0) | IP6_FW_SRCRT);

	return 0;
}


/*
 *	outbound
 */

int ipv6opt_bld_rthdr(struct sk_buff *skb, struct ipv6_options *opt,
		      struct in6_addr *addr, int proto)		      
{
	struct rt0_hdr *phdr, *ihdr;
	int hops;

	ihdr = (struct rt0_hdr *) opt->srcrt;
	
	phdr = (struct rt0_hdr *) skb_put(skb, (ihdr->rt_hdr.hdrlen + 1) << 3);
	memcpy(phdr, ihdr, sizeof(struct ipv6_rt_hdr));

	hops = ihdr->rt_hdr.hdrlen >> 1;
	
	if (hops > 1)
		memcpy(phdr->addr, ihdr->addr + 1,
		       (hops - 1) * sizeof(struct in6_addr));

	ipv6_addr_copy(phdr->addr + (hops - 1), addr);
	
	phdr->rt_hdr.nexthdr = proto;

	return NEXTHDR_ROUTING;
}
#endif