Skip to content

Commit

Permalink
fixup! gnrc_ipv6_nib: port to gnrc_netif2
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Aug 18, 2017
1 parent cbb4dab commit 3d16e16
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 36 deletions.
22 changes: 14 additions & 8 deletions sys/include/net/gnrc/ndp2.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,22 @@ gnrc_pktsnip_t *gnrc_ndp2_opt_mtu_build(uint32_t mtu, gnrc_pktsnip_t *next);
* @pre `(tgt != NULL) && !ipv6_addr_is_multicast(tgt)`
* @pre `(netif != NULL) && (dst != NULL)`
*
* @param[in] tgt The target address of the neighbor solicitation.
* May not be NULL and **MUST NOT** be multicast.
* @param[in] netif Interface to send over. May not be NULL.
* @param[in] src Source address for the neighbor solicitation. Will be chosen
* from the interface according to @p dst, if NULL.
* @param[in] dst Destination address for neighbor solicitation. May not be
* NULL.
* @param[in] tgt The target address of the neighbor solicitation.
* May not be NULL and **MUST NOT** be multicast.
* @param[in] netif Interface to send over. May not be NULL.
* @param[in] src Source address for the neighbor solicitation. Will be
* chosen from the interface according to @p dst, if NULL.
* @param[in] dst Destination address for neighbor solicitation. May not
* be NULL.
* @param[in] ext_opts External options for the neighbor advertisement.
* Leave NULL for none.
* **Warning:** these are not tested if they are suitable
* for a neighbor solicitation so be sure to check that.
* **Will be released** in an error case.
*/
void gnrc_ndp2_nbr_sol_send(const ipv6_addr_t *tgt, gnrc_netif2_t *netif,
const ipv6_addr_t *src, const ipv6_addr_t *dst);
const ipv6_addr_t *src, const ipv6_addr_t *dst,
gnrc_pktsnip_t *ext_opts);

/**
* @brief Send pre-compiled neighbor advertisement depending on a given
Expand Down
41 changes: 38 additions & 3 deletions sys/net/gnrc/network_layer/ipv6/nib/_nib-arsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include "net/gnrc/ndp2.h"
#include "net/gnrc/ipv6/nib.h"
#include "net/gnrc/netif2/internal.h"
#ifdef MODULE_GNRC_SIXLOWPAN_ND
#include "net/gnrc/sixlowpan/nd.h"
#endif

#include "_nib-arsm.h"
#include "_nib-6lr.h"
Expand All @@ -40,13 +43,45 @@ static char addr_str[IPV6_ADDR_MAX_STR_LEN];
static inline unsigned _get_l2addr_len(gnrc_netif2_t *netif,
const ndp_opt_t *opt);

void _snd_ns(const ipv6_addr_t *tgt, gnrc_netif2_t *netif,
const ipv6_addr_t *src, const ipv6_addr_t *dst)
{
gnrc_pktsnip_t *ext_opt = NULL;

#ifdef MODULE_GNRC_SIXLOWPAN_ND
_nib_dr_entry_t *dr = _nib_drl_get_dr();

assert(netif != NULL);
/* add ARO based on interface */
if ((src != NULL) && gnrc_netif2_is_6ln(netif) &&
(_nib_onl_get_if(dr->next_hop) == (unsigned)netif->pid) &&
ipv6_addr_equal(&dr->next_hop->ipv6, dst)) {
netdev_t *dev = netif->dev;
uint8_t l2src[GNRC_NETIF2_L2ADDR_MAXLEN];
size_t l2src_len = (uint16_t)dev->driver->get(dev, NETOPT_ADDRESS_LONG,
l2src, sizeof(l2src));
if (l2src_len != sizeof(eui64_t)) {
DEBUG("nib: can't get EUI-64 of the interface for ARO\n");
return;
}
ext_opt = gnrc_sixlowpan_nd_opt_ar_build(0, GNRC_SIXLOWPAN_ND_AR_LTIME,
(eui64_t *)l2src, NULL);
if (ext_opt == NULL) {
DEBUG("nib: error allocating ARO.\n");
return;
}
}
#endif /* MODULE_GNRC_SIXLOWPAN_ND */
gnrc_ndp2_nbr_sol_send(tgt, netif, src, dst, ext_opt);
}

