On Mar 30, 2012, at 9:42 AM, xinglp wrote:

> 在 2012年3月31日 上午12:05,Bruce Dubbs <bruce.du...@gmail.com> 写道:
>> xinglp wrote:
>>> http://www.linuxfromscratch.org/lfs/view/development/scripts/apds27.html
>>> 
>>>       if [ "$(ip addr show ${IFACE} | grep 'inet ')" != ""  ]; then
>>>          log_info_msg "Bringing down the ${IFACE} interface..."
>>>          ip link set ${IFACE} down
>>>          evaluate_retval
>>>       fi
>>> 
>>> should be
>>> 
>>>       if [ "$(ip addr show ${IFACE} | grep 'inet ')" == ""  ]; then
>>>          log_info_msg "Bringing down the ${IFACE} interface..."
>>>          ip link set ${IFACE} down
>>>          evaluate_retval
>>>       fi
>> 
>> I'm missing something here.  Why would we need to set an interface down
>> if the inet line is null?
> Maybe more than one address have been set to this
> interface(ipv4-static dhcp pppoe etc...)
> We've talked about this months before.

Xinglp is correct about the virtual interfaces.

[ Thinking aloud about a related issue-- ]

The current setup requires that services handle the hardware interface (like 
setting UP/DOWN state and MTU).  That seems unclean.  It also creates some 
confusion about bringing interfaces down.

It seems unclean to have ifdown set DOWN on an interface because multiple 
virtual interfaces don't virtualize the UP/DOWN state.  I've been trying to 
maintain a clean abstraction between hardware settings (e.g., MTU) from service 
settings (like IP).

But, it seems like it'd be hard to prevent ifdown from examining the IP 
settings (which I guess is a simple and straightforward way to implement 
service-side reference-counting of IP addresses configured on the one physical 
interface).

I think we still need a variable to point to the physical interface (I'm 
proposing PHYS for this purpose), and another for the logical interface.  IFACE 
could be used for this purpose--especially since that's what it actually means 
now.  This would allow IFACE to keep its current meaning, and it would replace 
INTERFACES in bridge with PHYS.  Importantly, ifup could be adjusted to look 
for IFACE if PHYS isn't found, and assume they are the same.  The upside is it 
doesn't require anyone to change their ifconfig files if they're using a pretty 
vanilla setup (i.e., non-bridged).

=========================================================================
A new vanilla file would look the same as the old one (without MTU):

        ONBOOT=yes
        IFACE=eth0
        MTU=9000
        SERVICE="ipv4-static"
        IP=192.168.0.250
        GATEWAY=192.168.0.1
        PREFIX=24 

And the bridge file would look a bit simpler than my original proposal:

        ONBOOT=yes
        PHYS="eth0"
        MTU=9000
        IFACE="br0"
        SERVICE="bridge ipv4-static"
        STP=no
        IP=192.168.0.250
        GATEWAY=192.168.0.1
        PREFIX=24

(MTU was thrown in as an example.)
=========================================================================

This would allow ifup to set MTU, it allows ifup/ifdown to set the UP/DOWN 
state properly, it allows ifdown to examine the logical interface for IP 
addresses (as a "hack-esque" but simple way to reference-count the number of 
"sharers" of the physical interface).  It also keeps IFACE around, though I'm 
not sure at what cost for things like bonding interfaces (or other 
"multi-layered" setups), though this all could be revisited when the time comes.

[ Back to the issue at hand-- ]

The current code:

>>> if [ "$(ip addr show ${IFACE} | grep 'inet ')" != ""  ]; then
>>>          log_info_msg "Bringing down the ${IFACE} interface..."
>>>          ip link set ${IFACE} down
>>>          evaluate_retval
>>>       fi

is not really correct, but for a different reason.  We should not set DOWN for 
an interface with an IP address still configured.  Hopefully no one is relying 
on that functionality.  And, those who are should be doing it through their own 
customs scripts.  IMO, that's bad behavior.

In fact, ifdown should *only* set DOWN when there are no IP configs still 
attached to the logical interface.  If there *is* an IP config still attached 
to the logical interface, then ifdown should just report a warning that it 
cannot set DOWN on that interface because either 1) there are still IP configs 
on other linked virtual interfaces, or 2) that the services failed to properly 
tear down the IP configs.  It might be hard to distinguish between the two, 
without polluting ifdown with more service-like code.

It should be up to the service(s) to bring down the configs.  With respect to 
virtual interfaces, presumably each eth0:n will be its own config file, and 
each ipv4-static (or whatever service gives the IP config) should tear down the 
IP config, too.  The check in ifdown is really just 
reference-counting-in-disguise to see if's "all clear" to set DOWN on the 
physical interface.

I'm busy ATM, but I'd be willing to get back to this in a week or so (adding 
support for virtual interfaces in my proposal).

        Q



-- 
http://linuxfromscratch.org/mailman/listinfo/lfs-dev
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page

Reply via email to