struct hostapd_vlan * vlan_add_dynamic(struct hostapd_data *hapd, struct hostapd_vlan *vlan, int vlan_id, struct vlan_description *vlan_desc) { struct hostapd_vlan *n; char ifname[IFNAMSIZ + 1], *pos; int ret; if (vlan == NULL || vlan->vlan_id != VLAN_ID_WILDCARD) return NULL; wpa_printf(MSG_DEBUG, "VLAN: %s(vlan_id=%d ifname=%s)", __func__, vlan_id, vlan->ifname); os_strlcpy(ifname, vlan->ifname, sizeof(ifname)); pos = os_strchr(ifname, '#'); if (pos == NULL) return NULL; *pos++ = '\0'; n = os_zalloc(sizeof(*n)); if (n == NULL) return NULL; n->vlan_id = vlan_id; if (vlan_desc) n->vlan_desc = *vlan_desc; n->dynamic_vlan = 1; ret = os_snprintf(n->ifname, sizeof(n->ifname), "%s%d%s", ifname, vlan_id, pos); if (os_snprintf_error(sizeof(n->ifname), ret)) { os_free(n); return NULL; } os_strlcpy(n->bridge, vlan->bridge, sizeof(n->bridge)); n->next = hapd->conf->vlan; hapd->conf->vlan = n; /* hapd->conf->vlan needs this new VLAN here for WPA setup */ if (vlan_if_add(hapd, n, 0)) { hapd->conf->vlan = n->next; os_free(n); n = NULL; } return n; }
struct hostapd_vlan * vlan_add_dynamic(struct hostapd_data *hapd, struct hostapd_vlan *vlan, int vlan_id) { struct hostapd_vlan *n = NULL; char *ifname, *pos; if (vlan == NULL || vlan_id <= 0 || vlan_id > MAX_VLAN_ID || vlan->vlan_id != VLAN_ID_WILDCARD) return NULL; wpa_printf(MSG_DEBUG, "VLAN: %s(vlan_id=%d ifname=%s)", __func__, vlan_id, vlan->ifname); ifname = os_strdup(vlan->ifname); if (ifname == NULL) return NULL; pos = os_strchr(ifname, '#'); if (pos == NULL) goto free_ifname; *pos++ = '\0'; n = os_zalloc(sizeof(*n)); if (n == NULL) goto free_ifname; n->vlan_id = vlan_id; n->dynamic_vlan = 1; os_snprintf(n->ifname, sizeof(n->ifname), "%s%d%s", ifname, vlan_id, pos); n->next = hapd->conf->vlan; hapd->conf->vlan = n; /* hapd->conf->vlan needs this new VLAN here for WPA setup */ if (vlan_if_add(hapd, n, 0)) { hapd->conf->vlan = n->next; os_free(n); n = NULL; goto free_ifname; } free_ifname: os_free(ifname); return n; }
static int vlan_dynamic_add(struct hostapd_data *hapd, struct hostapd_vlan *vlan) { while (vlan) { if (vlan->vlan_id != VLAN_ID_WILDCARD) { if (vlan_if_add(hapd, vlan, 1)) { wpa_printf(MSG_ERROR, "VLAN: Could not add VLAN %s: %s", vlan->ifname, strerror(errno)); return -1; } #ifdef CONFIG_FULL_DYNAMIC_VLAN vlan_newlink(vlan->ifname, hapd); #endif /* CONFIG_FULL_DYNAMIC_VLAN */ } vlan = vlan->next; } return 0; }