From 93fd8b707cd7005d6ecbe95710ba2955ac0d54a0 Mon Sep 17 00:00:00 2001 From: Lasse Lueder Date: Thu, 26 Sep 2019 22:05:20 +0200 Subject: [PATCH 1/3] net/ndp define ndp_opt_rdnss_impl_t The auxiliary struct internalizes the handy but non ISO-C++ compliant pointer to the payload in the packet struct. See PR #11299. --- sys/include/net/ndp.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sys/include/net/ndp.h b/sys/include/net/ndp.h index 01751bb380..0fc2e8b5fb 100644 --- a/sys/include/net/ndp.h +++ b/sys/include/net/ndp.h @@ -338,6 +338,7 @@ typedef struct __attribute__((packed)) { * @extends ndp_opt_t * * @see [RFC 8106, section 5.1](https://tools.ietf.org/html/rfc8106#section-5.1) + * @see ndp_opt_rdnss_impl_t */ typedef struct __attribute__((packed)) { uint8_t type; /**< option type */ @@ -347,6 +348,24 @@ typedef struct __attribute__((packed)) { ipv6_addr_t addrs[]; /**< addresses of IPv6 recursive DNS servers */ } ndp_opt_rdnss_t; +#ifndef __cplusplus +/** + * @brief Recursive DNS server option format with payload + * @extends ndp_opt_rdnss_t + * @details Auxiliary struct that contains a zero-length array as convenience + * pointer to the addresses. Only for use in C, invalid in ISO-C++. + * + * @see [RFC 8106, section 5.1](https://tools.ietf.org/html/rfc8106#section-5.1) + */ +typedef struct __attribute__((packed)) { + uint8_t type; /**< option type */ + uint8_t len; /**< length in units of 8 octets */ + network_uint16_t resv; /**< reserved field */ + network_uint32_t ltime; /**< lifetime in seconds */ + ipv6_addr_t addrs[]; /**< addresses of IPv6 recursive DNS servers */ +} ndp_opt_rdnss_impl_t; +#endif + #ifdef __cplusplus } #endif From 8a86ea4a4b2586eb6132fd731a772ea7815ed724 Mon Sep 17 00:00:00 2001 From: Lasse Lueder Date: Thu, 26 Sep 2019 22:06:46 +0200 Subject: [PATCH 2/3] use ndp_opt_rdnss_impl_t to access addresses --- sys/net/gnrc/network_layer/ipv6/nib/nib.c | 6 +++--- sys/net/gnrc/network_layer/ndp/gnrc_ndp.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sys/net/gnrc/network_layer/ipv6/nib/nib.c b/sys/net/gnrc/network_layer/ipv6/nib/nib.c index deef221b7c..8c0561c3d6 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/nib.c +++ b/sys/net/gnrc/network_layer/ipv6/nib/nib.c @@ -413,7 +413,7 @@ static void _handle_mtuo(gnrc_netif_t *netif, const icmpv6_hdr_t *icmpv6, const ndp_opt_mtu_t *mtuo); #if GNRC_IPV6_NIB_CONF_DNS static uint32_t _handle_rdnsso(gnrc_netif_t *netif, const icmpv6_hdr_t *icmpv6, - const ndp_opt_rdnss_t *rdnsso); + const ndp_opt_rdnss_impl_t *rdnsso); #endif #if GNRC_IPV6_NIB_CONF_MULTIHOP_P6C static uint32_t _handle_pio(gnrc_netif_t *netif, const icmpv6_hdr_t *icmpv6, @@ -729,7 +729,7 @@ static void _handle_rtr_adv(gnrc_netif_t *netif, const ipv6_hdr_t *ipv6, case NDP_OPT_RDNSS: next_timeout = _min(_handle_rdnsso(netif, (icmpv6_hdr_t *)rtr_adv, - (ndp_opt_rdnss_t *)opt), + (ndp_opt_rdnss_impl_t *)opt), next_timeout); break; #endif @@ -1349,7 +1349,7 @@ static void _handle_mtuo(gnrc_netif_t *netif, const icmpv6_hdr_t *icmpv6, #if GNRC_IPV6_NIB_CONF_DNS static uint32_t _handle_rdnsso(gnrc_netif_t *netif, const icmpv6_hdr_t *icmpv6, - const ndp_opt_rdnss_t *rdnsso) + const ndp_opt_rdnss_impl_t *rdnsso) { uint32_t ltime = UINT32_MAX; const ipv6_addr_t *addr; diff --git a/sys/net/gnrc/network_layer/ndp/gnrc_ndp.c b/sys/net/gnrc/network_layer/ndp/gnrc_ndp.c index c42477cfee..5110065529 100644 --- a/sys/net/gnrc/network_layer/ndp/gnrc_ndp.c +++ b/sys/net/gnrc/network_layer/ndp/gnrc_ndp.c @@ -234,7 +234,7 @@ gnrc_pktsnip_t *gnrc_ndp_opt_rdnss_build(uint32_t ltime, ipv6_addr_t *addrs, gnrc_pktsnip_t *pkt = gnrc_ndp_opt_build(NDP_OPT_RDNSS, opt_size, next); if (pkt != NULL) { - ndp_opt_rdnss_t *rdnss_opt = pkt->data; + ndp_opt_rdnss_impl_t *rdnss_opt = pkt->data; rdnss_opt->resv.u16 = 0; rdnss_opt->ltime = byteorder_htonl(ltime); for (unsigned i = 0; i < addrs_num; i++) { From 1b0fdf5a6fe283dabd21add50166162b7d7e3249 Mon Sep 17 00:00:00 2001 From: Lasse Lueder Date: Thu, 26 Sep 2019 22:07:11 +0200 Subject: [PATCH 3/3] net/ndp: remove convenience pointer in ndp_opt_rdnss_t --- sys/include/net/ndp.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sys/include/net/ndp.h b/sys/include/net/ndp.h index 0fc2e8b5fb..fd43a05cd0 100644 --- a/sys/include/net/ndp.h +++ b/sys/include/net/ndp.h @@ -334,7 +334,7 @@ typedef struct __attribute__((packed)) { } ndp_opt_mtu_t; /** - * @brief Recursive DNS server option format + * @brief Recursive DNS server option format without payload * @extends ndp_opt_t * * @see [RFC 8106, section 5.1](https://tools.ietf.org/html/rfc8106#section-5.1) @@ -345,7 +345,6 @@ typedef struct __attribute__((packed)) { uint8_t len; /**< length in units of 8 octets */ network_uint16_t resv; /**< reserved field */ network_uint32_t ltime; /**< lifetime in seconds */ - ipv6_addr_t addrs[]; /**< addresses of IPv6 recursive DNS servers */ } ndp_opt_rdnss_t; #ifndef __cplusplus