You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
5.8 KiB

From ec9cfb96c2db746f26ceaa577953cfc2dc9d0f49 Mon Sep 17 00:00:00 2001
Message-Id: <ec9cfb96c2db746f26ceaa577953cfc2dc9d0f49.1488376602.git.dcaratti@redhat.com>
From: Sabrina Dubroca <sd@queasysnail.net>
Date: Sun, 27 Nov 2016 20:08:51 +0100
Subject: [PATCH] drivers: Move driver_wired_deinit_common() 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 | 37 +----------------------------------
src/drivers/driver_wired.c | 35 +--------------------------------
src/drivers/driver_wired_common.c | 41 +++++++++++++++++++++++++++++++++++++++
src/drivers/driver_wired_common.h | 1 +
4 files changed, 44 insertions(+), 70 deletions(-)
diff --git a/src/drivers/driver_macsec_qca.c b/src/drivers/driver_macsec_qca.c
index 26003b0..30bf31c 100644
--- a/src/drivers/driver_macsec_qca.c
+++ b/src/drivers/driver_macsec_qca.c
@@ -174,43 +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 38476af..54217bc 100644
--- a/src/drivers/driver_wired.c
+++ b/src/drivers/driver_wired.c
@@ -410,41 +410,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 6f782c2..73c2b1b 100644
--- a/src/drivers/driver_wired_common.c
+++ b/src/drivers/driver_wired_common.c
@@ -256,3 +256,44 @@ int driver_wired_init_common(struct driver_wired_common_data *common,
return 0;
}
+
+
+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 e4f54b9..f362dbd 100644
--- a/src/drivers/driver_wired_common.h
+++ b/src/drivers/driver_wired_common.h
@@ -30,5 +30,6 @@ int driver_wired_get_ifstatus(const char *ifname, int *status);
int 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.7.4