lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240108011131.83295-1-shaozhengchao@huawei.com>
Date: Mon, 8 Jan 2024 09:11:31 +0800
From: Zhengchao Shao <shaozhengchao@...wei.com>
To: <netdev@...r.kernel.org>, <davem@...emloft.net>, <edumazet@...gle.com>,
	<kuba@...nel.org>, <pabeni@...hat.com>
CC: <weiyongjun1@...wei.com>, <yuehaibing@...wei.com>,
	<shaozhengchao@...wei.com>
Subject: [PATCH net-next] fib: rules: use memcmp to simplify code in rule_exists

In the fib_rule structure, the member variables 'pref' to 'oifname' are
consecutive. In addition, the newly generated rule uses kzalloc to
allocate memory, and all allocated memory is initialized to 0. Therefore,
the comparison of two fib_rule structures from 'pref' to 'oifname' can be
simplified into the comparison of continuous memory.

Signed-off-by: Zhengchao Shao <shaozhengchao@...wei.com>
---
 net/core/fib_rules.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index a50a0bde8db1..e6def052e7d3 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -686,6 +686,10 @@ static int rule_exists(struct fib_rules_ops *ops, struct fib_rule_hdr *frh,
 		       struct nlattr **tb, struct fib_rule *rule)
 {
 	struct fib_rule *r;
+	size_t off_len;
+
+	off_len = offsetof(struct fib_rule, uid_range) -
+		  offsetof(struct fib_rule, pref);
 
 	list_for_each_entry(r, &ops->rules_list, list) {
 		if (r->action != rule->action)
@@ -694,24 +698,12 @@ static int rule_exists(struct fib_rules_ops *ops, struct fib_rule_hdr *frh,
 		if (r->table != rule->table)
 			continue;
 
-		if (r->pref != rule->pref)
-			continue;
-
-		if (memcmp(r->iifname, rule->iifname, IFNAMSIZ))
-			continue;
-
-		if (memcmp(r->oifname, rule->oifname, IFNAMSIZ))
+		if (memcmp(&r->pref, &rule->pref, off_len))
 			continue;
 
 		if (r->mark != rule->mark)
 			continue;
 
-		if (r->suppress_ifgroup != rule->suppress_ifgroup)
-			continue;
-
-		if (r->suppress_prefixlen != rule->suppress_prefixlen)
-			continue;
-
 		if (r->mark_mask != rule->mark_mask)
 			continue;
 
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