sslug-teknik team mailing list archive
-
sslug-teknik team
-
Mailing list archive
-
Message #41801
Re: Hvordan bestemmes rækkefølgen af netkort
In <00b801c13b5c$881d82f0$254ef9c3@xxxxxx> "Jeppe Koefoed" <jeppe@xxxxxxxxxx> writes:
>Jeg har en maskine med 3 netkort med min egen kerne som _ikke_ benytter
>moduler. Derfor har jeg kompileret drivere til netkortene ind i kernen.
>Problemet er nu hvilken rækkefølge kortene får ved opstart. Det kan ses i
>dmesg hvordan de et efter et detekteres og dermed bliver tildelt eth0, eth1
>og eth2. Problemet er nu, at det åbentbart er forskelligt fra kerneversion
>til kerneversion i hvilken rækkefølge de bliver detekteret (og dermed er det
>besværligt at tildele ip osv. da det er baseret på ethX).
Jeg så en meget effektiv løsning på dette problem for nogen tid siden
på linux-kernel listen. Dengang handlede det om en laptop hvor netkortet
skiftede navn når den blev docked/undocked, men teknikken kan også bruges
i andre sammenhænge:
--- start på besked ---
From: Keith Owens <kaos@xxxxxxxxxx>
To: Jim Roland <jim@xxxxxxxxxx>
cc: linux-kernel@xxxxxxxxxxxxxxxx, linux-laptop@xxxxxxxxxxxxxxxx
Subject: Re: Ethernet-multiple NICs and laptop
Date: Sat, 08 Apr 2000 13:06:53 +1000
Message-ID: <1511.955163213@xxxxxxxx-net>
On Thu, 6 Apr 2000 08:32:36 -0600 (CST),
Jim Roland <jim@xxxxxxxxxx> wrote:
>I have a port replicator with a 3Com 3C905C NIC built-in. When I'm docked,
>my port replicator's NIC enables with eth0 and my PCMCIA network card
>enables with eth1. When I'm undocked my PCMCIA card takes over eth0. How
>do I get the PCMCIA card to ALWAYS use eth1???
Don't bother trying. eth0/eth1 are what the kernel calls the hardware
and is always going to be hardware dependent. The mistake is trying to
override the kernel's hardware numbering, this mistake arises because
the user wants to use eth0 and eth1 instead of "eth-pcmcia" and
"eth-docking". That is, you are trying to use a kernel construct as a
user identifier.
The solution to the problem of multiple NICs is to use separate kernel
and user identifiers. Anything in user space should use the user
identifier to get the kernel identifier. "Any problem can be solved by
another level of indirection".
Example.
In directory /etc/sysconfig/network-scripts (this is RedHat, other
distributions may use different names) there are ifup and ifdown
scripts. These are general scripts that obtain IP addresses and
routing data from ifcfg-<device>, e.g. ifcfg-eth0. Instead of hard
coding the pcmcia data in ifcfg-eth0 and the docking station data in
ifcfg-eth1, make the data dynamic. Create two files in
/etc/sysconfig/network-scripts for the pcmcia card and the docking
station data, call them eth-pcmcia and eth-docking. In those files you
store the IP data for the relevant card, lines like
# eth-pcmcia
USERDEVICENAME=eth-pcmcia
ONBOOT=no
BOOTPROTO=dhcp
# eth-docking
USERDEVICENAME=eth-docking
IPADDR=192.168.255.3
NETMASK=255.255.255.0
NETWORK=192.168.255.0
BROADCAST=192.168.255.255
GATEWAY=192.168.255.1
ONBOOT=yes
The job of ifcfg-eth[01] is now to work out which card is being
accessed and to map the kernel identifier (eth[01]) to a user
identifier (eth-{docking,pcmcia}). This example ifcfg-eth0 script uses
MAC addresses, replace the sample MAC addresses with your own. If you
do not like using MAC to identify cards, find some other way to
identify which physical card is being configured. Replace both the
ifcfg-eth0 and ifcfg-eth1 files (make one a link to the other) with
# ifcfg-eth*
USERDEVICENAME=
case `ifconfig $DEVICE | sed -ne 's/.*HWaddr *\([^ ]*\) */\1/p'` in
00:10:A4:F3:A3:79) . eth-pcmcia;; # read pcmcia data
00:80:AD:79:82:D8) . eth-docking;; # read docking station data
*) echo Unknown MAC address, please update ifcfg-eth0
esac
[ -n "$USERDEVICENAME" ] && echo $DEVICE > /var/tmp/$USERDEVICENAME
Now it does not matter whether the kernel calls a network card eth0 or
eth1 or even eth99. The configure scripts assign the correct IP and
routing data no matter what the kernel id is. If you need to access
the kernel id, use the value in /var/tmp/eth-*, e.g.
route add -net 192.168.0.0 netmask 255.255.0.0 dev `cat /var/tmp/eth-docking`
I use this technique on multi NIC boxes where device numbers have a
tendency to move around as slots or IRQs or the kernel scan order
changes. Instead of trying to force the kernel into your order, accept
whatever the kernel gives you and handle the mapping in user space.
--- slut på besked ---
--
Henrik Storner <henrik@xxxxxxx>
Jeg søger stadig job - http://www.hswn.dk/job/
References