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 Join a given multicast group.
203 *
204 * @param iface Network interface where join message is sent
205 * @param addr Multicast group to join
206 *
207 * @return Return 0 if joining was done, <0 otherwise.
208 */
209 #if defined(CONFIG_NET_IPV6_MLD)
210 int net_ipv6_mld_join(struct net_if *iface, const struct in6_addr *addr);
211 #else
212 static inline int
net_ipv6_mld_join(struct net_if * iface,const struct in6_addr * addr)213 net_ipv6_mld_join(struct net_if *iface, const struct in6_addr *addr)
214 {
215 ARG_UNUSED(iface);
216 ARG_UNUSED(addr);
217
218 return -ENOTSUP;
219 }
220 #endif /* CONFIG_NET_IPV6_MLD */
221
222 /**
223 * @brief Leave a given multicast group.
224 *
225 * @param iface Network interface where leave message is sent
226 * @param addr Multicast group to leave
227 *
228 * @return Return 0 if leaving is done, <0 otherwise.
229 */
230 #if defined(CONFIG_NET_IPV6_MLD)
231 int net_ipv6_mld_leave(struct net_if *iface, const struct in6_addr *addr);
232 #else
233 static inline int
net_ipv6_mld_leave(struct net_if * iface,const struct in6_addr * addr)234 net_ipv6_mld_leave(struct net_if *iface, const struct in6_addr *addr)
235 {
236 ARG_UNUSED(iface);
237 ARG_UNUSED(addr);
238
239 return -ENOTSUP;
240 }
241 #endif /* CONFIG_NET_IPV6_MLD */
242
243 /**
244 * @brief Send MLDv2 report message with a single entry.
245 *
246 * @param iface Network interface where message is sent
247 * @param addr Multicast group
248 * @param mode MLDv2 mode (NET_IPV6_MLDv2_MODE_IS_INCLUDE NET_IPV6_MLDv2_MODE_IS_EXCLUDE)
249 *
250 * @return Return 0 if leaving is done, <0 otherwise.
251 */
252 #if defined(CONFIG_NET_IPV6_MLD)
253 int net_ipv6_mld_send_single(struct net_if *iface, const struct in6_addr *addr, uint8_t mode);
254 #else
255 static inline int
net_ipv6_mld_send_single(struct net_if * iface,const struct in6_addr * addr,uint8_t mode)256 net_ipv6_mld_send_single(struct net_if *iface, const struct in6_addr *addr, uint8_t mode)
257 {
258 ARG_UNUSED(iface);
259 ARG_UNUSED(addr);
260 ARG_UNUSED(mode);
261
262 return -ENOTSUP;
263 }
264 #endif /* CONFIG_NET_IPV6_MLD */
265
266 /**
267 * @typedef net_nbr_cb_t
268 * @brief Callback used while iterating over neighbors.
269 *
270 * @param nbr A valid pointer on current neighbor.
271 * @param user_data A valid pointer on some user data or NULL
272 */
273 typedef void (*net_nbr_cb_t)(struct net_nbr *nbr, void *user_data);
274
275 /**
276 * @brief Make sure the link layer address is set according to
277 * destination address. If the ll address is not yet known, then
278 * start neighbor discovery to find it out. If ND needs to be done
279 * then the returned packet is the Neighbor Solicitation message
280 * and the original message is sent after Neighbor Advertisement
281 * message is received.
282 *
283 * @param pkt Network packet
284 *
285 * @return Return a verdict.
286 */
287 #if defined(CONFIG_NET_IPV6_NBR_CACHE) && defined(CONFIG_NET_NATIVE_IPV6)
288 enum net_verdict net_ipv6_prepare_for_send(struct net_pkt *pkt);
289 #else
net_ipv6_prepare_for_send(struct net_pkt * pkt)290 static inline enum net_verdict net_ipv6_prepare_for_send(struct net_pkt *pkt)
291 {
292 return NET_OK;
293 }
294 #endif
295
296 /**
297 * @brief Lock IPv6 Neighbor table mutex
298 *
299 * Neighbor table mutex is used by IPv6 Neighbor cache and IPv6 Routing module.
300 * Mutex shall be held whenever accessing or manipulating neighbor or routing
301 * table entries (for example when obtaining a pointer to the neighbor table
302 * entry). Neighbor and Routing API functions will lock the mutex when called.
303 */
304 void net_ipv6_nbr_lock(void);
305
306 /**
307 * @brief Unlock IPv6 Neighbor table mutex
308 */
309 void net_ipv6_nbr_unlock(void);
310
311 /**
312 * @brief Look for a neighbor from it's address on an iface
313 *
314 * @param iface A valid pointer on a network interface
315 * @param addr The IPv6 address to match
316 *
317 * @return A valid pointer on a neighbor on success, NULL otherwise
318 */
319 #if defined(CONFIG_NET_IPV6_NBR_CACHE) && defined(CONFIG_NET_NATIVE_IPV6)
320 struct net_nbr *net_ipv6_nbr_lookup(struct net_if *iface,
321 struct in6_addr *addr);
322 #else
net_ipv6_nbr_lookup(struct net_if * iface,struct in6_addr * addr)323 static inline struct net_nbr *net_ipv6_nbr_lookup(struct net_if *iface,
324 struct in6_addr *addr)
325 {
326 return NULL;
327 }
328 #endif
329
330 /**
331 * @brief Get neighbor from its index.
332 *
333 * @param iface Network interface to match. If NULL, then use
334 * whatever interface there is configured for the neighbor address.
335 * @param idx Index of the link layer address in the address array
336 *
337 * @return A valid pointer on a neighbor on success, NULL otherwise
338 */
339 struct net_nbr *net_ipv6_get_nbr(struct net_if *iface, uint8_t idx);
340
341 /**
342 * @brief Look for a neighbor from it's link local address index
343 *
344 * @param iface Network interface to match. If NULL, then use
345 * whatever interface there is configured for the neighbor address.
346 * @param idx Index of the link layer address in the address array
347 *
348 * @return A valid pointer on a neighbor on success, NULL otherwise
349 */
350 #if defined(CONFIG_NET_IPV6_NBR_CACHE) && defined(CONFIG_NET_NATIVE_IPV6)
351 struct in6_addr *net_ipv6_nbr_lookup_by_index(struct net_if *iface,
352 uint8_t idx);
353 #else
354 static inline
net_ipv6_nbr_lookup_by_index(struct net_if * iface,uint8_t idx)355 struct in6_addr *net_ipv6_nbr_lookup_by_index(struct net_if *iface,
356 uint8_t idx)
357 {
358 return NULL;
359 }
360 #endif
361
362 /**
363 * @brief Add a neighbor to neighbor cache
364 *
365 * Add a neighbor to the cache after performing a lookup and in case
366 * there exists an entry in the cache update its state and lladdr.
367 *
368 * @param iface A valid pointer on a network interface
369 * @param addr Neighbor IPv6 address
370 * @param lladdr Neighbor link layer address
371 * @param is_router Set to true if the neighbor is a router, false
372 * otherwise
373 * @param state Initial state of the neighbor entry in the cache
374 *
375 * @return A valid pointer on a neighbor on success, NULL otherwise
376 */
377 #if defined(CONFIG_NET_IPV6_NBR_CACHE) && defined(CONFIG_NET_NATIVE_IPV6)
378 struct net_nbr *net_ipv6_nbr_add(struct net_if *iface,
379 const struct in6_addr *addr,
380 const struct net_linkaddr *lladdr,
381 bool is_router,
382 enum net_ipv6_nbr_state state);
383 #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)384 static inline struct net_nbr *net_ipv6_nbr_add(struct net_if *iface,
385 const struct in6_addr *addr,
386 const struct net_linkaddr *lladdr,
387 bool is_router,
388 enum net_ipv6_nbr_state state)
389 {
390 return NULL;
391 }
392 #endif
393
394 /**
395 * @brief Remove a neighbor from neighbor cache.
396 *
397 * @param iface A valid pointer on a network interface
398 * @param addr Neighbor IPv6 address
399 *
400 * @return True if neighbor could be removed, False otherwise
401 */
402 #if defined(CONFIG_NET_IPV6_NBR_CACHE) && defined(CONFIG_NET_NATIVE_IPV6)
403 bool net_ipv6_nbr_rm(struct net_if *iface, struct in6_addr *addr);
404 #else
net_ipv6_nbr_rm(struct net_if * iface,struct in6_addr * addr)405 static inline bool net_ipv6_nbr_rm(struct net_if *iface, struct in6_addr *addr)
406 {
407 return true;
408 }
409 #endif
410
411 /**
412 * @brief Go through all the neighbors and call callback for each of them.
413 *
414 * @param cb User supplied callback function to call.
415 * @param user_data User specified data.
416 */
417 #if defined(CONFIG_NET_IPV6_NBR_CACHE) && defined(CONFIG_NET_NATIVE_IPV6)
418 void net_ipv6_nbr_foreach(net_nbr_cb_t cb, void *user_data);
419 #else /* CONFIG_NET_IPV6_NBR_CACHE */
net_ipv6_nbr_foreach(net_nbr_cb_t cb,void * user_data)420 static inline void net_ipv6_nbr_foreach(net_nbr_cb_t cb, void *user_data)
421 {
422 return;
423 }
424 #endif /* CONFIG_NET_IPV6_NBR_CACHE */
425
426 /**
427 * @brief Provide a reachability hint for IPv6 Neighbor Discovery.
428 *
429 * This function is intended for upper-layer protocols to inform the IPv6
430 * Neighbor Discovery process about the active link to a specific neighbor.
431 * By signaling recent "forward progress" event, such as the reception of
432 * an ACK, this function can help reducing unnecessary ND traffic as per the
433 * guidelines in RFC 4861 (section 7.3).
434 *
435 * @param iface A pointer to the network interface.
436 * @param ipv6_addr Pointer to the IPv6 address of the neighbor node.
437 */
438 #if defined(CONFIG_NET_IPV6_ND) && defined(CONFIG_NET_NATIVE_IPV6)
439 void net_ipv6_nbr_reachability_hint(struct net_if *iface, const struct in6_addr *ipv6_addr);
440 #else
net_ipv6_nbr_reachability_hint(struct net_if * iface,const struct in6_addr * ipv6_addr)441 static inline void net_ipv6_nbr_reachability_hint(struct net_if *iface,
442 const struct in6_addr *ipv6_addr)
443 {
444 ARG_UNUSED(iface);
445 ARG_UNUSED(ipv6_addr);
446 }
447 #endif
448
449 /**
450 * @brief Set the neighbor reachable timer.
451 *
452 * @param iface A valid pointer on a network interface
453 * @param nbr Neighbor struct pointer
454 */
455 #if defined(CONFIG_NET_IPV6_ND) && defined(CONFIG_NET_NATIVE_IPV6)
456 void net_ipv6_nbr_set_reachable_timer(struct net_if *iface,
457 struct net_nbr *nbr);
458
459 #else /* CONFIG_NET_IPV6_ND */
net_ipv6_nbr_set_reachable_timer(struct net_if * iface,struct net_nbr * nbr)460 static inline void net_ipv6_nbr_set_reachable_timer(struct net_if *iface,
461 struct net_nbr *nbr)
462 {
463 }
464 #endif
465
466 #if defined(CONFIG_NET_IPV6_FRAGMENT)
467 /** Store pending IPv6 fragment information that is needed for reassembly. */
468 struct net_ipv6_reassembly {
469 /** IPv6 source address of the fragment */
470 struct in6_addr src;
471
472 /** IPv6 destination address of the fragment */
473 struct in6_addr dst;
474
475 /**
476 * Timeout for cancelling the reassembly. The timer is used
477 * also to detect if this reassembly slot is used or not.
478 */
479 struct k_work_delayable timer;
480
481 /** Pointers to pending fragments */
482 struct net_pkt *pkt[CONFIG_NET_IPV6_FRAGMENT_MAX_PKT];
483
484 /** IPv6 fragment identification */
485 uint32_t id;
486 };
487 #else
488 struct net_ipv6_reassembly;
489 #endif
490
491 /**
492 * @typedef net_ipv6_frag_cb_t
493 * @brief Callback used while iterating over pending IPv6 fragments.
494 *
495 * @param reass IPv6 fragment reassembly struct
496 * @param user_data A valid pointer on some user data or NULL
497 */
498 typedef void (*net_ipv6_frag_cb_t)(struct net_ipv6_reassembly *reass,
499 void *user_data);
500
501 /**
502 * @brief Go through all the currently pending IPv6 fragments.
503 *
504 * @param cb Callback to call for each pending IPv6 fragment.
505 * @param user_data User specified data or NULL.
506 */
507 void net_ipv6_frag_foreach(net_ipv6_frag_cb_t cb, void *user_data);
508
509 /**
510 * @brief Find the last IPv6 extension header in the network packet.
511 *
512 * @param pkt Network head packet.
513 * @param next_hdr_off Offset of the next header field that points
514 * to last header. This is returned to caller.
515 * @param last_hdr_off Offset of the last header field in the packet.
516 * This is returned to caller.
517 *
518 * @return 0 on success, a negative errno otherwise.
519 */
520 int net_ipv6_find_last_ext_hdr(struct net_pkt *pkt, uint16_t *next_hdr_off,
521 uint16_t *last_hdr_off);
522
523 /**
524 * @brief Handles IPv6 fragmented packets.
525 *
526 * @param pkt Network head packet.
527 * @param hdr The IPv6 header of the current packet
528 * @param nexthdr IPv6 next header after fragment header part
529 *
530 * @return Return verdict about the packet
531 */
532 #if defined(CONFIG_NET_IPV6_FRAGMENT) && defined(CONFIG_NET_NATIVE_IPV6)
533 enum net_verdict net_ipv6_handle_fragment_hdr(struct net_pkt *pkt,
534 struct net_ipv6_hdr *hdr,
535 uint8_t nexthdr);
536 #else
537 static inline
net_ipv6_handle_fragment_hdr(struct net_pkt * pkt,struct net_ipv6_hdr * hdr,uint8_t nexthdr)538 enum net_verdict net_ipv6_handle_fragment_hdr(struct net_pkt *pkt,
539 struct net_ipv6_hdr *hdr,
540 uint8_t nexthdr)
541 {
542 ARG_UNUSED(pkt);
543 ARG_UNUSED(hdr);
544 ARG_UNUSED(nexthdr);
545
546 return NET_DROP;
547 }
548 #endif /* CONFIG_NET_IPV6_FRAGMENT */
549
550 #if defined(CONFIG_NET_NATIVE_IPV6)
551 void net_ipv6_init(void);
552 void net_ipv6_nbr_init(void);
553 #if defined(CONFIG_NET_IPV6_MLD)
554 void net_ipv6_mld_init(void);
555 #else
556 #define net_ipv6_mld_init(...)
557 #endif
558 #else
559 #define net_ipv6_init(...)
560 #define net_ipv6_nbr_init(...)
561 #endif
562
563 /**
564 * @brief Decode DSCP value from TC field.
565 *
566 * @param tc TC field value from the IPv6 header.
567 *
568 * @return Decoded DSCP value.
569 */
net_ipv6_get_dscp(uint8_t tc)570 static inline uint8_t net_ipv6_get_dscp(uint8_t tc)
571 {
572 return (tc & NET_IPV6_DSCP_MASK) >> NET_IPV6_DSCP_OFFSET;
573 }
574
575 /**
576 * @brief Encode DSCP value into TC field.
577 *
578 * @param tc A pointer to the TC field.
579 * @param dscp DSCP value to set.
580 */
net_ipv6_set_dscp(uint8_t * tc,uint8_t dscp)581 static inline void net_ipv6_set_dscp(uint8_t *tc, uint8_t dscp)
582 {
583 *tc &= ~NET_IPV6_DSCP_MASK;
584 *tc |= (dscp << NET_IPV6_DSCP_OFFSET) & NET_IPV6_DSCP_MASK;
585 }
586
587 /**
588 * @brief Convert DSCP value to priority.
589 *
590 * @param dscp DSCP value.
591 */
net_ipv6_dscp_to_priority(uint8_t dscp)592 static inline uint8_t net_ipv6_dscp_to_priority(uint8_t dscp)
593 {
594 return dscp >> 3;
595 }
596
597 /**
598 * @brief Decode ECN value from TC field.
599 *
600 * @param tc TC field value from the IPv6 header.
601 *
602 * @return Decoded ECN value.
603 */
net_ipv6_get_ecn(uint8_t tc)604 static inline uint8_t net_ipv6_get_ecn(uint8_t tc)
605 {
606 return tc & NET_IPV6_ECN_MASK;
607 }
608
609 /**
610 * @brief Encode ECN value into TC field.
611 *
612 * @param tc A pointer to the TC field.
613 * @param ecn ECN value to set.
614 */
net_ipv6_set_ecn(uint8_t * tc,uint8_t ecn)615 static inline void net_ipv6_set_ecn(uint8_t *tc, uint8_t ecn)
616 {
617 *tc &= ~NET_IPV6_ECN_MASK;
618 *tc |= ecn & NET_IPV6_ECN_MASK;
619 }
620
621 /**
622 * @brief Start IPv6 privacy extension procedure.
623 *
624 * @param iface Interface to use.
625 * @param prefix IPv6 prefix to use.
626 * @param vlifetime Lifetime of this IPv6 prefix (in seconds).
627 * @param preferred_lifetime Preferred lifetime of this IPv6 prefix (in seconds)
628 */
629 #if defined(CONFIG_NET_IPV6_PE)
630 void net_ipv6_pe_start(struct net_if *iface, const struct in6_addr *prefix,
631 uint32_t vlifetime, uint32_t preferred_lifetime);
632
633 #else
net_ipv6_pe_start(struct net_if * iface,const struct in6_addr * prefix,uint32_t vlifetime,uint32_t preferred_lifetime)634 static inline void net_ipv6_pe_start(struct net_if *iface,
635 const struct in6_addr *prefix,
636 uint32_t vlifetime,
637 uint32_t preferred_lifetime)
638 {
639 ARG_UNUSED(iface);
640 ARG_UNUSED(prefix);
641 ARG_UNUSED(vlifetime);
642 ARG_UNUSED(preferred_lifetime);
643 }
644 #endif /* CONFIG_NET_IPV6_PE */
645
646 /**
647 * @brief Check if maximum number of Duplicate Address Detection (DAD) requests
648 * have been done.
649 *
650 * @param count Number of DAD requests done.
651 *
652 * @return Return True if DAD can continue, False if max amount of DAD
653 * requests have been done.
654 */
655 #if defined(CONFIG_NET_IPV6_PE)
656 bool net_ipv6_pe_check_dad(int count);
657 #else
net_ipv6_pe_check_dad(int count)658 static inline bool net_ipv6_pe_check_dad(int count)
659 {
660 ARG_UNUSED(count);
661
662 return false;
663 }
664 #endif /* CONFIG_NET_IPV6_PE */
665
666 /**
667 * @brief Initialize IPv6 privacy extension support for a network interface.
668 *
669 * @param iface Network interface
670 *
671 * @return Return 0 if ok or <0 if there is an error.
672 */
673 #if defined(CONFIG_NET_IPV6_PE)
674 int net_ipv6_pe_init(struct net_if *iface);
675 #else
net_ipv6_pe_init(struct net_if * iface)676 static inline int net_ipv6_pe_init(struct net_if *iface)
677 {
678 iface->pe_enabled = false;
679 iface->pe_prefer_public = false;
680
681 return 0;
682 }
683 #endif /* CONFIG_NET_IPV6_PE */
684
685 typedef void (*net_ipv6_pe_filter_cb_t)(struct in6_addr *prefix,
686 bool is_blacklist,
687 void *user_data);
688
689 /**
690 * @brief Go through all the IPv6 privacy extension filters and call callback
691 * for each IPv6 prefix.
692 *
693 * @param cb User supplied callback function to call.
694 * @param user_data User specified data.
695 *
696 * @return Total number of filters found.
697 */
698 #if defined(CONFIG_NET_IPV6_PE)
699 int net_ipv6_pe_filter_foreach(net_ipv6_pe_filter_cb_t cb, void *user_data);
700 #else
net_ipv6_pe_filter_foreach(net_ipv6_pe_filter_cb_t cb,void * user_data)701 static inline int net_ipv6_pe_filter_foreach(net_ipv6_pe_filter_cb_t cb,
702 void *user_data)
703 {
704 ARG_UNUSED(cb);
705 ARG_UNUSED(user_data);
706
707 return 0;
708 }
709 #endif
710
711 #endif /* __IPV6_H */
712