From 1a6d4fd204ade9e087188693cd52a13df0d07627 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Thu, 29 Nov 2018 22:21:51 +0100 Subject: [PATCH] gnrc_netif_hdr: provide wrappers for gnrc_netif_ipv6_iid_from_addr() For convenience ;-). --- sys/include/net/gnrc/netif/hdr.h | 55 ++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/sys/include/net/gnrc/netif/hdr.h b/sys/include/net/gnrc/netif/hdr.h index 76a2bcb45ba76..05032db2b03a6 100644 --- a/sys/include/net/gnrc/netif/hdr.h +++ b/sys/include/net/gnrc/netif/hdr.h @@ -24,6 +24,7 @@ #include #include +#include "net/gnrc/netif.h" #include "net/gnrc/pkt.h" #include "net/gnrc/pktbuf.h" #include "net/gnrc/netif.h" @@ -197,6 +198,60 @@ static inline void gnrc_netif_hdr_set_dst_addr(gnrc_netif_hdr_t *hdr, uint8_t *a memcpy(((uint8_t *)(hdr + 1)) + hdr->src_l2addr_len, addr, addr_len); } +/** + * @brief Converts the source address of a given @ref net_gnrc_netif_hdr to + * an IPv6 IID + * + * @note @p netif is intentionally required to be provided so that the caller + * needs to retrieve it from gnrc_netif_hdr_t::if_pid of @p hdr only + * once instead of this function retrieving it at every call. + * + * @pre `netif->pid == hdr->if_pid` + * + * @param[in] netif A network interface. gnrc_netif_t::pid must be equal to + * gnrc_netif_hdr_t::if_pid of @p hdr. + * @param[in] hdr Header to convert source address from. + * @param[out] iid The IID based on gnrc_netif_t::device_type. + * + * @return same as @ref gnrc_netif_ipv6_iid_from_addr(). + */ +static inline int gnrc_netif_hdr_ipv6_iid_from_src(const gnrc_netif_t *netif, + const gnrc_netif_hdr_t *hdr, + eui64_t *iid) +{ + return gnrc_netif_ipv6_iid_from_addr(netif, + gnrc_netif_hdr_get_src_addr(hdr), + hdr->src_l2addr_len, + iid); +} + +/** + * @brief Converts the destination address of a given @ref net_gnrc_netif_hdr + * to an IPv6 IID + * + * @note @p netif is intentionally required to be provided so that the caller + * needs to retrieve it from gnrc_netif_hdr_t::if_pid of @p hdr only + * once instead of this function retrieving it at every call. + * + * @pre `netif->pid == hdr->if_pid` + * + * @param[in] netif A network interface. gnrc_netif_t::pid must be equal to + * gnrc_netif_hdr_t::if_pid of @p hdr. + * @param[in] hdr Header to convert destination address from. + * @param[out] iid The IID based on gnrc_netif_t::device_type. + * + * @return same as @ref gnrc_netif_ipv6_iid_from_addr(). + */ +static inline int gnrc_netif_hdr_ipv6_iid_from_dst(const gnrc_netif_t *netif, + const gnrc_netif_hdr_t *hdr, + eui64_t *iid) +{ + return gnrc_netif_ipv6_iid_from_addr(netif, + gnrc_netif_hdr_get_dst_addr(hdr), + hdr->dst_l2addr_len, + iid); +} + /** * @brief Builds a generic network interface header for sending and * adds it to the packet buffer.