1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

gnrc_ndp: add route information option

This commit is contained in:
Benjamin Valentin 2021-06-16 12:02:16 +02:00 committed by Benjamin Valentin
parent 1011af27a1
commit 68afd9d900
3 changed files with 80 additions and 0 deletions

View File

@ -232,6 +232,35 @@ gnrc_pktsnip_t *gnrc_ndp_opt_pi_build(const ipv6_addr_t *prefix,
uint8_t prefix_len,
uint32_t valid_ltime, uint32_t pref_ltime,
uint8_t flags, gnrc_pktsnip_t *next);
/**
* @brief Builds the route information option.
*
* @pre `prefix != NULL`
* @pre `!ipv6_addr_is_link_local(prefix) && !ipv6_addr_is_multicast(prefix)`
* @pre `prefix_len <= 128`
*
* @see [RFC 4191, section 2.3](https://tools.ietf.org/html/rfc4191#section-2.3)
*
* @note Should only be used with router advertisemnents. This is not checked
* however, since nodes should silently ignore it in other NDP messages.
*
* @param[in] prefix An IPv6 address or a prefix of an IPv6 address.
* Must not be NULL or be a link-local or
* multicast address.
* @param[in] prefix_len The length of @p prefix in bits. Must be between
* 0 and 128.
* @param[in] route_ltime Length of time in seconds that @p prefix is valid.
* UINT32_MAX represents infinity.
* @param[in] flags Flags as defined in net/ndp.h.
* @param[in] next More options in the packet. NULL, if there are none.
*
* @return The packet snip list of options, on success
* @return NULL, if packet buffer is full
*/
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);
/**
* @brief Builds the MTU option.

View File

@ -88,6 +88,7 @@ extern "C" {
#define NDP_OPT_PI (3) /**< prefix information option */
#define NDP_OPT_RH (4) /**< redirected option */
#define NDP_OPT_MTU (5) /**< MTU option */
#define NDP_OPT_RI (24) /**< Route Information Option */
#define NDP_OPT_RDNSS (25) /**< recursive DNS server option */
#define NDP_OPT_AR (33) /**< address registration option */
#define NDP_OPT_6CTX (34) /**< 6LoWPAN context option */
@ -103,6 +104,17 @@ extern "C" {
#define NDP_OPT_PI_FLAGS_A (0x40) /**< autonomous address configuration */
/** @} */
/**
* @{
* @name Flags for route information option
*/
#define NDP_OPT_RI_FLAGS_MASK (0x18)
#define NDP_OPT_RI_FLAGS_PRF_NONE (0x10) /**< ignore preference */
#define NDP_OPT_RI_FLAGS_PRF_NEG (0x18) /**< negative preference */
#define NDP_OPT_RI_FLAGS_PRF_ZERO (0x0) /**< zero preference */
#define NDP_OPT_RI_FLAGS_PRF_POS (0x8) /**< positive preference */
/** @} */
/**
* @{
* @name Prefix information option constants
@ -308,6 +320,21 @@ typedef struct __attribute__((packed)) {
ipv6_addr_t prefix; /**< prefix */
} ndp_opt_pi_t;
/**
* @brief Route information option format
* @extends ndp_opt_t
*
* @see [RFC 4191, section 2.3](https://tools.ietf.org/html/rfc4191#section-2.3)
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< option type */
uint8_t len; /**< length in units of 8 octets */
uint8_t prefix_len; /**< prefix length */
uint8_t flags; /**< flags */
network_uint32_t route_ltime; /**< route lifetime */
ipv6_addr_t prefix; /**< prefix */
} ndp_opt_ri_t;
/**
* @brief Redirected header option format
* @extends ndp_opt_t

View File

@ -201,6 +201,30 @@ gnrc_pktsnip_t *gnrc_ndp_opt_pi_build(const ipv6_addr_t *prefix,
return pkt;
}
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)
{
assert(prefix != NULL);
assert(!ipv6_addr_is_link_local(prefix) && !ipv6_addr_is_multicast(prefix));
assert(prefix_len <= 128);
gnrc_pktsnip_t *pkt = gnrc_ndp_opt_build(NDP_OPT_RI, sizeof(ndp_opt_ri_t),
next);
if (pkt != NULL) {
ndp_opt_ri_t *ri_opt = pkt->data;
ri_opt->prefix_len = prefix_len;
ri_opt->flags = (flags & NDP_OPT_PI_FLAGS_MASK);
ri_opt->route_ltime = byteorder_htonl(route_ltime);
/* Bits beyond prefix_len MUST be 0 */
ipv6_addr_set_unspecified(&ri_opt->prefix);
ipv6_addr_init_prefix(&ri_opt->prefix, prefix, prefix_len);
}
return pkt;
}
gnrc_pktsnip_t *gnrc_ndp_opt_mtu_build(uint32_t mtu, gnrc_pktsnip_t *next)
{
gnrc_pktsnip_t *pkt = gnrc_ndp_opt_build(NDP_OPT_MTU,