From 5a55ec38edd875fc6dc54c0483e1f96ad9cf8cf9 Mon Sep 17 00:00:00 2001 Message-Id: <5a55ec38edd875fc6dc54c0483e1f96ad9cf8cf9.1488376602.git.dcaratti@redhat.com> From: Sabrina Dubroca Date: Sun, 27 Nov 2016 20:08:49 +0100 Subject: [PATCH] drivers: Move driver_wired_get_ifstatus() to a common file This continues refactoring of the common parts of wired drivers code into a shared file, so that they can be reused by other drivers. Signed-off-by: Sabrina Dubroca --- src/drivers/driver_macsec_qca.c | 31 +------------------------------ src/drivers/driver_wired.c | 31 +------------------------------ src/drivers/driver_wired_common.c | 29 +++++++++++++++++++++++++++++ src/drivers/driver_wired_common.h | 1 + 4 files changed, 32 insertions(+), 60 deletions(-) diff --git a/src/drivers/driver_macsec_qca.c b/src/drivers/driver_macsec_qca.c index 31cb0dc..786e2e8 100644 --- a/src/drivers/driver_macsec_qca.c +++ b/src/drivers/driver_macsec_qca.c @@ -99,35 +99,6 @@ static int macsec_qca_get_capa(void *priv, struct wpa_driver_capa *capa) } -#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) -static int macsec_qca_get_ifstatus(const char *ifname, int *status) -{ - struct ifmediareq ifmr; - int s; - - s = socket(PF_INET, SOCK_DGRAM, 0); - if (s < 0) { - wpa_print(MSG_ERROR, "socket: %s", strerror(errno)); - return -1; - } - - os_memset(&ifmr, 0, sizeof(ifmr)); - os_strlcpy(ifmr.ifm_name, ifname, IFNAMSIZ); - if (ioctl(s, SIOCGIFMEDIA, (caddr_t) &ifmr) < 0) { - wpa_printf(MSG_ERROR, "ioctl[SIOCGIFMEDIA]: %s", - strerror(errno)); - close(s); - return -1; - } - close(s); - *status = (ifmr.ifm_status & (IFM_ACTIVE | IFM_AVALID)) == - (IFM_ACTIVE | IFM_AVALID); - - return 0; -} -#endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(FreeBSD_kernel__) */ - - static void __macsec_drv_init(struct macsec_qca_data *drv) { int ret = 0; @@ -243,7 +214,7 @@ static void * macsec_qca_init(void *ctx, const char *ifname) int status; wpa_printf(MSG_DEBUG, "%s: waiting for link to become active", __func__); - while (macsec_qca_get_ifstatus(ifname, &status) == 0 && + while (driver_wired_get_ifstatus(ifname, &status) == 0 && status == 0) sleep(1); } diff --git a/src/drivers/driver_wired.c b/src/drivers/driver_wired.c index 953fa3d..db83683 100644 --- a/src/drivers/driver_wired.c +++ b/src/drivers/driver_wired.c @@ -390,35 +390,6 @@ static int wpa_driver_wired_get_capa(void *priv, struct wpa_driver_capa *capa) } -#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) -static int wpa_driver_wired_get_ifstatus(const char *ifname, int *status) -{ - struct ifmediareq ifmr; - int s; - - s = socket(PF_INET, SOCK_DGRAM, 0); - if (s < 0) { - wpa_printf(MSG_ERROR, "socket: %s", strerror(errno)); - return -1; - } - - os_memset(&ifmr, 0, sizeof(ifmr)); - os_strlcpy(ifmr.ifm_name, ifname, IFNAMSIZ); - if (ioctl(s, SIOCGIFMEDIA, (caddr_t) &ifmr) < 0) { - wpa_printf(MSG_ERROR, "ioctl[SIOCGIFMEDIA]: %s", - strerror(errno)); - close(s); - return -1; - } - close(s); - *status = (ifmr.ifm_status & (IFM_ACTIVE | IFM_AVALID)) == - (IFM_ACTIVE | IFM_AVALID); - - return 0; -} -#endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(FreeBSD_kernel__) */ - - static void * wpa_driver_wired_init(void *ctx, const char *ifname) { struct wpa_driver_wired_data *drv; @@ -477,7 +448,7 @@ static void * wpa_driver_wired_init(void *ctx, const char *ifname) int status; wpa_printf(MSG_DEBUG, "%s: waiting for link to become active", __func__); - while (wpa_driver_wired_get_ifstatus(ifname, &status) == 0 && + while (driver_wired_get_ifstatus(ifname, &status) == 0 && status == 0) sleep(1); } diff --git a/src/drivers/driver_wired_common.c b/src/drivers/driver_wired_common.c index 52f22de..e55e2c7 100644 --- a/src/drivers/driver_wired_common.c +++ b/src/drivers/driver_wired_common.c @@ -162,3 +162,32 @@ int wired_multicast_membership(int sock, int ifindex, const u8 *addr, int add) return -1; #endif /* __linux__ */ } + + +#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) +int driver_wired_get_ifstatus(const char *ifname, int *status) +{ + struct ifmediareq ifmr; + int s; + + s = socket(PF_INET, SOCK_DGRAM, 0); + if (s < 0) { + wpa_printf(MSG_ERROR, "socket: %s", strerror(errno)); + return -1; + } + + os_memset(&ifmr, 0, sizeof(ifmr)); + os_strlcpy(ifmr.ifm_name, ifname, IFNAMSIZ); + if (ioctl(s, SIOCGIFMEDIA, (caddr_t) &ifmr) < 0) { + wpa_printf(MSG_ERROR, "ioctl[SIOCGIFMEDIA]: %s", + strerror(errno)); + close(s); + return -1; + } + close(s); + *status = (ifmr.ifm_status & (IFM_ACTIVE | IFM_AVALID)) == + (IFM_ACTIVE | IFM_AVALID); + + return 0; +} +#endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(FreeBSD_kernel__) */ diff --git a/src/drivers/driver_wired_common.h b/src/drivers/driver_wired_common.h index e2d8bbe..c8e347a 100644 --- a/src/drivers/driver_wired_common.h +++ b/src/drivers/driver_wired_common.h @@ -26,5 +26,6 @@ int driver_wired_get_ifflags(const char *ifname, int *flags); int driver_wired_set_ifflags(const char *ifname, int flags); int driver_wired_multi(const char *ifname, const u8 *addr, int add); int wired_multicast_membership(int sock, int ifindex, const u8 *addr, int add); +int driver_wired_get_ifstatus(const char *ifname, int *status); #endif /* DRIVER_WIRED_COMMON_H */ -- 2.7.4