nss-resolve: don't set scopeindex for non-link-local addresses
authorLennart Poettering <lennart@poettering.net>
Wed, 8 Feb 2017 18:40:48 +0000 (19:40 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 9 Feb 2017 15:13:07 +0000 (16:13 +0100)
Apparently some apps don't like that. And given that this isn't
necessary for link-local addresses, let's suppress this information.

Fixes: #4465

src/nss-resolve/nss-resolve.c

index d46a3af..ce8d59d 100644 (file)
@@ -110,6 +110,20 @@ static int count_addresses(sd_bus_message *m, int af, const char **canonical) {
         return c;
 }
 
+static uint32_t ifindex_to_scopeid(int family, const void *a, int ifindex) {
+        struct in6_addr in6;
+
+        if (family != AF_INET6)
+                return 0;
+
+        /* Some apps can't deal with the scope ID attached to non-link-local addresses. Hence, let's suppress that. */
+
+        assert(sizeof(in6) == FAMILY_ADDRESS_SIZE(AF_INET));
+        memcpy(&in6, a, sizeof(struct in6_addr));
+
+        return IN6_IS_ADDR_LINKLOCAL(&in6) ? ifindex : 0;
+}
+
 enum nss_status _nss_resolve_gethostbyname4_r(
                 const char *name,
                 struct gaih_addrtuple **pat,
@@ -245,7 +259,7 @@ enum nss_status _nss_resolve_gethostbyname4_r(
                 r_tuple->next = i == c-1 ? NULL : (struct gaih_addrtuple*) ((char*) r_tuple + ALIGN(sizeof(struct gaih_addrtuple)));
                 r_tuple->name = r_name;
                 r_tuple->family = family;
-                r_tuple->scopeid = ifindex;
+                r_tuple->scopeid = ifindex_to_scopeid(family, a, ifindex);
                 memcpy(r_tuple->addr, a, sz);
 
                 idx += ALIGN(sizeof(struct gaih_addrtuple));