[PATCH 08/13] drivers: move driver_wired_deinit_common to a common file

Sabrina Dubroca sd at queasysnail.net
Sun Nov 27 11:08:51 PST 2016


Signed-off-by: Sabrina Dubroca <sd at queasysnail.net>
---
 src/drivers/driver_macsec_qca.c   | 36 +-----------------------------------
 src/drivers/driver_wired.c        | 35 +----------------------------------
 src/drivers/driver_wired_common.c | 38 ++++++++++++++++++++++++++++++++++++++
 src/drivers/driver_wired_common.h |  1 +
 4 files changed, 41 insertions(+), 69 deletions(-)

diff --git a/src/drivers/driver_macsec_qca.c b/src/drivers/driver_macsec_qca.c
index 915897a893c4..eccd1d9d6c4a 100644
--- a/src/drivers/driver_macsec_qca.c
+++ b/src/drivers/driver_macsec_qca.c
@@ -174,42 +174,8 @@ static void * macsec_qca_init(void *ctx, const char *ifname)
 static void macsec_qca_deinit(void *priv)
 {
 	struct macsec_qca_data *drv = priv;
-	int flags;
-
-	if (drv->common.membership &&
-	    wired_multicast_membership(drv->common.pf_sock,
-					    if_nametoindex(drv->common.ifname),
-					    pae_group_addr, 0) < 0) {
-		wpa_printf(MSG_DEBUG,
-			   "%s: Failed to remove PAE multicast group (PACKET)",
-			   __func__);
-	}
-
-	if (drv->common.multi &&
-	    driver_wired_multi(drv->common.ifname, pae_group_addr, 0) < 0) {
-		wpa_printf(MSG_DEBUG,
-			   "%s: Failed to remove PAE multicast group (SIOCDELMULTI)",
-			   __func__);
-	}
-
-	if (drv->common.iff_allmulti &&
-	    (driver_wired_get_ifflags(drv->common.ifname, &flags) < 0 ||
-	     driver_wired_set_ifflags(drv->common.ifname, flags & ~IFF_ALLMULTI) < 0)) {
-		wpa_printf(MSG_DEBUG, "%s: Failed to disable allmulti mode",
-			   __func__);
-	}
-
-	if (drv->common.iff_up &&
-	    driver_wired_get_ifflags(drv->common.ifname, &flags) == 0 &&
-	    (flags & IFF_UP) &&
-	    driver_wired_set_ifflags(drv->common.ifname, flags & ~IFF_UP) < 0) {
-		wpa_printf(MSG_DEBUG, "%s: Failed to set the interface down",
-			   __func__);
-	}
-
-	if (drv->common.pf_sock != -1)
-		close(drv->common.pf_sock);
 
+	driver_wired_deinit_common(&drv->common);
 	os_free(drv);
 }
 
diff --git a/src/drivers/driver_wired.c b/src/drivers/driver_wired.c
index 19a1008963d5..86589a471ae4 100644
--- a/src/drivers/driver_wired.c
+++ b/src/drivers/driver_wired.c
@@ -408,41 +408,8 @@ static void * wpa_driver_wired_init(void *ctx, const char *ifname)
 static void wpa_driver_wired_deinit(void *priv)
 {
 	struct wpa_driver_wired_data *drv = priv;
-	int flags;
-
-	if (drv->common.membership &&
-	    wired_multicast_membership(drv->common.pf_sock,
-				       if_nametoindex(drv->common.ifname),
-				       pae_group_addr, 0) < 0) {
-		wpa_printf(MSG_DEBUG, "%s: Failed to remove PAE multicast "
-			   "group (PACKET)", __func__);
-	}
-
-	if (drv->common.multi &&
-	    driver_wired_multi(drv->common.ifname, pae_group_addr, 0) < 0) {
-		wpa_printf(MSG_DEBUG, "%s: Failed to remove PAE multicast "
-			   "group (SIOCDELMULTI)", __func__);
-	}
-
-	if (drv->common.iff_allmulti &&
-	    (driver_wired_get_ifflags(drv->common.ifname, &flags) < 0 ||
-	     driver_wired_set_ifflags(drv->common.ifname,
-					  flags & ~IFF_ALLMULTI) < 0)) {
-		wpa_printf(MSG_DEBUG, "%s: Failed to disable allmulti mode",
-			   __func__);
-	}
-
-	if (drv->common.iff_up &&
-	    driver_wired_get_ifflags(drv->common.ifname, &flags) == 0 &&
-	    (flags & IFF_UP) &&
-	    driver_wired_set_ifflags(drv->common.ifname, flags & ~IFF_UP) < 0) {
-		wpa_printf(MSG_DEBUG, "%s: Failed to set the interface down",
-			   __func__);
-	}
-
-	if (drv->common.pf_sock != -1)
-		close(drv->common.pf_sock);
 
+	driver_wired_deinit_common(&drv->common);
 	os_free(drv);
 }
 
diff --git a/src/drivers/driver_wired_common.c b/src/drivers/driver_wired_common.c
index 27298ff3c787..94f6bf6daf24 100644
--- a/src/drivers/driver_wired_common.c
+++ b/src/drivers/driver_wired_common.c
@@ -247,3 +247,41 @@ Boolean driver_wired_init_common(struct driver_wired_common_data *common, const
 
 	return TRUE;
 }
+
+void driver_wired_deinit_common(struct driver_wired_common_data *common)
+{
+	int flags;
+
+	if (common->membership &&
+	    wired_multicast_membership(common->pf_sock,
+				       if_nametoindex(common->ifname),
+				       pae_group_addr, 0) < 0) {
+		wpa_printf(MSG_DEBUG, "%s: Failed to remove PAE multicast "
+			   "group (PACKET)", __func__);
+	}
+
+	if (common->multi &&
+	    driver_wired_multi(common->ifname, pae_group_addr, 0) < 0) {
+		wpa_printf(MSG_DEBUG, "%s: Failed to remove PAE multicast "
+			   "group (SIOCDELMULTI)", __func__);
+	}
+
+	if (common->iff_allmulti &&
+	    (driver_wired_get_ifflags(common->ifname, &flags) < 0 ||
+	     driver_wired_set_ifflags(common->ifname,
+					  flags & ~IFF_ALLMULTI) < 0)) {
+		wpa_printf(MSG_DEBUG, "%s: Failed to disable allmulti mode",
+			   __func__);
+	}
+
+	if (common->iff_up &&
+	    driver_wired_get_ifflags(common->ifname, &flags) == 0 &&
+	    (flags & IFF_UP) &&
+	    driver_wired_set_ifflags(common->ifname, flags & ~IFF_UP) < 0) {
+		wpa_printf(MSG_DEBUG, "%s: Failed to set the interface down",
+			   __func__);
+	}
+
+	if (common->pf_sock != -1)
+		close(common->pf_sock);
+}
diff --git a/src/drivers/driver_wired_common.h b/src/drivers/driver_wired_common.h
index fe6a87c5f232..292cfffe0b29 100644
--- a/src/drivers/driver_wired_common.h
+++ b/src/drivers/driver_wired_common.h
@@ -31,4 +31,5 @@ int driver_wired_get_ifstatus(const char *ifname, int *status);
 #endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(FreeBSD_kernel__) */
 
 Boolean driver_wired_init_common(struct driver_wired_common_data *common, const char *ifname, void *ctx);
+void driver_wired_deinit_common(struct driver_wired_common_data *common);
 #endif /* DRIVER_WIRED_COMMON_H */
-- 
2.10.2




More information about the Hostap mailing list