Loading...
Searching...
No Matches
gnrc_ipv6_auto_subnets.c
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021 ML!PA Consulting GmbH
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
98
99#include "compiler_hints.h"
100#include "macros/utils.h"
101#include "net/gnrc/ipv6.h"
102#include "net/gnrc/netif.h"
103#include "net/gnrc/netif/hdr.h"
104#include "net/gnrc/udp.h"
105#include "net/gnrc/ipv6/nib.h"
106#include "net/gnrc/ndp.h"
107#include "net/gnrc/rpl.h"
108#include "random.h"
109#include "xtimer.h"
110
114#ifndef CONFIG_GNRC_IPV6_AUTO_SUBNETS_PORT
115#define CONFIG_GNRC_IPV6_AUTO_SUBNETS_PORT (16179)
116#endif
117
121#ifndef CONFIG_GNRC_IPV6_AUTO_SUBNETS_PEERS_MAX
122#define CONFIG_GNRC_IPV6_AUTO_SUBNETS_PEERS_MAX (4)
123#endif
124
128#ifndef CONFIG_GNRC_IPV6_AUTO_SUBNETS_TX_PER_PERIOD
129#define CONFIG_GNRC_IPV6_AUTO_SUBNETS_TX_PER_PERIOD (3)
130#endif
131
136#ifndef CONFIG_GNRC_IPV6_AUTO_SUBNETS_TIMEOUT_MS
137#define CONFIG_GNRC_IPV6_AUTO_SUBNETS_TIMEOUT_MS (50)
138#endif
139
149#ifndef CONFIG_GNRC_IPV6_AUTO_SUBNETS_PREFIX_FIX_LEN
150#define CONFIG_GNRC_IPV6_AUTO_SUBNETS_PREFIX_FIX_LEN (0)
151#endif
152
157#ifndef CONFIG_GNRC_IPV6_AUTO_SUBNETS_PREFIX_MIN_LEN
158#define CONFIG_GNRC_IPV6_AUTO_SUBNETS_PREFIX_MIN_LEN (0)
159#endif
160
170#ifndef CONFIG_GNRC_IPV6_AUTO_SUBNETS_NUMOF
171#define CONFIG_GNRC_IPV6_AUTO_SUBNETS_NUMOF (1)
172#endif
173
182#ifndef CONFIG_GNRC_IPV6_AUTO_SUBNETS_STATIC
183#define CONFIG_GNRC_IPV6_AUTO_SUBNETS_STATIC (0)
184#endif
185
186/* Code below should not be included by Doxygen */
187#ifndef DOXYGEN
188
189#define SERVER_THREAD_STACKSIZE (THREAD_STACKSIZE_DEFAULT)
190#define SERVER_MSG_QUEUE_SIZE (CONFIG_GNRC_IPV6_AUTO_SUBNETS_PEERS_MAX)
191#define SERVER_MSG_TYPE_TIMEOUT (0x8fae)
192
193#define ENABLE_DEBUG 0
194#include "debug.h"
195
196static char addr_str[IPV6_ADDR_MAX_STR_LEN];
197
198#if !IS_USED(MODULE_GNRC_IPV6_AUTO_SUBNETS_SIMPLE)
199
203typedef struct __attribute__((packed)) {
204 uint8_t version;
205 uint8_t num_subnets;
206} _auto_subnets_request_v0_t;
207
208/* keep a copy of PIO information in memory */
209static gnrc_netif_t *_upstream;
211static mutex_t _pio_cache_lock;
212
213static char auto_subnets_stack[SERVER_THREAD_STACKSIZE];
214static msg_t server_queue[SERVER_MSG_QUEUE_SIZE];
215
216/* store neighbor routers l2 address to ignore duplicate packets */
217static uint8_t l2addrs[CONFIG_GNRC_IPV6_AUTO_SUBNETS_PEERS_MAX]
219
220/* PID of the event thread */
221static kernel_pid_t _server_pid;
222
223static bool _store_pio(const ndp_opt_pi_t *pio)
224{
225 mutex_lock(&_pio_cache_lock);
226
227 for (unsigned i = 0; i < ARRAY_SIZE(_pio_cache); ++i) {
228 if (_pio_cache[i].len == 0) {
229 _pio_cache[i] = *pio;
230
231 mutex_unlock(&_pio_cache_lock);
232 return true;
233 }
234 }
235
236 mutex_unlock(&_pio_cache_lock);
237 return false;
238}
239
240static int _send_udp(gnrc_netif_t *netif, const ipv6_addr_t *addr,
241 uint16_t port, const void *data, size_t len)
242{
243 gnrc_pktsnip_t *payload, *udp, *ip;
244
245 /* allocate payload */
246 payload = gnrc_pktbuf_add(NULL, data, len, GNRC_NETTYPE_UNDEF);
247 if (payload == NULL) {
248 DEBUG("auto_subnets: unable to copy data to packet buffer\n");
249 return -ENOBUFS;
250 }
251
252 /* allocate UDP header, set source port := destination port */
253 udp = gnrc_udp_hdr_build(payload, port, port);
254 if (udp == NULL) {
255 DEBUG("auto_subnets: unable to allocate UDP header\n");
256 gnrc_pktbuf_release(payload);
257 return -ENOBUFS;
258 }
259
260 /* allocate IPv6 header */
261 ip = gnrc_ipv6_hdr_build(udp, NULL, addr);
262 if (ip == NULL) {
263 DEBUG("auto_subnets: unable to allocate IPv6 header\n");
265 return -ENOBUFS;
266 }
267
268 /* add netif header, if interface was given */
269 if (netif != NULL) {
270 gnrc_pktsnip_t *netif_hdr = gnrc_netif_hdr_build(NULL, 0, NULL, 0);
271 if (netif_hdr == NULL) {
272 DEBUG("auto_subnets: unable to allocate netif header\n");
274 return -ENOBUFS;
275 }
276
277 gnrc_netif_hdr_set_netif(netif_hdr->data, netif);
278 ip = gnrc_pkt_prepend(ip, netif_hdr);
279 }
280
281 /* send packet */
284 DEBUG("auto_subnets: unable to locate UDP thread\n");
286 return -ENETUNREACH;
287 }
288
289 return 0;
290}
291#endif /* !IS_USED(MODULE_GNRC_IPV6_AUTO_SUBNETS_SIMPLE) */
292
293static void _init_sub_prefix(ipv6_addr_t *out,
294 const ipv6_addr_t *prefix, uint8_t bits,
295 uint8_t idx, uint8_t idx_bits)
296{
297 uint8_t bytes = bits / 8;
298 uint8_t rem = bits % 8;
299 int8_t shift = 8 - rem - idx_bits;
300
301 /* first copy old prefix */
302 memset(out, 0, sizeof(*out));
303 ipv6_addr_init_prefix(out, prefix, bits);
304
305 /* if new bits are between bytes, first copy over the most significant bits */
306 if (shift < 0) {
307 out->u8[bytes] |= idx >> -shift;
308 out->u8[++bytes] = 0;
309 shift += 8;
310 }
311
312 /* shift remaining bits at the end of the prefix */
313 out->u8[bytes] |= idx << shift;
314}
315
316static uint8_t _init_sub_prefix_eui(ipv6_addr_t *out,
317 const ipv6_addr_t *prefix, uint8_t bits,
318 const uint8_t *eui, uint8_t eui_len)
319{
320 assert(eui_len <= sizeof(uint64_t));
321
322 /* If the EUI is too large, discard most significant bits as
323 those are typically manufacturer ID */
324 uint64_t mask = UINT64_MAX >> bits;
325
326 union {
327 uint64_t u64;
328 uint8_t u8[8];
329 } eui64 = {};
330 uint64_t pfx = byteorder_ntohll(prefix->u64[0]);
331
332 /* If EUI is small, we want to preserve leftover unused bits at the end */
333 uint8_t bits_total = bits + 8 * eui_len;
334 uint8_t shift = bits_total < 64
335 ? 64 - bits_total
336 : 0;
337
338 /* treat EUI as a EUI-64 with unused bytes set to 0 */
339 memcpy(&eui64.u8[sizeof(uint64_t) - eui_len], eui, eui_len);
340 eui64.u64 = ntohll(eui64.u64) & mask;
341
342 /* create downstream prefix from upstream prefix + masked EUI64 */
343 out->u64[0] = byteorder_htonll(pfx | (eui64.u64 << shift));
344
345 /* we don't create prefixes that longer than 64 bits */
346 return MIN(64, bits_total);
347}
348
349/* returns true if a new prefix was added, false if nothing changed */
350static bool _remove_old_prefix(gnrc_netif_t *netif,
351 const ipv6_addr_t *pfx, uint8_t pfx_len,
352 gnrc_pktsnip_t **ext_opts)
353{
354 gnrc_ipv6_nib_pl_t entry;
355 gnrc_pktsnip_t *tmp;
356 void *state = NULL;
357 ipv6_addr_t old_pfx;
359
360 /* iterate prefix list to see if the prefix already exists */
361 while (gnrc_ipv6_nib_pl_iter(netif->pid, &state, &entry)) {
362 uint8_t match_len = ipv6_addr_match_prefix(&entry.pfx, pfx);
363
364 /* The prefix did not change - nothing to do here */
365 if (match_len >= pfx_len && pfx_len == entry.pfx_len) {
366 return false;
367 }
368
369 /* find prefix that is closest to the new prefix */
370 if (match_len > old_pfx_len) {
371 old_pfx_len = entry.pfx_len;
372 old_pfx = entry.pfx;
373 }
374 }
375
376 /* no prefix found */
378 return true;
379 }
380
381 DEBUG("auto_subnets: remove old prefix %s/%u\n",
382 ipv6_addr_to_str(addr_str, &old_pfx, sizeof(addr_str)), old_pfx_len);
383
384 /* invalidate old prefix in RIO */
385 tmp = gnrc_ndp_opt_ri_build(&old_pfx, old_pfx_len, 0,
386 NDP_OPT_RI_FLAGS_PRF_ZERO, *ext_opts);
387 if (tmp) {
388 *ext_opts = tmp;
389 }
390
391 /* remove the prefix */
392 gnrc_ipv6_nib_pl_del(netif->pid, &old_pfx, old_pfx_len);
393
394 return true;
395}
396
397static void _configure_subnets(uint8_t subnets, uint8_t start_idx, gnrc_netif_t *upstream,
398 const ndp_opt_pi_t *pio, const ipv6_addr_t *src)
399{
400 gnrc_netif_t *downstream = NULL;
401 gnrc_pktsnip_t *ext_opts = NULL;
402 const ipv6_addr_t *prefix = &pio->prefix;
403 uint32_t valid_ltime = byteorder_ntohl(pio->valid_ltime);
404 uint32_t pref_ltime = byteorder_ntohl(pio->pref_ltime);
405 const uint8_t prefix_len = pio->prefix_len;
406 uint8_t new_prefix_len, subnet_len;
407
408 DEBUG("auto_subnets: create %u subnets, start with %u\n", subnets, start_idx);
409
410 /* Calculate remaining prefix length.
411 * For n subnets we consume floor(log_2 n) + 1 bits.
412 * To calculate floor(log_2 n) quickly, find the position of the
413 * most significant set bit by counting leading zeros.
414 */
415 subnet_len = 32 - __builtin_clz(subnets);
416 new_prefix_len = prefix_len + subnet_len;
417
418 if (new_prefix_len > 64) {
419 DEBUG("auto_subnets: can't split /%u into %u subnets\n", prefix_len, subnets);
420 return;
421 }
422
425 }
426
427 while ((downstream = gnrc_netif_iter(downstream))) {
428 gnrc_pktsnip_t *tmp;
429 ipv6_addr_t new_prefix;
430 int idx;
431
432 if (downstream == upstream) {
433 continue;
434 }
435
436 /* create subnet from upstream prefix */
437 if (IS_USED(MODULE_GNRC_IPV6_AUTO_SUBNETS_EUI)) {
438 uint8_t hwaddr[GNRC_NETIF_L2ADDR_MAXLEN];
439 int hwaddr_len = netif_get_opt(&downstream->netif, NETOPT_ADDRESS, 0,
440 hwaddr, sizeof(hwaddr));
441 if (hwaddr_len <= 0) {
442 DEBUG("auto_subnets: can't get l2 address from netif %u\n", downstream->pid);
443 continue;
444 }
445 new_prefix_len = _init_sub_prefix_eui(&new_prefix, prefix, prefix_len, hwaddr, hwaddr_len);
446 new_prefix_len = MAX(new_prefix_len, CONFIG_GNRC_IPV6_AUTO_SUBNETS_PREFIX_MIN_LEN);
447 } else {
448 _init_sub_prefix(&new_prefix, prefix, prefix_len, ++start_idx, subnet_len);
449 }
450
451 DEBUG("auto_subnets: configure prefix %s/%u on %u\n",
452 ipv6_addr_to_str(addr_str, &new_prefix, sizeof(addr_str)),
453 new_prefix_len, downstream->pid);
454
455 /* first remove old prefix if the prefix changed */
456 if (_remove_old_prefix(downstream, &new_prefix, new_prefix_len, &ext_opts)) {
457
458 /* configure subnet on downstream interface */
459 idx = gnrc_netif_ipv6_add_prefix(downstream, &new_prefix, new_prefix_len,
460 valid_ltime, pref_ltime);
461 if (idx < 0) {
462 DEBUG("auto_subnets: adding prefix to %u failed\n", downstream->pid);
463 continue;
464 }
465
466 /* start advertising subnet */
467 gnrc_ipv6_nib_change_rtr_adv_iface(downstream, true);
468
469 /* configure RPL root if applicable */
470 gnrc_rpl_configure_root(downstream, &downstream->ipv6.addrs[idx]);
471 }
472
473 /* add route information option with new subnet */
474 tmp = gnrc_ndp_opt_ri_build(&new_prefix, new_prefix_len, valid_ltime,
475 NDP_OPT_RI_FLAGS_PRF_ZERO, ext_opts);
476 if (tmp == NULL) {
477 DEBUG("auto_subnets: No space left in packet buffer. Not adding RIO\n");
478 } else {
479 ext_opts = tmp;
480 }
481 }
482
483 /* immediately send an RA with RIO */
484 if (ext_opts) {
485 gnrc_ndp_rtr_adv_send(upstream, NULL, src, true, ext_opts);
486 } else {
487 DEBUG("auto_subnets: Options empty, not sending RA\n");
488 }
489}
490
491void gnrc_ipv6_nib_rtr_adv_pio_cb(gnrc_netif_t *upstream, const ndp_opt_pi_t *pio,
492 const ipv6_addr_t *src)
493{
494 /* create a subnet for each downstream interface */
495 unsigned subnets = gnrc_netif_numof() - 1;
496
497 if (subnets == 0) {
498 return;
499 }
500
501 if (pio->valid_ltime.u32 == 0) {
502 return;
503 }
504
505 /* only consider prefix meant for autonomous address configuration */
506 if (!(pio->flags & NDP_OPT_PI_FLAGS_A)) {
507 return;
508 }
509
510#if IS_USED(MODULE_GNRC_IPV6_AUTO_SUBNETS_SIMPLE)
511 /* 'don't broadcast RA if we are a 6lo node - unicast allows l2 retransmissions */
512 if (!gnrc_netif_is_6ln(upstream)) {
513 src = NULL;
514 }
515 /* if we are the only router on this bus, we can directly choose a prefix */
516 _configure_subnets(subnets, 0, upstream, pio, src);
517#else
518 (void)src;
519
520 /* store PIO information for later use */
521 if (!_store_pio(pio)) {
522 DEBUG("auto_subnets: no space left in PIO cache, increase CONFIG_GNRC_IPV6_AUTO_SUBNETS_NUMOF\n");
523 return;
524 }
525 _upstream = upstream;
526
527 /* start advertising by sending timeout message to the server thread */
528 msg_t m = {
529 .type = SERVER_MSG_TYPE_TIMEOUT
530 };
531
532 msg_send(&m, _server_pid);
533#endif /* !IS_USED(MODULE_GNRC_IPV6_AUTO_SUBNETS_SIMPLE) */
534}
535
536#if !IS_USED(MODULE_GNRC_IPV6_AUTO_SUBNETS_SIMPLE)
545static bool _all_zero(const uint8_t *addr, size_t len)
546{
547 for (const uint8_t *end = addr + len; addr != end; ++addr) {
548 if (*addr) {
549 return false;
550 }
551 }
552 return true;
553}
554
565static int _alloc_l2addr_entry(const void *addr, size_t len)
566{
567 int empty = -1;
568 for (unsigned i = 0; i < CONFIG_GNRC_IPV6_AUTO_SUBNETS_PEERS_MAX; ++i) {
569 if (_all_zero(l2addrs[i], len)) {
570 empty = i;
571 continue;
572 }
573 if (memcmp(addr, l2addrs[i], len) == 0) {
574 return 0;
575 }
576 }
577
578 if (empty < 0) {
579 return -1;
580 }
581
582 memcpy(l2addrs[empty], addr, len);
583 return 1;
584}
585
601static int _get_my_l2addr_rank(gnrc_netif_t *iface, gnrc_pktsnip_t *pkt)
602{
603 const void *src_addr;
604 gnrc_pktsnip_t *netif_hdr;
605 gnrc_netif_hdr_t *hdr;
606
607 if (iface == NULL) {
608 return 0;
609 }
610
612 if (netif_hdr == NULL) {
613 return 0;
614 }
615
616 /* ignore packet if it was received on the wrong interface */
617 hdr = netif_hdr->data;
618 if (iface->pid != hdr->if_pid) {
619 return 0;
620 }
621
622 /* ignore packets without source address */
623 src_addr = gnrc_netif_hdr_get_src_addr(hdr);
624 if (src_addr == NULL) {
625 return 0;
626 }
627
628 /* check if we have seen the host before */
629 if (_alloc_l2addr_entry(src_addr, iface->l2addr_len) == 0) {
630 return 0;
631 }
632
633 return memcmp(iface->l2addr, src_addr, iface->l2addr_len);
634}
635
636static void _receive_announce(gnrc_pktsnip_t *pkt, uint8_t *subnets, uint8_t *idx_start)
637{
638 _auto_subnets_request_v0_t *request = pkt->data;
639
640 /* Check if we already got an announcement from that host, */
641 /* in this case, res will be 0. */
642 int res = _get_my_l2addr_rank(_upstream, pkt);
643 if (res) {
644 /* calculate total number of subnets */
645 *subnets += request->num_subnets;
646
647 DEBUG("auto_subnets: %u new remote subnets, total %u\n",
648 request->num_subnets, *subnets);
649
650 /* If other host is before us in order of MAC addresses, add
651 * their subnets to our offset */
652 if (res > 0) {
653 *idx_start += request->num_subnets;
654 }
655 }
656
658}
659
660static void _send_announce(uint8_t local_subnets, xtimer_t *timer, msg_t *msg)
661{
662 uint32_t timeout_us;
663 _auto_subnets_request_v0_t request = {
664 .num_subnets = local_subnets,
665 };
666
667 /* broadcast the number of subnets we want to create */
668 _send_udp(_upstream, &ipv6_addr_all_routers_link_local,
670 &request, sizeof(request));
671
672 /* configure timeout for resend */
673 timeout_us = random_uint32_range(
676 xtimer_set_msg(timer, timeout_us, msg, _server_pid);
677 DEBUG("auto_subnets: announce sent, next timeout in %" PRIu32 " µs\n", timeout_us);
678}
679
680static void _process_pio_cache(uint8_t subnets, uint8_t idx_start, gnrc_netif_t *upstream)
681{
682 mutex_lock(&_pio_cache_lock);
683
684 for (unsigned i = 0; i < ARRAY_SIZE(_pio_cache); ++i) {
685 if (!_pio_cache[i].len) {
686 continue;
687 }
688
689 /* use PIO for prefix configuration */
690 _configure_subnets(subnets, idx_start, upstream, &_pio_cache[i], NULL);
691
692 /* invalidate entry */
693 _pio_cache[i].len = 0;
694 }
695
696 mutex_unlock(&_pio_cache_lock);
697}
698
699static void *_eventloop(void *arg)
700{
701 (void)arg;
702
703 xtimer_t timeout_timer;
704 msg_t msg, timeout_msg = { .type = SERVER_MSG_TYPE_TIMEOUT };
706 const uint8_t local_subnets = gnrc_netif_numof() - 1;
707 uint8_t idx_start = 0;
708 uint8_t subnets = local_subnets;
710
711 /* only used with CONFIG_GNRC_IPV6_AUTO_SUBNETS_STATIC set */
712 uint8_t idx_old = 0;
713 uint8_t subnets_old = 0;
714
715 DEBUG("auto_subnets: %u local subnets\n", subnets);
716
717 if (subnets == 0) {
718 return NULL;
719 }
720
721 /* setup the message queue */
722 msg_init_queue(server_queue, SERVER_MSG_QUEUE_SIZE);
723
724 /* register server to receive messages from given port */
727
728 while (1) {
729 msg_receive(&msg);
730
731 switch (msg.type) {
733 _receive_announce(msg.content.ptr, &subnets, &idx_start);
734 break;
735 case SERVER_MSG_TYPE_TIMEOUT:
736 if (tx_period--) {
737 /* send subnet announcement */
738 _send_announce(local_subnets, &timeout_timer, &timeout_msg);
739 } else {
740
741 /* don't re-enumerate subnets of a downstream router goes down */
743 /* If we got less subnets than before, use the old value */
744 if (subnets < subnets_old) {
745 subnets = subnets_old;
746 idx_start = idx_old;
747 }
748 /* Store subnet high water mark for later use */
749 else {
750 subnets_old = subnets;
751 idx_old = idx_start;
752 }
753 }
754
755 /* config round done, configure subnets */
756 _process_pio_cache(subnets, idx_start, _upstream);
757
758 /* start a new round of counting */
760 memset(l2addrs, 0, sizeof(l2addrs));
761 idx_start = 0;
762 subnets = local_subnets;
763 }
764 break;
765 }
766 }
767
768 /* never reached */
769 return NULL;
770}
771
772void gnrc_ipv6_auto_subnets_init(void)
773{
774 /* initiate auto_subnets thread */
775 _server_pid = thread_create(auto_subnets_stack, sizeof(auto_subnets_stack),
777 _eventloop, NULL, "auto_subnets");
778}
779#endif /* !IS_USED(MODULE_GNRC_IPV6_AUTO_SUBNETS_SIMPLE) */
780#endif /* !DOXYGEN */
#define assert(cond)
abort the program if assertion is false
Definition assert.h:143
static uint64_t ntohll(uint64_t v)
Convert from network byte order to host byte order, 64 bit.
Definition byteorder.h:530
static uint32_t byteorder_ntohl(network_uint32_t v)
Convert from network byte order to host byte order, 32 bit.
Definition byteorder.h:495
static network_uint64_t byteorder_htonll(uint64_t v)
Convert from host byte order to network byte order, 64 bit.
Definition byteorder.h:483
static uint64_t byteorder_ntohll(network_uint64_t v)
Convert from network byte order to host byte order, 64 bit.
Definition byteorder.h:500
Common macros and compiler attributes/pragmas configuration.
static unsigned may_be_zero(unsigned n)
Wrapper function to silence "comparison is always false due to limited range of data type" ty...
#define ARRAY_SIZE(a)
Calculate the number of elements in a static array.
Definition container.h:79
Various helper macros.
#define MIN(a, b)
Get the minimum of the two parameters.
Definition utils.h:74
#define MAX(a, b)
Get the maximum of the two parameters.
Definition utils.h:64
Debug-header.
#define DEBUG(...)
Print debug information to stdout.
Definition debug.h:121
Definitions for GNRC's IPv6 implementation.
GNRC-specific neighbor discovery definitions.
Definition for GNRC's network interfaces.
UDP GNRC definition.
void msg_init_queue(msg_t *array, int num)
Initialize the current thread's message queue.
int msg_send(msg_t *m, kernel_pid_t target_pid)
Send a message (blocking).
int msg_receive(msg_t *m)
Receive a message.
int16_t kernel_pid_t
Unique process identifier.
Definition sched.h:134
#define KERNEL_PID_UNDEF
Canonical identifier for an invalid PID.
Definition sched.h:105
void mutex_unlock(mutex_t *mutex)
Unlocks the mutex.
static void mutex_lock(mutex_t *mutex)
Locks a mutex, blocking.
Definition mutex.h:202
kernel_pid_t thread_create(char *stack, int stacksize, uint8_t priority, int flags, thread_task_func_t task_func, void *arg, const char *name)
Creates a new thread.
static kernel_pid_t thread_getpid(void)
Returns the process ID of the currently running thread.
Definition thread.h:436
#define ENETUNREACH
Network unreachable.
Definition errno.h:108
#define ENOBUFS
No buffer space available.
Definition errno.h:110
#define CONFIG_GNRC_IPV6_AUTO_SUBNETS_PEERS_MAX
Max number of other routers on the same link.
#define CONFIG_GNRC_IPV6_AUTO_SUBNETS_TIMEOUT_MS
How long to wait for other routers announcements before resending or creating subnets when the retry ...
#define CONFIG_GNRC_IPV6_AUTO_SUBNETS_STATIC
Enable this if you have a static network that might experience high packet loss under certain conditi...
#define CONFIG_GNRC_IPV6_AUTO_SUBNETS_PORT
Port for the custom UDP sync protocol.
#define CONFIG_GNRC_IPV6_AUTO_SUBNETS_TX_PER_PERIOD
How often the number subnets should be announced by the routers.
#define CONFIG_GNRC_IPV6_AUTO_SUBNETS_PREFIX_MIN_LEN
Minimal length of a new prefix.
#define CONFIG_GNRC_IPV6_AUTO_SUBNETS_PREFIX_FIX_LEN
How many bits of a new prefix have to match the old prefix for it to be considered for replacement.
#define CONFIG_GNRC_IPV6_AUTO_SUBNETS_NUMOF
Number of subnets that can be configured.
gnrc_pktsnip_t * gnrc_ipv6_hdr_build(gnrc_pktsnip_t *payload, const ipv6_addr_t *src, const ipv6_addr_t *dst)
Builds an IPv6 header for sending and adds it to the packet buffer.
#define CONFIG_GNRC_IPV6_NIB_L2ADDR_MAX_LEN
Maximum link-layer address length (aligned)
Definition conf.h:278
bool gnrc_ipv6_nib_pl_iter(unsigned iface, void **state, gnrc_ipv6_nib_pl_t *ple)
Iterates over all prefix list entries in the NIB.
void gnrc_ipv6_nib_pl_del(unsigned iface, const ipv6_addr_t *pfx, unsigned pfx_len)
Deletes prefix from NIB.
void gnrc_ipv6_nib_change_rtr_adv_iface(gnrc_netif_t *netif, bool enable)
Changes the state if an interface advertises itself as a router or not.
void gnrc_ndp_rtr_adv_send(gnrc_netif_t *netif, const ipv6_addr_t *src, const ipv6_addr_t *dst, bool fin, gnrc_pktsnip_t *ext_opts)
Send pre-compiled router advertisement depending on a given network interface.
gnrc_pktsnip_t * gnrc_ndp_opt_ri_build(const ipv6_addr_t *prefix, uint8_t prefix_len, uint32_t route_ltime, uint8_t flags, gnrc_pktsnip_t *next)
Builds the route information option.
static int gnrc_netapi_dispatch_send(gnrc_nettype_t type, uint32_t demux_ctx, gnrc_pktsnip_t *pkt)
Sends a GNRC_NETAPI_MSG_TYPE_SND command to all subscribers to (type, demux_ctx).
Definition netapi.h:186
#define GNRC_NETAPI_MSG_TYPE_RCV
Messaging / IPC type for passing a Packet up the network stack
Definition netapi.h:72
#define GNRC_NETIF_L2ADDR_MAXLEN
Maximum length of the link-layer address.
Definition conf.h:155
static uint8_t * gnrc_netif_hdr_get_src_addr(const gnrc_netif_hdr_t *hdr)
Get the source address from the given header.
Definition hdr.h:195
static void gnrc_netif_hdr_set_netif(gnrc_netif_hdr_t *hdr, const gnrc_netif_t *netif)
Convenience function to set the interface of an interface header, given the network interface.
Definition hdr.h:397
gnrc_pktsnip_t * gnrc_netif_hdr_build(const uint8_t *src, uint8_t src_len, const uint8_t *dst, uint8_t dst_len)
Builds a generic network interface header for sending and adds it to the packet buffer.
gnrc_netif_t * gnrc_netif_iter(const gnrc_netif_t *prev)
Iterate over all network interfaces.
unsigned gnrc_netif_numof(void)
Get number of network interfaces actually allocated.
#define GNRC_NETREG_DEMUX_CTX_ALL
Demux context value to get all packets of a certain type.
Definition netreg.h:77
static void gnrc_netreg_entry_init_pid(gnrc_netreg_entry_t *entry, uint32_t demux_ctx, kernel_pid_t pid)
Initializes a netreg entry dynamically with PID.
Definition netreg.h:269
struct gnrc_netreg_entry gnrc_netreg_entry_t
Entry to the Network protocol registry.
#define GNRC_NETREG_ENTRY_INIT_PID(demux_ctx, pid)
Initializes a netreg entry statically with PID.
Definition netreg.h:98
int gnrc_netreg_register(gnrc_nettype_t type, gnrc_netreg_entry_t *entry)
Registers a thread to the registry.
@ GNRC_NETTYPE_NETIF
Protocol is as defined in gnrc_netif_hdr_t.
Definition nettype.h:58
@ GNRC_NETTYPE_UDP
Protocol is UDP.
Definition nettype.h:107
@ GNRC_NETTYPE_UNDEF
Protocol is undefined.
Definition nettype.h:59
static gnrc_pktsnip_t * gnrc_pkt_prepend(gnrc_pktsnip_t *pkt, gnrc_pktsnip_t *snip)
Prepends a snip to a packet.
Definition pkt.h:193
gnrc_pktsnip_t * gnrc_pktsnip_search_type(gnrc_pktsnip_t *pkt, gnrc_nettype_t type)
Searches the packet for a packet snip of a specific type.
struct gnrc_pktsnip gnrc_pktsnip_t
Type to represent parts (either headers or payload) of a packet, called snips.
gnrc_pktsnip_t * gnrc_pktbuf_add(gnrc_pktsnip_t *next, const void *data, size_t size, gnrc_nettype_t type)
Adds a new gnrc_pktsnip_t and its packet to the packet buffer.
static void gnrc_pktbuf_release(gnrc_pktsnip_t *pkt)
Decreases gnrc_pktsnip_t::users of pkt atomically and removes it if it reaches 0 and reports GNRC_NET...
Definition pktbuf.h:218
void gnrc_rpl_configure_root(gnrc_netif_t *netif, const ipv6_addr_t *dodag_id)
Convenience function to start a RPL root using the default configuration.
gnrc_pktsnip_t * gnrc_udp_hdr_build(gnrc_pktsnip_t *payload, uint16_t src, uint16_t dst)
Allocate and initialize a fresh UDP header in the packet buffer.
const ipv6_addr_t ipv6_addr_all_routers_link_local
char * ipv6_addr_to_str(char *result, const ipv6_addr_t *addr, uint8_t result_len)
Converts an IPv6 address to its string representation.
#define IPV6_ADDR_MAX_STR_LEN
Maximum length of an IPv6 address as string.
Definition addr.h:47
void ipv6_addr_init_prefix(ipv6_addr_t *out, const ipv6_addr_t *prefix, uint8_t bits)
Sets IPv6 address out with the first bits taken from prefix and leaves the remaining bits untouched.
uint8_t ipv6_addr_match_prefix(const ipv6_addr_t *a, const ipv6_addr_t *b)
Checks up to which bit-count two IPv6 addresses match in their prefix.
#define NDP_OPT_RI_FLAGS_PRF_ZERO
zero preference
Definition ndp.h:111
#define NDP_OPT_PI_FLAGS_A
autonomous address configuration
Definition ndp.h:101
int netif_get_opt(const netif_t *netif, netopt_t opt, uint16_t context, void *value, size_t max_len)
Gets option from an interface.
@ NETOPT_ADDRESS
(byte array, see below) link layer address in network byte order
Definition netopt.h:65
uint32_t random_uint32_range(uint32_t a, uint32_t b)
generates a random number r with a <= r < b.
#define US_PER_MS
The number of microseconds per millisecond.
Definition time_units.h:86
static void xtimer_set_msg(xtimer_t *timer, uint32_t offset, msg_t *msg, kernel_pid_t target_pid)
Set a timer that sends a message.
struct xtimer xtimer_t
xtimer timer structure
#define IS_USED(module)
Checks whether a module is being used or not.
Definition modules.h:67
Generic network interface header.
NIB definitions.
Common interface to the software PRNG.
RPL header.
Prefix list entry view on NIB.
Definition pl.h:35
uint8_t pfx_len
length of gnrc_ipv6_nib_pl_t::pfx in bits
Definition pl.h:37
ipv6_addr_t pfx
prefix
Definition pl.h:36
Generic network interface header.
Definition hdr.h:123
kernel_pid_t if_pid
PID of network interface.
Definition hdr.h:126
ipv6_addr_t addrs[CONFIG_GNRC_NETIF_IPV6_ADDRS_NUMOF]
IPv6 unicast and anycast addresses of the interface.
Definition ipv6.h:90
Representation of a network interface.
Definition netif.h:137
netif_t netif
network interface descriptor
Definition netif.h:138
uint8_t l2addr_len
Length in bytes of gnrc_netif_t::l2addr.
Definition netif.h:198
kernel_pid_t pid
PID of the network interface's thread.
Definition netif.h:225
uint8_t l2addr[GNRC_NETIF_L2ADDR_MAXLEN]
The link-layer address currently used as the source address on this interface.
Definition netif.h:191
gnrc_netif_ipv6_t ipv6
IPv6 component.
Definition netif.h:149
void * data
pointer to the data of the snip
Definition pkt.h:108
Describes a message object which can be sent between threads.
Definition msg.h:193
uint16_t type
Type field.
Definition msg.h:196
union msg_t::@320015036040264217111030043207077155207261357035 content
Content of the message.
void * ptr
Pointer content field.
Definition msg.h:198
Mutex structure.
Definition mutex.h:36
Prefix information option format.
Definition ndp.h:309
uint8_t flags
flags
Definition ndp.h:313
uint8_t prefix_len
prefix length
Definition ndp.h:312
network_uint32_t pref_ltime
preferred lifetime
Definition ndp.h:315
network_uint32_t valid_ltime
valid lifetime
Definition ndp.h:314
uint8_t len
length in units of 8 octets
Definition ndp.h:311
ipv6_addr_t prefix
prefix
Definition ndp.h:317
#define THREAD_PRIORITY_MAIN
Priority of the main thread.
uint32_t u32
32 bit representation
Definition byteorder.h:75
Data type to represent an IPv6 address.
Definition addr.h:64
uint8_t u8[16]
divided by 16 8-bit words.
Definition addr.h:65
network_uint64_t u64[2]
divided by 2 64-bit words.
Definition addr.h:68
xtimer interface definitions