[pve-devel] [pve-network] vlan plugin: add support for no vlan-aware bridge
Thomas Lamprecht
t.lamprecht at proxmox.com
Fri May 8 12:10:49 CEST 2020
On 5/8/20 11:00 AM, Alexandre Derumier wrote:
> Some users could have problem with vlan-aware and some nics.
>
> Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
> ---
> PVE/Network/SDN/Zones/Plugin.pm | 6 +++--
> PVE/Network/SDN/Zones/VlanPlugin.pm | 39 +++++++++++++++++++++++++++--
> 2 files changed, 41 insertions(+), 4 deletions(-)
>
> diff --git a/PVE/Network/SDN/Zones/Plugin.pm b/PVE/Network/SDN/Zones/Plugin.pm
> index aa53cce..2335d9e 100644
> --- a/PVE/Network/SDN/Zones/Plugin.pm
> +++ b/PVE/Network/SDN/Zones/Plugin.pm
> @@ -219,7 +219,8 @@ sub get_bridge_vlan {
> sub tap_create {
> my ($class, $plugin_config, $vnet, $iface, $vnetid) = @_;
>
> - my ($bridge, undef) = $class->get_bridge_vlan($plugin_config, $vnetid);
> + my $tag = $vnet->{tag};
> + my ($bridge, undef) = $class->get_bridge_vlan($plugin_config, $vnetid, $tag);
> die "unable to get bridge setting\n" if !$bridge;
>
> PVE::Network::tap_create($iface, $bridge);
> @@ -228,7 +229,8 @@ sub tap_create {
> sub veth_create {
> my ($class, $plugin_config, $vnet, $veth, $vethpeer, $vnetid, $hwaddr) = @_;
>
> - my ($bridge, undef) = $class->get_bridge_vlan($plugin_config, $vnetid);
> + my $tag = $vnet->{tag};
> + my ($bridge, undef) = $class->get_bridge_vlan($plugin_config, $vnetid, $tag);
> die "unable to get bridge setting\n" if !$bridge;
>
> PVE::Network::veth_create($veth, $vethpeer, $bridge, $hwaddr);
> diff --git a/PVE/Network/SDN/Zones/VlanPlugin.pm b/PVE/Network/SDN/Zones/VlanPlugin.pm
> index 28d6a00..b0d3784 100644
> --- a/PVE/Network/SDN/Zones/VlanPlugin.pm
> +++ b/PVE/Network/SDN/Zones/VlanPlugin.pm
> @@ -32,13 +32,47 @@ sub options {
> return {
> nodes => { optional => 1},
> 'bridge' => { optional => 0 },
> + mtu => { optional => 1 }
> };
> }
>
> # Plugin implementation
> sub generate_sdn_config {
> my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $interfaces_config, $config) = @_;
> - return "";
> +
> + my $bridge = $plugin_config->{bridge};
> + my $vlan_aware = PVE::Tools::file_read_firstline("/sys/class/net/$bridge/bridge/vlan_filtering");
> + my $is_ovs = 1 if !-d "/sys/class/net/$bridge/brif";
> + return if $vlan_aware || $is_ovs;
this was changed from return "" to return undef, is that OK?
> +
> + my $tag = $vnet->{tag};
> + my $alias = $vnet->{alias};
> + my $mtu = $plugin_config->{mtu} if $plugin_config->{mtu};
> + my $bridgevlan = $bridge."v".$tag;
> +
> + my @bridge_ifaces = ();
> + my $dir = "/sys/class/net/$bridge/brif";
> + PVE::Tools::dir_glob_foreach($dir, '(((eth|bond)\d+|en[^.]+)(\.\d+)?)', sub {
> + push @bridge_ifaces, $_[0];
> + });
> +
> + my $bridge_ports = "";
> + $bridge_ports = "none" if scalar(@bridge_ifaces) == 0;
> +
> + foreach my $bridge_iface (@bridge_ifaces) {
> + $bridge_ports .= " $bridge_iface.$tag";
> + }
> +
> + #vnet bridge (keep vmbrXvY for compatibility)
> + my @iface_config = ();
> + push @iface_config, "bridge_ports $bridge_ports";
> + push @iface_config, "bridge_stp off";
> + push @iface_config, "bridge_fd 0";
> + push @iface_config, "mtu $mtu" if $mtu;
> + push @iface_config, "alias $alias" if $alias;
> + push(@{$config->{$bridgevlan}}, @iface_config) if !$config->{$vnetid};
> +
> + return $config;
> }
>
> sub status {
> @@ -71,7 +105,8 @@ sub get_bridge_vlan {
> my $vlan_aware = PVE::Tools::file_read_firstline("/sys/class/net/$bridge/bridge/vlan_filtering");
> my $is_ovs = 1 if !-d "/sys/class/net/$bridge/brif";
>
> - die "bridge $bridge is not vlan aware" if !$is_ovs && !$vlan_aware;
> +
> + return ($bridge."v".$tag, undef) if !$is_ovs && !$vlan_aware;
>
> return ($bridge, $tag);
> }
>
More information about the pve-devel
mailing list