From: Roy Marples Date: Tue, 18 Feb 2025 09:48:19 +0000 (+0000) Subject: BSD: Fix netmask family and length for incoming route msgs X-Git-Tag: v10.2.1~9 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=f608e853a195bdeac6c7fb1a22d3b10fcfd5d01d;p=thirdparty%2Fdhcpcd.git BSD: Fix netmask family and length for incoming route msgs Netmask family and length are ignored by traditional userland tools such as route and netstat and are assumed to match the destination sockaddr. This is fortunate because BSD kernels use a radix tree to store routes which adjusts the netmask at the point of insertion where this information is lost. We can just sub in the values from the destination address. This is currently true for all BSD kernels. --- diff --git a/src/if-bsd.c b/src/if-bsd.c index 8af59610..32b51ba7 100644 --- a/src/if-bsd.c +++ b/src/if-bsd.c @@ -887,10 +887,22 @@ if_copyrt(struct dhcpcd_ctx *ctx, struct rt *rt, const struct rt_msghdr *rtm) rt->rt_flags = (unsigned int)rtm->rtm_flags; if_copysa(&rt->rt_dest, rti_info[RTAX_DST]); + if (rtm->rtm_addrs & RTA_NETMASK) { if_copysa(&rt->rt_netmask, rti_info[RTAX_NETMASK]); - if (rt->rt_netmask.sa_family == 255) /* Why? */ - rt->rt_netmask.sa_family = rt->rt_dest.sa_family; + /* + * Netmask family and length are ignored by traditional + * userland tools such as route and netstat and are assumed + * to match the destination sockaddr. + * This is fortunate because BSD kernels use a radix tree + * to store routes which adjusts the netmask at the point + * of insertion where this information is lost. + * We can just sub in the values from the destination address. + * + * This is currently true for all BSD kernels. + */ + rt->rt_netmask.sa_family = rt->rt_dest.sa_family; + rt->rt_netmask.sa_len = rt->rt_dest.sa_len; } /* dhcpcd likes an unspecified gateway to indicate via the link. diff --git a/src/sa.c b/src/sa.c index 9fdccb69..e8bff04f 100644 --- a/src/sa.c +++ b/src/sa.c @@ -419,11 +419,6 @@ sa_cmp(const struct sockaddr *sa1, const struct sockaddr *sa2) assert(sa1 != NULL); assert(sa2 != NULL); - /* Treat AF_UNSPEC as the unspecified address. */ - if ((sa1->sa_family == AF_UNSPEC || sa2->sa_family == AF_UNSPEC) && - sa_is_unspecified(sa1) && sa_is_unspecified(sa2)) - return 0; - if (sa1->sa_family != sa2->sa_family) return sa1->sa_family - sa2->sa_family;