Re: How does "alias ethX drivername" in modules.conf work?

Riley Williams
2001-08-06T22:56:44Z

[-- Attachment #1: Type: TEXT/PLAIN, Size: 3312 bytes --]

Hi Thomas.

>> One of my systems has SIX ethernet cards, these being three ISA
>> and two PCI NE2000 clones and a DEC Tulip. Here's the relevant
>> section of modules.conf on the system in question:

>> Q> alias eth0 ne
>> Q> options eth0 io=0x340
>> Q> alias eth1 ne
>> Q> options eth1 io=0x320
>> Q> alias eth2 ne
>> Q> options eth2 io=0x2c0
>> Q> alias eth3 ne2k-pci
>> Q> alias eth4 ne2k-pci
>> Q> alias eth5 tulip

> ok, well this makes sense for the ISA cards. I have card A in my
> hand, I set the jumpers on it to an io port 0x340, stick it in
> slot X on my computer, plug the wire into it from network 1,
> then I mentally can map all the stuff together, so I know how to
> setup the network in Linux

> eth0 == io 0x340 == card A == slot X in my computer == network 1

> but, how can you tell the difference between eth3 and eth4 --
> and specify which *physical* card gets assigned to which virtual
> eth? name...ie, how do I know which pci slot is which eth?

That depends on the driver used to map those cards. Here's what I know
so far, mainly from experimentation:

1. The ne2k-pci driver assigns cards in ascending ethernet address
on this machine.

2. On the same machine, when I had three tulip cards installed, the
tulip driver assigned them in descending ethernet address.

3. Both of the above results are independant of the order the cards
are plugged into the PCI bus.

As a result, there is no simple answer to your question, and the
answer above probably depends to a large extent on factors other than
the card itself.

However, if the cards are controlled by different drivers, you can
influence the order they are detected in by your choice of entries in
modules.conf - in the example above, the ISA cards are always eth0,
eth1 and eth2, the NE2k-pci cards are always eth3 and eth4, and the
tulip card is always eth5, simply because that's what the said file
says.

> besides reading the motherboard documentation and maybe learning
> which direction and how the pci bus is ordered...which can
> differ between motherboard manufacturers and BIOS's, etc, etc.

Remember that every ethernet card has an ethernet address assigned to
it, this being the "HWaddr" reported by `ifconfig` and (in theory at
least) these are all unique. All you need to do is to determine the
ethernet address of each of the cards in your system, then see which
interface has that ethernet address assigned to it, and you've found
the match...

> and how do I change it if I don't like the default order (based
> off of pci scan order). what if I want card B, a pci card stuck
> in PCI slot Y to be eth4?

You could always add "options eth? io=0x????" lines for the PCI ports,
and hope the addresses you've specified don't get changed, but I'll
not guarantee this works as I've never tried it.

Probably of more use is to set the IP address for a particular
interface dependant on the ethernet address of the card supplying it.
The enclosed bash script should achieve that - it's basically the
`ifconfig` command with the port name replaced by its ethernet
address, but it only works for "eth?" ports. I've tried it on my
system, and it does the job it's designed to, but YMMV...

> I hope this is clearer...

I hope this helps...

Best wishes from Riley.

[-- Attachment #2: /usr/local/sbin/ifmap --]
[-- Type: TEXT/PLAIN, Size: 1504 bytes --]

#!/bin/bash

###############################################################################
#
# This script provides a version of the `ifconfig` command that expects to
# see the ethernet address associated with a particular port, and performs
# the stated actions on whichever ethernet interface has the specified
# ethernet address. All actions associated with the `ifconfig` command are
# supported, and the only change in syntax is that the port name of "eth?"
# is replaced by the associated ethernet address.
#
# If no ethernet interface is found with the specified ethernet address,
# this script uses a return value of 1, otherwise it uses a return value
# of 0.
#
###############################################################################

function assign() {
local HW="$1" OK=Y
declare -i N=0

shift 1
while [ $OK = Y ]; do
if ! port eth$N ; then
if ifconfig eth$N up 2> /dev/null ; then
if [ "`hwaddr eth$N`" != "${HW}" ]; then
ifconfig eth$N down
else
ifconfig eth$N "$@"
OK=$?
fi
else
OK=0
fi
fi
N=$N+1
done
return $OK
}

function hwaddr() {
ifconfig "$1" | grep "^$1" | tr ' ' '\n' | grep '[0-9A-F]:[0-9A-F]'
}

function port() {
ifconfig | grep ^eth | fgrep "$1" > /dev/null
}

if [ $# -gt 0 ]; then
if assign "$@" ; then
echo No ethernet interface with address "$1" found. >&2
exit 1
else
exit 0
fi
else
ifconfig
exit 0
fi