|
|
6c9f0c |
From d718a5d975de2309dc4478a62f3475cb0726f2a1 Mon Sep 17 00:00:00 2001
|
|
|
6c9f0c |
Message-Id: <d718a5d975de2309dc4478a62f3475cb0726f2a1.1488376602.git.dcaratti@redhat.com>
|
|
|
6c9f0c |
From: Sabrina Dubroca <sd@queasysnail.net>
|
|
|
6c9f0c |
Date: Sun, 27 Nov 2016 20:08:48 +0100
|
|
|
6c9f0c |
Subject: [PATCH] drivers: Move driver_wired_set_ifflags() to a common file
|
|
|
6c9f0c |
|
|
|
6c9f0c |
This continues refactoring of the common parts of wired drivers code
|
|
|
6c9f0c |
into a shared file, so that they can be reused by other drivers.
|
|
|
6c9f0c |
|
|
|
6c9f0c |
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
|
|
|
6c9f0c |
---
|
|
|
6c9f0c |
src/drivers/driver_macsec_qca.c | 35 +++++------------------------------
|
|
|
6c9f0c |
src/drivers/driver_wired.c | 37 +++++--------------------------------
|
|
|
6c9f0c |
src/drivers/driver_wired_common.c | 25 +++++++++++++++++++++++++
|
|
|
6c9f0c |
src/drivers/driver_wired_common.h | 1 +
|
|
|
6c9f0c |
4 files changed, 36 insertions(+), 62 deletions(-)
|
|
|
6c9f0c |
|
|
|
6c9f0c |
diff --git a/src/drivers/driver_macsec_qca.c b/src/drivers/driver_macsec_qca.c
|
|
|
6c9f0c |
index d0d4611..31cb0dc 100644
|
|
|
6c9f0c |
--- a/src/drivers/driver_macsec_qca.c
|
|
|
6c9f0c |
+++ b/src/drivers/driver_macsec_qca.c
|
|
|
6c9f0c |
@@ -99,31 +99,6 @@ static int macsec_qca_get_capa(void *priv, struct wpa_driver_capa *capa)
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
|
|
|
6c9f0c |
|
|
|
6c9f0c |
-static int macsec_qca_set_ifflags(const char *ifname, int flags)
|
|
|
6c9f0c |
-{
|
|
|
6c9f0c |
- struct ifreq ifr;
|
|
|
6c9f0c |
- int s;
|
|
|
6c9f0c |
-
|
|
|
6c9f0c |
- s = socket(PF_INET, SOCK_DGRAM, 0);
|
|
|
6c9f0c |
- if (s < 0) {
|
|
|
6c9f0c |
- wpa_printf(MSG_ERROR, "socket: %s", strerror(errno));
|
|
|
6c9f0c |
- return -1;
|
|
|
6c9f0c |
- }
|
|
|
6c9f0c |
-
|
|
|
6c9f0c |
- os_memset(&ifr, 0, sizeof(ifr));
|
|
|
6c9f0c |
- os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
|
|
|
6c9f0c |
- ifr.ifr_flags = flags & 0xffff;
|
|
|
6c9f0c |
- if (ioctl(s, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
|
|
|
6c9f0c |
- wpa_printf(MSG_ERROR, "ioctl[SIOCSIFFLAGS]: %s",
|
|
|
6c9f0c |
- strerror(errno));
|
|
|
6c9f0c |
- close(s);
|
|
|
6c9f0c |
- return -1;
|
|
|
6c9f0c |
- }
|
|
|
6c9f0c |
- close(s);
|
|
|
6c9f0c |
- return 0;
|
|
|
6c9f0c |
-}
|
|
|
6c9f0c |
-
|
|
|
6c9f0c |
-
|
|
|
6c9f0c |
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
|
|
|
6c9f0c |
static int macsec_qca_get_ifstatus(const char *ifname, int *status)
|
|
|
6c9f0c |
{
|
|
|
6c9f0c |
@@ -229,7 +204,7 @@ static void * macsec_qca_init(void *ctx, const char *ifname)
|
|
|
6c9f0c |
|
|
|
6c9f0c |
if (driver_wired_get_ifflags(ifname, &flags) == 0 &&
|
|
|
6c9f0c |
!(flags & IFF_UP) &&
|
|
|
6c9f0c |
- macsec_qca_set_ifflags(ifname, flags | IFF_UP) == 0) {
|
|
|
6c9f0c |
+ driver_wired_set_ifflags(ifname, flags | IFF_UP) == 0) {
|
|
|
6c9f0c |
drv->common.iff_up = 1;
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
|
|
|
6c9f0c |
@@ -254,7 +229,7 @@ static void * macsec_qca_init(void *ctx, const char *ifname)
|
|
|
6c9f0c |
wpa_printf(MSG_DEBUG,
|
|
|
6c9f0c |
"%s: Interface is already configured for multicast",
|
|
|
6c9f0c |
__func__);
|
|
|
6c9f0c |
- } else if (macsec_qca_set_ifflags(ifname, flags | IFF_ALLMULTI) < 0) {
|
|
|
6c9f0c |
+ } else if (driver_wired_set_ifflags(ifname, flags | IFF_ALLMULTI) < 0) {
|
|
|
6c9f0c |
wpa_printf(MSG_INFO, "%s: Failed to enable allmulti",
|
|
|
6c9f0c |
__func__);
|
|
|
6c9f0c |
os_free(drv);
|
|
|
6c9f0c |
@@ -301,8 +276,8 @@ static void macsec_qca_deinit(void *priv)
|
|
|
6c9f0c |
|
|
|
6c9f0c |
if (drv->common.iff_allmulti &&
|
|
|
6c9f0c |
(driver_wired_get_ifflags(drv->common.ifname, &flags) < 0 ||
|
|
|
6c9f0c |
- macsec_qca_set_ifflags(drv->common.ifname,
|
|
|
6c9f0c |
- flags & ~IFF_ALLMULTI) < 0)) {
|
|
|
6c9f0c |
+ driver_wired_set_ifflags(drv->common.ifname,
|
|
|
6c9f0c |
+ flags & ~IFF_ALLMULTI) < 0)) {
|
|
|
6c9f0c |
wpa_printf(MSG_DEBUG, "%s: Failed to disable allmulti mode",
|
|
|
6c9f0c |
__func__);
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
@@ -310,7 +285,7 @@ static void macsec_qca_deinit(void *priv)
|
|
|
6c9f0c |
if (drv->common.iff_up &&
|
|
|
6c9f0c |
driver_wired_get_ifflags(drv->common.ifname, &flags) == 0 &&
|
|
|
6c9f0c |
(flags & IFF_UP) &&
|
|
|
6c9f0c |
- macsec_qca_set_ifflags(drv->common.ifname, flags & ~IFF_UP) < 0) {
|
|
|
6c9f0c |
+ driver_wired_set_ifflags(drv->common.ifname, flags & ~IFF_UP) < 0) {
|
|
|
6c9f0c |
wpa_printf(MSG_DEBUG, "%s: Failed to set the interface down",
|
|
|
6c9f0c |
__func__);
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
diff --git a/src/drivers/driver_wired.c b/src/drivers/driver_wired.c
|
|
|
6c9f0c |
index ad49eaf..953fa3d 100644
|
|
|
6c9f0c |
--- a/src/drivers/driver_wired.c
|
|
|
6c9f0c |
+++ b/src/drivers/driver_wired.c
|
|
|
6c9f0c |
@@ -390,31 +390,6 @@ static int wpa_driver_wired_get_capa(void *priv, struct wpa_driver_capa *capa)
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
|
|
|
6c9f0c |
|
|
|
6c9f0c |
-static int wpa_driver_wired_set_ifflags(const char *ifname, int flags)
|
|
|
6c9f0c |
-{
|
|
|
6c9f0c |
- struct ifreq ifr;
|
|
|
6c9f0c |
- int s;
|
|
|
6c9f0c |
-
|
|
|
6c9f0c |
- s = socket(PF_INET, SOCK_DGRAM, 0);
|
|
|
6c9f0c |
- if (s < 0) {
|
|
|
6c9f0c |
- wpa_printf(MSG_ERROR, "socket: %s", strerror(errno));
|
|
|
6c9f0c |
- return -1;
|
|
|
6c9f0c |
- }
|
|
|
6c9f0c |
-
|
|
|
6c9f0c |
- os_memset(&ifr, 0, sizeof(ifr));
|
|
|
6c9f0c |
- os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
|
|
|
6c9f0c |
- ifr.ifr_flags = flags & 0xffff;
|
|
|
6c9f0c |
- if (ioctl(s, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
|
|
|
6c9f0c |
- wpa_printf(MSG_ERROR, "ioctl[SIOCSIFFLAGS]: %s",
|
|
|
6c9f0c |
- strerror(errno));
|
|
|
6c9f0c |
- close(s);
|
|
|
6c9f0c |
- return -1;
|
|
|
6c9f0c |
- }
|
|
|
6c9f0c |
- close(s);
|
|
|
6c9f0c |
- return 0;
|
|
|
6c9f0c |
-}
|
|
|
6c9f0c |
-
|
|
|
6c9f0c |
-
|
|
|
6c9f0c |
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
|
|
|
6c9f0c |
static int wpa_driver_wired_get_ifstatus(const char *ifname, int *status)
|
|
|
6c9f0c |
{
|
|
|
6c9f0c |
@@ -465,7 +440,7 @@ static void * wpa_driver_wired_init(void *ctx, const char *ifname)
|
|
|
6c9f0c |
|
|
|
6c9f0c |
if (driver_wired_get_ifflags(ifname, &flags) == 0 &&
|
|
|
6c9f0c |
!(flags & IFF_UP) &&
|
|
|
6c9f0c |
- wpa_driver_wired_set_ifflags(ifname, flags | IFF_UP) == 0) {
|
|
|
6c9f0c |
+ driver_wired_set_ifflags(ifname, flags | IFF_UP) == 0) {
|
|
|
6c9f0c |
drv->common.iff_up = 1;
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
|
|
|
6c9f0c |
@@ -487,8 +462,7 @@ static void * wpa_driver_wired_init(void *ctx, const char *ifname)
|
|
|
6c9f0c |
} else if (flags & IFF_ALLMULTI) {
|
|
|
6c9f0c |
wpa_printf(MSG_DEBUG, "%s: Interface is already configured "
|
|
|
6c9f0c |
"for multicast", __func__);
|
|
|
6c9f0c |
- } else if (wpa_driver_wired_set_ifflags(ifname,
|
|
|
6c9f0c |
- flags | IFF_ALLMULTI) < 0) {
|
|
|
6c9f0c |
+ } else if (driver_wired_set_ifflags(ifname, flags | IFF_ALLMULTI) < 0) {
|
|
|
6c9f0c |
wpa_printf(MSG_INFO, "%s: Failed to enable allmulti",
|
|
|
6c9f0c |
__func__);
|
|
|
6c9f0c |
os_free(drv);
|
|
|
6c9f0c |
@@ -534,8 +508,8 @@ static void wpa_driver_wired_deinit(void *priv)
|
|
|
6c9f0c |
|
|
|
6c9f0c |
if (drv->common.iff_allmulti &&
|
|
|
6c9f0c |
(driver_wired_get_ifflags(drv->common.ifname, &flags) < 0 ||
|
|
|
6c9f0c |
- wpa_driver_wired_set_ifflags(drv->common.ifname,
|
|
|
6c9f0c |
- flags & ~IFF_ALLMULTI) < 0)) {
|
|
|
6c9f0c |
+ driver_wired_set_ifflags(drv->common.ifname,
|
|
|
6c9f0c |
+ flags & ~IFF_ALLMULTI) < 0)) {
|
|
|
6c9f0c |
wpa_printf(MSG_DEBUG, "%s: Failed to disable allmulti mode",
|
|
|
6c9f0c |
__func__);
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
@@ -543,8 +517,7 @@ static void wpa_driver_wired_deinit(void *priv)
|
|
|
6c9f0c |
if (drv->common.iff_up &&
|
|
|
6c9f0c |
driver_wired_get_ifflags(drv->common.ifname, &flags) == 0 &&
|
|
|
6c9f0c |
(flags & IFF_UP) &&
|
|
|
6c9f0c |
- wpa_driver_wired_set_ifflags(drv->common.ifname,
|
|
|
6c9f0c |
- flags & ~IFF_UP) < 0) {
|
|
|
6c9f0c |
+ driver_wired_set_ifflags(drv->common.ifname, flags & ~IFF_UP) < 0) {
|
|
|
6c9f0c |
wpa_printf(MSG_DEBUG, "%s: Failed to set the interface down",
|
|
|
6c9f0c |
__func__);
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
diff --git a/src/drivers/driver_wired_common.c b/src/drivers/driver_wired_common.c
|
|
|
6c9f0c |
index a84dcc7..52f22de 100644
|
|
|
6c9f0c |
--- a/src/drivers/driver_wired_common.c
|
|
|
6c9f0c |
+++ b/src/drivers/driver_wired_common.c
|
|
|
6c9f0c |
@@ -55,6 +55,31 @@ int driver_wired_get_ifflags(const char *ifname, int *flags)
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
|
|
|
6c9f0c |
|
|
|
6c9f0c |
+int driver_wired_set_ifflags(const char *ifname, int flags)
|
|
|
6c9f0c |
+{
|
|
|
6c9f0c |
+ struct ifreq ifr;
|
|
|
6c9f0c |
+ int s;
|
|
|
6c9f0c |
+
|
|
|
6c9f0c |
+ s = socket(PF_INET, SOCK_DGRAM, 0);
|
|
|
6c9f0c |
+ if (s < 0) {
|
|
|
6c9f0c |
+ wpa_printf(MSG_ERROR, "socket: %s", strerror(errno));
|
|
|
6c9f0c |
+ return -1;
|
|
|
6c9f0c |
+ }
|
|
|
6c9f0c |
+
|
|
|
6c9f0c |
+ os_memset(&ifr, 0, sizeof(ifr));
|
|
|
6c9f0c |
+ os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
|
|
|
6c9f0c |
+ ifr.ifr_flags = flags & 0xffff;
|
|
|
6c9f0c |
+ if (ioctl(s, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
|
|
|
6c9f0c |
+ wpa_printf(MSG_ERROR, "ioctl[SIOCSIFFLAGS]: %s",
|
|
|
6c9f0c |
+ strerror(errno));
|
|
|
6c9f0c |
+ close(s);
|
|
|
6c9f0c |
+ return -1;
|
|
|
6c9f0c |
+ }
|
|
|
6c9f0c |
+ close(s);
|
|
|
6c9f0c |
+ return 0;
|
|
|
6c9f0c |
+}
|
|
|
6c9f0c |
+
|
|
|
6c9f0c |
+
|
|
|
6c9f0c |
int driver_wired_multi(const char *ifname, const u8 *addr, int add)
|
|
|
6c9f0c |
{
|
|
|
6c9f0c |
struct ifreq ifr;
|
|
|
6c9f0c |
diff --git a/src/drivers/driver_wired_common.h b/src/drivers/driver_wired_common.h
|
|
|
6c9f0c |
index b8ed0e0..e2d8bbe 100644
|
|
|
6c9f0c |
--- a/src/drivers/driver_wired_common.h
|
|
|
6c9f0c |
+++ b/src/drivers/driver_wired_common.h
|
|
|
6c9f0c |
@@ -23,6 +23,7 @@ static const u8 pae_group_addr[ETH_ALEN] =
|
|
|
6c9f0c |
{ 0x01, 0x80, 0xc2, 0x00, 0x00, 0x03 };
|
|
|
6c9f0c |
|
|
|
6c9f0c |
int driver_wired_get_ifflags(const char *ifname, int *flags);
|
|
|
6c9f0c |
+int driver_wired_set_ifflags(const char *ifname, int flags);
|
|
|
6c9f0c |
int driver_wired_multi(const char *ifname, const u8 *addr, int add);
|
|
|
6c9f0c |
int wired_multicast_membership(int sock, int ifindex, const u8 *addr, int add);
|
|
|
6c9f0c |
|
|
|
6c9f0c |
--
|
|
|
6c9f0c |
2.7.4
|
|
|
6c9f0c |
|