Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 3 Dec 2020 10:32:54 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r368297 - stable/12/sbin/ifconfig
Message-ID:  <202012031032.0B3AWs0J066903@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Thu Dec  3 10:32:54 2020
New Revision: 368297
URL: https://svnweb.freebsd.org/changeset/base/368297

Log:
  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

Modified:
  stable/12/sbin/ifconfig/ifclone.c
  stable/12/sbin/ifconfig/ifconfig.c
  stable/12/sbin/ifconfig/ifconfig.h
  stable/12/sbin/ifconfig/ifieee80211.c
  stable/12/sbin/ifconfig/iflagg.c
  stable/12/sbin/ifconfig/ifvlan.c
  stable/12/sbin/ifconfig/ifvxlan.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sbin/ifconfig/ifclone.c
==============================================================================
--- stable/12/sbin/ifconfig/ifclone.c	Thu Dec  3 08:30:29 2020	(r368296)
+++ stable/12/sbin/ifconfig/ifclone.c	Thu Dec  3 10:32:54 2020	(r368297)
@@ -140,8 +140,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);
 	}

Modified: stable/12/sbin/ifconfig/ifconfig.c
==============================================================================
--- stable/12/sbin/ifconfig/ifconfig.c	Thu Dec  3 08:30:29 2020	(r368296)
+++ stable/12/sbin/ifconfig/ifconfig.c	Thu Dec  3 10:32:54 2020	(r368297)
@@ -198,6 +198,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

Modified: stable/12/sbin/ifconfig/ifconfig.h
==============================================================================
--- stable/12/sbin/ifconfig/ifconfig.h	Thu Dec  3 08:30:29 2020	(r368296)
+++ stable/12/sbin/ifconfig/ifconfig.h	Thu Dec  3 10:32:54 2020	(r368297)
@@ -158,3 +158,4 @@ struct ifmediareq *ifmedia_getstate(int s);
 
 void print_vhid(const struct ifaddrs *, const char *);
 
+void ioctl_ifcreate(int s, struct ifreq *);

Modified: stable/12/sbin/ifconfig/ifieee80211.c
==============================================================================
--- stable/12/sbin/ifconfig/ifieee80211.c	Thu Dec  3 08:30:29 2020	(r368296)
+++ stable/12/sbin/ifconfig/ifieee80211.c	Thu Dec  3 10:32:54 2020	(r368297)
@@ -5758,8 +5758,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) &params;
-	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));

Modified: stable/12/sbin/ifconfig/iflagg.c
==============================================================================
--- stable/12/sbin/ifconfig/iflagg.c	Thu Dec  3 08:30:29 2020	(r368296)
+++ stable/12/sbin/ifconfig/iflagg.c	Thu Dec  3 10:32:54 2020	(r368297)
@@ -322,8 +322,7 @@ static void
 lagg_create(int s, struct ifreq *ifr)
 {
 	ifr->ifr_data = (caddr_t) &params;
-	if (ioctl(s, SIOCIFCREATE2, ifr) < 0)
-		err(1, "SIOCIFCREATE2");
+	ioctl_ifcreate(s, ifr);
 }
 
 static struct cmd lagg_cmds[] = {

Modified: stable/12/sbin/ifconfig/ifvlan.c
==============================================================================
--- stable/12/sbin/ifconfig/ifvlan.c	Thu Dec  3 08:30:29 2020	(r368296)
+++ stable/12/sbin/ifconfig/ifvlan.c	Thu Dec  3 10:32:54 2020	(r368297)
@@ -107,8 +107,7 @@ vlan_create(int s, struct ifreq *ifr)
 			errx(1, "must specify a parent device for vlan create");
 		ifr->ifr_data = (caddr_t) &params;
 	}
-	if (ioctl(s, SIOCIFCREATE2, ifr) < 0)
-		err(1, "SIOCIFCREATE2");
+	ioctl_ifcreate(s, ifr);
 }
 
 static void

Modified: stable/12/sbin/ifconfig/ifvxlan.c
==============================================================================
--- stable/12/sbin/ifconfig/ifvxlan.c	Thu Dec  3 08:30:29 2020	(r368296)
+++ stable/12/sbin/ifconfig/ifvxlan.c	Thu Dec  3 10:32:54 2020	(r368297)
@@ -191,8 +191,7 @@ vxlan_create(int s, struct ifreq *ifr)
 	vxlan_check_params();
 
 	ifr->ifr_data = (caddr_t) &params;
-	if (ioctl(s, SIOCIFCREATE2, ifr) < 0)
-		err(1, "SIOCIFCREATE2");
+	ioctl_ifcreate(s, ifr);
 }
 
 static



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202012031032.0B3AWs0J066903>