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

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