diff --git a/sys/net/application_layer/dhcpv6/Kconfig b/sys/net/application_layer/dhcpv6/Kconfig index 690bf8dd0fb1..23a4db8adf29 100644 --- a/sys/net/application_layer/dhcpv6/Kconfig +++ b/sys/net/application_layer/dhcpv6/Kconfig @@ -27,7 +27,7 @@ menuconfig KCONFIG_USEMODULE_GNRC_DHCPV6_CLIENT_MUD_URL if KCONFIG_USEMODULE_GNRC_DHCPV6_CLIENT_MUD_URL -config CONFIG_DHCPV6_CLIENT_MUD_URL +config DHCPV6_CLIENT_MUD_URL string "URL pointing to a Manufacturer Usage Description file" endif # KCONFIG_USEMODULE_GNRC_DHCPV6_CLIENT_MUD_URL diff --git a/sys/net/application_layer/dhcpv6/_dhcpv6.h b/sys/net/application_layer/dhcpv6/_dhcpv6.h index 6bec53ebdecb..1aff58561f6c 100644 --- a/sys/net/application_layer/dhcpv6/_dhcpv6.h +++ b/sys/net/application_layer/dhcpv6/_dhcpv6.h @@ -220,8 +220,8 @@ typedef struct __attribute__((packed)) { */ typedef struct __attribute__((packed)) { network_uint16_t type; /**< @ref DHCPV6_OPT_MUD_URL */ - network_uint16_t len; /**< length of the MUDstring in octets. */ - char mudString[]; /**< MUD URL using the "https" scheme */ + network_uint16_t len; /**< length of the mud_string in octets. */ + char mud_string[]; /**< MUD URL using the "https" scheme */ } dhcpv6_opt_mud_url_t; #ifdef __cplusplus diff --git a/sys/net/application_layer/dhcpv6/client.c b/sys/net/application_layer/dhcpv6/client.c index cf7fb3f8472a..2fc8461febf2 100644 --- a/sys/net/application_layer/dhcpv6/client.c +++ b/sys/net/application_layer/dhcpv6/client.c @@ -85,6 +85,8 @@ static uint32_t transaction_start; static uint32_t transaction_id; static uint8_t duid_len = sizeof(dhcpv6_duid_l2_t); +static const char mud_url[] = CONFIG_DHCPV6_CLIENT_MUD_URL; + static void _post_solicit_servers(void *args); static void _solicit_servers(event_t *event); static void _request(event_t *event); @@ -127,6 +129,10 @@ static void *_thread(void *args) void dhcpv6_client_init(event_queue_t *eq, uint16_t netif) { assert(eq->waiter != NULL); + if (IS_USED(MODULE_GNRC_DHCPV6_CLIENT_MUD_URL)) { + assert(strlen(mud_url) <= MAX_MUD_URL_LENGTH); + assert(strncmp(mud_url, "https://", 8) == 0); + } event_queue = eq; local.netif = netif; remote.netif = netif; @@ -248,18 +254,21 @@ static inline size_t _compose_elapsed_time_opt(dhcpv6_opt_elapsed_time_t *time) } static inline size_t _compose_mud_url_opt(dhcpv6_opt_mud_url_t *mud_url_opt, - const char *mud_url, size_t len_max) + size_t len_max) { + if (!IS_USED(MODULE_GNRC_DHCPV6_CLIENT_MUD_URL)) { + return 0; + } uint16_t len = strlen(mud_url); if (len > len_max) { - assert(0); + assert(len <= len_max); return 0; } mud_url_opt->type = byteorder_htons(DHCPV6_OPT_MUD_URL); mud_url_opt->len = byteorder_htons(len); - strncpy(mud_url_opt->mudString, mud_url, len_max); + memcpy(mud_url_opt->mud_string, mud_url, len); return len + sizeof(dhcpv6_opt_mud_url_t); } @@ -729,15 +738,6 @@ static void _solicit_servers(event_t *event) msg_len += _compose_elapsed_time_opt(time); msg_len += _compose_oro_opt((dhcpv6_opt_oro_t *)&send_buf[msg_len], oro_opts, ARRAY_SIZE(oro_opts)); - - if (IS_USED(MODULE_GNRC_DHCPV6_CLIENT_MUD_URL)) { - const char mud_url[] = CONFIG_DHCPV6_CLIENT_MUD_URL; - assert(strlen(mud_url) <= MAX_MUD_URL_LENGTH); - assert(strncmp(mud_url, "https://", 8) == 0); - msg_len += _compose_mud_url_opt((dhcpv6_opt_mud_url_t *)&send_buf[msg_len], - mud_url, sizeof(send_buf) - msg_len); - } - msg_len += _add_ia_pd_from_config(&send_buf[msg_len], sizeof(send_buf) - msg_len); DEBUG("DHCPv6 client: send SOLICIT\n"); _flush_stale_replies(&sock); @@ -841,6 +841,8 @@ static void _request_renew_rebind(uint8_t type) if (type != DHCPV6_REBIND) { msg_len += _compose_sid_opt((dhcpv6_opt_duid_t *)&send_buf[msg_len]); } + msg_len += _compose_mud_url_opt((dhcpv6_opt_mud_url_t *)&send_buf[msg_len], + sizeof(send_buf) - msg_len); transaction_start = _now_cs(); time = (dhcpv6_opt_elapsed_time_t *)&send_buf[msg_len]; msg_len += _compose_elapsed_time_opt(time); diff --git a/tests/gnrc_dhcpv6_client/README.md b/tests/gnrc_dhcpv6_client/README.md index 90fbe649ca8e..8748fc262d3e 100644 --- a/tests/gnrc_dhcpv6_client/README.md +++ b/tests/gnrc_dhcpv6_client/README.md @@ -21,7 +21,7 @@ If you use any platform other than `native`, you need to use `ethos`, otherwise `netdev_tap` is chosen. An instance of Kea that configured via [kea-dhcp6.conf](kea-dhcp6.conf) is -started in parallel to `make term`/`make test`. +started in parallel to `make term`/`make test-as-root`. Read the [Kea documentation] on the configuration file for more information. @@ -31,7 +31,7 @@ If you created your interface and without the script, please reconfigure Kea by search & replacing "`tapbr0`" in the configuration file. ```sh -BOARD=samr21-xpro make flash test +BOARD=samr21-xpro make flash test-as-root ``` [Kea]: http://kea.isc.org diff --git a/tests/gnrc_dhcpv6_client_6lbr/README.md b/tests/gnrc_dhcpv6_client_6lbr/README.md index 31df19686b81..364edafe27c1 100644 --- a/tests/gnrc_dhcpv6_client_6lbr/README.md +++ b/tests/gnrc_dhcpv6_client_6lbr/README.md @@ -14,7 +14,7 @@ make flash And run the tests using ``` -sudo make test +sudo make test-as-root ``` Note that root privileges are required since `scapy` needs to construct Ethernet @@ -24,7 +24,7 @@ The tests succeeds if you see the string `SUCCESS`. If any problems are encountered (i.e. if the test prints the string `FAILED`), set the echo parameter in the `run()` function at the bottom of the test script -(tests/01-run.py) to `True`. The test script will then offer a more detailed +(tests-as-root/01-run.py) to `True`. The test script will then offer a more detailed output. [scapy]: https://scapy.readthedocs.io/en/latest/ diff --git a/tests/gnrc_dhcpv6_client_6lbr/tests-as-root/01-run.py b/tests/gnrc_dhcpv6_client_6lbr/tests-as-root/01-run.py index 0fe215060ad0..28e85b908767 100755 --- a/tests/gnrc_dhcpv6_client_6lbr/tests-as-root/01-run.py +++ b/tests/gnrc_dhcpv6_client_6lbr/tests-as-root/01-run.py @@ -129,12 +129,6 @@ def testfunc(child): # and it is asking for a prefix delegation assert DHCP6OptIA_PD in pkt - assert DHCP6OptMUD in pkt - mud_packet = pkt[DHCP6OptMUD] - assert mud_packet.optcode == 112 - assert mud_packet.optlen == len(MUD_TEST_URL) - assert mud_packet.data == MUD_TEST_URL - # reply to solicit with advertise and a prefix provided trid = pkt[DHCP6_Solicit].trid srv_duid = "aa:bb:cc:dd:ee:ff" @@ -167,6 +161,12 @@ def testfunc(child): # and is still asking for a prefix delegation assert DHCP6OptIA_PD in pkt + assert DHCP6OptMUD in pkt + mud_option = pkt[DHCP6OptMUD] + assert mud_option.optcode == 112 + assert mud_option.optlen == len(MUD_TEST_URL) + assert mud_option.data == MUD_TEST_URL + # reply to request with reply and a prefix provided trid = pkt[DHCP6_Request].trid sendp(build_reply_headers(pkt) / DHCP6_Reply(trid=trid) /