On Sat, May 26, 2018 at 11:49:29PM +0200, Denis Fondras wrote: > Not related to this diff but RFC2374 has been made obsolete by RFC3587 for > some > years : "implementations should not make any assumptions about 2000::/3 being > special". I think we can simplify this "else if" :) Agreed, although this should probably go into a separate diff; Your post on misc@ made me look at this in the first place, so I refrained from taking over your work.
> > + rtm_addrs |= RTA_NETMASK; > > Can't we consider this done in prefixlen() ? Yes. Missed to remove it from here, thanks. Updated diff below without the null and curly bracket cosmetics to avoid churn (and leave it for the RFC 3587 update around there). Index: route.c =================================================================== RCS file: /cvs/src/sbin/route/route.c,v retrieving revision 1.214 diff -u -p -r1.214 route.c --- route.c 1 May 2018 18:14:10 -0000 1.214 +++ route.c 27 May 2018 01:04:36 -0000 @@ -786,15 +786,11 @@ inet_makenetandmask(u_int32_t net, struc sin->sin_len = 1 + cp - (char *)sin; } -/* - * XXX the function may need more improvement... - */ int inet6_makenetandmask(struct sockaddr_in6 *sin6, char *plen) { struct in6_addr in6; - const char *errstr; - int i, len, q, r; + int i; if (NULL==plen) { if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr) && @@ -809,27 +805,13 @@ inet6_makenetandmask(struct sockaddr_in6 } } - if (!plen || strcmp(plen, "128") == 0) + if (!plen || prefixlen(AF_INET6, plen)) return (1); - else { - rtm_addrs |= RTA_NETMASK; - prefixlen(AF_INET6, plen); - - len = strtonum(plen, 0, 128, &errstr); - if (errstr) - errx(1, "prefixlen %s is %s", plen, errstr); - - q = (128-len) >> 3; - r = (128-len) & 7; - i = 15; - - while (q-- > 0) - sin6->sin6_addr.s6_addr[i--] = 0; - if (r > 0) - sin6->sin6_addr.s6_addr[i] &= 0xff << r; - return (0); - } + for (i = 0; i < 16; ++i) + sin6->sin6_addr.s6_addr[i] &= so_mask.sin6.sin6_addr.s6_addr[i]; + + return (0); } /*