summaryrefslogtreecommitdiffstats
path: root/src/if.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2020-02-04 16:29:07 +0000
committerRoy Marples <roy@marples.name>2020-02-04 16:31:41 +0000
commita5bb0a83e267a30e5048f2409197d5b969887a91 (patch)
treee9adbd0cffa6b81c37166791a56970b7c1d102e4 /src/if.c
parenta4afbd4c6eadb84bc31e21c8cfdcab56bc5df2ab (diff)
downloaddhcpcd-a5bb0a83e267a30e5048f2409197d5b969887a91.tar.xz
if: decode XEN vif1.2 and xvif1i2 as vif1:2
Diffstat (limited to 'src/if.c')
-rw-r--r--src/if.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/if.c b/src/if.c
index 2fa6e133..81e07827 100644
--- a/src/if.c
+++ b/src/if.c
@@ -666,11 +666,12 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs,
return ifs;
}
-/* Decode bge0:1 as dev = bge, ppa = 0 and lun = 1 */
+/* Decode bge0:1 as dev = bge, ppa = 0 and lun = 1
+ * Special case XEN where : could be i (NetBSD) or . (Linux) */
int
if_nametospec(const char *ifname, struct if_spec *spec)
{
- char *ep;
+ char *ep, *pp;
int e;
if (ifname == NULL || *ifname == '\0' ||
@@ -683,6 +684,8 @@ if_nametospec(const char *ifname, struct if_spec *spec)
return -1;
}
ep = strchr(spec->drvname, ':');
+ if (ep == NULL)
+ ep = strchr(spec->drvname, '.');
if (ep) {
spec->lun = (int)strtoi(ep + 1, NULL, 10, 0, INT_MAX, &e);
if (e != 0) {
@@ -695,16 +698,19 @@ if_nametospec(const char *ifname, struct if_spec *spec)
ep = spec->drvname + strlen(spec->drvname) - 1;
}
strlcpy(spec->devname, spec->drvname, sizeof(spec->devname));
- while (ep > spec->drvname && isdigit((int)*ep))
- ep--;
- if (*ep++ == ':') {
- errno = EINVAL;
- return -1;
+ for (ep = spec->drvname; *ep != '\0' && !isdigit((int)*ep); ep++) {
+ if (*ep == ':') {
+ errno = EINVAL;
+ return -1;
+ }
}
- spec->ppa = (int)strtoi(ep, NULL, 10, 0, INT_MAX, &e);
- if (e != 0)
- spec->ppa = -1;
+ spec->ppa = (int)strtoi(ep, &pp, 10, 0, INT_MAX, &e);
*ep = '\0';
+ if (pp != NULL && *pp == 'i' && spec->lun == -1) {
+ spec->lun = (int)strtoi(pp + 1, NULL, 10, 0, INT_MAX, &e);
+ if (e)
+ spec->lun = -1;
+ }
return 0;
}