Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gnrc_netif_hdr: provide wrappers for gnrc_netif_ipv6_iid_from_addr() #10520

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions sys/include/net/gnrc/netif/hdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
#ifndef NET_GNRC_NETIF_HDR_H
#define NET_GNRC_NETIF_HDR_H

#include <errno.h>
#include <string.h>
#include <stdint.h>

#include "net/gnrc/netif/internal.h"
#include "net/gnrc/pkt.h"
#include "net/gnrc/pktbuf.h"
#include "net/gnrc/netif.h"
Expand Down Expand Up @@ -197,6 +199,65 @@ 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);
}

#if defined(MODULE_GNRC_IPV6) || defined(DOXYGEN)
/**
* @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 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 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);
}
#else /* defined(MODULE_GNRC_IPV6) || defined(DOXYGEN) */
#define gnrc_netif_hdr_ipv6_iid_from_src(netif, hdr, iid) (-ENOTSUP);
#define gnrc_netif_hdr_ipv6_iid_from_dst(netif, hdr, iid) (-ENOTSUP);
#endif /* defined(MODULE_GNRC_IPV6) || defined(DOXYGEN) */

/**
* @brief Builds a generic network interface header for sending and
* adds it to the packet buffer.
Expand Down