Blame SOURCES/macsec-0023-drivers-Move-driver_wired_get_ifstatus-to-a-common-f.patch

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