summaryrefslogtreecommitdiff
path: root/usr/src/cmd/zonecfg
diff options
context:
space:
mode:
authorJerry Jelinek <jerry.jelinek@joyent.com>2012-02-16 21:00:50 +0000
committerJerry Jelinek <jerry.jelinek@joyent.com>2012-02-16 21:00:50 +0000
commit5b3fa78d35ca53d3e6bdab44423f44364eaf108c (patch)
tree04024f5944f24083d91a60d1fbc358cf02a0e7d8 /usr/src/cmd/zonecfg
parent672a906c603fae34ca7bbcc4950ccbb9cc8ce180 (diff)
downloadillumos-joyent-5b3fa78d35ca53d3e6bdab44423f44364eaf108c.tar.gz
OS-950 zonecfg should not barf when MAC address is formatted with or without leading zeros
Diffstat (limited to 'usr/src/cmd/zonecfg')
-rw-r--r--usr/src/cmd/zonecfg/zonecfg.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/usr/src/cmd/zonecfg/zonecfg.c b/usr/src/cmd/zonecfg/zonecfg.c
index f3d267b9dc..931acbcdbf 100644
--- a/usr/src/cmd/zonecfg/zonecfg.c
+++ b/usr/src/cmd/zonecfg/zonecfg.c
@@ -21,7 +21,7 @@
/*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2011, Joyent Inc. All rights reserved.
+ * Copyright (c) 2012, Joyent Inc. All rights reserved.
*/
/*
@@ -2793,6 +2793,32 @@ fill_in_fstab(cmd_t *cmd, struct zone_fstab *fstab, boolean_t fill_in_only)
return (zonecfg_lookup_filesystem(handle, fstab));
}
+/*
+ * Turn an addr that looks like f:2:0:44:5:6C into 0f:02:00:44:05:6c
+ * We're expecting a dst of at least MAXMACADDRLEN size here.
+ */
+static void
+normalize_mac_addr(char *dst, const char *src, int len)
+{
+ char *p, *e, *sep = "";
+ long n;
+ char buf[MAXMACADDRLEN], tmp[4];
+
+ *dst = '\0';
+ (void) strlcpy(buf, src, sizeof (buf));
+ p = strtok(buf, ":");
+ while (p != NULL) {
+ n = strtol(p, &e, 16);
+ if (*e != NULL || n > 0xff)
+ return;
+ (void) snprintf(tmp, sizeof (tmp), "%s%02x", sep, n);
+ (void) strlcat(dst, tmp, len);
+
+ sep = ":";
+ p = strtok(NULL, ":");
+ }
+}
+
static int
fill_in_nwiftab(cmd_t *cmd, struct zone_nwiftab *nwiftab,
boolean_t fill_in_only)
@@ -2827,7 +2853,7 @@ fill_in_nwiftab(cmd_t *cmd, struct zone_nwiftab *nwiftab,
sizeof (nwiftab->zone_nwif_physical));
break;
case PT_MAC:
- (void) strlcpy(nwiftab->zone_nwif_mac,
+ normalize_mac_addr(nwiftab->zone_nwif_mac,
pp->pv_simple,
sizeof (nwiftab->zone_nwif_mac));
break;
@@ -4675,7 +4701,7 @@ set_func(cmd_t *cmd)
sizeof (in_progress_nwiftab.zone_nwif_physical));
break;
case PT_MAC:
- (void) strlcpy(in_progress_nwiftab.zone_nwif_mac,
+ normalize_mac_addr(in_progress_nwiftab.zone_nwif_mac,
prop_id,
sizeof (in_progress_nwiftab.zone_nwif_mac));
break;