Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #ifndef _NDISC_H |
| 3 | #define _NDISC_H |
| 4 | |
| 5 | /* |
| 6 | * ICMP codes for neighbour discovery messages |
| 7 | */ |
| 8 | |
| 9 | #define NDISC_ROUTER_SOLICITATION 133 |
| 10 | #define NDISC_ROUTER_ADVERTISEMENT 134 |
| 11 | #define NDISC_NEIGHBOUR_SOLICITATION 135 |
| 12 | #define NDISC_NEIGHBOUR_ADVERTISEMENT 136 |
| 13 | #define NDISC_REDIRECT 137 |
| 14 | |
| 15 | /* |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 16 | * Router type: cross-layer information from link-layer to |
| 17 | * IPv6 layer reported by certain link types (e.g., RFC4214). |
| 18 | */ |
| 19 | #define NDISC_NODETYPE_UNSPEC 0 /* unspecified (default) */ |
| 20 | #define NDISC_NODETYPE_HOST 1 /* host or unauthorized router */ |
| 21 | #define NDISC_NODETYPE_NODEFAULT 2 /* non-default router */ |
| 22 | #define NDISC_NODETYPE_DEFAULT 3 /* default router */ |
| 23 | |
| 24 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | * ndisc options |
| 26 | */ |
| 27 | |
| 28 | enum { |
| 29 | __ND_OPT_PREFIX_INFO_END = 0, |
| 30 | ND_OPT_SOURCE_LL_ADDR = 1, /* RFC2461 */ |
| 31 | ND_OPT_TARGET_LL_ADDR = 2, /* RFC2461 */ |
| 32 | ND_OPT_PREFIX_INFO = 3, /* RFC2461 */ |
| 33 | ND_OPT_REDIRECT_HDR = 4, /* RFC2461 */ |
| 34 | ND_OPT_MTU = 5, /* RFC2461 */ |
Erik Nordmark | adc176c | 2016-12-02 14:00:08 -0800 | [diff] [blame] | 35 | ND_OPT_NONCE = 14, /* RFC7527 */ |
YOSHIFUJI Hideaki | 70ceb4f | 2006-03-20 17:06:24 -0800 | [diff] [blame] | 36 | __ND_OPT_ARRAY_MAX, |
| 37 | ND_OPT_ROUTE_INFO = 24, /* RFC4191 */ |
Pierre Ynard | 3191057 | 2007-10-10 21:22:05 -0700 | [diff] [blame] | 38 | ND_OPT_RDNSS = 25, /* RFC5006 */ |
Alexey I. Froloff | e35f30c | 2012-04-06 05:50:58 +0000 | [diff] [blame] | 39 | ND_OPT_DNSSL = 31, /* RFC6106 */ |
Alexander Aring | bbe5f5c | 2016-06-15 21:20:25 +0200 | [diff] [blame] | 40 | ND_OPT_6CO = 34, /* RFC6775 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | __ND_OPT_MAX |
| 42 | }; |
| 43 | |
| 44 | #define MAX_RTR_SOLICITATION_DELAY HZ |
| 45 | |
| 46 | #define ND_REACHABLE_TIME (30*HZ) |
| 47 | #define ND_RETRANS_TIMER HZ |
| 48 | |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 49 | #include <linux/compiler.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #include <linux/icmpv6.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 51 | #include <linux/in6.h> |
| 52 | #include <linux/types.h> |
David S. Miller | 30f2a5f | 2012-07-11 23:26:46 -0700 | [diff] [blame] | 53 | #include <linux/if_arp.h> |
| 54 | #include <linux/netdevice.h> |
Pavel Emelyanov | b14f243 | 2012-08-08 21:52:28 +0000 | [diff] [blame] | 55 | #include <linux/hash.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #include <net/neighbour.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 58 | |
Alexander Aring | cc84b3c | 2016-06-15 21:20:24 +0200 | [diff] [blame] | 59 | /* Set to 3 to get tracing... */ |
| 60 | #define ND_DEBUG 1 |
| 61 | |
| 62 | #define ND_PRINTK(val, level, fmt, ...) \ |
| 63 | do { \ |
| 64 | if (val <= ND_DEBUG) \ |
| 65 | net_##level##_ratelimited(fmt, ##__VA_ARGS__); \ |
| 66 | } while (0) |
| 67 | |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 68 | struct ctl_table; |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 69 | struct inet6_dev; |
| 70 | struct net_device; |
| 71 | struct net_proto_family; |
| 72 | struct sk_buff; |
Alexander Aring | f997c55 | 2016-06-15 21:20:23 +0200 | [diff] [blame] | 73 | struct prefix_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
| 75 | extern struct neigh_table nd_tbl; |
| 76 | |
| 77 | struct nd_msg { |
| 78 | struct icmp6hdr icmph; |
| 79 | struct in6_addr target; |
| 80 | __u8 opt[0]; |
| 81 | }; |
| 82 | |
| 83 | struct rs_msg { |
| 84 | struct icmp6hdr icmph; |
| 85 | __u8 opt[0]; |
| 86 | }; |
| 87 | |
| 88 | struct ra_msg { |
| 89 | struct icmp6hdr icmph; |
Al Viro | e69a4ad | 2006-11-14 20:56:00 -0800 | [diff] [blame] | 90 | __be32 reachable_time; |
| 91 | __be32 retrans_timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
Duan Jiong | 093d04d | 2012-12-14 02:59:59 +0000 | [diff] [blame] | 94 | struct rd_msg { |
| 95 | struct icmp6hdr icmph; |
| 96 | struct in6_addr target; |
| 97 | struct in6_addr dest; |
| 98 | __u8 opt[0]; |
| 99 | }; |
| 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | struct nd_opt_hdr { |
| 102 | __u8 nd_opt_type; |
| 103 | __u8 nd_opt_len; |
Eric Dumazet | bc10502 | 2010-06-03 03:21:52 -0700 | [diff] [blame] | 104 | } __packed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
David S. Miller | 30f2a5f | 2012-07-11 23:26:46 -0700 | [diff] [blame] | 106 | /* ND options */ |
| 107 | struct ndisc_options { |
| 108 | struct nd_opt_hdr *nd_opt_array[__ND_OPT_ARRAY_MAX]; |
| 109 | #ifdef CONFIG_IPV6_ROUTE_INFO |
| 110 | struct nd_opt_hdr *nd_opts_ri; |
| 111 | struct nd_opt_hdr *nd_opts_ri_end; |
| 112 | #endif |
| 113 | struct nd_opt_hdr *nd_useropts; |
| 114 | struct nd_opt_hdr *nd_useropts_end; |
Alexander Aring | bbe5f5c | 2016-06-15 21:20:25 +0200 | [diff] [blame] | 115 | #if IS_ENABLED(CONFIG_IEEE802154_6LOWPAN) |
| 116 | struct nd_opt_hdr *nd_802154_opt_array[ND_OPT_TARGET_LL_ADDR + 1]; |
| 117 | #endif |
David S. Miller | 30f2a5f | 2012-07-11 23:26:46 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
Alexander Aring | bbe5f5c | 2016-06-15 21:20:25 +0200 | [diff] [blame] | 120 | #define nd_opts_src_lladdr nd_opt_array[ND_OPT_SOURCE_LL_ADDR] |
| 121 | #define nd_opts_tgt_lladdr nd_opt_array[ND_OPT_TARGET_LL_ADDR] |
| 122 | #define nd_opts_pi nd_opt_array[ND_OPT_PREFIX_INFO] |
| 123 | #define nd_opts_pi_end nd_opt_array[__ND_OPT_PREFIX_INFO_END] |
| 124 | #define nd_opts_rh nd_opt_array[ND_OPT_REDIRECT_HDR] |
| 125 | #define nd_opts_mtu nd_opt_array[ND_OPT_MTU] |
Erik Nordmark | adc176c | 2016-12-02 14:00:08 -0800 | [diff] [blame] | 126 | #define nd_opts_nonce nd_opt_array[ND_OPT_NONCE] |
Alexander Aring | bbe5f5c | 2016-06-15 21:20:25 +0200 | [diff] [blame] | 127 | #define nd_802154_opts_src_lladdr nd_802154_opt_array[ND_OPT_SOURCE_LL_ADDR] |
| 128 | #define nd_802154_opts_tgt_lladdr nd_802154_opt_array[ND_OPT_TARGET_LL_ADDR] |
David S. Miller | 30f2a5f | 2012-07-11 23:26:46 -0700 | [diff] [blame] | 129 | |
| 130 | #define NDISC_OPT_SPACE(len) (((len)+2+7)&~7) |
| 131 | |
Alexander Aring | f997c55 | 2016-06-15 21:20:23 +0200 | [diff] [blame] | 132 | struct ndisc_options *ndisc_parse_options(const struct net_device *dev, |
| 133 | u8 *opt, int opt_len, |
Joe Perches | 3cc818a | 2013-09-21 10:22:47 -0700 | [diff] [blame] | 134 | struct ndisc_options *ndopts); |
David S. Miller | 30f2a5f | 2012-07-11 23:26:46 -0700 | [diff] [blame] | 135 | |
Alexander Aring | cc84b3c | 2016-06-15 21:20:24 +0200 | [diff] [blame] | 136 | void __ndisc_fill_addr_option(struct sk_buff *skb, int type, void *data, |
| 137 | int data_len, int pad); |
| 138 | |
Alexander Aring | f997c55 | 2016-06-15 21:20:23 +0200 | [diff] [blame] | 139 | #define NDISC_OPS_REDIRECT_DATA_SPACE 2 |
| 140 | |
| 141 | /* |
| 142 | * This structure defines the hooks for IPv6 neighbour discovery. |
| 143 | * The following hooks can be defined; unless noted otherwise, they are |
| 144 | * optional and can be filled with a null pointer. |
| 145 | * |
| 146 | * int (*is_useropt)(u8 nd_opt_type): |
| 147 | * This function is called when IPv6 decide RA userspace options. if |
| 148 | * this function returns 1 then the option given by nd_opt_type will |
| 149 | * be handled as userspace option additional to the IPv6 options. |
| 150 | * |
| 151 | * int (*parse_options)(const struct net_device *dev, |
| 152 | * struct nd_opt_hdr *nd_opt, |
| 153 | * struct ndisc_options *ndopts): |
| 154 | * This function is called while parsing ndisc ops and put each position |
| 155 | * as pointer into ndopts. If this function return unequal 0, then this |
| 156 | * function took care about the ndisc option, if 0 then the IPv6 ndisc |
| 157 | * option parser will take care about that option. |
| 158 | * |
| 159 | * void (*update)(const struct net_device *dev, struct neighbour *n, |
| 160 | * u32 flags, u8 icmp6_type, |
| 161 | * const struct ndisc_options *ndopts): |
| 162 | * This function is called when IPv6 ndisc updates the neighbour cache |
| 163 | * entry. Additional options which can be updated may be previously |
| 164 | * parsed by parse_opts callback and accessible over ndopts parameter. |
| 165 | * |
| 166 | * int (*opt_addr_space)(const struct net_device *dev, u8 icmp6_type, |
| 167 | * struct neighbour *neigh, u8 *ha_buf, |
| 168 | * u8 **ha): |
| 169 | * This function is called when the necessary option space will be |
| 170 | * calculated before allocating a skb. The parameters neigh, ha_buf |
| 171 | * abd ha are available on NDISC_REDIRECT messages only. |
| 172 | * |
| 173 | * void (*fill_addr_option)(const struct net_device *dev, |
| 174 | * struct sk_buff *skb, u8 icmp6_type, |
| 175 | * const u8 *ha): |
| 176 | * This function is called when the skb will finally fill the option |
| 177 | * fields inside skb. NOTE: this callback should fill the option |
| 178 | * fields to the skb which are previously indicated by opt_space |
| 179 | * parameter. That means the decision to add such option should |
| 180 | * not lost between these two callbacks, e.g. protected by interface |
| 181 | * up state. |
| 182 | * |
| 183 | * void (*prefix_rcv_add_addr)(struct net *net, struct net_device *dev, |
| 184 | * const struct prefix_info *pinfo, |
| 185 | * struct inet6_dev *in6_dev, |
| 186 | * struct in6_addr *addr, |
| 187 | * int addr_type, u32 addr_flags, |
| 188 | * bool sllao, bool tokenized, |
| 189 | * __u32 valid_lft, u32 prefered_lft, |
| 190 | * bool dev_addr_generated): |
| 191 | * This function is called when a RA messages is received with valid |
| 192 | * PIO option fields and an IPv6 address will be added to the interface |
| 193 | * for autoconfiguration. The parameter dev_addr_generated reports about |
| 194 | * if the address was based on dev->dev_addr or not. This can be used |
| 195 | * to add a second address if link-layer operates with two link layer |
| 196 | * addresses. E.g. 802.15.4 6LoWPAN. |
| 197 | */ |
| 198 | struct ndisc_ops { |
| 199 | int (*is_useropt)(u8 nd_opt_type); |
| 200 | int (*parse_options)(const struct net_device *dev, |
| 201 | struct nd_opt_hdr *nd_opt, |
| 202 | struct ndisc_options *ndopts); |
| 203 | void (*update)(const struct net_device *dev, struct neighbour *n, |
| 204 | u32 flags, u8 icmp6_type, |
| 205 | const struct ndisc_options *ndopts); |
| 206 | int (*opt_addr_space)(const struct net_device *dev, u8 icmp6_type, |
| 207 | struct neighbour *neigh, u8 *ha_buf, |
| 208 | u8 **ha); |
| 209 | void (*fill_addr_option)(const struct net_device *dev, |
| 210 | struct sk_buff *skb, u8 icmp6_type, |
| 211 | const u8 *ha); |
| 212 | void (*prefix_rcv_add_addr)(struct net *net, struct net_device *dev, |
| 213 | const struct prefix_info *pinfo, |
| 214 | struct inet6_dev *in6_dev, |
| 215 | struct in6_addr *addr, |
| 216 | int addr_type, u32 addr_flags, |
| 217 | bool sllao, bool tokenized, |
| 218 | __u32 valid_lft, u32 prefered_lft, |
| 219 | bool dev_addr_generated); |
| 220 | }; |
| 221 | |
| 222 | #if IS_ENABLED(CONFIG_IPV6) |
| 223 | static inline int ndisc_ops_is_useropt(const struct net_device *dev, |
| 224 | u8 nd_opt_type) |
| 225 | { |
| 226 | if (dev->ndisc_ops && dev->ndisc_ops->is_useropt) |
| 227 | return dev->ndisc_ops->is_useropt(nd_opt_type); |
| 228 | else |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | static inline int ndisc_ops_parse_options(const struct net_device *dev, |
| 233 | struct nd_opt_hdr *nd_opt, |
| 234 | struct ndisc_options *ndopts) |
| 235 | { |
| 236 | if (dev->ndisc_ops && dev->ndisc_ops->parse_options) |
| 237 | return dev->ndisc_ops->parse_options(dev, nd_opt, ndopts); |
| 238 | else |
| 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | static inline void ndisc_ops_update(const struct net_device *dev, |
| 243 | struct neighbour *n, u32 flags, |
| 244 | u8 icmp6_type, |
| 245 | const struct ndisc_options *ndopts) |
| 246 | { |
| 247 | if (dev->ndisc_ops && dev->ndisc_ops->update) |
| 248 | dev->ndisc_ops->update(dev, n, flags, icmp6_type, ndopts); |
| 249 | } |
| 250 | |
| 251 | static inline int ndisc_ops_opt_addr_space(const struct net_device *dev, |
| 252 | u8 icmp6_type) |
| 253 | { |
| 254 | if (dev->ndisc_ops && dev->ndisc_ops->opt_addr_space && |
| 255 | icmp6_type != NDISC_REDIRECT) |
| 256 | return dev->ndisc_ops->opt_addr_space(dev, icmp6_type, NULL, |
| 257 | NULL, NULL); |
| 258 | else |
| 259 | return 0; |
| 260 | } |
| 261 | |
| 262 | static inline int ndisc_ops_redirect_opt_addr_space(const struct net_device *dev, |
| 263 | struct neighbour *neigh, |
| 264 | u8 *ha_buf, u8 **ha) |
| 265 | { |
| 266 | if (dev->ndisc_ops && dev->ndisc_ops->opt_addr_space) |
| 267 | return dev->ndisc_ops->opt_addr_space(dev, NDISC_REDIRECT, |
| 268 | neigh, ha_buf, ha); |
| 269 | else |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | static inline void ndisc_ops_fill_addr_option(const struct net_device *dev, |
| 274 | struct sk_buff *skb, |
| 275 | u8 icmp6_type) |
| 276 | { |
| 277 | if (dev->ndisc_ops && dev->ndisc_ops->fill_addr_option && |
| 278 | icmp6_type != NDISC_REDIRECT) |
| 279 | dev->ndisc_ops->fill_addr_option(dev, skb, icmp6_type, NULL); |
| 280 | } |
| 281 | |
| 282 | static inline void ndisc_ops_fill_redirect_addr_option(const struct net_device *dev, |
| 283 | struct sk_buff *skb, |
| 284 | const u8 *ha) |
| 285 | { |
| 286 | if (dev->ndisc_ops && dev->ndisc_ops->fill_addr_option) |
| 287 | dev->ndisc_ops->fill_addr_option(dev, skb, NDISC_REDIRECT, ha); |
| 288 | } |
| 289 | |
| 290 | static inline void ndisc_ops_prefix_rcv_add_addr(struct net *net, |
| 291 | struct net_device *dev, |
| 292 | const struct prefix_info *pinfo, |
| 293 | struct inet6_dev *in6_dev, |
| 294 | struct in6_addr *addr, |
| 295 | int addr_type, u32 addr_flags, |
| 296 | bool sllao, bool tokenized, |
| 297 | __u32 valid_lft, |
| 298 | u32 prefered_lft, |
| 299 | bool dev_addr_generated) |
| 300 | { |
| 301 | if (dev->ndisc_ops && dev->ndisc_ops->prefix_rcv_add_addr) |
| 302 | dev->ndisc_ops->prefix_rcv_add_addr(net, dev, pinfo, in6_dev, |
| 303 | addr, addr_type, |
| 304 | addr_flags, sllao, |
| 305 | tokenized, valid_lft, |
| 306 | prefered_lft, |
| 307 | dev_addr_generated); |
| 308 | } |
| 309 | #endif |
| 310 | |
David S. Miller | 30f2a5f | 2012-07-11 23:26:46 -0700 | [diff] [blame] | 311 | /* |
| 312 | * Return the padding between the option length and the start of the |
| 313 | * link addr. Currently only IP-over-InfiniBand needs this, although |
| 314 | * if RFC 3831 IPv6-over-Fibre Channel is ever implemented it may |
| 315 | * also need a pad of 2. |
| 316 | */ |
Joe Perches | d9d10a3 | 2013-07-30 10:31:00 -0700 | [diff] [blame] | 317 | static inline int ndisc_addr_option_pad(unsigned short type) |
David S. Miller | 30f2a5f | 2012-07-11 23:26:46 -0700 | [diff] [blame] | 318 | { |
| 319 | switch (type) { |
| 320 | case ARPHRD_INFINIBAND: return 2; |
| 321 | default: return 0; |
| 322 | } |
| 323 | } |
| 324 | |
Alexander Aring | 1e82f96 | 2016-06-15 21:20:19 +0200 | [diff] [blame] | 325 | static inline int __ndisc_opt_addr_space(unsigned char addr_len, int pad) |
| 326 | { |
| 327 | return NDISC_OPT_SPACE(addr_len + pad); |
| 328 | } |
| 329 | |
Alexander Aring | f997c55 | 2016-06-15 21:20:23 +0200 | [diff] [blame] | 330 | #if IS_ENABLED(CONFIG_IPV6) |
| 331 | static inline int ndisc_opt_addr_space(struct net_device *dev, u8 icmp6_type) |
YOSHIFUJI Hideaki / 吉藤英明 | c558e9f | 2013-01-21 06:47:56 +0000 | [diff] [blame] | 332 | { |
Alexander Aring | 1e82f96 | 2016-06-15 21:20:19 +0200 | [diff] [blame] | 333 | return __ndisc_opt_addr_space(dev->addr_len, |
Alexander Aring | f997c55 | 2016-06-15 21:20:23 +0200 | [diff] [blame] | 334 | ndisc_addr_option_pad(dev->type)) + |
| 335 | ndisc_ops_opt_addr_space(dev, icmp6_type); |
YOSHIFUJI Hideaki / 吉藤英明 | c558e9f | 2013-01-21 06:47:56 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Alexander Aring | f997c55 | 2016-06-15 21:20:23 +0200 | [diff] [blame] | 338 | static inline int ndisc_redirect_opt_addr_space(struct net_device *dev, |
| 339 | struct neighbour *neigh, |
| 340 | u8 *ops_data_buf, |
| 341 | u8 **ops_data) |
| 342 | { |
| 343 | return __ndisc_opt_addr_space(dev->addr_len, |
| 344 | ndisc_addr_option_pad(dev->type)) + |
| 345 | ndisc_ops_redirect_opt_addr_space(dev, neigh, ops_data_buf, |
| 346 | ops_data); |
| 347 | } |
| 348 | #endif |
| 349 | |
Alexander Aring | 4f36ce8 | 2016-06-15 21:20:20 +0200 | [diff] [blame] | 350 | static inline u8 *__ndisc_opt_addr_data(struct nd_opt_hdr *p, |
| 351 | unsigned char addr_len, int prepad) |
David S. Miller | 30f2a5f | 2012-07-11 23:26:46 -0700 | [diff] [blame] | 352 | { |
| 353 | u8 *lladdr = (u8 *)(p + 1); |
| 354 | int lladdrlen = p->nd_opt_len << 3; |
Alexander Aring | 4f36ce8 | 2016-06-15 21:20:20 +0200 | [diff] [blame] | 355 | if (lladdrlen != __ndisc_opt_addr_space(addr_len, prepad)) |
David S. Miller | 30f2a5f | 2012-07-11 23:26:46 -0700 | [diff] [blame] | 356 | return NULL; |
| 357 | return lladdr + prepad; |
| 358 | } |
| 359 | |
Alexander Aring | 4f36ce8 | 2016-06-15 21:20:20 +0200 | [diff] [blame] | 360 | static inline u8 *ndisc_opt_addr_data(struct nd_opt_hdr *p, |
| 361 | struct net_device *dev) |
| 362 | { |
| 363 | return __ndisc_opt_addr_data(p, dev->addr_len, |
| 364 | ndisc_addr_option_pad(dev->type)); |
| 365 | } |
| 366 | |
David S. Miller | 2c2aba6 | 2011-12-28 15:06:58 -0500 | [diff] [blame] | 367 | static inline u32 ndisc_hashfn(const void *pkey, const struct net_device *dev, __u32 *hash_rnd) |
| 368 | { |
| 369 | const u32 *p32 = pkey; |
| 370 | |
Pavel Emelyanov | b14f243 | 2012-08-08 21:52:28 +0000 | [diff] [blame] | 371 | return (((p32[0] ^ hash32_ptr(dev)) * hash_rnd[0]) + |
David S. Miller | 2c2aba6 | 2011-12-28 15:06:58 -0500 | [diff] [blame] | 372 | (p32[1] * hash_rnd[1]) + |
| 373 | (p32[2] * hash_rnd[2]) + |
| 374 | (p32[3] * hash_rnd[3])); |
| 375 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
YOSHIFUJI Hideaki / 吉藤英明 | ac3175f | 2013-01-17 12:53:22 +0000 | [diff] [blame] | 377 | static inline struct neighbour *__ipv6_neigh_lookup_noref(struct net_device *dev, const void *pkey) |
David S. Miller | f83c779 | 2011-12-28 15:41:23 -0500 | [diff] [blame] | 378 | { |
Eric W. Biederman | 60395a2 | 2015-03-03 17:10:44 -0600 | [diff] [blame] | 379 | return ___neigh_lookup_noref(&nd_tbl, neigh_key_eq128, ndisc_hashfn, pkey, dev); |
YOSHIFUJI Hideaki / 吉藤英明 | ac3175f | 2013-01-17 12:53:22 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | static inline struct neighbour *__ipv6_neigh_lookup(struct net_device *dev, const void *pkey) |
| 383 | { |
| 384 | struct neighbour *n; |
| 385 | |
| 386 | rcu_read_lock_bh(); |
| 387 | n = __ipv6_neigh_lookup_noref(dev, pkey); |
Reshetova, Elena | 9f23743 | 2017-06-30 13:07:55 +0300 | [diff] [blame] | 388 | if (n && !refcount_inc_not_zero(&n->refcnt)) |
YOSHIFUJI Hideaki / 吉藤英明 | ac3175f | 2013-01-17 12:53:22 +0000 | [diff] [blame] | 389 | n = NULL; |
David S. Miller | f83c779 | 2011-12-28 15:41:23 -0500 | [diff] [blame] | 390 | rcu_read_unlock_bh(); |
| 391 | |
| 392 | return n; |
| 393 | } |
| 394 | |
Julian Anastasov | 63fca65 | 2017-02-06 23:14:15 +0200 | [diff] [blame] | 395 | static inline void __ipv6_confirm_neigh(struct net_device *dev, |
| 396 | const void *pkey) |
| 397 | { |
| 398 | struct neighbour *n; |
| 399 | |
| 400 | rcu_read_lock_bh(); |
| 401 | n = __ipv6_neigh_lookup_noref(dev, pkey); |
| 402 | if (n) { |
| 403 | unsigned long now = jiffies; |
| 404 | |
| 405 | /* avoid dirtying neighbour */ |
| 406 | if (n->confirmed != now) |
| 407 | n->confirmed = now; |
| 408 | } |
| 409 | rcu_read_unlock_bh(); |
| 410 | } |
| 411 | |
Joe Perches | 3cc818a | 2013-09-21 10:22:47 -0700 | [diff] [blame] | 412 | int ndisc_init(void); |
| 413 | int ndisc_late_init(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Joe Perches | 3cc818a | 2013-09-21 10:22:47 -0700 | [diff] [blame] | 415 | void ndisc_late_cleanup(void); |
| 416 | void ndisc_cleanup(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
Joe Perches | 3cc818a | 2013-09-21 10:22:47 -0700 | [diff] [blame] | 418 | int ndisc_rcv(struct sk_buff *skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
Jiri Benc | 38cf595 | 2015-09-22 18:57:13 +0200 | [diff] [blame] | 420 | void ndisc_send_ns(struct net_device *dev, const struct in6_addr *solicit, |
Erik Nordmark | adc176c | 2016-12-02 14:00:08 -0800 | [diff] [blame] | 421 | const struct in6_addr *daddr, const struct in6_addr *saddr, |
| 422 | u64 nonce); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
Joe Perches | 3cc818a | 2013-09-21 10:22:47 -0700 | [diff] [blame] | 424 | void ndisc_send_rs(struct net_device *dev, |
| 425 | const struct in6_addr *saddr, const struct in6_addr *daddr); |
Jiri Benc | 38cf595 | 2015-09-22 18:57:13 +0200 | [diff] [blame] | 426 | void ndisc_send_na(struct net_device *dev, const struct in6_addr *daddr, |
Joe Perches | 3cc818a | 2013-09-21 10:22:47 -0700 | [diff] [blame] | 427 | const struct in6_addr *solicited_addr, |
| 428 | bool router, bool solicited, bool override, bool inc_opt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
Joe Perches | 3cc818a | 2013-09-21 10:22:47 -0700 | [diff] [blame] | 430 | void ndisc_send_redirect(struct sk_buff *skb, const struct in6_addr *target); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
Joe Perches | 3cc818a | 2013-09-21 10:22:47 -0700 | [diff] [blame] | 432 | int ndisc_mc_map(const struct in6_addr *addr, char *buf, struct net_device *dev, |
| 433 | int dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
Alexander Aring | f997c55 | 2016-06-15 21:20:23 +0200 | [diff] [blame] | 435 | void ndisc_update(const struct net_device *dev, struct neighbour *neigh, |
| 436 | const u8 *lladdr, u8 new, u32 flags, u8 icmp6_type, |
| 437 | struct ndisc_options *ndopts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
| 439 | /* |
| 440 | * IGMP |
| 441 | */ |
Joe Perches | 3cc818a | 2013-09-21 10:22:47 -0700 | [diff] [blame] | 442 | int igmp6_init(void); |
Vlad Yasevich | 382ed72 | 2017-03-28 14:49:16 -0400 | [diff] [blame] | 443 | int igmp6_late_init(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
Joe Perches | 3cc818a | 2013-09-21 10:22:47 -0700 | [diff] [blame] | 445 | void igmp6_cleanup(void); |
Vlad Yasevich | 382ed72 | 2017-03-28 14:49:16 -0400 | [diff] [blame] | 446 | void igmp6_late_cleanup(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
Joe Perches | 3cc818a | 2013-09-21 10:22:47 -0700 | [diff] [blame] | 448 | int igmp6_event_query(struct sk_buff *skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
Joe Perches | 3cc818a | 2013-09-21 10:22:47 -0700 | [diff] [blame] | 450 | int igmp6_event_report(struct sk_buff *skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
| 453 | #ifdef CONFIG_SYSCTL |
Joe Perches | 3cc818a | 2013-09-21 10:22:47 -0700 | [diff] [blame] | 454 | int ndisc_ifinfo_sysctl_change(struct ctl_table *ctl, int write, |
| 455 | void __user *buffer, size_t *lenp, loff_t *ppos); |
Joe Perches | fedaf4f | 2013-06-13 19:37:54 -0700 | [diff] [blame] | 456 | int ndisc_ifinfo_sysctl_strategy(struct ctl_table *ctl, |
Alexey Dobriyan | f221e72 | 2008-10-15 22:04:23 -0700 | [diff] [blame] | 457 | void __user *oldval, size_t __user *oldlenp, |
YOSHIFUJI Hideaki | 0686caa | 2008-05-19 16:25:42 -0700 | [diff] [blame] | 458 | void __user *newval, size_t newlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | #endif |
| 460 | |
Joe Perches | 3cc818a | 2013-09-21 10:22:47 -0700 | [diff] [blame] | 461 | void inet6_ifinfo_notify(int event, struct inet6_dev *idev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | #endif |