ifconfig and SIOCSIFADDR

From: Andries.Brouwer@cwi.nl
Date: Tue Jul 24 2001 - 09:47:56 EST


I just noticed that the command

        ifconfig eth1 netmask 255.255.255.0 broadcast 10.0.0.255 10.0.0.150

(with ifconfig from net-tools-1.60)
results in a netmask of 255.0.0.0, which is wrong in my situation.

Why does ifconfig ignore the explicitly given netmask?
Because it does SIOCSIFNETMASK, then SIOCSIFBRDADDR, then SIOCSIFADDR,
and the last ioctl destroys the information set by the previous two.
        
I consider this a kernel bug, but the code has been in the kernel
for a long time. In 2.2 and 2.4 it is (devinet.c):

        case SIOCSIFADDR:
                ...
                if (!(dev->flags&IFF_POINTOPOINT)) {
                        ifa->ifa_prefixlen = inet_abc_len(ifa->ifa_address);
                        ifa->ifa_mask = inet_make_mask(ifa->ifa_prefixlen);
                        if ((dev->flags&IFF_BROADCAST) && ifa->ifa_prefixlen < 31)
                                ifa->ifa_broadcast = ifa->ifa_address|~ifa->ifa_mask;
                } else {
                        ifa->ifa_prefixlen = 32;
                        ifa->ifa_mask = inet_make_mask(32);
                }

and in 2.0 it is (net/core/dev.c):

        case SIOCSIFADDR:
                ...
                /* This is naughty. When net-032e comes out It wants moving
                   into the net032 code not the kernel. Till then it can sit
                   here (SIGH) */
                if (!dev->pa_mask)
                        dev->pa_mask = ip_get_mask(dev->pa_addr);
                if (!dev->pa_brdaddr)
                        dev->pa_brdaddr = dev->pa_addr | ~dev->pa_mask;

that is, 2.0 and earlier will only (reluctantly) set netmask and
broadcast address when it was not set already.

Probably things should be corrected both in the kernel and in ifconfig:
SIOCSIFADDR should not change netmask and broadcast address,
and ifconfig should assume that SIOCSIFADDR may be destructive
and hence wait with setting netmask and broadcast address
until after the SIOCSIFADDR.

Andries

        
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Tue Jul 31 2001 - 21:00:16 EST