diff options
| author | Roy Marples <roy@marples.name> | 2019-04-16 18:12:16 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2019-04-16 18:12:16 +0000 |
| commit | 504b658e5bb3f5c96c57c80d1edb0c107b62e559 (patch) | |
| tree | ce8636e5f4904d6d5fb25a7777889aa9c1e798ad /src/ipv6.c | |
| parent | c1209152039f7fa4fa84958f521948f187e78eae (diff) | |
| download | dhcpcd-504b658e5bb3f5c96c57c80d1edb0c107b62e559.tar.xz | |
if: Add a generic function to create an aliased address name
Reduces complexity between IPv4 and IPv6 and silences a warning
about potential string trunctaion if the LUN makes too big an
interface name.
Diffstat (limited to 'src/ipv6.c')
| -rw-r--r-- | src/ipv6.c | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -763,13 +763,13 @@ ipv6_addaddr1(struct ipv6_addr *ia, const struct timespec *now) } #ifdef ALIAS_ADDR -/* Find the next logical aliase address we can use. */ +/* Find the next logical alias address we can use. */ static int ipv6_aliasaddr(struct ipv6_addr *ia, struct ipv6_addr **repl) { struct ipv6_state *state; struct ipv6_addr *iap; - unsigned int unit; + unsigned int lun; char alias[IF_NAMESIZE]; if (ia->alias[0] != '\0') @@ -788,12 +788,14 @@ ipv6_aliasaddr(struct ipv6_addr *ia, struct ipv6_addr **repl) } } - unit = 0; + lun = 0; find_unit: - if (unit == 0) - strlcpy(alias, ia->iface->name, sizeof(alias)); - else - snprintf(alias, sizeof(alias), "%s:%u", ia->iface->name, unit); + if (if_makealias(alias, IF_NAMESIZE, ia->iface->name, lun) >= + IF_NAMESIZE) + { + errno = ENOMEM; + return -1; + } TAILQ_FOREACH(iap, &state->addrs, next) { if (iap->alias[0] == '\0') continue; @@ -809,11 +811,11 @@ find_unit: } if (iap != NULL) { - if (unit == UINT_MAX) { + if (lun == UINT_MAX) { errno = ERANGE; return -1; } - unit++; + lun++; goto find_unit; } |
