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

6c9f0c
From b0906ef770ec5a74221bcb4e63dbbc8682f49d5a Mon Sep 17 00:00:00 2001
6c9f0c
Message-Id: <b0906ef770ec5a74221bcb4e63dbbc8682f49d5a.1488376602.git.dcaratti@redhat.com>
6c9f0c
From: Sabrina Dubroca <sd@queasysnail.net>
6c9f0c
Date: Sun, 27 Nov 2016 20:08:45 +0100
6c9f0c
Subject: [PATCH] drivers: Move wired_multicast_membership() 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   | 40 +++++----------------------
6c9f0c
 src/drivers/driver_wired.c        | 28 -------------------
6c9f0c
 src/drivers/driver_wired_common.c | 57 +++++++++++++++++++++++++++++++++++++++
6c9f0c
 src/drivers/driver_wired_common.h |  2 ++
6c9f0c
 src/drivers/drivers.mak           |  6 +++++
6c9f0c
 src/drivers/drivers.mk            |  5 ++++
6c9f0c
 6 files changed, 76 insertions(+), 62 deletions(-)
6c9f0c
 create mode 100644 src/drivers/driver_wired_common.c
6c9f0c
6c9f0c
diff --git a/src/drivers/driver_macsec_qca.c b/src/drivers/driver_macsec_qca.c
6c9f0c
index 6391e08..e04fb0f 100644
6c9f0c
--- a/src/drivers/driver_macsec_qca.c
6c9f0c
+++ b/src/drivers/driver_macsec_qca.c
6c9f0c
@@ -76,34 +76,6 @@ struct macsec_qca_data {
6c9f0c
 };
6c9f0c
 
6c9f0c
 
6c9f0c
-static int macsec_qca_multicast_membership(int sock, int ifindex,
6c9f0c
-					   const u8 *addr, int add)
6c9f0c
-{
6c9f0c
-#ifdef __linux__
6c9f0c
-	struct packet_mreq mreq;
6c9f0c
-
6c9f0c
-	if (sock < 0)
6c9f0c
-		return -1;
6c9f0c
-
6c9f0c
-	os_memset(&mreq, 0, sizeof(mreq));
6c9f0c
-	mreq.mr_ifindex = ifindex;
6c9f0c
-	mreq.mr_type = PACKET_MR_MULTICAST;
6c9f0c
-	mreq.mr_alen = ETH_ALEN;
6c9f0c
-	os_memcpy(mreq.mr_address, addr, ETH_ALEN);
6c9f0c
-
6c9f0c
-	if (setsockopt(sock, SOL_PACKET,
6c9f0c
-		       add ? PACKET_ADD_MEMBERSHIP : PACKET_DROP_MEMBERSHIP,
6c9f0c
-		       &mreq, sizeof(mreq)) < 0) {
6c9f0c
-		wpa_printf(MSG_ERROR, "setsockopt: %s", strerror(errno));
6c9f0c
-		return -1;
6c9f0c
-	}
6c9f0c
-	return 0;
6c9f0c
-#else /* __linux__ */
6c9f0c
-	return -1;
6c9f0c
-#endif /* __linux__ */
6c9f0c
-}
6c9f0c
-
6c9f0c
-
6c9f0c
 static int macsec_qca_get_ssid(void *priv, u8 *ssid)
6c9f0c
 {
6c9f0c
 	ssid[0] = 0;
6c9f0c
@@ -341,9 +313,9 @@ static void * macsec_qca_init(void *ctx, const char *ifname)
6c9f0c
 		drv->common.iff_up = 1;
6c9f0c
 	}
6c9f0c
 
6c9f0c
-	if (macsec_qca_multicast_membership(drv->common.pf_sock,
6c9f0c
-					    if_nametoindex(drv->common.ifname),
6c9f0c
-					    pae_group_addr, 1) == 0) {
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,
6c9f0c
 			   "%s: Added multicast membership with packet socket",
6c9f0c
 			   __func__);
6c9f0c
@@ -392,9 +364,9 @@ static void macsec_qca_deinit(void *priv)
6c9f0c
 	int flags;
