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

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