|
|
6c9f0c |
From 0abc8d10cc357d71fff74470c613442f9070ae93 Mon Sep 17 00:00:00 2001
|
|
|
6c9f0c |
Message-Id: <0abc8d10cc357d71fff74470c613442f9070ae93.1488376602.git.dcaratti@redhat.com>
|
|
|
6c9f0c |
From: Sabrina Dubroca <sd@queasysnail.net>
|
|
|
6c9f0c |
Date: Sun, 27 Nov 2016 20:08:44 +0100
|
|
|
6c9f0c |
Subject: [PATCH] drivers: Move common definitions for wired drivers out
|
|
|
6c9f0c |
|
|
|
6c9f0c |
Refactor the common parts of wired drivers code into a shared file, so
|
|
|
6c9f0c |
that they can be reused by other drivers. The macsec_qca driver already
|
|
|
6c9f0c |
contains a lot of code duplication from the wired driver, and the
|
|
|
6c9f0c |
macsec_linux driver would do the same. A structure to hold data common
|
|
|
6c9f0c |
to all wired drivers is added and used in all these drivers.
|
|
|
6c9f0c |
|
|
|
6c9f0c |
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
|
|
|
6c9f0c |
---
|
|
|
6c9f0c |
src/drivers/driver_macsec_qca.c | 65 ++++++++++++-------------
|
|
|
6c9f0c |
src/drivers/driver_wired.c | 99 +++++++++++++++++++--------------------
|
|
|
6c9f0c |
src/drivers/driver_wired_common.h | 25 ++++++++++
|
|
|
6c9f0c |
3 files changed, 103 insertions(+), 86 deletions(-)
|
|
|
6c9f0c |
create mode 100644 src/drivers/driver_wired_common.h
|
|
|
6c9f0c |
|
|
|
6c9f0c |
diff --git a/src/drivers/driver_macsec_qca.c b/src/drivers/driver_macsec_qca.c
|
|
|
6c9f0c |
index 22d414c..6391e08 100644
|
|
|
6c9f0c |
--- a/src/drivers/driver_macsec_qca.c
|
|
|
6c9f0c |
+++ b/src/drivers/driver_macsec_qca.c
|
|
|
6c9f0c |
@@ -31,6 +31,7 @@
|
|
|
6c9f0c |
#include "common/ieee802_1x_defs.h"
|
|
|
6c9f0c |
#include "pae/ieee802_1x_kay.h"
|
|
|
6c9f0c |
#include "driver.h"
|
|
|
6c9f0c |
+#include "driver_wired_common.h"
|
|
|
6c9f0c |
|
|
|
6c9f0c |
#include "nss_macsec_secy.h"
|
|
|
6c9f0c |
#include "nss_macsec_secy_rx.h"
|
|
|
6c9f0c |
@@ -53,21 +54,14 @@
|
|
|
6c9f0c |
#pragma pack(pop)
|
|
|
6c9f0c |
#endif /* _MSC_VER */
|
|
|
6c9f0c |
|
|
|
6c9f0c |
-static const u8 pae_group_addr[ETH_ALEN] =
|
|
|
6c9f0c |
-{ 0x01, 0x80, 0xc2, 0x00, 0x00, 0x03 };
|
|
|
6c9f0c |
-
|
|
|
6c9f0c |
struct channel_map {
|
|
|
6c9f0c |
struct ieee802_1x_mka_sci sci;
|
|
|
6c9f0c |
};
|
|
|
6c9f0c |
|
|
|
6c9f0c |
struct macsec_qca_data {
|
|
|
6c9f0c |
- char ifname[IFNAMSIZ + 1];
|
|
|
6c9f0c |
- u32 secy_id;
|
|
|
6c9f0c |
- void *ctx;
|
|
|
6c9f0c |
+ struct driver_wired_common_data common;
|
|
|
6c9f0c |
|
|
|
6c9f0c |
- int sock; /* raw packet socket for driver access */
|
|
|
6c9f0c |
- int pf_sock;
|
|
|
6c9f0c |
- int membership, multi, iff_allmulti, iff_up;
|
|
|
6c9f0c |
+ u32 secy_id;
|
|
|
6c9f0c |
|
|
|
6c9f0c |
/* shadow */
|
|
|
6c9f0c |
Boolean always_include_sci;
|
|
|
6c9f0c |
@@ -322,43 +316,43 @@ static void * macsec_qca_init(void *ctx, const char *ifname)
|
|
|
6c9f0c |
drv = os_zalloc(sizeof(*drv));
|
|
|
6c9f0c |
if (drv == NULL)
|
|
|
6c9f0c |
return NULL;
|
|
|
6c9f0c |
- os_strlcpy(drv->ifname, ifname, sizeof(drv->ifname));
|
|
|
6c9f0c |
- drv->ctx = ctx;
|
|
|
6c9f0c |
+ os_strlcpy(drv->common.ifname, ifname, sizeof(drv->common.ifname));
|
|
|
6c9f0c |
+ drv->common.ctx = ctx;
|
|
|
6c9f0c |
|
|
|
6c9f0c |
/* Board specific settings */
|
|
|
6c9f0c |
- if (os_memcmp("eth2", drv->ifname, 4) == 0)
|
|
|
6c9f0c |
+ if (os_memcmp("eth2", drv->common.ifname, 4) == 0)
|
|
|
6c9f0c |
drv->secy_id = 1;
|
|
|
6c9f0c |
- else if (os_memcmp("eth3", drv->ifname, 4) == 0)
|
|
|
6c9f0c |
+ else if (os_memcmp("eth3", drv->common.ifname, 4) == 0)
|
|
|
6c9f0c |
drv->secy_id = 2;
|
|
|
6c9f0c |
else
|
|
|
6c9f0c |
drv->secy_id = -1;
|
|
|
6c9f0c |
|
|
|
6c9f0c |
#ifdef __linux__
|
|
|
6c9f0c |
- drv->pf_sock = socket(PF_PACKET, SOCK_DGRAM, 0);
|
|
|
6c9f0c |
- if (drv->pf_sock < 0)
|
|
|
6c9f0c |
+ drv->common.pf_sock = socket(PF_PACKET, SOCK_DGRAM, 0);
|
|
|
6c9f0c |
+ if (drv->common.pf_sock < 0)
|
|
|
6c9f0c |
wpa_printf(MSG_ERROR, "socket(PF_PACKET): %s", strerror(errno));
|
|
|
6c9f0c |
#else /* __linux__ */
|
|
|
6c9f0c |
- drv->pf_sock = -1;
|
|
|
6c9f0c |
+ drv->common.pf_sock = -1;
|
|
|
6c9f0c |
#endif /* __linux__ */
|
|
|
6c9f0c |
|
|
|
6c9f0c |
if (macsec_qca_get_ifflags(ifname, &flags) == 0 &&
|
|
|
6c9f0c |
!(flags & IFF_UP) &&
|
|
|
6c9f0c |
macsec_qca_set_ifflags(ifname, flags | IFF_UP) == 0) {
|
|
|
6c9f0c |
- drv->iff_up = 1;
|
|
|
6c9f0c |
+ drv->common.iff_up = 1;
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
|
|
|
6c9f0c |
- if (macsec_qca_multicast_membership(drv->pf_sock,
|
|
|
6c9f0c |
- if_nametoindex(drv->ifname),
|
|
|
6c9f0c |
+ if (macsec_qca_multicast_membership(drv->common.pf_sock,
|
|
|
6c9f0c |
+ if_nametoindex(drv->common.ifname),
|
|
|
6c9f0c |
pae_group_addr, 1) == 0) {
|
|
|
6c9f0c |
wpa_printf(MSG_DEBUG,
|
|
|
6c9f0c |
"%s: Added multicast membership with packet socket",
|
|
|
6c9f0c |
__func__);
|
|
|
6c9f0c |
- drv->membership = 1;
|
|
|
6c9f0c |
+ drv->common.membership = 1;
|
|
|
6c9f0c |
} else if (macsec_qca_multi(ifname, pae_group_addr, 1) == 0) {
|
|
|
6c9f0c |
wpa_printf(MSG_DEBUG,
|
|
|
6c9f0c |
"%s: Added multicast membership with SIOCADDMULTI",
|
|
|
6c9f0c |
__func__);
|
|
|
6c9f0c |
- drv->multi = 1;
|
|
|
6c9f0c |
+ drv->common.multi = 1;
|
|
|
6c9f0c |
} else if (macsec_qca_get_ifflags(ifname, &flags) < 0) {
|
|
|
6c9f0c |
wpa_printf(MSG_INFO, "%s: Could not get interface flags",
|
|
|
6c9f0c |
__func__);
|
|
|
6c9f0c |
@@ -375,7 +369,7 @@ static void * macsec_qca_init(void *ctx, const char *ifname)
|
|
|
6c9f0c |
return NULL;
|
|
|
6c9f0c |
} else {
|
|
|
6c9f0c |
wpa_printf(MSG_DEBUG, "%s: Enabled allmulti mode", __func__);
|
|
|
6c9f0c |
- drv->iff_allmulti = 1;
|
|
|
6c9f0c |
+ drv->common.iff_allmulti = 1;
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
|
|
|
6c9f0c |
{
|
|
|
6c9f0c |
@@ -397,39 +391,40 @@ static void macsec_qca_deinit(void *priv)
|
|
|
6c9f0c |
struct macsec_qca_data *drv = priv;
|
|
|
6c9f0c |
int flags;
|
|
|
6c9f0c |
|
|
|
6c9f0c |
- if (drv->membership &&
|
|
|
6c9f0c |
- macsec_qca_multicast_membership(drv->pf_sock,
|
|
|
6c9f0c |
- if_nametoindex(drv->ifname),
|
|
|
6c9f0c |
+ if (drv->common.membership &&
|
|
|
6c9f0c |
+ macsec_qca_multicast_membership(drv->common.pf_sock,
|
|
|
6c9f0c |
+ if_nametoindex(drv->common.ifname),
|
|
|
6c9f0c |
pae_group_addr, 0) < 0) {
|
|
|
6c9f0c |
wpa_printf(MSG_DEBUG,
|
|
|
6c9f0c |
"%s: Failed to remove PAE multicast group (PACKET)",
|
|
|
6c9f0c |
__func__);
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
|
|
|
6c9f0c |
- if (drv->multi &&
|
|
|
6c9f0c |
- macsec_qca_multi(drv->ifname, pae_group_addr, 0) < 0) {
|
|
|
6c9f0c |
+ if (drv->common.multi &&
|
|
|
6c9f0c |
+ macsec_qca_multi(drv->common.ifname, pae_group_addr, 0) < 0) {
|
|
|
6c9f0c |
wpa_printf(MSG_DEBUG,
|
|
|
6c9f0c |
"%s: Failed to remove PAE multicast group (SIOCDELMULTI)",
|
|
|
6c9f0c |
__func__);
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
|
|
|
6c9f0c |
- if (drv->iff_allmulti &&
|
|
|
6c9f0c |
- (macsec_qca_get_ifflags(drv->ifname, &flags) < 0 ||
|
|
|
6c9f0c |
- macsec_qca_set_ifflags(drv->ifname, flags & ~IFF_ALLMULTI) < 0)) {
|
|
|
6c9f0c |
+ if (drv->common.iff_allmulti &&
|
|
|
6c9f0c |
+ (macsec_qca_get_ifflags(drv->common.ifname, &flags) < 0 ||
|
|
|
6c9f0c |
+ macsec_qca_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 |
|
|
|
6c9f0c |
- if (drv->iff_up &&
|
|
|
6c9f0c |
- macsec_qca_get_ifflags(drv->ifname, &flags) == 0 &&
|
|
|
6c9f0c |
+ if (drv->common.iff_up &&
|
|
|
6c9f0c |
+ macsec_qca_get_ifflags(drv->common.ifname, &flags) == 0 &&
|
|
|
6c9f0c |
(flags & IFF_UP) &&
|
|
|
6c9f0c |
- macsec_qca_set_ifflags(drv->ifname, flags & ~IFF_UP) < 0) {
|
|
|
6c9f0c |
+ macsec_qca_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 |
|
|
|
6c9f0c |
- if (drv->pf_sock != -1)
|
|
|
6c9f0c |
- close(drv->pf_sock);
|
|
|
6c9f0c |
+ if (drv->common.pf_sock != -1)
|
|
|
6c9f0c |
+ close(drv->common.pf_sock);
|
|
|
6c9f0c |
|
|
|
6c9f0c |
os_free(drv);
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
diff --git a/src/drivers/driver_wired.c b/src/drivers/driver_wired.c
|
|
|
6c9f0c |
index 422a220..b6f79e3 100644
|
|
|
6c9f0c |
--- a/src/drivers/driver_wired.c
|
|
|
6c9f0c |
+++ b/src/drivers/driver_wired.c
|
|
|
6c9f0c |
@@ -12,6 +12,7 @@
|
|
|
6c9f0c |
#include "common.h"
|
|
|
6c9f0c |
#include "eloop.h"
|
|
|
6c9f0c |
#include "driver.h"
|
|
|
6c9f0c |
+#include "driver_wired_common.h"
|
|
|
6c9f0c |
|
|
|
6c9f0c |
#include <sys/ioctl.h>
|
|
|
6c9f0c |
#undef IFNAMSIZ
|
|
|
6c9f0c |
@@ -42,20 +43,12 @@ struct ieee8023_hdr {
|
|
|
6c9f0c |
#pragma pack(pop)
|
|
|
6c9f0c |
#endif /* _MSC_VER */
|
|
|
6c9f0c |
|
|
|
6c9f0c |
-static const u8 pae_group_addr[ETH_ALEN] =
|
|
|
6c9f0c |
-{ 0x01, 0x80, 0xc2, 0x00, 0x00, 0x03 };
|
|
|
6c9f0c |
-
|
|
|
6c9f0c |
|
|
|
6c9f0c |
struct wpa_driver_wired_data {
|
|
|
6c9f0c |
- char ifname[IFNAMSIZ + 1];
|
|
|
6c9f0c |
- void *ctx;
|
|
|
6c9f0c |
+ struct driver_wired_common_data common;
|
|
|
6c9f0c |
|
|
|
6c9f0c |
- int sock; /* raw packet socket for driver access */
|
|
|
6c9f0c |
int dhcp_sock; /* socket for dhcp packets */
|
|
|
6c9f0c |
int use_pae_group_addr;
|
|
|
6c9f0c |
-
|
|
|
6c9f0c |
- int pf_sock;
|
|
|
6c9f0c |
- int membership, multi, iff_allmulti, iff_up;
|
|
|
6c9f0c |
};
|
|
|
6c9f0c |
|
|
|
6c9f0c |
|
|
|
6c9f0c |
@@ -208,21 +201,22 @@ static int wired_init_sockets(struct wpa_driver_wired_data *drv, u8 *own_addr)
|
|
|
6c9f0c |
struct sockaddr_in addr2;
|
|
|
6c9f0c |
int n = 1;
|
|
|
6c9f0c |
|
|
|
6c9f0c |
- drv->sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_PAE));
|
|
|
6c9f0c |
- if (drv->sock < 0) {
|
|
|
6c9f0c |
+ drv->common.sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_PAE));
|
|
|
6c9f0c |
+ if (drv->common.sock < 0) {
|
|
|
6c9f0c |
wpa_printf(MSG_ERROR, "socket[PF_PACKET,SOCK_RAW]: %s",
|
|
|
6c9f0c |
strerror(errno));
|
|
|
6c9f0c |
return -1;
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
|
|
|
6c9f0c |
- if (eloop_register_read_sock(drv->sock, handle_read, drv->ctx, NULL)) {
|
|
|
6c9f0c |
+ if (eloop_register_read_sock(drv->common.sock, handle_read,
|
|
|
6c9f0c |
+ drv->common.ctx, NULL)) {
|
|
|
6c9f0c |
wpa_printf(MSG_INFO, "Could not register read socket");
|
|
|
6c9f0c |
return -1;
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
|
|
|
6c9f0c |
os_memset(&ifr, 0, sizeof(ifr));
|
|
|
6c9f0c |
- os_strlcpy(ifr.ifr_name, drv->ifname, sizeof(ifr.ifr_name));
|
|
|
6c9f0c |
- if (ioctl(drv->sock, SIOCGIFINDEX, &ifr) != 0) {
|
|
|
6c9f0c |
+ os_strlcpy(ifr.ifr_name, drv->common.ifname, sizeof(ifr.ifr_name));
|
|
|
6c9f0c |
+ if (ioctl(drv->common.sock, SIOCGIFINDEX, &ifr) != 0) {
|
|
|
6c9f0c |
wpa_printf(MSG_ERROR, "ioctl(SIOCGIFINDEX): %s",
|
|
|
6c9f0c |
strerror(errno));
|
|
|
6c9f0c |
return -1;
|
|
|
6c9f0c |
@@ -234,13 +228,14 @@ static int wired_init_sockets(struct wpa_driver_wired_data *drv, u8 *own_addr)
|
|
|
6c9f0c |
wpa_printf(MSG_DEBUG, "Opening raw packet socket for ifindex %d",
|
|
|
6c9f0c |
addr.sll_ifindex);
|
|
|
6c9f0c |
|
|
|
6c9f0c |
- if (bind(drv->sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
|
|
|
6c9f0c |
+ if (bind(drv->common.sock, (struct sockaddr *) &addr, sizeof(addr)) < 0)
|
|
|
6c9f0c |
+ {
|
|
|
6c9f0c |
wpa_printf(MSG_ERROR, "bind: %s", strerror(errno));
|
|
|
6c9f0c |
return -1;
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
|
|
|
6c9f0c |
/* filter multicast address */
|
|
|
6c9f0c |
- if (wired_multicast_membership(drv->sock, ifr.ifr_ifindex,
|
|
|
6c9f0c |
+ if (wired_multicast_membership(drv->common.sock, ifr.ifr_ifindex,
|
|
|
6c9f0c |
pae_group_addr, 1) < 0) {
|
|
|
6c9f0c |
wpa_printf(MSG_ERROR, "wired: Failed to add multicast group "
|
|
|
6c9f0c |
"membership");
|
|
|
6c9f0c |
@@ -248,8 +243,8 @@ static int wired_init_sockets(struct wpa_driver_wired_data *drv, u8 *own_addr)
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
|
|
|
6c9f0c |
os_memset(&ifr, 0, sizeof(ifr));
|
|
|
6c9f0c |
- os_strlcpy(ifr.ifr_name, drv->ifname, sizeof(ifr.ifr_name));
|
|
|
6c9f0c |
- if (ioctl(drv->sock, SIOCGIFHWADDR, &ifr) != 0) {
|
|
|
6c9f0c |
+ os_strlcpy(ifr.ifr_name, drv->common.ifname, sizeof(ifr.ifr_name));
|
|
|
6c9f0c |
+ if (ioctl(drv->common.sock, SIOCGIFHWADDR, &ifr) != 0) {
|
|
|
6c9f0c |
wpa_printf(MSG_ERROR, "ioctl(SIOCGIFHWADDR): %s",
|
|
|
6c9f0c |
strerror(errno));
|
|
|
6c9f0c |
return -1;
|
|
|
6c9f0c |
@@ -269,8 +264,8 @@ static int wired_init_sockets(struct wpa_driver_wired_data *drv, u8 *own_addr)
|
|
|
6c9f0c |
return -1;
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
|
|
|
6c9f0c |
- if (eloop_register_read_sock(drv->dhcp_sock, handle_dhcp, drv->ctx,
|
|
|
6c9f0c |
- NULL)) {
|
|
|
6c9f0c |
+ if (eloop_register_read_sock(drv->dhcp_sock, handle_dhcp,
|
|
|
6c9f0c |
+ drv->common.ctx, NULL)) {
|
|
|
6c9f0c |
wpa_printf(MSG_INFO, "Could not register read socket");
|
|
|
6c9f0c |
return -1;
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
@@ -294,7 +289,7 @@ static int wired_init_sockets(struct wpa_driver_wired_data *drv, u8 *own_addr)
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
|
|
|
6c9f0c |
os_memset(&ifr, 0, sizeof(ifr));
|
|
|
6c9f0c |
- os_strlcpy(ifr.ifr_ifrn.ifrn_name, drv->ifname, IFNAMSIZ);
|
|
|
6c9f0c |
+ os_strlcpy(ifr.ifr_ifrn.ifrn_name, drv->common.ifname, IFNAMSIZ);
|
|
|
6c9f0c |
if (setsockopt(drv->dhcp_sock, SOL_SOCKET, SO_BINDTODEVICE,
|
|
|
6c9f0c |
(char *) &ifr, sizeof(ifr)) < 0) {
|
|
|
6c9f0c |
wpa_printf(MSG_ERROR,
|
|
|
6c9f0c |
@@ -343,7 +338,7 @@ static int wired_send_eapol(void *priv, const u8 *addr,
|
|
|
6c9f0c |
pos = (u8 *) (hdr + 1);
|
|
|
6c9f0c |
os_memcpy(pos, data, data_len);
|
|
|
6c9f0c |
|
|
|
6c9f0c |
- res = send(drv->sock, (u8 *) hdr, len, 0);
|
|
|
6c9f0c |
+ res = send(drv->common.sock, (u8 *) hdr, len, 0);
|
|
|
6c9f0c |
os_free(hdr);
|
|
|
6c9f0c |
|
|
|
6c9f0c |
if (res < 0) {
|
|
|
6c9f0c |
@@ -368,8 +363,9 @@ static void * wired_driver_hapd_init(struct hostapd_data *hapd,
|
|
|
6c9f0c |
return NULL;
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
|
|
|
6c9f0c |
- drv->ctx = hapd;
|
|
|
6c9f0c |
- os_strlcpy(drv->ifname, params->ifname, sizeof(drv->ifname));
|
|
|
6c9f0c |
+ drv->common.ctx = hapd;
|
|
|
6c9f0c |
+ os_strlcpy(drv->common.ifname, params->ifname,
|
|
|
6c9f0c |
+ sizeof(drv->common.ifname));
|
|
|
6c9f0c |
drv->use_pae_group_addr = params->use_pae_group_addr;
|
|
|
6c9f0c |
|
|
|
6c9f0c |
if (wired_init_sockets(drv, params->own_addr)) {
|
|
|
6c9f0c |
@@ -385,9 +381,9 @@ static void wired_driver_hapd_deinit(void *priv)
|
|
|
6c9f0c |
{
|
|
|
6c9f0c |
struct wpa_driver_wired_data *drv = priv;
|
|
|
6c9f0c |
|
|
|
6c9f0c |
- if (drv->sock >= 0) {
|
|
|
6c9f0c |
- eloop_unregister_read_sock(drv->sock);
|
|
|
6c9f0c |
- close(drv->sock);
|
|
|
6c9f0c |
+ if (drv->common.sock >= 0) {
|
|
|
6c9f0c |
+ eloop_unregister_read_sock(drv->common.sock);
|
|
|
6c9f0c |
+ close(drv->common.sock);
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
|
|
|
6c9f0c |
if (drv->dhcp_sock >= 0) {
|
|
|
6c9f0c |
@@ -564,33 +560,33 @@ static void * wpa_driver_wired_init(void *ctx, const char *ifname)
|
|
|
6c9f0c |
drv = os_zalloc(sizeof(*drv));
|
|
|
6c9f0c |
if (drv == NULL)
|
|
|
6c9f0c |
return NULL;
|
|
|
6c9f0c |
- os_strlcpy(drv->ifname, ifname, sizeof(drv->ifname));
|
|
|
6c9f0c |
- drv->ctx = ctx;
|
|
|
6c9f0c |
+ os_strlcpy(drv->common.ifname, ifname, sizeof(drv->common.ifname));
|
|
|
6c9f0c |
+ drv->common.ctx = ctx;
|
|
|
6c9f0c |
|
|
|
6c9f0c |
#ifdef __linux__
|
|
|
6c9f0c |
- drv->pf_sock = socket(PF_PACKET, SOCK_DGRAM, 0);
|
|
|
6c9f0c |
- if (drv->pf_sock < 0)
|
|
|
6c9f0c |
+ drv->common.pf_sock = socket(PF_PACKET, SOCK_DGRAM, 0);
|
|
|
6c9f0c |
+ if (drv->common.pf_sock < 0)
|
|
|
6c9f0c |
wpa_printf(MSG_ERROR, "socket(PF_PACKET): %s", strerror(errno));
|
|
|
6c9f0c |
#else /* __linux__ */
|
|
|
6c9f0c |
- drv->pf_sock = -1;
|
|
|
6c9f0c |
+ drv->common.pf_sock = -1;
|
|
|
6c9f0c |
#endif /* __linux__ */
|
|
|
6c9f0c |
|
|
|
6c9f0c |
if (wpa_driver_wired_get_ifflags(ifname, &flags) == 0 &&
|
|
|
6c9f0c |
!(flags & IFF_UP) &&
|
|
|
6c9f0c |
wpa_driver_wired_set_ifflags(ifname, flags | IFF_UP) == 0) {
|
|
|
6c9f0c |
- drv->iff_up = 1;
|
|
|
6c9f0c |
+ drv->common.iff_up = 1;
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
|
|
|
6c9f0c |
- if (wired_multicast_membership(drv->pf_sock,
|
|
|
6c9f0c |
- if_nametoindex(drv->ifname),
|
|
|
6c9f0c |
+ if (wired_multicast_membership(drv->common.pf_sock,
|
|
|
6c9f0c |
+ if_nametoindex(drv->common.ifname),
|
|
|
6c9f0c |
pae_group_addr, 1) == 0) {
|
|
|
6c9f0c |
wpa_printf(MSG_DEBUG, "%s: Added multicast membership with "
|
|
|
6c9f0c |
"packet socket", __func__);
|
|
|
6c9f0c |
- drv->membership = 1;
|
|
|
6c9f0c |
+ drv->common.membership = 1;
|
|
|
6c9f0c |
} else if (wpa_driver_wired_multi(ifname, pae_group_addr, 1) == 0) {
|
|
|
6c9f0c |
wpa_printf(MSG_DEBUG, "%s: Added multicast membership with "
|
|
|
6c9f0c |
"SIOCADDMULTI", __func__);
|
|
|
6c9f0c |
- drv->multi = 1;
|
|
|
6c9f0c |
+ drv->common.multi = 1;
|
|
|
6c9f0c |
} else if (wpa_driver_wired_get_ifflags(ifname, &flags) < 0) {
|
|
|
6c9f0c |
wpa_printf(MSG_INFO, "%s: Could not get interface "
|
|
|
6c9f0c |
"flags", __func__);
|
|
|
6c9f0c |
@@ -608,7 +604,7 @@ static void * wpa_driver_wired_init(void *ctx, const char *ifname)
|
|
|
6c9f0c |
} else {
|
|
|
6c9f0c |
wpa_printf(MSG_DEBUG, "%s: Enabled allmulti mode",
|
|
|
6c9f0c |
__func__);
|
|
|
6c9f0c |
- drv->iff_allmulti = 1;
|
|
|
6c9f0c |
+ drv->common.iff_allmulti = 1;
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
|
|
|
6c9f0c |
{
|
|
|
6c9f0c |
@@ -630,38 +626,39 @@ static void wpa_driver_wired_deinit(void *priv)
|
|
|
6c9f0c |
struct wpa_driver_wired_data *drv = priv;
|
|
|
6c9f0c |
int flags;
|
|
|
6c9f0c |
|
|
|
6c9f0c |
- if (drv->membership &&
|
|
|
6c9f0c |
- wired_multicast_membership(drv->pf_sock,
|
|
|
6c9f0c |
- if_nametoindex(drv->ifname),
|
|
|
6c9f0c |
+ if (drv->common.membership &&
|
|
|
6c9f0c |
+ wired_multicast_membership(drv->common.pf_sock,
|
|
|
6c9f0c |
+ if_nametoindex(drv->common.ifname),
|
|
|
6c9f0c |
pae_group_addr, 0) < 0) {
|
|
|
6c9f0c |
wpa_printf(MSG_DEBUG, "%s: Failed to remove PAE multicast "
|
|
|
6c9f0c |
"group (PACKET)", __func__);
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
|
|
|
6c9f0c |
- if (drv->multi &&
|
|
|
6c9f0c |
- wpa_driver_wired_multi(drv->ifname, pae_group_addr, 0) < 0) {
|
|
|
6c9f0c |
+ if (drv->common.multi &&
|
|
|
6c9f0c |
+ wpa_driver_wired_multi(drv->common.ifname, pae_group_addr, 0) < 0) {
|
|
|
6c9f0c |
wpa_printf(MSG_DEBUG, "%s: Failed to remove PAE multicast "
|
|
|
6c9f0c |
"group (SIOCDELMULTI)", __func__);
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
|
|
|
6c9f0c |
- if (drv->iff_allmulti &&
|
|
|
6c9f0c |
- (wpa_driver_wired_get_ifflags(drv->ifname, &flags) < 0 ||
|
|
|
6c9f0c |
- wpa_driver_wired_set_ifflags(drv->ifname,
|
|
|
6c9f0c |
+ if (drv->common.iff_allmulti &&
|
|
|
6c9f0c |
+ (wpa_driver_wired_get_ifflags(drv->common.ifname, &flags) < 0 ||
|
|
|
6c9f0c |
+ wpa_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 |
|
|
|
6c9f0c |
- if (drv->iff_up &&
|
|
|
6c9f0c |
- wpa_driver_wired_get_ifflags(drv->ifname, &flags) == 0 &&
|
|
|
6c9f0c |
+ if (drv->common.iff_up &&
|
|
|
6c9f0c |
+ wpa_driver_wired_get_ifflags(drv->common.ifname, &flags) == 0 &&
|
|
|
6c9f0c |
(flags & IFF_UP) &&
|
|
|
6c9f0c |
- wpa_driver_wired_set_ifflags(drv->ifname, flags & ~IFF_UP) < 0) {
|
|
|
6c9f0c |
+ wpa_driver_wired_set_ifflags(drv->common.ifname,
|
|
|
6c9f0c |
+ flags & ~IFF_UP) < 0) {
|
|
|
6c9f0c |
wpa_printf(MSG_DEBUG, "%s: Failed to set the interface down",
|
|
|
6c9f0c |
__func__);
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
|
|
|
6c9f0c |
- if (drv->pf_sock != -1)
|
|
|
6c9f0c |
- close(drv->pf_sock);
|
|
|
6c9f0c |
+ if (drv->common.pf_sock != -1)
|
|
|
6c9f0c |
+ close(drv->common.pf_sock);
|
|
|
6c9f0c |
|
|
|
6c9f0c |
os_free(drv);
|
|
|
6c9f0c |
}
|
|
|
6c9f0c |
diff --git a/src/drivers/driver_wired_common.h b/src/drivers/driver_wired_common.h
|
|
|
6c9f0c |
new file mode 100644
|
|
|
6c9f0c |
index 0000000..8d9dd37
|
|
|
6c9f0c |
--- /dev/null
|
|
|
6c9f0c |
+++ b/src/drivers/driver_wired_common.h
|
|
|
6c9f0c |
@@ -0,0 +1,25 @@
|
|
|
6c9f0c |
+/*
|
|
|
6c9f0c |
+ * Common definitions for Wired Ethernet driver interfaces
|
|
|
6c9f0c |
+ * Copyright (c) 2005-2009, Jouni Malinen <j@w1.fi>
|
|
|
6c9f0c |
+ * Copyright (c) 2004, Gunter Burchardt <tira@isx.de>
|
|
|
6c9f0c |
+ *
|
|
|
6c9f0c |
+ * This software may be distributed under the terms of the BSD license.
|
|
|
6c9f0c |
+ * See README for more details.
|
|
|
6c9f0c |
+ */
|
|
|
6c9f0c |
+
|
|
|
6c9f0c |
+#ifndef DRIVER_WIRED_COMMON_H
|
|
|
6c9f0c |
+#define DRIVER_WIRED_COMMON_H
|
|
|
6c9f0c |
+
|
|
|
6c9f0c |
+struct driver_wired_common_data {
|
|
|
6c9f0c |
+ char ifname[IFNAMSIZ + 1];
|
|
|
6c9f0c |
+ void *ctx;
|
|
|
6c9f0c |
+
|
|
|
6c9f0c |
+ int sock; /* raw packet socket for driver access */
|
|
|
6c9f0c |
+ int pf_sock;
|
|
|
6c9f0c |
+ int membership, multi, iff_allmulti, iff_up;
|
|
|
6c9f0c |
+};
|
|
|
6c9f0c |
+
|
|
|
6c9f0c |
+static const u8 pae_group_addr[ETH_ALEN] =
|
|
|
6c9f0c |
+{ 0x01, 0x80, 0xc2, 0x00, 0x00, 0x03 };
|
|
|
6c9f0c |
+
|
|
|
6c9f0c |
+#endif /* DRIVER_WIRED_COMMON_H */
|
|
|
6c9f0c |
--
|
|
|
6c9f0c |
2.7.4
|
|
|
6c9f0c |
|