6c9f0c
 
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
+	    wired_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
diff --git a/src/drivers/driver_wired.c b/src/drivers/driver_wired.c
6c9f0c
index b6f79e3..68c55fd 100644
6c9f0c
--- a/src/drivers/driver_wired.c
6c9f0c
+++ b/src/drivers/driver_wired.c
6c9f0c
@@ -76,34 +76,6 @@ struct dhcp_message {
6c9f0c
 };
6c9f0c
 
6c9f0c
 
6c9f0c
-static int wired_multicast_membership(int sock, int ifindex,
6c9f0c
-				      const u8 *addr, int add)
6c9f0c
-{
6c9f0c
-#ifdef __linux__
6c9f0c
-	struct packet_mreq mreq;
6c9f0c
-
6c9f0c
-	if (sock < 0)
6c9f0c
-		return -1;
6c9f0c
-
6c9f0c
-	os_memset(&mreq, 0, sizeof(mreq));
6c9f0c
-	mreq.mr_ifindex = ifindex;
6c9f0c
-	mreq.mr_type = PACKET_MR_MULTICAST;
6c9f0c
-	mreq.mr_alen = ETH_ALEN;
6c9f0c
-	os_memcpy(mreq.mr_address, addr, ETH_ALEN);
6c9f0c
-
6c9f0c
-	if (setsockopt(sock, SOL_PACKET,
6c9f0c
-		       add ? PACKET_ADD_MEMBERSHIP : PACKET_DROP_MEMBERSHIP,
6c9f0c
-		       &mreq, sizeof(mreq)) < 0) {
6c9f0c
-		wpa_printf(MSG_ERROR, "setsockopt: %s", strerror(errno));
6c9f0c
-		return -1;
6c9f0c
-	}
6c9f0c
-	return 0;
6c9f0c
-#else /* __linux__ */
6c9f0c
-	return -1;
6c9f0c
-#endif /* __linux__ */
6c9f0c
-}
6c9f0c
-
6c9f0c
-
6c9f0c
 #ifdef __linux__
6c9f0c
 static void handle_data(void *ctx, unsigned char *buf, size_t len)
