summaryrefslogtreecommitdiffstats
path: root/libsysutils
diff options
context:
space:
mode:
authorErik Kline <ek@google.com>2015-06-17 15:53:29 +0900
committerErik Kline <ek@google.com>2015-06-18 15:44:41 +0900
commitba48ff7a5975ab9b90d2c98293dd2424baf52924 (patch)
tree5da2131362ba5a914d6f2b8dd47c133af08a94c2 /libsysutils
parentd50393057a6551c3bb498ed3a3bb7bd9eeb48225 (diff)
downloadsystem_core-ba48ff7a5975ab9b90d2c98293dd2424baf52924.tar.gz
system_core-ba48ff7a5975ab9b90d2c98293dd2424baf52924.tar.bz2
system_core-ba48ff7a5975ab9b90d2c98293dd2424baf52924.zip
Qualify IPv6 link-local DNS servers with an interface name
Bug: 21562630 Bug: 21764392 Change-Id: I7d271ae0f3fd92f70049017d38ccc15e3c1dda83
Diffstat (limited to 'libsysutils')
-rw-r--r--libsysutils/src/NetlinkEvent.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/libsysutils/src/NetlinkEvent.cpp b/libsysutils/src/NetlinkEvent.cpp
index ef3001743..2347028b8 100644
--- a/libsysutils/src/NetlinkEvent.cpp
+++ b/libsysutils/src/NetlinkEvent.cpp
@@ -455,18 +455,20 @@ bool NetlinkEvent::parseNdUserOptMessage(const struct nlmsghdr *nh) {
SLOGE("Invalid optlen %d for RDNSS option\n", optlen);
return false;
}
- int numaddrs = (optlen - 1) / 2;
+ const int numaddrs = (optlen - 1) / 2;
// Find the lifetime.
struct nd_opt_rdnss *rndss_opt = (struct nd_opt_rdnss *) opthdr;
- uint32_t lifetime = ntohl(rndss_opt->nd_opt_rdnss_lifetime);
+ const uint32_t lifetime = ntohl(rndss_opt->nd_opt_rdnss_lifetime);
// Construct "SERVERS=<comma-separated string of DNS addresses>".
- // Reserve (INET6_ADDRSTRLEN + 1) chars for each address: all but the
- // the last address are followed by ','; the last is followed by '\0'.
static const char kServerTag[] = "SERVERS=";
- static const int kTagLength = sizeof(kServerTag) - 1;
- int bufsize = kTagLength + numaddrs * (INET6_ADDRSTRLEN + 1);
+ static const int kTagLength = strlen(kServerTag);
+ // Reserve sufficient space for an IPv6 link-local address: all but the
+ // last address are followed by ','; the last is followed by '\0'.
+ static const int kMaxSingleAddressLength =
+ INET6_ADDRSTRLEN + strlen("%") + IFNAMSIZ + strlen(",");
+ const int bufsize = kTagLength + numaddrs * (INET6_ADDRSTRLEN + 1);
char *buf = (char *) malloc(bufsize);
if (!buf) {
SLOGE("RDNSS option: out of memory\n");
@@ -482,6 +484,10 @@ bool NetlinkEvent::parseNdUserOptMessage(const struct nlmsghdr *nh) {
}
inet_ntop(AF_INET6, addrs + i, buf + pos, bufsize - pos);
pos += strlen(buf + pos);
+ if (IN6_IS_ADDR_LINKLOCAL(addrs + i)) {
+ buf[pos++] = '%';
+ pos += strlcpy(buf + pos, ifname, bufsize - pos);
+ }
}
buf[pos] = '\0';