dhcpcd-discuss

Re: Unable to acquire router solicitation on ppp link after update from 9.0.2 to 9.1.2

Roy Marples

Tue Jun 23 22:44:11 2020

On 23/06/2020 21:31, Daniel Albers wrote:
I bisected it down to "c1e48321 Rename ifp->family -> ifp->hwtype so
it's less confusing".

Stepping through the code I noticed that ifp->index is set to 0 (match
all) for this interface. The correct interface number would be 8.

Looking at the diff I guess the cleanup of the SIOCGIFINDEX ioctl is
causing this:

-               else {
-                       /* This is a huge bug in getifaddrs(3) as there
-                        * is no reason why this can't be returned in
-                        * ifa_addr. */
-                       memset(&ifr, 0, sizeof(ifr));
-                       strlcpy(ifr.ifr_name, ifa->ifa_name,
-                           sizeof(ifr.ifr_name));
-                       if (ioctl(ctx->pf_inet_fd, SIOCGIFHWADDR, &ifr)
== -1)
-                               logerr("%s: SIOCGIFHWADDR", ifa-
ifa_name);
-                       ifp->family = ifr.ifr_hwaddr.sa_family;
-                       if (ioctl(ctx->pf_inet_fd, SIOCGIFINDEX, &ifr)
== -1)
-                               logerr("%s: SIOCGIFINDEX", ifa-
ifa_name);
-                       ifp->index = (unsigned int)ifr.ifr_ifindex;
-               }



Nice find!

This patch should fix it.
Please let me know!

I don't suppose you could try the same setup on an Alpine Linux distro? It uses mucl libc and might not be affected.
I'd rather try and limit this to glibc only and I lack a PPP setup to test :/

Roy
diff --git a/src/if.c b/src/if.c
index f867cd59..099eab9b 100644
--- a/src/if.c
+++ b/src/if.c
@@ -386,6 +386,39 @@ if_valid_hwaddr(const uint8_t *hwaddr, size_t hwlen)
 	return false;
 }
 
+#if defined(AF_PACKET) && !defined(AF_LINK)
+static unsigned int
+if_check_arphrd(struct interface *ifp, unsigned int active, bool if_noconf)
+{
+
+	switch(ifp->hwtype) {
+	case ARPHRD_ETHER:	/* FALLTHROUGH */
+	case ARPHRD_IEEE1394:	/* FALLTHROUGH */
+	case ARPHRD_INFINIBAND:	/* FALLTHROUGH */
+	case ARPHRD_NONE:	/* FALLTHROUGH */
+		break;
+	case ARPHRD_LOOPBACK:
+	case ARPHRD_PPP:
+		if (if_noconf) {
+			logdebugx("%s: ignoring due to interface type and"
+			    " no config",
+			    ifp->name);
+			active = IF_INACTIVE;
+		}
+		break;
+	default:
+		if (if_noconf)
+			active = IF_INACTIVE;
+		if (active)
+			logwarnx("%s: unsupported interface type 0x%.2x",
+			    ifp->name, ifp->hwtype);
+		break;
+	}
+
+	return active;
+}
+#endif
+
 struct if_head *
 if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs,
     int argc, char * const *argv)
@@ -597,34 +630,27 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs,
 			ifp->hwlen = sll->sll_halen;
 			if (ifp->hwlen != 0)
 				memcpy(ifp->hwaddr, sll->sll_addr, ifp->hwlen);
-
-			switch(ifp->hwtype) {
-			case ARPHRD_ETHER:	/* FALLTHROUGH */
-			case ARPHRD_IEEE1394:	/* FALLTHROUGH */
-			case ARPHRD_INFINIBAND:	/* FALLTHROUGH */
-			case ARPHRD_NONE:	/* FALLTHROUGH */
-				break;
-			case ARPHRD_LOOPBACK:
-			case ARPHRD_PPP:
-				if (if_noconf) {
-					logdebugx("%s: ignoring due to"
-					    " interface type and"
-					    " no config",
-					    ifp->name);
-					active = IF_INACTIVE;
-				}
-				break;
-			default:
-				if (if_noconf)
-					active = IF_INACTIVE;
-				if (active)
-					logwarnx("%s: unsupported"
-					    " interface type 0x%.2x",
-					    ifp->name, ifp->hwtype);
-				break;
-			}
+			active = if_check_arphrd(ifp, active, if_noconf);
 #endif
 		}
+#ifdef __GLIBC__
+		else {
+			struct ifreq ifr = { .ifr_flags = 0 };
+
+			/* This is a huge bug in getifaddrs(3) as there
+			 * is no reason why this can't be returned in
+			 * ifa_addr. */
+			strlcpy(ifr.ifr_name, ifa->ifa_name,
+			    sizeof(ifr.ifr_name));
+			if (ioctl(ctx->pf_inet_fd, SIOCGIFHWADDR, &ifr) == -1)
+				logerr("%s: SIOCGIFHWADDR", ifa->ifa_name);
+			ifp->hwtype = ifr.ifr_hwaddr.sa_family;
+			if (ioctl(ctx->pf_inet_fd, SIOCGIFINDEX, &ifr) == -1)
+				logerr("%s: SIOCGIFINDEX", ifa->ifa_name);
+			ifp->index = (unsigned int)ifr.ifr_ifindex;
+			if_check_arphrd(ifp, active, if_noconf);
+		}
+#endif
 
 		if (!(ctx->options & (DHCPCD_DUMPLEASE | DHCPCD_TEST))) {
 			/* Handle any platform init for the interface */

Follow-Ups:
Re: Unable to acquire router solicitation on ppp link after update from 9.0.2 to 9.1.2Daniel Albers
References:
Unable to acquire router solicitation on ppp link after update from 9.0.2 to 9.1.2Daniel Albers
Re: Unable to acquire router solicitation on ppp link after update from 9.0.2 to 9.1.2Roy Marples
Re: Unable to acquire router solicitation on ppp link after update from 9.0.2 to 9.1.2Daniel Albers
Archive administrator: postmaster@marples.name