6c9f0c
 {
6c9f0c
diff --git a/src/drivers/driver_wired_common.c b/src/drivers/driver_wired_common.c
6c9f0c
new file mode 100644
6c9f0c
index 0000000..3969880
6c9f0c
--- /dev/null
6c9f0c
+++ b/src/drivers/driver_wired_common.c
6c9f0c
@@ -0,0 +1,57 @@
6c9f0c
+/*
6c9f0c
+ * Common functions 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
+#include "includes.h"
6c9f0c
+
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
+#include <net/if.h>
6c9f0c
+#ifdef __linux__
6c9f0c
+#include <netpacket/packet.h>
6c9f0c
+#include <net/if_arp.h>
6c9f0c
+#include <net/if.h>
6c9f0c
+#endif /* __linux__ */
6c9f0c
+#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
6c9f0c
+#include <net/if_dl.h>
6c9f0c
+#include <net/if_media.h>
6c9f0c
+#endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) */
6c9f0c
+#ifdef __sun__
6c9f0c
+#include <sys/sockio.h>
6c9f0c
+#endif /* __sun__ */
6c9f0c
+
6c9f0c
+
6c9f0c
+int wired_multicast_membership(int sock, int ifindex, const u8 *addr, int add)
6c9f0c
+{
6c9f0c
+#ifdef __linux__
6c9f0c
+	struct packet_mreq mreq;
6c9f0c
+
6c9f0c
+	if (sock < 0)
6c9f0c
+		return -1;
6c9f0c
+
6c9f0c
+	os_memset(&mreq, 0, sizeof(mreq));
6c9f0c
+	mreq.mr_ifindex = ifindex;
6c9f0c
+	mreq.mr_type = PACKET_MR_MULTICAST;
6c9f0c
+	mreq.mr_alen = ETH_ALEN;
6c9f0c
+	os_memcpy(mreq.mr_address, addr, ETH_ALEN);
6c9f0c
+
6c9f0c
+	if (setsockopt(sock, SOL_PACKET,
6c9f0c
+		       add ? PACKET_ADD_MEMBERSHIP : PACKET_DROP_MEMBERSHIP,
6c9f0c
+		       &mreq, sizeof(mreq)) < 0) {
6c9f0c
+		wpa_printf(MSG_ERROR, "setsockopt: %s", strerror(errno));
6c9f0c
+		return -1;
6c9f0c
+	}
6c9f0c
+	return 0;
6c9f0c
+#else /* __linux__ */
6c9f0c
+	return -1;
6c9f0c
+#endif /* __linux__ */
6c9f0c
+}
6c9f0c
diff --git a/src/drivers/driver_wired_common.h b/src/drivers/driver_wired_common.h
6c9f0c
index 8d9dd37..39a57a6 100644
6c9f0c
--- a/src/drivers/driver_wired_common.h
6c9f0c
+++ b/src/drivers/driver_wired_common.h
6c9f0c
@@ -22,4 +22,6 @@ struct driver_wired_common_data {
6c9f0c
 static const u8 pae_group_addr[ETH_ALEN] =
6c9f0c
 { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x03 };
6c9f0c
 
6c9f0c
+int wired_multicast_membership(int sock, int ifindex, const u8 *addr, int add);
6c9f0c
+
6c9f0c
 #endif /* DRIVER_WIRED_COMMON_H */
6c9f0c
diff --git a/src/drivers/drivers.mak b/src/drivers/drivers.mak
6c9f0c
index c6d3f81..282da50 100644
6c9f0c
--- a/src/drivers/drivers.mak
6c9f0c
+++ b/src/drivers/drivers.mak
6c9f0c
@@ -15,11 +15,17 @@ DRV_AP_LIBS =
6c9f0c
 ifdef CONFIG_DRIVER_WIRED
6c9f0c
 DRV_CFLAGS += -DCONFIG_DRIVER_WIRED
6c9f0c
 DRV_OBJS += ../src/drivers/driver_wired.o
6c9f0c
+NEED_DRV_WIRED_COMMON=1
6c9f0c
 endif
6c9f0c
 
6c9f0c
 ifdef CONFIG_DRIVER_MACSEC_QCA
6c9f0c
 DRV_CFLAGS += -DCONFIG_DRIVER_MACSEC_QCA
6c9f0c
 DRV_OBJS += ../src/drivers/driver_macsec_qca.o
6c9f0c
+NEED_DRV_WIRED_COMMON=1
6c9f0c
+endif
6c9f0c
+
6c9f0c
+ifdef NEED_DRV_WIRED_COMMON
6c9f0c
+DRV_OBJS += ../src/drivers/driver_wired_common.o
6c9f0c
 endif
6c9f0c
 
6c9f0c
 ifdef CONFIG_DRIVER_NL80211
6c9f0c
diff --git a/src/drivers/drivers.mk b/src/drivers/drivers.mk
6c9f0c
index c6fe4c2..508f834 100644
6c9f0c
--- a/src/drivers/drivers.mk
6c9f0c
+++ b/src/drivers/drivers.mk
6c9f0c
@@ -15,6 +15,11 @@ DRV_AP_LIBS =
6c9f0c
 ifdef CONFIG_DRIVER_WIRED
6c9f0c
 DRV_CFLAGS += -DCONFIG_DRIVER_WIRED
6c9f0c
 DRV_OBJS += src/drivers/driver_wired.c
6c9f0c
+NEED_DRV_WIRED_COMMON=1
6c9f0c
+endif
6c9f0c
+
6c9f0c
+ifdef NEED_DRV_WIRED_COMMON
6c9f0c
+DRV_OBJS += src/drivers/driver_wired_common.c
6c9f0c
 endif
6c9f0c
 
6c9f0c
 ifdef CONFIG_DRIVER_NL80211
6c9f0c
-- 
6c9f0c
2.7.4
6c9f0c