]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Move vimaster checks to if-bsd.c
authorRoy Marples <roy@marples.name>
Tue, 21 Jan 2014 16:27:47 +0000 (16:27 +0000)
committerRoy Marples <roy@marples.name>
Tue, 21 Jan 2014 16:27:47 +0000 (16:27 +0000)
Make a note to try and support similar on Linux.

if-bsd.c
if-linux.c
net.c
net.h

index c5c4c3305ac42c15a6113875492768c3f447f711..3d44d43f181faddb2194a33e76b311dbae432785 100644 (file)
--- a/if-bsd.c
+++ b/if-bsd.c
@@ -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 @@ getifssid(const char *ifname, char *ssid)
        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 @@ getifssid(const char *ifname, char *ssid)
        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,
index 4f908476a5aa972a75be4739969f248da0238c58..b8ef954ac59bc890585965f7adda5cc7238bef84 100644 (file)
@@ -112,6 +112,14 @@ if_conf(struct interface *iface)
        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)
 {
diff --git a/net.c b/net.c
index 1cf601e429d5a6d37df1357b6dbccf53e7c3e3e9..13aa9a664bf2f33c27ab1dcd41a108f3dfa877b4 100644 (file)
--- a/net.c
+++ b/net.c
@@ -186,33 +186,6 @@ carrier_status(struct interface *iface)
        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 @@ discover_interfaces(int argc, char * const *argv)
                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;
diff --git a/net.h b/net.h
index 46742ac4ac74320b6f92a6322fb126f51cb71793..cc39ae802eb2d53ab736c81a999d0782ef0f97e3 100644 (file)
--- a/net.h
+++ b/net.h
@@ -93,6 +93,7 @@ char *hwaddr_ntoa(const unsigned char *, size_t);
 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);