Hi misc,

(this is on 4.6-stable, -current has the same issue)

I played around with our shiny new /32 and noticed that this is not
working:

$ sudo /sbin/route add -inet6 -prefixlen 48 2a00:15a8:6:: 2a00:15a8::3

$ route -n show -inet6 | fgrep 2a00:15a8::3
[...]
2a00:15a8:6::/64 2a00:15a8::3 UGS 0 0 - 8 em0


After some re-reading of route(8) and reading
/usr/src/sbin/route/route.c I figured out that I should be doing
something like this:

$ sudo /sbin/route add -inet6 2a00:15a8:6:: 2a00:15a8::3 -prefixlen 48

$ route -n show -inet6 | fgrep 2a00:15a8::3
[...]
2a00:15a8:6::/48 2a00:15a8::3 UGS 0 0 - 8 em0

$ sudo /sbin/route add -inet6 2a00:15a8:6:: -prefixlen 48 2a00:15a8::3
is working, too.

The obvious bug here is me not being able to call route the correct
way.

However, route's behavior in the first call is a bit strange, it
silently inserts a /64 route - ignoring the prefixlen.

The man page says:

     The implicit network mask generated in the AF_INET case can be
     overridden by making sure this option follows the destination
parameter.
     -prefixlen is also available for a similar purpose, for IPv6/v4.

Earlier it states:
     The other commands have the syntax:

           route [-dnqtv] command [modifiers] destination gateway

I don't think it's clear (from this synopsis) that -prefixlen is part
of the destination or gateway, I thought it's part of [modifiers].

This behavior is caused by the way the command line is parsed.
The parsers sees -prefixlen, calls int prefixlen(char *s) and sets a
global variable (so_mask).
Later it parses the network address (2a00:15a8:6:: in my case) and
calls int inet6_makenetandmask(struct sockaddr_in6 *sin6).
This function tries to figure out a prefixlen (0 if it thinks it's a
default route and 64 if the lower 8 bytes of the address are zero) and
overwrites the previously set prefixlen by calling int prefixlen(char
*s) again.

It would be nice if route refuses to do anything in the first call,
it's syntacticly and semanticly wrong or at least warn that it's
ignoring -prefixlen and inserting a /64 instead.

Best regards,

Florian

Reply via email to