[pve-devel] [PATCH] add vlan for testing

Dietmar Maurer dietmar at proxmox.com
Tue Mar 20 06:30:29 CET 2012


OK, committed that patch. 

I have a few question (inline):

> diff --git a/pve-bridge b/pve-bridge
> index 2d826cf..faf50fa 100755
> --- a/pve-bridge
> +++ b/pve-bridge
> @@ -3,6 +3,7 @@
>  use strict;
>  use PVE::QemuServer;
>  use PVE::Tools qw(run_command);
> +use PVE::Storage;
> 
>  my $iface = shift;
> 
> @@ -62,6 +63,58 @@ if ($net->{rate}) {
> 
>  }
> 
> +if ($net->{vlan}) {
> +
> +    my $vlan = $net->{vlan};
> +    my $bridgevlan = $bridge."v".$vlan;
> +
> +    #check if we have an only one ethX or bondX interface in the bridge
> +    my (undef, $interface) =
> PVE::Storage::dir_glob_regex("/sys/class/net/$bridge/brif/", '((eth|bond)\d+)');
> +    die "No interface in bridge" if !$interface;
> +    die "You can't have 2 physical interfaces on the same bridge"

Why is this limited to one interface? I just wonder if there is a technical point, or is that
to simplify things?

> + if(ref($interface) eq 'ARRAY');
> +
> +    my $interfacevlan = $interface.".".$vlan;
> +
> +    #create vlan on interface is not already exist
> +    unless (-d "/sys/class/net/$interfacevlan") {
> +    system ("/sbin/vconfig add $interface $vlan") == 0 ||
> +        die "can't add vlan $vlan to interface $interface\n";
> +    }
> +
> +    #be sure to have the interfacevlan up
> +    system ("/sbin/ip link set $interfacevlan up") == 0 ||
> +        die "can't up interface $interfacevlan\n";
> +
> +    # test if vlaninterface is already enslave in another bridge
> +    my $path="/sys/class/net/$interfacevlan/brport/bridge";
> +    if(-e $path) {
> +        my $targetbridge = readlink($path);
> +        if($targetbridge =~ m/([0-9A-Za-z]+)$/) {
> +                die "Interface $interfacevlan already exist in bridge $targetbridge" if
> $1 ne $bridgevlan;
> +        }
> +    }
> +
> +    #add bridgevlan if it doesn't already exist
> +    unless (-d "/sys/class/net/$bridgevlan") {
> +        system ("/usr/sbin/brctl addbr $bridgevlan") == 0 ||
> +            die "can't add bridge $bridgevlan\n";
> +    }

A bridge can have several options in /etc/network/interface. We need to
use the same options for the new bridge?

- Dietmar



More information about the pve-devel mailing list