Blob Blame History Raw
From 567b7d4ec29cd5b97b00703b5afb03d023abb532 Mon Sep 17 00:00:00 2001
Message-Id: <567b7d4ec29cd5b97b00703b5afb03d023abb532.1488376602.git.dcaratti@redhat.com>
From: Sabrina Dubroca <sd@queasysnail.net>
Date: Sun, 27 Nov 2016 20:08:47 +0100
Subject: [PATCH] drivers: Move driver_wired_get_ifflags() 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 <sd@queasysnail.net>
---
 src/drivers/driver_macsec_qca.c   | 33 ++++-----------------------------
 src/drivers/driver_wired.c        | 33 ++++-----------------------------
 src/drivers/driver_wired_common.c | 25 +++++++++++++++++++++++++
 src/drivers/driver_wired_common.h |  1 +
 4 files changed, 34 insertions(+), 58 deletions(-)

diff --git a/src/drivers/driver_macsec_qca.c b/src/drivers/driver_macsec_qca.c
index 6c07e01..d0d4611 100644
--- a/src/drivers/driver_macsec_qca.c
+++ b/src/drivers/driver_macsec_qca.c
@@ -99,31 +99,6 @@ static int macsec_qca_get_capa(void *priv, struct wpa_driver_capa *capa)
 }
 
 
