1 /*
2 * IPv6 input
3 * Linux INET6 implementation
4 *
5 * Authors:
6 * Pedro Roque <roque@di.fc.ul.pt>
7 * Ian P. Morris <I.P.Morris@soton.ac.uk>
8 *
9 * $Id: ip6_input.c,v 1.18 2000/12/08 17:15:54 davem Exp $
10 *
11 * Based in linux/net/ipv4/ip_input.c
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version
16 * 2 of the License, or (at your option) any later version.
17 */
18
19 #include <linux/errno.h>
20 #include <linux/types.h>
21 #include <linux/socket.h>
22 #include <linux/sockios.h>
23 #include <linux/sched.h>
24 #include <linux/net.h>
25 #include <linux/netdevice.h>
26 #include <linux/in6.h>
27 #include <linux/icmpv6.h>
28
29 #include <linux/netfilter.h>
30 #include <linux/netfilter_ipv6.h>
31
32 #include <net/sock.h>
33 #include <net/snmp.h>
34
35 #include <net/ipv6.h>
36 #include <net/protocol.h>
37 #include <net/transp_v6.h>
38 #include <net/rawv6.h>
39 #include <net/ndisc.h>
40 #include <net/ip6_route.h>
41 #include <net/addrconf.h>
42
43
44
45 static inline int ip6_rcv_finish( struct sk_buff *skb)
46 {
47
48 if (skb->dst == NULL)
49 ip6_route_input(skb);
50
51 return skb->dst->input(skb);
52 }
53
54 int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt)
55 {
56 struct ipv6hdr *hdr;
57 u32 pkt_len;
58
59 if (skb->pkt_type == PACKET_OTHERHOST)
60 goto drop;
61
62 IP6_INC_STATS_BH(Ip6InReceives);
63
64 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
65 goto out;
66
67 /* Store incoming device index. When the packet will
68 be queued, we cannot refer to skb->dev anymore.
69 */
70 ((struct inet6_skb_parm *)skb->cb)->iif = dev->ifindex;
71
72 hdr = skb->nh.ipv6h;
73
74 if (skb->len < sizeof(struct ipv6hdr) || hdr->version != 6)
75 goto err;
76
77 pkt_len = ntohs(hdr->payload_len);
78
79 /* pkt_len may be zero if Jumbo payload option is present */
80 if (pkt_len || hdr->nexthdr != NEXTHDR_HOP) {
81 if (pkt_len + sizeof(struct ipv6hdr) > skb->len)
82 goto truncated;
83 skb_trim(skb, pkt_len + sizeof(struct ipv6hdr));
84 }
85
86 if (hdr->nexthdr == NEXTHDR_HOP) {
87 skb->h.raw = (u8*)(hdr+1);
88 if (!ipv6_parse_hopopts(skb, &hdr->nexthdr)) {
89 IP6_INC_STATS_BH(Ip6InHdrErrors);
90 return 0;
91 }
92 }
93 return NF_HOOK(PF_INET6,NF_IP6_PRE_ROUTING, skb, dev, NULL, ip6_rcv_finish);
94 truncated:
95 IP6_INC_STATS_BH(Ip6InTruncatedPkts);
96 err:
97 IP6_INC_STATS_BH(Ip6InHdrErrors);
98 drop:
99 kfree_skb(skb);
100 out:
101 return 0;
102 }
103
104 /*
105 * Deliver the packet to the host
106 */
107
108
109 static inline int ip6_input_finish(struct sk_buff *skb)
110 {
111 struct ipv6hdr *hdr = skb->nh.ipv6h;
112 struct inet6_protocol *ipprot;
113 struct sock *raw_sk;
114 __u8 *nhptr;
115 int nexthdr;
116 int found = 0;
117 u8 hash;
118 int len;
119
120 skb->h.raw = skb->nh.raw + sizeof(struct ipv6hdr);
121
122 /*
123 * Parse extension headers
124 */
125
126 nexthdr = hdr->nexthdr;
127 nhptr = &hdr->nexthdr;
128
129 /* Skip hop-by-hop options, they are already parsed. */
130 if (nexthdr == NEXTHDR_HOP) {
131 nhptr = (u8*)(hdr+1);
132 nexthdr = *nhptr;
133 skb->h.raw += (nhptr[1]+1)<<3;
134 }
135
136 /* This check is sort of optimization.
137 It would be stupid to detect for optional headers,
138 which are missing with probability of 200%
139 */
140 if (nexthdr != IPPROTO_TCP && nexthdr != IPPROTO_UDP) {
141 nhptr = ipv6_parse_exthdrs(&skb, nhptr);
142 if (nhptr == NULL)
143 return 0;
144 nexthdr = *nhptr;
145 hdr = skb->nh.ipv6h;
146 }
147 len = skb->tail - skb->h.raw;
148
149 raw_sk = raw_v6_htable[nexthdr&(MAX_INET_PROTOS-1)];
150 if (raw_sk)
151 raw_sk = ipv6_raw_deliver(skb, nexthdr, len);
152
153 hash = nexthdr & (MAX_INET_PROTOS - 1);
154 for (ipprot = (struct inet6_protocol *) inet6_protos[hash];
155 ipprot != NULL;
156 ipprot = (struct inet6_protocol *) ipprot->next) {
157 struct sk_buff *buff = skb;
158
159 if (ipprot->protocol != nexthdr)
160 continue;
161
162 if (ipprot->copy || raw_sk)
163 buff = skb_clone(skb, GFP_ATOMIC);
164
165 if (buff)
166 ipprot->handler(buff, len);
167 found = 1;
168 }
169
170 if (raw_sk) {
171 rawv6_rcv(raw_sk, skb, len);
172 sock_put(raw_sk);
173 found = 1;
174 }
175
176 /*
177 * not found: send ICMP parameter problem back
178 */
179 if (!found) {
180 IP6_INC_STATS_BH(Ip6InUnknownProtos);
181 icmpv6_param_prob(skb, ICMPV6_UNK_NEXTHDR, nhptr);
182 }
183
184 return 0;
185 }
186
187
188 int ip6_input(struct sk_buff *skb)
189 {
190 return NF_HOOK(PF_INET6,NF_IP6_LOCAL_IN, skb, skb->dev, NULL, ip6_input_finish);
191 }
192
193 int ip6_mc_input(struct sk_buff *skb)
194 {
195 struct ipv6hdr *hdr;
196 int deliver = 0;
197 int discard = 1;
198
199 IP6_INC_STATS_BH(Ip6InMcastPkts);
200
201 hdr = skb->nh.ipv6h;
202 if (ipv6_chk_mcast_addr(skb->dev, &hdr->daddr))
203 deliver = 1;
204
205 /*
206 * IPv6 multicast router mode isnt currently supported.
207 */
208 #if 0
209 if (ipv6_config.multicast_route) {
210 int addr_type;
211
212 addr_type = ipv6_addr_type(&hdr->daddr);
213
214 if (!(addr_type & (IPV6_ADDR_LOOPBACK | IPV6_ADDR_LINKLOCAL))) {
215 struct sk_buff *skb2;
216 struct dst_entry *dst;
217
218 dst = skb->dst;
219
220 if (deliver) {
221 skb2 = skb_clone(skb, GFP_ATOMIC);
222 } else {
223 discard = 0;
224 skb2 = skb;
225 }
226
227 dst->output(skb2);
228 }
229 }
230 #endif
231
232 if (deliver) {
233 discard = 0;
234 ip6_input(skb);
235 }
236
237 if (discard)
238 kfree_skb(skb);
239
240 return 0;
241 }
242
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.