1 /** @file
2  @brief IPv6 data handler
3 
4  This is not to be included by the application.
5  */
6 
7 /*
8  * Copyright (c) 2016 Intel Corporation
9  *
10  * SPDX-License-Identifier: Apache-2.0
11  */
12 
13 #ifndef __IPV6_H
14 #define __IPV6_H
15 
16 #include <zephyr/types.h>
17 
18 #include <zephyr/net/net_ip.h>
19 #include <zephyr/net/net_pkt.h>
20 #include <zephyr/net/net_if.h>
21 #include <zephyr/net/net_context.h>
22 
23 #include "icmpv6.h"
24 #include "nbr.h"
25 
26 #define NET_IPV6_ND_HOP_LIMIT 255
27 #define NET_IPV6_ND_INFINITE_LIFETIME 0xFFFFFFFF
28 
29 #define NET_IPV6_DEFAULT_PREFIX_LEN 64
30 
31 #define NET_MAX_RS_COUNT 3
32 
33 #define NET_IPV6_DSCP_MASK 0xFC
34 #define NET_IPV6_DSCP_OFFSET 2
35 #define NET_IPV6_ECN_MASK 0x03
36 
37 /**
38  * @brief Bitmaps for IPv6 extension header processing
39  *
40  * When processing extension headers, we record which one we have seen.
41  * This is done as the network packet cannot have twice the same header,
42  * except for destination option.
43  * This information is stored in bitfield variable.
44  * The order of the bitmap is the order recommended in RFC 2460.
45  */
46 #define NET_IPV6_EXT_HDR_BITMAP_HBHO   0x01
47 #define NET_IPV6_EXT_HDR_BITMAP_DESTO1 0x02
48 #define NET_IPV6_EXT_HDR_BITMAP_ROUTING        0x04
49 #define NET_IPV6_EXT_HDR_BITMAP_FRAG   0x08
50 #define NET_IPV6_EXT_HDR_BITMAP_AH     0x10
51 #define NET_IPV6_EXT_HDR_BITMAP_ESP    0x20
52 #define NET_IPV6_EXT_HDR_BITMAP_DESTO2 0x40
53 
54 /**
55  * @brief Destination and Hop By Hop extension headers option types
56  */
57 #define NET_IPV6_EXT_HDR_OPT_PAD1  0
58 #define NET_IPV6_EXT_HDR_OPT_PADN  1
59 #define NET_IPV6_EXT_HDR_OPT_RPL   0x63
60 
61 /**
62  * @brief Multicast Listener Record v2 record types.
63  */
64 #define NET_IPV6_MLDv2_MODE_IS_INCLUDE        1
65 #define NET_IPV6_MLDv2_MODE_IS_EXCLUDE        2
66 #define NET_IPV6_MLDv2_CHANGE_TO_INCLUDE_MODE 3
67 #define NET_IPV6_MLDv2_CHANGE_TO_EXCLUDE_MODE 4
68 #define NET_IPV6_MLDv2_ALLOW_NEW_SOURCES      5
69 #define NET_IPV6_MLDv2_BLOCK_OLD_SOURCES      6
70 
71 /* State of the neighbor */
72 enum net_ipv6_nbr_state {
73 	NET_IPV6_NBR_STATE_INCOMPLETE,
74 	NET_IPV6_NBR_STATE_REACHABLE,
75 	NET_IPV6_NBR_STATE_STALE,
76 	NET_IPV6_NBR_STATE_DELAY,
77 	NET_IPV6_NBR_STATE_PROBE,
78 	NET_IPV6_NBR_STATE_STATIC,
79 };
80 
81 const char *net_ipv6_nbr_state2str(enum net_ipv6_nbr_state state);
82 
83 /**
84  * @brief IPv6 neighbor information.
85  */
86 struct net_ipv6_nbr_data {
87 	/** Any pending packet waiting ND to finish. */
88 	struct net_pkt *pending;
89 
90 	/** IPv6 address. */
91 	struct in6_addr addr;
92 
93 	/** Reachable timer. */
94 	int64_t reachable;
95 
96 	/** Reachable timeout */
97 	int32_t reachable_timeout;
98 
99 	/** Neighbor Solicitation reply timer */
100 	int64_t send_ns;
101 
102 	/** State of the neighbor discovery */
103 	enum net_ipv6_nbr_state state;
104 
105 	/** Link metric for the neighbor */
106 	uint16_t link_metric;
107 
108 	/** How many times we have sent NS */
109 	uint8_t ns_count;
110 
111 	/** Is the neighbor a router */
112 	bool is_router;
113 
114 #if defined(CONFIG_NET_IPV6_NBR_CACHE) || defined(CONFIG_NET_IPV6_ND)
115 	/** Stale counter used to removed oldest nbr in STALE state,
116 	 *  when table is full.
117 	 */
118 	uint32_t stale_counter;
119 #endif
120 };
121 
net_ipv6_nbr_data(struct net_nbr * nbr)122 static inline struct net_ipv6_nbr_data *net_ipv6_nbr_data(struct net_nbr *nbr)
123 {
124 	return (struct net_ipv6_nbr_data *)nbr->data;
125 }
126 
127 #if defined(CONFIG_NET_IPV6_DAD)
128 int net_ipv6_start_dad(struct net_if *iface, struct net_if_addr *ifaddr);
129 #endif
130 
131 int net_ipv6_send_ns(struct net_if *iface, struct net_pkt *pending,
132 		     const struct in6_addr *src, const struct in6_addr *dst,
133 		     const struct in6_addr *tgt, bool is_my_address);
134 
135 int net_ipv6_send_rs(struct net_if *iface);
136 int net_ipv6_start_rs(struct net_if *iface);
137 
138 int net_ipv6_send_na(struct net_if *iface, const struct in6_addr *src,
139 		     const struct in6_addr *dst, const struct in6_addr *tgt,
140 		     uint8_t flags);
141 
142 
net_ipv6_is_nexthdr_upper_layer(uint8_t nexthdr)143 static inline bool net_ipv6_is_nexthdr_upper_layer(uint8_t nexthdr)
144 {
145 	return (nexthdr == IPPROTO_ICMPV6 || nexthdr == IPPROTO_UDP ||
146 		nexthdr == IPPROTO_TCP ||
147 		(IS_ENABLED(CONFIG_NET_L2_VIRTUAL) &&
148 		 ((nexthdr == IPPROTO_IPV6) || (nexthdr == IPPROTO_IPIP))));
149 }
150 
151 /**
152  * @brief Create IPv6 packet in provided net_pkt.
153  *
154  * @param pkt Network packet
155  * @param src Source IPv6 address
156  * @param dst Destination IPv6 address
157  *
158  * @return 0 on success, negative errno otherwise.
159  */
160 #if defined(CONFIG_NET_NATIVE_IPV6)
161 int net_ipv6_create(struct net_pkt *pkt,
162 		    const struct in6_addr *src,
163 		    const struct in6_addr *dst);
164 #else
net_ipv6_create(struct net_pkt * pkt,const struct in6_addr * src,const struct in6_addr * dst)165 static inline int net_ipv6_create(struct net_pkt *pkt,
166 				  const struct in6_addr *src,
167 				  const struct in6_addr *dst)
168 {
169 	ARG_UNUSED(pkt);
170 	ARG_UNUSED(src);
171 	ARG_UNUSED(dst);
172 
173 	return -ENOTSUP;
174 }
175 #endif
176 
177 /**
178  * @brief Finalize IPv6 packet. It should be called right before
179  * sending the packet and after all the data has been added into
180  * the packet. This function will set the length of the
181  * packet and calculate the higher protocol checksum if needed.
182  *
183  * @param pkt Network packet
184  * @param next_header_proto Protocol type of the next header after IPv6 header.
185  *
186  * @return 0 on success, negative errno otherwise.
187  */
188 #if defined(CONFIG_NET_NATIVE_IPV6)
189 int net_ipv6_finalize(struct net_pkt *pkt, uint8_t next_header_proto);
190 #else
net_ipv6_finalize(struct net_pkt * pkt,uint8_t next_header_proto)191 static inline int net_ipv6_finalize(struct net_pkt *pkt,
192 				    uint8_t next_header_proto)
193 {
194 	ARG_UNUSED(pkt);
195 	ARG_UNUSED(next_header_proto);
196 
197 	return -ENOTSUP;
198 }
199 #endif
200 
201 /**
202  * @brief Send MLDv2 report message with a single entry.
203  *
204  * @param iface Network interface where message is sent
205  * @param addr Multicast group
206  * @param mode MLDv2 mode (NET_IPV6_MLDv2_MODE_IS_INCLUDE NET_IPV6_MLDv2_MODE_IS_EXCLUDE)
207  *
208  * @return Return 0 if leaving is done, <0 otherwise.
209  */
210 #if defined(CONFIG_NET_IPV6_MLD)
211 int net_ipv6_mld_send_single(struct net_if *iface, const struct in6_addr *addr, uint8_t mode);
212 #else
213 static inline int
net_ipv6_mld_send_single(struct net_if * iface,const struct in6_addr * addr,uint8_t mode)214 net_ipv6_mld_send_single(struct net_if *iface, const struct in6_addr *addr, uint8_t mode)
215 {
216 	ARG_UNUSED(iface);
217 	ARG_UNUSED(addr);
218 	ARG_UNUSED(mode);
219 
220 	return -ENOTSUP;
221 }
222 #endif /* CONFIG_NET_IPV6_MLD */
223 
224 /**
225  * @typedef net_nbr_cb_t
226  * @brief Callback used while iterating over neighbors.
227  *
228  * @param nbr A valid pointer on current neighbor.
229  * @param user_data A valid pointer on some user data or NULL
230  */
231 typedef void (*net_nbr_cb_t)(struct net_nbr *nbr, void *user_data);
232 
233 /**
234  * @brief Make sure the link layer address is set according to
235  * destination address. If the ll address is not yet known, then
236  * start neighbor discovery to find it out. If ND needs to be done
237  * then the returned packet is the Neighbor Solicitation message
238  * and the original message is sent after Neighbor Advertisement
239  * message is received.
240  *
241  * @param pkt Network packet
242  *
243  * @return Return a verdict.
244  */
245 #if defined(CONFIG_NET_IPV6_NBR_CACHE) && defined(CONFIG_NET_NATIVE_IPV6)
246 enum net_verdict net_ipv6_prepare_for_send(struct net_pkt *pkt);
247 #else
net_ipv6_prepare_for_send(struct net_pkt * pkt)248 static inline enum net_verdict net_ipv6_prepare_for_send(struct net_pkt *pkt)
249 {
250 	return NET_OK;
251 }
252 #endif
253 
254 /**
255  * @brief Lock IPv6 Neighbor table mutex
256  *
257  * Neighbor table mutex is used by IPv6 Neighbor cache and IPv6 Routing module.
258  * Mutex shall be held whenever accessing or manipulating neighbor or routing
259  * table entries (for example when obtaining a pointer to the neighbor table
260  * entry). Neighbor and Routing API functions will lock the mutex when called.
261  */
262 void net_ipv6_nbr_lock(void);
263 
264 /**
265  * @brief Unlock IPv6 Neighbor table mutex
266  */
267 void net_ipv6_nbr_unlock(void);
268 
269 /**
270  * @brief Look for a neighbor from it's address on an iface
271  *
272  * @param iface A valid pointer on a network interface
273  * @param addr The IPv6 address to match
274  *
275  * @return A valid pointer on a neighbor on success, NULL otherwise
276  */
277 #if defined(CONFIG_NET_IPV6_NBR_CACHE) && defined(CONFIG_NET_NATIVE_IPV6)
278 struct net_nbr *net_ipv6_nbr_lookup(struct net_if *iface,
279 				    struct in6_addr *addr);
280 #else
net_ipv6_nbr_lookup(struct net_if * iface,struct in6_addr * addr)281 static inline struct net_nbr *net_ipv6_nbr_lookup(struct net_if *iface,
282 						  struct in6_addr *addr)
283 {
284 	return NULL;
285 }
286 #endif
287 
288 /**
289  * @brief Get neighbor from its index.
290  *
291  * @param iface Network interface to match. If NULL, then use
292  * whatever interface there is configured for the neighbor address.
293  * @param idx Index of the link layer address in the address array
294  *
295  * @return A valid pointer on a neighbor on success, NULL otherwise
296  */
297 struct net_nbr *net_ipv6_get_nbr(struct net_if *iface, uint8_t idx);
298 
299 /**
300  * @brief Look for a neighbor from it's link local address index
301  *
302  * @param iface Network interface to match. If NULL, then use
303  * whatever interface there is configured for the neighbor address.
304  * @param idx Index of the link layer address in the address array
305  *
306  * @return A valid pointer on a neighbor on success, NULL otherwise
307  */
308 #if defined(CONFIG_NET_IPV6_NBR_CACHE) && defined(CONFIG_NET_NATIVE_IPV6)
309 struct in6_addr *net_ipv6_nbr_lookup_by_index(struct net_if *iface,
310 					      uint8_t idx);
311 #else
312 static inline
net_ipv6_nbr_lookup_by_index(struct net_if * iface,uint8_t idx)313 struct in6_addr *net_ipv6_nbr_lookup_by_index(struct net_if *iface,
314 					      uint8_t idx)
315 {
316 	return NULL;
317 }
318 #endif
319 
320 /**
321  * @brief Add a neighbor to neighbor cache
322  *
323  * Add a neighbor to the cache after performing a lookup and in case
324  * there exists an entry in the cache update its state and lladdr.
325  *
326  * @param iface A valid pointer on a network interface
327  * @param addr Neighbor IPv6 address
328  * @param lladdr Neighbor link layer address
329  * @param is_router Set to true if the neighbor is a router, false
330  * otherwise
331  * @param state Initial state of the neighbor entry in the cache
332  *
333  * @return A valid pointer on a neighbor on success, NULL otherwise
334  */
335 #if defined(CONFIG_NET_IPV6_NBR_CACHE) && defined(CONFIG_NET_NATIVE_IPV6)
336 struct net_nbr *net_ipv6_nbr_add(struct net_if *iface,
337 				 const struct in6_addr *addr,
338 				 const struct net_linkaddr *lladdr,
339 				 bool is_router,
340 				 enum net_ipv6_nbr_state state);
341 #else
net_ipv6_nbr_add(struct net_if * iface,const struct in6_addr * addr,const struct net_linkaddr * lladdr,bool is_router,enum net_ipv6_nbr_state state)342 static inline struct net_nbr *net_ipv6_nbr_add(struct net_if *iface,
343 					       const struct in6_addr *addr,
344 					       const struct net_linkaddr *lladdr,
345 					       bool is_router,
346 					       enum net_ipv6_nbr_state state)
347 {
348 	return NULL;
349 }
350 #endif
351 
352 /**
353  * @brief Remove a neighbor from neighbor cache.
354  *
355  * @param iface A valid pointer on a network interface
356  * @param addr Neighbor IPv6 address
357  *
358  * @return True if neighbor could be removed, False otherwise
359  */
360 #if defined(CONFIG_NET_IPV6_NBR_CACHE) && defined(CONFIG_NET_NATIVE_IPV6)
361 bool net_ipv6_nbr_rm(struct net_if *iface, struct in6_addr *addr);
362 #else
net_ipv6_nbr_rm(struct net_if * iface,struct in6_addr * addr)363 static inline bool net_ipv6_nbr_rm(struct net_if *iface, struct in6_addr *addr)
364 {
365 	return true;
366 }
367 #endif
368 
369 /**
370  * @brief Go through all the neighbors and call callback for each of them.
371  *
372  * @param cb User supplied callback function to call.
373  * @param user_data User specified data.
374  */
375 #if defined(CONFIG_NET_IPV6_NBR_CACHE) && defined(CONFIG_NET_NATIVE_IPV6)
376 void net_ipv6_nbr_foreach(net_nbr_cb_t cb, void *user_data);
377 #else /* CONFIG_NET_IPV6_NBR_CACHE */
net_ipv6_nbr_foreach(net_nbr_cb_t cb,void * user_data)378 static inline void net_ipv6_nbr_foreach(net_nbr_cb_t cb, void *user_data)
379 {
380 	return;
381 }
382 #endif /* CONFIG_NET_IPV6_NBR_CACHE */
383 
384 /**
385  * @brief Provide a reachability hint for IPv6 Neighbor Discovery.
386  *
387  * This function is intended for upper-layer protocols to inform the IPv6
388  * Neighbor Discovery process about the active link to a specific neighbor.
389  * By signaling recent "forward progress" event, such as the reception of
390  * an ACK, this function can help reducing unnecessary ND traffic as per the
391  * guidelines in RFC 4861 (section 7.3).
392  *
393  * @param iface A pointer to the network interface.
394  * @param ipv6_addr Pointer to the IPv6 address of the neighbor node.
395  */
396 #if defined(CONFIG_NET_IPV6_ND) && defined(CONFIG_NET_NATIVE_IPV6)
397 void net_ipv6_nbr_reachability_hint(struct net_if *iface, const struct in6_addr *ipv6_addr);
398 #else
net_ipv6_nbr_reachability_hint(struct net_if * iface,const struct in6_addr * ipv6_addr)399 static inline void net_ipv6_nbr_reachability_hint(struct net_if *iface,
400 						  const struct in6_addr *ipv6_addr)
401 {
402 	ARG_UNUSED(iface);
403 	ARG_UNUSED(ipv6_addr);
404 }
405 #endif
406 
407 /**
408  * @brief Set the neighbor reachable timer.
409  *
410  * @param iface A valid pointer on a network interface
411  * @param nbr Neighbor struct pointer
412  */
413 #if defined(CONFIG_NET_IPV6_ND) && defined(CONFIG_NET_NATIVE_IPV6)
414 void net_ipv6_nbr_set_reachable_timer(struct net_if *iface,
415 				      struct net_nbr *nbr);
416 
417 #else /* CONFIG_NET_IPV6_ND */
net_ipv6_nbr_set_reachable_timer(struct net_if * iface,struct net_nbr * nbr)418 static inline void net_ipv6_nbr_set_reachable_timer(struct net_if *iface,
419 						    struct net_nbr *nbr)
420 {
421 }
422 #endif
423 
424 #if defined(CONFIG_NET_IPV6_FRAGMENT)
425 /** Store pending IPv6 fragment information that is needed for reassembly. */
426 struct net_ipv6_reassembly {
427 	/** IPv6 source address of the fragment */
428 	struct in6_addr src;
429 
430 	/** IPv6 destination address of the fragment */
431 	struct in6_addr dst;
432 
433 	/**
434 	 * Timeout for cancelling the reassembly. The timer is used
435 	 * also to detect if this reassembly slot is used or not.
436 	 */
437 	struct k_work_delayable timer;
438 
439 	/** Pointers to pending fragments */
440 	struct net_pkt *pkt[CONFIG_NET_IPV6_FRAGMENT_MAX_PKT];
441 
442 	/** IPv6 fragment identification */
443 	uint32_t id;
444 };
445 #else
446 struct net_ipv6_reassembly;
447 #endif
448 
449 /**
450  * @typedef net_ipv6_frag_cb_t
451  * @brief Callback used while iterating over pending IPv6 fragments.
452  *
453  * @param reass IPv6 fragment reassembly struct
454  * @param user_data A valid pointer on some user data or NULL
455  */
456 typedef void (*net_ipv6_frag_cb_t)(struct net_ipv6_reassembly *reass,
457 				   void *user_data);
458 
459 /**
460  * @brief Go through all the currently pending IPv6 fragments.
461  *
462  * @param cb Callback to call for each pending IPv6 fragment.
463  * @param user_data User specified data or NULL.
464  */
465 void net_ipv6_frag_foreach(net_ipv6_frag_cb_t cb, void *user_data);
466 
467 /**
468  * @brief Find the last IPv6 extension header in the network packet.
469  *
470  * @param pkt Network head packet.
471  * @param next_hdr_off Offset of the next header field that points
472  * to last header. This is returned to caller.
473  * @param last_hdr_off Offset of the last header field in the packet.
474  * This is returned to caller.
475  *
476  * @return 0 on success, a negative errno otherwise.
477  */
478 int net_ipv6_find_last_ext_hdr(struct net_pkt *pkt, uint16_t *next_hdr_off,
479 			       uint16_t *last_hdr_off);
480 
481 /**
482  * @brief Handles IPv6 fragmented packets.
483  *
484  * @param pkt     Network head packet.
485  * @param hdr     The IPv6 header of the current packet
486  * @param nexthdr IPv6 next header after fragment header part
487  *
488  * @return Return verdict about the packet
489  */
490 #if defined(CONFIG_NET_IPV6_FRAGMENT) && defined(CONFIG_NET_NATIVE_IPV6)
491 enum net_verdict net_ipv6_handle_fragment_hdr(struct net_pkt *pkt,
492 					      struct net_ipv6_hdr *hdr,
493 					      uint8_t nexthdr);
494 #else
495 static inline
net_ipv6_handle_fragment_hdr(struct net_pkt * pkt,struct net_ipv6_hdr * hdr,uint8_t nexthdr)496 enum net_verdict net_ipv6_handle_fragment_hdr(struct net_pkt *pkt,
497 					      struct net_ipv6_hdr *hdr,
498 					      uint8_t nexthdr)
499 {
500 	ARG_UNUSED(pkt);
501 	ARG_UNUSED(hdr);
502 	ARG_UNUSED(nexthdr);
503 
504 	return NET_DROP;
505 }
506 #endif /* CONFIG_NET_IPV6_FRAGMENT */
507 
508 #if defined(CONFIG_NET_NATIVE_IPV6)
509 void net_ipv6_init(void);
510 void net_ipv6_nbr_init(void);
511 #if defined(CONFIG_NET_IPV6_MLD)
512 void net_ipv6_mld_init(void);
513 #else
514 #define net_ipv6_mld_init(...)
515 #endif
516 #else
517 #define net_ipv6_init(...)
518 #define net_ipv6_nbr_init(...)
519 #endif
520 
521 /**
522  * @brief Decode DSCP value from TC field.
523  *
524  * @param tc TC field value from the IPv6 header.
525  *
526  * @return Decoded DSCP value.
527  */
net_ipv6_get_dscp(uint8_t tc)528 static inline uint8_t net_ipv6_get_dscp(uint8_t tc)
529 {
530 	return (tc & NET_IPV6_DSCP_MASK) >> NET_IPV6_DSCP_OFFSET;
531 }
532 
533 /**
534  * @brief Encode DSCP value into TC field.
535  *
536  * @param tc A pointer to the TC field.
537  * @param dscp DSCP value to set.
538  */
net_ipv6_set_dscp(uint8_t * tc,uint8_t dscp)539 static inline void net_ipv6_set_dscp(uint8_t *tc, uint8_t dscp)
540 {
541 	*tc &= ~NET_IPV6_DSCP_MASK;
542 	*tc |= (dscp << NET_IPV6_DSCP_OFFSET) & NET_IPV6_DSCP_MASK;
543 }
544 
545 /**
546  * @brief Convert DSCP value to priority.
547  *
548  * @param dscp DSCP value.
549  */
net_ipv6_dscp_to_priority(uint8_t dscp)550 static inline uint8_t net_ipv6_dscp_to_priority(uint8_t dscp)
551 {
552 	return dscp >> 3;
553 }
554 
555 /**
556  * @brief Decode ECN value from TC field.
557  *
558  * @param tc TC field value from the IPv6 header.
559  *
560  * @return Decoded ECN value.
561  */
net_ipv6_get_ecn(uint8_t tc)562 static inline uint8_t net_ipv6_get_ecn(uint8_t tc)
563 {
564 	return tc & NET_IPV6_ECN_MASK;
565 }
566 
567 /**
568  * @brief Encode ECN value into TC field.
569  *
570  * @param tc A pointer to the TC field.
571  * @param ecn ECN value to set.
572  */
net_ipv6_set_ecn(uint8_t * tc,uint8_t ecn)573 static inline void net_ipv6_set_ecn(uint8_t *tc, uint8_t ecn)
574 {
575 	*tc &= ~NET_IPV6_ECN_MASK;
576 	*tc |= ecn & NET_IPV6_ECN_MASK;
577 }
578 
579 /**
580  * @brief Start IPv6 privacy extension procedure.
581  *
582  * @param iface Interface to use.
583  * @param prefix IPv6 prefix to use.
584  * @param vlifetime Lifetime of this IPv6 prefix (in seconds).
585  * @param preferred_lifetime Preferred lifetime of this IPv6 prefix (in seconds)
586  */
587 #if defined(CONFIG_NET_IPV6_PE)
588 void net_ipv6_pe_start(struct net_if *iface, const struct in6_addr *prefix,
589 		       uint32_t vlifetime, uint32_t preferred_lifetime);
590 
591 #else
net_ipv6_pe_start(struct net_if * iface,const struct in6_addr * prefix,uint32_t vlifetime,uint32_t preferred_lifetime)592 static inline void net_ipv6_pe_start(struct net_if *iface,
593 				     const struct in6_addr *prefix,
594 				     uint32_t vlifetime,
595 				     uint32_t preferred_lifetime)
596 {
597 	ARG_UNUSED(iface);
598 	ARG_UNUSED(prefix);
599 	ARG_UNUSED(vlifetime);
600 	ARG_UNUSED(preferred_lifetime);
601 }
602 #endif /* CONFIG_NET_IPV6_PE */
603 
604 /**
605  * @brief Check if maximum number of Duplicate Address Detection (DAD) requests
606  *        have been done.
607  *
608  * @param count Number of DAD requests done.
609  *
610  * @return Return True if DAD can continue, False if max amount of DAD
611  *         requests have been done.
612  */
613 #if defined(CONFIG_NET_IPV6_PE)
614 bool net_ipv6_pe_check_dad(int count);
615 #else
net_ipv6_pe_check_dad(int count)616 static inline bool net_ipv6_pe_check_dad(int count)
617 {
618 	ARG_UNUSED(count);
619 
620 	return false;
621 }
622 #endif /* CONFIG_NET_IPV6_PE */
623 
624 /**
625  * @brief Initialize IPv6 privacy extension support for a network interface.
626  *
627  * @param iface Network interface
628  *
629  * @return Return 0 if ok or <0 if there is an error.
630  */
631 #if defined(CONFIG_NET_IPV6_PE)
632 int net_ipv6_pe_init(struct net_if *iface);
633 #else
net_ipv6_pe_init(struct net_if * iface)634 static inline int net_ipv6_pe_init(struct net_if *iface)
635 {
636 	iface->pe_enabled = false;
637 	iface->pe_prefer_public = false;
638 
639 	return 0;
640 }
641 #endif /* CONFIG_NET_IPV6_PE */
642 
643 typedef void (*net_ipv6_pe_filter_cb_t)(struct in6_addr *prefix,
644 					bool is_blacklist,
645 					void *user_data);
646 
647 /**
648  * @brief Go through all the IPv6 privacy extension filters and call callback
649  * for each IPv6 prefix.
650  *
651  * @param cb User supplied callback function to call.
652  * @param user_data User specified data.
653  *
654  * @return Total number of filters found.
655  */
656 #if defined(CONFIG_NET_IPV6_PE)
657 int net_ipv6_pe_filter_foreach(net_ipv6_pe_filter_cb_t cb, void *user_data);
658 #else
net_ipv6_pe_filter_foreach(net_ipv6_pe_filter_cb_t cb,void * user_data)659 static inline int net_ipv6_pe_filter_foreach(net_ipv6_pe_filter_cb_t cb,
660 					     void *user_data)
661 {
662 	ARG_UNUSED(cb);
663 	ARG_UNUSED(user_data);
664 
665 	return 0;
666 }
667 #endif
668 
669 #endif /* __IPV6_H */
670