[pve-devel] [PATCH] add vlan aware bridge ifupdown script v2

Alexandre DERUMIER aderumier at odiso.com
Tue Jul 28 14:42:41 CEST 2015


Here the script for vlan.

Note than ifupdown is now able to manage vlan tag for "auto iface..", without the vlan package, for some named interfaces (ethX,bondX,wlanX).
But the problem, is that it's not working for vlan interface in bridge_ports and other random named interfaces.

here a bug report from michael : https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=742547

Anyway, to avoid double ifup (1 by ifdown and 1 by vlan script), the vlan script test if the device already exist.



if-pre-up.d/vlan
------------------
#!/bin/sh

# Most of this stuff is to enable vlans
case "$IFACE" in
  # Ignore any alias (#272891) which uses <interface>:<alabel>
  *:*)
    exit 0
  ;;
  vlan[0-9]*)
    VLANID=`echo $IFACE|sed "s/vlan*//"`
  ;;
  *.[0-9]*)
    VLANID=`echo $IFACE|sed "s/[a-zA-Z0-9]*\.//g"`
    IF_VLAN_RAW_DEVICE=`echo $IFACE|sed "s/\([a-zA-Z0-9]*\)\..*/\1/"`
  ;;

  *)
    exit 0
  ;;
esac

if [ -n "$IF_VLAN_RAW_DEVICE" ]; then
    if ! ip link show dev "$IF_VLAN_RAW_DEVICE" > /dev/null; then
        echo "$IF_VLAN_RAW_DEVICE does not exist, unable to create $IFACE"
        exit 1
    fi
    if [ ! -e "/sys/class/net/$IFACE" ]; then
        ip link set up dev $IF_VLAN_RAW_DEVICE
	ip link add link $IF_VLAN_RAW_DEVICE name $IFACE type vlan id $VLANID 
    fi
    if [ -e "/sys/class/net/$IF_VLAN_RAW_DEVICE/bridge/vlan_filtering" ]; then 
	bridge vlan add dev $IF_VLAN_RAW_DEVICE vid $VLANID self
    fi
fi

# This is not vlan specific, and should actually go somewhere else.
if [ -n "$IF_HW_MAC_ADDRESS" ]; then
    ip link set $IFACE address $IF_HW_MAC_ADDRESS
fi



if-post-down.d/vlan
--------------------
#!/bin/sh

# If IFACE is an automagic vlan interface (without the vlan-raw-device
# parameter) then let's try to discover the magic here..  Another way would be
# to just probe for the right device name in /proc/net/vlan

case "$IFACE" in
  # Ignore any alias (#272891)
  *:*)
    exit 0
  ;;
  *.[0-9]*)
    # Silently ignore interfaces which ifupdown handles on its own
    # If IF_BRIDGE_PORTS is set, probably we're called by bridge-utils
    [ -z "$IF_VLAN_RAW_DEVICE" -a -z "$IF_BRIDGE_PORTS" ] && exit 0
    IF_VLAN_RAW_DEVICE=`echo $IFACE|sed "s/\([A-Za-z0-9]*\)\..*/\1/"`
  ;;
  # Test for vlan raw device (#196890, #292648)
  *)
    [ -z "$IF_VLAN_RAW_DEVICE" ] && exit 0
  ;;
esac

if [ -e "/sys/class/net/$IFACE" ]; then
    ip link delete $IFACE
fi




----- Mail original -----
De: "dietmar" <dietmar at proxmox.com>
À: "aderumier" <aderumier at odiso.com>
Cc: "Wolfgang Bumiller" <w.bumiller at proxmox.com>, "pve-devel" <pve-devel at pve.proxmox.com>
Envoyé: Mardi 28 Juillet 2015 13:07:26
Objet: Re: [pve-devel] [PATCH] add vlan aware bridge ifupdown script v2

> I would like to send it to debian maintainers. (I don't known how much time it 
> could take). 
> 
> But first, I think we could remove the vlan package, and push scripts in 
> pve-manager package. 
> I can remove the vconfig binaries, so only 2-3 scripts are needed. 

Ah, OK - good idea. 

I will also add iproute2 packages from stretch to our repository. 



More information about the pve-devel mailing list