changeset 5021:6bac2fa75c95 draft

if: decode XEN vif1.2 and xvif1i2 as vif1:2
author Roy Marples <roy@marples.name>
date Tue, 04 Feb 2020 16:29:07 +0000
parents b1cda92cbf98
children cb03ee4a2a37
files src/if.c
diffstat 1 files changed, 16 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/if.c	Mon Jan 27 20:22:21 2020 +0000
+++ b/src/if.c	Tue Feb 04 16:29:07 2020 +0000
@@ -612,11 +612,12 @@
 	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 @@
 		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 @@
 		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;
 }