Skip to contentSkip to conversation

ipaddress.c: do not show address priority in brief mode

PATCH New Arseny Maslennikov 1 participant 1 message May 6

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipaddress.c: do not show address priority in brief mode

Otherwise, the following output is possible:

% ip -br a

  lo               UNKNOWN    127.0.0.1/8 ::1/128
  enp7s0           UP         10.5.0.9/16 metric 1024 fe80::546f:33ff:fee1:9/64 2001:db8:0:a:546f:33ff:fee1:9/64

This was observed on a machine with systemd-networkd stable 258.5 active.

The point of ip -brief a is to provide basic information about addresses easily processed by awk(1) and the like. Consumers of its output have come to expect $3 and further fields to be a space-separated list of addresses. The above output breaks this expectation. While a human reader may distinguish "metric" and "1024" from an address/prefixlen pair, existing scripts won't.

Fixes 78d04c7b27cf ("ipaddress: Add support for address metric")
---
 ip/ipaddress.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ip/ipaddress.c +1 -1
index 4d93a04a..80070a1a 100644
@@ -1636,7 +1636,7 @@ int print_addrinfo(struct nlmsghdr *n, void *arg)
 		}
 		print_int(PRINT_ANY, "prefixlen", "/%d ", ifa->ifa_prefixlen);
 
-		if (rta_tb[IFA_RT_PRIORITY])
+		if (!brief && rta_tb[IFA_RT_PRIORITY])
 			print_uint(PRINT_ANY, "metric", "metric %u ",
 				   rta_getattr_u32(rta_tb[IFA_RT_PRIORITY]));
 	}
Signature · 1 line
2.50.1