From: Vladislav Grishenko Date: Thu, 25 Jul 2024 19:51:09 +0000 (+0500) Subject: odhcp6c: allow to request specific ipv6 prefix X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;ds=sidebyside;p=project%2Fodhcp6c.git odhcp6c: allow to request specific ipv6 prefix Expand -P option with optional exact ipv6 prefix format. This allows to keep the IPv6 prefix in some cases, for example if the prefix is issued dynamically on upstream. Examples: -P -P Based on https://github.com/openwrt/odhcp6c/pull/86 --- diff --git a/src/dhcpv6.c b/src/dhcpv6.c index ca5957e..c1603f5 100644 --- a/src/dhcpv6.c +++ b/src/dhcpv6.c @@ -384,7 +384,8 @@ static void dhcpv6_send(enum dhcpv6_msg type, uint8_t trid[3], uint32_t ecs) struct dhcpv6_ia_prefix pref = { .type = htons(DHCPV6_OPT_IA_PREFIX), .len = htons(sizeof(pref) - 4), - .prefix = request_prefixes[i].length + .prefix = request_prefixes[i].length, + .addr = request_prefixes[i].addr }; memcpy(ia_pd + ia_pd_len, &hdr_ia_pd, sizeof(hdr_ia_pd)); ia_pd_len += sizeof(hdr_ia_pd); diff --git a/src/odhcp6c.c b/src/odhcp6c.c index 4a6d7bd..20b4040 100644 --- a/src/odhcp6c.c +++ b/src/odhcp6c.c @@ -241,17 +241,29 @@ int main(_unused int argc, char* const argv[]) if (allow_slaac_only >= 0 && allow_slaac_only < 10) allow_slaac_only = 10; + struct odhcp6c_request_prefix prefix = { 0 }; + + optpos = strchr(optarg, '/'); + if (optpos) { + strncpy((char *)buf, optarg, optpos - optarg); + buf[optpos - optarg] = '\0'; + if (inet_pton(AF_INET6, (char *)buf, &prefix.addr) <= 0) { + syslog(LOG_ERR, "invalid argument: '%s'", optarg); + return 1; + } + optpos++; + } else + optpos = optarg; + char *iaid_begin; int iaid_len = 0; - int prefix_length = strtoul(optarg, &iaid_begin, 10); + prefix.length = strtoul(optpos, &iaid_begin, 10); if (*iaid_begin != '\0' && *iaid_begin != ',' && *iaid_begin != ':') { syslog(LOG_ERR, "invalid argument: '%s'", optarg); return 1; } - struct odhcp6c_request_prefix prefix = { 0, prefix_length }; - if (*iaid_begin == ',' && (iaid_len = strlen(iaid_begin)) > 1) memcpy(&prefix.iaid, iaid_begin + 1, iaid_len > 4 ? 4 : iaid_len); else if (*iaid_begin == ':') @@ -614,7 +626,7 @@ static int usage(void) " -S