From patchwork Sat Nov 16 21:32:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Remi Pommarel X-Patchwork-Id: 18685 X-Patchwork-Delegate: a@unstable.cc Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from diktynna.open-mesh.org (localhost [IPv6:::1]) by diktynna.open-mesh.org (Postfix) with ESMTP id B321A83FFA for ; Sat, 16 Nov 2024 22:33:56 +0100 (CET) ARC-Seal: i=2; cv=pass; a=rsa-sha256; d=open-mesh.org; s=20121; t=1731792836; b=C4g3mBUxJitLGfkBznKRkjjia9Z/K23gkJ2f+4f01WWrGgIEfK0Uq/wsgmu1kyaKTiBKB QJEMaIi4mDL0xZpA5wrCVnlWK07zsczjlDEnskOFz22Nt/rQDIuFg9UMwRO3agWpwTqY+Z1 CW69tSb0TKrz/mNIv6mqsNaRKVljCeM= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1731792836; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=u6z1fpT89DJv+WCGgPTmM9WnXFPOlNs13l5DouQ0kuU=; b=iVoZhe4TVwqz2fEqxqUtSaQqhikHdjOu/TKObwZ/2fL8XmnEC2MTQdfp+5fpeQUOsGMFu mRg5sb1lWKQgRJoWBoiv3TXFg9ZfXYHYhYxGAw9NOzoFKQ6c8Xl8LRPewMsiCR4XmRzlxil Hp5qI32dZHGjk+j+eX1WDCAawmi55jE= ARC-Authentication-Results: i=2; open-mesh.org; dkim=fail header.d=smtpservice.net; arc=pass; dmarc=fail (Used From Domain Record) header.from=triplefau.lt policy.dmarc=quarantine Authentication-Results: open-mesh.org; dkim=fail header.d=smtpservice.net; arc=pass; dmarc=fail (Used From Domain Record) header.from=triplefau.lt policy.dmarc=quarantine Received: from e2i340.smtp2go.com (e2i340.smtp2go.com [103.2.141.84]) by diktynna.open-mesh.org (Postfix) with ESMTPS id 1CD8F832F6 for ; Sat, 16 Nov 2024 22:33:14 +0100 (CET) ARC-Seal: i=1; s=20121; d=open-mesh.org; t=1731792794; a=rsa-sha256; cv=none; b=CV3nHbY1+wVlxLb4st3aP9Dfz9v1ZZmaSiPpaQenAaCESjZzAwBLIp6CNhs5L/XtfgxwDQ HWHTDbV1/Jn1tqsr3eKXZMDcPZ4yt6S9XItWHMbO3firTLcfikaWDgUpSuuHuzQzpgT2rU dPsdh6qPL7vwve/SgJo7tvzALKTdUmM= ARC-Authentication-Results: i=1; diktynna.open-mesh.org; dkim=none ("invalid DKIM record") header.d=smtpservice.net header.s=maxzs0.a1-4.dyn header.b=rBGdXkwj; dkim=pass header.d=triplefau.lt header.s=s510616 header.b=gCRWhPWO; dmarc=pass (policy=quarantine) header.from=triplefau.lt; spf=pass (diktynna.open-mesh.org: domain of "bT.kfvp1xgkq78sa59=6m8m8heth3as=jzd7v3dv93fwy9@em510616.triplefau.lt" designates 103.2.141.84 as permitted sender) smtp.mailfrom="bT.kfvp1xgkq78sa59=6m8m8heth3as=jzd7v3dv93fwy9@em510616.triplefau.lt" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1731792794; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=u6z1fpT89DJv+WCGgPTmM9WnXFPOlNs13l5DouQ0kuU=; b=G9mfFn66IR+HSs6WatH7FlwHQ2Ozk0aVUjf2SNhWSTZ525IjBXHRX866ztyGkq1vwsG+Aw CG9qq611KZF0A7Ad1KKVySeI0YphojeHP2tqRBjRlilOe3sN4xaPBgVZOypwhTe1xJTqzs ivNOaNIyOAu36BCC6jiEZMuodWvdeC8= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=maxzs0.a1-4.dyn; x=1731793694; h=Feedback-ID: X-Smtpcorp-Track:Message-Id:Date:Subject:To:From:Reply-To:Sender: List-Unsubscribe:List-Unsubscribe-Post; bh=u6z1fpT89DJv+WCGgPTmM9WnXFPOlNs13l5DouQ0kuU=; b=rBGdXkwj2BOisFMCmNIN3jsmSt sm+GyyQjnbfaHnB45sR/dn9ffNgDSbcZO32jzgfpgmGKZ9Z/fg1dCkcCJz1U3GnhkudhKyIcOyXMa McE/5lxMRSSrM0CoA4+g4AqBLYp5/ehXuFCW72J68sjfzLNH/J6xeI5f1Zrl/WvAP9tkgw6xlD737 bBTS1JSU2bD48GTKh96EEmRlN9HWvae/5u3WWTA+qtHaB14ITVkTnIzQ+JKZkepwtFg1dXzh57rC7 tVfKf+TH5gW4DrXrI5Thib94QbZYbm9bYKduFjGetEWcaP0p21iWzObfniV3ldkEU/K7mOMZvZo7S VA4CyuqA==; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=triplefau.lt; i=@triplefau.lt; q=dns/txt; s=s510616; t=1731792794; h=from : subject : to : message-id : date; bh=u6z1fpT89DJv+WCGgPTmM9WnXFPOlNs13l5DouQ0kuU=; b=gCRWhPWO0xPEJQGM4H2J1gBcoPbAllisczp+F2V2wEurgA5w6ZZJ30uhb9dHJAgRPQXZl R+TpjArmlY2XYzVOL0zfY1cnLzHrDPKd8AVYu/KkeBksQCIdGwgHwSpfFJtUB1BYDxLANxW eUf7MT0IPa2zbYQuIUhY0a1Yz8d2/LaYehULLO7+nYnP009wVnkgRLmoZyrLYTAR69aP7ue F51mH50Bkops1XY5yVTqWxfgAS1MqKFqjGm0wLXz7oNG0fsWiRusYItN/GEFLdItG1yd5o5 WcthIGcwmPnLwEM7RfKBiTv3gqPsokxEfV/sNModLb5pHe5YtgDZvoMHqYXg== Received: from [10.172.233.45] (helo=SmtpCorp) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2-S2G) (envelope-from ) id 1tCQPp-TRk3qi-89; Sat, 16 Nov 2024 21:33:13 +0000 Received: from [10.12.239.196] (helo=localhost) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.97.1-S2G) (envelope-from ) id 1tCQPo-AIkwcC8wlAQ-Kn3H; Sat, 16 Nov 2024 21:33:13 +0000 From: Remi Pommarel To: b.a.t.m.a.n@lists.open-mesh.org Cc: Marek Lindner , Simon Wunderlich , Antonio Quartulli , Sven Eckelmann , Remi Pommarel Subject: [PATCH v2 1/5] batman-adv: Do not send uninitialized TT changes Date: Sat, 16 Nov 2024 22:32:05 +0100 Message-Id: X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-Smtpcorp-Track: _af7wBTE6phH.pNPRTZ_-9sjr.NA2EGgiH_pD Feedback-ID: 510616m:510616apGKSTK:510616sEBlNEGTBc X-Report-Abuse: Please forward a copy of this message, including all headers, to Message-ID-Hash: HRBXBSOEG2CS2GIF6GWRLRFMS53TIYHW X-Message-ID-Hash: HRBXBSOEG2CS2GIF6GWRLRFMS53TIYHW X-MailFrom: bT.kfvp1xgkq78sa59=6m8m8heth3as=jzd7v3dv93fwy9@em510616.triplefau.lt X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-b.a.t.m.a.n.lists.open-mesh.org-0; header-match-b.a.t.m.a.n.lists.open-mesh.org-1; header-match-b.a.t.m.a.n.lists.open-mesh.org-2; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The number of TT changes can be less than initially expected in batadv_tt_tvlv_container_update() (changes can be removed by batadv_tt_local_event() in ADD+DEL sequence between reading tt_diff_entries_num and actually iterating the change list under lock). Thus tt_diff_len could be bigger than the actual changes size that need to be sent. Because batadv_send_my_tt_response sends the whole packet, uninitialized data can be interpreted as TT changes on other nodes leading to weird TT global entries on those nodes such as: * 00:00:00:00:00:00 -1 [....] ( 0) 88:12:4e:ad:7e:ba (179) (0x45845380) * 00:00:00:00:78:79 4092 [.W..] ( 0) 88:12:4e:ad:7e:3c (145) (0x8ebadb8b) All of the above also applies to OGM tvlv container buffer's tvlv_len. Remove the extra allocated space to avoid sending uninitialized TT changes in batadv_send_my_tt_response() and batadv_v_ogm_send_softif(). Fixes: e1bf0c14096f ("batman-adv: tvlv - convert tt data sent within OGMs") Signed-off-by: Remi Pommarel --- net/batman-adv/translation-table.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 2243cec18ecc..f0590f9bc2b1 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -990,6 +990,7 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv) int tt_diff_len, tt_change_len = 0; int tt_diff_entries_num = 0; int tt_diff_entries_count = 0; + size_t tt_extra_len = 0; u16 tvlv_len; tt_diff_entries_num = atomic_read(&bat_priv->tt.local_changes); @@ -1027,6 +1028,9 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv) } spin_unlock_bh(&bat_priv->tt.changes_list_lock); + tt_extra_len = batadv_tt_len(tt_diff_entries_num - + tt_diff_entries_count); + /* Keep the buffer for possible tt_request */ spin_lock_bh(&bat_priv->tt.last_changeset_lock); kfree(bat_priv->tt.last_changeset); @@ -1035,6 +1039,7 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv) tt_change_len = batadv_tt_len(tt_diff_entries_count); /* check whether this new OGM has no changes due to size problems */ if (tt_diff_entries_count > 0) { + tt_diff_len -= tt_extra_len; /* if kmalloc() fails we will reply with the full table * instead of providing the diff */ @@ -1047,6 +1052,8 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv) } spin_unlock_bh(&bat_priv->tt.last_changeset_lock); + /* Remove extra packet space for OGM */ + tvlv_len -= tt_extra_len; container_register: batadv_tvlv_container_register(bat_priv, BATADV_TVLV_TT, 1, tt_data, tvlv_len); From patchwork Sat Nov 16 21:32:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Remi Pommarel X-Patchwork-Id: 18686 X-Patchwork-Delegate: a@unstable.cc Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from diktynna.open-mesh.org (localhost [IPv6:::1]) by diktynna.open-mesh.org (Postfix) with ESMTP id 892FE83F62 for ; Sat, 16 Nov 2024 22:35:21 +0100 (CET) ARC-Seal: i=2; cv=pass; a=rsa-sha256; d=open-mesh.org; s=20121; t=1731792921; b=ZjWLAzYi/YSE2iLprIUUaCX39LGda1CQ+M9nZfAAsHlmAk9OGaGidZuIO+GVw2MhmydtG 7tbSO00GWs7tBdMB8n0obcG9hUr4yvceatWeS5fFQqxn3JdJgKaDenGwefkrNj0wz07A5/g dV8WJyXs1J0g+ZrShkbgN+G1uujnAPk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1731792921; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=uuDta22mMh3/kW6qGm+GdNvL9ScEBCVkLdZ9wYo6+Fg=; b=XOX5QUDhS/bN4DxUjbNSv3vRiUoh2SjuFA2O4/fzJS3YLmtNxYYG/sybLqw84l7fAPgk0 BXBzp0Idi5xbB+/P/Q9chH3nvQb3iwyGlyKPW0lOXro3fOEFVSVFgnhXX9H2gh200oDC5JT ZMbUkxJB9GHhTjyHRYBwpSHXCK/+OtM= ARC-Authentication-Results: i=2; open-mesh.org; dkim=fail header.d=smtpservice.net; arc=pass; dmarc=fail (Used From Domain Record) header.from=triplefau.lt policy.dmarc=quarantine Authentication-Results: open-mesh.org; dkim=fail header.d=smtpservice.net; arc=pass; dmarc=fail (Used From Domain Record) header.from=triplefau.lt policy.dmarc=quarantine Received: from e2i340.smtp2go.com (e2i340.smtp2go.com [103.2.141.84]) by diktynna.open-mesh.org (Postfix) with ESMTPS id CB39283597 for ; Sat, 16 Nov 2024 22:33:14 +0100 (CET) ARC-Seal: i=1; s=20121; d=open-mesh.org; t=1731792795; a=rsa-sha256; cv=none; b=hKmTpo/bEYK+29ftKaDqz7xoPYz0mWSFBvhcdM+Ui1U7OFtsiwKMF5c27cLz0QHmmzV4lE 9UONUrJdk+C3heVlZuKRpKIjfF57DHyYxJ7J2+j4AmZPc/GT8+im2XpLQvVtveWk/BQKpk xg1bH9/6f1pzxFiqqzsfha7GS43wIRE= ARC-Authentication-Results: i=1; diktynna.open-mesh.org; dkim=none ("invalid DKIM record") header.d=smtpservice.net header.s=maxzs0.a1-4.dyn header.b=wRrwTKAr; dkim=pass header.d=triplefau.lt header.s=s510616 header.b=K4ypuHhH; dmarc=pass (policy=quarantine) header.from=triplefau.lt; spf=pass (diktynna.open-mesh.org: domain of "bT.4rsol2zghb5jkt7=9bnqja2rk49o=55h8uyuxhbcnar@em510616.triplefau.lt" designates 103.2.141.84 as permitted sender) smtp.mailfrom="bT.4rsol2zghb5jkt7=9bnqja2rk49o=55h8uyuxhbcnar@em510616.triplefau.lt" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1731792795; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=uuDta22mMh3/kW6qGm+GdNvL9ScEBCVkLdZ9wYo6+Fg=; b=uecU6QR8gug20tqbprwaejCUgbW9Nplnel/e+Uc+RDikLr0YklBe6LUok+610wJiOcl1at 439bpDZtJP9m0GlxxReJCj6tu39MesBvJEUm9/2XkXWBSYCNc5hDkWMm8eCvwqIY+O6tM2 MtanwLEM8RjKDKqlrZINPvvBbUFPHlo= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=maxzs0.a1-4.dyn; x=1731793694; h=Feedback-ID: X-Smtpcorp-Track:Message-Id:Date:Subject:To:From:Reply-To:Sender: List-Unsubscribe:List-Unsubscribe-Post; bh=uuDta22mMh3/kW6qGm+GdNvL9ScEBCVkLdZ9wYo6+Fg=; b=wRrwTKArRcGhrfeqh3VyELrUyw ZUfkiqsQozn6vlAM4JyglSGT8nbVv+Rs8QpBrCZWvJ5KS4sLVu91hfZnvX+7uIuL3xMmKginn2v2d /nFDB9STyhbbyyVoOZbIrF23hBohs9YS+ymXDgQM5xzluWqrzfzaksebeCy7xMPQm+E1dDuYDAnmt 6KjraBvk+wnJMBNXTCebl8qzZ4iOfqndqYt8rXgwQOBi0xs5DsflENZJ5zc1ZK2AGEh50MtJNk4b4 iK7Rx4Y4uujAnJbh7uJyV5tCdkngfuYQzscLZQNCYzJWn3MwbFk8E+KXd5dMxDkcsXrM7jjD30e3p v/RImzlg==; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=triplefau.lt; i=@triplefau.lt; q=dns/txt; s=s510616; t=1731792794; h=from : subject : to : message-id : date; bh=uuDta22mMh3/kW6qGm+GdNvL9ScEBCVkLdZ9wYo6+Fg=; b=K4ypuHhHl+AH7gLrPwNEKK29L6aFxgA36yI7PBgJd6i3cnCWE+yqGa1bmhljpS7sfw/XD QIjthA51jSutE9xHiee/C3YuDtzrHAZgceeNPgF3BxDjg5/RRTmUBGgyXo//Kfjy+fcf0CG BZLI3RMnx/aaA3VOv93nYAvLPSkqEHRQ1yGj92onmsL1aStaz3w6jToWI2vsPm7DzmekZbl AOYdeQTF9li6KDoAbFl2ur04GcAlw2qfH0JJLW/7GKUUQQb2izCFwe1Cv8ayx4hW9ALj3in JRXa/X+YR8bjAY/5NWs8pWnDquCdjr5kKI1vLTbjEKmXejLa8YbZTi8r1tRA== Received: from [10.172.233.58] (helo=SmtpCorp) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2-S2G) (envelope-from ) id 1tCQPp-TRk3uC-UL; Sat, 16 Nov 2024 21:33:13 +0000 Received: from [10.12.239.196] (helo=localhost) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.97.1-S2G) (envelope-from ) id 1tCQPp-FnQW0hPpSTZ-mYjE; Sat, 16 Nov 2024 21:33:13 +0000 From: Remi Pommarel To: b.a.t.m.a.n@lists.open-mesh.org Cc: Marek Lindner , Simon Wunderlich , Antonio Quartulli , Sven Eckelmann , Remi Pommarel Subject: [PATCH v2 2/5] batman-adv: Remove uninitialized data in full table TT response Date: Sat, 16 Nov 2024 22:32:06 +0100 Message-Id: <0368cc2fc6c7719a40a52eeab3c1c6458fc3ebe4.1731792497.git.repk@triplefau.lt> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-Smtpcorp-Track: sMxJmqXPIHTn.G2UHnx8ot6Ja.efTBFAhwJui Feedback-ID: 510616m:510616apGKSTK:510616sNo-S-f3w4 X-Report-Abuse: Please forward a copy of this message, including all headers, to Message-ID-Hash: BQ3QKOF6PW6MT47EM6O2WHTRSK2CXEQT X-Message-ID-Hash: BQ3QKOF6PW6MT47EM6O2WHTRSK2CXEQT X-MailFrom: bT.4rsol2zghb5jkt7=9bnqja2rk49o=55h8uyuxhbcnar@em510616.triplefau.lt X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-b.a.t.m.a.n.lists.open-mesh.org-0; header-match-b.a.t.m.a.n.lists.open-mesh.org-1; header-match-b.a.t.m.a.n.lists.open-mesh.org-2; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The number of entries filled by batadv_tt_tvlv_generate() can be less than initially expected in batadv_tt_prepare_tvlv_{global,local}_data() (changes can be removed by batadv_tt_local_event() in ADD+DEL sequence in the meantime as the lock held during the whole tvlv global/local data generation). Thus tvlv_len could be bigger than the actual TT entry size that need to be sent so full table TT_RESPONSE could hold invalid TT entries such as below. * 00:00:00:00:00:00 -1 [....] ( 0) 88:12:4e:ad:7e:ba (179) (0x45845380) * 00:00:00:00:78:79 4092 [.W..] ( 0) 88:12:4e:ad:7e:3c (145) (0x8ebadb8b) Remove the extra allocated space to avoid sending uninitialized entries for full table TT_RESPONSE in both batadv_send_other_tt_response() and batadv_send_my_tt_response(). Fixes: 7ea7b4a14275 ("batman-adv: make the TT CRC logic VLAN specific") Signed-off-by: Remi Pommarel --- net/batman-adv/translation-table.c | 37 ++++++++++++++++++------------ 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index f0590f9bc2b1..bbab7491c83f 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -2754,14 +2754,16 @@ static bool batadv_tt_global_valid(const void *entry_ptr, * * Fills the tvlv buff with the tt entries from the specified hash. If valid_cb * is not provided then this becomes a no-op. + * + * Return: Remaining unused length in tvlv_buff. */ -static void batadv_tt_tvlv_generate(struct batadv_priv *bat_priv, - struct batadv_hashtable *hash, - void *tvlv_buff, u16 tt_len, - bool (*valid_cb)(const void *, - const void *, - u8 *flags), - void *cb_data) +static u16 batadv_tt_tvlv_generate(struct batadv_priv *bat_priv, + struct batadv_hashtable *hash, + void *tvlv_buff, u16 tt_len, + bool (*valid_cb)(const void *, + const void *, + u8 *flags), + void *cb_data) { struct batadv_tt_common_entry *tt_common_entry; struct batadv_tvlv_tt_change *tt_change; @@ -2775,7 +2777,7 @@ static void batadv_tt_tvlv_generate(struct batadv_priv *bat_priv, tt_change = tvlv_buff; if (!valid_cb) - return; + return tt_len; rcu_read_lock(); for (i = 0; i < hash->size; i++) { @@ -2801,6 +2803,8 @@ static void batadv_tt_tvlv_generate(struct batadv_priv *bat_priv, } } rcu_read_unlock(); + + return batadv_tt_len(tt_tot - tt_num_entries); } /** @@ -3076,10 +3080,11 @@ static bool batadv_send_other_tt_response(struct batadv_priv *bat_priv, goto out; /* fill the rest of the tvlv with the real TT entries */ - batadv_tt_tvlv_generate(bat_priv, bat_priv->tt.global_hash, - tt_change, tt_len, - batadv_tt_global_valid, - req_dst_orig_node); + tvlv_len -= batadv_tt_tvlv_generate(bat_priv, + bat_priv->tt.global_hash, + tt_change, tt_len, + batadv_tt_global_valid, + req_dst_orig_node); } /* Don't send the response, if larger than fragmented packet. */ @@ -3203,9 +3208,11 @@ static bool batadv_send_my_tt_response(struct batadv_priv *bat_priv, goto out; /* fill the rest of the tvlv with the real TT entries */ - batadv_tt_tvlv_generate(bat_priv, bat_priv->tt.local_hash, - tt_change, tt_len, - batadv_tt_local_valid, NULL); + tvlv_len -= batadv_tt_tvlv_generate(bat_priv, + bat_priv->tt.local_hash, + tt_change, tt_len, + batadv_tt_local_valid, + NULL); } tvlv_tt_data->flags = BATADV_TT_RESPONSE; From patchwork Sat Nov 16 21:32:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Remi Pommarel X-Patchwork-Id: 18687 X-Patchwork-Delegate: a@unstable.cc Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from diktynna.open-mesh.org (localhost [IPv6:::1]) by diktynna.open-mesh.org (Postfix) with ESMTP id 2BF54840C5 for ; Sat, 16 Nov 2024 22:36:02 +0100 (CET) ARC-Seal: i=2; cv=pass; a=rsa-sha256; d=open-mesh.org; s=20121; t=1731792962; b=SKzaGhBma3Tw0Oe7vP+rLUVVVDKlkFoLkaHha4aNQ3Fn+UgazwNf9doLAyuaZ1KtvagnC K4i9skhkdEj731wzKu/CvdsrEDQ1hx/h6Q0C8tsRL9hL602u7a56NnYtTdt4cW+gdJZYxBn Y/0vz+lOJeti6PQYuJUIL5kADSK2jR4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1731792962; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=lWhkZCCzgCW8vCWkau0Ze+ipuBdeEi5EAc9P8Jy3LjA=; b=c0IRSyAMFxBVkNtgxoLv+77Qdpuj//ow79bKJulUbaJpGr0NCUwnCVscj+jXFHIyovgOm CG/7719tDM0ZrKQ3DUIaHEoQRy7s4lYn4c8NYe+XE0JenHmMviXOYpG8Agipq4642EPPvqy WHiR/SnTSLEsIULQCP+v3IhGnhdFGbo= ARC-Authentication-Results: i=2; open-mesh.org; dkim=fail header.d=smtpservice.net; arc=pass; dmarc=fail (Used From Domain Record) header.from=triplefau.lt policy.dmarc=quarantine Authentication-Results: open-mesh.org; dkim=fail header.d=smtpservice.net; arc=pass; dmarc=fail (Used From Domain Record) header.from=triplefau.lt policy.dmarc=quarantine Received: from e2i340.smtp2go.com (e2i340.smtp2go.com [103.2.141.84]) by diktynna.open-mesh.org (Postfix) with ESMTPS id EBE7A80F41 for ; Sat, 16 Nov 2024 22:33:16 +0100 (CET) ARC-Seal: i=1; s=20121; d=open-mesh.org; t=1731792797; a=rsa-sha256; cv=none; b=ERWcKvhmJHkABQ8pk5NsF1glC3/7OtohoB7N3CYM/Tx32OZQ4glUZDCYG1M/6vwe141sYV QrM46cfYMehkc81k8M0T8w80wHAzBWxg3G/RRNtVIxruBee4HRkSzE/i3FF6lqV/1nwNUV 696bUEXnHQ6wyCQy7FFwfyt9KgFrXHY= ARC-Authentication-Results: i=1; diktynna.open-mesh.org; dkim=none ("invalid DKIM record") header.d=smtpservice.net header.s=maxzs0.a1-4.dyn header.b="c/sA65pO"; dkim=pass header.d=triplefau.lt header.s=s510616 header.b=QE1qnxqG; dmarc=pass (policy=quarantine) header.from=triplefau.lt; spf=pass (diktynna.open-mesh.org: domain of "bT.4zwizspkw2x2694=d87ik7vd36cn=6ups2e7b2wyl8i@em510616.triplefau.lt" designates 103.2.141.84 as permitted sender) smtp.mailfrom="bT.4zwizspkw2x2694=d87ik7vd36cn=6ups2e7b2wyl8i@em510616.triplefau.lt" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1731792797; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lWhkZCCzgCW8vCWkau0Ze+ipuBdeEi5EAc9P8Jy3LjA=; b=NcIfQ0jzaph43jyTmKzGbzsPEYOyuw9weOJTL+P/1a5Beb1foG8AfxGo/ggjwYeEsBh2qw lyKFUm3Tlomu/iTR4L81Dl1v6Y5UqtY3t8ffPTQyAt0a5WjyhVN0QQ2GT6Hb4yuaozCcB0 mzB+3/9EaOx0jhg1Z2DWxbANfszWIuQ= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=maxzs0.a1-4.dyn; x=1731793696; h=Feedback-ID: X-Smtpcorp-Track:Message-Id:Date:Subject:To:From:Reply-To:Sender: List-Unsubscribe:List-Unsubscribe-Post; bh=lWhkZCCzgCW8vCWkau0Ze+ipuBdeEi5EAc9P8Jy3LjA=; b=c/sA65pObbzsvEQ8oJYRBaNAt8 ID8DY3apwBjuAtOkQ/beO6kktGbLEVPkB9my8f74HllaeDc8qpmu7aHRMNkrVc3cio+P/ymXkVezS RuTEN9z4Uh6OPPjByHkCnjxSyGpUn0j7H74kdSnkk7YqAuw5bVsXrtwL3ra5qXHBy59FQVjgFhJU7 /ClGzdIJbb2a1bzeMAFwMieoyZtOv7IHm60OzBaEitUknBXhZjNLxMhBWh31c/EK8HJZizSt0Wu8+ ss+MAUi8+ma0P1AhmFtL/H9KUlIDWRKY8eHL0ES94tAALgtjO3aApSP4AzZueddDaUZOkK8DejJZL whPju6Mg==; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=triplefau.lt; i=@triplefau.lt; q=dns/txt; s=s510616; t=1731792796; h=from : subject : to : message-id : date; bh=lWhkZCCzgCW8vCWkau0Ze+ipuBdeEi5EAc9P8Jy3LjA=; b=QE1qnxqGpU0bEcIp+SkL6VH8VeAUorUnruHJNW4hEqPWG50qziUBArxJjO89FMaRw/yeh aFqxxI5ol+yVUdze7vNp1+MBiRG5M1n6MvTILL86Xr6b1qqDySzOO+SGOHdWonOfzFs9qcq 9G2sgUMIILSva7/XQnzeojv4jHGiQFz4eu9S63zwxrTANhtNfzTadhIeGMfsYbX3bd8I6UO HoIVa4hQCkZorSpbzcQnHS9xuNWmHbCjEPiKpR4l0Ln5heP9XQZAPTnv5q4mdzVGgCuRCrA jBDQI4yL2OMd3BLcGC6YFvPLiJ9IZIiQaEOSnqAil9CBtaSsgWXvyvn8Dt5A== Received: from [10.176.58.103] (helo=SmtpCorp) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2-S2G) (envelope-from ) id 1tCQPr-TRk499-Rl; Sat, 16 Nov 2024 21:33:15 +0000 Received: from [10.12.239.196] (helo=localhost) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.97.1-S2G) (envelope-from ) id 1tCQPr-4o5NDgrpLKg-pyD7; Sat, 16 Nov 2024 21:33:15 +0000 From: Remi Pommarel To: b.a.t.m.a.n@lists.open-mesh.org Cc: Marek Lindner , Simon Wunderlich , Antonio Quartulli , Sven Eckelmann , Remi Pommarel Subject: [PATCH v2 3/5] batman-adv: Do not let TT changes list grows indefinitely Date: Sat, 16 Nov 2024 22:32:07 +0100 Message-Id: <2edb71795ee8c18b4275925b4fd338dea1ad5957.1731792497.git.repk@triplefau.lt> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-Smtpcorp-Track: TaU5i3oi_-gv.qMdR2ycCohPx.se1qZgi7Bi- Feedback-ID: 510616m:510616apGKSTK:510616s-XLYWOQlo X-Report-Abuse: Please forward a copy of this message, including all headers, to Message-ID-Hash: HBZVE2MSWEWEW2R4O3AVLWS2DEADMNTG X-Message-ID-Hash: HBZVE2MSWEWEW2R4O3AVLWS2DEADMNTG X-MailFrom: bT.4zwizspkw2x2694=d87ik7vd36cn=6ups2e7b2wyl8i@em510616.triplefau.lt X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-b.a.t.m.a.n.lists.open-mesh.org-0; header-match-b.a.t.m.a.n.lists.open-mesh.org-1; header-match-b.a.t.m.a.n.lists.open-mesh.org-2; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: When TT changes list is too big to fit in packet due to MTU size, an empty OGM is sent expected other node to send TT request to get the changes. The issue is that tt.last_changeset was not built thus the originator was responding with previous changes to those TT requests (see batadv_send_my_tt_response). Also the changes list was never cleaned up effectively never ending growing from this point onwards, repeatedly sending the same TT response changes over and over, and a creatind a new empty OGM every OGM interval expecting for the local changes to be purged. When there is more TT changes that can fit in packet, drop all changes, send emtpy OGM and wait for TT request so we can respond with a full table instead. Fixes: e1bf0c14096f ("batman-adv: tvlv - convert tt data sent within OGMs") Signed-off-by: Remi Pommarel --- net/batman-adv/translation-table.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index bbab7491c83f..d7b43868b624 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -990,6 +990,7 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv) int tt_diff_len, tt_change_len = 0; int tt_diff_entries_num = 0; int tt_diff_entries_count = 0; + bool drop_changes = false; size_t tt_extra_len = 0; u16 tvlv_len; @@ -997,21 +998,29 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv) tt_diff_len = batadv_tt_len(tt_diff_entries_num); /* if we have too many changes for one packet don't send any - * and wait for the tt table request which will be fragmented + * and wait for the tt table request so we can reply with the full + * table. + * + * The local change history should still be cleaned up or it will only + * grow from this point onwards. Also tt.last_changeset should be set + * to NULL so tt response could send the full table instead of diff. */ - if (tt_diff_len > bat_priv->soft_iface->mtu) + if (tt_diff_len > bat_priv->soft_iface->mtu) { tt_diff_len = 0; + tt_diff_entries_num = 0; + drop_changes = true; + } tvlv_len = batadv_tt_prepare_tvlv_local_data(bat_priv, &tt_data, &tt_change, &tt_diff_len); if (!tvlv_len) return; - tt_data->flags = BATADV_TT_OGM_DIFF; - - if (tt_diff_len == 0) + if (!drop_changes && tt_diff_len == 0) goto container_register; + tt_data->flags = BATADV_TT_OGM_DIFF; + spin_lock_bh(&bat_priv->tt.changes_list_lock); atomic_set(&bat_priv->tt.local_changes, 0); From patchwork Sat Nov 16 21:32:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Remi Pommarel X-Patchwork-Id: 18688 X-Patchwork-Delegate: a@unstable.cc Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from diktynna.open-mesh.org (localhost [IPv6:::1]) by diktynna.open-mesh.org (Postfix) with ESMTP id 1FE1584216 for ; Sat, 16 Nov 2024 22:36:59 +0100 (CET) ARC-Seal: i=2; cv=pass; a=rsa-sha256; d=open-mesh.org; s=20121; t=1731793019; b=pVotNxBnly3CtzUCGjILUPJm6xacKM57LZ5iXKF7jms7zru/W0FgBgQ0KGDLFx0DYp61I llCENXGh1syDE/kyQCrGjZUbSXHxo7EXTrsmAaVpHl255TJz9tJXlsc4SKcsSEgSzxs17HZ 2Kr/nuPXA6AjlYmdeWDMLahD0vGB97A= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1731793019; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=gRGXQPdTIGAlAMk6aVpuKgOTm6JMFCt3/6wY+EdOiVE=; b=g/PE08K9UKxJef/1X4O38zsaZ4icJCdtf58CaZVFH2b2kUp6CP6SHDr73sdvpMx1HZHpP 8clcv5kY2tXgplCK9x2ljSbGWr76pJeVrGPQ0Zn/spgA7B6WE7q2S3buEOxjugMOpZn+3aD JJs2iGfamWoOnWsfp+UoPcFFecfR9mo= ARC-Authentication-Results: i=2; open-mesh.org; dkim=fail header.d=smtpservice.net; arc=pass; dmarc=fail (Used From Domain Record) header.from=triplefau.lt policy.dmarc=quarantine Authentication-Results: open-mesh.org; dkim=fail header.d=smtpservice.net; arc=pass; dmarc=fail (Used From Domain Record) header.from=triplefau.lt policy.dmarc=quarantine Received: from e2i340.smtp2go.com (e2i340.smtp2go.com [103.2.141.84]) by diktynna.open-mesh.org (Postfix) with ESMTPS id 493F181CAE for ; Sat, 16 Nov 2024 22:33:18 +0100 (CET) ARC-Seal: i=1; s=20121; d=open-mesh.org; t=1731792798; a=rsa-sha256; cv=none; b=k8yp1aFoo7xkqQUqxln/I03vBSPnL2JPstOCeIq/6lcilQ4D/QIm4K1mF4BsN0QwOvFe8j ZOw4VsE+SUp2l+Oyo0FazpsqsifAx+bf2G3jVfBiRBN4Gzvl+iE1SbhofV3aIIKuJbDLr+ oDj932MoXsTuFTB0ZUNbqfao7k00WiA= ARC-Authentication-Results: i=1; diktynna.open-mesh.org; dkim=none ("invalid DKIM record") header.d=smtpservice.net header.s=maxzs0.a1-4.dyn header.b=ORaGa9Yl; dkim=pass header.d=triplefau.lt header.s=s510616 header.b=Rt7ST4BK; dmarc=pass (policy=quarantine) header.from=triplefau.lt; spf=pass (diktynna.open-mesh.org: domain of "bT.qvlkah60p9n7uf7=50cqxgof8a9n=7aqioyfw1y2pvz@em510616.triplefau.lt" designates 103.2.141.84 as permitted sender) smtp.mailfrom="bT.qvlkah60p9n7uf7=50cqxgof8a9n=7aqioyfw1y2pvz@em510616.triplefau.lt" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1731792798; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gRGXQPdTIGAlAMk6aVpuKgOTm6JMFCt3/6wY+EdOiVE=; b=zkarXQbbKLBtn5PF9Tjv6eEfzKDPGXFgs5Dgds1qXWbgdPitQUBUvs0Y1aVHie6GcV6+Fe kNOXJidyuHZMluGge3ihuTddMigW+Bja+kzKR0PAj7VesCUObsRZHCDtBk6XK/ceqt6ttB 6xaB0r9Zb7CBAEeD1rOwfTzyYPI3/f8= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=maxzs0.a1-4.dyn; x=1731793698; h=Feedback-ID: X-Smtpcorp-Track:Message-Id:Date:Subject:To:From:Reply-To:Sender: List-Unsubscribe:List-Unsubscribe-Post; bh=gRGXQPdTIGAlAMk6aVpuKgOTm6JMFCt3/6wY+EdOiVE=; b=ORaGa9Yll5L/OXT0ZEJ8jGAtRT y1+aD4OvVoMmUQoSJ3WVD4OdaApOnOFfIz34ysAF7EljMxPlkvSveESeznaorqMuvN9QOCnVg+WhP mQc+Wgp86QXmKgkXQ/DV5ZJflksFAYLkdqFEr1F7rFVeaRuECgSCr4+Vy5KpFHfpQ9tiQ2NwoIOtM xIkbSe/GYT4+30hte/pqi8516GMkVSbA7COuOPI1qoQz9UzLOGd2pBQwIU4CZIezf184XJf3zHDcY rx9UgMCfORDi+kEIKr3SnBjyHGfUfuBOlzZkI3Ob58glTS0dugsj13M6Wb12uimOacYg7loV9AjXR n42kneTw==; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=triplefau.lt; i=@triplefau.lt; q=dns/txt; s=s510616; t=1731792798; h=from : subject : to : message-id : date; bh=gRGXQPdTIGAlAMk6aVpuKgOTm6JMFCt3/6wY+EdOiVE=; b=Rt7ST4BKPfS/c/+hR4aAHtJUsf/s4k5ybWeWwuXOuhvU3c2iiol/zsJiV0GIC4+VWK60p 8ZnqSKAx1QKK++ADUwvh7Bzm2KR7jfYwtGYEJ9BPsAxevLSL6jpRmYafjOhRrsgv3y3NcBD Ndzyu8SKaXAJrQ8z8jVfa3KnU1IDDtg24CqGNTU29ry24riSbiZmZfXtg+RHw4qFF8K8jxL kXz7xy0lx6i7QmoJGiS2Xe65NJpef4M53s8aAKOTpY4JHxmo0HN1Ram6/CKNe8J/mO7PDHz JGBfcrOw/zmN+KEPW9ADqMnKwdDZyDLR58yNoaqMDhTk8BxOWW6HgNEZGq/A== Received: from [10.139.162.187] (helo=SmtpCorp) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2-S2G) (envelope-from ) id 1tCQPt-TRk4JG-G3; Sat, 16 Nov 2024 21:33:17 +0000 Received: from [10.12.239.196] (helo=localhost) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.97.1-S2G) (envelope-from ) id 1tCQPt-4o5NDgrnRnT-kQOb; Sat, 16 Nov 2024 21:33:17 +0000 From: Remi Pommarel To: b.a.t.m.a.n@lists.open-mesh.org Cc: Marek Lindner , Simon Wunderlich , Antonio Quartulli , Sven Eckelmann , Remi Pommarel Subject: [PATCH v2 4/5] batman-adv: Remove atomic usage for tt.local_changes Date: Sat, 16 Nov 2024 22:32:08 +0100 Message-Id: <15b37f540888d50f068da096e4f46be033394efe.1731792497.git.repk@triplefau.lt> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-Smtpcorp-Track: pjHTmeJgKlco.IgtiDssVValm.Y5zCewj8NbC Feedback-ID: 510616m:510616apGKSTK:510616sMK70FM1WB X-Report-Abuse: Please forward a copy of this message, including all headers, to Message-ID-Hash: Z6TGQTM4ULUIX53STNF474PMPIWLHENA X-Message-ID-Hash: Z6TGQTM4ULUIX53STNF474PMPIWLHENA X-MailFrom: bT.qvlkah60p9n7uf7=50cqxgof8a9n=7aqioyfw1y2pvz@em510616.triplefau.lt X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-b.a.t.m.a.n.lists.open-mesh.org-0; header-match-b.a.t.m.a.n.lists.open-mesh.org-1; header-match-b.a.t.m.a.n.lists.open-mesh.org-2; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The tt.local_changes atomic is either written with tt.changes_list_lock or close to it (see batadv_tt_local_event()). Thus the performance gain using an atomic was limited (or because of atomic_read() impact even negative). Using atomic also comes with the need to be wary of potential negative tt.local_changes value. Simplify the tt.local_changes usage by removing the atomic property and modifying it only with tt.changes_list_lock held. Signed-off-by: Remi Pommarel --- net/batman-adv/soft-interface.c | 2 +- net/batman-adv/translation-table.c | 17 ++++++----------- net/batman-adv/types.h | 4 ++-- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c index 2758aba47a2f..2575f13992d2 100644 --- a/net/batman-adv/soft-interface.c +++ b/net/batman-adv/soft-interface.c @@ -783,13 +783,13 @@ static int batadv_softif_init_late(struct net_device *dev) atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE); atomic_set(&bat_priv->bcast_seqno, 1); atomic_set(&bat_priv->tt.vn, 0); - atomic_set(&bat_priv->tt.local_changes, 0); atomic_set(&bat_priv->tt.ogm_append_cnt, 0); #ifdef CONFIG_BATMAN_ADV_BLA atomic_set(&bat_priv->bla.num_requests, 0); #endif atomic_set(&bat_priv->tp_num, 0); + bat_priv->tt.local_changes = 0; bat_priv->tt.last_changeset = NULL; bat_priv->tt.last_changeset_len = 0; bat_priv->isolation_mark = 0; diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index d7b43868b624..39704af81169 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -463,7 +463,6 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv, struct batadv_tt_change_node *tt_change_node, *entry, *safe; struct batadv_tt_common_entry *common = &tt_local_entry->common; u8 flags = common->flags | event_flags; - bool event_removed = false; bool del_op_requested, del_op_entry; tt_change_node = kmem_cache_alloc(batadv_tt_change_cache, GFP_ATOMIC); @@ -508,21 +507,17 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv, del: list_del(&entry->list); kmem_cache_free(batadv_tt_change_cache, entry); + bat_priv->tt.local_changes--; kmem_cache_free(batadv_tt_change_cache, tt_change_node); - event_removed = true; goto unlock; } /* track the change in the OGMinterval list */ list_add_tail(&tt_change_node->list, &bat_priv->tt.changes_list); + bat_priv->tt.local_changes++; unlock: spin_unlock_bh(&bat_priv->tt.changes_list_lock); - - if (event_removed) - atomic_dec(&bat_priv->tt.local_changes); - else - atomic_inc(&bat_priv->tt.local_changes); } /** @@ -994,7 +989,7 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv) size_t tt_extra_len = 0; u16 tvlv_len; - tt_diff_entries_num = atomic_read(&bat_priv->tt.local_changes); + tt_diff_entries_num = READ_ONCE(bat_priv->tt.local_changes); tt_diff_len = batadv_tt_len(tt_diff_entries_num); /* if we have too many changes for one packet don't send any @@ -1022,7 +1017,7 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv) tt_data->flags = BATADV_TT_OGM_DIFF; spin_lock_bh(&bat_priv->tt.changes_list_lock); - atomic_set(&bat_priv->tt.local_changes, 0); + bat_priv->tt.local_changes = 0; list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list, list) { @@ -1438,7 +1433,7 @@ static void batadv_tt_changes_list_free(struct batadv_priv *bat_priv) kmem_cache_free(batadv_tt_change_cache, entry); } - atomic_set(&bat_priv->tt.local_changes, 0); + bat_priv->tt.local_changes = 0; spin_unlock_bh(&bat_priv->tt.changes_list_lock); } @@ -3708,7 +3703,7 @@ static void batadv_tt_local_commit_changes_nolock(struct batadv_priv *bat_priv) { lockdep_assert_held(&bat_priv->tt.commit_lock); - if (atomic_read(&bat_priv->tt.local_changes) < 1) { + if (READ_ONCE(bat_priv->tt.local_changes) < 1) { if (!batadv_atomic_dec_not_zero(&bat_priv->tt.ogm_append_cnt)) batadv_tt_tvlv_container_update(bat_priv); return; diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h index 04f6398b3a40..f491bff8c51b 100644 --- a/net/batman-adv/types.h +++ b/net/batman-adv/types.h @@ -1022,7 +1022,7 @@ struct batadv_priv_tt { atomic_t ogm_append_cnt; /** @local_changes: changes registered in an originator interval */ - atomic_t local_changes; + size_t local_changes; /** * @changes_list: tracks tt local changes within an originator interval @@ -1044,7 +1044,7 @@ struct batadv_priv_tt { */ struct list_head roam_list; - /** @changes_list_lock: lock protecting changes_list */ + /** @changes_list_lock: lock protecting changes_list & local_changes */ spinlock_t changes_list_lock; /** @req_list_lock: lock protecting req_list */ From patchwork Sat Nov 16 21:32:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Remi Pommarel X-Patchwork-Id: 18689 X-Patchwork-Delegate: a@unstable.cc Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from diktynna.open-mesh.org (localhost [IPv6:::1]) by diktynna.open-mesh.org (Postfix) with ESMTP id 7AEB783FD8 for ; Sat, 16 Nov 2024 22:37:39 +0100 (CET) ARC-Seal: i=2; cv=pass; a=rsa-sha256; d=open-mesh.org; s=20121; t=1731793059; b=kzw9gwCDkDyjCrBqkkqZx7+Eo8p4y5lBLLa9EcHAmB9GKYfY86Wy7bCNvuQOX6l6pjZ4k 1aaSeg9Lux68qE9zQmUQu0zfcvuMG+Q1PtK62aFtNy9LN2A7WLMOq9p/ADIQCunOjA2Z8w2 r0oW1HHsux41X39isAvsm/lwVOxiGDU= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1731793059; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=43KYER6I8y6+KDVjhT8DcGdKRHWYM+yH2KqbvaTh15w=; b=R4KUi1gshmf8bQmWSmS6UBnKHosANx9DJkA4+OfyA52egneyUUKmOU/kfqgtHT6j3sbDA mlt6eqNrh8p6313n7xejbvSY05vo/yD9Vs3PxtbkWg8xmPFDPsyrdRLxCRl3MQlh7Qedd0r EQdD+sv56SvmqUZCX+RY+C44i7Ef7rE= ARC-Authentication-Results: i=2; open-mesh.org; dkim=fail header.d=smtpservice.net; arc=pass; dmarc=fail (Used From Domain Record) header.from=triplefau.lt policy.dmarc=quarantine Authentication-Results: open-mesh.org; dkim=fail header.d=smtpservice.net; arc=pass; dmarc=fail (Used From Domain Record) header.from=triplefau.lt policy.dmarc=quarantine Received: from e2i340.smtp2go.com (e2i340.smtp2go.com [103.2.141.84]) by diktynna.open-mesh.org (Postfix) with ESMTPS id A3D7C81CAE for ; Sat, 16 Nov 2024 22:33:18 +0100 (CET) ARC-Seal: i=1; s=20121; d=open-mesh.org; t=1731792798; a=rsa-sha256; cv=none; b=tnp1Tq0fxBRoUfDOVbGTJSCGDKQ2JPn2ozLCZSKG+/Wp1Doy5lBESPVwlIqeJy2paMfUeq CWYJIL2seyinykz883kTSRMJm6AZYd9Y94Radu5BjZMfMHNIwa7fPrdO36ABAvHYLjRph2 NIj1WmzjXSB5twRXUMHYvmGuoxhHEPw= ARC-Authentication-Results: i=1; diktynna.open-mesh.org; dkim=none ("invalid DKIM record") header.d=smtpservice.net header.s=maxzs0.a1-4.dyn header.b=Kep0kfeo; dkim=pass header.d=triplefau.lt header.s=s510616 header.b=m6Fx5uFf; dmarc=pass (policy=quarantine) header.from=triplefau.lt; spf=pass (diktynna.open-mesh.org: domain of "bT.44d0dmh5o4o6wf1=70vy3344f3mg=tzwf63jik5f86v@em510616.triplefau.lt" designates 103.2.141.84 as permitted sender) smtp.mailfrom="bT.44d0dmh5o4o6wf1=70vy3344f3mg=tzwf63jik5f86v@em510616.triplefau.lt" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1731792798; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=43KYER6I8y6+KDVjhT8DcGdKRHWYM+yH2KqbvaTh15w=; b=wzPKbCBknjEbFTbOXKLdKg4TxopYEZtksJk20QcIwcpTZiupmKUaT3lTf+99ATcXDbPEj4 YuvirRGuOnoSDuNPhycPtey0x3cfpliL5rgaG5DesL/n+24Xo0xO2o92cN25IQc3EYQwBM tNPbvnimY0RRjBKIfll9Cakm270WfPA= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=maxzs0.a1-4.dyn; x=1731793698; h=Feedback-ID: X-Smtpcorp-Track:Message-Id:Date:Subject:To:From:Reply-To:Sender: List-Unsubscribe:List-Unsubscribe-Post; bh=43KYER6I8y6+KDVjhT8DcGdKRHWYM+yH2KqbvaTh15w=; b=Kep0kfeoTktifyupMRdwsGi2ck XEym3oIzTdlqRkrkVOi9pmKe5HmUneMIo7LeKrXkG5fLD1gGGZu94zT1i1cOrCEsxfRmVjWaL9DLe EpidlkfaTxMSw9thxgx/QpmnpwqP+qUL0O6wQTdbu6yGYZz7FvKW+VVZTw1kgbWoxiTfYFRhQXhI3 HaDiIxDN1B13tO6Bb4B/0WQwFpODC+5kiWVA+LDq2V5z3Y1P8ty7htsfFWLdGDi2qZqQtxcmnuY0v 25VlGCLc2qqlgLM/al2CoATEJ0uNShylwJ8Rrb5H4qwpD+R+AR7+kG+kvfHOjlCxvCt7jNoJWdI+z b7QzQB1Q==; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=triplefau.lt; i=@triplefau.lt; q=dns/txt; s=s510616; t=1731792798; h=from : subject : to : message-id : date; bh=43KYER6I8y6+KDVjhT8DcGdKRHWYM+yH2KqbvaTh15w=; b=m6Fx5uFfBnbcUm6QQpLCAlnbyAlRxejujY3XuPC0TyrmCsVpO8SifROlknKVE3uuol9Gn KFVtO3/ljhgVd8GOFUXuDp8LjyNyJjBikYQRt/tR1tMww9FQN6tjgbwLdcCHbAI9CYGeak0 9636TtlvD0lE0wRyo09tkNtx5MKLICnG4i6LruLMI4w0t1b5q3oDdxqh7yWbb1AxWLkeN7G j+cfsL9nU2QBYD9WxGgl4q7JzNIoBJ9QXINl4+3iI0QHcZHHhLt61wKR4cUK7IdHfxhf7Bz c3HgW9DltUDZNoEH/GRSKVDK91X2+D9cAUNwR9kBgYPQ9UGQthgB6jfcOU4w== Received: from [10.172.233.45] (helo=SmtpCorp) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2-S2G) (envelope-from ) id 1tCQPt-TRk4No-O6; Sat, 16 Nov 2024 21:33:17 +0000 Received: from [10.12.239.196] (helo=localhost) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.97.1-S2G) (envelope-from ) id 1tCQPt-AIkwcC8wlDZ-If9i; Sat, 16 Nov 2024 21:33:17 +0000 From: Remi Pommarel To: b.a.t.m.a.n@lists.open-mesh.org Cc: Marek Lindner , Simon Wunderlich , Antonio Quartulli , Sven Eckelmann , Remi Pommarel Subject: [PATCH v2 5/5] batman-adv: Don't keep redundant TT change events Date: Sat, 16 Nov 2024 22:32:09 +0100 Message-Id: <1c8b34d63121834bdf6d39c7ed1447ae3536be7d.1731792497.git.repk@triplefau.lt> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-Smtpcorp-Track: A1B8Ibb72XZm.7RhoyLFUROi3.ZMViRglZKnq Feedback-ID: 510616m:510616apGKSTK:510616sgQ0CG08HI X-Report-Abuse: Please forward a copy of this message, including all headers, to Message-ID-Hash: QISVSSFCS5CZBYSIV5SYNOBSUM7ST257 X-Message-ID-Hash: QISVSSFCS5CZBYSIV5SYNOBSUM7ST257 X-MailFrom: bT.44d0dmh5o4o6wf1=70vy3344f3mg=tzwf63jik5f86v@em510616.triplefau.lt X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-b.a.t.m.a.n.lists.open-mesh.org-0; header-match-b.a.t.m.a.n.lists.open-mesh.org-1; header-match-b.a.t.m.a.n.lists.open-mesh.org-2; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: When adding a local TT twice within the same OGM interval (e.g. happens when flag get updated), the flags of the first TT change entry is updated with the second one and both change events is added to the change list. This leads to having the same ADD change entry twice. Similarly a DEL+DEL scenario is also creating twice the same event. Deduplicate ADD+ADD or DEL+DEL scenarios to reduce the TT change events that need to be sent in both OGM and TT response. Signed-off-by: Remi Pommarel --- net/batman-adv/translation-table.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 39704af81169..2e0e71845df1 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -500,14 +500,17 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv, /* this is a second add in the same originator interval. It * means that flags have been changed: update them! */ - if (!del_op_requested && !del_op_entry) + if (del_op_requested == del_op_entry) { entry->change.flags = flags; + goto discard; + } continue; del: list_del(&entry->list); kmem_cache_free(batadv_tt_change_cache, entry); bat_priv->tt.local_changes--; +discard: kmem_cache_free(batadv_tt_change_cache, tt_change_node); goto unlock; }