icmp.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Internet Control Message Protocol (ICMPv6)
  4. * Linux INET6 implementation
  5. *
  6. * Authors:
  7. * Pedro Roque <roque@di.fc.ul.pt>
  8. *
  9. * Based on net/ipv4/icmp.c
  10. *
  11. * RFC 1885
  12. */
  13. /*
  14. * Changes:
  15. *
  16. * Andi Kleen : exception handling
  17. * Andi Kleen add rate limits. never reply to a icmp.
  18. * add more length checks and other fixes.
  19. * yoshfuji : ensure to sent parameter problem for
  20. * fragments.
  21. * YOSHIFUJI Hideaki @USAGI: added sysctl for icmp rate limit.
  22. * Randy Dunlap and
  23. * YOSHIFUJI Hideaki @USAGI: Per-interface statistics support
  24. * Kazunori MIYAZAWA @USAGI: change output process to use ip6_append_data
  25. */
  26. #define pr_fmt(fmt) "IPv6: " fmt
  27. #include <linux/module.h>
  28. #include <linux/errno.h>
  29. #include <linux/types.h>
  30. #include <linux/socket.h>
  31. #include <linux/in.h>
  32. #include <linux/kernel.h>
  33. #include <linux/sockios.h>
  34. #include <linux/net.h>
  35. #include <linux/skbuff.h>
  36. #include <linux/init.h>
  37. #include <linux/netfilter.h>
  38. #include <linux/slab.h>
  39. #ifdef CONFIG_SYSCTL
  40. #include <linux/sysctl.h>
  41. #endif
  42. #include <linux/inet.h>
  43. #include <linux/netdevice.h>
  44. #include <linux/icmpv6.h>
  45. #include <net/ip.h>
  46. #include <net/sock.h>
  47. #include <net/ipv6.h>
  48. #include <net/ip6_checksum.h>
  49. #include <net/ping.h>
  50. #include <net/protocol.h>
  51. #include <net/raw.h>
  52. #include <net/rawv6.h>
  53. #include <net/seg6.h>
  54. #include <net/transp_v6.h>
  55. #include <net/ip6_route.h>
  56. #include <net/addrconf.h>
  57. #include <net/icmp.h>
  58. #include <net/xfrm.h>
  59. #include <net/inet_common.h>
  60. #include <net/dsfield.h>
  61. #include <net/l3mdev.h>
  62. #include <linux/uaccess.h>
  63. static DEFINE_PER_CPU(struct sock *, ipv6_icmp_sk);
  64. static int icmpv6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
  65. u8 type, u8 code, int offset, __be32 info)
  66. {
  67. /* icmpv6_notify checks 8 bytes can be pulled, icmp6hdr is 8 bytes */
  68. struct icmp6hdr *icmp6 = (struct icmp6hdr *) (skb->data + offset);
  69. struct net *net = dev_net_rcu(skb->dev);
  70. if (type == ICMPV6_PKT_TOOBIG)
  71. ip6_update_pmtu(skb, net, info, skb->dev->ifindex, 0, sock_net_uid(net, NULL));
  72. else if (type == NDISC_REDIRECT)
  73. ip6_redirect(skb, net, skb->dev->ifindex, 0,
  74. sock_net_uid(net, NULL));
  75. if (!(type & ICMPV6_INFOMSG_MASK))
  76. if (icmp6->icmp6_type == ICMPV6_ECHO_REQUEST)
  77. ping_err(skb, offset, ntohl(info));
  78. return 0;
  79. }
  80. static int icmpv6_rcv(struct sk_buff *skb);
  81. static const struct inet6_protocol icmpv6_protocol = {
  82. .handler = icmpv6_rcv,
  83. .err_handler = icmpv6_err,
  84. .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
  85. };
  86. /* Called with BH disabled */
  87. static struct sock *icmpv6_xmit_lock(struct net *net)
  88. {
  89. struct sock *sk;
  90. sk = this_cpu_read(ipv6_icmp_sk);
  91. if (unlikely(!spin_trylock(&sk->sk_lock.slock))) {
  92. /* This can happen if the output path (f.e. SIT or
  93. * ip6ip6 tunnel) signals dst_link_failure() for an
  94. * outgoing ICMP6 packet.
  95. */
  96. return NULL;
  97. }
  98. sock_net_set(sk, net);
  99. return sk;
  100. }
  101. static void icmpv6_xmit_unlock(struct sock *sk)
  102. {
  103. sock_net_set(sk, &init_net);
  104. spin_unlock(&sk->sk_lock.slock);
  105. }
  106. /*
  107. * Figure out, may we reply to this packet with icmp error.
  108. *
  109. * We do not reply, if:
  110. * - it was icmp error message.
  111. * - it is truncated, so that it is known, that protocol is ICMPV6
  112. * (i.e. in the middle of some exthdr)
  113. *
  114. * --ANK (980726)
  115. */
  116. static bool is_ineligible(const struct sk_buff *skb)
  117. {
  118. int ptr = (u8 *)(ipv6_hdr(skb) + 1) - skb->data;
  119. int len = skb->len - ptr;
  120. __u8 nexthdr = ipv6_hdr(skb)->nexthdr;
  121. __be16 frag_off;
  122. if (len < 0)
  123. return true;
  124. ptr = ipv6_skip_exthdr(skb, ptr, &nexthdr, &frag_off);
  125. if (ptr < 0)
  126. return false;
  127. if (nexthdr == IPPROTO_ICMPV6) {
  128. u8 _type, *tp;
  129. tp = skb_header_pointer(skb,
  130. ptr+offsetof(struct icmp6hdr, icmp6_type),
  131. sizeof(_type), &_type);
  132. /* Based on RFC 8200, Section 4.5 Fragment Header, return
  133. * false if this is a fragment packet with no icmp header info.
  134. */
  135. if (!tp && frag_off != 0)
  136. return false;
  137. else if (!tp || !(*tp & ICMPV6_INFOMSG_MASK))
  138. return true;
  139. }
  140. return false;
  141. }
  142. static bool icmpv6_mask_allow(struct net *net, int type)
  143. {
  144. if (type > ICMPV6_MSG_MAX)
  145. return true;
  146. /* Limit if icmp type is set in ratemask. */
  147. if (!test_bit(type, net->ipv6.sysctl.icmpv6_ratemask))
  148. return true;
  149. return false;
  150. }
  151. static bool icmpv6_global_allow(struct net *net, int type,
  152. bool *apply_ratelimit)
  153. {
  154. if (icmpv6_mask_allow(net, type))
  155. return true;
  156. if (icmp_global_allow(net)) {
  157. *apply_ratelimit = true;
  158. return true;
  159. }
  160. __ICMP_INC_STATS(net, ICMP_MIB_RATELIMITGLOBAL);
  161. return false;
  162. }
  163. /*
  164. * Check the ICMP output rate limit
  165. */
  166. static bool icmpv6_xrlim_allow(struct sock *sk, u8 type,
  167. struct flowi6 *fl6, bool apply_ratelimit)
  168. {
  169. struct net *net = sock_net(sk);
  170. struct dst_entry *dst;
  171. bool res = false;
  172. if (!apply_ratelimit)
  173. return true;
  174. /*
  175. * Look up the output route.
  176. * XXX: perhaps the expire for routing entries cloned by
  177. * this lookup should be more aggressive (not longer than timeout).
  178. */
  179. dst = ip6_route_output(net, sk, fl6);
  180. if (dst->error) {
  181. IP6_INC_STATS(net, ip6_dst_idev(dst),
  182. IPSTATS_MIB_OUTNOROUTES);
  183. } else if (dst->dev && (dst->dev->flags&IFF_LOOPBACK)) {
  184. res = true;
  185. } else {
  186. struct rt6_info *rt = dst_rt6_info(dst);
  187. int tmo = net->ipv6.sysctl.icmpv6_time;
  188. struct inet_peer *peer;
  189. /* Give more bandwidth to wider prefixes. */
  190. if (rt->rt6i_dst.plen < 128)
  191. tmo >>= ((128 - rt->rt6i_dst.plen)>>5);
  192. rcu_read_lock();
  193. peer = inet_getpeer_v6(net->ipv6.peers, &fl6->daddr);
  194. res = inet_peer_xrlim_allow(peer, tmo);
  195. rcu_read_unlock();
  196. }
  197. if (!res)
  198. __ICMP6_INC_STATS(net, ip6_dst_idev(dst),
  199. ICMP6_MIB_RATELIMITHOST);
  200. else
  201. icmp_global_consume(net);
  202. dst_release(dst);
  203. return res;
  204. }
  205. static bool icmpv6_rt_has_prefsrc(struct sock *sk, u8 type,
  206. struct flowi6 *fl6)
  207. {
  208. struct net *net = sock_net(sk);
  209. struct dst_entry *dst;
  210. bool res = false;
  211. dst = ip6_route_output(net, sk, fl6);
  212. if (!dst->error) {
  213. struct rt6_info *rt = dst_rt6_info(dst);
  214. struct in6_addr prefsrc;
  215. rt6_get_prefsrc(rt, &prefsrc);
  216. res = !ipv6_addr_any(&prefsrc);
  217. }
  218. dst_release(dst);
  219. return res;
  220. }
  221. /*
  222. * an inline helper for the "simple" if statement below
  223. * checks if parameter problem report is caused by an
  224. * unrecognized IPv6 option that has the Option Type
  225. * highest-order two bits set to 10
  226. */
  227. static bool opt_unrec(struct sk_buff *skb, __u32 offset)
  228. {
  229. u8 _optval, *op;
  230. offset += skb_network_offset(skb);
  231. op = skb_header_pointer(skb, offset, sizeof(_optval), &_optval);
  232. if (!op)
  233. return true;
  234. return (*op & 0xC0) == 0x80;
  235. }
  236. void icmpv6_push_pending_frames(struct sock *sk, struct flowi6 *fl6,
  237. struct icmp6hdr *thdr, int len)
  238. {
  239. struct sk_buff *skb;
  240. struct icmp6hdr *icmp6h;
  241. skb = skb_peek(&sk->sk_write_queue);
  242. if (!skb)
  243. return;
  244. icmp6h = icmp6_hdr(skb);
  245. memcpy(icmp6h, thdr, sizeof(struct icmp6hdr));
  246. icmp6h->icmp6_cksum = 0;
  247. if (skb_queue_len(&sk->sk_write_queue) == 1) {
  248. skb->csum = csum_partial(icmp6h,
  249. sizeof(struct icmp6hdr), skb->csum);
  250. icmp6h->icmp6_cksum = csum_ipv6_magic(&fl6->saddr,
  251. &fl6->daddr,
  252. len, fl6->flowi6_proto,
  253. skb->csum);
  254. } else {
  255. __wsum tmp_csum = 0;
  256. skb_queue_walk(&sk->sk_write_queue, skb) {
  257. tmp_csum = csum_add(tmp_csum, skb->csum);
  258. }
  259. tmp_csum = csum_partial(icmp6h,
  260. sizeof(struct icmp6hdr), tmp_csum);
  261. icmp6h->icmp6_cksum = csum_ipv6_magic(&fl6->saddr,
  262. &fl6->daddr,
  263. len, fl6->flowi6_proto,
  264. tmp_csum);
  265. }
  266. ip6_push_pending_frames(sk);
  267. }
  268. struct icmpv6_msg {
  269. struct sk_buff *skb;
  270. int offset;
  271. uint8_t type;
  272. };
  273. static int icmpv6_getfrag(void *from, char *to, int offset, int len, int odd, struct sk_buff *skb)
  274. {
  275. struct icmpv6_msg *msg = (struct icmpv6_msg *) from;
  276. struct sk_buff *org_skb = msg->skb;
  277. __wsum csum;
  278. csum = skb_copy_and_csum_bits(org_skb, msg->offset + offset,
  279. to, len);
  280. skb->csum = csum_block_add(skb->csum, csum, odd);
  281. if (!(msg->type & ICMPV6_INFOMSG_MASK))
  282. nf_ct_attach(skb, org_skb);
  283. return 0;
  284. }
  285. #if IS_ENABLED(CONFIG_IPV6_MIP6)
  286. static void mip6_addr_swap(struct sk_buff *skb, const struct inet6_skb_parm *opt)
  287. {
  288. struct ipv6hdr *iph = ipv6_hdr(skb);
  289. struct ipv6_destopt_hao *hao;
  290. int off;
  291. if (opt->dsthao) {
  292. off = ipv6_find_tlv(skb, opt->dsthao, IPV6_TLV_HAO);
  293. if (likely(off >= 0)) {
  294. hao = (struct ipv6_destopt_hao *)
  295. (skb_network_header(skb) + off);
  296. swap(iph->saddr, hao->addr);
  297. }
  298. }
  299. }
  300. #else
  301. static inline void mip6_addr_swap(struct sk_buff *skb, const struct inet6_skb_parm *opt) {}
  302. #endif
  303. static struct dst_entry *icmpv6_route_lookup(struct net *net,
  304. struct sk_buff *skb,
  305. struct sock *sk,
  306. struct flowi6 *fl6)
  307. {
  308. struct dst_entry *dst, *dst2;
  309. struct flowi6 fl2;
  310. int err;
  311. err = ip6_dst_lookup(net, sk, &dst, fl6);
  312. if (err)
  313. return ERR_PTR(err);
  314. /*
  315. * We won't send icmp if the destination is known
  316. * anycast unless we need to treat anycast as unicast.
  317. */
  318. if (!READ_ONCE(net->ipv6.sysctl.icmpv6_error_anycast_as_unicast) &&
  319. ipv6_anycast_destination(dst, &fl6->daddr)) {
  320. net_dbg_ratelimited("icmp6_send: acast source\n");
  321. dst_release(dst);
  322. return ERR_PTR(-EINVAL);
  323. }
  324. /* No need to clone since we're just using its address. */
  325. dst2 = dst;
  326. dst = xfrm_lookup(net, dst, flowi6_to_flowi(fl6), sk, 0);
  327. if (!IS_ERR(dst)) {
  328. if (dst != dst2)
  329. return dst;
  330. } else {
  331. if (PTR_ERR(dst) == -EPERM)
  332. dst = NULL;
  333. else
  334. return dst;
  335. }
  336. err = xfrm_decode_session_reverse(net, skb, flowi6_to_flowi(&fl2), AF_INET6);
  337. if (err)
  338. goto relookup_failed;
  339. err = ip6_dst_lookup(net, sk, &dst2, &fl2);
  340. if (err)
  341. goto relookup_failed;
  342. dst2 = xfrm_lookup(net, dst2, flowi6_to_flowi(&fl2), sk, XFRM_LOOKUP_ICMP);
  343. if (!IS_ERR(dst2)) {
  344. dst_release(dst);
  345. dst = dst2;
  346. } else {
  347. err = PTR_ERR(dst2);
  348. if (err == -EPERM) {
  349. dst_release(dst);
  350. return dst2;
  351. } else
  352. goto relookup_failed;
  353. }
  354. relookup_failed:
  355. if (dst)
  356. return dst;
  357. return ERR_PTR(err);
  358. }
  359. static struct net_device *icmp6_dev(const struct sk_buff *skb)
  360. {
  361. struct net_device *dev = skb->dev;
  362. /* for local traffic to local address, skb dev is the loopback
  363. * device. Check if there is a dst attached to the skb and if so
  364. * get the real device index. Same is needed for replies to a link
  365. * local address on a device enslaved to an L3 master device
  366. */
  367. if (unlikely(dev->ifindex == LOOPBACK_IFINDEX || netif_is_l3_master(skb->dev))) {
  368. const struct rt6_info *rt6 = skb_rt6_info(skb);
  369. /* The destination could be an external IP in Ext Hdr (SRv6, RPL, etc.),
  370. * and ip6_null_entry could be set to skb if no route is found.
  371. */
  372. if (rt6 && rt6->rt6i_idev)
  373. dev = rt6->rt6i_idev->dev;
  374. }
  375. return dev;
  376. }
  377. static int icmp6_iif(const struct sk_buff *skb)
  378. {
  379. return icmp6_dev(skb)->ifindex;
  380. }
  381. /*
  382. * Send an ICMP message in response to a packet in error
  383. */
  384. void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
  385. const struct in6_addr *force_saddr,
  386. const struct inet6_skb_parm *parm)
  387. {
  388. struct inet6_dev *idev = NULL;
  389. struct ipv6hdr *hdr = ipv6_hdr(skb);
  390. struct sock *sk;
  391. struct net *net;
  392. struct ipv6_pinfo *np;
  393. const struct in6_addr *saddr = NULL;
  394. bool apply_ratelimit = false;
  395. struct dst_entry *dst;
  396. struct icmp6hdr tmp_hdr;
  397. struct flowi6 fl6;
  398. struct icmpv6_msg msg;
  399. struct ipcm6_cookie ipc6;
  400. int iif = 0;
  401. int addr_type = 0;
  402. int len;
  403. u32 mark;
  404. if ((u8 *)hdr < skb->head ||
  405. (skb_network_header(skb) + sizeof(*hdr)) > skb_tail_pointer(skb))
  406. return;
  407. if (!skb->dev)
  408. return;
  409. rcu_read_lock();
  410. net = dev_net_rcu(skb->dev);
  411. mark = IP6_REPLY_MARK(net, skb->mark);
  412. /*
  413. * Make sure we respect the rules
  414. * i.e. RFC 1885 2.4(e)
  415. * Rule (e.1) is enforced by not using icmp6_send
  416. * in any code that processes icmp errors.
  417. */
  418. addr_type = ipv6_addr_type(&hdr->daddr);
  419. if (ipv6_chk_addr(net, &hdr->daddr, skb->dev, 0) ||
  420. ipv6_chk_acast_addr_src(net, skb->dev, &hdr->daddr))
  421. saddr = &hdr->daddr;
  422. /*
  423. * Dest addr check
  424. */
  425. if (addr_type & IPV6_ADDR_MULTICAST || skb->pkt_type != PACKET_HOST) {
  426. if (type != ICMPV6_PKT_TOOBIG &&
  427. !(type == ICMPV6_PARAMPROB &&
  428. code == ICMPV6_UNK_OPTION &&
  429. (opt_unrec(skb, info))))
  430. goto out;
  431. saddr = NULL;
  432. }
  433. addr_type = ipv6_addr_type(&hdr->saddr);
  434. /*
  435. * Source addr check
  436. */
  437. if (__ipv6_addr_needs_scope_id(addr_type)) {
  438. iif = icmp6_iif(skb);
  439. } else {
  440. /*
  441. * The source device is used for looking up which routing table
  442. * to use for sending an ICMP error.
  443. */
  444. iif = l3mdev_master_ifindex(skb->dev);
  445. }
  446. /*
  447. * Must not send error if the source does not uniquely
  448. * identify a single node (RFC2463 Section 2.4).
  449. * We check unspecified / multicast addresses here,
  450. * and anycast addresses will be checked later.
  451. */
  452. if ((addr_type == IPV6_ADDR_ANY) || (addr_type & IPV6_ADDR_MULTICAST)) {
  453. net_dbg_ratelimited("icmp6_send: addr_any/mcast source [%pI6c > %pI6c]\n",
  454. &hdr->saddr, &hdr->daddr);
  455. goto out;
  456. }
  457. /*
  458. * Never answer to a ICMP packet.
  459. */
  460. if (is_ineligible(skb)) {
  461. net_dbg_ratelimited("icmp6_send: no reply to icmp error [%pI6c > %pI6c]\n",
  462. &hdr->saddr, &hdr->daddr);
  463. goto out;
  464. }
  465. /* Needed by both icmpv6_global_allow and icmpv6_xmit_lock */
  466. local_bh_disable();
  467. /* Check global sysctl_icmp_msgs_per_sec ratelimit */
  468. if (!(skb->dev->flags & IFF_LOOPBACK) &&
  469. !icmpv6_global_allow(net, type, &apply_ratelimit))
  470. goto out_bh_enable;
  471. mip6_addr_swap(skb, parm);
  472. sk = icmpv6_xmit_lock(net);
  473. if (!sk)
  474. goto out_bh_enable;
  475. memset(&fl6, 0, sizeof(fl6));
  476. fl6.flowi6_proto = IPPROTO_ICMPV6;
  477. fl6.daddr = hdr->saddr;
  478. if (force_saddr)
  479. saddr = force_saddr;
  480. if (saddr) {
  481. fl6.saddr = *saddr;
  482. } else if (!icmpv6_rt_has_prefsrc(sk, type, &fl6)) {
  483. /* select a more meaningful saddr from input if */
  484. struct net_device *in_netdev;
  485. in_netdev = dev_get_by_index(net, parm->iif);
  486. if (in_netdev) {
  487. ipv6_dev_get_saddr(net, in_netdev, &fl6.daddr,
  488. inet6_sk(sk)->srcprefs,
  489. &fl6.saddr);
  490. dev_put(in_netdev);
  491. }
  492. }
  493. fl6.flowi6_mark = mark;
  494. fl6.flowi6_oif = iif;
  495. fl6.fl6_icmp_type = type;
  496. fl6.fl6_icmp_code = code;
  497. fl6.flowi6_uid = sock_net_uid(net, NULL);
  498. fl6.mp_hash = rt6_multipath_hash(net, &fl6, skb, NULL);
  499. security_skb_classify_flow(skb, flowi6_to_flowi_common(&fl6));
  500. np = inet6_sk(sk);
  501. if (!icmpv6_xrlim_allow(sk, type, &fl6, apply_ratelimit))
  502. goto out_unlock;
  503. tmp_hdr.icmp6_type = type;
  504. tmp_hdr.icmp6_code = code;
  505. tmp_hdr.icmp6_cksum = 0;
  506. tmp_hdr.icmp6_pointer = htonl(info);
  507. if (!fl6.flowi6_oif && ipv6_addr_is_multicast(&fl6.daddr))
  508. fl6.flowi6_oif = READ_ONCE(np->mcast_oif);
  509. else if (!fl6.flowi6_oif)
  510. fl6.flowi6_oif = READ_ONCE(np->ucast_oif);
  511. ipcm6_init_sk(&ipc6, sk);
  512. ipc6.sockc.mark = mark;
  513. fl6.flowlabel = ip6_make_flowinfo(ipc6.tclass, fl6.flowlabel);
  514. dst = icmpv6_route_lookup(net, skb, sk, &fl6);
  515. if (IS_ERR(dst))
  516. goto out_unlock;
  517. ipc6.hlimit = ip6_sk_dst_hoplimit(np, &fl6, dst);
  518. msg.skb = skb;
  519. msg.offset = skb_network_offset(skb);
  520. msg.type = type;
  521. len = skb->len - msg.offset;
  522. len = min_t(unsigned int, len, IPV6_MIN_MTU - sizeof(struct ipv6hdr) - sizeof(struct icmp6hdr));
  523. if (len < 0) {
  524. net_dbg_ratelimited("icmp: len problem [%pI6c > %pI6c]\n",
  525. &hdr->saddr, &hdr->daddr);
  526. goto out_dst_release;
  527. }
  528. idev = __in6_dev_get(skb->dev);
  529. if (ip6_append_data(sk, icmpv6_getfrag, &msg,
  530. len + sizeof(struct icmp6hdr),
  531. sizeof(struct icmp6hdr),
  532. &ipc6, &fl6, dst_rt6_info(dst),
  533. MSG_DONTWAIT)) {
  534. ICMP6_INC_STATS(net, idev, ICMP6_MIB_OUTERRORS);
  535. ip6_flush_pending_frames(sk);
  536. } else {
  537. icmpv6_push_pending_frames(sk, &fl6, &tmp_hdr,
  538. len + sizeof(struct icmp6hdr));
  539. }
  540. out_dst_release:
  541. dst_release(dst);
  542. out_unlock:
  543. icmpv6_xmit_unlock(sk);
  544. out_bh_enable:
  545. local_bh_enable();
  546. out:
  547. rcu_read_unlock();
  548. }
  549. EXPORT_SYMBOL(icmp6_send);
  550. /* Slightly more convenient version of icmp6_send with drop reasons.
  551. */
  552. void icmpv6_param_prob_reason(struct sk_buff *skb, u8 code, int pos,
  553. enum skb_drop_reason reason)
  554. {
  555. icmp6_send(skb, ICMPV6_PARAMPROB, code, pos, NULL, IP6CB(skb));
  556. kfree_skb_reason(skb, reason);
  557. }
  558. /* Generate icmpv6 with type/code ICMPV6_DEST_UNREACH/ICMPV6_ADDR_UNREACH
  559. * if sufficient data bytes are available
  560. * @nhs is the size of the tunnel header(s) :
  561. * Either an IPv4 header for SIT encap
  562. * an IPv4 header + GRE header for GRE encap
  563. */
  564. int ip6_err_gen_icmpv6_unreach(struct sk_buff *skb, int nhs, int type,
  565. unsigned int data_len)
  566. {
  567. struct in6_addr temp_saddr;
  568. struct rt6_info *rt;
  569. struct sk_buff *skb2;
  570. u32 info = 0;
  571. if (!pskb_may_pull(skb, nhs + sizeof(struct ipv6hdr) + 8))
  572. return 1;
  573. /* RFC 4884 (partial) support for ICMP extensions */
  574. if (data_len < 128 || (data_len & 7) || skb->len < data_len)
  575. data_len = 0;
  576. skb2 = data_len ? skb_copy(skb, GFP_ATOMIC) : skb_clone(skb, GFP_ATOMIC);
  577. if (!skb2)
  578. return 1;
  579. skb_dst_drop(skb2);
  580. skb_pull(skb2, nhs);
  581. skb_reset_network_header(skb2);
  582. rt = rt6_lookup(dev_net_rcu(skb->dev), &ipv6_hdr(skb2)->saddr,
  583. NULL, 0, skb, 0);
  584. if (rt && rt->dst.dev)
  585. skb2->dev = rt->dst.dev;
  586. ipv6_addr_set_v4mapped(ip_hdr(skb)->saddr, &temp_saddr);
  587. if (data_len) {
  588. /* RFC 4884 (partial) support :
  589. * insert 0 padding at the end, before the extensions
  590. */
  591. __skb_push(skb2, nhs);
  592. skb_reset_network_header(skb2);
  593. memmove(skb2->data, skb2->data + nhs, data_len - nhs);
  594. memset(skb2->data + data_len - nhs, 0, nhs);
  595. /* RFC 4884 4.5 : Length is measured in 64-bit words,
  596. * and stored in reserved[0]
  597. */
  598. info = (data_len/8) << 24;
  599. }
  600. if (type == ICMP_TIME_EXCEEDED)
  601. icmp6_send(skb2, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT,
  602. info, &temp_saddr, IP6CB(skb2));
  603. else
  604. icmp6_send(skb2, ICMPV6_DEST_UNREACH, ICMPV6_ADDR_UNREACH,
  605. info, &temp_saddr, IP6CB(skb2));
  606. if (rt)
  607. ip6_rt_put(rt);
  608. kfree_skb(skb2);
  609. return 0;
  610. }
  611. EXPORT_SYMBOL(ip6_err_gen_icmpv6_unreach);
  612. static enum skb_drop_reason icmpv6_echo_reply(struct sk_buff *skb)
  613. {
  614. struct net *net = dev_net_rcu(skb->dev);
  615. struct sock *sk;
  616. struct inet6_dev *idev;
  617. struct ipv6_pinfo *np;
  618. const struct in6_addr *saddr = NULL;
  619. struct icmp6hdr *icmph = icmp6_hdr(skb);
  620. bool apply_ratelimit = false;
  621. struct icmp6hdr tmp_hdr;
  622. struct flowi6 fl6;
  623. struct icmpv6_msg msg;
  624. struct dst_entry *dst;
  625. struct ipcm6_cookie ipc6;
  626. u32 mark = IP6_REPLY_MARK(net, skb->mark);
  627. SKB_DR(reason);
  628. bool acast;
  629. u8 type;
  630. if (ipv6_addr_is_multicast(&ipv6_hdr(skb)->daddr) &&
  631. net->ipv6.sysctl.icmpv6_echo_ignore_multicast)
  632. return reason;
  633. saddr = &ipv6_hdr(skb)->daddr;
  634. acast = ipv6_anycast_destination(skb_dst(skb), saddr);
  635. if (acast && net->ipv6.sysctl.icmpv6_echo_ignore_anycast)
  636. return reason;
  637. if (!ipv6_unicast_destination(skb) &&
  638. !(net->ipv6.sysctl.anycast_src_echo_reply && acast))
  639. saddr = NULL;
  640. if (icmph->icmp6_type == ICMPV6_EXT_ECHO_REQUEST)
  641. type = ICMPV6_EXT_ECHO_REPLY;
  642. else
  643. type = ICMPV6_ECHO_REPLY;
  644. memcpy(&tmp_hdr, icmph, sizeof(tmp_hdr));
  645. tmp_hdr.icmp6_type = type;
  646. memset(&fl6, 0, sizeof(fl6));
  647. if (net->ipv6.sysctl.flowlabel_reflect & FLOWLABEL_REFLECT_ICMPV6_ECHO_REPLIES)
  648. fl6.flowlabel = ip6_flowlabel(ipv6_hdr(skb));
  649. fl6.flowi6_proto = IPPROTO_ICMPV6;
  650. fl6.daddr = ipv6_hdr(skb)->saddr;
  651. if (saddr)
  652. fl6.saddr = *saddr;
  653. fl6.flowi6_oif = icmp6_iif(skb);
  654. fl6.fl6_icmp_type = type;
  655. fl6.flowi6_mark = mark;
  656. fl6.flowi6_uid = sock_net_uid(net, NULL);
  657. security_skb_classify_flow(skb, flowi6_to_flowi_common(&fl6));
  658. local_bh_disable();
  659. sk = icmpv6_xmit_lock(net);
  660. if (!sk)
  661. goto out_bh_enable;
  662. np = inet6_sk(sk);
  663. if (!fl6.flowi6_oif && ipv6_addr_is_multicast(&fl6.daddr))
  664. fl6.flowi6_oif = READ_ONCE(np->mcast_oif);
  665. else if (!fl6.flowi6_oif)
  666. fl6.flowi6_oif = READ_ONCE(np->ucast_oif);
  667. if (ip6_dst_lookup(net, sk, &dst, &fl6))
  668. goto out;
  669. dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), sk, 0);
  670. if (IS_ERR(dst))
  671. goto out;
  672. /* Check the ratelimit */
  673. if ((!(skb->dev->flags & IFF_LOOPBACK) &&
  674. !icmpv6_global_allow(net, ICMPV6_ECHO_REPLY, &apply_ratelimit)) ||
  675. !icmpv6_xrlim_allow(sk, ICMPV6_ECHO_REPLY, &fl6, apply_ratelimit))
  676. goto out_dst_release;
  677. idev = __in6_dev_get(skb->dev);
  678. msg.skb = skb;
  679. msg.offset = 0;
  680. msg.type = type;
  681. ipcm6_init_sk(&ipc6, sk);
  682. ipc6.hlimit = ip6_sk_dst_hoplimit(np, &fl6, dst);
  683. ipc6.tclass = ipv6_get_dsfield(ipv6_hdr(skb));
  684. ipc6.sockc.mark = mark;
  685. if (icmph->icmp6_type == ICMPV6_EXT_ECHO_REQUEST)
  686. if (!icmp_build_probe(skb, (struct icmphdr *)&tmp_hdr))
  687. goto out_dst_release;
  688. if (ip6_append_data(sk, icmpv6_getfrag, &msg,
  689. skb->len + sizeof(struct icmp6hdr),
  690. sizeof(struct icmp6hdr), &ipc6, &fl6,
  691. dst_rt6_info(dst), MSG_DONTWAIT)) {
  692. __ICMP6_INC_STATS(net, idev, ICMP6_MIB_OUTERRORS);
  693. ip6_flush_pending_frames(sk);
  694. } else {
  695. icmpv6_push_pending_frames(sk, &fl6, &tmp_hdr,
  696. skb->len + sizeof(struct icmp6hdr));
  697. reason = SKB_CONSUMED;
  698. }
  699. out_dst_release:
  700. dst_release(dst);
  701. out:
  702. icmpv6_xmit_unlock(sk);
  703. out_bh_enable:
  704. local_bh_enable();
  705. return reason;
  706. }
  707. enum skb_drop_reason icmpv6_notify(struct sk_buff *skb, u8 type,
  708. u8 code, __be32 info)
  709. {
  710. struct inet6_skb_parm *opt = IP6CB(skb);
  711. struct net *net = dev_net_rcu(skb->dev);
  712. const struct inet6_protocol *ipprot;
  713. enum skb_drop_reason reason;
  714. int inner_offset;
  715. __be16 frag_off;
  716. u8 nexthdr;
  717. reason = pskb_may_pull_reason(skb, sizeof(struct ipv6hdr));
  718. if (reason != SKB_NOT_DROPPED_YET)
  719. goto out;
  720. seg6_icmp_srh(skb, opt);
  721. nexthdr = ((struct ipv6hdr *)skb->data)->nexthdr;
  722. if (ipv6_ext_hdr(nexthdr)) {
  723. /* now skip over extension headers */
  724. inner_offset = ipv6_skip_exthdr(skb, sizeof(struct ipv6hdr),
  725. &nexthdr, &frag_off);
  726. if (inner_offset < 0) {
  727. SKB_DR_SET(reason, IPV6_BAD_EXTHDR);
  728. goto out;
  729. }
  730. } else {
  731. inner_offset = sizeof(struct ipv6hdr);
  732. }
  733. /* Checkin header including 8 bytes of inner protocol header. */
  734. reason = pskb_may_pull_reason(skb, inner_offset + 8);
  735. if (reason != SKB_NOT_DROPPED_YET)
  736. goto out;
  737. /* BUGGG_FUTURE: we should try to parse exthdrs in this packet.
  738. Without this we will not able f.e. to make source routed
  739. pmtu discovery.
  740. Corresponding argument (opt) to notifiers is already added.
  741. --ANK (980726)
  742. */
  743. ipprot = rcu_dereference(inet6_protos[nexthdr]);
  744. if (ipprot && ipprot->err_handler)
  745. ipprot->err_handler(skb, opt, type, code, inner_offset, info);
  746. raw6_icmp_error(skb, nexthdr, type, code, inner_offset, info);
  747. return SKB_CONSUMED;
  748. out:
  749. __ICMP6_INC_STATS(net, __in6_dev_get(skb->dev), ICMP6_MIB_INERRORS);
  750. return reason;
  751. }
  752. /*
  753. * Handle icmp messages
  754. */
  755. static int icmpv6_rcv(struct sk_buff *skb)
  756. {
  757. enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
  758. struct net *net = dev_net_rcu(skb->dev);
  759. struct net_device *dev = icmp6_dev(skb);
  760. struct inet6_dev *idev = __in6_dev_get(dev);
  761. const struct in6_addr *saddr, *daddr;
  762. struct icmp6hdr *hdr;
  763. u8 type;
  764. if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) {
  765. struct sec_path *sp = skb_sec_path(skb);
  766. int nh;
  767. if (!(sp && sp->xvec[sp->len - 1]->props.flags &
  768. XFRM_STATE_ICMP)) {
  769. reason = SKB_DROP_REASON_XFRM_POLICY;
  770. goto drop_no_count;
  771. }
  772. if (!pskb_may_pull(skb, sizeof(*hdr) + sizeof(struct ipv6hdr)))
  773. goto drop_no_count;
  774. nh = skb_network_offset(skb);
  775. skb_set_network_header(skb, sizeof(*hdr));
  776. if (!xfrm6_policy_check_reverse(NULL, XFRM_POLICY_IN,
  777. skb)) {
  778. reason = SKB_DROP_REASON_XFRM_POLICY;
  779. goto drop_no_count;
  780. }
  781. skb_set_network_header(skb, nh);
  782. }
  783. __ICMP6_INC_STATS(dev_net_rcu(dev), idev, ICMP6_MIB_INMSGS);
  784. saddr = &ipv6_hdr(skb)->saddr;
  785. daddr = &ipv6_hdr(skb)->daddr;
  786. if (skb_checksum_validate(skb, IPPROTO_ICMPV6, ip6_compute_pseudo)) {
  787. net_dbg_ratelimited("ICMPv6 checksum failed [%pI6c > %pI6c]\n",
  788. saddr, daddr);
  789. goto csum_error;
  790. }
  791. if (!pskb_pull(skb, sizeof(*hdr)))
  792. goto discard_it;
  793. hdr = icmp6_hdr(skb);
  794. type = hdr->icmp6_type;
  795. ICMP6MSGIN_INC_STATS(dev_net_rcu(dev), idev, type);
  796. switch (type) {
  797. case ICMPV6_ECHO_REQUEST:
  798. if (!net->ipv6.sysctl.icmpv6_echo_ignore_all)
  799. reason = icmpv6_echo_reply(skb);
  800. break;
  801. case ICMPV6_EXT_ECHO_REQUEST:
  802. if (!net->ipv6.sysctl.icmpv6_echo_ignore_all &&
  803. READ_ONCE(net->ipv4.sysctl_icmp_echo_enable_probe))
  804. reason = icmpv6_echo_reply(skb);
  805. break;
  806. case ICMPV6_ECHO_REPLY:
  807. reason = ping_rcv(skb);
  808. break;
  809. case ICMPV6_EXT_ECHO_REPLY:
  810. reason = ping_rcv(skb);
  811. break;
  812. case ICMPV6_PKT_TOOBIG:
  813. /* BUGGG_FUTURE: if packet contains rthdr, we cannot update
  814. standard destination cache. Seems, only "advanced"
  815. destination cache will allow to solve this problem
  816. --ANK (980726)
  817. */
  818. if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
  819. goto discard_it;
  820. hdr = icmp6_hdr(skb);
  821. /* to notify */
  822. fallthrough;
  823. case ICMPV6_DEST_UNREACH:
  824. case ICMPV6_TIME_EXCEED:
  825. case ICMPV6_PARAMPROB:
  826. reason = icmpv6_notify(skb, type, hdr->icmp6_code,
  827. hdr->icmp6_mtu);
  828. break;
  829. case NDISC_ROUTER_SOLICITATION:
  830. case NDISC_ROUTER_ADVERTISEMENT:
  831. case NDISC_NEIGHBOUR_SOLICITATION:
  832. case NDISC_NEIGHBOUR_ADVERTISEMENT:
  833. case NDISC_REDIRECT:
  834. reason = ndisc_rcv(skb);
  835. break;
  836. case ICMPV6_MGM_QUERY:
  837. igmp6_event_query(skb);
  838. return 0;
  839. case ICMPV6_MGM_REPORT:
  840. igmp6_event_report(skb);
  841. return 0;
  842. case ICMPV6_MGM_REDUCTION:
  843. case ICMPV6_NI_QUERY:
  844. case ICMPV6_NI_REPLY:
  845. case ICMPV6_MLD2_REPORT:
  846. case ICMPV6_DHAAD_REQUEST:
  847. case ICMPV6_DHAAD_REPLY:
  848. case ICMPV6_MOBILE_PREFIX_SOL:
  849. case ICMPV6_MOBILE_PREFIX_ADV:
  850. break;
  851. default:
  852. /* informational */
  853. if (type & ICMPV6_INFOMSG_MASK)
  854. break;
  855. net_dbg_ratelimited("icmpv6: msg of unknown type [%pI6c > %pI6c]\n",
  856. saddr, daddr);
  857. /*
  858. * error of unknown type.
  859. * must pass to upper level
  860. */
  861. reason = icmpv6_notify(skb, type, hdr->icmp6_code,
  862. hdr->icmp6_mtu);
  863. }
  864. /* until the v6 path can be better sorted assume failure and
  865. * preserve the status quo behaviour for the rest of the paths to here
  866. */
  867. if (reason)
  868. kfree_skb_reason(skb, reason);
  869. else
  870. consume_skb(skb);
  871. return 0;
  872. csum_error:
  873. reason = SKB_DROP_REASON_ICMP_CSUM;
  874. __ICMP6_INC_STATS(dev_net_rcu(dev), idev, ICMP6_MIB_CSUMERRORS);
  875. discard_it:
  876. __ICMP6_INC_STATS(dev_net_rcu(dev), idev, ICMP6_MIB_INERRORS);
  877. drop_no_count:
  878. kfree_skb_reason(skb, reason);
  879. return 0;
  880. }
  881. void icmpv6_flow_init(const struct sock *sk, struct flowi6 *fl6, u8 type,
  882. const struct in6_addr *saddr,
  883. const struct in6_addr *daddr, int oif)
  884. {
  885. memset(fl6, 0, sizeof(*fl6));
  886. fl6->saddr = *saddr;
  887. fl6->daddr = *daddr;
  888. fl6->flowi6_proto = IPPROTO_ICMPV6;
  889. fl6->fl6_icmp_type = type;
  890. fl6->fl6_icmp_code = 0;
  891. fl6->flowi6_oif = oif;
  892. security_sk_classify_flow(sk, flowi6_to_flowi_common(fl6));
  893. }
  894. int __init icmpv6_init(void)
  895. {
  896. struct sock *sk;
  897. int err, i;
  898. for_each_possible_cpu(i) {
  899. err = inet_ctl_sock_create(&sk, PF_INET6,
  900. SOCK_RAW, IPPROTO_ICMPV6, &init_net);
  901. if (err < 0) {
  902. pr_err("Failed to initialize the ICMP6 control socket (err %d)\n",
  903. err);
  904. return err;
  905. }
  906. per_cpu(ipv6_icmp_sk, i) = sk;
  907. /* Enough space for 2 64K ICMP packets, including
  908. * sk_buff struct overhead.
  909. */
  910. sk->sk_sndbuf = 2 * SKB_TRUESIZE(64 * 1024);
  911. }
  912. err = -EAGAIN;
  913. if (inet6_add_protocol(&icmpv6_protocol, IPPROTO_ICMPV6) < 0)
  914. goto fail;
  915. err = inet6_register_icmp_sender(icmp6_send);
  916. if (err)
  917. goto sender_reg_err;
  918. return 0;
  919. sender_reg_err:
  920. inet6_del_protocol(&icmpv6_protocol, IPPROTO_ICMPV6);
  921. fail:
  922. pr_err("Failed to register ICMP6 protocol\n");
  923. return err;
  924. }
  925. void icmpv6_cleanup(void)
  926. {
  927. inet6_unregister_icmp_sender(icmp6_send);
  928. inet6_del_protocol(&icmpv6_protocol, IPPROTO_ICMPV6);
  929. }
  930. static const struct icmp6_err {
  931. int err;
  932. int fatal;
  933. } tab_unreach[] = {
  934. { /* NOROUTE */
  935. .err = ENETUNREACH,
  936. .fatal = 0,
  937. },
  938. { /* ADM_PROHIBITED */
  939. .err = EACCES,
  940. .fatal = 1,
  941. },
  942. { /* Was NOT_NEIGHBOUR, now reserved */
  943. .err = EHOSTUNREACH,
  944. .fatal = 0,
  945. },
  946. { /* ADDR_UNREACH */
  947. .err = EHOSTUNREACH,
  948. .fatal = 0,
  949. },
  950. { /* PORT_UNREACH */
  951. .err = ECONNREFUSED,
  952. .fatal = 1,
  953. },
  954. { /* POLICY_FAIL */
  955. .err = EACCES,
  956. .fatal = 1,
  957. },
  958. { /* REJECT_ROUTE */
  959. .err = EACCES,
  960. .fatal = 1,
  961. },
  962. };
  963. int icmpv6_err_convert(u8 type, u8 code, int *err)
  964. {
  965. int fatal = 0;
  966. *err = EPROTO;
  967. switch (type) {
  968. case ICMPV6_DEST_UNREACH:
  969. fatal = 1;
  970. if (code < ARRAY_SIZE(tab_unreach)) {
  971. *err = tab_unreach[code].err;
  972. fatal = tab_unreach[code].fatal;
  973. }
  974. break;
  975. case ICMPV6_PKT_TOOBIG:
  976. *err = EMSGSIZE;
  977. break;
  978. case ICMPV6_PARAMPROB:
  979. *err = EPROTO;
  980. fatal = 1;
  981. break;
  982. case ICMPV6_TIME_EXCEED:
  983. *err = EHOSTUNREACH;
  984. break;
  985. }
  986. return fatal;
  987. }
  988. EXPORT_SYMBOL(icmpv6_err_convert);
  989. #ifdef CONFIG_SYSCTL
  990. static struct ctl_table ipv6_icmp_table_template[] = {
  991. {
  992. .procname = "ratelimit",
  993. .data = &init_net.ipv6.sysctl.icmpv6_time,
  994. .maxlen = sizeof(int),
  995. .mode = 0644,
  996. .proc_handler = proc_dointvec_ms_jiffies,
  997. },
  998. {
  999. .procname = "echo_ignore_all",
  1000. .data = &init_net.ipv6.sysctl.icmpv6_echo_ignore_all,
  1001. .maxlen = sizeof(u8),
  1002. .mode = 0644,
  1003. .proc_handler = proc_dou8vec_minmax,
  1004. },
  1005. {
  1006. .procname = "echo_ignore_multicast",
  1007. .data = &init_net.ipv6.sysctl.icmpv6_echo_ignore_multicast,
  1008. .maxlen = sizeof(u8),
  1009. .mode = 0644,
  1010. .proc_handler = proc_dou8vec_minmax,
  1011. },
  1012. {
  1013. .procname = "echo_ignore_anycast",
  1014. .data = &init_net.ipv6.sysctl.icmpv6_echo_ignore_anycast,
  1015. .maxlen = sizeof(u8),
  1016. .mode = 0644,
  1017. .proc_handler = proc_dou8vec_minmax,
  1018. },
  1019. {
  1020. .procname = "ratemask",
  1021. .data = &init_net.ipv6.sysctl.icmpv6_ratemask_ptr,
  1022. .maxlen = ICMPV6_MSG_MAX + 1,
  1023. .mode = 0644,
  1024. .proc_handler = proc_do_large_bitmap,
  1025. },
  1026. {
  1027. .procname = "error_anycast_as_unicast",
  1028. .data = &init_net.ipv6.sysctl.icmpv6_error_anycast_as_unicast,
  1029. .maxlen = sizeof(u8),
  1030. .mode = 0644,
  1031. .proc_handler = proc_dou8vec_minmax,
  1032. .extra1 = SYSCTL_ZERO,
  1033. .extra2 = SYSCTL_ONE,
  1034. },
  1035. };
  1036. struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
  1037. {
  1038. struct ctl_table *table;
  1039. table = kmemdup(ipv6_icmp_table_template,
  1040. sizeof(ipv6_icmp_table_template),
  1041. GFP_KERNEL);
  1042. if (table) {
  1043. table[0].data = &net->ipv6.sysctl.icmpv6_time;
  1044. table[1].data = &net->ipv6.sysctl.icmpv6_echo_ignore_all;
  1045. table[2].data = &net->ipv6.sysctl.icmpv6_echo_ignore_multicast;
  1046. table[3].data = &net->ipv6.sysctl.icmpv6_echo_ignore_anycast;
  1047. table[4].data = &net->ipv6.sysctl.icmpv6_ratemask_ptr;
  1048. table[5].data = &net->ipv6.sysctl.icmpv6_error_anycast_as_unicast;
  1049. }
  1050. return table;
  1051. }
  1052. size_t ipv6_icmp_sysctl_table_size(void)
  1053. {
  1054. return ARRAY_SIZE(ipv6_icmp_table_template);
  1055. }
  1056. #endif