3 * Linux INET6 implementation
6 * Pedro Roque <roque@di.fc.ul.pt>
7 * Ian P. Morris <I.P.Morris@soton.ac.uk>
9 * $Id: ip6_input.c,v 1.15 2000/01/09 02:19:54 davem Exp $
11 * Based in linux/net/ipv4/ip_input.c
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.
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>
33 #include <net/protocol.h>
34 #include <net/transp_v6.h>
35 #include <net/rawv6.h>
36 #include <net/ndisc.h>
37 #include <net/ip6_route.h>
38 #include <net/addrconf.h>
41 int ipv6_rcv(struct sk_buff
*skb
, struct net_device
*dev
, struct packet_type
*pt
)
46 if (skb
->pkt_type
== PACKET_OTHERHOST
)
49 IP6_INC_STATS_BH(Ip6InReceives
);
51 if ((skb
= skb_share_check(skb
, GFP_ATOMIC
)) == NULL
)
54 /* Store incoming device index. When the packet will
55 be queued, we cannot refer to skb->dev anymore.
57 ((struct inet6_skb_parm
*)skb
->cb
)->iif
= dev
->ifindex
;
61 if (skb
->len
< sizeof(struct ipv6hdr
) || hdr
->version
!= 6)
64 pkt_len
= ntohs(hdr
->payload_len
);
66 /* pkt_len may be zero if Jumbo payload option is present */
67 if (pkt_len
|| hdr
->nexthdr
!= NEXTHDR_HOP
) {
68 if (pkt_len
+ sizeof(struct ipv6hdr
) > skb
->len
)
70 skb_trim(skb
, pkt_len
+ sizeof(struct ipv6hdr
));
73 if (hdr
->nexthdr
== NEXTHDR_HOP
) {
74 skb
->h
.raw
= (u8
*)(hdr
+1);
75 if (!ipv6_parse_hopopts(skb
, &hdr
->nexthdr
)) {
76 IP6_INC_STATS_BH(Ip6InHdrErrors
);
84 return skb
->dst
->input(skb
);
87 IP6_INC_STATS_BH(Ip6InTruncatedPkts
);
89 IP6_INC_STATS_BH(Ip6InHdrErrors
);
97 * Deliver the packet to the host
100 int ip6_input(struct sk_buff
*skb
)
102 struct ipv6hdr
*hdr
= skb
->nh
.ipv6h
;
103 struct inet6_protocol
*ipprot
;
111 skb
->h
.raw
= skb
->nh
.raw
+ sizeof(struct ipv6hdr
);
114 * Parse extension headers
117 nexthdr
= hdr
->nexthdr
;
118 nhptr
= &hdr
->nexthdr
;
120 /* Skip hop-by-hop options, they are already parsed. */
121 if (nexthdr
== NEXTHDR_HOP
) {
122 nhptr
= (u8
*)(hdr
+1);
124 skb
->h
.raw
+= (nhptr
[1]+1)<<3;
127 /* This check is sort of optimization.
128 It would be stupid to detect for optional headers,
129 which are missing with probability of 200%
131 if (nexthdr
!= IPPROTO_TCP
&& nexthdr
!= IPPROTO_UDP
) {
132 nhptr
= ipv6_parse_exthdrs(&skb
, nhptr
);
138 len
= skb
->tail
- skb
->h
.raw
;
141 dev_put(skb
->rx_dev
);
145 raw_sk
= raw_v6_htable
[nexthdr
&(MAX_INET_PROTOS
-1)];
147 raw_sk
= ipv6_raw_deliver(skb
, nexthdr
, len
);
149 hash
= nexthdr
& (MAX_INET_PROTOS
- 1);
150 read_lock(&inet6_protocol_lock
);
151 for (ipprot
= (struct inet6_protocol
*) inet6_protos
[hash
];
153 ipprot
= (struct inet6_protocol
*) ipprot
->next
) {
154 struct sk_buff
*buff
= skb
;
156 if (ipprot
->protocol
!= nexthdr
)
159 if (ipprot
->copy
|| raw_sk
)
160 buff
= skb_clone(skb
, GFP_ATOMIC
);
163 ipprot
->handler(buff
, len
);
166 read_unlock(&inet6_protocol_lock
);
169 rawv6_rcv(raw_sk
, skb
, len
);
175 * not found: send ICMP parameter problem back
178 IP6_INC_STATS_BH(Ip6InUnknownProtos
);
179 icmpv6_param_prob(skb
, ICMPV6_UNK_NEXTHDR
, nhptr
);
185 int ip6_mc_input(struct sk_buff
*skb
)
191 IP6_INC_STATS_BH(Ip6InMcastPkts
);
194 if (ipv6_chk_mcast_addr(skb
->dev
, &hdr
->daddr
))
198 * IPv6 multicast router mode isnt currently supported.
201 if (ipv6_config
.multicast_route
) {
204 addr_type
= ipv6_addr_type(&hdr
->daddr
);
206 if (!(addr_type
& (IPV6_ADDR_LOOPBACK
| IPV6_ADDR_LINKLOCAL
))) {
207 struct sk_buff
*skb2
;
208 struct dst_entry
*dst
;
213 skb2
= skb_clone(skb
, GFP_ATOMIC
);