1 package PVE
::Network
::SDN
::Zones
::VlanPlugin
;
5 use PVE
::Network
::SDN
::Zones
::Plugin
;
7 use base
('PVE::Network::SDN::Zones::Plugin');
13 PVE
::JSONSchema
::register_format
('pve-sdn-vlanrange', \
&pve_verify_sdn_vlanrange
);
14 sub pve_verify_sdn_vlanrange
{
17 PVE
::Network
::SDN
::Zones
::Plugin
::parse_tag_number_or_range
($vlanstr, '4096');
26 minimum
=> 1, maximum
=> 4096,
27 description
=> 'Uplink interface',
30 type
=> 'string', format
=> 'pve-sdn-vlanrange',
31 description
=> "Allowed vlan range",
39 'uplink-id' => { optional
=> 0 },
40 'vlan-allowed' => { optional
=> 1 },
44 # Plugin implementation
45 sub generate_sdn_config
{
46 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $config) = @_;
48 my $tag = $vnet->{tag
};
49 my $mtu = $vnet->{mtu
};
50 my $alias = $vnet->{alias
};
51 my $uplink = $plugin_config->{'uplink-id'};
53 die "missing vlan tag" if !$tag;
55 my $iface = $uplinks->{$uplink}->{name
};
56 $iface = "uplink${uplink}" if !$iface;
60 my @iface_config = ();
61 push @iface_config, "mtu $mtu" if $mtu;
62 push(@{$config->{$iface}}, @iface_config) if !$config->{$iface};
66 push @iface_config, "bridge_ports $iface";
67 push @iface_config, "bridge_stp off";
68 push @iface_config, "bridge_fd 0";
69 push @iface_config, "mtu $mtu" if $mtu;
70 push @iface_config, "alias $alias" if $alias;
71 push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
77 my ($class, $transportid, $sdn_cfg) = @_;
79 # verify that no vnet are associated to this transport
80 foreach my $id (keys %{$sdn_cfg->{ids
}}) {
81 my $sdn = $sdn_cfg->{ids
}->{$id};
82 die "transport $transportid is used by vnet $id"
83 if ($sdn->{type
} eq 'vnet' && defined($sdn->{zone
}) && $sdn->{zone
} eq $transportid);
88 my ($class, $transportid, $sdn_cfg) = @_;
90 my $transport = $sdn_cfg->{ids
}->{$transportid};
92 # verify that vlan-allowed don't conflict with another vlan-allowed transport
94 # verify that vlan-allowed is matching currently vnet tag in this transport
95 my $vlanallowed = $transport->{'vlan-allowed'};
97 foreach my $id (keys %{$sdn_cfg->{ids
}}) {
98 my $sdn = $sdn_cfg->{ids
}->{$id};
99 if ($sdn->{type
} eq 'vnet' && defined($sdn->{tag
})) {
100 if(defined($sdn->{zone
}) && $sdn->{zone
} eq $transportid) {
101 my $tag = $sdn->{tag
};
103 PVE
::Network
::SDN
::Zones
::Plugin
::parse_tag_number_or_range
($vlanallowed, '4096', $tag);
106 die "vlan $tag is not allowed in transport $transportid";