]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
AP: Add a generic "x_snoop" infrastructure for Proxy ARP
authorKyeyoon Park <kyeyoonp@qca.qualcomm.com>
Sat, 1 Nov 2014 01:18:35 +0000 (18:18 -0700)
committerJouni Malinen <j@w1.fi>
Wed, 19 Nov 2014 14:14:02 +0000 (16:14 +0200)
Signed-off-by: Kyeyoon Park <kyeyoonp@qca.qualcomm.com>
hostapd/Makefile
src/ap/x_snoop.c [new file with mode: 0644]
src/ap/x_snoop.h [new file with mode: 0644]

index 06cd6c7a4e8ab6afc94ed7cb6418990be5970eeb..317271c8bfeda3e3f31a40bb3a69971368b1bcdb 100644 (file)
@@ -853,6 +853,7 @@ endif
 
 ifdef CONFIG_PROXYARP
 CFLAGS += -DCONFIG_PROXYARP
+OBJS += ../src/ap/x_snoop.o
 OBJS += ../src/ap/dhcp_snoop.o
 endif
 
diff --git a/src/ap/x_snoop.c b/src/ap/x_snoop.c
new file mode 100644 (file)
index 0000000..20e8401
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Generic Snooping for Proxy ARP
+ * Copyright (c) 2014, Qualcomm Atheros, Inc.
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+#include "hostapd.h"
+#include "ap_drv_ops.h"
+#include "x_snoop.h"
+
+
+int x_snoop_init(struct hostapd_data *hapd)
+{
+       struct hostapd_bss_config *conf = hapd->conf;
+
+       if (!conf->isolate) {
+               wpa_printf(MSG_DEBUG,
+                          "x_snoop: ap_isolate must be enabled for x_snoop");
+               return -1;
+       }
+
+       if (conf->bridge[0] == '\0') {
+               wpa_printf(MSG_DEBUG,
+                          "x_snoop: Bridge must be configured for x_snoop");
+               return -1;
+       }
+
+       if (hostapd_drv_br_port_set_attr(hapd, DRV_BR_PORT_ATTR_HAIRPIN_MODE,
+                                        1)) {
+               wpa_printf(MSG_DEBUG,
+                          "x_snoop: Failed to enable hairpin_mode on the bridge port");
+               return -1;
+       }
+
+       if (hostapd_drv_br_port_set_attr(hapd, DRV_BR_PORT_ATTR_PROXYARP, 1)) {
+               wpa_printf(MSG_DEBUG,
+                          "x_snoop: Failed to enable proxyarp on the bridge port");
+               return -1;
+       }
+
+       if (hostapd_drv_br_set_net_param(hapd, DRV_BR_NET_PARAM_GARP_ACCEPT,
+                                        1)) {
+               wpa_printf(MSG_DEBUG,
+                          "x_snoop: Failed to enable accepting gratuitous ARP on the bridge");
+               return -1;
+       }
+
+       return 0;
+}
+
+
+struct l2_packet_data *
+x_snoop_get_l2_packet(struct hostapd_data *hapd,
+                     void (*handler)(void *ctx, const u8 *src_addr,
+                                     const u8 *buf, size_t len),
+                     enum l2_packet_filter_type type)
+{
+       struct hostapd_bss_config *conf = hapd->conf;
+       struct l2_packet_data *l2;
+
+       l2 = l2_packet_init(conf->bridge, NULL, ETH_P_ALL, handler, hapd, 1);
+       if (l2 == NULL) {
+               wpa_printf(MSG_DEBUG,
+                          "x_snoop: Failed to initialize L2 packet processing %s",
+                          strerror(errno));
+               return NULL;
+       }
+
+       if (l2_packet_set_packet_filter(l2, type)) {
+               wpa_printf(MSG_DEBUG,
+                          "x_snoop: Failed to set L2 packet filter for type: %d",
+                          type);
+               l2_packet_deinit(l2);
+               return NULL;
+       }
+
+       return l2;
+}
+
+
+void x_snoop_deinit(struct hostapd_data *hapd)
+{
+       hostapd_drv_br_set_net_param(hapd, DRV_BR_NET_PARAM_GARP_ACCEPT, 0);
+       hostapd_drv_br_port_set_attr(hapd, DRV_BR_PORT_ATTR_PROXYARP, 0);
+       hostapd_drv_br_port_set_attr(hapd, DRV_BR_PORT_ATTR_HAIRPIN_MODE, 0);
+}
diff --git a/src/ap/x_snoop.h b/src/ap/x_snoop.h
new file mode 100644 (file)
index 0000000..67ca0c6
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Generic Snooping for Proxy ARP
+ * Copyright (c) 2014, Qualcomm Atheros, Inc.
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#ifndef X_SNOOP_H
+#define X_SNOOP_H
+
+#include "l2_packet/l2_packet.h"
+
+#ifdef CONFIG_PROXYARP
+
+int x_snoop_init(struct hostapd_data *hapd);
+struct l2_packet_data *
+x_snoop_get_l2_packet(struct hostapd_data *hapd,
+                     void (*handler)(void *ctx, const u8 *src_addr,
+                                     const u8 *buf, size_t len),
+                     enum l2_packet_filter_type type);
+void x_snoop_deinit(struct hostapd_data *hapd);
+
+#else /* CONFIG_PROXYARP */
+
+static inline int x_snoop_init(struct hostapd_data *hapd)
+{
+       return 0;
+}
+
+static inline struct l2_packet_data *
+x_snoop_get_l2_packet(struct hostapd_data *hapd,
+                     void (*handler)(void *ctx, const u8 *src_addr,
+                                     const u8 *buf, size_t len),
+                     enum l2_packet_filter_type type)
+{
+       return NULL;
+}
+
+static inline void x_snoop_deinit(struct hostapd_data *hapd)
+{
+}
+
+#endif /* CONFIG_PROXYARP */
+
+#endif /* X_SNOOP_H */