From patchwork Wed Mar 6 17:39:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Kumar Singh X-Patchwork-Id: 1908954 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=0ot5mVj8; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=quicinc.com header.i=@quicinc.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=R6riCOOS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TqfqK1Skpz23qN for ; Thu, 7 Mar 2024 04:41:01 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=bfABq7KE1T4PIl1RkKkF8mHDvFqKFlcsqT5DE3be+N0=; b=0ot5mVj8ZTB2XM n5toe6jc0Fud4WPuD9t1fM4r0l79GX2sKTQuNGCWFb+3PQ1mPlsR3OJUjyoZpFJzXg4elxDNd6vLi qAZJKndSwR+vj2/ejnwmSSUhyI2Z5p9jm4E/5Q66M/ud43jpJ02Y2h+KvblRCBm/XttvU/HwLOl8l iZcS/bd6707tPeaRRk2T5QD9CC/hS5GSSNtjORMxL5vokOTLewhRnGhFaE1W8HRfDLBKaKFUYqOAC 6Y2ttNs6wwAJpafEWrzs1dP6JOy+9ggl0PBzrB4zJ1Qa0HFFxcDjPB+rOgqCMdA7qybeubkomzk0l RnEDxKwLO/LIkRLaprsA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rhvFp-00000001DmE-19W6; Wed, 06 Mar 2024 17:40:33 +0000 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rhvFh-00000001DiH-3AS9 for hostap@lists.infradead.org; Wed, 06 Mar 2024 17:40:27 +0000 Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 426FHfDt006805 for ; Wed, 6 Mar 2024 17:40:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= qcppdkim1; bh=t4UFv9PUf00+PevabxLMF4pmHUUvB96L84tD88FAfRk=; b=R6 riCOOSuAx9OWC48mub0TUkkrmTIpaEt8pJvozw6MNNrCk9wQYrZ7xyK+1e88Rbik AJcgwMFg2i67Z6Z/isqrDHRyvR7hKM/rBkhukoco84rhB6NEMfBK2bB9MSOx+cXr dpUW/hZp/z5URZDsH1r4VVJJTaXpEYY3cSlFuVOZ1s9fUCyfpckv8fm6vFT08zwt 8eKMf6gZlJsEkbKiT5F4ddEek8aZcZwvE0sL1K/xvS2io5sz7l5MDLDRLktvPZKx 3cDDVXYGxcTjJgDGr2EMf1kyrClrRR3PlgM2fPlIQ78OTW5c2Nq3xdIEGCpPxH94 AzVY1SC8MZ2tFYEDk8Fg== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3wpjy3sfqv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 06 Mar 2024 17:40:24 +0000 (GMT) Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 426HeNut017244 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 6 Mar 2024 17:40:23 GMT Received: from cdcwlex322514-lin.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Wed, 6 Mar 2024 09:40:22 -0800 From: Aditya Kumar Singh To: CC: Aditya Kumar Singh Subject: [PATCH 06/16] hostapd: MLO: clean up MLD when not required any further Date: Wed, 6 Mar 2024 23:09:37 +0530 Message-ID: <20240306173947.2611965-7-quic_adisi@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240306173947.2611965-1-quic_adisi@quicinc.com> References: <20240306173947.2611965-1-quic_adisi@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: 27AivawC0tgrsTzPA-R4utQn68XemrPj X-Proofpoint-ORIG-GUID: 27AivawC0tgrsTzPA-R4utQn68XemrPj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-06_11,2024-03-05_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 impostorscore=0 adultscore=0 priorityscore=1501 lowpriorityscore=0 mlxlogscore=951 suspectscore=0 phishscore=0 malwarescore=0 mlxscore=0 spamscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2403060143 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240306_094025_959432_FB3777EA X-CRM114-Status: GOOD ( 29.43 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Currently, whenever a new BSS is created, if it is an EHT then it is tied to a corresponding MLD structure. If structure does not exist already, a new one is created and tied to it. Accordingly link I [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Currently, whenever a new BSS is created, if it is an EHT then it is tied to a corresponding MLD structure. If structure does not exist already, a new one is created and tied to it. Accordingly link ID is assigned as well. However, when BSS is deleted, the MLD structure is not freed and when the next time it is again created, it increments the link ID further and gets a wrong link ID. For example - 2 GHz SLO AP case. First ADD, link ID 0 would be assigned and mld wlan0 would be created. When REMOVE is issued, BSS would be deleted but mld wlan0 will not. When again ADD is issued, BSS will tie back to mld wlan0 but this time link ID will be incremented again and 1 would be assigned. Hence at subsequent REMOVE/ADD, link ID keeps on incrementing. Since link ID remains till lifetime of the BSS and MLD, the next link ID counter can not be just reset back to 0 when a BSS is deleted. Otherwise, in interleaved link enable/disable case, link ID would be changed. Hence to overcome this situation, add changes so that whenever a BSS is deleted, if the MLD is not referenced by any other existing BSS, delete the MLD structure itself. In order to know how many BSSes are referring a given MLD, introduce a new member refcount in MLD. If he value is 0 then it is safe to delete the MLD. Signed-off-by: Aditya Kumar Singh --- src/ap/hostapd.c | 132 +++++++++++++++++++++++++++++++++++++++++++++++ src/ap/hostapd.h | 8 +++ 2 files changed, 140 insertions(+) diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c index 38c4e253047d..a8ae0130fef6 100644 --- a/src/ap/hostapd.c +++ b/src/ap/hostapd.c @@ -73,6 +73,11 @@ static void hostapd_switch_color_timeout_handler(void *eloop_data, void *user_ctx); #endif /* CONFIG_IEEE80211AX */ +#ifdef CONFIG_IEEE80211BE +static void hostapd_mld_ref_inc(struct hostapd_mld *mld); +static void hostapd_mld_ref_dec(struct hostapd_mld *mld); +#endif /* CONFIG_IEEE80211BE */ + int hostapd_for_each_interface(struct hapd_interfaces *interfaces, int (*cb)(struct hostapd_iface *iface, void *ctx), void *ctx) @@ -2891,6 +2896,11 @@ void hostapd_interface_free(struct hostapd_iface *iface) for (j = 0; j < iface->num_bss; j++) { if (!iface->bss) break; +#ifdef CONFIG_IEEE80211BE + if (iface->bss[j]) + hostapd_mld_ref_dec(iface->bss[j]->mld); +#endif /* CONFIG_IEEE80211BE */ + wpa_printf(MSG_DEBUG, "%s: free hapd %p", __func__, iface->bss[j]); os_free(iface->bss[j]); @@ -2913,6 +2923,34 @@ struct hostapd_iface * hostapd_alloc_iface(void) } #ifdef CONFIG_IEEE80211BE +static void hostapd_mld_ref_inc(struct hostapd_mld *mld) +{ + if (!mld) + return; + + if (mld->refcount == HOSTAPD_MLD_MAX_REF_COUNT) { + wpa_printf(MSG_ERROR, "MLD %s: Ref count overflow", + mld->name); + return; + } + + mld->refcount++; +} + +static void hostapd_mld_ref_dec(struct hostapd_mld *mld) +{ + if (!mld) + return; + + if (!mld->refcount) { + wpa_printf(MSG_ERROR, "MLD %s: Ref count underflow", + mld->name); + return; + } + + mld->refcount--; +} + static void hostapd_bss_alloc_link_id(struct hostapd_data *hapd) { hapd->mld_link_id = hapd->mld->next_link_id++; @@ -2943,6 +2981,7 @@ static void hostapd_bss_setup_multi_link(struct hostapd_data *hapd, continue; hapd->mld = mld; + hostapd_mld_ref_inc(mld); hostapd_bss_alloc_link_id(hapd); break; } @@ -2957,12 +2996,14 @@ static void hostapd_bss_setup_multi_link(struct hostapd_data *hapd, os_strlcpy(mld->name, conf->iface, sizeof(conf->iface)); mld->next_link_id = 0; mld->num_links = 0; + mld->refcount = 0; mld->fbss = NULL; dl_list_init(&mld->links); wpa_printf(MSG_DEBUG, "MLD %s created", mld->name); hapd->mld = mld; + hostapd_mld_ref_inc(mld); hostapd_bss_alloc_link_id(hapd); all_mld = os_realloc_array(interfaces->mld, interfaces->mld_count + 1, @@ -2983,6 +3024,81 @@ fail: os_free(mld); hapd->mld = NULL; } + +static void hostapd_cleanup_unused_mlds(struct hapd_interfaces *interfaces) +{ + struct hostapd_mld *mld, **all_mld; + size_t i, j, num_mlds; + bool forced_remove, remove; + + if (!interfaces || !interfaces->mld) + return; + + num_mlds = interfaces->mld_count; + + for (i = 0; i < interfaces->mld_count; i++) { + mld = interfaces->mld[i]; + if (!mld) + continue; + + remove = false; + forced_remove = false; + + if (!mld->refcount) + remove = true; + + /* If mld is still being referenced but no. of interfaces + * are zero then it is safe to force delete it. Normally, + * this should not happen but even if it does, let us free + * the memory + */ + if (!remove && !interfaces->count) + forced_remove = true; + + if (!remove && !forced_remove) + continue; + + wpa_printf(MSG_DEBUG, "MLD %s: freed (forced: %d)", mld->name, + forced_remove); + os_free(mld); + interfaces->mld[i] = NULL; + num_mlds--; + } + + if (!num_mlds) { + interfaces->mld_count = 0; + os_free(interfaces->mld); + interfaces->mld = NULL; + return; + } + + all_mld = os_zalloc(num_mlds * sizeof(struct hostapd_mld *)); + if (!all_mld) { + wpa_printf(MSG_DEBUG, + "MLD: failed to re-allocate the MLDs. Expect issues"); + return; + } + + for (i = 0, j = 0; i < interfaces->mld_count; i++) { + mld = interfaces->mld[i]; + if (!mld) + continue; + + all_mld[j++] = mld; + } + + /* should not happen */ + if (j != num_mlds) { + wpa_printf(MSG_DEBUG, + "MLD: some error occurred while reallocating MLDs. Expect issues."); + os_free(all_mld); + return; + } + + os_free(interfaces->mld); + interfaces->mld = all_mld; + interfaces->mld_count = num_mlds; +} #endif /* CONFIG_IEEE80211BE */ /** @@ -3587,6 +3703,9 @@ int hostapd_add_iface(struct hapd_interfaces *interfaces, char *buf) __func__, hapd, hapd->conf->iface); hostapd_config_free_bss(hapd->conf); hapd->conf = NULL; +#ifdef CONFIG_IEEE80211BE + hostapd_mld_ref_dec(hapd->mld); +#endif /* CONFIG_IEEE80211BE */ os_free(hapd); return -1; } @@ -3678,6 +3797,9 @@ fail: hapd->conf->iface); hostapd_bss_link_deinit(hapd); hostapd_cleanup(hapd); +#ifdef CONFIG_IEEE80211BE + hostapd_mld_ref_dec(hapd->mld); +#endif /* CONFIG_IEEE80211BE */ os_free(hapd); hapd_iface->bss[i] = NULL; } @@ -3687,6 +3809,9 @@ fail: if (new_iface) { interfaces->count--; interfaces->iface[interfaces->count] = NULL; +#ifdef CONFIG_IEEE80211BE + hostapd_cleanup_unused_mlds(interfaces); +#endif /* CONFIG_IEEE80211BE */ } hostapd_cleanup_iface(hapd_iface); } @@ -3709,6 +3834,9 @@ static int hostapd_remove_bss(struct hostapd_iface *iface, unsigned int idx) __func__, hapd, hapd->conf->iface); hostapd_config_free_bss(hapd->conf); hapd->conf = NULL; +#ifdef CONFIG_IEEE80211BE + hostapd_mld_ref_dec(hapd->mld); +#endif /* CONFIG_IEEE80211BE */ os_free(hapd); iface->num_bss--; @@ -3751,6 +3879,10 @@ int hostapd_remove_iface(struct hapd_interfaces *interfaces, char *buf) k++; } interfaces->count--; +#ifdef CONFIG_IEEE80211BE + hostapd_cleanup_unused_mlds(interfaces); +#endif /* CONFIG_IEEE80211BE */ + return 0; } diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h index ec090cbbaa85..27b158c51de9 100644 --- a/src/ap/hostapd.h +++ b/src/ap/hostapd.h @@ -506,10 +506,18 @@ struct hostapd_mld { u8 mld_addr[ETH_ALEN]; u8 next_link_id; u8 num_links; + /* No. of hostapd_data (hapd) referencing to this. num_links can't + * be used since num_links can go to 0 even when bss is disabled + * and when it is enabled back, the MLD should exist hence it can + * not be freed when it is 0. + */ + u8 refcount; struct hostapd_data *fbss; struct dl_list links; /* List HEAD of all affiliated links */ }; + +#define HOSTAPD_MLD_MAX_REF_COUNT 0xFF #endif /* CONFIG_IEEE80211BE */ /**