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

Martine Lenders notifications at github.com
Thu Jul 29 11:31:10 CEST 2021


@miri64 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

Last thought (and I am aware that this is more or less asking you to clean up my mess :sweat_smile:): Would it make sense to move these as convenience functions to `net/gnrc/sixlowpan/ctx.h`?

-- 
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#pullrequestreview-717876161
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210729/56411fe7/attachment.htm>


More information about the notifications mailing list