mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: ifconfig and SIOCSIFADDR
@ 2001-07-25 20:26 Andries.Brouwer
  0 siblings, 0 replies; 7+ messages in thread
From: Andries.Brouwer @ 2001-07-25 20:26 UTC (permalink / raw)
  To: Andries.Brouwer, kuznet; +Cc: linux-kernel, net-tools, philb

	Hello!

And hello again!

	> Yes. It didn't in 2.0.

	Soooory, it did. This behavior is copied from there. :-)

You are mistaken. I already quoted you the source.
In case you do not believe in source reading I can demo as well.

2.4:
# ifconfig lo netmask 255.254.0.0 10.0.0.150
# ifconfig lo
lo        Link encap:Local Loopback  
          inet addr:10.0.0.150  Mask:255.0.0.0
[2.4.6, net-tools 1.60]


2.0:
# ifconfig lo netmask 255.254.0.0 10.0.0.150
# ifconfig lo
lo        Link encap:Local Loopback  
          inet addr:10.0.0.150  Bcast:127.255.255.255  Mask:255.254.0.0

[2.0.34, net-tools 1.33]


As you see, the behaviour where setting the address kills
the already set netmask is new.



	> Yes. I liked such logic thirty years ago. That is Unix.

	:-) Seems, thirty years ago there were not only Internet but Unix too.

Yes, rounded to a nice number. I suppose we started using Unix
26 or 27 years ago or so.

	BTW I did not hear about any kind of Unix, which forgets
	to set a valid mask on newly selected address.

Linux 2.0, when there already is a nonzero mask.
A zero mask is replaced by a default:

2.0:
# ifconfig lo netmask 0.0.0.0 10.0.0.150
# ifconfig lo
lo        Link encap:Local Loopback  
          inet addr:10.0.0.150  Bcast:127.255.255.255  Mask:255.0.0.0
...

Andries



^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: ifconfig and SIOCSIFADDR
@ 2001-07-25 19:23 Andries.Brouwer
  2001-07-25 19:40 ` kuznet
  0 siblings, 1 reply; 7+ messages in thread
From: Andries.Brouwer @ 2001-07-25 19:23 UTC (permalink / raw)
  To: Andries.BRouwer, kuznet; +Cc: linux-kernel, net-tools, philb

    From kuznet@mops.inr.ac.ru Wed Jul 25 18:37:10 2001

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

    Exactly.

    > 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

Yes. It didn't in 2.0. It does in 2.2 and 2.4.

    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_.

Yes. I liked such logic thirty years ago. That is Unix.
Today I am less sure that it is a good idea to expect users
to read the kernel and ifconfig sources, but I did and know.

Since you don't like changing the current behaviour, we should
probably document it (say, in ifconfig(8)).

Andries


ifconfig(8):
SYNOPSIS
...
       ifconfig interface [aftype] [address] options

OPTIONS
       Since options are read and transmitted to the kernel
       in the order given, and since giving an address parameter
       causes resetting address related information (such as
       netmask and broadcast address) to a default, any non-default
       such address related information should be given after the
       address parameter (if any).

^ permalink raw reply	[flat|nested] 7+ messages in thread
* ifconfig and SIOCSIFADDR
@ 2001-07-24 14:47 Andries.Brouwer
  2001-07-24 16:05 ` Ingo Oeser
  2001-07-24 22:50 ` Alexey Kuznetsov
  0 siblings, 2 replies; 7+ messages in thread
From: Andries.Brouwer @ 2001-07-24 14:47 UTC (permalink / raw)
  To: linux-kernel, net-tools, philb

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

	

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2001-07-26 14:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-25 20:26 ifconfig and SIOCSIFADDR Andries.Brouwer
  -- strict thread matches above, loose matches on Subject: below --
2001-07-25 19:23 Andries.Brouwer
2001-07-25 19:40 ` kuznet
2001-07-26 14:47   ` Gerhard Mack
2001-07-24 14:47 Andries.Brouwer
2001-07-24 16:05 ` Ingo Oeser
2001-07-24 22:50 ` Alexey Kuznetsov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®