diff options
author | Hans Petter Selasky <hselasky@FreeBSD.org> | 2020-12-03 10:41:06 +0000 |
---|---|---|
committer | Hans Petter Selasky <hselasky@FreeBSD.org> | 2020-12-03 10:41:06 +0000 |
commit | e232e33f1f7de48d5332769ef24e9982f737b60c (patch) | |
tree | d8779ef7cdc120cc5942ac464ad0663e60bac8c8 | |
parent | 9a584be27a15ef0c7bfea70b734f43f55643c2f9 (diff) | |
download | src-test-e232e33f1f7de48d5332769ef24e9982f737b60c.tar.gz src-test-e232e33f1f7de48d5332769ef24e9982f737b60c.zip |
MFC r368058:
Ensure consistent error messages from ifconfig(8).
If multiple threads are invoking "ifconfig XXX create" a race may occur
which can lead to two different error messages for the same error.
a) ifconfig: SIOCIFCREATE2: File exists
b) ifconfig: interface XXX already exists
This patch ensures ifconfig prints the same error code
for the same case.
Reviewed by: imp@ and kib@
Differential Revision: https://reviews.freebsd.org/D27380
Sponsored by: Mellanox Technologies // NVIDIA Networking
Notes
Notes:
svn path=/stable/11/; revision=368298
-rw-r--r-- | sbin/ifconfig/ifclone.c | 3 | ||||
-rw-r--r-- | sbin/ifconfig/ifconfig.c | 13 | ||||
-rw-r--r-- | sbin/ifconfig/ifconfig.h | 1 | ||||
-rw-r--r-- | sbin/ifconfig/ifieee80211.c | 3 | ||||
-rw-r--r-- | sbin/ifconfig/ifvlan.c | 3 | ||||
-rw-r--r-- | sbin/ifconfig/ifvxlan.c | 3 |
6 files changed, 18 insertions, 8 deletions
diff --git a/sbin/ifconfig/ifclone.c b/sbin/ifconfig/ifclone.c index 21dcdc3dec8e8..30ce5b2461252 100644 --- a/sbin/ifconfig/ifclone.c +++ b/sbin/ifconfig/ifclone.c @@ -138,8 +138,7 @@ ifclonecreate(int s, void *arg) } if (clone_cb == NULL) { /* NB: no parameters */ - if (ioctl(s, SIOCIFCREATE2, &ifr) < 0) - err(1, "SIOCIFCREATE2"); + ioctl_ifcreate(s, &ifr); } else { clone_cb(s, &ifr); } diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 02c8339b1edb8..17d4cf6bf1717 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -185,6 +185,19 @@ usage(void) exit(1); } +void +ioctl_ifcreate(int s, struct ifreq *ifr) +{ + if (ioctl(s, SIOCIFCREATE2, ifr) < 0) { + switch (errno) { + case EEXIST: + errx(1, "interface %s already exists", ifr->ifr_name); + default: + err(1, "SIOCIFCREATE2"); + } + } +} + #define ORDERS_SIZE(x) sizeof(x) / sizeof(x[0]) static int diff --git a/sbin/ifconfig/ifconfig.h b/sbin/ifconfig/ifconfig.h index 5a9af3aaa7b8b..bb4d0b77cb553 100644 --- a/sbin/ifconfig/ifconfig.h +++ b/sbin/ifconfig/ifconfig.h @@ -157,3 +157,4 @@ struct ifmediareq *ifmedia_getstate(int s); void print_vhid(const struct ifaddrs *, const char *); +void ioctl_ifcreate(int s, struct ifreq *); diff --git a/sbin/ifconfig/ifieee80211.c b/sbin/ifconfig/ifieee80211.c index b13f674e6a830..bc0bf5fb77d00 100644 --- a/sbin/ifconfig/ifieee80211.c +++ b/sbin/ifconfig/ifieee80211.c @@ -5233,8 +5233,7 @@ wlan_create(int s, struct ifreq *ifr) memcmp(params.icp_bssid, zerobssid, sizeof(zerobssid)) == 0) errx(1, "no bssid specified for WDS (use wlanbssid)"); ifr->ifr_data = (caddr_t) ¶ms; - if (ioctl(s, SIOCIFCREATE2, ifr) < 0) - err(1, "SIOCIFCREATE2"); + ioctl_ifcreate(s, ifr); /* XXX preserve original name for ifclonecreate(). */ strlcpy(orig_name, name, sizeof(orig_name)); diff --git a/sbin/ifconfig/ifvlan.c b/sbin/ifconfig/ifvlan.c index 3b37160c3c851..faa0c4e617088 100644 --- a/sbin/ifconfig/ifvlan.c +++ b/sbin/ifconfig/ifvlan.c @@ -105,8 +105,7 @@ vlan_create(int s, struct ifreq *ifr) errx(1, "must specify a parent device for vlan create"); ifr->ifr_data = (caddr_t) ¶ms; } - if (ioctl(s, SIOCIFCREATE2, ifr) < 0) - err(1, "SIOCIFCREATE2"); + ioctl_ifcreate(s, ifr); } static void diff --git a/sbin/ifconfig/ifvxlan.c b/sbin/ifconfig/ifvxlan.c index 7f78d2be88899..9c31358392203 100644 --- a/sbin/ifconfig/ifvxlan.c +++ b/sbin/ifconfig/ifvxlan.c @@ -191,8 +191,7 @@ vxlan_create(int s, struct ifreq *ifr) vxlan_check_params(); ifr->ifr_data = (caddr_t) ¶ms; - if (ioctl(s, SIOCIFCREATE2, ifr) < 0) - err(1, "SIOCIFCREATE2"); + ioctl_ifcreate(s, ifr); } static |