From patchwork Fri Nov 22 15:52:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Remi Pommarel X-Patchwork-Id: 18700 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 1F3B284379 for ; Fri, 22 Nov 2024 16:54:46 +0100 (CET) ARC-Seal: i=2; cv=pass; a=rsa-sha256; d=open-mesh.org; s=20121; t=1732290886; b=Uw5PfbRpVTcOxmnreV6AaDuZhtaVd2tzNMJSBwAMuv26/g2bjVXqPmfFjsddHD4wdYh/F gPGL+FuocuCpTmyLADbcNQnBVfFWjBzslxXog+gmLOL/wRPuO0xH9UpBlB7P1RlRwL6Q7to iTVReIfefs4q7OgY5maUdgR9u6cKJBc= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1732290886; 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=lzoMUguxkK3KwLUE14ItUYRdPS5CVeg3Mpae9z6tVbx3EU1p4gVrF/h49vqGnkkyEQ3N9 2Z1mncnVkJuepY32lK9O7EavTsoPFIyz6Nhu8XxCnLMNtXDifyfqX1cPD6Lpd9/DCqQzcnY k+02lwfFL6pnfwgydX3C5eOdI/0YN2E= 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 CA8B080B7C for ; Fri, 22 Nov 2024 16:54:07 +0100 (CET) ARC-Seal: i=1; s=20121; d=open-mesh.org; t=1732290848; a=rsa-sha256; cv=none; b=lZlv3vUb8+27XdOERqMcYcg3Tr0cwth4iW6Li6R2arnsPwB+6egRxbcMaITGThSae8GYCm B4vNDf9OmZx+rtALHouKoL+8qE3YJx8/zjafomMpUK8FzCYdsdK6zR06Xj8e7DkrFjjE1l z6/OGmCl5WlsIIZDVQFgptYnlprOvYo= 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=3Zn+JXDq; dkim=pass header.d=triplefau.lt header.s=s510616 header.b=MVq0SHct; dmarc=pass (policy=quarantine) header.from=triplefau.lt; spf=pass (diktynna.open-mesh.org: domain of "bT.e6gcrnuvgwovs78=tfmufzrtgp2z=24m8xplmfsxo2l@em510616.triplefau.lt" designates 103.2.141.84 as permitted sender) smtp.mailfrom="bT.e6gcrnuvgwovs78=tfmufzrtgp2z=24m8xplmfsxo2l@em510616.triplefau.lt" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1732290848; 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=woLPsxwynkWOCco0oTml/ZqiOaTFn8srZsgSvdnyp4YLE30Gz6b0J0IV90pcqfEY8Oefdn R8pyJFDlMrTXKi/s+C078dj5mHqDt7K9jLhAG81EVV6oFczDWeXb1pM2SBaoa+bMR7RW6E jIw3q96ab/dhSuhbAGtmwjxi5/vUAtY= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=maxzs0.a1-4.dyn; x=1732291747; h=Feedback-ID: X-Smtpcorp-Track:Message-Id:Date:Subject:To:From:Reply-To:Sender: List-Unsubscribe:List-Unsubscribe-Post; bh=u6z1fpT89DJv+WCGgPTmM9WnXFPOlNs13l5DouQ0kuU=; b=3Zn+JXDq3ZrcIL8LQ3p727vdLi w9ZK9C/bOVYw89q+Vsqk5Q2f70zWz6vq0p48kA0AJh2EmeJCQUzk3UiP984ooB0L8026EG5F2m0fa sBbYvJ8KMTnC487f2DDPbcBtzfIS2XXUJWA7pldTQ6OR5buKjCEigZNMmsWUDfBhSJ2aNlWBwosll YaTl5oz/dDoMRLRVyUGbO6YuG5BETENXUALFhct6apJ52rG6nurf7Pdd+I/N8C6s4jEHGVhKxKkQM rUXl1K719FDI6RAvDYcYbMcVGa5sWG5gal6cxXYFhSTaVOy09lxNxNu4Irgm59vSqcZU6HjNKKyoL qT2D71Pg==; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=triplefau.lt; i=@triplefau.lt; q=dns/txt; s=s510616; t=1732290847; h=from : subject : to : message-id : date; bh=u6z1fpT89DJv+WCGgPTmM9WnXFPOlNs13l5DouQ0kuU=; b=MVq0SHctM+NYfej2/Y32m6r/NTZM+AwnvCGWRLzgxXJ8sbclNY4EGk32zzkW7L4Myo16E U4iA+gy0WoHbIU2han09FQSbWp0PkgY5mHmcJxJ3PYjZprEiYcSoLRdl0WlhBGZZvxZUKfu 8smxJEsZqah8jJbIV0rTFkIl3vFCbnfieEHM97TOHEvBqO4vn56BfLXqTzSc2pXXiVjDavY DgEfW6hk94JkGgUMsGUngDRPUQ+x8PVAMOSRZpSelbwWLbt9pYgSpzy4mHTuPpIyWCvAMEC YSGpROKOrmAAy+iFi7WyrnFvT8cmH7HxTY4AztnPwVlELFk1jALxZwaWyqtg== 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 1tEVyw-TRjyoS-Tf; Fri, 22 Nov 2024 15:54:06 +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 1tEVyw-AIkwcC8lUBd-JEWP; Fri, 22 Nov 2024 15:54:06 +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 v4 1/5] batman-adv: Do not send uninitialized TT changes Date: Fri, 22 Nov 2024 16:52:48 +0100 Message-Id: X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-Smtpcorp-Track: v6nARUKQeY4U.SL1gheXEvxPa.fEvhEwRhkS8 Feedback-ID: 510616m:510616apGKSTK:510616ssI3AUS-ay X-Report-Abuse: Please forward a copy of this message, including all headers, to Message-ID-Hash: 2SYGETTUKYJGGKGYGDR2SYP6TSMXZSPV X-Message-ID-Hash: 2SYGETTUKYJGGKGYGDR2SYP6TSMXZSPV X-MailFrom: bT.e6gcrnuvgwovs78=tfmufzrtgp2z=24m8xplmfsxo2l@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 Fri Nov 22 15:52:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Remi Pommarel X-Patchwork-Id: 18701 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 078C583FD5 for ; Fri, 22 Nov 2024 16:55:18 +0100 (CET) ARC-Seal: i=2; cv=pass; a=rsa-sha256; d=open-mesh.org; s=20121; t=1732290918; b=hBcF6PDVVlrmOg91Rx11XipO0yqPH9XRJ6i9c7xBBo2vhzQjS2F19ogdI75F0/cjCAs6j pIfr2NH5GjCJSLQNe1gxZSA5B3/QbZ6gL3F7i+iQl1CdrEpDMWYbeQMsUx6Ox/q1sq5DIKC e5XCQq+YkZHhAPxbVqHnpGDQ/VCKdew= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1732290918; 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=QAkDNgOzmBr6/dYKllWByPvMwlG6nnpPwMoLn84Az9qz3PFJg+mUWee9QuONcAylSG4o9 swx0Qrsl7Z/hAs1X9QSfkrhoAMRXq9P59i67L+BEhrpGOizHlDQO4qVMfWkdxNrrw06qBE2 51YVLKtnLBdVPXnyvi9hHYuowJ7BJuI= 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 D892A8301D for ; Fri, 22 Nov 2024 16:54:07 +0100 (CET) ARC-Seal: i=1; s=20121; d=open-mesh.org; t=1732290848; a=rsa-sha256; cv=none; b=dCKQ454efN3id3DPWJx+zZvtVrtDx7ZWXoelYNJ6OZXr9EVQPMdMYHsThTVMondMihkGL9 vWUeNZM14ecmS0luagbpdE2tbJ4XMkCecdf1B9ONs4MWbPzl7lBzguArXYaUKIpTqcNwxH seHkHmBhH2nnTSrC4wil+lWjE09+Tpw= 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=s3bjKukP; dkim=pass header.d=triplefau.lt header.s=s510616 header.b=VTOFSOJe; dmarc=pass (policy=quarantine) header.from=triplefau.lt; spf=pass (diktynna.open-mesh.org: domain of "bT.nk18xu5086yedp2=tsiuojm8pex6=6td3kznilydl8p@em510616.triplefau.lt" designates 103.2.141.84 as permitted sender) smtp.mailfrom="bT.nk18xu5086yedp2=tsiuojm8pex6=6td3kznilydl8p@em510616.triplefau.lt" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1732290848; 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=A2McOsoa70POiMaai+Oe+4aq14HpcQc35W1AKjtOdPUmaTE6AcEl+7Mz6dyLQMxqpdgbxr BIr3SzQjhxKM26bnNCEhD5aKnm2LsJssLXJazHpS19yuGnL0uPEUz3/dClJqgzMPW4NQIC LiNcGD6RoVkAm38JjJKpIpDuwWQRkF0= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=maxzs0.a1-4.dyn; x=1732291747; 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=s3bjKukPuBybALikS4os3QFsP+ G44vuMIHtTAdSY8gJcWnalv22nUFew14u8ExjTuij2I1HpV2FBLVt8ZFyLgFM6oqK/x+c1XO0Qw3J 1HF+ILPQmoyCEyAB5oem7TDK9PWtH723QZJVIjxKU408m30iNF7RzjeTHuEdJRfIhCX2xJOFXon5R oRxgA0vzK07hqP6Zs9yykQdTh1Go8aPBKfZVv6vjNiG/5sBOofOb21ov+7L0aPi9dpx4bB4TTfmd7 8RZjU21TdnIsjuCmEofnA4W/zvhyVNNxQaQBjDQVJ4N+aTgLsaXoZQ8YRW/zL+pnTDWxCTRq253I0 nu3M5SYg==; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=triplefau.lt; i=@triplefau.lt; q=dns/txt; s=s510616; t=1732290847; h=from : subject : to : message-id : date; bh=uuDta22mMh3/kW6qGm+GdNvL9ScEBCVkLdZ9wYo6+Fg=; b=VTOFSOJe9wguW8glAFwJUgpQBH1Hj9GNbGPsxTIEwGF2toZ49XujKzWrgQbxOzcWGNrxu Kkgm1n0V6ZeBLVkLmYRpPMcYZHmPPyLXdTVLGR3/y5Y4RIaWMB5e7TGTL1FFtIS6YXHGlqD X6RrqX6tymHq4brX6uN7PoHD4bBWL6Asmd55wnjVWJMVqvXjqWLH7t1RlNtdtR46QgfnjoW KD9Ylmq2xj/1CUv1iEDdOzhg7vG11xp7kxlcd6/eNn+Nma25maoutlKnk3WjUKL/hQHzKFa 4JFEfejWi81SEtSz9RcvgKjCLhThbRatrhRNRRzOurDj5nhae21K2EJ+D66g== 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 1tEVyx-TRjyom-2h; Fri, 22 Nov 2024 15:54:07 +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 1tEVyw-4o5NDgrfRq0-neqn; Fri, 22 Nov 2024 15:54:06 +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 v4 2/5] batman-adv: Remove uninitialized data in full table TT response Date: Fri, 22 Nov 2024 16:52:49 +0100 Message-Id: <0368cc2fc6c7719a40a52eeab3c1c6458fc3ebe4.1732290614.git.repk@triplefau.lt> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-Smtpcorp-Track: Ip5HN1DntQjD.ZZ3cnI10zUaX.c9nKIQO_STC Feedback-ID: 510616m:510616apGKSTK:510616sEEkeO0hgn X-Report-Abuse: Please forward a copy of this message, including all headers, to Message-ID-Hash: TYXBNXGDTAQ7ODZPANNS4FKHLEMBZAYU X-Message-ID-Hash: TYXBNXGDTAQ7ODZPANNS4FKHLEMBZAYU X-MailFrom: bT.nk18xu5086yedp2=tsiuojm8pex6=6td3kznilydl8p@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 Fri Nov 22 15:52:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Remi Pommarel X-Patchwork-Id: 18702 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 D745A8449F for ; Fri, 22 Nov 2024 16:55:47 +0100 (CET) ARC-Seal: i=2; cv=pass; a=rsa-sha256; d=open-mesh.org; s=20121; t=1732290947; b=ZEvtYruW8Q9TbMhVBWMkBBzZqTuH2C5gtASpS4AH4BcamcPZleJfM1dd1vb5iOitwXYPi V84uh4+0/kxTypJNjrkQ+GKtLRchVQXebOEGG3koR2Uz1++cAo5LicI3Q1+BjVUKkfSDtve ilOiBfRzaqbScclx4d8sUL5u6ptNyM4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1732290947; 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=Lzx+Og/rywSv4YjLlWccBLHFqHV7fABbu3KjvJZBrrg=; b=cArIHrqCvtE/FnSy5Kg4yDPs+W/JHyHUF2jDp1asvbDjLcPJn2vkXQIcE5uoUQ4/P6F44 Qj14hLVVF/YNCNVyfNOXg2At+iEBqqQwdyrIFjUk3Pjb1f1cJUZXihc44MBCd75Wmy0E/0c VNmPghVS784jTecwTmyuB49TroF1+Po= 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 05A6783EC7 for ; Fri, 22 Nov 2024 16:54:10 +0100 (CET) ARC-Seal: i=1; s=20121; d=open-mesh.org; t=1732290850; a=rsa-sha256; cv=none; b=RlavAmWWOgE/cJHzaSNB/DnAjLrcf63zjJZU9Y+4jPrgW2rLIMDc2yOEzCnpq3fHsnKbmv d6CLc1MLnErcPZOLCB+0Pv7bsYvG64P9xhvCmLjvbswiAk0yaZOg05BYOSNVfRvO+C5Pr8 aqT4Z/Aqp9ogOo9c42dslnZKMBey9Xg= 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=mig1Qu4X; dkim=pass header.d=triplefau.lt header.s=s510616 header.b=jv1o1FgT; dmarc=pass (policy=quarantine) header.from=triplefau.lt; spf=pass (diktynna.open-mesh.org: domain of "bT.1pccv6nrmu5jcr2=sybys4a23vlz=627iqwx2bvyd2y@em510616.triplefau.lt" designates 103.2.141.84 as permitted sender) smtp.mailfrom="bT.1pccv6nrmu5jcr2=sybys4a23vlz=627iqwx2bvyd2y@em510616.triplefau.lt" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1732290850; 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=Lzx+Og/rywSv4YjLlWccBLHFqHV7fABbu3KjvJZBrrg=; b=NmChfSDkJLRaGLFmXvDYtunMdizIgRzSOsquGsy3LkI6JxJcOk/hZi4VGWjDzDiwX2cyp4 5OcSsmMKJ4Aka1OQito2iTJjIB2hKl+4R7iuYA5nvcwwn5yceggAkH2HiYnhGw2M5/lCLA CsuJPGE1reJeKsNrua4RtIJyRAjnGQU= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=maxzs0.a1-4.dyn; x=1732291750; h=Feedback-ID: X-Smtpcorp-Track:Message-Id:Date:Subject:To:From:Reply-To:Sender: List-Unsubscribe:List-Unsubscribe-Post; bh=Lzx+Og/rywSv4YjLlWccBLHFqHV7fABbu3KjvJZBrrg=; b=mig1Qu4XQiuGWzghROVaJFX1fw e/jt/oQwkS9juU7/axM4CPr9nl6TJuFnO/3qo9BYbu6aj5SVJsqFd1qvJXXOviQjPIap+pU8Dd3za Thw4PTZfuW9AY2zeeDYrQpzqVmtcv0aNP4KA/csDyCmYakRWLFDUCLgl6KJkos6tJMGmqzP8iR2wm bo7zFybtNzqz44bw9m7TYbcQv1Gr9/weW+JOuItD7hW41J+sIBaKvfca7Uou2bb5EXG0+QHy0/xIB ch6Zp63p1LJjzpHWMV6HrYG7T33dGzuKQ1mjCjsD6FBjvhF3hs9HxM8Hbzr0MFxFdw7q5Iiy/Ff0C CX84R2Mw==; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=triplefau.lt; i=@triplefau.lt; q=dns/txt; s=s510616; t=1732290849; h=from : subject : to : message-id : date; bh=Lzx+Og/rywSv4YjLlWccBLHFqHV7fABbu3KjvJZBrrg=; b=jv1o1FgTvjU58Wscj0BHhwYkmDx6hcGHq1ZOlj1M00TA8NmOhFMgYXLJkI2Eebe6x28Y0 lXd6m8AT5Es4BTGSCPcNRT12Wd9LRS2tw74/BDSqlQH7fJ/xGEiQbeXcUmuWSlYyMoKnvZA BonU3ob23a/tWCLCq3VGGs5y2kZJVc54+U2sc605WYSNIrrB0W19iN2ZJK0JPmO8BEGxuYR I/ZYLV9Hfmk4uy7+03YPo12isteeR8EO9izuQSjTsgWuXSAVmZgAcv16AndLaw11/Si+XPU A896DeusDl5fc9NyF7iyRPX6TEGgIwe3qfZH7JT1gddbsGvFI9AZad+ApKFA== 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 1tEVyz-TRjyvh-6J; Fri, 22 Nov 2024 15:54:09 +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 1tEVyy-4o5NDgrtp3M-rWqJ; Fri, 22 Nov 2024 15:54:08 +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 v4 3/5] batman-adv: Do not let TT changes list grows indefinitely Date: Fri, 22 Nov 2024 16:52:50 +0100 Message-Id: <7a8b08f7c9e63281cb4dbc6d43926ec5e953a306.1732290614.git.repk@triplefau.lt> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-Smtpcorp-Track: JBVNwZUch6wp.ACDUhNc6cYYl.N14gVQWuva8 Feedback-ID: 510616m:510616apGKSTK:510616siD4vwfscd X-Report-Abuse: Please forward a copy of this message, including all headers, to Message-ID-Hash: LGNX3PMOE5ALQ3GI743ZGVWKSITNEAP4 X-Message-ID-Hash: LGNX3PMOE5ALQ3GI743ZGVWKSITNEAP4 X-MailFrom: bT.1pccv6nrmu5jcr2=sybys4a23vlz=627iqwx2bvyd2y@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 creating 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 empty 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 Acked-by: Antonio Quartulli --- net/batman-adv/translation-table.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index bbab7491c83f..53dea8ae96e4 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,10 +998,17 @@ 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 + * (fragmented) table. + * + * The local change history should still be cleaned up so the next + * TT round can start again with a clean state. */ - 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); @@ -1009,7 +1017,7 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv) tt_data->flags = BATADV_TT_OGM_DIFF; - if (tt_diff_len == 0) + if (!drop_changes && tt_diff_len == 0) goto container_register; spin_lock_bh(&bat_priv->tt.changes_list_lock); From patchwork Fri Nov 22 15:52:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Remi Pommarel X-Patchwork-Id: 18703 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 6414384512 for ; Fri, 22 Nov 2024 16:56:33 +0100 (CET) ARC-Seal: i=2; cv=pass; a=rsa-sha256; d=open-mesh.org; s=20121; t=1732290993; b=2HT6YDZwdTzmCe3LvHI3BONOrhWsjv7ykw1FkfWK3c9OIZhKSUcOCWRhosPwbdMe4CkcP 1bo0cG2RxEkiBMEXP/hY9xYYrJbyx5cLxSHr1Ff3Y8jqva4hbZd8PnDNIMBlt/akf2Gc+7V Vz6yBvSumZBl0mv9zhT9wGMX6M79kJc= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1732290993; 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=VKvkWkmuG38R+omGcedcWNPtEBxKJ0cjy7RFLDK5D2U=; b=nTexbhs+rcVSPybLETbeh0jH/uhsrG3Tfx6I1JDAXSVmlySqHQQ+ClFr08QNl9FuxRGAh wkaW4+pgiKpSV2t/MFQ8q3aoKM+JhZKNsR5wvN2RHJ3WtdpEI4XoLuLJS1IYlGT/4Ep2Y5i 7CCmyOFaFOOo3u/Uy45RUG5N3LTlWBo= 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 2945283F76 for ; Fri, 22 Nov 2024 16:54:12 +0100 (CET) ARC-Seal: i=1; s=20121; d=open-mesh.org; t=1732290852; a=rsa-sha256; cv=none; b=OlLEypXPra+zpsWdwguY43XLhasyHgeHPiqeHPbM1zq59IE9MfIDeOJw0p9/Gh6MlxUgha KCCRCWeC29w1F/YtOUsGEt/UXvHD1cjDz1N2O/yDyRnz8gyLQjUYxc2RaQeBEA1BrlOfsW GtCGlHd4lNjcUQQEYIEfcJCBs+YEDp8= 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=WM7LuIQE; dkim=pass header.d=triplefau.lt header.s=s510616 header.b="BlcqH/dp"; dmarc=pass (policy=quarantine) header.from=triplefau.lt; spf=pass (diktynna.open-mesh.org: domain of "bT.mhaxosk8qwnr4i0=hby2epvdei4e=ttqtuuutpjvd8q@em510616.triplefau.lt" designates 103.2.141.84 as permitted sender) smtp.mailfrom="bT.mhaxosk8qwnr4i0=hby2epvdei4e=ttqtuuutpjvd8q@em510616.triplefau.lt" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1732290852; 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=VKvkWkmuG38R+omGcedcWNPtEBxKJ0cjy7RFLDK5D2U=; b=N6M5wEZ47Evb4S2KaW/+PBaiv8BKGybJx5dzmEswCXcEhBR1nDgXLjGtEU25ynGLZlG01B jpBLVidZFfsLA8VizKwisoOPzWwSEiLTFFlpK16T7jNl/vlc1IhbpQN94A5shDbQlEadPH GBiSja4KymgElWw7k273PFplT7KcS2c= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=maxzs0.a1-4.dyn; x=1732291752; h=Feedback-ID: X-Smtpcorp-Track:Message-Id:Date:Subject:To:From:Reply-To:Sender: List-Unsubscribe:List-Unsubscribe-Post; bh=VKvkWkmuG38R+omGcedcWNPtEBxKJ0cjy7RFLDK5D2U=; b=WM7LuIQEQLeL76RJFpNzu/RRPf PWpPn3mRPGs4j7CkSMrllC5EHwqjzebafIDGn4KVv/5ywHirjKf2pFTcxp7A6mQaZ0NfTGIhwlJfQ 1bBWIz9v1dTBh8gcL21aUjWEupe1k/b8xdghHN1EDlTBKrZ+dYpeno870BOXFXlgj0AE60PJOqCM7 kAYk+O/ryfufXlFaaXpI+8J/vpLbaVG5ggb0YcDddt2856He3ImHKmADayZZRSGrbJK8t91S/Vgbg iFx24Nxo/hAxIKsjH01/bEwQ2blNNqsO7ljtvaPC6z2+cBIONfWAWYiPuivnYb4gYfTaSN8QwRp41 tANE2Slg==; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=triplefau.lt; i=@triplefau.lt; q=dns/txt; s=s510616; t=1732290852; h=from : subject : to : message-id : date; bh=VKvkWkmuG38R+omGcedcWNPtEBxKJ0cjy7RFLDK5D2U=; b=BlcqH/dppdiiQ5Pp2yxQ2Q7Fz3+C6JgPXSt8BOYMAod3/i2Ba++5rjLtENs3Xx0deINz1 LcWsibzHWVGtSTKb4ie2rzAxxcuPcgrDRckVCXogxQwH412zVk9xRIc6KUwr8FAE2PhXn1V pYA0FqEl8+2jFHM8XEL2XzsE4UF2X3luYC37Gyvv8b2cOwOu039tNWU5pbXQmT33Z9GkBoD s7y5diWvNuucFzTwY0AB4At6H/win06ydAtbFNUd6heZifMfuDpCwlp/JTtoAVmQWt0qAwa OeYZnl1ufpJGU6yle0Uvjv8sgs5ffp9FAhyttUXHjirUqWJ2tWJBGkQAk2Dw== 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 1tEVz1-TRjz4e-BJ; Fri, 22 Nov 2024 15:54:11 +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 1tEVz1-FnQW0hPtFAB-kRvT; Fri, 22 Nov 2024 15:54:11 +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 v4 4/5] batman-adv: Remove atomic usage for tt.local_changes Date: Fri, 22 Nov 2024 16:52:51 +0100 Message-Id: <791771d927478ef15dfd4103dc4285648acafa2b.1732290614.git.repk@triplefau.lt> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-Smtpcorp-Track: 3W2DcvhQ0n16.r6M1v73OQJrQ.AS53gQoX1E1 Feedback-ID: 510616m:510616apGKSTK:510616sHlluK3jC9 X-Report-Abuse: Please forward a copy of this message, including all headers, to Message-ID-Hash: WRYU6JL5I2LYYOIWSROSSRBROV5DIXL3 X-Message-ID-Hash: WRYU6JL5I2LYYOIWSROSSRBROV5DIXL3 X-MailFrom: bT.mhaxosk8qwnr4i0=hby2epvdei4e=ttqtuuutpjvd8q@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 | 24 +++++++++++------------- net/batman-adv/types.h | 4 ++-- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c index 2758aba47a2f..5666c268cead 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); + WRITE_ONCE(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 53dea8ae96e4..f7e894811e7f 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -463,8 +463,8 @@ 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; + size_t changes; tt_change_node = kmem_cache_alloc(batadv_tt_change_cache, GFP_ATOMIC); if (!tt_change_node) @@ -480,6 +480,7 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv, /* check for ADD+DEL or DEL+ADD events */ spin_lock_bh(&bat_priv->tt.changes_list_lock); + changes = READ_ONCE(bat_priv->tt.local_changes); list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list, list) { if (!batadv_compare_eth(entry->change.addr, common->addr)) @@ -508,21 +509,18 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv, del: list_del(&entry->list); kmem_cache_free(batadv_tt_change_cache, entry); + changes--; kmem_cache_free(batadv_tt_change_cache, tt_change_node); - event_removed = true; - goto unlock; + goto update_changes; } /* track the change in the OGMinterval list */ list_add_tail(&tt_change_node->list, &bat_priv->tt.changes_list); + changes++; -unlock: +update_changes: + WRITE_ONCE(bat_priv->tt.local_changes, changes); 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 +992,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 @@ -1021,7 +1019,7 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv) goto container_register; spin_lock_bh(&bat_priv->tt.changes_list_lock); - atomic_set(&bat_priv->tt.local_changes, 0); + WRITE_ONCE(bat_priv->tt.local_changes, 0); list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list, list) { @@ -1437,7 +1435,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); + WRITE_ONCE(bat_priv->tt.local_changes, 0); spin_unlock_bh(&bat_priv->tt.changes_list_lock); } @@ -3707,7 +3705,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) == 0) { 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 Fri Nov 22 15:52:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Remi Pommarel X-Patchwork-Id: 18704 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 AAD5E84532 for ; Fri, 22 Nov 2024 16:57:03 +0100 (CET) ARC-Seal: i=2; cv=pass; a=rsa-sha256; d=open-mesh.org; s=20121; t=1732291023; b=sbo/mq16op9yotmRMc917SRD1dDuZEeKzrz3mSfTyB43XePWJUjhhlCwcs+mJ2NLULUcL CRO+Vbtgdy+Y78GiHPW1xJTAgA/3faHn4q6nhhLOAqF9vlYqj7vyrdSQaeHRp8dOU1t8h2L YQhSOYVlG8DLShN6lloOwgBcP47rRRU= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1732291023; 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=JcSS7AOyM0f7SJKMMLWb/AV4vmfNhPja2jn99QswWvg=; b=NYn+u8PbzO558NgJDMbofb4FB0nc96CFj8hRfp74ALX1rKUam+T5CGzw5aKk4YFgccXg/ fePKaK7mwkFfou5fXbqinLBvnA4VaoGDFWeD2ifnVQx3L7lI+SEsHJNFzBpDXxzRUyOBjfo OfFrFSwQZzu+E4Pb1WhDs3O7WN+Ycu8= 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 AF88E83F77 for ; Fri, 22 Nov 2024 16:54:12 +0100 (CET) ARC-Seal: i=1; s=20121; d=open-mesh.org; t=1732290852; a=rsa-sha256; cv=none; b=KlqKcyVpGlXMXQlBskyxsFr0+81jY+IddUA1QuxwxB+XdUG63INv3E4WlWpD43nYcvsC2l VYgKnygXU4eGeuCVoAuHNYpHX6plYkmGJ8GrmYz3xPBGXvtw1bN47swx9zqSe6p5d5o6Ya GSRWShk/o6BOTWBAE6H0F59hRF+ViMs= 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="QgECQ4U/"; dkim=pass header.d=triplefau.lt header.s=s510616 header.b="UAhw/P+3"; dmarc=pass (policy=quarantine) header.from=triplefau.lt; spf=pass (diktynna.open-mesh.org: domain of "bT.1vbcjro7e0651q5=iet6zrhwrfvf=zky9isihklzct1@em510616.triplefau.lt" designates 103.2.141.84 as permitted sender) smtp.mailfrom="bT.1vbcjro7e0651q5=iet6zrhwrfvf=zky9isihklzct1@em510616.triplefau.lt" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1732290852; 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=JcSS7AOyM0f7SJKMMLWb/AV4vmfNhPja2jn99QswWvg=; b=p1X+MNREw3SVm/0FYAV+azuAiPFUqqtNpTOdfaHDVq1t87MmQ9rzmSPk9Fw7WzcaZ5HIf8 f5UR9rzbEpbBvPUiU8E8A0sLXFNL964s7qKSr4Ov0BEPrbnM+ojkEx+ha7iWyrG8dsgi/d duHg5PD6BzNsbWFNfjHrqGXJu8CL77c= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=maxzs0.a1-4.dyn; x=1732291752; h=Feedback-ID: X-Smtpcorp-Track:Message-Id:Date:Subject:To:From:Reply-To:Sender: List-Unsubscribe:List-Unsubscribe-Post; bh=JcSS7AOyM0f7SJKMMLWb/AV4vmfNhPja2jn99QswWvg=; b=QgECQ4U/rVTR7LecBcRQT9hIng vEGuZZt6lrHLZrVDRNWzjJAYgBy5pXBwdpiAexwzGG6n+h70oG6k+ShXHrelK9KUQ2mmFY08vogcS W5hkW9qUx7l2O1y/N2K/INTBYsTEPWtDvT94c45I36kOiCC92ciY3xiBA+uiR1t7zSJLUeEqK30Wk ODjQvS6NySdsNAVbdyYjLkH6xWQ9YfnyAmkLP7g3L/tiS3T/jcDyWp5K9zwjvbu44phEJT9VzlIrV MQPkVyeiykkD0h1aOfer5XlhWO7sfGQPH9uttnUY9SMbJcq6kvf0L4PZQm1GQHMunu48Tz9p5KQ8/ 2+d+hbZw==; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=triplefau.lt; i=@triplefau.lt; q=dns/txt; s=s510616; t=1732290852; h=from : subject : to : message-id : date; bh=JcSS7AOyM0f7SJKMMLWb/AV4vmfNhPja2jn99QswWvg=; b=UAhw/P+3duOgVZpZBgjWRkI9TBBQsSuZ1WliUupN/21mOhOl0pgRdmFRBqGmJUMZkzQat p8AkmjzkzhR2HwB2tocRu/Q3wB25PwLqMSEGWxmO5nguvo32vvJN+GEwIHxntDiQMgaZc2R uQdKEGwkdecqOkHAOT54JNKt/vjp9as0dbgdZdRoLHNyFrdFwScFY+XzxttSfMYyu+qA6Zt JfIJLS4xqGCuXpLNaCgoYfOU3KMeYc9BFzCr5KbPsZO4YN+kmOZBt5/aVTWQCvodNefxfMi YRlXB1x5tMHP7IRagtK4MtMFpLGxfSLFLZ+bgcHBbsY8BNVaOP6CQkOgArCw== 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 1tEVz1-TRjz6j-V6; Fri, 22 Nov 2024 15:54:11 +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 1tEVz1-AIkwcC8lUNd-JGUV; Fri, 22 Nov 2024 15:54:11 +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 v4 5/5] batman-adv: Don't keep redundant TT change events Date: Fri, 22 Nov 2024 16:52:52 +0100 Message-Id: <3ffeca62cb1808f3d5fd3d1e0937c1e812cf16c2.1732290614.git.repk@triplefau.lt> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-Smtpcorp-Track: dndJR0QZPt0o.nGc9avZj1H0B.lRwY9QdVVle Feedback-ID: 510616m:510616apGKSTK:510616skPZRtbB3N X-Report-Abuse: Please forward a copy of this message, including all headers, to Message-ID-Hash: DHLQ7WML2UEBTWW6M7Z3NMDYO7RPBFFZ X-Message-ID-Hash: DHLQ7WML2UEBTWW6M7Z3NMDYO7RPBFFZ X-MailFrom: bT.1vbcjro7e0651q5=iet6zrhwrfvf=zky9isihklzct1@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. Co-developped-by: Sven Eckelmann Signed-off-by: Remi Pommarel --- net/batman-adv/translation-table.c | 43 +++++++++++++----------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index f7e894811e7f..b22a9d2aa5b2 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -478,7 +478,7 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv, del_op_requested = flags & BATADV_TT_CLIENT_DEL; - /* check for ADD+DEL or DEL+ADD events */ + /* check for ADD+DEL, DEL+ADD, ADD+ADD or DEL+DEL events */ spin_lock_bh(&bat_priv->tt.changes_list_lock); changes = READ_ONCE(bat_priv->tt.local_changes); list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list, @@ -486,30 +486,25 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv, if (!batadv_compare_eth(entry->change.addr, common->addr)) continue; - /* DEL+ADD in the same orig interval have no effect and can be - * removed to avoid silly behaviour on the receiver side. The - * other way around (ADD+DEL) can happen in case of roaming of - * a client still in the NEW state. Roaming of NEW clients is - * now possible due to automatically recognition of "temporary" - * clients - */ - del_op_entry = entry->change.flags & BATADV_TT_CLIENT_DEL; - if (!del_op_requested && del_op_entry) - goto del; - if (del_op_requested && !del_op_entry) - goto del; - - /* 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) - entry->change.flags = flags; + if (del_op_requested != del_op_entry) { + /* DEL+ADD in the same orig interval have no effect and + * can be removed to avoid silly behaviour on the + * receiver side. The other way around (ADD+DEL) can + * happen in case of roaming of a client still in the + * NEW state. Roaming of NEW clients is now possible due + * to automatically recognition of "temporary" clients + */ + list_del(&entry->list); + kmem_cache_free(batadv_tt_change_cache, entry); + changes--; + } else { + /* this is a second add or del in the same originator + * interval. It could mean that flags have been changed + * (e.g. double add): update them + */ + entry->change.flags = flags; + } - continue; -del: - list_del(&entry->list); - kmem_cache_free(batadv_tt_change_cache, entry); - changes--; kmem_cache_free(batadv_tt_change_cache, tt_change_node); goto update_changes; }