Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Tue, 17 Nov 2015 11:33:49 +0100
From: Jo-Philipp Wich <jow@...nwrt.org>
To: musl@...ts.openwall.com
Cc: Jo-Philipp Wich <jow@...nwrt.org>
Subject: [PATCH] properly handle point-to-point interfaces in getifaddrs()

With point-to-point interfaces, the IFA_ADDRESS netlink attribute contains
the peer address while an extra attribute IFA_LOCAL carries the actual local
interface address.

Both the glibc and uclibc implementations of getifaddrs() handle this case
by moving the ifa_addr contents to the broadcast/remote address union and
overwriting ifa_addr upon receipt of an IFA_LOCAL attribute.

This patch adds the same special treatment logic of IFA_LOCAL to musl's
implementation of getifaddrs() in order to align its behaviour with that
of uclibc and musl.

Signed-off-by: Jo-Philipp Wich <jow@...nwrt.org>
---
 src/network/getifaddrs.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/network/getifaddrs.c b/src/network/getifaddrs.c
index 89a8f72..9a610c2 100644
--- a/src/network/getifaddrs.c
+++ b/src/network/getifaddrs.c
@@ -161,6 +161,15 @@ static int netlink_msg_to_ifaddr(void *pctx, struct nlmsghdr *h)
 		ifs->ifa.ifa_flags = ifs0->ifa.ifa_flags;
 		for (rta = NLMSG_RTA(h, sizeof(*ifa)); NLMSG_RTAOK(rta, h); rta = RTA_NEXT(rta)) {
 			switch (rta->rta_type) {
+			case IFA_LOCAL:
+				/* If ifa_addr is set and we get IFA_LOCAL, assume we have
+				 * a point-to-point network. Move address to correct field.  */
+				if (ifs->ifa.ifa_addr) {
+					ifs->ifu = ifs->addr;
+					ifs->ifa.ifa_dstaddr = &ifs->ifu.sa;
+					memset(&ifs->addr, 0, sizeof(ifs->addr));
+				}
+				/* fall through */
 			case IFA_ADDRESS:
 				copy_addr(&ifs->ifa.ifa_addr, ifa->ifa_family, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
 				break;
-- 
2.1.4

Powered by blists - more mailing lists

Your e-mail address:

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.