blob: 9ee208a348f559b27dcc56ee80bf9ad51630cb45 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * IPv6 input
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +09003 * Linux INET6 implementation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * Authors:
6 * Pedro Roque <roque@di.fc.ul.pt>
7 * Ian P. Morris <I.P.Morris@soton.ac.uk>
8 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * Based in linux/net/ipv4/ip_input.c
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
15 */
16/* Changes
17 *
Ian Morris67ba4152014-08-24 21:53:10 +010018 * Mitsuru KANDA @USAGI and
19 * YOSHIFUJI Hideaki @USAGI: Remove ipv6_parse_exthdrs().
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 */
21
22#include <linux/errno.h>
23#include <linux/types.h>
24#include <linux/socket.h>
25#include <linux/sockios.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/net.h>
27#include <linux/netdevice.h>
28#include <linux/in6.h>
29#include <linux/icmpv6.h>
YOSHIFUJI Hideaki7bc570c2008-04-03 09:22:53 +090030#include <linux/mroute6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33#include <linux/netfilter.h>
34#include <linux/netfilter_ipv6.h>
35
36#include <net/sock.h>
37#include <net/snmp.h>
38
39#include <net/ipv6.h>
40#include <net/protocol.h>
41#include <net/transp_v6.h>
42#include <net/rawv6.h>
43#include <net/ndisc.h>
44#include <net/ip6_route.h>
45#include <net/addrconf.h>
46#include <net/xfrm.h>
Eric Dumazet1f07d032013-08-06 03:32:11 -070047#include <net/inet_ecn.h>
Wei-Chun Chao48fb6b52015-07-22 18:13:12 -070048#include <net/dst_metadata.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -050050int ip6_rcv_finish(struct net *net, struct sock *sk, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -060052 void (*edemux)(struct sk_buff *skb);
53
David Ahern74b20582016-05-10 11:19:50 -070054 /* if ingress device is enslaved to an L3 master device pass the
55 * skb to its handler for processing
56 */
57 skb = l3mdev_ip6_rcv(skb);
58 if (!skb)
59 return NET_RX_SUCCESS;
60
Nikolay Borisove21145a2016-02-15 12:11:30 +020061 if (net->ipv4.sysctl_ip_early_demux && !skb_dst(skb) && skb->sk == NULL) {
Eric Dumazetc7109982012-07-26 12:18:11 +000062 const struct inet6_protocol *ipprot;
63
Eric Dumazetc7109982012-07-26 12:18:11 +000064 ipprot = rcu_dereference(inet6_protos[ipv6_hdr(skb)->nexthdr]);
subashab@codeaurora.orgdddb64b2017-03-23 13:34:16 -060065 if (ipprot && (edemux = READ_ONCE(ipprot->early_demux)))
66 edemux(skb);
Eric Dumazetc7109982012-07-26 12:18:11 +000067 }
Wei-Chun Chao48fb6b52015-07-22 18:13:12 -070068 if (!skb_valid_dst(skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 ip6_route_input(skb);
70
71 return dst_input(skb);
72}
73
David S. Millerf2ccd8f2005-08-09 19:34:12 -070074int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
Eric Dumazetb71d1d42011-04-22 04:53:02 +000076 const struct ipv6hdr *hdr;
Ian Morris67ba4152014-08-24 21:53:10 +010077 u32 pkt_len;
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +090078 struct inet6_dev *idev;
Denis V. Lunev483a47d2008-10-08 11:09:27 -070079 struct net *net = dev_net(skb->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +090081 if (skb->pkt_type == PACKET_OTHERHOST) {
82 kfree_skb(skb);
Mark Smith5c91fac2009-07-06 11:26:24 +000083 return NET_RX_DROP;
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +090084 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +090086 rcu_read_lock();
87
88 idev = __in6_dev_get(skb->dev);
89
Eric Dumazetc2005eb2016-04-27 16:44:41 -070090 __IP6_UPD_PO_STATS(net, idev, IPSTATS_MIB_IN, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
YOSHIFUJI Hideaki778d80b2008-06-28 14:17:11 +090092 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL ||
93 !idev || unlikely(idev->cnf.disable_ipv6)) {
Eric Dumazet1d015502016-04-27 16:44:40 -070094 __IP6_INC_STATS(net, idev, IPSTATS_MIB_INDISCARDS);
Jesper Nilsson71f6f6d2009-03-27 00:17:45 -070095 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 }
97
Guillaume Chazarain6b7fdc32006-07-24 23:44:44 -070098 memset(IP6CB(skb), 0, sizeof(struct inet6_skb_parm));
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 /*
101 * Store incoming device index. When the packet will
102 * be queued, we cannot refer to skb->dev anymore.
103 *
104 * BTW, when we send a packet for our own local address on a
105 * non-loopback interface (e.g. ethX), it is being delivered
Daniel Lezcanode3cb742007-09-25 19:16:28 -0700106 * via the loopback interface (lo) here; skb->dev = loopback_dev.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 * It, however, should be considered as if it is being
108 * arrived via the sending interface (ethX), because of the
109 * nature of scoping architecture. --yoshfuji
110 */
Wei-Chun Chao48fb6b52015-07-22 18:13:12 -0700111 IP6CB(skb)->iif = skb_valid_dst(skb) ? ip6_dst_idev(skb_dst(skb))->dev->ifindex : dev->ifindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Herbert Xu28891392006-06-30 13:35:46 -0700113 if (unlikely(!pskb_may_pull(skb, sizeof(*hdr))))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 goto err;
115
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -0700116 hdr = ipv6_hdr(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118 if (hdr->version != 6)
119 goto err;
120
Eric Dumazet1d015502016-04-27 16:44:40 -0700121 __IP6_ADD_STATS(net, idev,
122 IPSTATS_MIB_NOECTPKTS +
Eric Dumazet1f07d032013-08-06 03:32:11 -0700123 (ipv6_get_dsfield(hdr) & INET_ECN_MASK),
Eric Dumazet1d015502016-04-27 16:44:40 -0700124 max_t(unsigned short, 1, skb_shinfo(skb)->gso_segs));
YOSHIFUJI Hideakif630e432008-06-19 16:33:57 -0700125 /*
126 * RFC4291 2.5.3
Florian Westphal0aa8c132017-04-14 20:22:43 +0200127 * The loopback address must not be used as the source address in IPv6
128 * packets that are sent outside of a single node. [..]
YOSHIFUJI Hideakif630e432008-06-19 16:33:57 -0700129 * A packet received on an interface with a destination address
130 * of loopback must be dropped.
131 */
Florian Westphal0aa8c132017-04-14 20:22:43 +0200132 if ((ipv6_addr_loopback(&hdr->saddr) ||
133 ipv6_addr_loopback(&hdr->daddr)) &&
134 !(dev->flags & IFF_LOOPBACK))
YOSHIFUJI Hideakif630e432008-06-19 16:33:57 -0700135 goto err;
136
Hannes Frederic Sowa1c4a1542013-03-26 08:13:34 +0000137 /* RFC4291 Errata ID: 3480
138 * Interface-Local scope spans only a single interface on a
139 * node and is useful only for loopback transmission of
140 * multicast. Packets with interface-local scope received
141 * from another node must be discarded.
142 */
143 if (!(skb->pkt_type == PACKET_LOOPBACK ||
144 dev->flags & IFF_LOOPBACK) &&
145 ipv6_addr_is_multicast(&hdr->daddr) &&
146 IPV6_ADDR_MC_SCOPE(&hdr->daddr) == 1)
147 goto err;
148
Johannes Bergabbc3042016-02-04 13:31:19 +0100149 /* If enabled, drop unicast packets that were encapsulated in link-layer
150 * multicast or broadcast to protected against the so-called "hole-196"
151 * attack in 802.11 wireless.
152 */
153 if (!ipv6_addr_is_multicast(&hdr->daddr) &&
154 (skb->pkt_type == PACKET_BROADCAST ||
155 skb->pkt_type == PACKET_MULTICAST) &&
156 idev->cnf.drop_unicast_in_l2_multicast)
157 goto err;
158
Hannes Frederic Sowa20314092013-02-10 05:35:22 +0000159 /* RFC4291 2.7
160 * Nodes must not originate a packet to a multicast address whose scope
161 * field contains the reserved value 0; if such a packet is received, it
162 * must be silently dropped.
163 */
164 if (ipv6_addr_is_multicast(&hdr->daddr) &&
165 IPV6_ADDR_MC_SCOPE(&hdr->daddr) == 0)
166 goto err;
167
Brian Haleyc4573382011-11-08 04:41:42 +0000168 /*
169 * RFC4291 2.7
170 * Multicast addresses must not be used as source addresses in IPv6
171 * packets or appear in any Routing header.
172 */
173 if (ipv6_addr_is_multicast(&hdr->saddr))
174 goto err;
175
Arnaldo Carvalho de Melob0e380b2007-04-10 21:21:55 -0700176 skb->transport_header = skb->network_header + sizeof(*hdr);
Patrick McHardy951dbc82006-01-06 23:02:34 -0800177 IP6CB(skb)->nhoff = offsetof(struct ipv6hdr, nexthdr);
178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 pkt_len = ntohs(hdr->payload_len);
180
181 /* pkt_len may be zero if Jumbo payload option is present */
182 if (pkt_len || hdr->nexthdr != NEXTHDR_HOP) {
Mitsuru Chinen60e5c162007-04-04 23:54:59 -0700183 if (pkt_len + sizeof(struct ipv6hdr) > skb->len) {
Eric Dumazet1d015502016-04-27 16:44:40 -0700184 __IP6_INC_STATS(net,
185 idev, IPSTATS_MIB_INTRUNCATEDPKTS);
Mitsuru Chinen60e5c162007-04-04 23:54:59 -0700186 goto drop;
187 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 if (pskb_trim_rcsum(skb, pkt_len + sizeof(struct ipv6hdr))) {
Eric Dumazet1d015502016-04-27 16:44:40 -0700189 __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 goto drop;
191 }
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -0700192 hdr = ipv6_hdr(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 }
194
195 if (hdr->nexthdr == NEXTHDR_HOP) {
Herbert Xue5bbef22007-10-15 12:50:28 -0700196 if (ipv6_parse_hopopts(skb) < 0) {
Eric Dumazet1d015502016-04-27 16:44:40 -0700197 __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS);
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900198 rcu_read_unlock();
Mark Smith5c91fac2009-07-06 11:26:24 +0000199 return NET_RX_DROP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 }
202
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900203 rcu_read_unlock();
204
Herbert Xu71f9dac2009-06-26 19:22:37 -0700205 /* Must drop socket now because of tproxy. */
206 skb_orphan(skb);
207
Eric W. Biederman29a26a52015-09-15 20:04:16 -0500208 return NF_HOOK(NFPROTO_IPV6, NF_INET_PRE_ROUTING,
209 net, NULL, skb, dev, NULL,
Patrick McHardy6e23ae22007-11-19 18:53:30 -0800210 ip6_rcv_finish);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211err:
Eric Dumazet1d015502016-04-27 16:44:40 -0700212 __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213drop:
YOSHIFUJI Hideakia11d2062006-11-04 20:11:37 +0900214 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 kfree_skb(skb);
Mark Smith5c91fac2009-07-06 11:26:24 +0000216 return NET_RX_DROP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217}
218
219/*
220 * Deliver the packet to the host
221 */
222
223
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500224static int ip6_input_finish(struct net *net, struct sock *sk, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225{
Alexey Dobriyan41135cc2009-09-14 12:22:28 +0000226 const struct inet6_protocol *ipprot;
David S. Millerf9242b62012-06-19 18:56:21 -0700227 struct inet6_dev *idev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 unsigned int nhoff;
Eric Dumazeta50feda2012-05-18 18:57:34 +0000229 int nexthdr;
230 bool raw;
Tom Herbert1da44f92016-05-18 09:06:12 -0700231 bool have_final = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 /*
234 * Parse extension headers
235 */
236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 rcu_read_lock();
David S. Miller1b0ccfe2015-06-10 15:29:31 -0700238resubmit:
Eric Dumazetadf30902009-06-02 05:19:30 +0000239 idev = ip6_dst_idev(skb_dst(skb));
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -0700240 if (!pskb_pull(skb, skb_transport_offset(skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 goto discard;
Patrick McHardy951dbc82006-01-06 23:02:34 -0800242 nhoff = IP6CB(skb)->nhoff;
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -0700243 nexthdr = skb_network_header(skb)[nhoff];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Tom Herbert4c642422016-05-18 09:06:11 -0700245resubmit_final:
Pavel Emelyanov69d6da02007-11-19 22:35:57 -0800246 raw = raw6_local_deliver(skb, nexthdr);
Ian Morrise5d08d72014-11-23 21:28:43 +0000247 ipprot = rcu_dereference(inet6_protos[nexthdr]);
Ian Morris53b24b82015-03-29 14:00:05 +0100248 if (ipprot) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 int ret;
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +0900250
Tom Herbert1da44f92016-05-18 09:06:12 -0700251 if (have_final) {
252 if (!(ipprot->flags & INET6_PROTO_FINAL)) {
253 /* Once we've seen a final protocol don't
254 * allow encapsulation on any non-final
255 * ones. This allows foo in UDP encapsulation
256 * to work.
257 */
258 goto discard;
259 }
260 } else if (ipprot->flags & INET6_PROTO_FINAL) {
Eric Dumazetb71d1d42011-04-22 04:53:02 +0000261 const struct ipv6hdr *hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
Tom Herbert1da44f92016-05-18 09:06:12 -0700263 /* Only do this once for first final protocol */
264 have_final = true;
265
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800266 /* Free reference early: we don't need it any more,
267 and it may hold ip_conntrack module loaded
268 indefinitely. */
269 nf_reset(skb);
270
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -0700271 skb_postpull_rcsum(skb, skb_network_header(skb),
Arnaldo Carvalho de Melocfe1fc72007-03-16 17:26:39 -0300272 skb_network_header_len(skb));
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -0700273 hdr = ipv6_hdr(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 if (ipv6_addr_is_multicast(&hdr->daddr) &&
275 !ipv6_chk_mcast_addr(skb->dev, &hdr->daddr,
276 &hdr->saddr) &&
YOSHIFUJI Hideaki / 吉藤英明daad1512013-01-13 05:02:18 +0000277 !ipv6_is_mld(skb, nexthdr, skb_network_header_len(skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 goto discard;
279 }
280 if (!(ipprot->flags & INET6_PROTO_NOPOLICY) &&
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +0900281 !xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 goto discard;
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +0900283
Herbert Xue5bbef22007-10-15 12:50:28 -0700284 ret = ipprot->handler(skb);
Tom Herbert4c642422016-05-18 09:06:11 -0700285 if (ret > 0) {
286 if (ipprot->flags & INET6_PROTO_FINAL) {
287 /* Not an extension header, most likely UDP
288 * encapsulation. Use return value as nexthdr
289 * protocol not nhoff (which presumably is
290 * not set by handler).
291 */
292 nexthdr = ret;
293 goto resubmit_final;
294 } else {
295 goto resubmit;
296 }
297 } else if (ret == 0) {
Eric Dumazet1d015502016-04-27 16:44:40 -0700298 __IP6_INC_STATS(net, idev, IPSTATS_MIB_INDELIVERS);
Tom Herbert4c642422016-05-18 09:06:11 -0700299 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 } else {
Pavel Emelyanov69d6da02007-11-19 22:35:57 -0800301 if (!raw) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 if (xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) {
Eric Dumazet1d015502016-04-27 16:44:40 -0700303 __IP6_INC_STATS(net, idev,
304 IPSTATS_MIB_INUNKNOWNPROTOS);
Patrick McHardyfad87ac2005-08-16 21:03:41 -0700305 icmpv6_send(skb, ICMPV6_PARAMPROB,
Alexey Dobriyan3ffe5332010-02-18 08:25:24 +0000306 ICMPV6_UNK_NEXTHDR, nhoff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 }
Neil Hormand8c6f4b2013-03-01 07:44:08 +0000308 kfree_skb(skb);
309 } else {
Eric Dumazet1d015502016-04-27 16:44:40 -0700310 __IP6_INC_STATS(net, idev, IPSTATS_MIB_INDELIVERS);
Neil Hormand8c6f4b2013-03-01 07:44:08 +0000311 consume_skb(skb);
312 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 }
314 rcu_read_unlock();
315 return 0;
316
317discard:
Eric Dumazet1d015502016-04-27 16:44:40 -0700318 __IP6_INC_STATS(net, idev, IPSTATS_MIB_INDISCARDS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 rcu_read_unlock();
320 kfree_skb(skb);
321 return 0;
322}
323
324
325int ip6_input(struct sk_buff *skb)
326{
Eric W. Biederman29a26a52015-09-15 20:04:16 -0500327 return NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_IN,
328 dev_net(skb->dev), NULL, skb, skb->dev, NULL,
Patrick McHardy6e23ae22007-11-19 18:53:30 -0800329 ip6_input_finish);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330}
David Ahernb4869aa2016-06-06 20:50:40 -0700331EXPORT_SYMBOL_GPL(ip6_input);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
333int ip6_mc_input(struct sk_buff *skb)
334{
Eric Dumazetb71d1d42011-04-22 04:53:02 +0000335 const struct ipv6hdr *hdr;
Eric Dumazeta50feda2012-05-18 18:57:34 +0000336 bool deliver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
Eric Dumazetc2005eb2016-04-27 16:44:41 -0700338 __IP6_UPD_PO_STATS(dev_net(skb_dst(skb)->dev),
Eric Dumazetadf30902009-06-02 05:19:30 +0000339 ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_INMCAST,
Neil Hormanedf391f2009-04-27 02:45:02 -0700340 skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -0700342 hdr = ipv6_hdr(skb);
YOSHIFUJI Hideaki4c7966b2008-03-31 19:30:45 -0700343 deliver = ipv6_chk_mcast_addr(skb->dev, &hdr->daddr, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
YOSHIFUJI Hideaki7bc570c2008-04-03 09:22:53 +0900345#ifdef CONFIG_IPV6_MROUTE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 /*
YOSHIFUJI Hideaki7bc570c2008-04-03 09:22:53 +0900347 * IPv6 multicast router mode is now supported ;)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 */
YOSHIFUJI Hideaki53b79972008-07-19 22:35:03 -0700349 if (dev_net(skb->dev)->ipv6.devconf_all->mc_forwarding &&
Hannes Frederic Sowaddf64352013-03-08 02:07:23 +0000350 !(ipv6_addr_type(&hdr->daddr) &
351 (IPV6_ADDR_LOOPBACK|IPV6_ADDR_LINKLOCAL)) &&
YOSHIFUJI Hideaki7bc570c2008-04-03 09:22:53 +0900352 likely(!(IP6CB(skb)->flags & IP6SKB_FORWARDED))) {
353 /*
354 * Okay, we try to forward - split and duplicate
355 * packets.
356 */
357 struct sk_buff *skb2;
358 struct inet6_skb_parm *opt = IP6CB(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
YOSHIFUJI Hideaki7bc570c2008-04-03 09:22:53 +0900360 /* Check for MLD */
YOSHIFUJI Hideaki / 吉藤英明dd3332b2013-01-13 05:02:45 +0000361 if (unlikely(opt->flags & IP6SKB_ROUTERALERT)) {
YOSHIFUJI Hideaki7bc570c2008-04-03 09:22:53 +0900362 /* Check if this is a mld message */
YOSHIFUJI Hideaki7bc570c2008-04-03 09:22:53 +0900363 u8 nexthdr = hdr->nexthdr;
Jesse Gross75f28112011-11-30 17:05:51 -0800364 __be16 frag_off;
YOSHIFUJI Hideaki7bc570c2008-04-03 09:22:53 +0900365 int offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
YOSHIFUJI Hideaki7bc570c2008-04-03 09:22:53 +0900367 /* Check if the value of Router Alert
368 * is for MLD (0x0000).
369 */
YOSHIFUJI Hideaki / 吉藤英明dd3332b2013-01-13 05:02:45 +0000370 if (opt->ra == htons(IPV6_OPT_ROUTERALERT_MLD)) {
Eric Dumazeta50feda2012-05-18 18:57:34 +0000371 deliver = false;
YOSHIFUJI Hideakiaba60962008-04-10 15:41:26 +0900372
YOSHIFUJI Hideaki7bc570c2008-04-03 09:22:53 +0900373 if (!ipv6_ext_hdr(nexthdr)) {
374 /* BUG */
YOSHIFUJI Hideakiaba60962008-04-10 15:41:26 +0900375 goto out;
YOSHIFUJI Hideaki7bc570c2008-04-03 09:22:53 +0900376 }
377 offset = ipv6_skip_exthdr(skb, sizeof(*hdr),
Jesse Gross75f28112011-11-30 17:05:51 -0800378 &nexthdr, &frag_off);
YOSHIFUJI Hideaki7bc570c2008-04-03 09:22:53 +0900379 if (offset < 0)
YOSHIFUJI Hideakiaba60962008-04-10 15:41:26 +0900380 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Angga4c938d22015-07-03 14:40:52 +1200382 if (ipv6_is_mld(skb, nexthdr, offset))
383 deliver = true;
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +0900384
Angga4c938d22015-07-03 14:40:52 +1200385 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 }
YOSHIFUJI Hideaki7bc570c2008-04-03 09:22:53 +0900387 /* unknown RA - process it normally */
388 }
389
390 if (deliver)
391 skb2 = skb_clone(skb, GFP_ATOMIC);
392 else {
393 skb2 = skb;
394 skb = NULL;
395 }
396
397 if (skb2) {
YOSHIFUJI Hideaki7bc570c2008-04-03 09:22:53 +0900398 ip6_mr_input(skb2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 }
400 }
YOSHIFUJI Hideaki7bc570c2008-04-03 09:22:53 +0900401out:
YOSHIFUJI Hideakiaba60962008-04-10 15:41:26 +0900402#endif
403 if (likely(deliver))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 ip6_input(skb);
YOSHIFUJI Hideakiaba60962008-04-10 15:41:26 +0900405 else {
406 /* discard */
407 kfree_skb(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
410 return 0;
411}