[riot-notifications] [RIOT-OS/RIOT] net/gnrc/ipv6: move gnrc_util_conf_prefix() to common code (#16672)

benpicco notifications at github.com
Thu Jul 29 12:12:35 CEST 2021


@benpicco commented on this pull request.



> +#if IS_USED(MODULE_GNRC_SIXLOWPAN_CTX)
+static bool _ctx_match(const gnrc_sixlowpan_ctx_t *ctx,
+                       const ipv6_addr_t *prefix, uint8_t prefix_len)
+{
+    return (ctx != NULL) &&
+           (ctx->prefix_len == prefix_len) &&
+           (ipv6_addr_match_prefix(&ctx->prefix, prefix) >= prefix_len);
+}
+
+/* configure 6LoWPAN compression context */
+static void _update_6ctx(const ipv6_addr_t *prefix, uint8_t prefix_len,
+                         uint32_t valid)
+{
+    gnrc_sixlowpan_ctx_t *ctx = gnrc_sixlowpan_ctx_lookup_addr(prefix);
+    uint8_t cid = 0;
+
+    if (!_ctx_match(ctx, prefix, prefix_len)) {
+        /* While the context is a prefix match, the defined prefix within the
+         * context does not match => use new context */
+        ctx = NULL;
+    }
+    else {
+        cid = ctx->flags_id & GNRC_SIXLOWPAN_CTX_FLAGS_CID_MASK;
+    }
+    /* find first free context ID */
+    if (ctx == NULL) {
+        while (((ctx = gnrc_sixlowpan_ctx_lookup_id(cid)) != NULL) &&
+               !_ctx_match(ctx, prefix, prefix_len)) {
+            cid++;
+        }
+    }
+    if (cid < GNRC_SIXLOWPAN_CTX_SIZE) {
+        DEBUG("GNRC util: add compression context %u for prefix %s/%u\n", cid,
+              ipv6_addr_to_str(addr_str, prefix, sizeof(addr_str)),
+              prefix_len);
+        gnrc_sixlowpan_ctx_update(cid, (ipv6_addr_t *)prefix, prefix_len,
+                                  valid / (60 * MS_PER_SEC),
+                                  true);
+    }
+}
+#else
+static void _update_6ctx(const ipv6_addr_t *prefix, uint8_t prefix_len,
+                         uint32_t valid)
+{
+    (void)prefix;
+    (void)prefix_len;
+    (void)valid;
+}
+#endif

Ok, moved it there and added some documentation. 

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/16672#discussion_r679018306
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210729/7101a0f1/attachment.htm>


More information about the notifications mailing list