Skip to contentSkip to conversation

ip: Properly display AF_BRIDGE address information for neighbor events

PATCH Superseded Donald Sharp 2 participants 4 messages Feb 22, 2018 – Feb 23, 2018

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

PATCH 1/1 ip: Properly display AF_BRIDGE address information for neighbor events

The vxlan driver when a neighbor add/delete event occurs sends NDA_DST filled with a union:

union vxlan_addr {
	struct sockaddr_in sin;
	struct sockaddr_in6 sin6;
	struct sockaddr sa;
};

This eventually calls rt_addr_n2a_r which had no handler for the AF_BRIDGE family and "???" was being printed.

Add code to properly display this data when requested.

---
 lib/utils.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
lib/utils.c +18 -0
index 24aeddd8..e01e18a7 100644
@@ -1004,6 +1004,24 @@ const char *rt_addr_n2a_r(int af, int len,
 	}
 	case AF_PACKET:
 		return ll_addr_n2a(addr, len, ARPHRD_VOID, buf, buflen);
+	case AF_BRIDGE:
+	{
+		unsigned short family = ((struct sockaddr *)addr)->sa_family;
+		struct sockaddr_in6 *sin6;
+		struct sockaddr_in *sin;
+
+		switch(family) {
+		case AF_INET:
+			sin = (struct sockaddr_in *)addr;
+			return inet_ntop(AF_INET, &sin->sin_addr, buf, buflen);
+		case AF_INET6:
+			sin6 = (struct sockaddr_in6 *)addr;
+			return inet_ntop(AF_INET6, &sin6->sin6_addr,
+					 buf, buflen);
+		}
+
+		/* fallthrough */
+	}
 	default:
 		return "???";
 	}
Signature · 1 line
2.14.3
#1 lore raw
Quoted 9 lines · On Wed, 21 Feb 2018 21:26:50 -0500 Donald Sharp <[email protected]>…

The vxlan driver when a neighbor add/delete event occurs sends NDA_DST filled with a union:

union vxlan_addr {
	struct sockaddr_in sin;
	struct sockaddr_in6 sin6;
	struct sockaddr sa;
};
Quoted 6 lines

This eventually calls rt_addr_n2a_r which had no handler for the AF_BRIDGE family and "???" was being printed.

Add code to properly display this data when requested.

Minor style comment.

Quoted 9 lines
---
 lib/utils.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
lib/utils.c +0 -0
index 24aeddd8..e01e18a7 100644

lib/utils.c const char *rt_addr_n2a_r(int af, int len, · line 1012

Quoted 9 lines
lib/utils.c +6 -0
@@ -1004,6 +1004,24 @@ const char *rt_addr_n2a_r(int af, int len,
 	}
 	case AF_PACKET:
 		return ll_addr_n2a(addr, len, ARPHRD_VOID, buf, buflen);
+	case AF_BRIDGE:
+	{
+		unsigned short family = ((struct sockaddr *)addr)->sa_family;
+		struct sockaddr_in6 *sin6;
+		struct sockaddr_in *sin;
+

Since you are doing aliasing, would it be clearer to do?

		union {
			struct sockaddr sa;
			struct sockaddr_in6 sin6;
			struct sockaddr_in sin;
		} *sa = addr;

lib/utils.c const char *rt_addr_n2a_r(int af, int len, · line 1015

Quoted 3 lines
lib/utils.c +3 -0
+		switch(family) {
+		case AF_INET:
+			sin = (struct sockaddr_in *)addr;

Casting a void pointer is unnecessary

Quoted 12 lines
lib/utils.c +9 -0
+			return inet_ntop(AF_INET, &sin->sin_addr, buf, buflen);
+		case AF_INET6:
+			sin6 = (struct sockaddr_in6 *)addr;
+			return inet_ntop(AF_INET6, &sin6->sin6_addr,
+					 buf, buflen);
+		}
+
+		/* fallthrough */
+	}
 	default:
 		return "???";
 	}
#2 lore raw

PATCH v2 1/1 ip: Properly display AF_BRIDGE address information for neighbor events

In reply to Donald Sharp

The vxlan driver when a neighbor add/delete event occurs sends NDA_DST filled with a union:

union vxlan_addr {
	struct sockaddr_in sin;
	struct sockaddr_in6 sin6;
	struct sockaddr sa;
};

This eventually calls rt_addr_n2a_r which had no handler for the AF_BRIDGE family and "???" was being printed.

Add code to properly display this data when requested.

---
 lib/utils.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
lib/utils.c +19 -0
index 24aeddd8..fe5841f6 100644
@@ -1004,6 +1004,25 @@ const char *rt_addr_n2a_r(int af, int len,
 	}
 	case AF_PACKET:
 		return ll_addr_n2a(addr, len, ARPHRD_VOID, buf, buflen);
+	case AF_BRIDGE:
+	{
+		const union {
+			struct sockaddr sa;
+			struct sockaddr_in sin;
+			struct sockaddr_in6 sin6;
+		} *sa = addr;
+		unsigned short family = sa->sa.sa_family;
+
+		switch(family) {
+		case AF_INET:
+			return inet_ntop(AF_INET, &sa->sin.sin_addr, buf, buflen);
+		case AF_INET6:
+			return inet_ntop(AF_INET6, &sa->sin6.sin6_addr,
+					 buf, buflen);
+		}
+
+		/* fallthrough */
+	}
 	default:
 		return "???";
 	}
Signature · 1 line
2.14.3
#3 lore raw
Quoted 9 lines · On Fri, 23 Feb 2018 14:10:09 -0500 Donald Sharp <[email protected]>…

The vxlan driver when a neighbor add/delete event occurs sends NDA_DST filled with a union:

union vxlan_addr {
	struct sockaddr_in sin;
	struct sockaddr_in6 sin6;
	struct sockaddr sa;
};
Quoted 6 lines

This eventually calls rt_addr_n2a_r which had no handler for the AF_BRIDGE family and "???" was being printed.

Add code to properly display this data when requested.

I did some minor changes to the patch and applied it. (need space after switch, and can don't need local variable family). Thanks.