2 * Generic Snooping for Proxy ARP
3 * Copyright (c) 2014, Qualcomm Atheros, Inc.
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
14 #include "ap_drv_ops.h"
18 int x_snoop_init(struct hostapd_data *hapd)
20 struct hostapd_bss_config *conf = hapd->conf;
24 "x_snoop: ap_isolate must be enabled for x_snoop");
28 if (conf->bridge[0] == '\0') {
30 "x_snoop: Bridge must be configured for x_snoop");
34 if (hostapd_drv_br_port_set_attr(hapd, DRV_BR_PORT_ATTR_HAIRPIN_MODE,
37 "x_snoop: Failed to enable hairpin_mode on the bridge port");
41 if (hostapd_drv_br_port_set_attr(hapd, DRV_BR_PORT_ATTR_PROXYARP, 1)) {
43 "x_snoop: Failed to enable proxyarp on the bridge port");
47 if (hostapd_drv_br_set_net_param(hapd, DRV_BR_NET_PARAM_GARP_ACCEPT,
50 "x_snoop: Failed to enable accepting gratuitous ARP on the bridge");
55 if (hostapd_drv_br_set_net_param(hapd, DRV_BR_MULTICAST_SNOOPING, 1)) {
57 "x_snoop: Failed to enable multicast snooping on the bridge");
60 #endif /* CONFIG_IPV6 */
66 struct l2_packet_data *
67 x_snoop_get_l2_packet(struct hostapd_data *hapd,
68 void (*handler)(void *ctx, const u8 *src_addr,
69 const u8 *buf, size_t len),
70 enum l2_packet_filter_type type)
72 struct hostapd_bss_config *conf = hapd->conf;
73 struct l2_packet_data *l2;
75 l2 = l2_packet_init(conf->bridge, NULL, ETH_P_ALL, handler, hapd, 1);
78 "x_snoop: Failed to initialize L2 packet processing %s",
83 if (l2_packet_set_packet_filter(l2, type)) {
85 "x_snoop: Failed to set L2 packet filter for type: %d",
95 void x_snoop_mcast_to_ucast_convert_send(struct hostapd_data *hapd,
96 struct sta_info *sta, u8 *buf,
103 if (!(dst_addr[0] & 0x01))
106 wpa_printf(MSG_EXCESSIVE, "x_snoop: Multicast-to-unicast conversion "
107 MACSTR " -> " MACSTR " (len %u)",
108 MAC2STR(dst_addr), MAC2STR(sta->addr), (unsigned int) len);
110 /* save the multicast destination address for restoring it later */
111 os_memcpy(addr, buf, ETH_ALEN);
113 os_memcpy(buf, sta->addr, ETH_ALEN);
114 res = l2_packet_send(hapd->sock_dhcp, NULL, 0, buf, len);
116 wpa_printf(MSG_DEBUG,
117 "x_snoop: Failed to send mcast to ucast converted packet to "
118 MACSTR, MAC2STR(sta->addr));
121 /* restore the multicast destination address */
122 os_memcpy(buf, addr, ETH_ALEN);
126 void x_snoop_deinit(struct hostapd_data *hapd)
128 hostapd_drv_br_set_net_param(hapd, DRV_BR_NET_PARAM_GARP_ACCEPT, 0);
129 hostapd_drv_br_port_set_attr(hapd, DRV_BR_PORT_ATTR_PROXYARP, 0);
130 hostapd_drv_br_port_set_attr(hapd, DRV_BR_PORT_ATTR_HAIRPIN_MODE, 0);