1 package PVE
::Network
::SDN
::Zones
::VlanPlugin
;
5 use PVE
::Network
::SDN
::Zones
::Plugin
;
6 use PVE
::Exception
qw(raise raise_param_exc);
8 use base
('PVE::Network::SDN::Zones::Plugin');
14 PVE
::JSONSchema
::register_format
('pve-sdn-vlanrange', \
&pve_verify_sdn_vlanrange
);
15 sub pve_verify_sdn_vlanrange
{
18 PVE
::Network
::SDN
::Zones
::Plugin
::parse_tag_number_or_range
($vlanstr, '4096');
34 nodes
=> { optional
=> 1},
35 'bridge' => { optional
=> 0 },
36 mtu
=> { optional
=> 1 },
37 dns
=> { optional
=> 1 },
38 reversedns
=> { optional
=> 1 },
39 dnszone
=> { optional
=> 1 },
40 ipam
=> { optional
=> 0 },
44 # Plugin implementation
45 sub generate_sdn_config
{
46 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $controller_cfg, $subnet_cfg, $interfaces_config, $config) = @_;
48 my $bridge = $plugin_config->{bridge
};
49 PVE
::Network
::SDN
::Zones
::Plugin
::find_bridge
($bridge);
51 my $vlan_aware = PVE
::Network
::SDN
::Zones
::Plugin
::is_vlanaware
($bridge);
52 my $is_ovs = PVE
::Network
::SDN
::Zones
::Plugin
::is_ovs
($bridge);
54 my $tag = $vnet->{tag
};
55 my $alias = $vnet->{alias
};
56 my $mtu = $plugin_config->{mtu
};
58 my $vnet_uplink = "ln_".$vnetid;
59 my $vnet_uplinkpeer = "pr_".$vnetid;
61 my @iface_config = ();
65 # keep vmbrXvY for compatibility with existing network
66 # eth0----ovs vmbr0--(ovsintport tag)---->vnet---->vm
69 push @iface_config, "ovs_type OVSIntPort";
70 push @iface_config, "ovs_bridge $bridge";
71 push @iface_config, "ovs_mtu $mtu" if $mtu;
72 if($vnet->{vlanaware
}) {
73 push @iface_config, "ovs_options vlan_mode=dot1q-tunnel other_config:qinq-ethtype=802.1q tag=$tag";
75 push @iface_config, "ovs_options tag=$tag";
77 push(@{$config->{$vnet_uplink}}, @iface_config) if !$config->{$vnet_uplink};
79 #redefine main ovs bridge, ifupdown2 will merge ovs_ports
81 push @iface_config, "ovs_ports $vnet_uplink";
82 push(@{$config->{$bridge}}, @iface_config);
84 } elsif ($vlan_aware) {
85 # eth0----vlanaware bridge vmbr0--(vmbr0.X tag)---->vnet---->vm
86 $vnet_uplink = "$bridge.$tag";
89 # keep vmbrXvY for compatibility with existing network
90 # eth0<---->eth0.X----vmbr0v10------vnet---->vm
92 my $bridgevlan = $bridge."v".$tag;
94 my @bridge_ifaces = PVE
::Network
::SDN
::Zones
::Plugin
::get_bridge_ifaces
($bridge);
96 my $bridge_ports = "";
97 foreach my $bridge_iface (@bridge_ifaces) {
98 $bridge_ports .= " $bridge_iface.$tag";
102 push @iface_config, "link-type veth";
103 push @iface_config, "veth-peer-name $vnet_uplinkpeer";
104 push(@{$config->{$vnet_uplink}}, @iface_config) if !$config->{$vnet_uplink};
107 push @iface_config, "link-type veth";
108 push @iface_config, "veth-peer-name $vnet_uplink";
109 push(@{$config->{$vnet_uplinkpeer}}, @iface_config) if !$config->{$vnet_uplinkpeer};
112 push @iface_config, "bridge_ports $bridge_ports $vnet_uplinkpeer";
113 push @iface_config, "bridge_stp off";
114 push @iface_config, "bridge_fd 0";
115 push(@{$config->{$bridgevlan}}, @iface_config) if !$config->{$bridgevlan};
120 push @iface_config, "bridge_ports $vnet_uplink";
121 push @iface_config, "bridge_stp off";
122 push @iface_config, "bridge_fd 0";
123 if($vnet->{vlanaware
}) {
124 push @iface_config, "bridge-vlan-aware yes";
125 push @iface_config, "bridge-vids 2-4094";
127 push @iface_config, "mtu $mtu" if $mtu;
128 push @iface_config, "alias $alias" if $alias;
129 push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
135 my ($class, $plugin_config, $zone, $vnetid, $vnet, $status) = @_;
137 my $bridge = $plugin_config->{bridge
};
140 if (!-d
"/sys/class/net/$bridge") {
141 push @$err_msg, "missing $bridge";
145 my $vlan_aware = PVE
::Network
::SDN
::Zones
::Plugin
::is_vlanaware
($bridge);
146 my $is_ovs = PVE
::Network
::SDN
::Zones
::Plugin
::is_ovs
($bridge);
148 my $tag = $vnet->{tag
};
149 my $vnet_uplink = "ln_".$vnetid;
150 my $vnet_uplinkpeer = "pr_".$vnetid;
153 my $ifaces = [ $vnetid, $bridge ];
155 push @$ifaces, $vnet_uplink;
156 } elsif (!$vlan_aware) {
157 my $bridgevlan = $bridge."v".$tag;
158 push @$ifaces, $bridgevlan;
159 push @$ifaces, $vnet_uplink;
160 push @$ifaces, $vnet_uplinkpeer;
163 foreach my $iface (@{$ifaces}) {
164 if (!$status->{$iface}->{status
}) {
165 push @$err_msg, "missing $iface";
166 } elsif ($status->{$iface}->{status
} ne 'pass') {
167 push @$err_msg, "error iface $iface";
173 sub vnet_update_hook
{
174 my ($class, $vnet_cfg, $vnetid, $zone_cfg) = @_;
176 my $vnet = $vnet_cfg->{ids
}->{$vnetid};
177 my $tag = $vnet->{tag
};
179 raise_param_exc
({ tag
=> "missing vlan tag"}) if !defined($vnet->{tag
});
180 raise_param_exc
({ tag
=> "vlan tag max value is 4096"}) if $vnet->{tag
} > 4096;
182 # verify that tag is not already defined in another vnet on same zone
183 foreach my $id (keys %{$vnet_cfg->{ids
}}) {
184 next if $id eq $vnetid;
185 my $othervnet = $vnet_cfg->{ids
}->{$id};
186 my $other_tag = $othervnet->{tag
};
187 next if $vnet->{zone
} ne $othervnet->{zone
};
188 raise_param_exc
({ tag
=> "tag $tag already exist in vnet $id"}) if $other_tag && $tag eq $other_tag;