void _snd_uc_ns(_nib_onl_entry_t *nbr, bool reset)
{
gnrc_netif2_t *netif = gnrc_netif2_get_by_pid(_nib_onl_get_if(nbr));

assert(netif != NULL);
gnrc_netif2_acquire(netif);
DEBUG("unicast to %s (retrans. timer = %ums)\n",
DEBUG("nib: unicast to %s (retrans. timer = %ums)\n",
ipv6_addr_to_str(addr_str, &nbr->ipv6, sizeof(addr_str)),
(unsigned)netif->ipv6.retrans_time);
#if GNRC_IPV6_NIB_CONF_ARSM
Expand All @@ -56,7 +91,7 @@ void _snd_uc_ns(_nib_onl_entry_t *nbr, bool reset)
#else
(void)reset;
#endif
gnrc_ndp2_nbr_sol_send(&nbr->ipv6, netif, NULL, &nbr->ipv6);
_snd_ns(&nbr->ipv6, netif, NULL, &nbr->ipv6);
_evtimer_add(nbr, GNRC_IPV6_NIB_SND_UC_NS, &nbr->nud_timeout,
netif->ipv6.retrans_time);
gnrc_netif2_release(netif);
Expand Down Expand Up @@ -312,7 +347,7 @@ void _probe_nbr(_nib_onl_entry_t *nbr, bool reset)
}
DEBUG("(retrans. timer = %ums)\n", (unsigned)retrans_time);
ipv6_addr_set_solicited_nodes(&sol_nodes, &nbr->ipv6);
gnrc_ndp2_nbr_sol_send(&nbr->ipv6, netif, NULL, &sol_nodes);
_snd_ns(&nbr->ipv6, netif, NULL, &sol_nodes);
_evtimer_add(nbr, GNRC_IPV6_NIB_SND_MC_NS, &nbr->nud_timeout,
retrans_time);
if (nbr->ns_sent < UINT8_MAX) {
Expand Down
17 changes: 17 additions & 0 deletions sys/net/gnrc/network_layer/ipv6/nib/_nib-arsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@
extern "C" {
#endif

/**
* @brief Send neighbor solicitation (including ARO if required)
*
* @pre `(tgt != NULL) && !ipv6_addr_is_multicast(tgt)`
* @pre `(netif != NULL) && (dst != NULL)`
*
* @param[in] tgt The target address of the neighbor solicitation.
* May not be NULL and **MUST NOT** be multicast.
* @param[in] netif Interface to send over. May not be NULL.
* @param[in] src Source address for the neighbor solicitation. Will be
* chosen from the interface according to @p dst, if NULL.
* @param[in] dst Destination address for neighbor solicitation. May not
* be NULL.
*/
void _snd_ns(const ipv6_addr_t *tgt, gnrc_netif2_t *netif,
const ipv6_addr_t *src, const ipv6_addr_t *dst);

/**
* @brief Send unicast neighbor solicitation and reset corresponding timer
* event
Expand Down
28 changes: 4 additions & 24 deletions sys/net/gnrc/network_layer/ndp2/gnrc_ndp2.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,12 @@ static gnrc_pktsnip_t *_build_headers(gnrc_netif2_t *netif,
static inline size_t _get_l2src(const gnrc_netif2_t *netif, uint8_t *l2src);

void gnrc_ndp2_nbr_sol_send(const ipv6_addr_t *tgt, gnrc_netif2_t *netif,
const ipv6_addr_t *src, const ipv6_addr_t *dst)
const ipv6_addr_t *src, const ipv6_addr_t *dst,
gnrc_pktsnip_t *ext_opts)
{
assert((tgt != NULL) && !ipv6_addr_is_multicast(tgt));
assert((netif != NULL) && (dst != NULL));
gnrc_pktsnip_t *hdr, *pkt = NULL;
gnrc_pktsnip_t *hdr, *pkt = ext_opts;
/* cppcheck-suppress variableScope
* (reason: also used in MODULE_GNRC_SIXLOWPAN_ND compile path) */
uint8_t l2src[8];
Expand All @@ -235,35 +236,14 @@ void gnrc_ndp2_nbr_sol_send(const ipv6_addr_t *tgt, gnrc_netif2_t *netif,

if (l2src_len > 0) {
/* add source address link-layer address option */
pkt = gnrc_ndp2_opt_sl2a_build(l2src, l2src_len, NULL);
pkt = gnrc_ndp2_opt_sl2a_build(l2src, l2src_len, pkt);

if (pkt == NULL) {
DEBUG("ndp2: error allocating SL2AO.\n");
break;
}
}
}
#ifdef MODULE_GNRC_SIXLOWPAN_ND
/* add ARO based on interface */
if (gnrc_netif2_is_6ln(netif)) {
if (l2src_len != sizeof(eui64_t)) {
l2src_len = (uint16_t)gnrc_netapi_get(netif->pid,
NETOPT_ADDRESS_LONG, 0,
l2src, sizeof(l2src));
if (l2src_len != sizeof(eui64_t)) {
DEBUG("ndp2: can't get EUI-64 of the interface\n");
break;
}
}
hdr = gnrc_sixlowpan_nd_opt_ar_build(0, GNRC_SIXLOWPAN_ND_AR_LTIME,
(eui64_t *)l2src, pkt);
if (hdr == NULL) {
DEBUG("ndp2: error allocating ARO.\n");
break;
}
pkt = hdr;
}
#endif /* MODULE_GNRC_SIXLOWPAN_ND */
/* add neighbor solicitation header */
hdr = gnrc_ndp2_nbr_sol_build(tgt, pkt);
if (hdr == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion tests/gnrc_ndp2/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ static void test_nbr_sol_send(const ipv6_addr_t *src)
ndp_nbr_sol_t *nbr_sol;

TEST_ASSERT_NOT_NULL(test_netif);
gnrc_ndp2_nbr_sol_send(&test_tgt, test_netif, src, &test_dst);
gnrc_ndp2_nbr_sol_send(&test_tgt, test_netif, src, &test_dst, NULL);
msg_receive(&msg);
TEST_ASSERT_EQUAL_INT(GNRC_NETAPI_MSG_TYPE_SND, msg.type);
pkt = msg.content.ptr;
Expand Down

0 comments on commit 3d16e16

Please sign in to comment.