changeset 2237:b2bf5887f15a draft

Move vimaster checks to if-bsd.c Make a note to try and support similar on Linux.
author Roy Marples <roy@marples.name>
date Tue, 21 Jan 2014 16:27:47 +0000
parents d1cd3082f593
children a9b2a3826495
files if-bsd.c if-linux.c net.c net.h
diffstat 4 files changed, 45 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/if-bsd.c	Tue Jan 21 15:57:30 2014 +0000
+++ b/if-bsd.c	Tue Jan 21 16:27:47 2014 +0000
@@ -38,6 +38,7 @@
 #ifdef __FreeBSD__ /* Needed so that including netinet6/in6_var.h works */
 #  include <net/if_var.h>
 #endif
+#include <net/if_media.h>
 #include <net/route.h>
 #include <netinet/in.h>
 #include <netinet6/in6_var.h>
@@ -159,8 +160,10 @@
 	ifr.ifr_data = (void *)&nwid;
 	if (ioctl(socket_afnet, SIOCG80211NWID, &ifr) == 0) {
 		retval = nwid.i_len;
-		memcpy(ssid, nwid.i_nwid, nwid.i_len);
-		ssid[nwid.i_len] = '\0';
+		if (ssid) {
+			memcpy(ssid, nwid.i_nwid, nwid.i_len);
+			ssid[nwid.i_len] = '\0';
+		}
 	}
 #elif defined(IEEE80211_IOC_SSID) /* FreeBSD */
 	memset(&ireq, 0, sizeof(ireq));
@@ -171,13 +174,40 @@
 	ireq.i_data = &nwid;
 	if (ioctl(socket_afnet, SIOCG80211, &ireq) == 0) {
 		retval = ireq.i_len;
-		memcpy(ssid, nwid, ireq.i_len);
-		ssid[ireq.i_len] = '\0';
+		if (ssid) {
+			memcpy(ssid, nwid, ireq.i_len);
+			ssid[ireq.i_len] = '\0';
+		}
 	}
 #endif
 	return retval;
 }
 
+/*
+ * FreeBSD allows for Virtual Access Points
+ * We need to check if the interface is a Virtual Interface Master
+ * and if so, don't use it.
+ * This check is made by virtue of being a IEEE80211 device but
+ * returning the SSID gives an error.
+ */
+int
+if_vimaster(const char *ifname)
+{
+	struct ifmediareq ifmr;
+
+	memset(&ifmr, 0, sizeof(ifmr));
+	strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name));
+	if (ioctl(socket_afnet, SIOCGIFMEDIA, &ifmr) == -1)
+		return -1;
+	if (ifmr.ifm_status & IFM_AVALID &&
+	    IFM_TYPE(ifmr.ifm_active) == IFM_IEEE80211)
+	{
+		if (getifssid(ifname, NULL) == -1)
+			return 1;
+	}
+	return 0;
+}
+
 #ifdef INET
 int
 if_address(const struct interface *iface, const struct in_addr *address,
--- a/if-linux.c	Tue Jan 21 15:57:30 2014 +0000
+++ b/if-linux.c	Tue Jan 21 16:27:47 2014 +0000
@@ -112,6 +112,14 @@
 	return 0;
 }
 
+/* XXX work out Virtal Interface Masters */
+int
+if_vimaster(_unused const char *ifname)
+{
+
+	return 0;
+}
+
 static int
 _open_link_socket(struct sockaddr_nl *nl)
 {
--- a/net.c	Tue Jan 21 15:57:30 2014 +0000
+++ b/net.c	Tue Jan 21 16:27:47 2014 +0000
@@ -186,33 +186,6 @@
 	return ret;
 }
 
-/*
- * FreeBSD allows for Virtual Access Points
- * We need to check if the interface is a Virtual Interface Master
- * and if so, don't use it.
- */
-static int
-vi_master(const char *ifname)
-{
-#ifdef SIOCGIFMEDIA
-	struct ifmediareq ifmr;
-	char ssid[IF_SSIDSIZE];
-
-	memset(&ifmr, 0, sizeof(ifmr));
-	strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name));
-	if (ioctl(socket_afnet, SIOCGIFMEDIA, &ifmr) == -1)
-		return -1;
-	if (ifmr.ifm_status & IFM_AVALID &&
-	    IFM_TYPE(ifmr.ifm_active) == IFM_IEEE80211)
-	{
-		if (getifssid(ifname, ssid) == -1)
-			return 1;
-	}
-#endif
-
-	return 0;
-}
-
 int
 up_interface(struct interface *iface)
 {
@@ -345,8 +318,8 @@
 		if (ifac && i == ifac)
 			continue;
 
-		if (vi_master(ifa->ifa_name) == 1) {
-			syslog(LOG_DEBUG,
+		if (if_vimaster(ifa->ifa_name) == 1) {
+			syslog(argc ? LOG_ERR : LOG_DEBUG,
 				"%s: is a Virtual Interface Master, skipping",
 				ifa->ifa_name);
 			continue;
--- a/net.h	Tue Jan 21 15:57:30 2014 +0000
+++ b/net.h	Tue Jan 21 16:27:47 2014 +0000
@@ -93,6 +93,7 @@
 size_t hwaddr_aton(unsigned char *, const char *);
 
 int getifssid(const char *, char *);
+int if_vimaster(const char *);
 struct if_head *discover_interfaces(int, char * const *);
 void free_interface(struct interface *);
 int do_mtu(const char *, short int);