xref: /openbmc/linux/include/net/ndisc.h (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds #ifndef _NDISC_H
31da177e4SLinus Torvalds #define _NDISC_H
41da177e4SLinus Torvalds 
571df5777SDavid Ahern #include <net/ipv6_stubs.h>
671df5777SDavid Ahern 
71da177e4SLinus Torvalds /*
81da177e4SLinus Torvalds  *	ICMP codes for neighbour discovery messages
91da177e4SLinus Torvalds  */
101da177e4SLinus Torvalds 
111da177e4SLinus Torvalds #define NDISC_ROUTER_SOLICITATION	133
121da177e4SLinus Torvalds #define NDISC_ROUTER_ADVERTISEMENT	134
131da177e4SLinus Torvalds #define NDISC_NEIGHBOUR_SOLICITATION	135
141da177e4SLinus Torvalds #define NDISC_NEIGHBOUR_ADVERTISEMENT	136
151da177e4SLinus Torvalds #define NDISC_REDIRECT			137
161da177e4SLinus Torvalds 
171da177e4SLinus Torvalds /*
18fadf6bf0STemplin, Fred L  * Router type: cross-layer information from link-layer to
19fadf6bf0STemplin, Fred L  * IPv6 layer reported by certain link types (e.g., RFC4214).
20fadf6bf0STemplin, Fred L  */
21fadf6bf0STemplin, Fred L #define NDISC_NODETYPE_UNSPEC		0	/* unspecified (default) */
22fadf6bf0STemplin, Fred L #define NDISC_NODETYPE_HOST		1	/* host or unauthorized router */
23fadf6bf0STemplin, Fred L #define NDISC_NODETYPE_NODEFAULT	2	/* non-default router */
24fadf6bf0STemplin, Fred L #define NDISC_NODETYPE_DEFAULT		3	/* default router */
25fadf6bf0STemplin, Fred L 
26fadf6bf0STemplin, Fred L /*
271da177e4SLinus Torvalds  *	ndisc options
281da177e4SLinus Torvalds  */
291da177e4SLinus Torvalds 
301da177e4SLinus Torvalds enum {
311da177e4SLinus Torvalds 	__ND_OPT_PREFIX_INFO_END = 0,
321da177e4SLinus Torvalds 	ND_OPT_SOURCE_LL_ADDR = 1,	/* RFC2461 */
331da177e4SLinus Torvalds 	ND_OPT_TARGET_LL_ADDR = 2,	/* RFC2461 */
341da177e4SLinus Torvalds 	ND_OPT_PREFIX_INFO = 3,		/* RFC2461 */
351da177e4SLinus Torvalds 	ND_OPT_REDIRECT_HDR = 4,	/* RFC2461 */
361da177e4SLinus Torvalds 	ND_OPT_MTU = 5,			/* RFC2461 */
37adc176c5SErik Nordmark 	ND_OPT_NONCE = 14,              /* RFC7527 */
3870ceb4f5SYOSHIFUJI Hideaki 	__ND_OPT_ARRAY_MAX,
3970ceb4f5SYOSHIFUJI Hideaki 	ND_OPT_ROUTE_INFO = 24,		/* RFC4191 */
4031910575SPierre Ynard 	ND_OPT_RDNSS = 25,		/* RFC5006 */
41e35f30c1SAlexey I. Froloff 	ND_OPT_DNSSL = 31,		/* RFC6106 */
42bbe5f5ceSAlexander Aring 	ND_OPT_6CO = 34,		/* RFC6775 */
4366b5f1c4SMaciej Żenczykowski 	ND_OPT_CAPTIVE_PORTAL = 37,	/* RFC7710 */
449175d3f3SMaciej Żenczykowski 	ND_OPT_PREF64 = 38,		/* RFC8781 */
451da177e4SLinus Torvalds 	__ND_OPT_MAX
461da177e4SLinus Torvalds };
471da177e4SLinus Torvalds 
481da177e4SLinus Torvalds #define MAX_RTR_SOLICITATION_DELAY	HZ
491da177e4SLinus Torvalds 
501da177e4SLinus Torvalds #define ND_REACHABLE_TIME		(30*HZ)
511da177e4SLinus Torvalds #define ND_RETRANS_TIMER		HZ
521da177e4SLinus Torvalds 
5314c85021SArnaldo Carvalho de Melo #include <linux/compiler.h>
541da177e4SLinus Torvalds #include <linux/icmpv6.h>
5514c85021SArnaldo Carvalho de Melo #include <linux/in6.h>
5614c85021SArnaldo Carvalho de Melo #include <linux/types.h>
5730f2a5f3SDavid S. Miller #include <linux/if_arp.h>
5830f2a5f3SDavid S. Miller #include <linux/netdevice.h>
59b14f243aSPavel Emelyanov #include <linux/hash.h>
6014c85021SArnaldo Carvalho de Melo 
611da177e4SLinus Torvalds #include <net/neighbour.h>
6214c85021SArnaldo Carvalho de Melo 
63cc84b3c6SAlexander Aring /* Set to 3 to get tracing... */
64cc84b3c6SAlexander Aring #define ND_DEBUG 1
65cc84b3c6SAlexander Aring 
66cc84b3c6SAlexander Aring #define ND_PRINTK(val, level, fmt, ...)				\
67cc84b3c6SAlexander Aring do {								\
68cc84b3c6SAlexander Aring 	if (val <= ND_DEBUG)					\
69cc84b3c6SAlexander Aring 		net_##level##_ratelimited(fmt, ##__VA_ARGS__);	\
70cc84b3c6SAlexander Aring } while (0)
71cc84b3c6SAlexander Aring 
7214c85021SArnaldo Carvalho de Melo struct ctl_table;
7314c85021SArnaldo Carvalho de Melo struct inet6_dev;
7414c85021SArnaldo Carvalho de Melo struct net_device;
7514c85021SArnaldo Carvalho de Melo struct net_proto_family;
7614c85021SArnaldo Carvalho de Melo struct sk_buff;
77f997c55cSAlexander Aring struct prefix_info;
781da177e4SLinus Torvalds 
791da177e4SLinus Torvalds extern struct neigh_table nd_tbl;
801da177e4SLinus Torvalds 
811da177e4SLinus Torvalds struct nd_msg {
821da177e4SLinus Torvalds         struct icmp6hdr	icmph;
831da177e4SLinus Torvalds         struct in6_addr	target;
8453e76f48SGustavo A. R. Silva 	__u8		opt[];
851da177e4SLinus Torvalds };
861da177e4SLinus Torvalds 
871da177e4SLinus Torvalds struct rs_msg {
881da177e4SLinus Torvalds 	struct icmp6hdr	icmph;
8953e76f48SGustavo A. R. Silva 	__u8		opt[];
901da177e4SLinus Torvalds };
911da177e4SLinus Torvalds 
921da177e4SLinus Torvalds struct ra_msg {
931da177e4SLinus Torvalds         struct icmp6hdr		icmph;
94e69a4adcSAl Viro 	__be32			reachable_time;
95e69a4adcSAl Viro 	__be32			retrans_timer;
961da177e4SLinus Torvalds };
971da177e4SLinus Torvalds 
98093d04d4SDuan Jiong struct rd_msg {
99093d04d4SDuan Jiong 	struct icmp6hdr icmph;
100093d04d4SDuan Jiong 	struct in6_addr	target;
101093d04d4SDuan Jiong 	struct in6_addr	dest;
10253e76f48SGustavo A. R. Silva 	__u8		opt[];
103093d04d4SDuan Jiong };
104093d04d4SDuan Jiong 
1051da177e4SLinus Torvalds struct nd_opt_hdr {
1061da177e4SLinus Torvalds 	__u8		nd_opt_type;
1071da177e4SLinus Torvalds 	__u8		nd_opt_len;
108bc10502dSEric Dumazet } __packed;
1091da177e4SLinus Torvalds 
11030f2a5f3SDavid S. Miller /* ND options */
11130f2a5f3SDavid S. Miller struct ndisc_options {
11230f2a5f3SDavid S. Miller 	struct nd_opt_hdr *nd_opt_array[__ND_OPT_ARRAY_MAX];
11330f2a5f3SDavid S. Miller #ifdef CONFIG_IPV6_ROUTE_INFO
11430f2a5f3SDavid S. Miller 	struct nd_opt_hdr *nd_opts_ri;
11530f2a5f3SDavid S. Miller 	struct nd_opt_hdr *nd_opts_ri_end;
11630f2a5f3SDavid S. Miller #endif
11730f2a5f3SDavid S. Miller 	struct nd_opt_hdr *nd_useropts;
11830f2a5f3SDavid S. Miller 	struct nd_opt_hdr *nd_useropts_end;
119bbe5f5ceSAlexander Aring #if IS_ENABLED(CONFIG_IEEE802154_6LOWPAN)
120bbe5f5ceSAlexander Aring 	struct nd_opt_hdr *nd_802154_opt_array[ND_OPT_TARGET_LL_ADDR + 1];
121bbe5f5ceSAlexander Aring #endif
12230f2a5f3SDavid S. Miller };
12330f2a5f3SDavid S. Miller 
12430f2a5f3SDavid S. Miller #define nd_opts_src_lladdr		nd_opt_array[ND_OPT_SOURCE_LL_ADDR]
12530f2a5f3SDavid S. Miller #define nd_opts_tgt_lladdr		nd_opt_array[ND_OPT_TARGET_LL_ADDR]
12630f2a5f3SDavid S. Miller #define nd_opts_pi			nd_opt_array[ND_OPT_PREFIX_INFO]
12730f2a5f3SDavid S. Miller #define nd_opts_pi_end			nd_opt_array[__ND_OPT_PREFIX_INFO_END]
12830f2a5f3SDavid S. Miller #define nd_opts_rh			nd_opt_array[ND_OPT_REDIRECT_HDR]
12930f2a5f3SDavid S. Miller #define nd_opts_mtu			nd_opt_array[ND_OPT_MTU]
130adc176c5SErik Nordmark #define nd_opts_nonce			nd_opt_array[ND_OPT_NONCE]
131bbe5f5ceSAlexander Aring #define nd_802154_opts_src_lladdr	nd_802154_opt_array[ND_OPT_SOURCE_LL_ADDR]
132bbe5f5ceSAlexander Aring #define nd_802154_opts_tgt_lladdr	nd_802154_opt_array[ND_OPT_TARGET_LL_ADDR]
13330f2a5f3SDavid S. Miller 
13430f2a5f3SDavid S. Miller #define NDISC_OPT_SPACE(len) (((len)+2+7)&~7)
13530f2a5f3SDavid S. Miller 
136f997c55cSAlexander Aring struct ndisc_options *ndisc_parse_options(const struct net_device *dev,
137f997c55cSAlexander Aring 					  u8 *opt, int opt_len,
13830f2a5f3SDavid S. Miller 					  struct ndisc_options *ndopts);
13930f2a5f3SDavid S. Miller 
1401a8a23d2SJakub Kicinski void __ndisc_fill_addr_option(struct sk_buff *skb, int type, const void *data,
141cc84b3c6SAlexander Aring 			      int data_len, int pad);
142cc84b3c6SAlexander Aring 
143f997c55cSAlexander Aring #define NDISC_OPS_REDIRECT_DATA_SPACE	2
144f997c55cSAlexander Aring 
145f997c55cSAlexander Aring /*
146f997c55cSAlexander Aring  * This structure defines the hooks for IPv6 neighbour discovery.
147f997c55cSAlexander Aring  * The following hooks can be defined; unless noted otherwise, they are
148f997c55cSAlexander Aring  * optional and can be filled with a null pointer.
149f997c55cSAlexander Aring  *
150f997c55cSAlexander Aring  * int (*is_useropt)(u8 nd_opt_type):
151f997c55cSAlexander Aring  *     This function is called when IPv6 decide RA userspace options. if
152f997c55cSAlexander Aring  *     this function returns 1 then the option given by nd_opt_type will
153f997c55cSAlexander Aring  *     be handled as userspace option additional to the IPv6 options.
154f997c55cSAlexander Aring  *
155f997c55cSAlexander Aring  * int (*parse_options)(const struct net_device *dev,
156f997c55cSAlexander Aring  *			struct nd_opt_hdr *nd_opt,
157f997c55cSAlexander Aring  *			struct ndisc_options *ndopts):
158f997c55cSAlexander Aring  *     This function is called while parsing ndisc ops and put each position
159f997c55cSAlexander Aring  *     as pointer into ndopts. If this function return unequal 0, then this
160f997c55cSAlexander Aring  *     function took care about the ndisc option, if 0 then the IPv6 ndisc
161f997c55cSAlexander Aring  *     option parser will take care about that option.
162f997c55cSAlexander Aring  *
163f997c55cSAlexander Aring  * void (*update)(const struct net_device *dev, struct neighbour *n,
164f997c55cSAlexander Aring  *		  u32 flags, u8 icmp6_type,
165f997c55cSAlexander Aring  *		  const struct ndisc_options *ndopts):
166f997c55cSAlexander Aring  *     This function is called when IPv6 ndisc updates the neighbour cache
167f997c55cSAlexander Aring  *     entry. Additional options which can be updated may be previously
168f997c55cSAlexander Aring  *     parsed by parse_opts callback and accessible over ndopts parameter.
169f997c55cSAlexander Aring  *
170f997c55cSAlexander Aring  * int (*opt_addr_space)(const struct net_device *dev, u8 icmp6_type,
171f997c55cSAlexander Aring  *			 struct neighbour *neigh, u8 *ha_buf,
172f997c55cSAlexander Aring  *			 u8 **ha):
173f997c55cSAlexander Aring  *     This function is called when the necessary option space will be
174f997c55cSAlexander Aring  *     calculated before allocating a skb. The parameters neigh, ha_buf
175f997c55cSAlexander Aring  *     abd ha are available on NDISC_REDIRECT messages only.
176f997c55cSAlexander Aring  *
177f997c55cSAlexander Aring  * void (*fill_addr_option)(const struct net_device *dev,
178f997c55cSAlexander Aring  *			    struct sk_buff *skb, u8 icmp6_type,
179f997c55cSAlexander Aring  *			    const u8 *ha):
180f997c55cSAlexander Aring  *     This function is called when the skb will finally fill the option
181f997c55cSAlexander Aring  *     fields inside skb. NOTE: this callback should fill the option
182f997c55cSAlexander Aring  *     fields to the skb which are previously indicated by opt_space
183f997c55cSAlexander Aring  *     parameter. That means the decision to add such option should
184f997c55cSAlexander Aring  *     not lost between these two callbacks, e.g. protected by interface
185f997c55cSAlexander Aring  *     up state.
186f997c55cSAlexander Aring  *
187f997c55cSAlexander Aring  * void (*prefix_rcv_add_addr)(struct net *net, struct net_device *dev,
188f997c55cSAlexander Aring  *			       const struct prefix_info *pinfo,
189f997c55cSAlexander Aring  *			       struct inet6_dev *in6_dev,
190f997c55cSAlexander Aring  *			       struct in6_addr *addr,
191f997c55cSAlexander Aring  *			       int addr_type, u32 addr_flags,
192f997c55cSAlexander Aring  *			       bool sllao, bool tokenized,
193f997c55cSAlexander Aring  *			       __u32 valid_lft, u32 prefered_lft,
194f997c55cSAlexander Aring  *			       bool dev_addr_generated):
195f997c55cSAlexander Aring  *     This function is called when a RA messages is received with valid
196f997c55cSAlexander Aring  *     PIO option fields and an IPv6 address will be added to the interface
197f997c55cSAlexander Aring  *     for autoconfiguration. The parameter dev_addr_generated reports about
198f997c55cSAlexander Aring  *     if the address was based on dev->dev_addr or not. This can be used
199f997c55cSAlexander Aring  *     to add a second address if link-layer operates with two link layer
200f997c55cSAlexander Aring  *     addresses. E.g. 802.15.4 6LoWPAN.
201f997c55cSAlexander Aring  */
202f997c55cSAlexander Aring struct ndisc_ops {
203f997c55cSAlexander Aring 	int	(*is_useropt)(u8 nd_opt_type);
204f997c55cSAlexander Aring 	int	(*parse_options)(const struct net_device *dev,
205f997c55cSAlexander Aring 				 struct nd_opt_hdr *nd_opt,
206f997c55cSAlexander Aring 				 struct ndisc_options *ndopts);
207f997c55cSAlexander Aring 	void	(*update)(const struct net_device *dev, struct neighbour *n,
208f997c55cSAlexander Aring 			  u32 flags, u8 icmp6_type,
209f997c55cSAlexander Aring 			  const struct ndisc_options *ndopts);
210f997c55cSAlexander Aring 	int	(*opt_addr_space)(const struct net_device *dev, u8 icmp6_type,
211f997c55cSAlexander Aring 				  struct neighbour *neigh, u8 *ha_buf,
212f997c55cSAlexander Aring 				  u8 **ha);
213f997c55cSAlexander Aring 	void	(*fill_addr_option)(const struct net_device *dev,
214f997c55cSAlexander Aring 				    struct sk_buff *skb, u8 icmp6_type,
215f997c55cSAlexander Aring 				    const u8 *ha);
216f997c55cSAlexander Aring 	void	(*prefix_rcv_add_addr)(struct net *net, struct net_device *dev,
217f997c55cSAlexander Aring 				       const struct prefix_info *pinfo,
218f997c55cSAlexander Aring 				       struct inet6_dev *in6_dev,
219f997c55cSAlexander Aring 				       struct in6_addr *addr,
220f997c55cSAlexander Aring 				       int addr_type, u32 addr_flags,
221f997c55cSAlexander Aring 				       bool sllao, bool tokenized,
222f997c55cSAlexander Aring 				       __u32 valid_lft, u32 prefered_lft,
223f997c55cSAlexander Aring 				       bool dev_addr_generated);
224f997c55cSAlexander Aring };
225f997c55cSAlexander Aring 
226f997c55cSAlexander Aring #if IS_ENABLED(CONFIG_IPV6)
ndisc_ops_is_useropt(const struct net_device * dev,u8 nd_opt_type)227f997c55cSAlexander Aring static inline int ndisc_ops_is_useropt(const struct net_device *dev,
228f997c55cSAlexander Aring 				       u8 nd_opt_type)
229f997c55cSAlexander Aring {
230f997c55cSAlexander Aring 	if (dev->ndisc_ops && dev->ndisc_ops->is_useropt)
231f997c55cSAlexander Aring 		return dev->ndisc_ops->is_useropt(nd_opt_type);
232f997c55cSAlexander Aring 	else
233f997c55cSAlexander Aring 		return 0;
234f997c55cSAlexander Aring }
235f997c55cSAlexander Aring 
ndisc_ops_parse_options(const struct net_device * dev,struct nd_opt_hdr * nd_opt,struct ndisc_options * ndopts)236f997c55cSAlexander Aring static inline int ndisc_ops_parse_options(const struct net_device *dev,
237f997c55cSAlexander Aring 					  struct nd_opt_hdr *nd_opt,
238f997c55cSAlexander Aring 					  struct ndisc_options *ndopts)
239f997c55cSAlexander Aring {
240f997c55cSAlexander Aring 	if (dev->ndisc_ops && dev->ndisc_ops->parse_options)
241f997c55cSAlexander Aring 		return dev->ndisc_ops->parse_options(dev, nd_opt, ndopts);
242f997c55cSAlexander Aring 	else
243f997c55cSAlexander Aring 		return 0;
244f997c55cSAlexander Aring }
245f997c55cSAlexander Aring 
ndisc_ops_update(const struct net_device * dev,struct neighbour * n,u32 flags,u8 icmp6_type,const struct ndisc_options * ndopts)246f997c55cSAlexander Aring static inline void ndisc_ops_update(const struct net_device *dev,
247f997c55cSAlexander Aring 					  struct neighbour *n, u32 flags,
248f997c55cSAlexander Aring 					  u8 icmp6_type,
249f997c55cSAlexander Aring 					  const struct ndisc_options *ndopts)
250f997c55cSAlexander Aring {
251f997c55cSAlexander Aring 	if (dev->ndisc_ops && dev->ndisc_ops->update)
252f997c55cSAlexander Aring 		dev->ndisc_ops->update(dev, n, flags, icmp6_type, ndopts);
253f997c55cSAlexander Aring }
254f997c55cSAlexander Aring 
ndisc_ops_opt_addr_space(const struct net_device * dev,u8 icmp6_type)255f997c55cSAlexander Aring static inline int ndisc_ops_opt_addr_space(const struct net_device *dev,
256f997c55cSAlexander Aring 					   u8 icmp6_type)
257f997c55cSAlexander Aring {
258f997c55cSAlexander Aring 	if (dev->ndisc_ops && dev->ndisc_ops->opt_addr_space &&
259f997c55cSAlexander Aring 	    icmp6_type != NDISC_REDIRECT)
260f997c55cSAlexander Aring 		return dev->ndisc_ops->opt_addr_space(dev, icmp6_type, NULL,
261f997c55cSAlexander Aring 						      NULL, NULL);
262f997c55cSAlexander Aring 	else
263f997c55cSAlexander Aring 		return 0;
264f997c55cSAlexander Aring }
265f997c55cSAlexander Aring 
ndisc_ops_redirect_opt_addr_space(const struct net_device * dev,struct neighbour * neigh,u8 * ha_buf,u8 ** ha)266f997c55cSAlexander Aring static inline int ndisc_ops_redirect_opt_addr_space(const struct net_device *dev,
267f997c55cSAlexander Aring 						    struct neighbour *neigh,
268f997c55cSAlexander Aring 						    u8 *ha_buf, u8 **ha)
269f997c55cSAlexander Aring {
270f997c55cSAlexander Aring 	if (dev->ndisc_ops && dev->ndisc_ops->opt_addr_space)
271f997c55cSAlexander Aring 		return dev->ndisc_ops->opt_addr_space(dev, NDISC_REDIRECT,
272f997c55cSAlexander Aring 						      neigh, ha_buf, ha);
273f997c55cSAlexander Aring 	else
274f997c55cSAlexander Aring 		return 0;
275f997c55cSAlexander Aring }
276f997c55cSAlexander Aring 
ndisc_ops_fill_addr_option(const struct net_device * dev,struct sk_buff * skb,u8 icmp6_type)277f997c55cSAlexander Aring static inline void ndisc_ops_fill_addr_option(const struct net_device *dev,
278f997c55cSAlexander Aring 					      struct sk_buff *skb,
279f997c55cSAlexander Aring 					      u8 icmp6_type)
280f997c55cSAlexander Aring {
281f997c55cSAlexander Aring 	if (dev->ndisc_ops && dev->ndisc_ops->fill_addr_option &&
282f997c55cSAlexander Aring 	    icmp6_type != NDISC_REDIRECT)
283f997c55cSAlexander Aring 		dev->ndisc_ops->fill_addr_option(dev, skb, icmp6_type, NULL);
284f997c55cSAlexander Aring }
285f997c55cSAlexander Aring 
ndisc_ops_fill_redirect_addr_option(const struct net_device * dev,struct sk_buff * skb,const u8 * ha)286f997c55cSAlexander Aring static inline void ndisc_ops_fill_redirect_addr_option(const struct net_device *dev,
287f997c55cSAlexander Aring 						       struct sk_buff *skb,
288f997c55cSAlexander Aring 						       const u8 *ha)
289f997c55cSAlexander Aring {
290f997c55cSAlexander Aring 	if (dev->ndisc_ops && dev->ndisc_ops->fill_addr_option)
291f997c55cSAlexander Aring 		dev->ndisc_ops->fill_addr_option(dev, skb, NDISC_REDIRECT, ha);
292f997c55cSAlexander Aring }
293f997c55cSAlexander Aring 
ndisc_ops_prefix_rcv_add_addr(struct net * net,struct net_device * dev,const struct prefix_info * pinfo,struct inet6_dev * in6_dev,struct in6_addr * addr,int addr_type,u32 addr_flags,bool sllao,bool tokenized,__u32 valid_lft,u32 prefered_lft,bool dev_addr_generated)294f997c55cSAlexander Aring static inline void ndisc_ops_prefix_rcv_add_addr(struct net *net,
295f997c55cSAlexander Aring 						 struct net_device *dev,
296f997c55cSAlexander Aring 						 const struct prefix_info *pinfo,
297f997c55cSAlexander Aring 						 struct inet6_dev *in6_dev,
298f997c55cSAlexander Aring 						 struct in6_addr *addr,
299f997c55cSAlexander Aring 						 int addr_type, u32 addr_flags,
300f997c55cSAlexander Aring 						 bool sllao, bool tokenized,
301f997c55cSAlexander Aring 						 __u32 valid_lft,
302f997c55cSAlexander Aring 						 u32 prefered_lft,
303f997c55cSAlexander Aring 						 bool dev_addr_generated)
304f997c55cSAlexander Aring {
305f997c55cSAlexander Aring 	if (dev->ndisc_ops && dev->ndisc_ops->prefix_rcv_add_addr)
306f997c55cSAlexander Aring 		dev->ndisc_ops->prefix_rcv_add_addr(net, dev, pinfo, in6_dev,
307f997c55cSAlexander Aring 						    addr, addr_type,
308f997c55cSAlexander Aring 						    addr_flags, sllao,
309f997c55cSAlexander Aring 						    tokenized, valid_lft,
310f997c55cSAlexander Aring 						    prefered_lft,
311f997c55cSAlexander Aring 						    dev_addr_generated);
312f997c55cSAlexander Aring }
313f997c55cSAlexander Aring #endif
314f997c55cSAlexander Aring 
31530f2a5f3SDavid S. Miller /*
31630f2a5f3SDavid S. Miller  * Return the padding between the option length and the start of the
31730f2a5f3SDavid S. Miller  * link addr.  Currently only IP-over-InfiniBand needs this, although
31830f2a5f3SDavid S. Miller  * if RFC 3831 IPv6-over-Fibre Channel is ever implemented it may
31930f2a5f3SDavid S. Miller  * also need a pad of 2.
32030f2a5f3SDavid S. Miller  */
ndisc_addr_option_pad(unsigned short type)321d9d10a30SJoe Perches static inline int ndisc_addr_option_pad(unsigned short type)
32230f2a5f3SDavid S. Miller {
32330f2a5f3SDavid S. Miller 	switch (type) {
32430f2a5f3SDavid S. Miller 	case ARPHRD_INFINIBAND: return 2;
32530f2a5f3SDavid S. Miller 	default:                return 0;
32630f2a5f3SDavid S. Miller 	}
32730f2a5f3SDavid S. Miller }
32830f2a5f3SDavid S. Miller 
__ndisc_opt_addr_space(unsigned char addr_len,int pad)3291e82f961SAlexander Aring static inline int __ndisc_opt_addr_space(unsigned char addr_len, int pad)
3301e82f961SAlexander Aring {
3311e82f961SAlexander Aring 	return NDISC_OPT_SPACE(addr_len + pad);
3321e82f961SAlexander Aring }
3331e82f961SAlexander Aring 
334f997c55cSAlexander Aring #if IS_ENABLED(CONFIG_IPV6)
ndisc_opt_addr_space(struct net_device * dev,u8 icmp6_type)335f997c55cSAlexander Aring static inline int ndisc_opt_addr_space(struct net_device *dev, u8 icmp6_type)
336c558e9fcSYOSHIFUJI Hideaki / 吉藤英明 {
3371e82f961SAlexander Aring 	return __ndisc_opt_addr_space(dev->addr_len,
338f997c55cSAlexander Aring 				      ndisc_addr_option_pad(dev->type)) +
339f997c55cSAlexander Aring 		ndisc_ops_opt_addr_space(dev, icmp6_type);
340c558e9fcSYOSHIFUJI Hideaki / 吉藤英明 }
341c558e9fcSYOSHIFUJI Hideaki / 吉藤英明 
ndisc_redirect_opt_addr_space(struct net_device * dev,struct neighbour * neigh,u8 * ops_data_buf,u8 ** ops_data)342f997c55cSAlexander Aring static inline int ndisc_redirect_opt_addr_space(struct net_device *dev,
343f997c55cSAlexander Aring 						struct neighbour *neigh,
344f997c55cSAlexander Aring 						u8 *ops_data_buf,
345f997c55cSAlexander Aring 						u8 **ops_data)
346f997c55cSAlexander Aring {
347f997c55cSAlexander Aring 	return __ndisc_opt_addr_space(dev->addr_len,
348f997c55cSAlexander Aring 				      ndisc_addr_option_pad(dev->type)) +
349f997c55cSAlexander Aring 		ndisc_ops_redirect_opt_addr_space(dev, neigh, ops_data_buf,
350f997c55cSAlexander Aring 						  ops_data);
351f997c55cSAlexander Aring }
352f997c55cSAlexander Aring #endif
353f997c55cSAlexander Aring 
__ndisc_opt_addr_data(struct nd_opt_hdr * p,unsigned char addr_len,int prepad)3544f36ce84SAlexander Aring static inline u8 *__ndisc_opt_addr_data(struct nd_opt_hdr *p,
3554f36ce84SAlexander Aring 					unsigned char addr_len, int prepad)
35630f2a5f3SDavid S. Miller {
35730f2a5f3SDavid S. Miller 	u8 *lladdr = (u8 *)(p + 1);
35830f2a5f3SDavid S. Miller 	int lladdrlen = p->nd_opt_len << 3;
3594f36ce84SAlexander Aring 	if (lladdrlen != __ndisc_opt_addr_space(addr_len, prepad))
36030f2a5f3SDavid S. Miller 		return NULL;
36130f2a5f3SDavid S. Miller 	return lladdr + prepad;
36230f2a5f3SDavid S. Miller }
36330f2a5f3SDavid S. Miller 
ndisc_opt_addr_data(struct nd_opt_hdr * p,struct net_device * dev)3644f36ce84SAlexander Aring static inline u8 *ndisc_opt_addr_data(struct nd_opt_hdr *p,
3654f36ce84SAlexander Aring 				      struct net_device *dev)
3664f36ce84SAlexander Aring {
3674f36ce84SAlexander Aring 	return __ndisc_opt_addr_data(p, dev->addr_len,
3684f36ce84SAlexander Aring 				     ndisc_addr_option_pad(dev->type));
3694f36ce84SAlexander Aring }
3704f36ce84SAlexander Aring 
ndisc_hashfn(const void * pkey,const struct net_device * dev,__u32 * hash_rnd)3712c2aba6cSDavid S. Miller static inline u32 ndisc_hashfn(const void *pkey, const struct net_device *dev, __u32 *hash_rnd)
3722c2aba6cSDavid S. Miller {
3732c2aba6cSDavid S. Miller 	const u32 *p32 = pkey;
3742c2aba6cSDavid S. Miller 
375b14f243aSPavel Emelyanov 	return (((p32[0] ^ hash32_ptr(dev)) * hash_rnd[0]) +
3762c2aba6cSDavid S. Miller 		(p32[1] * hash_rnd[1]) +
3772c2aba6cSDavid S. Miller 		(p32[2] * hash_rnd[2]) +
3782c2aba6cSDavid S. Miller 		(p32[3] * hash_rnd[3]));
3792c2aba6cSDavid S. Miller }
3801da177e4SLinus Torvalds 
__ipv6_neigh_lookup_noref(struct net_device * dev,const void * pkey)381ac3175feSYOSHIFUJI Hideaki / 吉藤英明 static inline struct neighbour *__ipv6_neigh_lookup_noref(struct net_device *dev, const void *pkey)
382f83c7790SDavid S. Miller {
38360395a20SEric W. Biederman 	return ___neigh_lookup_noref(&nd_tbl, neigh_key_eq128, ndisc_hashfn, pkey, dev);
384ac3175feSYOSHIFUJI Hideaki / 吉藤英明 }
385ac3175feSYOSHIFUJI Hideaki / 吉藤英明 
38671df5777SDavid Ahern static inline
__ipv6_neigh_lookup_noref_stub(struct net_device * dev,const void * pkey)38771df5777SDavid Ahern struct neighbour *__ipv6_neigh_lookup_noref_stub(struct net_device *dev,
38871df5777SDavid Ahern 						 const void *pkey)
38971df5777SDavid Ahern {
39071df5777SDavid Ahern 	return ___neigh_lookup_noref(ipv6_stub->nd_tbl, neigh_key_eq128,
39171df5777SDavid Ahern 				     ndisc_hashfn, pkey, dev);
39271df5777SDavid Ahern }
39371df5777SDavid Ahern 
__ipv6_neigh_lookup(struct net_device * dev,const void * pkey)394ac3175feSYOSHIFUJI Hideaki / 吉藤英明 static inline struct neighbour *__ipv6_neigh_lookup(struct net_device *dev, const void *pkey)
395ac3175feSYOSHIFUJI Hideaki / 吉藤英明 {
396ac3175feSYOSHIFUJI Hideaki / 吉藤英明 	struct neighbour *n;
397ac3175feSYOSHIFUJI Hideaki / 吉藤英明 
398*09eed119SEric Dumazet 	rcu_read_lock();
399ac3175feSYOSHIFUJI Hideaki / 吉藤英明 	n = __ipv6_neigh_lookup_noref(dev, pkey);
4009f237430SReshetova, Elena 	if (n && !refcount_inc_not_zero(&n->refcnt))
401f83c7790SDavid S. Miller 		n = NULL;
402*09eed119SEric Dumazet 	rcu_read_unlock();
403f83c7790SDavid S. Miller 
404f83c7790SDavid S. Miller 	return n;
405f83c7790SDavid S. Miller }
406f83c7790SDavid S. Miller 
__ipv6_confirm_neigh(struct net_device * dev,const void * pkey)40763fca65dSJulian Anastasov static inline void __ipv6_confirm_neigh(struct net_device *dev,
40863fca65dSJulian Anastasov 					const void *pkey)
40963fca65dSJulian Anastasov {
41063fca65dSJulian Anastasov 	struct neighbour *n;
41163fca65dSJulian Anastasov 
412*09eed119SEric Dumazet 	rcu_read_lock();
41363fca65dSJulian Anastasov 	n = __ipv6_neigh_lookup_noref(dev, pkey);
4141e84dc6bSYajun Deng 	neigh_confirm(n);
415*09eed119SEric Dumazet 	rcu_read_unlock();
41663fca65dSJulian Anastasov }
41763fca65dSJulian Anastasov 
__ipv6_confirm_neigh_stub(struct net_device * dev,const void * pkey)41871df5777SDavid Ahern static inline void __ipv6_confirm_neigh_stub(struct net_device *dev,
41971df5777SDavid Ahern 					     const void *pkey)
42071df5777SDavid Ahern {
42171df5777SDavid Ahern 	struct neighbour *n;
42271df5777SDavid Ahern 
423*09eed119SEric Dumazet 	rcu_read_lock();
42471df5777SDavid Ahern 	n = __ipv6_neigh_lookup_noref_stub(dev, pkey);
4251e84dc6bSYajun Deng 	neigh_confirm(n);
426*09eed119SEric Dumazet 	rcu_read_unlock();
42771df5777SDavid Ahern }
42871df5777SDavid Ahern 
42971df5777SDavid Ahern /* uses ipv6_stub and is meant for use outside of IPv6 core */
ip_neigh_gw6(struct net_device * dev,const void * addr)43071df5777SDavid Ahern static inline struct neighbour *ip_neigh_gw6(struct net_device *dev,
43171df5777SDavid Ahern 					     const void *addr)
43271df5777SDavid Ahern {
43371df5777SDavid Ahern 	struct neighbour *neigh;
43471df5777SDavid Ahern 
43571df5777SDavid Ahern 	neigh = __ipv6_neigh_lookup_noref_stub(dev, addr);
43671df5777SDavid Ahern 	if (unlikely(!neigh))
43771df5777SDavid Ahern 		neigh = __neigh_create(ipv6_stub->nd_tbl, addr, dev, false);
43871df5777SDavid Ahern 
43971df5777SDavid Ahern 	return neigh;
44071df5777SDavid Ahern }
44171df5777SDavid Ahern 
4423cc818a2SJoe Perches int ndisc_init(void);
4433cc818a2SJoe Perches int ndisc_late_init(void);
4441da177e4SLinus Torvalds 
4453cc818a2SJoe Perches void ndisc_late_cleanup(void);
4463cc818a2SJoe Perches void ndisc_cleanup(void);
4471da177e4SLinus Torvalds 
448545dbcd1SEric Dumazet enum skb_drop_reason ndisc_rcv(struct sk_buff *skb);
4491da177e4SLinus Torvalds 
450696c6544SHangbin Liu struct sk_buff *ndisc_ns_create(struct net_device *dev, const struct in6_addr *solicit,
451696c6544SHangbin Liu 				const struct in6_addr *saddr, u64 nonce);
45238cf595bSJiri Benc void ndisc_send_ns(struct net_device *dev, const struct in6_addr *solicit,
453adc176c5SErik Nordmark 		   const struct in6_addr *daddr, const struct in6_addr *saddr,
454adc176c5SErik Nordmark 		   u64 nonce);
4551da177e4SLinus Torvalds 
456696c6544SHangbin Liu void ndisc_send_skb(struct sk_buff *skb, const struct in6_addr *daddr,
457696c6544SHangbin Liu 		    const struct in6_addr *saddr);
458696c6544SHangbin Liu 
4593cc818a2SJoe Perches void ndisc_send_rs(struct net_device *dev,
4603cc818a2SJoe Perches 		   const struct in6_addr *saddr, const struct in6_addr *daddr);
46138cf595bSJiri Benc void ndisc_send_na(struct net_device *dev, const struct in6_addr *daddr,
462f564f45cSCong Wang 		   const struct in6_addr *solicited_addr,
4633cc818a2SJoe Perches 		   bool router, bool solicited, bool override, bool inc_opt);
4641da177e4SLinus Torvalds 
4653cc818a2SJoe Perches void ndisc_send_redirect(struct sk_buff *skb, const struct in6_addr *target);
4661da177e4SLinus Torvalds 
4673cc818a2SJoe Perches int ndisc_mc_map(const struct in6_addr *addr, char *buf, struct net_device *dev,
4683cc818a2SJoe Perches 		 int dir);
4691da177e4SLinus Torvalds 
470f997c55cSAlexander Aring void ndisc_update(const struct net_device *dev, struct neighbour *neigh,
471f997c55cSAlexander Aring 		  const u8 *lladdr, u8 new, u32 flags, u8 icmp6_type,
472f997c55cSAlexander Aring 		  struct ndisc_options *ndopts);
4731da177e4SLinus Torvalds 
4741da177e4SLinus Torvalds /*
4751da177e4SLinus Torvalds  *	IGMP
4761da177e4SLinus Torvalds  */
4773cc818a2SJoe Perches int igmp6_init(void);
478382ed724SVlad Yasevich int igmp6_late_init(void);
4791da177e4SLinus Torvalds 
4803cc818a2SJoe Perches void igmp6_cleanup(void);
481382ed724SVlad Yasevich void igmp6_late_cleanup(void);
4821da177e4SLinus Torvalds 
4832d3916f3SEric Dumazet void igmp6_event_query(struct sk_buff *skb);
4841da177e4SLinus Torvalds 
4852d3916f3SEric Dumazet void igmp6_event_report(struct sk_buff *skb);
4861da177e4SLinus Torvalds 
4871da177e4SLinus Torvalds 
4881da177e4SLinus Torvalds #ifdef CONFIG_SYSCTL
4893cc818a2SJoe Perches int ndisc_ifinfo_sysctl_change(struct ctl_table *ctl, int write,
4903622adb0STobias Klauser 			       void *buffer, size_t *lenp, loff_t *ppos);
4911da177e4SLinus Torvalds #endif
4921da177e4SLinus Torvalds 
4933cc818a2SJoe Perches void inet6_ifinfo_notify(int event, struct inet6_dev *idev);
4941da177e4SLinus Torvalds 
4951da177e4SLinus Torvalds #endif
496