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/ipv6/nib: automatically create 6ctx for downstream networks #21086

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
45 changes: 45 additions & 0 deletions sys/net/gnrc/network_layer/ipv6/nib/nib.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@
icmpv6_len -= (opt->len << 3), \
opt = (ndp_opt_t *)(((uint8_t *)opt) + (opt->len << 3)))

#if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_ROUTER)

Check warning on line 565 in sys/net/gnrc/network_layer/ipv6/nib/nib.c

View workflow job for this annotation

GitHub Actions / static-tests

full block {} expected in the control structure
static void _handle_rtr_sol(gnrc_netif_t *netif, const ipv6_hdr_t *ipv6,
const ndp_rtr_sol_t *rtr_sol, size_t icmpv6_len)
{
Expand Down Expand Up @@ -1787,6 +1787,28 @@
return "invalid";
}

static gnrc_pktsnip_t *_build_ctxs(_nib_abr_entry_t *abr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't there already be a function like this somewhere in the code base?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only a function that adds all options

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid code duplication, does it make sense to call the function at hand there as well?

{
gnrc_pktsnip_t *ext_opts = NULL;

for (int i = 0; i < GNRC_SIXLOWPAN_CTX_SIZE; i++) {
gnrc_sixlowpan_ctx_t *ctx;
if (bf_isset(abr->ctxs, i) &&
((ctx = gnrc_sixlowpan_ctx_lookup_id(i)) != NULL)) {
gnrc_pktsnip_t *sixco = gnrc_sixlowpan_nd_opt_6ctx_build(
ctx->prefix_len, ctx->flags_id,
ctx->ltime, &ctx->prefix, ext_opts);
if (sixco == NULL) {
DEBUG("nib: No space left in packet buffer. Not adding 6LO\n");
return NULL;
}
ext_opts = sixco;
}
}

return gnrc_sixlowpan_nd_opt_abr_build(abr->version, 0, &abr->addr, ext_opts);
}

static uint32_t _handle_rio(gnrc_netif_t *netif, const ipv6_hdr_t *ipv6,
const ndp_opt_ri_t *rio)
{
Expand Down Expand Up @@ -1815,6 +1837,29 @@
netif->pid, route_ltime == UINT32_MAX ? 0 : route_ltime);
}

if (IS_ACTIVE(CONFIG_GNRC_NETIF_IPV6_BR_AUTO_6CTX) && gnrc_netif_is_6lbr(netif)) {
/* configure compression context */
if (gnrc_sixlowpan_ctx_update_6ctx(&rio->prefix, rio->prefix_len, route_ltime)) {
DEBUG("nib: add compression context for prefix from RIO\n");
}

gnrc_sixlowpan_ctx_t *ctx = gnrc_sixlowpan_ctx_lookup_addr(&rio->prefix);
assert(ctx);
uint8_t ctx_id = ctx->flags_id & GNRC_SIXLOWPAN_CTX_FLAGS_CID_MASK;

_nib_abr_entry_t *abr = NULL;
DEBUG("nib: Send router advertisements with updated compression contexts\n");
while ((abr = _nib_abr_iter(abr))) {
if (!route_ltime) {
bf_unset(abr->ctxs, ctx_id);
continue;
}
bf_set(abr->ctxs, ctx_id);
gnrc_pktsnip_t *ext_opts = _build_ctxs(abr);
gnrc_ndp_rtr_adv_send(netif, NULL, &ipv6->src, false, ext_opts);
}
}

return route_ltime;
}

Expand Down
Loading