Using Ifupdown to Configure Transient Interfaces

Adding Context

So far, our laptop will configure its interfaces for any combination of docked/undocked and PCMCIA ethercard inserted/removed. This is good, but not quite a solution to the problem. We need to keep the PCMCIA card from being configured if the laptop is in the docking station. This seems difficult, given that ifupdown processes each interface individually and provides no context information.

Fortunately, the iface stanza provides the pre-up command. The pre-up command tells ifupdown to run an arbitrary program before brining an interface up. If the command fails, ifupdown will abort the operation and not even attempt to bring that interface up. It seems, then, that we should be able to run some kind of "dock query" in the card configuration to check for the absence of the dock before proceeding. For example:

iface card inet dhcp
  pre-up check-nodock
But what facilities are available to check for the dock? Again, the provided examples give us a start. The example script takes a kernel interface name and MAC address and uses ifconfig to compare them. It returns success if they match, failure otherwise. If we create a script,, that, instead, returns success only if they don't match, then we could do this:
iface card inet dhcp
  pre-up /usr/local/sbin/ eth0 00:20:E0:64:0B:28
which works for our specific case but would break if the docking ethernet interface were assigned to eth1 (say, after a kernel recompile).

A solution might exist, however, by revisiting our mapping. We can distinguish the exact interface with which our dock might be associated by using:
mapping eth0
        script /usr/local/sbin/
        map 00:50:DA:EB:41:73 card0
        map 00:20:E0:64:0B:28 dock

mapping eth1
        script /usr/local/sbin/
        map 00:50:DA:EB:41:73 card1
        map 00:20:E0:64:0B:28 dock
This gives us two logical interfaces for the PCMCIA card, card0 and card1, which express which kernel interface is assigned to the card (and thus, which one isn't assigned to the dock).

Now the rest is pretty easy. Create two card iface stanzas that check for the presence of the dock on the opposite interface:

# card found on eth0
iface card0 inet dhcp
        # check that eth1 is not dock
        pre-up /usr/local/sbin/ eth1 00:20:E0:64:0B:28

# card found on eth1
iface card1 inet dhcp
        # check that eth0 is not dock
        pre-up /usr/local/sbin/ eth0 00:20:E0:64:0B:28

# always configure dock if its there.
iface dock inet static

Voila! The PCMCIA card won't be configured unless the the laptop is undocked.

10/08/2002 Greg Wiley

Copyright © 2.001K Orthogony Netspan. All rights reserved.
Email webmaster