From 1d783762cf1ab1f37924af22d59db724adcbdc7b Mon Sep 17 00:00:00 2001 From: Kyeyoon Park Date: Fri, 31 Oct 2014 18:18:35 -0700 Subject: [PATCH] AP: Convert "dhcp_snoop" to use the generic "x_snoop" Signed-off-by: Kyeyoon Park --- src/ap/dhcp_snoop.c | 51 +++------------------------------------------ src/ap/hostapd.c | 17 ++++++++++++--- 2 files changed, 17 insertions(+), 51 deletions(-) diff --git a/src/ap/dhcp_snoop.c b/src/ap/dhcp_snoop.c index 1bd4ba456..24ac446d0 100644 --- a/src/ap/dhcp_snoop.c +++ b/src/ap/dhcp_snoop.c @@ -7,7 +7,6 @@ */ #include "utils/includes.h" -#include #include #include @@ -16,6 +15,7 @@ #include "hostapd.h" #include "sta_info.h" #include "ap_drv_ops.h" +#include "x_snoop.h" #include "dhcp_snoop.h" struct bootp_pkt { @@ -132,22 +132,8 @@ static void handle_dhcp(void *ctx, const u8 *src_addr, const u8 *buf, int dhcp_snoop_init(struct hostapd_data *hapd) { - struct hostapd_bss_config *conf = hapd->conf; - - if (!conf->isolate) { - wpa_printf(MSG_DEBUG, - "dhcp_snoop: ap_isolate must be enabled for DHCP snooping"); - return -1; - } - - if (conf->bridge[0] == '\0') { - wpa_printf(MSG_DEBUG, - "dhcp_snoop: Bridge must be configured for DHCP snooping"); - return -1; - } - - hapd->sock_dhcp = l2_packet_init(conf->bridge, NULL, ETH_P_ALL, - handle_dhcp, hapd, 1); + hapd->sock_dhcp = x_snoop_get_l2_packet(hapd, handle_dhcp, + L2_PACKET_FILTER_DHCP); if (hapd->sock_dhcp == NULL) { wpa_printf(MSG_DEBUG, "dhcp_snoop: Failed to initialize L2 packet processing for DHCP packet: %s", @@ -155,42 +141,11 @@ int dhcp_snoop_init(struct hostapd_data *hapd) return -1; } - if (l2_packet_set_packet_filter(hapd->sock_dhcp, - L2_PACKET_FILTER_DHCP)) { - wpa_printf(MSG_DEBUG, - "dhcp_snoop: Failed to set L2 packet filter for DHCP: %s", - strerror(errno)); - return -1; - } - - if (hostapd_drv_br_port_set_attr(hapd, DRV_BR_PORT_ATTR_HAIRPIN_MODE, - 1)) { - wpa_printf(MSG_DEBUG, - "dhcp_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, - "dhcp_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, - "dhcp_snoop: Failed to enable accepting gratuitous ARP on the bridge"); - return -1; - } - return 0; } void dhcp_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); l2_packet_deinit(hapd->sock_dhcp); } diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c index 2871b9b76..2ed16046e 100644 --- a/src/ap/hostapd.c +++ b/src/ap/hostapd.c @@ -36,6 +36,7 @@ #include "dfs.h" #include "ieee802_11.h" #include "bss_load.h" +#include "x_snoop.h" #include "dhcp_snoop.h" @@ -314,6 +315,7 @@ static void hostapd_free_hapd_data(struct hostapd_data *hapd) bss_load_update_deinit(hapd); dhcp_snoop_deinit(hapd); + x_snoop_deinit(hapd); #ifdef CONFIG_SQLITE bin_clear_free(hapd->tmp_eap_user.identity, @@ -893,9 +895,18 @@ static int hostapd_setup_bss(struct hostapd_data *hapd, int first) return -1; } - if (conf->proxy_arp && dhcp_snoop_init(hapd)) { - wpa_printf(MSG_ERROR, "DHCP snooping initialization failed"); - return -1; + if (conf->proxy_arp) { + if (x_snoop_init(hapd)) { + wpa_printf(MSG_ERROR, + "Generic snooping infrastructure initialization failed"); + return -1; + } + + if (dhcp_snoop_init(hapd)) { + wpa_printf(MSG_ERROR, + "DHCP snooping initialization failed"); + return -1; + } } if (!hostapd_drv_none(hapd) && vlan_init(hapd)) {