From: Mark on
Hello

As I understand typically the Layer2 switch may have one MAC address shared
by its every port (MAC address isn't necessary for frames forwarding, but is
for management functions). I would like to understand, how does the kernel
treat multiport switches - it it viewed as one single NIC, or every port is
a NIC for the kernel?

I believe it depends on a device driver's design - if so then what is the
right way to design the driver? And making it more complicated - how does
the OS view multiple VLANs, each of them may have its own IP address. Will
it be a single interface for OS?

Thanks for any valuable comments.

--
Mark

From: Philip Paeps on
Mark <mark_cruzNOTFORSPAM(a)hotmail.com> wrote:
> As I understand typically the Layer2 switch may have one MAC address shared
> by its every port (MAC address isn't necessary for frames forwarding, but is
> for management functions). I would like to understand, how does the kernel
> treat multiport switches - it it viewed as one single NIC, or every port is
> a NIC for the kernel?

It depends on the hardware. Most multiport Ethernet NICs I've seen, have a
MAC and a PHY per port. In this case, the kernel creates a network interface
device per port (eth0, eth1, eth2, eth3). If you bridge those all together,
the bridge will either use a randomly generated MAC address, or the address of
the first port you add to the bridge.

> I believe it depends on a device driver's design - if so then what is the
> right way to design the driver? And making it more complicated - how does
> the OS view multiple VLANs, each of them may have its own IP address. Will
> it be a single interface for OS?

In the case where a multiport card has a PHY and a MAC per card, the kernel
will see four distinct cards. If the card shares a MAC between all the PHYs,
the driver will only see frames addressed to that MAC. The chip may offer a
method to push other frames up too, but that depends. In the case of VLANs,
if the chip is a bit intelligent, it will handle them in hardware. If not,
the kernel will need to provide tagged frames and remove tags itself.

- Philip

--
Philip Paeps Please don't email any replies
philip(a)paeps.cx I follow the newsgroup.

hundred-and-one symptoms of being an internet addict:
21. Your dog has its own home page.
From: Pascal Hambourg on
Hello,

Philip Paeps a �crit :
> Mark <mark_cruzNOTFORSPAM(a)hotmail.com> wrote:
>> As I understand typically the Layer2 switch may have one MAC address shared
>> by its every port (MAC address isn't necessary for frames forwarding, but is
>> for management functions). I would like to understand, how does the kernel
>> treat multiport switches - it it viewed as one single NIC, or every port is
>> a NIC for the kernel?

What kind of switch are you talking about ? Hardware switch ? Linux
bridge created with brctl ? Virtual bridge such as VDE (virtual
distributed switch) ?

> It depends on the hardware. Most multiport Ethernet NICs I've seen, have a
> MAC and a PHY per port. In this case, the kernel creates a network interface
> device per port (eth0, eth1, eth2, eth3). If you bridge those all together,
> the bridge will either use a randomly generated MAC address, or the address of
> the first port you add to the bridge.

Actually the Linux bridge code uses the lowest MAC address of all ports.
IMO that sucks, because the bridge adress may change when you add a port.
From: Philip Paeps on
Pascal Hambourg <boite-a-spam(a)plouf.fr.eu.org> wrote:
> Philip Paeps a écrit :
>> Mark <mark_cruzNOTFORSPAM(a)hotmail.com> wrote:
>>> As I understand typically the Layer2 switch may have one MAC address shared
>>> by its every port (MAC address isn't necessary for frames forwarding, but is
>>> for management functions). I would like to understand, how does the kernel
>>> treat multiport switches - it it viewed as one single NIC, or every port is
>>> a NIC for the kernel?
>
> What kind of switch are you talking about ? Hardware switch ? Linux
> bridge created with brctl ? Virtual bridge such as VDE (virtual
> distributed switch) ?
>
>> It depends on the hardware. Most multiport Ethernet NICs I've seen, have a
>> MAC and a PHY per port. In this case, the kernel creates a network interface
>> device per port (eth0, eth1, eth2, eth3). If you bridge those all together,
>> the bridge will either use a randomly generated MAC address, or the address of
>> the first port you add to the bridge.
>
> Actually the Linux bridge code uses the lowest MAC address of all ports.
> IMO that sucks, because the bridge adress may change when you add a port.

I thought that has been made configurable. But it turns out misremember. It
also turns out that there's an amusing bug in the implementation. :-)

# brctl addbr br0
(MAC is now random)
# brctl addif br0 eth0
(MAC is now MAC of eth0)
# brctl addif br0 eth1
(MAC is now MAC of eth0)
# brctl delif br0 eth0
(MAC is now MAC of eth1)
# brctl delif br0 eth1
(MAC is now all zeros)

So indeed: it sucks that the address of the bridge may change, but it doesn't
change when you add interfaces (except for the first one). It changes when
you remove interfaces though. And it changes in a particularly nasty way when
you remove the last interface.

At one point, I modified the FreeBSD kernel to have the bridge take the MAC
address of the first interface put into the bridge. My implementation was
careful to keep track of the randomly generated address though, so that it
could be restored when the last interface was removed from the bridge.[1]

It was quickly discovered that MAC addresses changing in the network made a
number of things unpredictable, so I reverted that. It also turned out that
some hardware (and device drivers) tried to be clever about certain kinds of
frames addressed to (their perception of) their MAC address, which broke ARP
on some systems and even multicast in one case.

I don't know why the problems I saw on FreeBSD don't manifest themselves on
Linux (or if they do, why this manifestation doesn't cause as many problems).
I imagine it's more device driver related than anything, but that's just a
guess.

My current feeling is that bridges should keep their MAC addresses for their
entire lifetime. Either randomly generated or computed from a physical MAC
address belonging to an interface in the machine.

It's been a while since I've played with these things in depth though.

- Philip

[1] If you're interested in the FreeBSD implementation at all:

http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/net/if_bridge.c?rev=1.113
http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/net/if_bridge.c.diff?r1=1.112;r2=1.113



--
Philip Paeps Please don't email any replies
philip(a)paeps.cx I follow the newsgroup.

There is a solution to every problem;
the only difficulty is finding it.
From: Pascal Hambourg on
Philip Paeps a �crit :
> Pascal Hambourg <boite-a-spam(a)plouf.fr.eu.org> wrote:
>>
>> Actually the Linux bridge code uses the lowest MAC address of all ports.
>> IMO that sucks, because the bridge adress may change when you add a port.
>
> I thought that has been made configurable. But it turns out misremember. It
> also turns out that there's an amusing bug in the implementation. :-)
>
> # brctl addbr br0
> (MAC is now random)
> # brctl addif br0 eth0
> (MAC is now MAC of eth0)
> # brctl addif br0 eth1
> (MAC is now MAC of eth0)
> # brctl delif br0 eth0
> (MAC is now MAC of eth1)
> # brctl delif br0 eth1
> (MAC is now all zeros)
>
> So indeed: it sucks that the address of the bridge may change, but it doesn't
> change when you add interfaces (except for the first one).

It does change when the added interface has a lower MAC address. I bet
that eth0 has a lower address than eth1, so if you add eth1 first, then
the bridge address will change when you add eth0.