Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion sys/net/application_layer/dhcpv6/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sys/net/application_layer/dhcpv6/_dhcpv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 14 additions & 12 deletions sys/net/application_layer/dhcpv6/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/gnrc_dhcpv6_client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/gnrc_dhcpv6_client_6lbr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

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

@miri64 Thanks :) While I was at it I corrected the path to the test files in this line and also squashed it already. I hope that this was okay

output.

[scapy]: https://scapy.readthedocs.io/en/latest/
12 changes: 6 additions & 6 deletions tests/gnrc_dhcpv6_client_6lbr/tests-as-root/01-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) /
Expand Down