From owner-svn-src-all@FreeBSD.ORG Fri Feb 27 00:31:34 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AB63C1065670; Fri, 27 Feb 2009 00:31:34 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 8F07B8FC08; Fri, 27 Feb 2009 00:31:34 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n1R0VYII043697; Fri, 27 Feb 2009 00:31:34 GMT (envelope-from rpaulo@svn.freebsd.org) Received: (from rpaulo@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n1R0VY8E043693; Fri, 27 Feb 2009 00:31:34 GMT (envelope-from rpaulo@svn.freebsd.org) Message-Id: <200902270031.n1R0VY8E043693@svn.freebsd.org> From: Rui Paulo Date: Fri, 27 Feb 2009 00:31:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r189096 - head/sbin/ifconfig X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Feb 2009 00:31:35 -0000 Author: rpaulo Date: Fri Feb 27 00:31:34 2009 New Revision: 189096 URL: http://svn.freebsd.org/changeset/base/189096 Log: Replace clone_setcallback() with a new function clone_setdefcallback() that selects a callback from an interface prefix name. This allows us to report a meaningful error when the user types 'ifconfig wlan0 create', for example, and also kills some redundant code. Reviewed by: sam (earlier version) Modified: head/sbin/ifconfig/ifclone.c head/sbin/ifconfig/ifconfig.h head/sbin/ifconfig/ifieee80211.c head/sbin/ifconfig/ifvlan.c Modified: head/sbin/ifconfig/ifclone.c ============================================================================== --- head/sbin/ifconfig/ifclone.c Thu Feb 26 23:21:32 2009 (r189095) +++ head/sbin/ifconfig/ifclone.c Fri Feb 27 00:31:34 2009 (r189096) @@ -32,6 +32,7 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* not lint */ +#include #include #include #include @@ -88,14 +89,24 @@ list_cloners(void) free(buf); } -static clone_callback_func *clone_cb = NULL; +struct clone_defcb { + char ifprefix[IFNAMSIZ]; + clone_callback_func *clone_cb; + SLIST_ENTRY(clone_defcb) next; +}; + +static SLIST_HEAD(, clone_defcb) clone_defcbh = + SLIST_HEAD_INITIALIZER(clone_defcbh); void -clone_setcallback(clone_callback_func *p) +clone_setdefcallback(const char *ifprefix, clone_callback_func *p) { - if (clone_cb != NULL && clone_cb != p) - errx(1, "conflicting device create parameters"); - clone_cb = p; + struct clone_defcb *dcp; + + dcp = malloc(sizeof(*dcp)); + strlcpy(dcp->ifprefix, ifprefix, IFNAMSIZ-1); + dcp->clone_cb = p; + SLIST_INSERT_HEAD(&clone_defcbh, dcp, next); } /* @@ -108,9 +119,22 @@ static void ifclonecreate(int s, void *arg) { struct ifreq ifr; + struct clone_defcb *dcp; + clone_callback_func *clone_cb = NULL; memset(&ifr, 0, sizeof(ifr)); (void) strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + + if (clone_cb == NULL) { + /* Try to find a default callback */ + SLIST_FOREACH(dcp, &clone_defcbh, next) { + if (strncmp(dcp->ifprefix, ifr.ifr_name, + strlen(dcp->ifprefix)) == 0) { + clone_cb = dcp->clone_cb; + break; + } + } + } if (clone_cb == NULL) { /* NB: no parameters */ if (ioctl(s, SIOCIFCREATE2, &ifr) < 0) Modified: head/sbin/ifconfig/ifconfig.h ============================================================================== --- head/sbin/ifconfig/ifconfig.h Thu Feb 26 23:21:32 2009 (r189095) +++ head/sbin/ifconfig/ifconfig.h Fri Feb 27 00:31:34 2009 (r189096) @@ -141,7 +141,7 @@ void printb(const char *s, unsigned valu void ifmaybeload(const char *name); typedef void clone_callback_func(int, struct ifreq *); -void clone_setcallback(clone_callback_func *); +void clone_setdefcallback(const char *, clone_callback_func *); /* * XXX expose this so modules that neeed to know of any pending Modified: head/sbin/ifconfig/ifieee80211.c ============================================================================== --- head/sbin/ifconfig/ifieee80211.c Thu Feb 26 23:21:32 2009 (r189095) +++ head/sbin/ifconfig/ifieee80211.c Fri Feb 27 00:31:34 2009 (r189096) @@ -4667,7 +4667,8 @@ wlan_create(int s, struct ifreq *ifr) static const uint8_t zerobssid[IEEE80211_ADDR_LEN]; if (params.icp_parent[0] == '\0') - errx(1, "must specify a parent when creating a wlan device"); + errx(1, "must specify a parent device (wlandev) when creating " + "a wlan device"); if (params.icp_opmode == IEEE80211_M_WDS && memcmp(params.icp_bssid, zerobssid, sizeof(zerobssid)) == 0) errx(1, "no bssid specified for WDS (use wlanbssid)"); @@ -4680,7 +4681,6 @@ static DECL_CMD_FUNC(set80211clone_wlandev, arg, d) { strlcpy(params.icp_parent, arg, IFNAMSIZ); - clone_setcallback(wlan_create); } static @@ -4692,7 +4692,6 @@ DECL_CMD_FUNC(set80211clone_wlanbssid, a if (ea == NULL) errx(1, "%s: cannot parse bssid", arg); memcpy(params.icp_bssid, ea->octet, IEEE80211_ADDR_LEN); - clone_setcallback(wlan_create); } static @@ -4705,7 +4704,6 @@ DECL_CMD_FUNC(set80211clone_wlanaddr, ar errx(1, "%s: cannot parse addres", arg); memcpy(params.icp_macaddr, ea->octet, IEEE80211_ADDR_LEN); params.icp_flags |= IEEE80211_CLONE_MACADDR; - clone_setcallback(wlan_create); } static @@ -4729,7 +4727,6 @@ DECL_CMD_FUNC(set80211clone_wlanmode, ar params.icp_flags |= IEEE80211_CLONE_TDMA; } else errx(1, "Don't know to create %s for %s", arg, name); - clone_setcallback(wlan_create); #undef iseq } @@ -4741,7 +4738,6 @@ set80211clone_beacons(const char *val, i params.icp_flags &= ~IEEE80211_CLONE_NOBEACONS; else params.icp_flags |= IEEE80211_CLONE_NOBEACONS; - clone_setcallback(wlan_create); } static void @@ -4751,7 +4747,6 @@ set80211clone_bssid(const char *val, int params.icp_flags |= IEEE80211_CLONE_BSSID; else params.icp_flags &= ~IEEE80211_CLONE_BSSID; - clone_setcallback(wlan_create); } static void @@ -4761,7 +4756,6 @@ set80211clone_wdslegacy(const char *val, params.icp_flags |= IEEE80211_CLONE_WDSLEGACY; else params.icp_flags &= ~IEEE80211_CLONE_WDSLEGACY; - clone_setcallback(wlan_create); } static struct cmd ieee80211_cmds[] = { @@ -4935,5 +4929,6 @@ ieee80211_ctor(void) for (i = 0; i < N(ieee80211_cmds); i++) cmd_register(&ieee80211_cmds[i]); af_register(&af_ieee80211); + clone_setdefcallback("wlan", wlan_create); #undef N } Modified: head/sbin/ifconfig/ifvlan.c ============================================================================== --- head/sbin/ifconfig/ifvlan.c Thu Feb 26 23:21:32 2009 (r189095) +++ head/sbin/ifconfig/ifvlan.c Fri Feb 27 00:31:34 2009 (r189096) @@ -136,8 +136,6 @@ DECL_CMD_FUNC(setvlantag, val, d) if (getvlan(s, &ifr, &vreq) != -1) vlan_set(s, &ifr); - else - clone_setcallback(vlan_create); } static @@ -149,8 +147,6 @@ DECL_CMD_FUNC(setvlandev, val, d) if (getvlan(s, &ifr, &vreq) != -1) vlan_set(s, &ifr); - else - clone_setcallback(vlan_create); } static @@ -202,5 +198,6 @@ vlan_ctor(void) cmd_register(&vlan_cmds[i]); af_register(&af_vlan); callback_register(vlan_cb, NULL); + clone_setdefcallback("vlan", vlan_create); #undef N }