]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
if: decode XEN vif1.2 and xvif1i2 as vif1:2
authorRoy Marples <roy@marples.name>
Tue, 4 Feb 2020 16:29:07 +0000 (16:29 +0000)
committerRoy Marples <roy@marples.name>
Tue, 4 Feb 2020 16:29:07 +0000 (16:29 +0000)
src/if.c

index c0b67ec991442432ff3b9bd08b79d54928ed83a6..044dba459d0178d253e1e178fe87d74c998d50d1 100644 (file)
--- a/src/if.c
+++ b/src/if.c
@@ -612,11 +612,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' ||
@@ -629,6 +630,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) {
@@ -641,16 +644,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;
 }