[PATCH v5 22/22] VLAN: Preserve interfaces that already existed while creating

Michael Braun michael-dev at fami-braun.de
Tue Nov 19 14:48:30 EST 2013


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

diff --git a/src/ap/vlan_init.c b/src/ap/vlan_init.c
index a6c21e2..5e2b82e 100644
--- a/src/ap/vlan_init.c
+++ b/src/ap/vlan_init.c
@@ -1110,6 +1110,9 @@ struct hostapd_vlan * vlan_add_dynamic(struct hostapd_data *hapd,
 {
 	struct hostapd_vlan *n, *i, *prev;
 	char *ifname, *pos;
+#ifdef CONFIG_FULL_DYNAMIC_VLAN
+	int ifidx, created = 0;
+#endif /* CONFIG_FULL_DYNAMIC_VLAN */
 
 	if (vlan == NULL
 	    || vlan_untagged(&vlan_id) <= 0
@@ -1169,14 +1172,21 @@ struct hostapd_vlan * vlan_add_dynamic(struct hostapd_data *hapd,
 	            artifical_id, pos);
 	os_free(ifname);
 
-	if (hostapd_vlan_if_add(hapd, n->ifname)) {
-		os_free(n);
-		return NULL;
-	}
 #ifdef CONFIG_FULL_DYNAMIC_VLAN
-	// if id_add returned the ifidx, it could be reused here
+	ifidx = if_nametoindex(n->ifname);
+	if (!ifidx) {
+		/* interface does not yet exist */
+		if (hostapd_vlan_if_add(hapd, n->ifname)) {
+			/* interface could not be created */
+			os_free(n);
+			return NULL;
+		}
+		created = 1;
+	}
+	hapd_get_dynamic_iface(NULL, n->ifname, created, hapd);
+	// if if_add returned the ifidx, it could be reused here
 	n->ifidx = if_nametoindex(n->ifname);
-#endif
+#endif /* CONFIG_FULL_DYNAMIC_VLAN */
 
 	/* insert into list */
 	if (!prev) {
@@ -1199,9 +1209,10 @@ int vlan_remove_dynamic(struct hostapd_data *hapd,
                         struct vlan_description vlan_id)
 {
 	struct hostapd_vlan *vlan;
-	char buf[IFNAMSIZ+1];
+	char ifname[IFNAMSIZ+1];
 
-	if (vlan_untagged(&vlan_id) == VLAN_ID_WILDCARD)
+	if (vlan_untagged(&vlan_id) == VLAN_ID_WILDCARD
+	    || !vlan_notempty(&vlan_id))
 		return 1;
 
 	wpa_printf(MSG_DEBUG, "VLAN: %s(vlan_id=%s)", __func__,
@@ -1220,14 +1231,20 @@ int vlan_remove_dynamic(struct hostapd_data *hapd,
 	if (vlan == NULL)
 		return 1;
 
-	if (vlan->dynamic_vlan == 0) {
-		os_strlcpy(buf, vlan->ifname, sizeof(buf));
-#ifdef CONFIG_FULL_DYNAMIC_VLAN
-		vlan_dellink(buf, vlan->ifidx, hapd);
-#endif
-		vlan = NULL; /* freed by vlan_dellink */
-		hostapd_vlan_if_remove(hapd, buf);
-	}
+	if (vlan->dynamic_vlan != 0)
+		return 0;
 
+	os_strlcpy(ifname, vlan->ifname, sizeof(ifname));
+#ifndef CONFIG_FULL_DYNAMIC_VLAN
+	hostapd_vlan_if_remove(hapd, ifname);
+#else
+	vlan_dellink(ifname, vlan->ifidx, hapd);
+	vlan = NULL; /* freed by vlan_dellink */
+
+	if (hapd_put_dynamic_iface(NULL, ifname, hapd) == 1)
+		hostapd_vlan_if_remove(hapd, ifname);
+	return 0;
+
+#endif /* CONFIG_FULL_DYNAMIC_VLAN */
 	return 0;
 }



More information about the HostAP mailing list