[PATCHv3 6/6] vlan: use untagged/tagged for vlan configuration

michael-dev at fami-braun.de michael-dev
Thu Apr 11 02:52:44 PDT 2013


From: Michael Braun <michael-dev at fami-braun.de>

Signed-hostap: Michael Braun <michael-dev at fami-braun.de>
---
 src/ap/vlan_init.c | 192 ++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 125 insertions(+), 67 deletions(-)

diff --git a/src/ap/vlan_init.c b/src/ap/vlan_init.c
index 27afbc8..da40ade 100644
--- a/src/ap/vlan_init.c
+++ b/src/ap/vlan_init.c
@@ -492,55 +492,81 @@ static int vlan_set_name_type(unsigned int name_type)
 #endif /* CONFIG_VLAN_NETLINK */
 
 
-static void vlan_newlink(char *ifname, struct hostapd_data *hapd)
+static void vlan_newlink_vlan(struct hostapd_vlan *vlan, struct hostapd_data *hapd, int vlan_id, char* ifname)
 {
 	char vlan_ifname[IFNAMSIZ];
 	char br_name[IFNAMSIZ];
-	struct hostapd_vlan *vlan = hapd->conf->vlan;
 	char *tagged_interface = hapd->conf->ssid.vlan_tagged_interface;
 	int vlan_naming = hapd->conf->ssid.vlan_naming;
 
-	wpa_printf(MSG_DEBUG, "VLAN: vlan_newlink(%s)", ifname);
+	os_snprintf(br_name, sizeof(br_name), "brvlan%d", vlan_id);
 
-	while (vlan) {
-		if (os_strcmp(ifname, vlan->ifname) == 0) {
+	if (!br_addbr(br_name))
+		vlan->clean |= DVLAN_CLEAN_BR;
 
-			os_snprintf(br_name, sizeof(br_name), "brvlan%d",
-				    vlan->vlan_id);
+	ifconfig_up(br_name);
 
-			if (!br_addbr(br_name))
-				vlan->clean |= DVLAN_CLEAN_BR;
+	if (tagged_interface) {
+		if (vlan_naming ==
+		    DYNAMIC_VLAN_NAMING_WITH_DEVICE)
+			os_snprintf(vlan_ifname,
+				    sizeof(vlan_ifname),
+				    "%s.%d", tagged_interface,
+				    vlan_id);
+		else
+			os_snprintf(vlan_ifname,
+				    sizeof(vlan_ifname),
+				    "vlan%d", vlan_id);
 
-			ifconfig_up(br_name);
+		ifconfig_up(tagged_interface);
+		if (!vlan_add(tagged_interface, vlan_id, vlan_ifname))
+			vlan->clean |= DVLAN_CLEAN_VLAN;
 
-			if (tagged_interface) {
-				if (vlan_naming ==
-				    DYNAMIC_VLAN_NAMING_WITH_DEVICE)
-					os_snprintf(vlan_ifname,
-						    sizeof(vlan_ifname),
-						    "%s.%d", tagged_interface,
-						    vlan->vlan_id);
-				else
-					os_snprintf(vlan_ifname,
-						    sizeof(vlan_ifname),
-						    "vlan%d", vlan->vlan_id);
+		if (!br_addif(br_name, vlan_ifname))
+			vlan->clean |= DVLAN_CLEAN_VLAN_PORT;
 
-				ifconfig_up(tagged_interface);
-				if (!vlan_add(tagged_interface, vlan->vlan_id,
-					      vlan_ifname))
-					vlan->clean |= DVLAN_CLEAN_VLAN;
+		ifconfig_up(vlan_ifname);
+	}
 
-				if (!br_addif(br_name, vlan_ifname))
-					vlan->clean |= DVLAN_CLEAN_VLAN_PORT;
+	if (!br_addif(br_name, ifname))
+		vlan->clean |= DVLAN_CLEAN_WLAN_PORT;
 
-				ifconfig_up(vlan_ifname);
-			}
+	ifconfig_up(ifname);
+}
 
-			if (!br_addif(br_name, ifname))
-				vlan->clean |= DVLAN_CLEAN_WLAN_PORT;
+static void vlan_newlink(char *ifname, struct hostapd_data *hapd)
+{
+	struct hostapd_vlan *vlan = hapd->conf->vlan;
+	#ifdef CONFIG_VLAN_TAGGED
+	char vlan_ifname[IFNAMSIZ];
+	int i;
+	#endif
 
-			ifconfig_up(ifname);
+	wpa_printf(MSG_DEBUG, "VLAN: vlan_newlink(%s)", ifname);
 
+	while (vlan) {
+		if (os_strcmp(ifname, vlan->ifname) == 0) {
+			#ifdef CONFIG_VLAN_TAGGED
+			if (vlan_mapping.counter < vlan->vlan_id || vlan->vlan_id <= 0)
+				break;
+			if (vlan_mapping.vlan[vlan->vlan_id-1].untagged > 0)
+				vlan_newlink_vlan(vlan, hapd, vlan_mapping.vlan[vlan->vlan_id-1].untagged, ifname);
+			else
+				ifconfig_up(ifname);
+			for (i = 0; i < vlan_mapping.vlan[vlan->vlan_id-1].num_tagged; i++) {
+				int vlan_id = vlan_mapping.vlan[vlan->vlan_id-1].tagged[i];
+				// add tagged interface on wlan
+				os_snprintf(vlan_ifname, sizeof(vlan_ifname),
+					    "%s.%d", ifname, vlan_id);
+				vlan_add(ifname, vlan_id, vlan_ifname);
+				// add this to bridge
+				vlan_newlink_vlan(vlan, hapd, vlan_id, vlan_ifname);
+			}
+			#else
+			if (MAX_VLAN_ID < vlan->vlan_id || vlan->vlan_id <= 0)
+				break;
+			vlan_newlink_vlan(vlan, hapd, vlan->vlan_id, ifname);
+			#endif
 			break;
 		}
 		vlan = vlan->next;
@@ -548,58 +574,84 @@ static void vlan_newlink(char *ifname, struct hostapd_data *hapd)
 }
 
 
-static void vlan_dellink(char *ifname, struct hostapd_data *hapd)
+static void vlan_dellink_vlan(struct hostapd_vlan *vlan, struct hostapd_data *hapd, int vlan_id, char* ifname)
 {
 	char vlan_ifname[IFNAMSIZ];
 	char br_name[IFNAMSIZ];
-	struct hostapd_vlan *first, *prev, *vlan = hapd->conf->vlan;
 	char *tagged_interface = hapd->conf->ssid.vlan_tagged_interface;
 	int vlan_naming = hapd->conf->ssid.vlan_naming;
 
+	os_snprintf(br_name, sizeof(br_name), "brvlan%d", vlan_id);
+
+	if (vlan->clean & DVLAN_CLEAN_WLAN_PORT)
+		br_delif(br_name, ifname);
+
+	if (tagged_interface) {
+		if (vlan_naming ==
+		    DYNAMIC_VLAN_NAMING_WITH_DEVICE)
+			os_snprintf(vlan_ifname,
+				    sizeof(vlan_ifname),
+				    "%s.%d", tagged_interface,
+				    vlan_id);
+		else
+			os_snprintf(vlan_ifname,
+				    sizeof(vlan_ifname),
+				    "vlan%d", vlan_id);
+		if (vlan->clean & DVLAN_CLEAN_VLAN_PORT)
+			br_delif(br_name, vlan_ifname);
+		ifconfig_down(vlan_ifname);
+
+		if (vlan->clean & DVLAN_CLEAN_VLAN)
+			vlan_rem(vlan_ifname);
+	}
+
+	if ((vlan->clean & DVLAN_CLEAN_BR) &&
+	    br_getnumports(br_name) == 0) {
+		ifconfig_down(br_name);
+		br_delbr(br_name);
+	}
+
+}
+
+static void vlan_dellink(char *ifname, struct hostapd_data *hapd)
+{
+	struct hostapd_vlan *first, *prev, *vlan = hapd->conf->vlan;
+	#ifdef CONFIG_VLAN_TAGGED
+	char vlan_ifname[IFNAMSIZ];
+	int i;
+	#endif
+
 	wpa_printf(MSG_DEBUG, "VLAN: vlan_dellink(%s)", ifname);
 
 	first = prev = vlan;
 
 	while (vlan) {
 		if (os_strcmp(ifname, vlan->ifname) == 0) {
-			os_snprintf(br_name, sizeof(br_name), "brvlan%d",
-				    vlan->vlan_id);
-
-			if (vlan->clean & DVLAN_CLEAN_WLAN_PORT)
-				br_delif(br_name, vlan->ifname);
-
-			if (tagged_interface) {
-				if (vlan_naming ==
-				    DYNAMIC_VLAN_NAMING_WITH_DEVICE)
-					os_snprintf(vlan_ifname,
-						    sizeof(vlan_ifname),
-						    "%s.%d", tagged_interface,
-						    vlan->vlan_id);
-				else
-					os_snprintf(vlan_ifname,
-						    sizeof(vlan_ifname),
-						    "vlan%d", vlan->vlan_id);
-				if (vlan->clean & DVLAN_CLEAN_VLAN_PORT)
-					br_delif(br_name, vlan_ifname);
-				ifconfig_down(vlan_ifname);
-
-				if (vlan->clean & DVLAN_CLEAN_VLAN)
-					vlan_rem(vlan_ifname);
-			}
-
-			if ((vlan->clean & DVLAN_CLEAN_BR) &&
-			    br_getnumports(br_name) == 0) {
-				ifconfig_down(br_name);
-				br_delbr(br_name);
+			#ifdef CONFIG_VLAN_TAGGED
+			if (vlan_mapping.counter < vlan->vlan_id || vlan->vlan_id <= 0)
+				break;
+			if (vlan_mapping.vlan[vlan->vlan_id-1].untagged > 0)
+				vlan_dellink_vlan(vlan, hapd, vlan_mapping.vlan[vlan->vlan_id-1].untagged, ifname);
+			for (i = 0; i < vlan_mapping.vlan[vlan->vlan_id-1].num_tagged; i++) {
+				int vlan_id = vlan_mapping.vlan[vlan->vlan_id-1].tagged[i];
+				// add tagged interface on wlan
+				os_snprintf(vlan_ifname, sizeof(vlan_ifname),
+					    "%s.%d", ifname, vlan_id);
+				vlan_rem(vlan_ifname);
+				// add this to bridge
+				vlan_dellink_vlan(vlan, hapd, vlan_id, vlan_ifname);
 			}
-
+			#else
+			if (MAX_VLAN_ID < vlan->vlan_id || vlan->vlan_id <= 0)
+				break;
+			vlan_dellink_vlan(vlan, hapd, vlan->vlan_id, ifname);
+			#endif
 			if (vlan == first) {
 				hapd->conf->vlan = vlan->next;
 			} else {
 				prev->next = vlan->next;
 			}
 			os_free(vlan);
-
 			break;
 		}
 		prev = vlan;
@@ -893,9 +945,15 @@ struct hostapd_vlan * vlan_add_dynamic(struct hostapd_data *hapd,
 	struct hostapd_vlan *n;
 	char *ifname, *pos;
 
-	if (vlan == NULL || vlan_id <= 0 || vlan_id > MAX_VLAN_ID ||
-	    vlan->vlan_id != VLAN_ID_WILDCARD)
+	if (vlan == NULL || vlan_id <= 0 || vlan->vlan_id != VLAN_ID_WILDCARD)
+		return NULL;
+	#ifdef CONFIG_VLAN_TAGGED
+	if (vlan_mapping.counter < vlan_id)
+		return NULL;
+	#else
+	if (MAX_VLAN_ID < vlan_id)
 		return NULL;
+	#endif
 
 	wpa_printf(MSG_DEBUG, "VLAN: %s(vlan_id=%d ifname=%s)",
 		   __func__, vlan_id, vlan->ifname);
-- 
1.8.1.5




More information about the Hostap mailing list