[Users] How to configure range of auto-generated MAC addresses for VETH devices?

Axton axton.grams at gmail.com
Wed Mar 20 23:58:36 EDT 2013


On Wed, Feb 6, 2013 at 7:19 AM, Roman Haefeli <reduzent at gmail.com> wrote:
>
> Hi!
>
> When adding VETH interfaces to containers with the following command:
>
> vzct set CTID --netif_add eth0,,,,vzbr0 --save
>
> an automatically generated MAC address of the format  00:18:51:XX:XX:XX
> is configured for the container.
>
> This can cause problems with bridges, since bridges seem to use the MAC
> address of the member with the lowest MAC address. So if I start said
> container on the hostnode, and the hostnode's physical NIC has a MAC
> 00:30:48:XX:XX:XX, the MAC of vzbr0 switches from  00:30:48:XX:XX:XX to
> 00:18:51:XX:XX:XX (and vice versa when stopping said CT).
>
> This MAC address switching causes network lags for all members of the
> bridge vzbr0.
>
> Of course, I can manually change the configured MAC address in each CT's
> ctid.conf (which I did in the past), but I wonder if there is a way to
> configure the range of the auto-generated MAC addresses.
>
> Roman

I update the script /usr/sbin/vznetaddbr as follows.  This retains the
original mac of the bridge on the HN regardless of the mac used by the
CT.

root at cluster-02:/usr/sbin# diff -ub vznetaddbr.original vznetaddbr
--- vznetaddbr.original 2013-03-02 11:27:37.456405654 -0600
+++ vznetaddbr  2013-03-02 11:32:49.414553255 -0600
@@ -29,6 +29,9 @@
     [ -n "$bridge" ] ||
        bridge=vmbr0

+    # Get the current mac address for the interface
+    brmac=`cat /sys/class/net/vlan40/address`
+
     echo "Adding interface $host_ifname to bridge $bridge on CT0 for CT$VEID"
     ip link set dev "$host_ifname" up
     ip addr add 0.0.0.0/0 dev "$host_ifname"
@@ -36,6 +39,9 @@
     echo 1 >"/proc/sys/net/ipv4/conf/$host_ifname/forwarding"
     brctl addif "$bridge" "$host_ifname"

+    # Retain the bridge's existing MAC address when the veth
interfaces are added to the bridge
+    ip link set dev $bridge address $brmac
+
     break
 done


This works on my machines because all the bridge interfaces share the
same physical interface (hence, mac address).  You may need to adjust
to use the mac based on the bridge if this does not fit your
situation.

For example, instead of the following:

@@ -29,6 +29,9 @@
     [ -n "$bridge" ] ||
        bridge=vmbr0

+    # Get the current mac address for the interface
+    brmac=`cat /sys/class/net/vlan40/address`
+

You could use something like this:

@@ -29,6 +29,9 @@
     [ -n "$bridge" ] ||
        bridge=vmbr0

+    # Get the current mac address for the interface
+    brmac=`cat /sys/class/net/$bridge/address`
+

That works in every case I can think of.

Axton Grams


More information about the Users mailing list