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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1466525921-15738-8-git-send-email-phil@nwl.cc>
Date:	Tue, 21 Jun 2016 18:18:41 +0200
From:	Phil Sutter <phil@....cc>
To:	Stephen Hemminger <shemming@...cade.com>
Cc:	Daniel Borkmann <daniel@...earbox.net>,
	David Ahern <dsa@...ulusnetworks.com>,
	Nicolas Dichtel <nicolas.dichtel@...nd.com>,
	Julien Floret <julien.floret@...nd.com>, netdev@...r.kernel.org
Subject: [iproute PATCH v2 7/7] ip/tcp_metrics: Simplify process_msg a bit

By combining the attribute extraction and check for existence, the
additional indentation level in the 'else' clause can be avoided.

In addition to that, common actions for 'daddr' are combined since the
function returns if neither of the branches are taken.

Signed-off-by: Phil Sutter <phil@....cc>
---
 ip/tcp_metrics.c | 45 ++++++++++++++++++---------------------------
 1 file changed, 18 insertions(+), 27 deletions(-)

diff --git a/ip/tcp_metrics.c b/ip/tcp_metrics.c
index f82604f458ada..899830c127bcb 100644
--- a/ip/tcp_metrics.c
+++ b/ip/tcp_metrics.c
@@ -112,47 +112,38 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n,
 	parse_rtattr(attrs, TCP_METRICS_ATTR_MAX, (void *) ghdr + GENL_HDRLEN,
 		     len);
 
-	a = attrs[TCP_METRICS_ATTR_ADDR_IPV4];
-	if (a) {
+	if ((a = attrs[TCP_METRICS_ATTR_ADDR_IPV4])) {
 		if (f.daddr.family && f.daddr.family != AF_INET)
 			return 0;
-		memcpy(&daddr.data, RTA_DATA(a), 4);
 		daddr.bytelen = 4;
 		family = AF_INET;
 		atype = TCP_METRICS_ATTR_ADDR_IPV4;
-		dlen = RTA_PAYLOAD(a);
-	} else {
-		a = attrs[TCP_METRICS_ATTR_ADDR_IPV6];
-		if (a) {
-			if (f.daddr.family && f.daddr.family != AF_INET6)
-				return 0;
-			memcpy(&daddr.data, RTA_DATA(a), 16);
-			daddr.bytelen = 16;
-			family = AF_INET6;
-			atype = TCP_METRICS_ATTR_ADDR_IPV6;
-			dlen = RTA_PAYLOAD(a);
-		} else
+	} else if ((a = attrs[TCP_METRICS_ATTR_ADDR_IPV6])) {
+		if (f.daddr.family && f.daddr.family != AF_INET6)
 			return 0;
+		daddr.bytelen = 16;
+		family = AF_INET6;
+		atype = TCP_METRICS_ATTR_ADDR_IPV6;
+	} else {
+		return 0;
 	}
+	memcpy(&daddr.data, RTA_DATA(a), daddr.bytelen);
+	dlen = RTA_PAYLOAD(a);
 
-	a = attrs[TCP_METRICS_ATTR_SADDR_IPV4];
-	if (a) {
+	if ((a = attrs[TCP_METRICS_ATTR_SADDR_IPV4])) {
 		if (f.saddr.family && f.saddr.family != AF_INET)
 			return 0;
 		memcpy(&saddr.data, RTA_DATA(a), 4);
 		saddr.bytelen = 4;
 		stype = TCP_METRICS_ATTR_SADDR_IPV4;
 		slen = RTA_PAYLOAD(a);
-	} else {
-		a = attrs[TCP_METRICS_ATTR_SADDR_IPV6];
-		if (a) {
-			if (f.saddr.family && f.saddr.family != AF_INET6)
-				return 0;
-			memcpy(&saddr.data, RTA_DATA(a), 16);
-			saddr.bytelen = 16;
-			stype = TCP_METRICS_ATTR_SADDR_IPV6;
-			slen = RTA_PAYLOAD(a);
-		}
+	} else if ((a = attrs[TCP_METRICS_ATTR_SADDR_IPV6])) {
+		if (f.saddr.family && f.saddr.family != AF_INET6)
+			return 0;
+		memcpy(&saddr.data, RTA_DATA(a), 16);
+		saddr.bytelen = 16;
+		stype = TCP_METRICS_ATTR_SADDR_IPV6;
+		slen = RTA_PAYLOAD(a);
 	}
 
 	if (f.daddr.family && f.daddr.bitlen >= 0 &&
-- 
2.8.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