-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
sys/net/dhcpv6: include IA Prefix Option in SOLICIT #19225
Conversation
I added two more small quality of life improvements. |
3c77872
to
b5c0422
Compare
I have not read RFC 8415, but I seeked for "Prefix Option" within it. For the record:
The IA Prefix Option belongs in the IA Prefix Delegation Option. It is not a separate option apparently.
Prefix length should be 0 and prefix should be |
Good catch, we actually have to zero out the prefix. |
So I think the IA PD option is reverse constructed like this, or similar: patchdiff --git a/sys/net/application_layer/dhcpv6/client.c b/sys/net/application_layer/dhcpv6/client.c
index b33aeaa528..8d7471d7a8 100644
--- a/sys/net/application_layer/dhcpv6/client.c
+++ b/sys/net/application_layer/dhcpv6/client.c
@@ -15,6 +15,7 @@
#include <assert.h>
#include <stdbool.h>
+#include <string.h>
#include "event.h"
#include "event/timeout.h"
@@ -448,11 +449,11 @@ static inline size_t _compose_iapfx_opt(dhcpv6_opt_iapfx_t *iapfx,
if (lease->pfx_len == 0) {
return 0;
}
+ /* set all unused/requested fields to 0 */
+ memset(iapfx, 0, sizeof(*iapfx));
iapfx->type = byteorder_htons(DHCPV6_OPT_IAPFX);
iapfx->len = byteorder_htons(len);
- iapfx->pref = byteorder_htonl(0);
- iapfx->valid = byteorder_htonl(0);
iapfx->pfx_len = lease->pfx_len;
return len + sizeof(dhcpv6_opt_t);
@@ -505,28 +506,33 @@ static inline size_t _add_ia_pd_from_config(uint8_t *buf, size_t len_max)
if (!IS_USED(MODULE_DHCPV6_CLIENT_IA_PD)) {
return 0;
}
-
- size_t msg_len = 0;
+ uint8_t *start = buf, *end = &buf[len_max];
for (unsigned i = 0; i < CONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX; i++) {
uint32_t ia_id = pfx_leases[i].parent.ia_id.id;
if (ia_id != 0) {
+ size_t len = 0;
+ /* add IA Prefix Option included in IA Prefix Delegation Option */
+ dhcpv6_opt_iapfx_t *pa_pfx = (dhcpv6_opt_iapfx_t *)(end - sizeof(dhcpv6_opt_iapfx_t));
+ if ((uint8_t *)pa_pfx < start) {
+ assert(0); /* not supposed to happen */
+ return 0;
+ }
+ len = _compose_iapfx_opt(pa_pfx, &pfx_leases[i], len);
+ end -= len;
/* add Identity Association for Prefix Delegation Option */
- dhcpv6_opt_ia_pd_t *ia_pd = (dhcpv6_opt_ia_pd_t *)(&buf[msg_len]);
- msg_len += _compose_ia_pd_opt(ia_pd, ia_id, 0);
-
- /* add IA Prefix Option */
- dhcpv6_opt_iapfx_t *pa_pfx = (dhcpv6_opt_iapfx_t *)(&buf[msg_len]);
- msg_len += _compose_iapfx_opt(pa_pfx, &pfx_leases[i], 0);
+ dhcpv6_opt_ia_pd_t *ia_pd = (dhcpv6_opt_ia_pd_t *)(end - sizeof(dhcpv6_opt_ia_pd_t));
+ if ((uint8_t *)ia_pd < start) {
+ assert(0); /* not supposed to happen */
+ return 0;
+ }
+ len = _compose_ia_pd_opt(ia_pd, ia_id, len);
+ /* move to buffer start */
+ memmove(start, ia_pd, len);
+ start += len;
}
}
-
- if (msg_len > len_max) {
- assert(0);
- return 0;
- }
-
- return msg_len;
+ return start - buf;
}
static inline int32_t get_rand_ms_factor(void)
|
I think there is no need to move memory around, let's keep things simple and move the sub-option generation into the function the generates the option. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, it works fine. Please squash
c79f9ce
to
77a4ba2
Compare
Add the IA Prefix Option when soliciting a prefix so we can tell the server what prefix length we want.
77a4ba2
to
a693ecc
Compare
bors merge |
Build succeeded: |
Contribution description
I was always wondering why I would get a /62 from my DHCPv6 server when
dhcpv6_client_req_ia_pd()
is called with a prefix length of 64.Turns out that prefix length was never included in the request.
This is a problem as e.g. Linux clients do not accept router advertisements for SLAAC if the prefix length != 64.
Add the IA Prefix Option when soliciting a prefix so we can tell the server what prefix length we want.
Testing procedure
Can be tested on
native
with your local DHCPv6 server:create TAP bridge with LAN
run
gnrc_border_router
The DHCPv6 server now returns a prefix with the requested length
Issues/PRs references