Browse Source

AP: Convert "dhcp_snoop" to use the generic "x_snoop"

Signed-off-by: Kyeyoon Park <kyeyoonp@qca.qualcomm.com>
Kyeyoon Park 10 years ago
parent
commit
1d783762cf
2 changed files with 17 additions and 51 deletions
  1. 3 48
      src/ap/dhcp_snoop.c
  2. 14 3
      src/ap/hostapd.c

+ 3 - 48
src/ap/dhcp_snoop.c

@@ -7,7 +7,6 @@
  */
 
 #include "utils/includes.h"
-#include <linux/filter.h>
 #include <linux/ip.h>
 #include <linux/udp.h>
 
@@ -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);
 }

+ 14 - 3
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)) {