^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Neighbour Discovery for IPv6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Linux INET6 implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Pedro Roque <roque@di.fc.ul.pt>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Mike Shaver <shaver@ingenia.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Changes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Alexey I. Froloff : RFC6106 (DNSSL) support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * Pierre Ynard : export userland ND options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * through netlink (RDNSS support)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Lars Fenneberg : fixed MTU setting on receipt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * of an RA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * Janos Farkas : kmalloc failure checks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * Alexey Kuznetsov : state machine reworked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * and moved to net/core.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * Pekka Savola : RFC2461 validation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * YOSHIFUJI Hideaki @USAGI : Verify ND options properly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define pr_fmt(fmt) "ICMPv6: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/sockios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/in6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <linux/sysctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <linux/if_addr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <linux/if_ether.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include <linux/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include <linux/icmpv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include <linux/jhash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include <net/snmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #include <net/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #include <net/protocol.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #include <net/ndisc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #include <net/ip6_route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #include <net/addrconf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #include <net/icmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #include <net/netlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #include <net/flow.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #include <net/ip6_checksum.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #include <net/inet_common.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #include <linux/netfilter.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #include <linux/netfilter_ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) static u32 ndisc_hash(const void *pkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) const struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) __u32 *hash_rnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static bool ndisc_key_eq(const struct neighbour *neigh, const void *pkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static bool ndisc_allow_add(const struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct netlink_ext_ack *extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static int ndisc_constructor(struct neighbour *neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static void ndisc_solicit(struct neighbour *neigh, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static void ndisc_error_report(struct neighbour *neigh, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static int pndisc_constructor(struct pneigh_entry *n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static void pndisc_destructor(struct pneigh_entry *n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static void pndisc_redo(struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) static int ndisc_is_multicast(const void *pkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static const struct neigh_ops ndisc_generic_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) .family = AF_INET6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) .solicit = ndisc_solicit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) .error_report = ndisc_error_report,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) .output = neigh_resolve_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) .connected_output = neigh_connected_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) static const struct neigh_ops ndisc_hh_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) .family = AF_INET6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) .solicit = ndisc_solicit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) .error_report = ndisc_error_report,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) .output = neigh_resolve_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) .connected_output = neigh_resolve_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static const struct neigh_ops ndisc_direct_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) .family = AF_INET6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) .output = neigh_direct_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) .connected_output = neigh_direct_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct neigh_table nd_tbl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) .family = AF_INET6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) .key_len = sizeof(struct in6_addr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) .protocol = cpu_to_be16(ETH_P_IPV6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) .hash = ndisc_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) .key_eq = ndisc_key_eq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) .constructor = ndisc_constructor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) .pconstructor = pndisc_constructor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .pdestructor = pndisc_destructor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) .proxy_redo = pndisc_redo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) .is_multicast = ndisc_is_multicast,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) .allow_add = ndisc_allow_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) .id = "ndisc_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) .parms = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) .tbl = &nd_tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) .reachable_time = ND_REACHABLE_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) .data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) [NEIGH_VAR_MCAST_PROBES] = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) [NEIGH_VAR_UCAST_PROBES] = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) [NEIGH_VAR_RETRANS_TIME] = ND_RETRANS_TIMER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) [NEIGH_VAR_BASE_REACHABLE_TIME] = ND_REACHABLE_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) [NEIGH_VAR_DELAY_PROBE_TIME] = 5 * HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) [NEIGH_VAR_GC_STALETIME] = 60 * HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) [NEIGH_VAR_QUEUE_LEN_BYTES] = SK_WMEM_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) [NEIGH_VAR_PROXY_QLEN] = 64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) [NEIGH_VAR_ANYCAST_DELAY] = 1 * HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) [NEIGH_VAR_PROXY_DELAY] = (8 * HZ) / 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .gc_interval = 30 * HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) .gc_thresh1 = 128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) .gc_thresh2 = 512,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .gc_thresh3 = 1024,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) EXPORT_SYMBOL_GPL(nd_tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) void __ndisc_fill_addr_option(struct sk_buff *skb, int type, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) int data_len, int pad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) int space = __ndisc_opt_addr_space(data_len, pad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) u8 *opt = skb_put(skb, space);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) opt[0] = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) opt[1] = space>>3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) memset(opt + 2, 0, pad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) opt += pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) space -= pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) memcpy(opt+2, data, data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) data_len += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) opt += data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) space -= data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (space > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) memset(opt, 0, space);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) EXPORT_SYMBOL_GPL(__ndisc_fill_addr_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static inline void ndisc_fill_addr_option(struct sk_buff *skb, int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) void *data, u8 icmp6_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) __ndisc_fill_addr_option(skb, type, data, skb->dev->addr_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) ndisc_addr_option_pad(skb->dev->type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) ndisc_ops_fill_addr_option(skb->dev, skb, icmp6_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static inline void ndisc_fill_redirect_addr_option(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) void *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) const u8 *ops_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) ndisc_fill_addr_option(skb, ND_OPT_TARGET_LL_ADDR, ha, NDISC_REDIRECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) ndisc_ops_fill_redirect_addr_option(skb->dev, skb, ops_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static struct nd_opt_hdr *ndisc_next_option(struct nd_opt_hdr *cur,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct nd_opt_hdr *end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (!cur || !end || cur >= end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) type = cur->nd_opt_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) cur = ((void *)cur) + (cur->nd_opt_len << 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) } while (cur < end && cur->nd_opt_type != type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return cur <= end && cur->nd_opt_type == type ? cur : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static inline int ndisc_is_useropt(const struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct nd_opt_hdr *opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return opt->nd_opt_type == ND_OPT_RDNSS ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) opt->nd_opt_type == ND_OPT_DNSSL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) opt->nd_opt_type == ND_OPT_CAPTIVE_PORTAL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) opt->nd_opt_type == ND_OPT_PREF64 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) ndisc_ops_is_useropt(dev, opt->nd_opt_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static struct nd_opt_hdr *ndisc_next_useropt(const struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) struct nd_opt_hdr *cur,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct nd_opt_hdr *end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (!cur || !end || cur >= end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) cur = ((void *)cur) + (cur->nd_opt_len << 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) } while (cur < end && !ndisc_is_useropt(dev, cur));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return cur <= end && ndisc_is_useropt(dev, cur) ? cur : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) struct ndisc_options *ndisc_parse_options(const struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) u8 *opt, int opt_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) struct ndisc_options *ndopts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct nd_opt_hdr *nd_opt = (struct nd_opt_hdr *)opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (!nd_opt || opt_len < 0 || !ndopts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) memset(ndopts, 0, sizeof(*ndopts));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) while (opt_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) int l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (opt_len < sizeof(struct nd_opt_hdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) l = nd_opt->nd_opt_len << 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (opt_len < l || l == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (ndisc_ops_parse_options(dev, nd_opt, ndopts))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) goto next_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) switch (nd_opt->nd_opt_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) case ND_OPT_SOURCE_LL_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) case ND_OPT_TARGET_LL_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) case ND_OPT_MTU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) case ND_OPT_NONCE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) case ND_OPT_REDIRECT_HDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (ndopts->nd_opt_array[nd_opt->nd_opt_type]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) ND_PRINTK(2, warn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) "%s: duplicated ND6 option found: type=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) __func__, nd_opt->nd_opt_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) ndopts->nd_opt_array[nd_opt->nd_opt_type] = nd_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) case ND_OPT_PREFIX_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) ndopts->nd_opts_pi_end = nd_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) if (!ndopts->nd_opt_array[nd_opt->nd_opt_type])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) ndopts->nd_opt_array[nd_opt->nd_opt_type] = nd_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) #ifdef CONFIG_IPV6_ROUTE_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) case ND_OPT_ROUTE_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) ndopts->nd_opts_ri_end = nd_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (!ndopts->nd_opts_ri)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) ndopts->nd_opts_ri = nd_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if (ndisc_is_useropt(dev, nd_opt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) ndopts->nd_useropts_end = nd_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (!ndopts->nd_useropts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) ndopts->nd_useropts = nd_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * Unknown options must be silently ignored,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * to accommodate future extension to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) ND_PRINTK(2, notice,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) "%s: ignored unsupported option; type=%d, len=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) nd_opt->nd_opt_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) nd_opt->nd_opt_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) next_opt:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) opt_len -= l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) nd_opt = ((void *)nd_opt) + l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) return ndopts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) int ndisc_mc_map(const struct in6_addr *addr, char *buf, struct net_device *dev, int dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) switch (dev->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) case ARPHRD_ETHER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) case ARPHRD_IEEE802: /* Not sure. Check it later. --ANK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) case ARPHRD_FDDI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) ipv6_eth_mc_map(addr, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) case ARPHRD_ARCNET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) ipv6_arcnet_mc_map(addr, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) case ARPHRD_INFINIBAND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) ipv6_ib_mc_map(addr, dev->broadcast, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) case ARPHRD_IPGRE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) return ipv6_ipgre_mc_map(addr, dev->broadcast, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) if (dir) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) memcpy(buf, dev->broadcast, dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) EXPORT_SYMBOL(ndisc_mc_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) static u32 ndisc_hash(const void *pkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) const struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) __u32 *hash_rnd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) return ndisc_hashfn(pkey, dev, hash_rnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) static bool ndisc_key_eq(const struct neighbour *n, const void *pkey)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) return neigh_key_eq128(n, pkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static int ndisc_constructor(struct neighbour *neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) struct in6_addr *addr = (struct in6_addr *)&neigh->primary_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) struct net_device *dev = neigh->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) struct inet6_dev *in6_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) struct neigh_parms *parms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) bool is_multicast = ipv6_addr_is_multicast(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) in6_dev = in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) if (!in6_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) parms = in6_dev->nd_parms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) __neigh_parms_put(neigh->parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) neigh->parms = neigh_parms_clone(parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) neigh->type = is_multicast ? RTN_MULTICAST : RTN_UNICAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (!dev->header_ops) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) neigh->nud_state = NUD_NOARP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) neigh->ops = &ndisc_direct_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) neigh->output = neigh_direct_output;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) if (is_multicast) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) neigh->nud_state = NUD_NOARP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) ndisc_mc_map(addr, neigh->ha, dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) } else if (dev->flags&(IFF_NOARP|IFF_LOOPBACK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) neigh->nud_state = NUD_NOARP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) memcpy(neigh->ha, dev->dev_addr, dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) if (dev->flags&IFF_LOOPBACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) neigh->type = RTN_LOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) } else if (dev->flags&IFF_POINTOPOINT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) neigh->nud_state = NUD_NOARP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) memcpy(neigh->ha, dev->broadcast, dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (dev->header_ops->cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) neigh->ops = &ndisc_hh_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) neigh->ops = &ndisc_generic_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) if (neigh->nud_state&NUD_VALID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) neigh->output = neigh->ops->connected_output;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) neigh->output = neigh->ops->output;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) in6_dev_put(in6_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) static int pndisc_constructor(struct pneigh_entry *n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) struct in6_addr *addr = (struct in6_addr *)&n->key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) struct in6_addr maddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) struct net_device *dev = n->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (!dev || !__in6_dev_get(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) addrconf_addr_solict_mult(addr, &maddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) ipv6_dev_mc_inc(dev, &maddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) static void pndisc_destructor(struct pneigh_entry *n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) struct in6_addr *addr = (struct in6_addr *)&n->key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) struct in6_addr maddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) struct net_device *dev = n->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (!dev || !__in6_dev_get(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) addrconf_addr_solict_mult(addr, &maddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) ipv6_dev_mc_dec(dev, &maddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) /* called with rtnl held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) static bool ndisc_allow_add(const struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) struct inet6_dev *idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) if (!idev || idev->cnf.disable_ipv6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) NL_SET_ERR_MSG(extack, "IPv6 is disabled on this device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) static struct sk_buff *ndisc_alloc_skb(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) int hlen = LL_RESERVED_SPACE(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) int tlen = dev->needed_tailroom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) struct sock *sk = dev_net(dev)->ipv6.ndisc_sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) skb = alloc_skb(hlen + sizeof(struct ipv6hdr) + len + tlen, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) ND_PRINTK(0, err, "ndisc: %s failed to allocate an skb\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) skb->protocol = htons(ETH_P_IPV6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) skb->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) skb_reserve(skb, hlen + sizeof(struct ipv6hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) skb_reset_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) /* Manually assign socket ownership as we avoid calling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) * sock_alloc_send_pskb() to bypass wmem buffer limits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) skb_set_owner_w(skb, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) static void ip6_nd_hdr(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) const struct in6_addr *saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) const struct in6_addr *daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) int hop_limit, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) struct ipv6hdr *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) unsigned tclass;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) idev = __in6_dev_get(skb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) tclass = idev ? idev->cnf.ndisc_tclass : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) skb_push(skb, sizeof(*hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) skb_reset_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) hdr = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) ip6_flow_hdr(hdr, tclass, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) hdr->payload_len = htons(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) hdr->nexthdr = IPPROTO_ICMPV6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) hdr->hop_limit = hop_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) hdr->saddr = *saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) hdr->daddr = *daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static void ndisc_send_skb(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) const struct in6_addr *daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) const struct in6_addr *saddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) struct dst_entry *dst = skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) struct net *net = dev_net(skb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) struct sock *sk = net->ipv6.ndisc_sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) struct icmp6hdr *icmp6h = icmp6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) u8 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) type = icmp6h->icmp6_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) if (!dst) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) struct flowi6 fl6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) int oif = skb->dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) icmpv6_flow_init(sk, &fl6, type, saddr, daddr, oif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) dst = icmp6_dst_alloc(skb->dev, &fl6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) if (IS_ERR(dst)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) skb_dst_set(skb, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) icmp6h->icmp6_cksum = csum_ipv6_magic(saddr, daddr, skb->len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) IPPROTO_ICMPV6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) csum_partial(icmp6h,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) skb->len, 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) ip6_nd_hdr(skb, saddr, daddr, inet6_sk(sk)->hop_limit, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) idev = __in6_dev_get(dst->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) IP6_UPD_PO_STATS(net, idev, IPSTATS_MIB_OUT, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) err = NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) net, sk, skb, NULL, dst->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) dst_output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) ICMP6MSGOUT_INC_STATS(net, idev, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) ICMP6_INC_STATS(net, idev, ICMP6_MIB_OUTMSGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) void ndisc_send_na(struct net_device *dev, const struct in6_addr *daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) const struct in6_addr *solicited_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) bool router, bool solicited, bool override, bool inc_opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) struct in6_addr tmpaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) struct inet6_ifaddr *ifp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) const struct in6_addr *src_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) struct nd_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) int optlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) /* for anycast or proxy, solicited_addr != src_addr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) ifp = ipv6_get_ifaddr(dev_net(dev), solicited_addr, dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) if (ifp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) src_addr = solicited_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) if (ifp->flags & IFA_F_OPTIMISTIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) override = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) inc_opt |= ifp->idev->cnf.force_tllao;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) in6_ifa_put(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) &tmpaddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) src_addr = &tmpaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (!dev->addr_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) inc_opt = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) if (inc_opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) optlen += ndisc_opt_addr_space(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) NDISC_NEIGHBOUR_ADVERTISEMENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) skb = ndisc_alloc_skb(dev, sizeof(*msg) + optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) msg = skb_put(skb, sizeof(*msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) *msg = (struct nd_msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) .icmph = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) .icmp6_type = NDISC_NEIGHBOUR_ADVERTISEMENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) .icmp6_router = router,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) .icmp6_solicited = solicited,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) .icmp6_override = override,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) .target = *solicited_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) if (inc_opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) ndisc_fill_addr_option(skb, ND_OPT_TARGET_LL_ADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) dev->dev_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) NDISC_NEIGHBOUR_ADVERTISEMENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) ndisc_send_skb(skb, daddr, src_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) static void ndisc_send_unsol_na(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) struct inet6_ifaddr *ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) idev = in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) if (!idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) read_lock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) list_for_each_entry(ifa, &idev->addr_list, if_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) /* skip tentative addresses until dad completes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) if (ifa->flags & IFA_F_TENTATIVE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) !(ifa->flags & IFA_F_OPTIMISTIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) ndisc_send_na(dev, &in6addr_linklocal_allnodes, &ifa->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) /*router=*/ !!idev->cnf.forwarding,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) /*solicited=*/ false, /*override=*/ true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) /*inc_opt=*/ true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) read_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) in6_dev_put(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) void ndisc_send_ns(struct net_device *dev, const struct in6_addr *solicit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) const struct in6_addr *daddr, const struct in6_addr *saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) u64 nonce)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) struct in6_addr addr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) int inc_opt = dev->addr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) int optlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) struct nd_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) if (!saddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) if (ipv6_get_lladdr(dev, &addr_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) (IFA_F_TENTATIVE|IFA_F_OPTIMISTIC)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) saddr = &addr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) if (ipv6_addr_any(saddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) inc_opt = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) if (inc_opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) optlen += ndisc_opt_addr_space(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) NDISC_NEIGHBOUR_SOLICITATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) if (nonce != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) optlen += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) skb = ndisc_alloc_skb(dev, sizeof(*msg) + optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) msg = skb_put(skb, sizeof(*msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) *msg = (struct nd_msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) .icmph = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) .icmp6_type = NDISC_NEIGHBOUR_SOLICITATION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) .target = *solicit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) if (inc_opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) ndisc_fill_addr_option(skb, ND_OPT_SOURCE_LL_ADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) dev->dev_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) NDISC_NEIGHBOUR_SOLICITATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) if (nonce != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) u8 *opt = skb_put(skb, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) opt[0] = ND_OPT_NONCE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) opt[1] = 8 >> 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) memcpy(opt + 2, &nonce, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) ndisc_send_skb(skb, daddr, saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) void ndisc_send_rs(struct net_device *dev, const struct in6_addr *saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) const struct in6_addr *daddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) struct rs_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) int send_sllao = dev->addr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) int optlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) * According to section 2.2 of RFC 4429, we must not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) * send router solicitations with a sllao from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) * optimistic addresses, but we may send the solicitation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) * if we don't include the sllao. So here we check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) * if our address is optimistic, and if so, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) * suppress the inclusion of the sllao.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) if (send_sllao) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) struct inet6_ifaddr *ifp = ipv6_get_ifaddr(dev_net(dev), saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) if (ifp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) if (ifp->flags & IFA_F_OPTIMISTIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) send_sllao = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) in6_ifa_put(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) send_sllao = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) if (send_sllao)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) optlen += ndisc_opt_addr_space(dev, NDISC_ROUTER_SOLICITATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) skb = ndisc_alloc_skb(dev, sizeof(*msg) + optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) msg = skb_put(skb, sizeof(*msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) *msg = (struct rs_msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) .icmph = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) .icmp6_type = NDISC_ROUTER_SOLICITATION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) if (send_sllao)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) ndisc_fill_addr_option(skb, ND_OPT_SOURCE_LL_ADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) dev->dev_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) NDISC_ROUTER_SOLICITATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) ndisc_send_skb(skb, daddr, saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) static void ndisc_error_report(struct neighbour *neigh, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) * "The sender MUST return an ICMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) * destination unreachable"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) dst_link_failure(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) /* Called with locked neigh: either read or both */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) static void ndisc_solicit(struct neighbour *neigh, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) struct in6_addr *saddr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) struct in6_addr mcaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) struct net_device *dev = neigh->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) struct in6_addr *target = (struct in6_addr *)&neigh->primary_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) int probes = atomic_read(&neigh->probes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) if (skb && ipv6_chk_addr_and_flags(dev_net(dev), &ipv6_hdr(skb)->saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) dev, false, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) IFA_F_TENTATIVE|IFA_F_OPTIMISTIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) saddr = &ipv6_hdr(skb)->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) probes -= NEIGH_VAR(neigh->parms, UCAST_PROBES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) if (probes < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) if (!(neigh->nud_state & NUD_VALID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) ND_PRINTK(1, dbg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) "%s: trying to ucast probe in NUD_INVALID: %pI6\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) __func__, target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) ndisc_send_ns(dev, target, target, saddr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) } else if ((probes -= NEIGH_VAR(neigh->parms, APP_PROBES)) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) neigh_app_ns(neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) addrconf_addr_solict_mult(target, &mcaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) ndisc_send_ns(dev, target, &mcaddr, saddr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) static int pndisc_is_router(const void *pkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) struct pneigh_entry *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) int ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) read_lock_bh(&nd_tbl.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) n = __pneigh_lookup(&nd_tbl, dev_net(dev), pkey, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) if (n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) ret = !!(n->flags & NTF_ROUTER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) read_unlock_bh(&nd_tbl.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) void ndisc_update(const struct net_device *dev, struct neighbour *neigh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) const u8 *lladdr, u8 new, u32 flags, u8 icmp6_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) struct ndisc_options *ndopts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) neigh_update(neigh, lladdr, new, flags, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) /* report ndisc ops about neighbour update */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) ndisc_ops_update(dev, neigh, flags, icmp6_type, ndopts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) static void ndisc_recv_ns(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) struct nd_msg *msg = (struct nd_msg *)skb_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) const struct in6_addr *saddr = &ipv6_hdr(skb)->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) const struct in6_addr *daddr = &ipv6_hdr(skb)->daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) u8 *lladdr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) u32 ndoptlen = skb_tail_pointer(skb) - (skb_transport_header(skb) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) offsetof(struct nd_msg, opt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) struct ndisc_options ndopts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) struct net_device *dev = skb->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) struct inet6_ifaddr *ifp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) struct inet6_dev *idev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) struct neighbour *neigh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) int dad = ipv6_addr_any(saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) bool inc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) int is_router = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) u64 nonce = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) if (skb->len < sizeof(struct nd_msg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) ND_PRINTK(2, warn, "NS: packet too short\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) if (ipv6_addr_is_multicast(&msg->target)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) ND_PRINTK(2, warn, "NS: multicast target address\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) * RFC2461 7.1.1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) * DAD has to be destined for solicited node multicast address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) if (dad && !ipv6_addr_is_solict_mult(daddr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) ND_PRINTK(2, warn, "NS: bad DAD packet (wrong destination)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) if (!ndisc_parse_options(dev, msg->opt, ndoptlen, &ndopts)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) ND_PRINTK(2, warn, "NS: invalid ND options\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) if (ndopts.nd_opts_src_lladdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) lladdr = ndisc_opt_addr_data(ndopts.nd_opts_src_lladdr, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) if (!lladdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) ND_PRINTK(2, warn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) "NS: invalid link-layer address length\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) /* RFC2461 7.1.1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) * If the IP source address is the unspecified address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) * there MUST NOT be source link-layer address option
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) * in the message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) if (dad) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) ND_PRINTK(2, warn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) "NS: bad DAD packet (link-layer address option)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) if (ndopts.nd_opts_nonce && ndopts.nd_opts_nonce->nd_opt_len == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) memcpy(&nonce, (u8 *)(ndopts.nd_opts_nonce + 1), 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) inc = ipv6_addr_is_multicast(daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) ifp = ipv6_get_ifaddr(dev_net(dev), &msg->target, dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) if (ifp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) have_ifp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) if (ifp->flags & (IFA_F_TENTATIVE|IFA_F_OPTIMISTIC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) if (dad) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) if (nonce != 0 && ifp->dad_nonce == nonce) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) u8 *np = (u8 *)&nonce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) /* Matching nonce if looped back */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) ND_PRINTK(2, notice,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) "%s: IPv6 DAD loopback for address %pI6c nonce %pM ignored\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) ifp->idev->dev->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) &ifp->addr, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) * We are colliding with another node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) * who is doing DAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) * so fail our DAD process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) addrconf_dad_failure(skb, ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) * This is not a dad solicitation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) * If we are an optimistic node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) * we should respond.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) * Otherwise, we should ignore it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) if (!(ifp->flags & IFA_F_OPTIMISTIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) idev = ifp->idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) struct net *net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) /* perhaps an address on the master device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) if (netif_is_l3_slave(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) struct net_device *mdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) mdev = netdev_master_upper_dev_get_rcu(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) if (mdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) ifp = ipv6_get_ifaddr(net, &msg->target, mdev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) if (ifp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) goto have_ifp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) idev = in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) if (!idev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) /* XXX: count this drop? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) if (ipv6_chk_acast_addr(net, dev, &msg->target) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) (idev->cnf.forwarding &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) (net->ipv6.devconf_all->proxy_ndp || idev->cnf.proxy_ndp) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) (is_router = pndisc_is_router(&msg->target, dev)) >= 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) if (!(NEIGH_CB(skb)->flags & LOCALLY_ENQUEUED) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) skb->pkt_type != PACKET_HOST &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) inc &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) NEIGH_VAR(idev->nd_parms, PROXY_DELAY) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) * for anycast or proxy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) * sender should delay its response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) * by a random time between 0 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) * MAX_ANYCAST_DELAY_TIME seconds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) * (RFC2461) -- yoshfuji
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) struct sk_buff *n = skb_clone(skb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) if (n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) pneigh_enqueue(&nd_tbl, idev->nd_parms, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) if (is_router < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) is_router = idev->cnf.forwarding;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) if (dad) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) ndisc_send_na(dev, &in6addr_linklocal_allnodes, &msg->target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) !!is_router, false, (ifp != NULL), true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) if (inc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) NEIGH_CACHE_STAT_INC(&nd_tbl, rcv_probes_mcast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) NEIGH_CACHE_STAT_INC(&nd_tbl, rcv_probes_ucast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) * update / create cache entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) * for the source address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) neigh = __neigh_lookup(&nd_tbl, saddr, dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) !inc || lladdr || !dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) if (neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) ndisc_update(dev, neigh, lladdr, NUD_STALE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) NEIGH_UPDATE_F_WEAK_OVERRIDE|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) NEIGH_UPDATE_F_OVERRIDE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) NDISC_NEIGHBOUR_SOLICITATION, &ndopts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) if (neigh || !dev->header_ops) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) ndisc_send_na(dev, saddr, &msg->target, !!is_router,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) true, (ifp != NULL && inc), inc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) if (neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) neigh_release(neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) if (ifp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) in6_ifa_put(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) in6_dev_put(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) static void ndisc_recv_na(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) struct nd_msg *msg = (struct nd_msg *)skb_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) struct in6_addr *saddr = &ipv6_hdr(skb)->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) const struct in6_addr *daddr = &ipv6_hdr(skb)->daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) u8 *lladdr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) u32 ndoptlen = skb_tail_pointer(skb) - (skb_transport_header(skb) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) offsetof(struct nd_msg, opt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) struct ndisc_options ndopts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) struct net_device *dev = skb->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) struct inet6_dev *idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) struct inet6_ifaddr *ifp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) struct neighbour *neigh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) if (skb->len < sizeof(struct nd_msg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) ND_PRINTK(2, warn, "NA: packet too short\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) if (ipv6_addr_is_multicast(&msg->target)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) ND_PRINTK(2, warn, "NA: target address is multicast\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) if (ipv6_addr_is_multicast(daddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) msg->icmph.icmp6_solicited) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) ND_PRINTK(2, warn, "NA: solicited NA is multicasted\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) /* For some 802.11 wireless deployments (and possibly other networks),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) * there will be a NA proxy and unsolicitd packets are attacks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) * and thus should not be accepted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) if (!msg->icmph.icmp6_solicited && idev &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) idev->cnf.drop_unsolicited_na)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) if (!ndisc_parse_options(dev, msg->opt, ndoptlen, &ndopts)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) ND_PRINTK(2, warn, "NS: invalid ND option\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) if (ndopts.nd_opts_tgt_lladdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) lladdr = ndisc_opt_addr_data(ndopts.nd_opts_tgt_lladdr, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) if (!lladdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) ND_PRINTK(2, warn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) "NA: invalid link-layer address length\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) ifp = ipv6_get_ifaddr(dev_net(dev), &msg->target, dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) if (ifp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) if (skb->pkt_type != PACKET_LOOPBACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) && (ifp->flags & IFA_F_TENTATIVE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) addrconf_dad_failure(skb, ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) /* What should we make now? The advertisement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) is invalid, but ndisc specs say nothing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) about it. It could be misconfiguration, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) an smart proxy agent tries to help us :-)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) We should not print the error if NA has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) received from loopback - it is just our own
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) unsolicited advertisement.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) if (skb->pkt_type != PACKET_LOOPBACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) ND_PRINTK(1, warn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) "NA: %pM advertised our address %pI6c on %s!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) eth_hdr(skb)->h_source, &ifp->addr, ifp->idev->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) in6_ifa_put(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) neigh = neigh_lookup(&nd_tbl, &msg->target, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) if (neigh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) u8 old_flags = neigh->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) struct net *net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) if (neigh->nud_state & NUD_FAILED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) * Don't update the neighbor cache entry on a proxy NA from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) * ourselves because either the proxied node is off link or it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) * has already sent a NA to us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) if (lladdr && !memcmp(lladdr, dev->dev_addr, dev->addr_len) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) net->ipv6.devconf_all->forwarding && net->ipv6.devconf_all->proxy_ndp &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) pneigh_lookup(&nd_tbl, net, &msg->target, dev, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) /* XXX: idev->cnf.proxy_ndp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) ndisc_update(dev, neigh, lladdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) msg->icmph.icmp6_solicited ? NUD_REACHABLE : NUD_STALE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) NEIGH_UPDATE_F_WEAK_OVERRIDE|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) (msg->icmph.icmp6_override ? NEIGH_UPDATE_F_OVERRIDE : 0)|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) NEIGH_UPDATE_F_OVERRIDE_ISROUTER|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) (msg->icmph.icmp6_router ? NEIGH_UPDATE_F_ISROUTER : 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) NDISC_NEIGHBOUR_ADVERTISEMENT, &ndopts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) if ((old_flags & ~neigh->flags) & NTF_ROUTER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) * Change: router to host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) rt6_clean_tohost(dev_net(dev), saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) neigh_release(neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) static void ndisc_recv_rs(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) struct rs_msg *rs_msg = (struct rs_msg *)skb_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) unsigned long ndoptlen = skb->len - sizeof(*rs_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) struct neighbour *neigh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) const struct in6_addr *saddr = &ipv6_hdr(skb)->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) struct ndisc_options ndopts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) u8 *lladdr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) if (skb->len < sizeof(*rs_msg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) idev = __in6_dev_get(skb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) if (!idev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) ND_PRINTK(1, err, "RS: can't find in6 device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) /* Don't accept RS if we're not in router mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) if (!idev->cnf.forwarding)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) * Don't update NCE if src = ::;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) * this implies that the source node has no ip address assigned yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) if (ipv6_addr_any(saddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) /* Parse ND options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) if (!ndisc_parse_options(skb->dev, rs_msg->opt, ndoptlen, &ndopts)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) ND_PRINTK(2, notice, "NS: invalid ND option, ignored\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) if (ndopts.nd_opts_src_lladdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) lladdr = ndisc_opt_addr_data(ndopts.nd_opts_src_lladdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) skb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) if (!lladdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) neigh = __neigh_lookup(&nd_tbl, saddr, skb->dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) if (neigh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) ndisc_update(skb->dev, neigh, lladdr, NUD_STALE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) NEIGH_UPDATE_F_WEAK_OVERRIDE|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) NEIGH_UPDATE_F_OVERRIDE|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) NEIGH_UPDATE_F_OVERRIDE_ISROUTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) NDISC_ROUTER_SOLICITATION, &ndopts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) neigh_release(neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) static void ndisc_ra_useropt(struct sk_buff *ra, struct nd_opt_hdr *opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) struct icmp6hdr *icmp6h = (struct icmp6hdr *)skb_transport_header(ra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) struct nlmsghdr *nlh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) struct nduseroptmsg *ndmsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) struct net *net = dev_net(ra->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) int base_size = NLMSG_ALIGN(sizeof(struct nduseroptmsg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) + (opt->nd_opt_len << 3));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) size_t msg_size = base_size + nla_total_size(sizeof(struct in6_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) skb = nlmsg_new(msg_size, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) err = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) nlh = nlmsg_put(skb, 0, 0, RTM_NEWNDUSEROPT, base_size, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) if (!nlh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) ndmsg = nlmsg_data(nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) ndmsg->nduseropt_family = AF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) ndmsg->nduseropt_ifindex = ra->dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) ndmsg->nduseropt_icmp_type = icmp6h->icmp6_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) ndmsg->nduseropt_icmp_code = icmp6h->icmp6_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) ndmsg->nduseropt_opts_len = opt->nd_opt_len << 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) memcpy(ndmsg + 1, opt, opt->nd_opt_len << 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) if (nla_put_in6_addr(skb, NDUSEROPT_SRCADDR, &ipv6_hdr(ra)->saddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) nlmsg_end(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) rtnl_notify(skb, net, 0, RTNLGRP_ND_USEROPT, NULL, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) nlmsg_free(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) err = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) errout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) rtnl_set_sk_err(net, RTNLGRP_ND_USEROPT, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) static void ndisc_router_discovery(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) struct ra_msg *ra_msg = (struct ra_msg *)skb_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) struct neighbour *neigh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) struct inet6_dev *in6_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) struct fib6_info *rt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) struct net *net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) int lifetime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) struct ndisc_options ndopts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) int optlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) unsigned int pref = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) __u32 old_if_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) bool send_ifinfo_notify = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) __u8 *opt = (__u8 *)(ra_msg + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) optlen = (skb_tail_pointer(skb) - skb_transport_header(skb)) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) sizeof(struct ra_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) ND_PRINTK(2, info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) "RA: %s, dev: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) __func__, skb->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) if (!(ipv6_addr_type(&ipv6_hdr(skb)->saddr) & IPV6_ADDR_LINKLOCAL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) ND_PRINTK(2, warn, "RA: source address is not link-local\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) if (optlen < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) ND_PRINTK(2, warn, "RA: packet too short\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) #ifdef CONFIG_IPV6_NDISC_NODETYPE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) if (skb->ndisc_nodetype == NDISC_NODETYPE_HOST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) ND_PRINTK(2, warn, "RA: from host or unauthorized router\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) * set the RA_RECV flag in the interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) in6_dev = __in6_dev_get(skb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) if (!in6_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) ND_PRINTK(0, err, "RA: can't find inet6 device for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) skb->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) if (!ndisc_parse_options(skb->dev, opt, optlen, &ndopts)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) ND_PRINTK(2, warn, "RA: invalid ND options\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) if (!ipv6_accept_ra(in6_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) ND_PRINTK(2, info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) "RA: %s, did not accept ra for dev: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) __func__, skb->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) goto skip_linkparms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) #ifdef CONFIG_IPV6_NDISC_NODETYPE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) /* skip link-specific parameters from interior routers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) if (skb->ndisc_nodetype == NDISC_NODETYPE_NODEFAULT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) ND_PRINTK(2, info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) "RA: %s, nodetype is NODEFAULT, dev: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) __func__, skb->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) goto skip_linkparms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) if (in6_dev->if_flags & IF_RS_SENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) * flag that an RA was received after an RS was sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) * out on this interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) in6_dev->if_flags |= IF_RA_RCVD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) * Remember the managed/otherconf flags from most recently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) * received RA message (RFC 2462) -- yoshfuji
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) old_if_flags = in6_dev->if_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) in6_dev->if_flags = (in6_dev->if_flags & ~(IF_RA_MANAGED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) IF_RA_OTHERCONF)) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) (ra_msg->icmph.icmp6_addrconf_managed ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) IF_RA_MANAGED : 0) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) (ra_msg->icmph.icmp6_addrconf_other ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) IF_RA_OTHERCONF : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) if (old_if_flags != in6_dev->if_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) send_ifinfo_notify = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) if (!in6_dev->cnf.accept_ra_defrtr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) ND_PRINTK(2, info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) "RA: %s, defrtr is false for dev: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) __func__, skb->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) goto skip_defrtr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) /* Do not accept RA with source-addr found on local machine unless
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) * accept_ra_from_local is set to true.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) net = dev_net(in6_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) if (!in6_dev->cnf.accept_ra_from_local &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) ipv6_chk_addr(net, &ipv6_hdr(skb)->saddr, in6_dev->dev, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) ND_PRINTK(2, info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) "RA from local address detected on dev: %s: default router ignored\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) skb->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) goto skip_defrtr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) lifetime = ntohs(ra_msg->icmph.icmp6_rt_lifetime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) #ifdef CONFIG_IPV6_ROUTER_PREF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) pref = ra_msg->icmph.icmp6_router_pref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) /* 10b is handled as if it were 00b (medium) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) if (pref == ICMPV6_ROUTER_PREF_INVALID ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) !in6_dev->cnf.accept_ra_rtr_pref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) pref = ICMPV6_ROUTER_PREF_MEDIUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) /* routes added from RAs do not use nexthop objects */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) rt = rt6_get_dflt_router(net, &ipv6_hdr(skb)->saddr, skb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) if (rt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) neigh = ip6_neigh_lookup(&rt->fib6_nh->fib_nh_gw6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) rt->fib6_nh->fib_nh_dev, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) &ipv6_hdr(skb)->saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) if (!neigh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) ND_PRINTK(0, err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) "RA: %s got default router without neighbour\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) fib6_info_release(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) if (rt && lifetime == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) ip6_del_rt(net, rt, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) rt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) ND_PRINTK(3, info, "RA: rt: %p lifetime: %d, for dev: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) rt, lifetime, skb->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) if (!rt && lifetime) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) ND_PRINTK(3, info, "RA: adding default router\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) rt = rt6_add_dflt_router(net, &ipv6_hdr(skb)->saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) skb->dev, pref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) if (!rt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) ND_PRINTK(0, err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) "RA: %s failed to add default route\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) neigh = ip6_neigh_lookup(&rt->fib6_nh->fib_nh_gw6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) rt->fib6_nh->fib_nh_dev, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) &ipv6_hdr(skb)->saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) if (!neigh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) ND_PRINTK(0, err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) "RA: %s got default router without neighbour\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) fib6_info_release(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) neigh->flags |= NTF_ROUTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) } else if (rt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) rt->fib6_flags = (rt->fib6_flags & ~RTF_PREF_MASK) | RTF_PREF(pref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) if (rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) fib6_set_expires(rt, jiffies + (HZ * lifetime));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) if (in6_dev->cnf.accept_ra_min_hop_limit < 256 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) ra_msg->icmph.icmp6_hop_limit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) if (in6_dev->cnf.accept_ra_min_hop_limit <= ra_msg->icmph.icmp6_hop_limit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) in6_dev->cnf.hop_limit = ra_msg->icmph.icmp6_hop_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) fib6_metric_set(rt, RTAX_HOPLIMIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) ra_msg->icmph.icmp6_hop_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) ND_PRINTK(2, warn, "RA: Got route advertisement with lower hop_limit than minimum\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) skip_defrtr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) * Update Reachable Time and Retrans Timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) if (in6_dev->nd_parms) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) unsigned long rtime = ntohl(ra_msg->retrans_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) if (rtime && rtime/1000 < MAX_SCHEDULE_TIMEOUT/HZ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) rtime = (rtime*HZ)/1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) if (rtime < HZ/100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) rtime = HZ/100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) NEIGH_VAR_SET(in6_dev->nd_parms, RETRANS_TIME, rtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) in6_dev->tstamp = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) send_ifinfo_notify = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) rtime = ntohl(ra_msg->reachable_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) if (rtime && rtime/1000 < MAX_SCHEDULE_TIMEOUT/(3*HZ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) rtime = (rtime*HZ)/1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) if (rtime < HZ/10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) rtime = HZ/10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) if (rtime != NEIGH_VAR(in6_dev->nd_parms, BASE_REACHABLE_TIME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) NEIGH_VAR_SET(in6_dev->nd_parms,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) BASE_REACHABLE_TIME, rtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) NEIGH_VAR_SET(in6_dev->nd_parms,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) GC_STALETIME, 3 * rtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) in6_dev->nd_parms->reachable_time = neigh_rand_reach_time(rtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) in6_dev->tstamp = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) send_ifinfo_notify = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) * Send a notify if RA changed managed/otherconf flags or timer settings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) if (send_ifinfo_notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) inet6_ifinfo_notify(RTM_NEWLINK, in6_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) skip_linkparms:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) * Process options.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) if (!neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) neigh = __neigh_lookup(&nd_tbl, &ipv6_hdr(skb)->saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) skb->dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) if (neigh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) u8 *lladdr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) if (ndopts.nd_opts_src_lladdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) lladdr = ndisc_opt_addr_data(ndopts.nd_opts_src_lladdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) skb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) if (!lladdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) ND_PRINTK(2, warn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) "RA: invalid link-layer address length\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) ndisc_update(skb->dev, neigh, lladdr, NUD_STALE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) NEIGH_UPDATE_F_WEAK_OVERRIDE|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) NEIGH_UPDATE_F_OVERRIDE|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) NEIGH_UPDATE_F_OVERRIDE_ISROUTER|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) NEIGH_UPDATE_F_ISROUTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) NDISC_ROUTER_ADVERTISEMENT, &ndopts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) if (!ipv6_accept_ra(in6_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) ND_PRINTK(2, info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) "RA: %s, accept_ra is false for dev: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) __func__, skb->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) #ifdef CONFIG_IPV6_ROUTE_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) if (!in6_dev->cnf.accept_ra_from_local &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) ipv6_chk_addr(dev_net(in6_dev->dev), &ipv6_hdr(skb)->saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) in6_dev->dev, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) ND_PRINTK(2, info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) "RA from local address detected on dev: %s: router info ignored.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) skb->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) goto skip_routeinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) if (in6_dev->cnf.accept_ra_rtr_pref && ndopts.nd_opts_ri) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) struct nd_opt_hdr *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) for (p = ndopts.nd_opts_ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) p = ndisc_next_option(p, ndopts.nd_opts_ri_end)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) struct route_info *ri = (struct route_info *)p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) #ifdef CONFIG_IPV6_NDISC_NODETYPE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) if (skb->ndisc_nodetype == NDISC_NODETYPE_NODEFAULT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) ri->prefix_len == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) if (ri->prefix_len == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) !in6_dev->cnf.accept_ra_defrtr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) if (ri->prefix_len < in6_dev->cnf.accept_ra_rt_info_min_plen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) if (ri->prefix_len > in6_dev->cnf.accept_ra_rt_info_max_plen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) rt6_route_rcv(skb->dev, (u8 *)p, (p->nd_opt_len) << 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) &ipv6_hdr(skb)->saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) skip_routeinfo:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) #ifdef CONFIG_IPV6_NDISC_NODETYPE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) /* skip link-specific ndopts from interior routers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) if (skb->ndisc_nodetype == NDISC_NODETYPE_NODEFAULT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) ND_PRINTK(2, info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) "RA: %s, nodetype is NODEFAULT (interior routes), dev: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) __func__, skb->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) if (in6_dev->cnf.accept_ra_pinfo && ndopts.nd_opts_pi) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) struct nd_opt_hdr *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) for (p = ndopts.nd_opts_pi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) p = ndisc_next_option(p, ndopts.nd_opts_pi_end)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) addrconf_prefix_rcv(skb->dev, (u8 *)p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) (p->nd_opt_len) << 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) ndopts.nd_opts_src_lladdr != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) if (ndopts.nd_opts_mtu && in6_dev->cnf.accept_ra_mtu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) __be32 n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) u32 mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) memcpy(&n, ((u8 *)(ndopts.nd_opts_mtu+1))+2, sizeof(mtu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) mtu = ntohl(n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) if (mtu < IPV6_MIN_MTU || mtu > skb->dev->mtu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) ND_PRINTK(2, warn, "RA: invalid mtu: %d\n", mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) } else if (in6_dev->cnf.mtu6 != mtu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) in6_dev->cnf.mtu6 = mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) fib6_metric_set(rt, RTAX_MTU, mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) rt6_mtu_change(skb->dev, mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) if (ndopts.nd_useropts) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) struct nd_opt_hdr *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) for (p = ndopts.nd_useropts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) p = ndisc_next_useropt(skb->dev, p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) ndopts.nd_useropts_end)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) ndisc_ra_useropt(skb, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) if (ndopts.nd_opts_tgt_lladdr || ndopts.nd_opts_rh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) ND_PRINTK(2, warn, "RA: invalid RA options\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) fib6_info_release(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) if (neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) neigh_release(neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) static void ndisc_redirect_rcv(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) u8 *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) struct ndisc_options ndopts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) struct rd_msg *msg = (struct rd_msg *)skb_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) u32 ndoptlen = skb_tail_pointer(skb) - (skb_transport_header(skb) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) offsetof(struct rd_msg, opt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) #ifdef CONFIG_IPV6_NDISC_NODETYPE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) switch (skb->ndisc_nodetype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) case NDISC_NODETYPE_HOST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) case NDISC_NODETYPE_NODEFAULT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) ND_PRINTK(2, warn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) "Redirect: from host or unauthorized router\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) if (!(ipv6_addr_type(&ipv6_hdr(skb)->saddr) & IPV6_ADDR_LINKLOCAL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) ND_PRINTK(2, warn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) "Redirect: source address is not link-local\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) if (!ndisc_parse_options(skb->dev, msg->opt, ndoptlen, &ndopts))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) if (!ndopts.nd_opts_rh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) ip6_redirect_no_header(skb, dev_net(skb->dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) skb->dev->ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) hdr = (u8 *)ndopts.nd_opts_rh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) hdr += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) if (!pskb_pull(skb, hdr - skb_transport_header(skb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) icmpv6_notify(skb, NDISC_REDIRECT, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) static void ndisc_fill_redirect_hdr_option(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) struct sk_buff *orig_skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) int rd_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) u8 *opt = skb_put(skb, rd_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) memset(opt, 0, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) *(opt++) = ND_OPT_REDIRECT_HDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) *(opt++) = (rd_len >> 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) opt += 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) skb_copy_bits(orig_skb, skb_network_offset(orig_skb), opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) rd_len - 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) void ndisc_send_redirect(struct sk_buff *skb, const struct in6_addr *target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) struct net_device *dev = skb->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) struct net *net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) struct sock *sk = net->ipv6.ndisc_sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) int optlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) struct inet_peer *peer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) struct sk_buff *buff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) struct rd_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) struct in6_addr saddr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) struct rt6_info *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) struct dst_entry *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) struct flowi6 fl6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) int rd_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) u8 ha_buf[MAX_ADDR_LEN], *ha = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) ops_data_buf[NDISC_OPS_REDIRECT_DATA_SPACE], *ops_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) bool ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) if (netif_is_l3_master(skb->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) dev = __dev_get_by_index(dev_net(skb->dev), IPCB(skb)->iif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) if (ipv6_get_lladdr(dev, &saddr_buf, IFA_F_TENTATIVE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) ND_PRINTK(2, warn, "Redirect: no link-local address on %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) if (!ipv6_addr_equal(&ipv6_hdr(skb)->daddr, target) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) ipv6_addr_type(target) != (IPV6_ADDR_UNICAST|IPV6_ADDR_LINKLOCAL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) ND_PRINTK(2, warn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) "Redirect: target address is not link-local unicast\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) icmpv6_flow_init(sk, &fl6, NDISC_REDIRECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) &saddr_buf, &ipv6_hdr(skb)->saddr, dev->ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) dst = ip6_route_output(net, NULL, &fl6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) if (dst->error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) dst_release(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) if (IS_ERR(dst))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) rt = (struct rt6_info *) dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) if (rt->rt6i_flags & RTF_GATEWAY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) ND_PRINTK(2, warn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) "Redirect: destination is not a neighbour\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) goto release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) peer = inet_getpeer_v6(net->ipv6.peers, &ipv6_hdr(skb)->saddr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) ret = inet_peer_xrlim_allow(peer, 1*HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) if (peer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) inet_putpeer(peer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) goto release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) if (dev->addr_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) struct neighbour *neigh = dst_neigh_lookup(skb_dst(skb), target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) if (!neigh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) ND_PRINTK(2, warn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) "Redirect: no neigh for target address\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) goto release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) read_lock_bh(&neigh->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) if (neigh->nud_state & NUD_VALID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) memcpy(ha_buf, neigh->ha, dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) read_unlock_bh(&neigh->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) ha = ha_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) optlen += ndisc_redirect_opt_addr_space(dev, neigh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) ops_data_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) &ops_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) read_unlock_bh(&neigh->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) neigh_release(neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) rd_len = min_t(unsigned int,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) IPV6_MIN_MTU - sizeof(struct ipv6hdr) - sizeof(*msg) - optlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) skb->len + 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) rd_len &= ~0x7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) optlen += rd_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) buff = ndisc_alloc_skb(dev, sizeof(*msg) + optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) if (!buff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) goto release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) msg = skb_put(buff, sizeof(*msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) *msg = (struct rd_msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) .icmph = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) .icmp6_type = NDISC_REDIRECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) .target = *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) .dest = ipv6_hdr(skb)->daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) * include target_address option
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) if (ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) ndisc_fill_redirect_addr_option(buff, ha, ops_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) * build redirect option and copy skb over to the new packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) if (rd_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) ndisc_fill_redirect_hdr_option(buff, skb, rd_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) skb_dst_set(buff, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) ndisc_send_skb(buff, &ipv6_hdr(skb)->saddr, &saddr_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) dst_release(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) static void pndisc_redo(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) ndisc_recv_ns(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) static int ndisc_is_multicast(const void *pkey)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) return ipv6_addr_is_multicast((struct in6_addr *)pkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) static bool ndisc_suppress_frag_ndisc(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) struct inet6_dev *idev = __in6_dev_get(skb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) if (!idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) if (IP6CB(skb)->flags & IP6SKB_FRAGMENTED &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) idev->cnf.suppress_frag_ndisc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) net_warn_ratelimited("Received fragmented ndisc packet. Carefully consider disabling suppress_frag_ndisc.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) int ndisc_rcv(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) struct nd_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) if (ndisc_suppress_frag_ndisc(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) if (skb_linearize(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) msg = (struct nd_msg *)skb_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) __skb_push(skb, skb->data - skb_transport_header(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) if (ipv6_hdr(skb)->hop_limit != 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) ND_PRINTK(2, warn, "NDISC: invalid hop-limit: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) ipv6_hdr(skb)->hop_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) if (msg->icmph.icmp6_code != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) ND_PRINTK(2, warn, "NDISC: invalid ICMPv6 code: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) msg->icmph.icmp6_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) switch (msg->icmph.icmp6_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) case NDISC_NEIGHBOUR_SOLICITATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) memset(NEIGH_CB(skb), 0, sizeof(struct neighbour_cb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) ndisc_recv_ns(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) case NDISC_NEIGHBOUR_ADVERTISEMENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) ndisc_recv_na(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) case NDISC_ROUTER_SOLICITATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) ndisc_recv_rs(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) case NDISC_ROUTER_ADVERTISEMENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) ndisc_router_discovery(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) case NDISC_REDIRECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) ndisc_redirect_rcv(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) static int ndisc_netdev_event(struct notifier_block *this, unsigned long event, void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) struct net_device *dev = netdev_notifier_info_to_dev(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) struct netdev_notifier_change_info *change_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) struct net *net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) case NETDEV_CHANGEADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) neigh_changeaddr(&nd_tbl, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) fib6_run_gc(0, net, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) case NETDEV_UP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) idev = in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) if (!idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) if (idev->cnf.ndisc_notify ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) net->ipv6.devconf_all->ndisc_notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) ndisc_send_unsol_na(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) in6_dev_put(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) case NETDEV_CHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) change_info = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) if (change_info->flags_changed & IFF_NOARP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) neigh_changeaddr(&nd_tbl, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) if (!netif_carrier_ok(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) neigh_carrier_down(&nd_tbl, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) case NETDEV_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) neigh_ifdown(&nd_tbl, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) fib6_run_gc(0, net, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) case NETDEV_NOTIFY_PEERS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) ndisc_send_unsol_na(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) static struct notifier_block ndisc_netdev_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) .notifier_call = ndisc_netdev_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) .priority = ADDRCONF_NOTIFY_PRIORITY - 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) static void ndisc_warn_deprecated_sysctl(struct ctl_table *ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) const char *func, const char *dev_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) static char warncomm[TASK_COMM_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) static int warned;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) if (strcmp(warncomm, current->comm) && warned < 5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) strcpy(warncomm, current->comm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) pr_warn("process `%s' is using deprecated sysctl (%s) net.ipv6.neigh.%s.%s - use net.ipv6.neigh.%s.%s_ms instead\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) warncomm, func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) dev_name, ctl->procname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) dev_name, ctl->procname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) warned++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) int ndisc_ifinfo_sysctl_change(struct ctl_table *ctl, int write, void *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) size_t *lenp, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) struct net_device *dev = ctl->extra1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) if ((strcmp(ctl->procname, "retrans_time") == 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) (strcmp(ctl->procname, "base_reachable_time") == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) ndisc_warn_deprecated_sysctl(ctl, "syscall", dev ? dev->name : "default");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) if (strcmp(ctl->procname, "retrans_time") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) ret = neigh_proc_dointvec(ctl, write, buffer, lenp, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) else if (strcmp(ctl->procname, "base_reachable_time") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) ret = neigh_proc_dointvec_jiffies(ctl, write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) buffer, lenp, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) else if ((strcmp(ctl->procname, "retrans_time_ms") == 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) (strcmp(ctl->procname, "base_reachable_time_ms") == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) ret = neigh_proc_dointvec_ms_jiffies(ctl, write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) buffer, lenp, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) if (write && ret == 0 && dev && (idev = in6_dev_get(dev)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) if (ctl->data == &NEIGH_VAR(idev->nd_parms, BASE_REACHABLE_TIME))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) idev->nd_parms->reachable_time =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) neigh_rand_reach_time(NEIGH_VAR(idev->nd_parms, BASE_REACHABLE_TIME));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) idev->tstamp = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) inet6_ifinfo_notify(RTM_NEWLINK, idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) in6_dev_put(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) static int __net_init ndisc_net_init(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) struct ipv6_pinfo *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) err = inet_ctl_sock_create(&sk, PF_INET6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) SOCK_RAW, IPPROTO_ICMPV6, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) ND_PRINTK(0, err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) "NDISC: Failed to initialize the control socket (err %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) net->ipv6.ndisc_sk = sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) np->hop_limit = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) /* Do not loopback ndisc messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) np->mc_loop = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) static void __net_exit ndisc_net_exit(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) inet_ctl_sock_destroy(net->ipv6.ndisc_sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) static struct pernet_operations ndisc_net_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) .init = ndisc_net_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) .exit = ndisc_net_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) int __init ndisc_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) err = register_pernet_subsys(&ndisc_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) * Initialize the neighbour table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) neigh_table_init(NEIGH_ND_TABLE, &nd_tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) err = neigh_sysctl_register(NULL, &nd_tbl.parms,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) ndisc_ifinfo_sysctl_change);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) goto out_unregister_pernet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) out_unregister_pernet:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) unregister_pernet_subsys(&ndisc_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) int __init ndisc_late_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) return register_netdevice_notifier(&ndisc_netdev_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) void ndisc_late_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) unregister_netdevice_notifier(&ndisc_netdev_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) void ndisc_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) neigh_sysctl_unregister(&nd_tbl.parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) neigh_table_clear(NEIGH_ND_TABLE, &nd_tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) unregister_pernet_subsys(&ndisc_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) }