From 99d8c4dca3deb66d9cd259339cdccbf82e255aee Mon Sep 17 00:00:00 2001 From: Gurumoorthi Gnanasambandhan Date: Thu, 5 Dec 2019 12:38:47 +0200 Subject: [PATCH] hostapd: Support VLAN offload to the driver If the driver supports VLAN offload mechanism with a single netdev, use that instead of separate per-VLAN netdevs. Signed-off-by: Gurumoorthi Gnanasambandhan --- src/ap/sta_info.c | 3 ++- src/ap/wpa_auth_glue.c | 42 ++++++++++++++++++++++++++---------------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/ap/sta_info.c b/src/ap/sta_info.c index d0198b256..c0503f6c5 100644 --- a/src/ap/sta_info.c +++ b/src/ap/sta_info.c @@ -1050,7 +1050,8 @@ int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta) if (sta->vlan_id == old_vlanid) goto skip_counting; - if (sta->vlan_id > 0 && vlan == NULL) { + if (sta->vlan_id > 0 && !vlan && + !(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) { hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_DEBUG, "could not find VLAN for " "binding station to (vlan_id=%d)", diff --git a/src/ap/wpa_auth_glue.c b/src/ap/wpa_auth_glue.c index a0131b2b1..e871cc900 100644 --- a/src/ap/wpa_auth_glue.c +++ b/src/ap/wpa_auth_glue.c @@ -385,8 +385,12 @@ static int hostapd_wpa_auth_set_key(void *ctx, int vlan_id, enum wpa_alg alg, if (vlan_id > 0) { ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan, vlan_id); - if (ifname == NULL) - return -1; + if (!ifname) { + if (!(hapd->iface->drv_flags & + WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) + return -1; + ifname = hapd->conf->iface; + } } #ifdef CONFIG_TESTING_OPTIONS @@ -849,26 +853,32 @@ static int hostapd_wpa_auth_update_vlan(void *ctx, const u8 *addr, int vlan_id) #ifndef CONFIG_NO_VLAN struct hostapd_data *hapd = ctx; struct sta_info *sta; - struct vlan_description vlan_desc; sta = ap_get_sta(hapd, addr); if (!sta) return -1; - os_memset(&vlan_desc, 0, sizeof(vlan_desc)); - vlan_desc.notempty = 1; - vlan_desc.untagged = vlan_id; - if (!hostapd_vlan_valid(hapd->conf->vlan, &vlan_desc)) { - wpa_printf(MSG_INFO, "Invalid VLAN ID %d in wpa_psk_file", - vlan_id); - return -1; - } + if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) { + struct vlan_description vlan_desc; - if (ap_sta_set_vlan(hapd, sta, &vlan_desc) < 0) { - wpa_printf(MSG_INFO, - "Failed to assign VLAN ID %d from wpa_psk_file to " - MACSTR, vlan_id, MAC2STR(sta->addr)); - return -1; + os_memset(&vlan_desc, 0, sizeof(vlan_desc)); + vlan_desc.notempty = 1; + vlan_desc.untagged = vlan_id; + if (!hostapd_vlan_valid(hapd->conf->vlan, &vlan_desc)) { + wpa_printf(MSG_INFO, + "Invalid VLAN ID %d in wpa_psk_file", + vlan_id); + return -1; + } + + if (ap_sta_set_vlan(hapd, sta, &vlan_desc) < 0) { + wpa_printf(MSG_INFO, + "Failed to assign VLAN ID %d from wpa_psk_file to " + MACSTR, vlan_id, MAC2STR(sta->addr)); + return -1; + } + } else { + sta->vlan_id = vlan_id; } wpa_printf(MSG_INFO,