Re: Pre-release 2.0.5 breaks network config scripts

really kuznet@ms2.inr.ac.ru (inr-linux-kernel@ms2.inr.ac.ru)
20 May 1996 22:24:56 +0400


Herbert Rosmanith (herp@wildsau.idv.uni-linz.ac.AT) wrote:
: > Can we at least put a patch into route to strip the host portion. This is
: > the way I use route. I want say: route the net for which this host
: > address is valid. In this way, a simple shell scripts can say:
: >
: > echo -n "Enter IP"
: > read ip
: > ifconfig eth0 $ip
: > route add -net $ip

: how about this patch:

: - route add -net $ip
: + route add -host $ip

Incorrect. "route add -host $ip" will not add route to your
ethernet network.

Correct (but pretty ugly 8) script:

echo -n "Enter IP: "
read ip
echo -n "Enter NETMASK: "
read netmask
echo -n "Enter BROADCAST: "
read broadcast
ifconfig eth0 $ip netmask $netmask broadcast $broadcast
!echo -n "Enter NETWORK: "
!read ip
route add -net $ip netmask $netmask eth0

Lines marked with '!' can be deleted, if your "route" strips host part
of address.

It is possible to patch linux/net/ipv4/route.c:

else if (mask && r->rt_genmask.sa_family != AF_INET)
return -EAFNOSUPPORT;

+ if (mask)
+ daddr &= mask;

if (flags & RTF_GATEWAY)
{

but I do not like this, because it makes almost any (addr,mask) pair
valid. I believe that it is user problem
to specify correct interface network, and kernel should only
check (addr,mask) pair for validity.

Does it look complicated? No, it is the only correct way.

If some distribution contains broken scripts (a sort of
cited above) it will stop to work in more complex environments
with "not default" network masks.
When you make "ifconfig eth0 ip-addr", kernel sets netmask (and broadcast)
in accordance with obsolete notion of A,B,C class networks.
Yes, I understand, that a lot of people consider this convention
convenient, but do not forget that there exist a lot of networks
that do not use ABC masks.
So that I believe, modern kernel should not contain
any references to ABC. It still does because of obsolete
SIOCSIF* ioctls. I hope it will go away in >=2.1.

If you want to write modern and correct script,
you should:

1. ask for IP address
2. ask for netmask (and propose ABC mask as default)
3. if configured interface is broadcastable, ask
for broadcast address (default is evaluated by replacing host part
of address with 1s)
4. Evaluate IP network
5. ifconfig $if_name $if_address netmask $if_mask broadcast $if_broadcast
6 route add -net $if_net netmask $if_mask dev $if_name

Alexey Kuznetsov.