Blame SOURCES/macsec-0019-drivers-Move-wired_multicast_membership-to-a-common-.patch

b645d2
From b0906ef770ec5a74221bcb4e63dbbc8682f49d5a Mon Sep 17 00:00:00 2001
b645d2
Message-Id: <b0906ef770ec5a74221bcb4e63dbbc8682f49d5a.1488376602.git.dcaratti@redhat.com>
b645d2
From: Sabrina Dubroca <sd@queasysnail.net>
b645d2
Date: Sun, 27 Nov 2016 20:08:45 +0100
b645d2
Subject: [PATCH] drivers: Move wired_multicast_membership() to a common file
b645d2
b645d2
This continues refactoring of the common parts of wired drivers code
b645d2
into a shared file, so that they can be reused by other drivers.
b645d2
b645d2
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
b645d2
---
b645d2
 src/drivers/driver_macsec_qca.c   | 40 +++++----------------------
b645d2
 src/drivers/driver_wired.c        | 28 -------------------
b645d2
 src/drivers/driver_wired_common.c | 57 +++++++++++++++++++++++++++++++++++++++
b645d2
 src/drivers/driver_wired_common.h |  2 ++
b645d2
 src/drivers/drivers.mak           |  6 +++++
b645d2
 src/drivers/drivers.mk            |  5 ++++
b645d2
 6 files changed, 76 insertions(+), 62 deletions(-)
b645d2
 create mode 100644 src/drivers/driver_wired_common.c
b645d2
b645d2
diff --git a/src/drivers/driver_macsec_qca.c b/src/drivers/driver_macsec_qca.c
b645d2
index 6391e08..e04fb0f 100644
b645d2
--- a/src/drivers/driver_macsec_qca.c
b645d2
+++ b/src/drivers/driver_macsec_qca.c
b645d2
@@ -76,34 +76,6 @@ struct macsec_qca_data {
b645d2
 };
b645d2
 
b645d2
 
b645d2
-static int macsec_qca_multicast_membership(int sock, int ifindex,
b645d2
-					   const u8 *addr, int add)
b645d2
-{
b645d2
-#ifdef __linux__
b645d2
-	struct packet_mreq mreq;
b645d2
-
b645d2
-	if (sock < 0)
b645d2
-		return -1;
b645d2
-
b645d2
-	os_memset(&mreq, 0, sizeof(mreq));
b645d2
-	mreq.mr_ifindex = ifindex;
b645d2
-	mreq.mr_type = PACKET_MR_MULTICAST;
b645d2
-	mreq.mr_alen = ETH_ALEN;
b645d2
-	os_memcpy(mreq.mr_address, addr, ETH_ALEN);
b645d2
-
b645d2
-	if (setsockopt(sock, SOL_PACKET,
b645d2
-		       add ? PACKET_ADD_MEMBERSHIP : PACKET_DROP_MEMBERSHIP,
b645d2
-		       &mreq, sizeof(mreq)) < 0) {
b645d2
-		wpa_printf(MSG_ERROR, "setsockopt: %s", strerror(errno));
b645d2
-		return -1;
b645d2
-	}
b645d2
-	return 0;
b645d2
-#else /* __linux__ */
b645d2
-	return -1;
b645d2
-#endif /* __linux__ */
b645d2
-}
b645d2
-
b645d2
-
b645d2
 static int macsec_qca_get_ssid(void *priv, u8 *ssid)
b645d2
 {
b645d2
 	ssid[0] = 0;
b645d2
@@ -341,9 +313,9 @@ static void * macsec_qca_init(void *ctx, const char *ifname)
b645d2
 		drv->common.iff_up = 1;
b645d2
 	}
b645d2
 
