ifdown/ifup and friends

ifdown/ifup and friends

Tzafrir Cohen tzafrir at cohens.org.il
Tue Apr 24 18:08:48 IDT 2018


Hi,

Not a good answer, just some thoughts:

On Tue, Apr 24, 2018 at 05:51:40PM +0300, Oleg Goldshmidt wrote:
> 
> Hi all,
> 
> I am trying to get my head around the problem of bringing network
> interfaces up and down and checking the state. I googled extensively,
> but I have not found an answer to the conundrum, and I am hoping that
> someone here may shed some light.
> 
> My target platform is Debian wheezy (no, I can't upgrade it), but what I
> describe below is very similar on an up-to-date Fedora 27 (that,
> obviously, has a very different set of userspace tools and a very
> different kernel).
> 
> What I am trying to achieve is as follows. Assume that the system in
> question gets a command (imagine an API of sorts) to reconfigure one of
> its multiple interfaces. Let's say that the control interface is eth0
> and the request is to reconfigure eth3. Here, "reconfigure" may mean,
> e.g., "change the static IP address and maybe some routing rules" (or
> toggle between static and DHCP or whatever - staying static seems
> conceptually simpler).
> 
> So the is an implementation (bash, run as root, etc.) that goes, in
> essence,
> 
> * stop interface eth3
> * change eth3 configuration
> * start interface eth3
> 
> which looks natural enough. It is also natural that there are stop() and
> start() functions that may include some subtleties such as flushing IP
> address, etc. The start() and stop() functions are used in other
> workflows and, in general, one would like to check whether the interface
> is up or down, at least to avoid superfluous error messages when one
> tries to bring up an interface that is already up, etc. (Such messages
> may pollute things for the API client, and hiding stderr in general is
> not a good idea because real errors may be lost.)
> 
> The problem is that whatever I do in stop() (or by hand), e.g.,
> 
> * ifconfig eth3 down
> * ifdown --force eth3 (and --no-scripts, and whatever - on Debian)
> * ip link set eth3 down

Why don't you stop the interface with 'ifdown'? Also: why not use ip
(and generally: iproute2 tools) everywhere?

> 
> etc., etc., with infinite variations, the UP flag remains set (I also
> check with ifconfig, ip link show, etc.).
> 
> Technically, the UP flag is the IFF_UP bit in the ifr_flags field of
> struct ifreq accessible through a ioctl (cf. man 7 netdevice). I went as
> far as writing a C program that uses the ioctl(s) (SIOCGIFFLAGS,
> SIOCSIFFLAGS) directly. To no avail: right after I toggle IFF_UP I check
> it again and it is *always* up... Again, this is on both Debian wheezy
> (old, kernel 3.2.0) and Fedora 27 (fully updated, kernel 4.15.17)...
> 
> It also does not depend on whether the interface is designated as "auto"
> (on Debian) or anything else I could think of.

"auto" only means this interface is to be started at boot. So it indeed
should be irrelevant.

-- 
Tzafrir Cohen         | tzafrir at jabber.org | VIM is
http://tzafrir.org.il |                    | a Mutt's
tzafrir at cohens.org.il |                    |  best
tzafrir at debian.org    |                    | friend



More information about the Linux-il mailing list