I’ve looked at bit at musl, glibc, and linux. They both do the same thing to fill out ifa_ifu.ifu_dstaddr when translating the netlink data and in glibc’s case this has remained unchanged since the initial commit in 2003. Neither of them actually touch the flags, they just copy them directly from the kernel. The bug is definitely not in connman, as getifaddrs() explicitly specifies that ifu_dstaddr is valid if IFF_POINTOPOINT is set. Between linux and libc I’m guessing this is a kernel bug. libc calls RTM_GETLINK followed by RTM_GETADDR.
For RTM_GETLINK it’s pretty simple: in drivers/net/wireguard/device.c:wg_setup(), wireguard sets:
dev->addr_len = 0;
...
dev->flags = IFF_POINTOPOINT | IFF_NOARP;
and in net/core/rtnetlink.c:rtnl_fill_ifinfo() linux does the following:
if (dev->addr_len) {
if (nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr) ||
nla_put(skb, IFLA_BROADCAST, dev->addr_len, dev->broadcast))
goto nla_put_failure;
}
So no IFLA_ADDRESS or IFLA_BROADCAST is returned for the first entry that connman encounters. This isn’t a problem though since the address is NULL, so it just skips that entry. Based on ipv6 sit, dev->broadcast should have contained the P2P destination address, which works out as ifu_dstaddr is in a union with ifu_broadaddr, which is where libc puts the IFLA_BROADCAST address.
For RTM_GETADDR we turn to net/ipv6/addrconf.c:inet6_fill_ifaddr(), where we see this:
if (!ipv6_addr_any(&ifa->peer_addr)) {
if (nla_put_in6_addr(skb, IFA_LOCAL, &ifa->addr) < 0 ||
nla_put_in6_addr(skb, IFA_ADDRESS, &ifa->peer_addr) < 0)
goto error;
} else {
if (nla_put_in6_addr(skb, IFA_ADDRESS, &ifa->addr) < 0)
goto error;
}
ipv6_addr_any() just checks if the entire address is zero so presumably this means that the peer_addr is unset and thus it only returns the interface address. What libc does here is, if it receives an IFA_LOCAL first, it puts the IFA_ADDRESS in ifu_dstaddr, so the second time connman encounters the wgN interface, it still has the IFF_POINTOPOINT bit set and it again has no ifu_dstaddr. This time it has an address though, so it processes the entry and crashes. This isn’t a problem on IPv4, since those have broadcast addresses sent as IFA_BROADCAST that end up in the same memory due to the unioning.
I’ve pulled the netlink data with strace and confirmed that this is what’s happening, and the output of getifaddrs() looks like this on my (working) desktop setup, which has the same wireguard setup as I’ve been trying on my phone:
lo addr=family=17 broadaddr=yes flags=10049
enp1s0f0 addr=family=17 broadaddr=yes flags=1002
sit0 addr=family=17 broadaddr=yes flags=80
wlp2s0 addr=family=17 broadaddr=yes flags=11043
wghermes addr=NULL broadaddr=no flags=100D1
wgwirbelwind addr=NULL broadaddr=no flags=100D1
wgtest addr=NULL broadaddr=no flags=100D1
lo addr=127.0.0.1 broadaddr=yes flags=10049
wlp2s0 addr=192.168.0.132 broadaddr=yes flags=11043
wgtest addr=198.51.100.1 broadaddr=yes flags=100D1
lo addr=::1 broadaddr=no flags=10049
wlp2s0 addr=fe80::67b:cbff:feb3:dbe8 broadaddr=no flags=11043
wghermes addr=fe80::6a6f:7369:0:1 broadaddr=no flags=100D1
wgwirbelwind addr=fe80::6a6f:7369:0:1 broadaddr=no flags=100D1
wgtest addr=fe80::6a6f:7369:0:1 broadaddr=no flags=100D1
IFF_POINTOPOINT is 1<<4, so you’ll see it’s set on every wg interface. IPv4 setups are unaffected since the getifaddrs() responses are filtered by address family as well.
I’m not really sure how to fix this. It doesn’t exactly make sense to put a singular destination address in dev->broadcast since there can be many, and I don’t know if it’s safe to remove the IFF_POINTOPOINT flag from wg interfaces. It clearly is a P2P interface but libc code unchanged since 2003 expects there to be multiple addresses in the rtnetlink response.