From: Jo-Philipp Wich <jow@openwrt.org>
To: musl@lists.openwall.com
Cc: Jo-Philipp Wich <jow@openwrt.org>
Subject: [PATCHv2] properly handle point-to-point interfaces in getifaddrs()
Date: Thu, 19 Nov 2015 21:43:10 +0100 [thread overview]
Message-ID: <1447965790-8151-1-git-send-email-jow@openwrt.org> (raw)
In-Reply-To: <1447756429-2304-2-git-send-email-jow@openwrt.org>
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@openwrt.org>
---
Changelog v2:
* Handle IFA_LOCAL, IFA_ADDRESS in arbritary order
* Remove misleading comment for IFA_BROADCAST, no such attribute on ptp links
---
src/network/getifaddrs.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/src/network/getifaddrs.c b/src/network/getifaddrs.c
index 89a8f72..fed75bd 100644
--- a/src/network/getifaddrs.c
+++ b/src/network/getifaddrs.c
@@ -162,13 +162,26 @@ static int netlink_msg_to_ifaddr(void *pctx, struct nlmsghdr *h)
for (rta = NLMSG_RTA(h, sizeof(*ifa)); NLMSG_RTAOK(rta, h); rta = RTA_NEXT(rta)) {
switch (rta->rta_type) {
case IFA_ADDRESS:
- copy_addr(&ifs->ifa.ifa_addr, ifa->ifa_family, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
+ /* If ifa_addr is already set we, received an IFA_LOCAL before
+ * so treat this as destination address */
+ if (ifs->ifa.ifa_addr)
+ copy_addr(&ifs->ifa.ifa_dstaddr, ifa->ifa_family, &ifs->ifu, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
+ else
+ copy_addr(&ifs->ifa.ifa_addr, ifa->ifa_family, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
break;
case IFA_BROADCAST:
- /* For point-to-point links this is peer, but ifa_broadaddr
- * and ifa_dstaddr are union, so this works for both. */
copy_addr(&ifs->ifa.ifa_broadaddr, ifa->ifa_family, &ifs->ifu, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
break;
+ 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));
+ }
+ copy_addr(&ifs->ifa.ifa_addr, ifa->ifa_family, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
+ break;
case IFA_LABEL:
if (RTA_DATALEN(rta) < sizeof(ifs->name)) {
memcpy(ifs->name, RTA_DATA(rta), RTA_DATALEN(rta));
--
2.1.4
next prev parent reply other threads:[~2015-11-19 20:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-17 10:33 Fix handling of peer-to-peer " Jo-Philipp Wich
2015-11-17 10:33 ` [PATCH] properly handle point-to-point " Jo-Philipp Wich
2015-11-19 20:43 ` Jo-Philipp Wich [this message]
2015-11-21 9:14 ` [PATCHv2] " Timo Teras
2015-11-21 19:20 ` Rich Felker
2015-11-23 9:12 ` Timo Teras
2015-11-23 17:01 ` Rich Felker
2015-11-30 20:01 ` Rich Felker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1447965790-8151-1-git-send-email-jow@openwrt.org \
--to=jow@openwrt.org \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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).