Skip to contentSkip to conversation

ifconfig and SIOCSIFADDR

DISCUSSION [email protected] 3 participants 3 messages Jul 24, 2001 – Jul 25, 2001

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw

Hi Andries,

Quoted 6 lines · On Tue, Jul 24, 2001 at 02:47:56PM +0000, [email protected] wrote:

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.

Just change this to

ifconfig eth1 10.0.0.150 netmask 255.255.255.0 broadcast 10.0.0.255

and be happy.

Deciding about bugs vs. "undefined behavior" is not my business, so I bite my tongue about this topic ;-)

Regards

Ingo Oeser

Signature · 1 line
Use ReiserFS to get a faster fsck and Ext2 to fsck slowly and gently.
#2 lore raw
In reply to [email protected]

Hello!

Quoted 1 line

and the last ioctl destroys the information set by the previous two.

Exactly.

Quoted 1 line

I consider this a kernel bug,

No. And even not a feature, but just the only eligible way. SIOCSIFADDR resets all previously set address information and changes it to some legal defaults, otherwise you will stay with illegal netmask/broadcast set for previously set address on this interface.

BTW, if no address was selected before, setting netmask and broadcast etc. simply fails.
So that you had some address set on the interface before you did the operation and that netmask is set for _that_ address_.

Quoted 3 lines

and ifconfig should assume that SIOCSIFADDR may be destructive and hence wait with setting netmask and broadcast address until after the SIOCSIFADDR.

I think it is even worse idea. ifconfig is low level tool and should execute ops in the order, which it was asked. Especially, taking into account that they are not commutative. Leave this logic to config scripts or to human brains.

Actually, ifconfig does some too "clever" things by hisorical reasons, sort of automic upping interface, when setting address. This is very confusing and inconvenint, however, it is impossible to change by the same (historical) reasons.

Alexey