netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2] ip-address: properly display zero IPv4 peer address
@ 2015-10-22  8:34 Thomas Haller
  2015-11-11 11:34 ` Phil Sutter
  2015-11-24  0:04 ` Stephen Hemminger
  0 siblings, 2 replies; 5+ messages in thread
From: Thomas Haller @ 2015-10-22  8:34 UTC (permalink / raw)
  To: netdev; +Cc: Thomas Haller

Kernel allows for zero IPv4 peer addresses (IFA_ADDRESS):

   ip address add 192.168.5.1 peer 0.0.0.0/24 dev dummy

which is distinct from a usual address like:

   ip address add 192.168.5.1/24 dev dummy
   ip address add 192.168.5.1 peer 192.168.5.1/24 dev dummy

For IPv4, a missing IFA_ADDRESS attribute means that the peer
is 0.0.0.0. See inet_fill_ifaddr(), which does:

  if ((ifa->ifa_address &&
       nla_put_in_addr(skb, IFA_ADDRESS, ifa->ifa_address)) ||

Signed-off-by: Thomas Haller <thaller@redhat.com>
---
 ip/ipaddress.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index f290205..6fc4520 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -949,7 +949,8 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
 
 	if (!rta_tb[IFA_LOCAL])
 		rta_tb[IFA_LOCAL] = rta_tb[IFA_ADDRESS];
-	if (!rta_tb[IFA_ADDRESS])
+	if (!rta_tb[IFA_ADDRESS] &&
+	    ifa->ifa_family != AF_INET)
 		rta_tb[IFA_ADDRESS] = rta_tb[IFA_LOCAL];
 
 	if (filter.ifindex && filter.ifindex != ifa->ifa_index)
@@ -1034,16 +1035,18 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
 						RTA_DATA(rta_tb[IFA_LOCAL]),
 						abuf, sizeof(abuf)));
 
-		if (rta_tb[IFA_ADDRESS] == NULL ||
+		if (rta_tb[IFA_ADDRESS] != NULL &&
 		    memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]), RTA_DATA(rta_tb[IFA_LOCAL]),
 			   ifa->ifa_family == AF_INET ? 4 : 16) == 0) {
 			fprintf(fp, "/%d ", ifa->ifa_prefixlen);
 		} else {
 			fprintf(fp, " peer %s/%d ",
-				format_host(ifa->ifa_family,
-					    RTA_PAYLOAD(rta_tb[IFA_ADDRESS]),
-					    RTA_DATA(rta_tb[IFA_ADDRESS]),
-					    abuf, sizeof(abuf)),
+				rta_tb[IFA_ADDRESS]
+					? format_host(ifa->ifa_family,
+						      RTA_PAYLOAD(rta_tb[IFA_ADDRESS]),
+						      RTA_DATA(rta_tb[IFA_ADDRESS]),
+						      abuf, sizeof(abuf))
+					: "0.0.0.0",
 				ifa->ifa_prefixlen);
 		}
 	}
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-11-24 12:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-22  8:34 [PATCH iproute2] ip-address: properly display zero IPv4 peer address Thomas Haller
2015-11-11 11:34 ` Phil Sutter
2015-11-24  0:04 ` Stephen Hemminger
2015-11-24 11:44   ` Phil Sutter
2015-11-24 12:14     ` Thomas Haller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).