mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-13 10:02:38 +00:00
Class based addressing went out in the early 90's. Basically
if a entry is not route add -net xxx/bits then we should use the addr (xxx) to establish the number of bits by looking at the first non-zero bit. So if we enter route add -net 10.1.1.0 10.1.3.5 this is the same as doing route add -net 10.1.1.0/24 Since the 8th bit (zero counting) is set to 1 we set bits to 32-8. Users can of course still use the /x to change this behavior or in cases where the network is in the trailing part of the address, a "netmask" argument can be supplied to override what is established from the interpretation of the address itself. e.g: route add -net 10.1.1.8 -netmask 0xff00ffff should overide and place the proper CIDR mask in place. PR: 131365 MFC after: 1 week
This commit is contained in:
parent
47e493d28c
commit
7f749ed938
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=190758
@ -713,7 +713,7 @@ newroute(argc, argv)
|
|||||||
#ifdef INET6
|
#ifdef INET6
|
||||||
if (af == AF_INET6) {
|
if (af == AF_INET6) {
|
||||||
rtm_addrs &= ~RTA_NETMASK;
|
rtm_addrs &= ~RTA_NETMASK;
|
||||||
memset((void *)&so_mask, 0, sizeof(so_mask));
|
memset((void *)&so_mask, 0, sizeof(so_mask));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -803,21 +803,22 @@ inet_makenetandmask(net, sin, bits)
|
|||||||
addr = net << IN_CLASSC_NSHIFT;
|
addr = net << IN_CLASSC_NSHIFT;
|
||||||
else
|
else
|
||||||
addr = net;
|
addr = net;
|
||||||
|
/*
|
||||||
if (bits != 0)
|
* If no /xx was specified we must cacluate the
|
||||||
mask = 0xffffffff << (32 - bits);
|
* CIDR address.
|
||||||
else if (net == 0)
|
*/
|
||||||
mask = 0;
|
if ((bits == 0) && (addr != 0)) {
|
||||||
else if (IN_CLASSA(addr))
|
int i, j;
|
||||||
mask = IN_CLASSA_NET;
|
for(i=0,j=1; i<32; i++) {
|
||||||
else if (IN_CLASSB(addr))
|
if (addr & j) {
|
||||||
mask = IN_CLASSB_NET;
|
break;
|
||||||
else if (IN_CLASSC(addr))
|
}
|
||||||
mask = IN_CLASSC_NET;
|
j <<= 1;
|
||||||
else if (IN_MULTICAST(addr))
|
}
|
||||||
mask = IN_CLASSD_NET;
|
/* i holds the first non zero bit */
|
||||||
else
|
bits = 32 - i;
|
||||||
mask = 0xffffffff;
|
}
|
||||||
|
mask = 0xffffffff << (32 - bits);
|
||||||
|
|
||||||
sin->sin_addr.s_addr = htonl(addr);
|
sin->sin_addr.s_addr = htonl(addr);
|
||||||
sin = &so_mask.sin;
|
sin = &so_mask.sin;
|
||||||
|
Loading…
Reference in New Issue
Block a user