11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * IPv6 input 31da177e4SLinus Torvalds * Linux INET6 implementation 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Authors: 61da177e4SLinus Torvalds * Pedro Roque <[email protected]> 71da177e4SLinus Torvalds * Ian P. Morris <[email protected]> 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * Based in linux/net/ipv4/ip_input.c 101da177e4SLinus Torvalds * 111da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or 121da177e4SLinus Torvalds * modify it under the terms of the GNU General Public License 131da177e4SLinus Torvalds * as published by the Free Software Foundation; either version 141da177e4SLinus Torvalds * 2 of the License, or (at your option) any later version. 151da177e4SLinus Torvalds */ 161da177e4SLinus Torvalds /* Changes 171da177e4SLinus Torvalds * 181da177e4SLinus Torvalds * Mitsuru KANDA @USAGI and 191da177e4SLinus Torvalds * YOSHIFUJI Hideaki @USAGI: Remove ipv6_parse_exthdrs(). 201da177e4SLinus Torvalds */ 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds #include <linux/errno.h> 231da177e4SLinus Torvalds #include <linux/types.h> 241da177e4SLinus Torvalds #include <linux/socket.h> 251da177e4SLinus Torvalds #include <linux/sockios.h> 261da177e4SLinus Torvalds #include <linux/net.h> 271da177e4SLinus Torvalds #include <linux/netdevice.h> 281da177e4SLinus Torvalds #include <linux/in6.h> 291da177e4SLinus Torvalds #include <linux/icmpv6.h> 307bc570c8SYOSHIFUJI Hideaki #include <linux/mroute6.h> 315a0e3ad6STejun Heo #include <linux/slab.h> 321da177e4SLinus Torvalds 331da177e4SLinus Torvalds #include <linux/netfilter.h> 341da177e4SLinus Torvalds #include <linux/netfilter_ipv6.h> 351da177e4SLinus Torvalds 361da177e4SLinus Torvalds #include <net/sock.h> 371da177e4SLinus Torvalds #include <net/snmp.h> 381da177e4SLinus Torvalds 391da177e4SLinus Torvalds #include <net/ipv6.h> 401da177e4SLinus Torvalds #include <net/protocol.h> 411da177e4SLinus Torvalds #include <net/transp_v6.h> 421da177e4SLinus Torvalds #include <net/rawv6.h> 431da177e4SLinus Torvalds #include <net/ndisc.h> 441da177e4SLinus Torvalds #include <net/ip6_route.h> 451da177e4SLinus Torvalds #include <net/addrconf.h> 461da177e4SLinus Torvalds #include <net/xfrm.h> 471f07d03eSEric Dumazet #include <net/inet_ecn.h> 4848fb6b55SWei-Chun Chao #include <net/dst_metadata.h> 491da177e4SLinus Torvalds 500c4b51f0SEric W. Biederman int ip6_rcv_finish(struct net *net, struct sock *sk, struct sk_buff *skb) 511da177e4SLinus Torvalds { 5274b20582SDavid Ahern /* if ingress device is enslaved to an L3 master device pass the 5374b20582SDavid Ahern * skb to its handler for processing 5474b20582SDavid Ahern */ 5574b20582SDavid Ahern skb = l3mdev_ip6_rcv(skb); 5674b20582SDavid Ahern if (!skb) 5774b20582SDavid Ahern return NET_RX_SUCCESS; 5874b20582SDavid Ahern 59e21145a9SNikolay Borisov if (net->ipv4.sysctl_ip_early_demux && !skb_dst(skb) && skb->sk == NULL) { 60c7109986SEric Dumazet const struct inet6_protocol *ipprot; 61c7109986SEric Dumazet 62c7109986SEric Dumazet ipprot = rcu_dereference(inet6_protos[ipv6_hdr(skb)->nexthdr]); 63c7109986SEric Dumazet if (ipprot && ipprot->early_demux) 64c7109986SEric Dumazet ipprot->early_demux(skb); 65c7109986SEric Dumazet } 6648fb6b55SWei-Chun Chao if (!skb_valid_dst(skb)) 671da177e4SLinus Torvalds ip6_route_input(skb); 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds return dst_input(skb); 701da177e4SLinus Torvalds } 711da177e4SLinus Torvalds 72f2ccd8faSDavid S. Miller int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev) 731da177e4SLinus Torvalds { 74b71d1d42SEric Dumazet const struct ipv6hdr *hdr; 751da177e4SLinus Torvalds u32 pkt_len; 76a11d206dSYOSHIFUJI Hideaki struct inet6_dev *idev; 77483a47d2SDenis V. Lunev struct net *net = dev_net(skb->dev); 781da177e4SLinus Torvalds 79a11d206dSYOSHIFUJI Hideaki if (skb->pkt_type == PACKET_OTHERHOST) { 80a11d206dSYOSHIFUJI Hideaki kfree_skb(skb); 815c91faceSMark Smith return NET_RX_DROP; 82a11d206dSYOSHIFUJI Hideaki } 831da177e4SLinus Torvalds 84a11d206dSYOSHIFUJI Hideaki rcu_read_lock(); 85a11d206dSYOSHIFUJI Hideaki 86a11d206dSYOSHIFUJI Hideaki idev = __in6_dev_get(skb->dev); 87a11d206dSYOSHIFUJI Hideaki 88c2005eb0SEric Dumazet __IP6_UPD_PO_STATS(net, idev, IPSTATS_MIB_IN, skb->len); 891da177e4SLinus Torvalds 90778d80beSYOSHIFUJI Hideaki if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL || 91778d80beSYOSHIFUJI Hideaki !idev || unlikely(idev->cnf.disable_ipv6)) { 921d015503SEric Dumazet __IP6_INC_STATS(net, idev, IPSTATS_MIB_INDISCARDS); 9371f6f6dfSJesper Nilsson goto drop; 941da177e4SLinus Torvalds } 951da177e4SLinus Torvalds 966b7fdc3aSGuillaume Chazarain memset(IP6CB(skb), 0, sizeof(struct inet6_skb_parm)); 976b7fdc3aSGuillaume Chazarain 981da177e4SLinus Torvalds /* 991da177e4SLinus Torvalds * Store incoming device index. When the packet will 1001da177e4SLinus Torvalds * be queued, we cannot refer to skb->dev anymore. 1011da177e4SLinus Torvalds * 1021da177e4SLinus Torvalds * BTW, when we send a packet for our own local address on a 1031da177e4SLinus Torvalds * non-loopback interface (e.g. ethX), it is being delivered 104de3cb747SDaniel Lezcano * via the loopback interface (lo) here; skb->dev = loopback_dev. 1051da177e4SLinus Torvalds * It, however, should be considered as if it is being 1061da177e4SLinus Torvalds * arrived via the sending interface (ethX), because of the 1071da177e4SLinus Torvalds * nature of scoping architecture. --yoshfuji 1081da177e4SLinus Torvalds */ 10948fb6b55SWei-Chun Chao IP6CB(skb)->iif = skb_valid_dst(skb) ? ip6_dst_idev(skb_dst(skb))->dev->ifindex : dev->ifindex; 1101da177e4SLinus Torvalds 1112889139aSHerbert Xu if (unlikely(!pskb_may_pull(skb, sizeof(*hdr)))) 1121da177e4SLinus Torvalds goto err; 1131da177e4SLinus Torvalds 1140660e03fSArnaldo Carvalho de Melo hdr = ipv6_hdr(skb); 1151da177e4SLinus Torvalds 1161da177e4SLinus Torvalds if (hdr->version != 6) 1171da177e4SLinus Torvalds goto err; 1181da177e4SLinus Torvalds 1191d015503SEric Dumazet __IP6_ADD_STATS(net, idev, 1201f07d03eSEric Dumazet IPSTATS_MIB_NOECTPKTS + 1211f07d03eSEric Dumazet (ipv6_get_dsfield(hdr) & INET_ECN_MASK), 1221f07d03eSEric Dumazet max_t(unsigned short, 1, skb_shinfo(skb)->gso_segs)); 123f630e43aSYOSHIFUJI Hideaki /* 124f630e43aSYOSHIFUJI Hideaki * RFC4291 2.5.3 125*0aa8c13eSFlorian Westphal * The loopback address must not be used as the source address in IPv6 126*0aa8c13eSFlorian Westphal * packets that are sent outside of a single node. [..] 127f630e43aSYOSHIFUJI Hideaki * A packet received on an interface with a destination address 128f630e43aSYOSHIFUJI Hideaki * of loopback must be dropped. 129f630e43aSYOSHIFUJI Hideaki */ 130*0aa8c13eSFlorian Westphal if ((ipv6_addr_loopback(&hdr->saddr) || 131*0aa8c13eSFlorian Westphal ipv6_addr_loopback(&hdr->daddr)) && 132*0aa8c13eSFlorian Westphal !(dev->flags & IFF_LOOPBACK)) 133f630e43aSYOSHIFUJI Hideaki goto err; 134f630e43aSYOSHIFUJI Hideaki 1351c4a154eSHannes Frederic Sowa /* RFC4291 Errata ID: 3480 1361c4a154eSHannes Frederic Sowa * Interface-Local scope spans only a single interface on a 1371c4a154eSHannes Frederic Sowa * node and is useful only for loopback transmission of 1381c4a154eSHannes Frederic Sowa * multicast. Packets with interface-local scope received 1391c4a154eSHannes Frederic Sowa * from another node must be discarded. 1401c4a154eSHannes Frederic Sowa */ 1411c4a154eSHannes Frederic Sowa if (!(skb->pkt_type == PACKET_LOOPBACK || 1421c4a154eSHannes Frederic Sowa dev->flags & IFF_LOOPBACK) && 1431c4a154eSHannes Frederic Sowa ipv6_addr_is_multicast(&hdr->daddr) && 1441c4a154eSHannes Frederic Sowa IPV6_ADDR_MC_SCOPE(&hdr->daddr) == 1) 1451c4a154eSHannes Frederic Sowa goto err; 1461c4a154eSHannes Frederic Sowa 147abbc3043SJohannes Berg /* If enabled, drop unicast packets that were encapsulated in link-layer 148abbc3043SJohannes Berg * multicast or broadcast to protected against the so-called "hole-196" 149abbc3043SJohannes Berg * attack in 802.11 wireless. 150abbc3043SJohannes Berg */ 151abbc3043SJohannes Berg if (!ipv6_addr_is_multicast(&hdr->daddr) && 152abbc3043SJohannes Berg (skb->pkt_type == PACKET_BROADCAST || 153abbc3043SJohannes Berg skb->pkt_type == PACKET_MULTICAST) && 154abbc3043SJohannes Berg idev->cnf.drop_unicast_in_l2_multicast) 155abbc3043SJohannes Berg goto err; 156abbc3043SJohannes Berg 15720314092SHannes Frederic Sowa /* RFC4291 2.7 15820314092SHannes Frederic Sowa * Nodes must not originate a packet to a multicast address whose scope 15920314092SHannes Frederic Sowa * field contains the reserved value 0; if such a packet is received, it 16020314092SHannes Frederic Sowa * must be silently dropped. 16120314092SHannes Frederic Sowa */ 16220314092SHannes Frederic Sowa if (ipv6_addr_is_multicast(&hdr->daddr) && 16320314092SHannes Frederic Sowa IPV6_ADDR_MC_SCOPE(&hdr->daddr) == 0) 16420314092SHannes Frederic Sowa goto err; 16520314092SHannes Frederic Sowa 166c457338dSBrian Haley /* 167c457338dSBrian Haley * RFC4291 2.7 168c457338dSBrian Haley * Multicast addresses must not be used as source addresses in IPv6 169c457338dSBrian Haley * packets or appear in any Routing header. 170c457338dSBrian Haley */ 171c457338dSBrian Haley if (ipv6_addr_is_multicast(&hdr->saddr)) 172c457338dSBrian Haley goto err; 173c457338dSBrian Haley 174b0e380b1SArnaldo Carvalho de Melo skb->transport_header = skb->network_header + sizeof(*hdr); 175951dbc8aSPatrick McHardy IP6CB(skb)->nhoff = offsetof(struct ipv6hdr, nexthdr); 176951dbc8aSPatrick McHardy 1771da177e4SLinus Torvalds pkt_len = ntohs(hdr->payload_len); 1781da177e4SLinus Torvalds 1791da177e4SLinus Torvalds /* pkt_len may be zero if Jumbo payload option is present */ 1801da177e4SLinus Torvalds if (pkt_len || hdr->nexthdr != NEXTHDR_HOP) { 18160e5c166SMitsuru Chinen if (pkt_len + sizeof(struct ipv6hdr) > skb->len) { 1821d015503SEric Dumazet __IP6_INC_STATS(net, 183483a47d2SDenis V. Lunev idev, IPSTATS_MIB_INTRUNCATEDPKTS); 18460e5c166SMitsuru Chinen goto drop; 18560e5c166SMitsuru Chinen } 1861da177e4SLinus Torvalds if (pskb_trim_rcsum(skb, pkt_len + sizeof(struct ipv6hdr))) { 1871d015503SEric Dumazet __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS); 1881da177e4SLinus Torvalds goto drop; 1891da177e4SLinus Torvalds } 1900660e03fSArnaldo Carvalho de Melo hdr = ipv6_hdr(skb); 1911da177e4SLinus Torvalds } 1921da177e4SLinus Torvalds 1931da177e4SLinus Torvalds if (hdr->nexthdr == NEXTHDR_HOP) { 194e5bbef20SHerbert Xu if (ipv6_parse_hopopts(skb) < 0) { 1951d015503SEric Dumazet __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS); 196a11d206dSYOSHIFUJI Hideaki rcu_read_unlock(); 1975c91faceSMark Smith return NET_RX_DROP; 1981da177e4SLinus Torvalds } 1991da177e4SLinus Torvalds } 2001da177e4SLinus Torvalds 201a11d206dSYOSHIFUJI Hideaki rcu_read_unlock(); 202a11d206dSYOSHIFUJI Hideaki 20371f9dacdSHerbert Xu /* Must drop socket now because of tproxy. */ 20471f9dacdSHerbert Xu skb_orphan(skb); 20571f9dacdSHerbert Xu 20629a26a56SEric W. Biederman return NF_HOOK(NFPROTO_IPV6, NF_INET_PRE_ROUTING, 20729a26a56SEric W. Biederman net, NULL, skb, dev, NULL, 2086e23ae2aSPatrick McHardy ip6_rcv_finish); 2091da177e4SLinus Torvalds err: 2101d015503SEric Dumazet __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS); 2111da177e4SLinus Torvalds drop: 212a11d206dSYOSHIFUJI Hideaki rcu_read_unlock(); 2131da177e4SLinus Torvalds kfree_skb(skb); 2145c91faceSMark Smith return NET_RX_DROP; 2151da177e4SLinus Torvalds } 2161da177e4SLinus Torvalds 2171da177e4SLinus Torvalds /* 2181da177e4SLinus Torvalds * Deliver the packet to the host 2191da177e4SLinus Torvalds */ 2201da177e4SLinus Torvalds 2211da177e4SLinus Torvalds 2220c4b51f0SEric W. Biederman static int ip6_input_finish(struct net *net, struct sock *sk, struct sk_buff *skb) 2231da177e4SLinus Torvalds { 22441135cc8SAlexey Dobriyan const struct inet6_protocol *ipprot; 225f9242b6bSDavid S. Miller struct inet6_dev *idev; 2261da177e4SLinus Torvalds unsigned int nhoff; 227a50feda5SEric Dumazet int nexthdr; 228a50feda5SEric Dumazet bool raw; 2291da44f9cSTom Herbert bool have_final = false; 2301da177e4SLinus Torvalds 2311da177e4SLinus Torvalds /* 2321da177e4SLinus Torvalds * Parse extension headers 2331da177e4SLinus Torvalds */ 2341da177e4SLinus Torvalds 2351da177e4SLinus Torvalds rcu_read_lock(); 2361b0ccfe5SDavid S. Miller resubmit: 237adf30907SEric Dumazet idev = ip6_dst_idev(skb_dst(skb)); 238ea2ae17dSArnaldo Carvalho de Melo if (!pskb_pull(skb, skb_transport_offset(skb))) 2391da177e4SLinus Torvalds goto discard; 240951dbc8aSPatrick McHardy nhoff = IP6CB(skb)->nhoff; 241d56f90a7SArnaldo Carvalho de Melo nexthdr = skb_network_header(skb)[nhoff]; 2421da177e4SLinus Torvalds 2434c64242aSTom Herbert resubmit_final: 24469d6da0bSPavel Emelyanov raw = raw6_local_deliver(skb, nexthdr); 245e5d08d71SIan Morris ipprot = rcu_dereference(inet6_protos[nexthdr]); 24653b24b8fSIan Morris if (ipprot) { 2471da177e4SLinus Torvalds int ret; 2481da177e4SLinus Torvalds 2491da44f9cSTom Herbert if (have_final) { 2501da44f9cSTom Herbert if (!(ipprot->flags & INET6_PROTO_FINAL)) { 2511da44f9cSTom Herbert /* Once we've seen a final protocol don't 2521da44f9cSTom Herbert * allow encapsulation on any non-final 2531da44f9cSTom Herbert * ones. This allows foo in UDP encapsulation 2541da44f9cSTom Herbert * to work. 2551da44f9cSTom Herbert */ 2561da44f9cSTom Herbert goto discard; 2571da44f9cSTom Herbert } 2581da44f9cSTom Herbert } else if (ipprot->flags & INET6_PROTO_FINAL) { 259b71d1d42SEric Dumazet const struct ipv6hdr *hdr; 2601da177e4SLinus Torvalds 2611da44f9cSTom Herbert /* Only do this once for first final protocol */ 2621da44f9cSTom Herbert have_final = true; 2631da44f9cSTom Herbert 2649fb9cbb1SYasuyuki Kozakai /* Free reference early: we don't need it any more, 2659fb9cbb1SYasuyuki Kozakai and it may hold ip_conntrack module loaded 2669fb9cbb1SYasuyuki Kozakai indefinitely. */ 2679fb9cbb1SYasuyuki Kozakai nf_reset(skb); 2689fb9cbb1SYasuyuki Kozakai 269d56f90a7SArnaldo Carvalho de Melo skb_postpull_rcsum(skb, skb_network_header(skb), 270cfe1fc77SArnaldo Carvalho de Melo skb_network_header_len(skb)); 2710660e03fSArnaldo Carvalho de Melo hdr = ipv6_hdr(skb); 2721da177e4SLinus Torvalds if (ipv6_addr_is_multicast(&hdr->daddr) && 2731da177e4SLinus Torvalds !ipv6_chk_mcast_addr(skb->dev, &hdr->daddr, 2741da177e4SLinus Torvalds &hdr->saddr) && 275daad1512SYOSHIFUJI Hideaki / 吉藤英明 !ipv6_is_mld(skb, nexthdr, skb_network_header_len(skb))) 2761da177e4SLinus Torvalds goto discard; 2771da177e4SLinus Torvalds } 2781da177e4SLinus Torvalds if (!(ipprot->flags & INET6_PROTO_NOPOLICY) && 2791da177e4SLinus Torvalds !xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) 2801da177e4SLinus Torvalds goto discard; 2811da177e4SLinus Torvalds 282e5bbef20SHerbert Xu ret = ipprot->handler(skb); 2834c64242aSTom Herbert if (ret > 0) { 2844c64242aSTom Herbert if (ipprot->flags & INET6_PROTO_FINAL) { 2854c64242aSTom Herbert /* Not an extension header, most likely UDP 2864c64242aSTom Herbert * encapsulation. Use return value as nexthdr 2874c64242aSTom Herbert * protocol not nhoff (which presumably is 2884c64242aSTom Herbert * not set by handler). 2894c64242aSTom Herbert */ 2904c64242aSTom Herbert nexthdr = ret; 2914c64242aSTom Herbert goto resubmit_final; 2924c64242aSTom Herbert } else { 2931da177e4SLinus Torvalds goto resubmit; 2944c64242aSTom Herbert } 2954c64242aSTom Herbert } else if (ret == 0) { 2961d015503SEric Dumazet __IP6_INC_STATS(net, idev, IPSTATS_MIB_INDELIVERS); 2974c64242aSTom Herbert } 2981da177e4SLinus Torvalds } else { 29969d6da0bSPavel Emelyanov if (!raw) { 3001da177e4SLinus Torvalds if (xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) { 3011d015503SEric Dumazet __IP6_INC_STATS(net, idev, 302483a47d2SDenis V. Lunev IPSTATS_MIB_INUNKNOWNPROTOS); 303fad87acaSPatrick McHardy icmpv6_send(skb, ICMPV6_PARAMPROB, 3043ffe533cSAlexey Dobriyan ICMPV6_UNK_NEXTHDR, nhoff); 3051da177e4SLinus Torvalds } 3061da177e4SLinus Torvalds kfree_skb(skb); 307d8c6f4b9SNeil Horman } else { 3081d015503SEric Dumazet __IP6_INC_STATS(net, idev, IPSTATS_MIB_INDELIVERS); 309d8c6f4b9SNeil Horman consume_skb(skb); 310d8c6f4b9SNeil Horman } 3111da177e4SLinus Torvalds } 3121da177e4SLinus Torvalds rcu_read_unlock(); 3131da177e4SLinus Torvalds return 0; 3141da177e4SLinus Torvalds 3151da177e4SLinus Torvalds discard: 3161d015503SEric Dumazet __IP6_INC_STATS(net, idev, IPSTATS_MIB_INDISCARDS); 3171da177e4SLinus Torvalds rcu_read_unlock(); 3181da177e4SLinus Torvalds kfree_skb(skb); 3191da177e4SLinus Torvalds return 0; 3201da177e4SLinus Torvalds } 3211da177e4SLinus Torvalds 3221da177e4SLinus Torvalds 3231da177e4SLinus Torvalds int ip6_input(struct sk_buff *skb) 3241da177e4SLinus Torvalds { 32529a26a56SEric W. Biederman return NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_IN, 32629a26a56SEric W. Biederman dev_net(skb->dev), NULL, skb, skb->dev, NULL, 3276e23ae2aSPatrick McHardy ip6_input_finish); 3281da177e4SLinus Torvalds } 329b4869aa2SDavid Ahern EXPORT_SYMBOL_GPL(ip6_input); 3301da177e4SLinus Torvalds 3311da177e4SLinus Torvalds int ip6_mc_input(struct sk_buff *skb) 3321da177e4SLinus Torvalds { 333b71d1d42SEric Dumazet const struct ipv6hdr *hdr; 334a50feda5SEric Dumazet bool deliver; 3351da177e4SLinus Torvalds 336c2005eb0SEric Dumazet __IP6_UPD_PO_STATS(dev_net(skb_dst(skb)->dev), 337adf30907SEric Dumazet ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_INMCAST, 338edf391ffSNeil Horman skb->len); 3391da177e4SLinus Torvalds 3400660e03fSArnaldo Carvalho de Melo hdr = ipv6_hdr(skb); 3414c7966b8SYOSHIFUJI Hideaki deliver = ipv6_chk_mcast_addr(skb->dev, &hdr->daddr, NULL); 3421da177e4SLinus Torvalds 3437bc570c8SYOSHIFUJI Hideaki #ifdef CONFIG_IPV6_MROUTE 3441da177e4SLinus Torvalds /* 3457bc570c8SYOSHIFUJI Hideaki * IPv6 multicast router mode is now supported ;) 3461da177e4SLinus Torvalds */ 34753b7997fSYOSHIFUJI Hideaki if (dev_net(skb->dev)->ipv6.devconf_all->mc_forwarding && 348ddf64354SHannes Frederic Sowa !(ipv6_addr_type(&hdr->daddr) & 349ddf64354SHannes Frederic Sowa (IPV6_ADDR_LOOPBACK|IPV6_ADDR_LINKLOCAL)) && 3507bc570c8SYOSHIFUJI Hideaki likely(!(IP6CB(skb)->flags & IP6SKB_FORWARDED))) { 3517bc570c8SYOSHIFUJI Hideaki /* 3527bc570c8SYOSHIFUJI Hideaki * Okay, we try to forward - split and duplicate 3537bc570c8SYOSHIFUJI Hideaki * packets. 3547bc570c8SYOSHIFUJI Hideaki */ 3551da177e4SLinus Torvalds struct sk_buff *skb2; 3567bc570c8SYOSHIFUJI Hideaki struct inet6_skb_parm *opt = IP6CB(skb); 3571da177e4SLinus Torvalds 3587bc570c8SYOSHIFUJI Hideaki /* Check for MLD */ 359dd3332bfSYOSHIFUJI Hideaki / 吉藤英明 if (unlikely(opt->flags & IP6SKB_ROUTERALERT)) { 3607bc570c8SYOSHIFUJI Hideaki /* Check if this is a mld message */ 3617bc570c8SYOSHIFUJI Hideaki u8 nexthdr = hdr->nexthdr; 36275f2811cSJesse Gross __be16 frag_off; 3637bc570c8SYOSHIFUJI Hideaki int offset; 3641da177e4SLinus Torvalds 3657bc570c8SYOSHIFUJI Hideaki /* Check if the value of Router Alert 3667bc570c8SYOSHIFUJI Hideaki * is for MLD (0x0000). 3677bc570c8SYOSHIFUJI Hideaki */ 368dd3332bfSYOSHIFUJI Hideaki / 吉藤英明 if (opt->ra == htons(IPV6_OPT_ROUTERALERT_MLD)) { 369a50feda5SEric Dumazet deliver = false; 370aba6096bSYOSHIFUJI Hideaki 3717bc570c8SYOSHIFUJI Hideaki if (!ipv6_ext_hdr(nexthdr)) { 3727bc570c8SYOSHIFUJI Hideaki /* BUG */ 373aba6096bSYOSHIFUJI Hideaki goto out; 3741da177e4SLinus Torvalds } 3757bc570c8SYOSHIFUJI Hideaki offset = ipv6_skip_exthdr(skb, sizeof(*hdr), 37675f2811cSJesse Gross &nexthdr, &frag_off); 3777bc570c8SYOSHIFUJI Hideaki if (offset < 0) 378aba6096bSYOSHIFUJI Hideaki goto out; 3797bc570c8SYOSHIFUJI Hideaki 3804c938d22SAngga if (ipv6_is_mld(skb, nexthdr, offset)) 381a50feda5SEric Dumazet deliver = true; 3824c938d22SAngga 3834c938d22SAngga goto out; 3847bc570c8SYOSHIFUJI Hideaki } 3857bc570c8SYOSHIFUJI Hideaki /* unknown RA - process it normally */ 3867bc570c8SYOSHIFUJI Hideaki } 3877bc570c8SYOSHIFUJI Hideaki 3887bc570c8SYOSHIFUJI Hideaki if (deliver) 3897bc570c8SYOSHIFUJI Hideaki skb2 = skb_clone(skb, GFP_ATOMIC); 3907bc570c8SYOSHIFUJI Hideaki else { 3917bc570c8SYOSHIFUJI Hideaki skb2 = skb; 3927bc570c8SYOSHIFUJI Hideaki skb = NULL; 3937bc570c8SYOSHIFUJI Hideaki } 3947bc570c8SYOSHIFUJI Hideaki 3957bc570c8SYOSHIFUJI Hideaki if (skb2) { 3967bc570c8SYOSHIFUJI Hideaki ip6_mr_input(skb2); 3971da177e4SLinus Torvalds } 3981da177e4SLinus Torvalds } 3997bc570c8SYOSHIFUJI Hideaki out: 400aba6096bSYOSHIFUJI Hideaki #endif 401aba6096bSYOSHIFUJI Hideaki if (likely(deliver)) 4021da177e4SLinus Torvalds ip6_input(skb); 403aba6096bSYOSHIFUJI Hideaki else { 4041da177e4SLinus Torvalds /* discard */ 4051da177e4SLinus Torvalds kfree_skb(skb); 406aba6096bSYOSHIFUJI Hideaki } 4071da177e4SLinus Torvalds 4081da177e4SLinus Torvalds return 0; 4091da177e4SLinus Torvalds } 410