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 <length>
-P <prefix/length>
Based on https://github.com/openwrt/odhcp6c/pull/86
struct dhcpv6_ia_prefix pref = {
.type = htons(DHCPV6_OPT_IA_PREFIX),
.len = htons(sizeof(pref) - 4),
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);
};
memcpy(ia_pd + ia_pd_len, &hdr_ia_pd, sizeof(hdr_ia_pd));
ia_pd_len += sizeof(hdr_ia_pd);
if (allow_slaac_only >= 0 && allow_slaac_only < 10)
allow_slaac_only = 10;
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;
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;
}
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 == ':')
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 == ':')
" -S <time> Wait at least <time> sec for a DHCP-server (0)\n"
" -D Discard advertisements without any address or prefix proposed\n"
" -N <mode> Mode for requesting addresses [try|force|none]\n"
" -S <time> Wait at least <time> sec for a DHCP-server (0)\n"
" -D Discard advertisements without any address or prefix proposed\n"
" -N <mode> Mode for requesting addresses [try|force|none]\n"
- " -P <length> Request IPv6-Prefix (0 = auto)\n"
+ " -P <[pfx/]len> Request IPv6-Prefix (0 = auto)\n"
" -F Force IPv6-Prefix\n"
" -V <class> Set vendor-class option (base-16 encoded)\n"
" -u <user-class> Set user-class option string\n"
" -F Force IPv6-Prefix\n"
" -V <class> Set vendor-class option (base-16 encoded)\n"
" -u <user-class> Set user-class option string\n"
struct odhcp6c_request_prefix {
uint32_t iaid;
struct odhcp6c_request_prefix {
uint32_t iaid;
+ uint8_t length;
+ struct in6_addr addr;
};
enum odhcp6c_opt_flags {
};
enum odhcp6c_opt_flags {