summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorkp <kp@FreeBSD.org>2016-03-06 08:52:03 +0000
committerkp <kp@FreeBSD.org>2016-03-06 08:52:03 +0000
commita0a9dc5d39bce93901950e25e91887b10edd6402 (patch)
treeb7530b1a66b20cd4cf98d809d1b0d18733fca459 /sbin
parent241b0e18f171e529b4c5596005704c3a624ed8a2 (diff)
downloadFreeBSD-src-a0a9dc5d39bce93901950e25e91887b10edd6402.zip
FreeBSD-src-a0a9dc5d39bce93901950e25e91887b10edd6402.tar.gz
MFC r295836:
ifconfig(8): can't use 'name' or 'description' when creating interface with auto numbering If one does 'ifconfig tap create name blah', it will return error because the 'name' command doesn't properly populate the request sent to ioctl(...). The 'description' command has the same bug, and is also fixed with this patch. If one does 'ifconfig tap create mtu 9000 name blah', it DOES work, but 'tap0' (or other sequence number) is echoed, instead of the expected 'blah'. (assuming the name change actually succeeded) PR: 206876 Submitted by: Marie Helene Kvello-Aune <marieheleneka@gmail.com> Differential Revision: https://reviews.freebsd.org/D5341
Diffstat (limited to 'sbin')
-rw-r--r--sbin/ifconfig/ifclone.c5
-rw-r--r--sbin/ifconfig/ifconfig.c20
-rw-r--r--sbin/ifconfig/ifconfig.h1
3 files changed, 24 insertions, 2 deletions
diff --git a/sbin/ifconfig/ifclone.c b/sbin/ifconfig/ifclone.c
index 6a60d41..0eda438 100644
--- a/sbin/ifconfig/ifclone.c
+++ b/sbin/ifconfig/ifclone.c
@@ -144,11 +144,12 @@ ifclonecreate(int s, void *arg)
}
/*
- * If we get a different name back than we put in, print it.
+ * If we get a different name back than we put in, update record and
+ * indicate it should be printed later.
*/
if (strncmp(name, ifr.ifr_name, sizeof(name)) != 0) {
strlcpy(name, ifr.ifr_name, sizeof(name));
- printf("%s\n", name);
+ printifname = 1;
}
}
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index 19bd1ac..47b75c3 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -93,6 +93,7 @@ int clearaddr;
int newaddr = 1;
int verbose;
int noload;
+int printifname = 0;
int supmedia = 0;
int printkeys = 0; /* Print keying material for interfaces. */
@@ -108,6 +109,8 @@ static struct afswtch *af_getbyname(const char *name);
static struct afswtch *af_getbyfamily(int af);
static void af_other_status(int);
+void printifnamemaybe(void);
+
static struct option *opts = NULL;
void
@@ -141,6 +144,12 @@ usage(void)
exit(1);
}
+void printifnamemaybe()
+{
+ if (printifname)
+ printf("%s\n", name);
+}
+
int
main(int argc, char *argv[])
{
@@ -156,6 +165,12 @@ main(int argc, char *argv[])
size_t iflen;
all = downonly = uponly = namesonly = noload = verbose = 0;
+
+ /*
+ * Ensure we print interface name when expected to,
+ * even if we terminate early due to error.
+ */
+ atexit(printifnamemaybe);
/* Parse leading line options */
strlcpy(options, "adklmnuv", sizeof(options));
@@ -856,6 +871,8 @@ setifname(const char *val, int dummy __unused, int s,
const struct afswtch *afp)
{
char *newname;
+
+ strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
newname = strdup(val);
if (newname == NULL)
@@ -865,6 +882,7 @@ setifname(const char *val, int dummy __unused, int s,
free(newname);
err(1, "ioctl SIOCSIFNAME (set name)");
}
+ printifname = 1;
strlcpy(name, newname, sizeof(name));
free(newname);
}
@@ -876,6 +894,8 @@ setifdescr(const char *val, int dummy __unused, int s,
{
char *newdescr;
+ strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+
ifr.ifr_buffer.length = strlen(val) + 1;
if (ifr.ifr_buffer.length == 1) {
ifr.ifr_buffer.buffer = newdescr = NULL;
diff --git a/sbin/ifconfig/ifconfig.h b/sbin/ifconfig/ifconfig.h
index 6df9acf..ada224f 100644
--- a/sbin/ifconfig/ifconfig.h
+++ b/sbin/ifconfig/ifconfig.h
@@ -133,6 +133,7 @@ extern int supmedia;
extern int printkeys;
extern int newaddr;
extern int verbose;
+extern int printifname;
void setifcap(const char *, int value, int s, const struct afswtch *);
OpenPOWER on IntegriCloud