From: Roy Marples Date: Tue, 21 Jan 2014 16:27:47 +0000 (+0000) Subject: Move vimaster checks to if-bsd.c X-Git-Tag: v6.3.0~96 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7d766720b48a7fbd522ddacc1a9ffa6f821d99e4;p=thirdparty%2Fdhcpcd.git Move vimaster checks to if-bsd.c Make a note to try and support similar on Linux. --- diff --git a/if-bsd.c b/if-bsd.c index c5c4c330..3d44d43f 100644 --- a/if-bsd.c +++ b/if-bsd.c @@ -38,6 +38,7 @@ #ifdef __FreeBSD__ /* Needed so that including netinet6/in6_var.h works */ # include #endif +#include #include #include #include @@ -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, diff --git a/if-linux.c b/if-linux.c index 4f908476..b8ef954a 100644 --- a/if-linux.c +++ b/if-linux.c @@ -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 1cf601e4..13aa9a66 100644 --- 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 46742ac4..cc39ae80 100644 --- 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);