24 #include <linux/errno.h>
25 #include <linux/types.h>
26 #include <linux/socket.h>
28 #include <linux/net.h>
29 #include <linux/netdevice.h>
30 #include <linux/in6.h>
31 #include <linux/icmpv6.h>
32 #include <linux/slab.h>
33 #include <linux/export.h>
46 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
50 #include <asm/uaccess.h>
54 const unsigned char *nh = skb_network_header(skb);
59 if (offset + 2 > packet_len)
62 len = ((hdr->
hdrlen + 1) << 3);
64 if (offset + len > packet_len)
82 optlen = nh[offset + 1] + 2;
115 static bool ip6_tlvopt_unknown(
struct sk_buff *
skb,
int optoff)
117 switch ((skb_network_header(skb)[optoff] & 0xC0) >> 6) {
128 if (ipv6_addr_is_multicast(&ipv6_hdr(skb)->
daddr))
144 const unsigned char *nh = skb_network_header(skb);
145 int off = skb_network_header_len(skb);
146 int len = (skb_transport_header(skb)[1] + 1) << 3;
149 if (skb_transport_offset(skb) + len > skb_headlen(skb))
156 int optlen = nh[off + 1] + 2;
180 for (i = 2; i < optlen; i++) {
181 if (nh[off + i] != 0)
189 for (curr=procs; curr->
type >= 0; curr++) {
190 if (curr->
type == nh[off]) {
194 if (curr->
func(skb, off) ==
false)
199 if (curr->
type < 0) {
200 if (ip6_tlvopt_unknown(skb, off) == 0)
213 if ((padlen == 6) && ((off - skb_network_header_len(skb)) == 8))
227 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
228 static bool ipv6_dest_hao(
struct sk_buff *skb,
int optoff)
232 struct ipv6hdr *ipv6h = ipv6_hdr(skb);
240 opt->dsthao = opt->
dst1;
262 if (skb_cloned(skb)) {
269 ipv6h = ipv6_hdr(skb);
275 tmp_addr = ipv6h->
saddr;
277 hao->
addr = tmp_addr;
280 __net_timestamp(skb);
290 static const struct tlvtype_proc tlvprocdestopt_lst[] = {
291 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
294 .func = ipv6_dest_hao,
300 static int ipv6_destopt_rcv(
struct sk_buff *skb)
303 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
308 if (!pskb_may_pull(skb, skb_transport_offset(skb) + 8) ||
309 !pskb_may_pull(skb, (skb_transport_offset(skb) +
310 ((skb_transport_header(skb)[1] + 1) << 3)))) {
317 opt->
lastopt = opt->
dst1 = skb_network_header_len(skb);
318 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
322 if (ip6_parse_tlv(tlvprocdestopt_lst, skb)) {
325 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
343 static int ipv6_rthdr_rcv(
struct sk_buff *skb)
353 int accept_source_route = net->ipv6.devconf_all->accept_source_route;
355 idev = __in6_dev_get(skb->
dev);
356 if (idev && accept_source_route > idev->
cnf.accept_source_route)
357 accept_source_route = idev->
cnf.accept_source_route;
359 if (!pskb_may_pull(skb, skb_transport_offset(skb) + 8) ||
360 !pskb_may_pull(skb, (skb_transport_offset(skb) +
361 ((skb_transport_header(skb)[1] + 1) << 3)))) {
368 hdr = (
struct ipv6_rt_hdr *)skb_transport_header(skb);
370 if (ipv6_addr_is_multicast(&ipv6_hdr(skb)->
daddr) ||
381 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
398 opt->
lastopt = opt->
srcrt = skb_network_header_len(skb);
407 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
409 if (accept_source_route < 0)
436 skb_network_header(skb)));
443 if (skb_cloned(skb)) {
451 hdr = (
struct ipv6_rt_hdr *)skb_transport_header(skb);
459 rthdr = (
struct rt0_hdr *) hdr;
464 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
474 if (!ipv6_chk_home_addr(dev_net(skb_dst(skb)->
dev), addr)) {
486 if (ipv6_addr_is_multicast(addr)) {
494 *addr = ipv6_hdr(skb)->daddr;
495 ipv6_hdr(skb)->daddr =
daddr;
499 if (skb_dst(skb)->
error) {
514 ipv6_hdr(skb)->hop_limit--;
525 (&hdr->
type) - skb_network_header(skb));
529 static const struct inet6_protocol rthdr_protocol = {
530 .handler = ipv6_rthdr_rcv,
531 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_GSO_EXTHDR,
534 static const struct inet6_protocol destopt_protocol = {
535 .handler = ipv6_destopt_rcv,
536 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_GSO_EXTHDR,
539 static const struct inet6_protocol nodata_protocol = {
541 .flags = INET6_PROTO_NOPOLICY,
585 return skb_dst(skb) ? ip6_dst_idev(skb_dst(skb)) : __in6_dev_get(skb->
dev);
588 static inline struct net *ipv6_skb_net(
struct sk_buff *skb)
590 return skb_dst(skb) ? dev_net(skb_dst(skb)->
dev) : dev_net(skb->
dev);
595 static bool ipv6_hop_ra(
struct sk_buff *skb,
int optoff)
597 const unsigned char *nh = skb_network_header(skb);
599 if (nh[optoff + 1] == 2) {
600 IP6CB(skb)->ra = optoff;
611 static bool ipv6_hop_jumbo(
struct sk_buff *skb,
int optoff)
613 const unsigned char *nh = skb_network_header(skb);
614 struct net *net = ipv6_skb_net(skb);
617 if (nh[optoff + 1] != 4 || (optoff & 3) != 2) {
639 if (pkt_len > skb->
len -
sizeof(
struct ipv6hdr)) {
645 if (pskb_trim_rcsum(skb, pkt_len +
sizeof(
struct ipv6hdr)))
655 static const struct tlvtype_proc tlvprochopopt_lst[] = {
662 .func = ipv6_hop_jumbo,
677 if (!pskb_may_pull(skb,
sizeof(
struct ipv6hdr) + 8) ||
678 !pskb_may_pull(skb, (
sizeof(
struct ipv6hdr) +
679 ((skb_transport_header(skb)[1] + 1) << 3)))) {
685 if (ip6_parse_tlv(tlvprochopopt_lst, skb)) {
716 hops = ihdr->
rt_hdr.hdrlen >> 1;
720 (hops - 1) *
sizeof(
struct in6_addr));
722 phdr->
addr[hops - 1] = **addr_p;
723 *addr_p = ihdr->
addr;
743 ipv6_push_rthdr(skb, proto, opt->
srcrt, daddr);
769 long dif = (
char *)opt2 - (
char *)
opt;
772 *((
char **)&opt2->
hopopt) += dif;
774 *((
char **)&opt2->
dst0opt) += dif;
776 *((
char **)&opt2->
dst1opt) += dif;
778 *((
char **)&opt2->
srcrt) += dif;
784 static int ipv6_renew_option(
void *ohdr,
830 if (newopt && newoptlen)
836 tot_len +=
sizeof(*opt2);
844 p = (
char *)(opt2 + 1);
846 err = ipv6_renew_option(opt ? opt->
hopopt :
NULL, newopt, newoptlen,
852 err = ipv6_renew_option(opt ? opt->
dst0opt : NULL, newopt, newoptlen,
858 err = ipv6_renew_option(opt ? opt->
srcrt : NULL, newopt, newoptlen,
864 err = ipv6_renew_option(opt ? opt->
dst1opt : NULL, newopt, newoptlen,
889 if (opt_space != opt) {
890 memcpy(opt_space, opt,
sizeof(*opt_space));
916 if (!opt || !opt->
srcrt)