diff options
author | mav <mav@FreeBSD.org> | 2009-01-18 11:38:35 +0000 |
---|---|---|
committer | mav <mav@FreeBSD.org> | 2009-01-18 11:38:35 +0000 |
commit | 61329c22c2e4437413c72b285a4c539856731a69 (patch) | |
tree | d84e8d67c3c77ba7db8832233eee2915a4304e12 /sbin/route | |
parent | 6fc1971988d00734e0f141e5e115d6c574052ea6 (diff) | |
download | FreeBSD-src-61329c22c2e4437413c72b285a4c539856731a69.zip FreeBSD-src-61329c22c2e4437413c72b285a4c539856731a69.tar.gz |
Fix regression introduced in rev. 173124:
0.0.0.0/1 is not the same as 0.0.0.0/0.
MFC after: 1 month
Diffstat (limited to 'sbin/route')
-rw-r--r-- | sbin/route/route.c | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/sbin/route/route.c b/sbin/route/route.c index bae9983..90ea509 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -791,33 +791,34 @@ inet_makenetandmask(net, sin, bits) char *cp; rtm_addrs |= RTA_NETMASK; - if (net == 0) - mask = addr = 0; - else { - if (net <= 0xff) - addr = net << IN_CLASSA_NSHIFT; - else if (net <= 0xffff) - addr = net << IN_CLASSB_NSHIFT; - else if (net <= 0xffffff) - addr = net << IN_CLASSC_NSHIFT; - else - addr = net; + /* + * XXX: This approach unable to handle 0.0.0.1/32 correctly + * as inet_network() converts 0.0.0.1 and 1 equally. + */ + if (net <= 0xff) + addr = net << IN_CLASSA_NSHIFT; + else if (net <= 0xffff) + addr = net << IN_CLASSB_NSHIFT; + else if (net <= 0xffffff) + addr = net << IN_CLASSC_NSHIFT; + else + addr = net; + + if (bits != 0) + mask = 0xffffffff << (32 - bits); + else if (net == 0) + mask = 0; + else if (IN_CLASSA(addr)) + mask = IN_CLASSA_NET; + else if (IN_CLASSB(addr)) + mask = IN_CLASSB_NET; + else if (IN_CLASSC(addr)) + mask = IN_CLASSC_NET; + else if (IN_MULTICAST(addr)) + mask = IN_CLASSD_NET; + else + mask = 0xffffffff; - if (bits != 0) - mask = 0xffffffff << (32 - bits); - else { - if (IN_CLASSA(addr)) - mask = IN_CLASSA_NET; - else if (IN_CLASSB(addr)) - mask = IN_CLASSB_NET; - else if (IN_CLASSC(addr)) - mask = IN_CLASSC_NET; - else if (IN_MULTICAST(addr)) - mask = IN_CLASSD_NET; - else - mask = 0xffffffff; - } - } sin->sin_addr.s_addr = htonl(addr); sin = &so_mask.sin; sin->sin_addr.s_addr = htonl(mask); |