[riot-notifications] [RIOT-OS/RIOT] sys/net/dhcpv6: Add IA_NA support to the DHCPv6 client (#16228)

Martine Lenders notifications at github.com
Tue Aug 10 21:33:09 CEST 2021


@miri64 requested changes on this pull request.



> +    return extract_global_address(child), extract_global_address(child)
+
+
+def check_ia_na_addr(ia_na_addr):
+    """Check if the expected IA_NA address has been assigned"""
+    return IPv6Address(ia_na_addr) in IPv6Network("{}/64".format(IA_NA_ADDRESS_POOL_PREFIX))
+
+
+def check_ia_pd_addr(ia_pd_addr, global_pfx):
+    """Check if the expected IA_PD address has been assigned"""
+    return ia_pd_addr.startswith(global_pfx)
+
+
+def check_global_addrs(ia_na_addr, ia_pd_addr, global_pfx):
+    """Perform IA_NA check for the first and IA_PD for the second address"""
+    return check_ia_na_addr(ia_na_addr) and check_ia_pd_addr(ia_pd_addr, global_pfx)

Due to lazy evaluation, the second function will be skipped when `check_ia_na_addr(ia_na_addr)` returns `False` (so a positive `ia_pd` is never checked). I think this can be prevented by doing the following

```suggestion
    return [i for i, b enumerate([
        check_ia_na_addr(ia_na_addr), 
        check_ia_pd_addr(ia_pd_addr, global_pfx)
    ]) if b]
```

This way an index list of all true checks is returned, with 0 being `check_ia_na_addr()` and 1 being `check_ia_pd_addr()`.

> +
+def check_ia_pd_addr(ia_pd_addr, global_pfx):
+    """Check if the expected IA_PD address has been assigned"""
+    return ia_pd_addr.startswith(global_pfx)
+
+
+def check_global_addrs(ia_na_addr, ia_pd_addr, global_pfx):
+    """Perform IA_NA check for the first and IA_PD for the second address"""
+    return check_ia_na_addr(ia_na_addr) and check_ia_pd_addr(ia_pd_addr, global_pfx)
+
+
+def test_global_addrs(global_addr_1, global_addr_2, global_pfx):
+    """Assert that one global address is the IA_NA and the other one is the IA_PD address"""
+    result_1 = check_global_addrs(global_addr_1, global_addr_2, global_pfx)
+    result_2 = check_global_addrs(global_addr_2, global_addr_1, global_pfx)
+    assert result_1 != result_2

And this way, this check is still valid.

-- 
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/16228#pullrequestreview-726765910
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210810/1c7a404a/attachment.htm>


More information about the notifications mailing list