Denis Fondras(de...@openbsd.org) on 2018.05.24 17:57:19 +0200:
> On Thu, May 24, 2018 at 07:04:04AM -0400, David Higgs wrote:
> > But shouldn???t the answer be the same, since I have a valid default route?
> > 
> 
> It should but that's not how route(8) works for now :)
> 
> Barely tested diff, assumes that no netmask means /128 (similar to IPv4 
> handling
> where no netmask means /32)

But it doesn't:

[benoit@blap:~]$ doas route add 192.168.5 10.8.0.137
[benoit@blap:~]$ doas route -n get 192.168.5.33 
   route to: 192.168.5.33
destination: 192.168.5.0
       mask: 255.255.255.0
    gateway: 10.8.0.137

---> 192.168.5 is interpreted as /24

[benoit@blap:~]$ doas route delete 192.168.5 10.8.0.137
delete net 192.168.5: gateway 10.8.0.137

---> 192.168.5.0/24 is deleted

Indeed, if i do

[benoit@blap:~]$ doas route add 192.168.5.66 10.8.0.137  
add host 192.168.5.66: gateway 10.8.0.137

i get a /32 route

[benoit@blap:~]$ doas route -n get 192.168.5.66         
   route to: 192.168.5.66
destination: 192.168.5.66
       mask: 255.255.255.255
    gateway: 10.8.0.137

but thats equivalent to doing

[benoit@blap:~]$ route add 2607:f8b0:4004:805::2004 ::

Now. for ipv6 the spec says what 2607:f8b0:4004:805::
means, whereas for ipv4 its just historical accident that

192.168.5 is interpreded in some way.

So i think the answer to the OP is: always use a netmask, except when you
specify full host address.

/Benno

> 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   24 May 2018 15:54:37 -0000
> @@ -800,13 +800,8 @@ inet6_makenetandmask(struct sockaddr_in6
>               if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr) &&
>                   sin6->sin6_scope_id == 0) {
>                       plen = "0";
> -             } else if ((sin6->sin6_addr.s6_addr[0] & 0xe0) == 0x20) {
> -                     /* aggregatable global unicast - RFC2374 */
> -                     memset(&in6, 0, sizeof(in6));
> -                     if (!memcmp(&sin6->sin6_addr.s6_addr[8],
> -                         &in6.s6_addr[8], 8))
> -                             plen = "64";
> -             }
> +             } else
> +                     plen = "128";
>       }
>  
>       if (!plen || strcmp(plen, "128") == 0)
> 

-- 

Reply via email to