-static int macsec_qca_get_ifflags(const char *ifname, int *flags)
-{
-	struct ifreq ifr;
-	int s;
-
-	s = socket(PF_INET, SOCK_DGRAM, 0);
-	if (s < 0) {
-		wpa_printf(MSG_ERROR, "socket: %s", strerror(errno));
-		return -1;
-	}
-
-	os_memset(&ifr, 0, sizeof(ifr));
-	os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
-	if (ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
-		wpa_printf(MSG_ERROR, "ioctl[SIOCGIFFLAGS]: %s",
-			   strerror(errno));
-		close(s);
-		return -1;
-	}
-	close(s);
-	*flags = ifr.ifr_flags & 0xffff;
-	return 0;
-}
-
-
 static int macsec_qca_set_ifflags(const char *ifname, int flags)
 {
 	struct ifreq ifr;
@@ -252,7 +227,7 @@ static void * macsec_qca_init(void *ctx, const char *ifname)
 	drv->common.pf_sock = -1;
 #endif /* __linux__ */
 
-	if (macsec_qca_get_ifflags(ifname, &flags) == 0 &&
+	if (driver_wired_get_ifflags(ifname, &flags) == 0 &&
 	    !(flags & IFF_UP) &&
 	    macsec_qca_set_ifflags(ifname, flags | IFF_UP) == 0) {
 		drv->common.iff_up = 1;
@@ -270,7 +245,7 @@ static void * macsec_qca_init(void *ctx, const char *ifname)
 			   "%s: Added multicast membership with SIOCADDMULTI",
 			   __func__);
 		drv->common.multi = 1;
-	} else if (macsec_qca_get_ifflags(ifname, &flags) < 0) {
+	} else if (driver_wired_get_ifflags(ifname, &flags) < 0) {
 		wpa_printf(MSG_INFO, "%s: Could not get interface flags",
 			   __func__);
 		os_free(drv);
@@ -325,7 +300,7 @@ static void macsec_qca_deinit(void *priv)
 	}
 
 	if (drv->common.iff_allmulti &&
-	    (macsec_qca_get_ifflags(drv->common.ifname, &flags) < 0 ||
+	    (driver_wired_get_ifflags(drv->common.ifname, &flags) < 0 ||
 	     macsec_qca_set_ifflags(drv->common.ifname,
 				    flags & ~IFF_ALLMULTI) < 0)) {
 		wpa_printf(MSG_DEBUG, "%s: Failed to disable allmulti mode",
@@ -333,7 +308,7 @@ static void macsec_qca_deinit(void *priv)
 	}
 
 	if (drv->common.iff_up &&
-	    macsec_qca_get_ifflags(drv->common.ifname, &flags) == 0 &&
+	    driver_wired_get_ifflags(drv->common.ifname, &flags) == 0 &&
 	    (flags & IFF_UP) &&
 	    macsec_qca_set_ifflags(drv->common.ifname, flags & ~IFF_UP) < 0) {
 		wpa_printf(MSG_DEBUG, "%s: Failed to set the interface down",
diff --git a/src/drivers/driver_wired.c b/src/drivers/driver_wired.c
index 20c66e3..ad49eaf 100644
--- a/src/drivers/driver_wired.c
+++ b/src/drivers/driver_wired.c
@@ -390,31 +390,6 @@ static int wpa_driver_wired_get_capa(void *priv, struct wpa_driver_capa *capa)
 }
 
 
-static int wpa_driver_wired_get_ifflags(const char *ifname, int *flags)
-{
-	struct ifreq ifr;
-	int s;
-
-	s = socket(PF_INET, SOCK_DGRAM, 0);
-	if (s < 0) {
-		wpa_printf(MSG_ERROR, "socket: %s", strerror(errno));
-		return -1;
-	}
-
-	os_memset(&ifr, 0, sizeof(ifr));
-	os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
-	if (ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
-		wpa_printf(MSG_ERROR, "ioctl[SIOCGIFFLAGS]: %s",
-			   strerror(errno));
-		close(s);
-		return -1;
-	}
-	close(s);
-	*flags = ifr.ifr_flags & 0xffff;
-	return 0;
-}
-
-
 static int wpa_driver_wired_set_ifflags(const char *ifname, int flags)
 {
 	struct ifreq ifr;
@@ -488,7 +463,7 @@ static void * wpa_driver_wired_init(void *ctx, const char *ifname)
 	drv->common.pf_sock = -1;
 #endif /* __linux__ */
 
-	if (wpa_driver_wired_get_ifflags(ifname, &flags) == 0 &&
+	if (driver_wired_get_ifflags(ifname, &flags) == 0 &&
 	    !(flags & IFF_UP) &&
 	    wpa_driver_wired_set_ifflags(ifname, flags | IFF_UP) == 0) {
 		drv->common.iff_up = 1;
@@ -504,7 +479,7 @@ static void * wpa_driver_wired_init(void *ctx, const char *ifname)
 		wpa_printf(MSG_DEBUG, "%s: Added multicast membership with "
 			   "SIOCADDMULTI", __func__);
 		drv->common.multi = 1;
-	} else if (wpa_driver_wired_get_ifflags(ifname, &flags) < 0) {
+	} else if (driver_wired_get_ifflags(ifname, &flags) < 0) {
 		wpa_printf(MSG_INFO, "%s: Could not get interface "
 			   "flags", __func__);
 		os_free(drv);
@@ -558,7 +533,7 @@ static void wpa_driver_wired_deinit(void *priv)
 	}
 
 	if (drv->common.iff_allmulti &&
-	    (wpa_driver_wired_get_ifflags(drv->common.ifname, &flags) < 0 ||
+	    (driver_wired_get_ifflags(drv->common.ifname, &flags) < 0 ||
 	     wpa_driver_wired_set_ifflags(drv->common.ifname,
 					  flags & ~IFF_ALLMULTI) < 0)) {
 		wpa_printf(MSG_DEBUG, "%s: Failed to disable allmulti mode",
@@ -566,7 +541,7 @@ static void wpa_driver_wired_deinit(void *priv)
 	}
 
 	if (drv->common.iff_up &&
-	    wpa_driver_wired_get_ifflags(drv->common.ifname, &flags) == 0 &&
+	    driver_wired_get_ifflags(drv->common.ifname, &flags) == 0 &&
 	    (flags & IFF_UP) &&
 	    wpa_driver_wired_set_ifflags(drv->common.ifname,
 					 flags & ~IFF_UP) < 0) {
diff --git a/src/drivers/driver_wired_common.c b/src/drivers/driver_wired_common.c
index 4cb04da..a84dcc7 100644
--- a/src/drivers/driver_wired_common.c
+++ b/src/drivers/driver_wired_common.c
@@ -30,6 +30,31 @@
 #endif /* __sun__ */
 
 
+int driver_wired_get_ifflags(const char *ifname, int *flags)
+{
+	struct ifreq ifr;
+	int s;
+
+	s = socket(PF_INET, SOCK_DGRAM, 0);
+	if (s < 0) {
+		wpa_printf(MSG_ERROR, "socket: %s", strerror(errno));
+		return -1;
+	}
+
+	os_memset(&ifr, 0, sizeof(ifr));
+	os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
+	if (ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
+		wpa_printf(MSG_ERROR, "ioctl[SIOCGIFFLAGS]: %s",
+			   strerror(errno));
+		close(s);
+		return -1;
+	}
+	close(s);
+	*flags = ifr.ifr_flags & 0xffff;
+	return 0;
+}
+
+
 int driver_wired_multi(const char *ifname, const u8 *addr, int add)
 {
 	struct ifreq ifr;
diff --git a/src/drivers/driver_wired_common.h b/src/drivers/driver_wired_common.h
index 9bbe94f..b8ed0e0 100644
--- a/src/drivers/driver_wired_common.h
+++ b/src/drivers/driver_wired_common.h
@@ -22,6 +22,7 @@ struct driver_wired_common_data {
 static const u8 pae_group_addr[ETH_ALEN] =
 { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x03 };
 
+int driver_wired_get_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);
 
-- 
2.7.4