1 package PVE
::Network
::SDN
::VlanPlugin
;
5 use PVE
::Network
::SDN
::Plugin
;
7 use base
('PVE::Network::SDN::Plugin');
19 PVE
::JSONSchema
::register_format
('pve-sdn-vlanrange', \
&pve_verify_sdn_vlanrange
);
20 sub pve_verify_sdn_vlanrange
{
23 PVE
::Network
::SDN
::Plugin
::parse_tag_number_or_range
($vlanstr, '4096');
32 minimum
=> 1, maximum
=> 4096,
33 description
=> 'Uplink interface',
36 type
=> 'string', format
=> 'pve-sdn-vlanrange',
37 description
=> "Allowed vlan range",
45 'uplink-id' => { optional
=> 0 },
46 'vlan-allowed' => { optional
=> 1 },
50 # Plugin implementation
51 sub generate_sdn_config
{
52 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $config) = @_;
54 my $tag = $vnet->{tag
};
55 my $mtu = $vnet->{mtu
};
56 my $alias = $vnet->{alias
};
57 my $uplink = $plugin_config->{'uplink-id'};
59 die "missing vlan tag" if !$tag;
61 my $iface = $uplinks->{$uplink}->{name
};
62 $iface = "uplink${uplink}" if !$iface;
66 my @iface_config = ();
67 push @iface_config, "mtu $mtu" if $mtu;
68 push(@{$config->{$iface}}, @iface_config) if !$config->{$iface};
72 push @iface_config, "bridge_ports $iface";
73 push @iface_config, "bridge_stp off";
74 push @iface_config, "bridge_fd 0";
75 push @iface_config, "mtu $mtu" if $mtu;
76 push @iface_config, "alias $alias" if $alias;
77 push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
83 my ($class, $transportid, $sdn_cfg) = @_;
85 # verify that no vnet are associated to this transport
86 foreach my $id (keys %{$sdn_cfg->{ids
}}) {
87 my $sdn = $sdn_cfg->{ids
}->{$id};
88 die "transport $transportid is used by vnet $id"
89 if ($sdn->{type
} eq 'vnet' && defined($sdn->{transportzone
}) && $sdn->{transportzone
} eq $transportid);
94 my ($class, $transportid, $sdn_cfg) = @_;
96 my $transport = $sdn_cfg->{ids
}->{$transportid};
98 # verify that vlan-allowed don't conflict with another vlan-allowed transport
100 # verify that vlan-allowed is matching currently vnet tag in this transport
101 my $vlanallowed = $transport->{'vlan-allowed'};
103 foreach my $id (keys %{$sdn_cfg->{ids
}}) {
104 my $sdn = $sdn_cfg->{ids
}->{$id};
105 if ($sdn->{type
} eq 'vnet' && defined($sdn->{tag
})) {
106 if(defined($sdn->{transportzone
}) && $sdn->{transportzone
} eq $transportid) {
107 my $tag = $sdn->{tag
};
109 PVE
::Network
::SDN
::Plugin
::parse_tag_number_or_range
($vlanallowed, '4096', $tag);
112 die "vlan $tag is not allowed in transport $transportid";