b645d2
-	if (macsec_qca_multicast_membership(drv->common.pf_sock,
b645d2
-					    if_nametoindex(drv->common.ifname),
b645d2
-					    pae_group_addr, 1) == 0) {
b645d2
+	if (wired_multicast_membership(drv->common.pf_sock,
b645d2
+				       if_nametoindex(drv->common.ifname),
b645d2
+				       pae_group_addr, 1) == 0) {
b645d2
 		wpa_printf(MSG_DEBUG,
b645d2
 			   "%s: Added multicast membership with packet socket",
b645d2
 			   __func__);
b645d2
@@ -392,9 +364,9 @@ static void macsec_qca_deinit(void *priv)
b645d2
 	int flags;
b645d2
 
b645d2
 	if (drv->common.membership &&
b645d2
-	    macsec_qca_multicast_membership(drv->common.pf_sock,
b645d2
-					    if_nametoindex(drv->common.ifname),
b645d2
-					    pae_group_addr, 0) < 0) {
b645d2
+	    wired_multicast_membership(drv->common.pf_sock,
b645d2
+				       if_nametoindex(drv->common.ifname),
b645d2
+				       pae_group_addr, 0) < 0) {
b645d2
 		wpa_printf(MSG_DEBUG,
b645d2
 			   "%s: Failed to remove PAE multicast group (PACKET)",
b645d2
 			   __func__);
b645d2
diff --git a/src/drivers/driver_wired.c b/src/drivers/driver_wired.c
b645d2
index b6f79e3..68c55fd 100644
b645d2
--- a/src/drivers/driver_wired.c
b645d2
+++ b/src/drivers/driver_wired.c
b645d2
@@ -76,34 +76,6 @@ struct dhcp_message {
b645d2
 };
b645d2
 
b645d2
 
b645d2
-static int wired_multicast_membership(int sock, int ifindex,
b645d2
-				      const u8 *addr, int add)
b645d2
-{
b645d2
-#ifdef __linux__
b645d2
-	struct packet_mreq mreq;
b645d2
-
b645d2
-	if (sock < 0)
b645d2
-		return -1;
b645d2
-
b645d2
-	os_memset(&mreq, 0, sizeof(mreq));
b645d2
-	mreq.mr_ifindex = ifindex;
b645d2
-	mreq.mr_type = PACKET_MR_MULTICAST;
b645d2
-	mreq.mr_alen = ETH_ALEN;
b645d2
-	os_memcpy(mreq.mr_address, addr, ETH_ALEN);
b645d2
-
b645d2
-	if (setsockopt(sock, SOL_PACKET,
b645d2
-		       add ? PACKET_ADD_MEMBERSHIP : PACKET_DROP_MEMBERSHIP,
b645d2
-		       &mreq, sizeof(mreq)) < 0) {
b645d2
-		wpa_printf(MSG_ERROR, "setsockopt: %s", strerror(errno));
b645d2
-		return -1;
b645d2
-	}
b645d2
-	return 0;
b645d2
-#else /* __linux__ */
b645d2
-	return -1;
b645d2
-#endif /* __linux__ */
b645d2
-}
b645d2
-
b645d2
-
b645d2
 #ifdef __linux__
b645d2
 static void handle_data(void *ctx, unsigned char *buf, size_t len)
b645d2
 {
b645d2
diff --git a/src/drivers/driver_wired_common.c b/src/drivers/driver_wired_common.c
b645d2
new file mode 100644
b645d2
index 0000000..3969880
b645d2
--- /dev/null
b645d2
+++ b/src/drivers/driver_wired_common.c
b645d2
@@ -0,0 +1,57 @@
b645d2
+/*
b645d2
+ * Common functions for Wired Ethernet driver interfaces
b645d2
+ * Copyright (c) 2005-2009, Jouni Malinen <j@w1.fi>
b645d2
+ * Copyright (c) 2004, Gunter Burchardt <tira@isx.de>
b645d2
+ *
b645d2
+ * This software may be distributed under the terms of the BSD license.
b645d2
+ * See README for more details.
b645d2
+ */
b645d2
+
b645d2
+#include "includes.h"
b645d2
+
b645d2
+#include "common.h"
b645d2
+#include "eloop.h"
b645d2
+#include "driver.h"
b645d2
+#include "driver_wired_common.h"
b645d2
+
b645d2
+#include <sys/ioctl.h>
b645d2
+#include <net/if.h>
b645d2
+#ifdef __linux__
b645d2
+#include <netpacket/packet.h>
b645d2
+#include <net/if_arp.h>
b645d2
+#include <net/if.h>
b645d2
+#endif /* __linux__ */
b645d2
+#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
b645d2
+#include <net/if_dl.h>
b645d2
+#include <net/if_media.h>
b645d2
+#endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) */
b645d2
+#ifdef __sun__
b645d2
+#include <sys/sockio.h>
b645d2
+#endif /* __sun__ */
b645d2
+
b645d2
+
b645d2
+int wired_multicast_membership(int sock, int ifindex, const u8 *addr, int add)
b645d2
+{
b645d2
+#ifdef __linux__
b645d2
+	struct packet_mreq mreq;
b645d2
+
b645d2
+	if (sock < 0)
b645d2
+		return -1;
b645d2
+
b645d2
+	os_memset(&mreq, 0, sizeof(mreq));
b645d2
+	mreq.mr_ifindex = ifindex;
b645d2
+	mreq.mr_type = PACKET_MR_MULTICAST;
b645d2
+	mreq.mr_alen = ETH_ALEN;
b645d2
+	os_memcpy(mreq.mr_address, addr, ETH_ALEN);
b645d2
+
b645d2
+	if (setsockopt(sock, SOL_PACKET,
b645d2
+		       add ? PACKET_ADD_MEMBERSHIP : PACKET_DROP_MEMBERSHIP,
b645d2
+		       &mreq, sizeof(mreq)) < 0) {
b645d2
+		wpa_printf(MSG_ERROR, "setsockopt: %s", strerror(errno));
b645d2
+		return -1;
b645d2
+	}
b645d2
+	return 0;
b645d2
+#else /* __linux__ */
b645d2
+	return -1;
b645d2
+#endif /* __linux__ */
b645d2
+}
b645d2
diff --git a/src/drivers/driver_wired_common.h b/src/drivers/driver_wired_common.h
b645d2
index 8d9dd37..39a57a6 100644
b645d2
--- a/src/drivers/driver_wired_common.h
b645d2
+++ b/src/drivers/driver_wired_common.h
b645d2
@@ -22,4 +22,6 @@ struct driver_wired_common_data {
b645d2
 static const u8 pae_group_addr[ETH_ALEN] =
b645d2
 { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x03 };
b645d2
 
b645d2
+int wired_multicast_membership(int sock, int ifindex, const u8 *addr, int add);
b645d2
+
b645d2
 #endif /* DRIVER_WIRED_COMMON_H */
b645d2
diff --git a/src/drivers/drivers.mak b/src/drivers/drivers.mak
b645d2
index c6d3f81..282da50 100644
b645d2
--- a/src/drivers/drivers.mak
b645d2
+++ b/src/drivers/drivers.mak
b645d2
@@ -15,11 +15,17 @@ DRV_AP_LIBS =
b645d2
 ifdef CONFIG_DRIVER_WIRED
b645d2
 DRV_CFLAGS += -DCONFIG_DRIVER_WIRED
b645d2
 DRV_OBJS += ../src/drivers/driver_wired.o
b645d2
+NEED_DRV_WIRED_COMMON=1
b645d2
 endif
b645d2
 
b645d2
 ifdef CONFIG_DRIVER_MACSEC_QCA
b645d2
 DRV_CFLAGS += -DCONFIG_DRIVER_MACSEC_QCA
b645d2
 DRV_OBJS += ../src/drivers/driver_macsec_qca.o
b645d2
+NEED_DRV_WIRED_COMMON=1
b645d2
+endif
b645d2
+
b645d2
+ifdef NEED_DRV_WIRED_COMMON
b645d2
+DRV_OBJS += ../src/drivers/driver_wired_common.o
b645d2
 endif
b645d2
 
b645d2
 ifdef CONFIG_DRIVER_NL80211
b645d2
diff --git a/src/drivers/drivers.mk b/src/drivers/drivers.mk
b645d2
index c6fe4c2..508f834 100644
b645d2
--- a/src/drivers/drivers.mk
b645d2
+++ b/src/drivers/drivers.mk
b645d2
@@ -15,6 +15,11 @@ DRV_AP_LIBS =
b645d2
 ifdef CONFIG_DRIVER_WIRED
b645d2
 DRV_CFLAGS += -DCONFIG_DRIVER_WIRED
b645d2
 DRV_OBJS += src/drivers/driver_wired.c
b645d2
+NEED_DRV_WIRED_COMMON=1
b645d2
+endif
b645d2
+
b645d2
+ifdef NEED_DRV_WIRED_COMMON
b645d2
+DRV_OBJS += src/drivers/driver_wired_common.c
b645d2
 endif
b645d2
 
b645d2
 ifdef CONFIG_DRIVER_NL80211
b645d2
-- 
b645d2
2.7.4
b645d2