1 package PVE
::Network
::SDN
::Zones
::VxlanPlugin
;
5 use PVE
::Network
::SDN
::Zones
::Plugin
;
6 use PVE
::Tools
qw($IPV4RE);
8 use PVE
::Network
::SDN
::Controllers
::EvpnPlugin
;
9 use PVE
::Exception
qw(raise raise_param_exc);
11 use base
('PVE::Network::SDN::Zones::Plugin');
13 PVE
::JSONSchema
::register_format
('pve-sdn-vxlanrange', \
&pve_verify_sdn_vxlanrange
);
14 sub pve_verify_sdn_vxlanrange
{
17 PVE
::Network
::SDN
::Zones
::Plugin
::parse_tag_number_or_range
($vxlanstr, '16777216');
29 description
=> "peers address list.",
30 type
=> 'string', format
=> 'ip-list'
37 nodes
=> { optional
=> 1},
38 peers
=> { optional
=> 0 },
39 mtu
=> { optional
=> 1 },
40 dns
=> { optional
=> 1 },
41 reversedns
=> { optional
=> 1 },
42 dnszone
=> { optional
=> 1 },
43 ipam
=> { optional
=> 1 },
47 # Plugin implementation
48 sub generate_sdn_config
{
49 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $controller_cfg, $subnet_cfg, $interfaces_config, $config) = @_;
51 my $tag = $vnet->{tag
};
52 my $alias = $vnet->{alias
};
53 my $multicastaddress = $plugin_config->{'multicast-address'};
55 @peers = PVE
::Tools
::split_list
($plugin_config->{'peers'}) if $plugin_config->{'peers'};
56 my $vxlan_iface = "vxlan_$vnetid";
58 die "missing vxlan tag" if !$tag;
60 my ($ifaceip, $iface) = PVE
::Network
::SDN
::Zones
::Plugin
::find_local_ip_interface_peers
(\
@peers);
63 $mtu = $interfaces_config->{$iface}->{mtu
} - 50 if $interfaces_config->{$iface}->{mtu
};
64 $mtu = $plugin_config->{mtu
} if $plugin_config->{mtu
};
67 my @iface_config = ();
68 push @iface_config, "vxlan-id $tag";
70 for my $address (@peers) {
71 next if $address eq $ifaceip;
72 push @iface_config, "vxlan_remoteip $address";
76 push @iface_config, "mtu $mtu" if $mtu;
77 push(@{$config->{$vxlan_iface}}, @iface_config) if !$config->{$vxlan_iface};
81 push @iface_config, "bridge_ports $vxlan_iface";
82 push @iface_config, "bridge_stp off";
83 push @iface_config, "bridge_fd 0";
84 if ($vnet->{vlanaware
}) {
85 push @iface_config, "bridge-vlan-aware yes";
86 push @iface_config, "bridge-vids 2-4094";
88 push @iface_config, "mtu $mtu" if $mtu;
89 push @iface_config, "alias $alias" if $alias;
90 push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
95 sub vnet_update_hook
{
96 my ($class, $vnet_cfg, $vnetid, $zone_cfg) = @_;
98 my $vnet = $vnet_cfg->{ids
}->{$vnetid};
99 my $tag = $vnet->{tag
};
101 raise_param_exc
({ tag
=> "missing vxlan tag"}) if !defined($tag);
102 raise_param_exc
({ tag
=> "vxlan tag max value is 16777216"}) if $tag > 16777216;
104 # verify that tag is not already defined globally (vxlan-id are unique)
105 for my $id (sort keys %{$vnet_cfg->{ids
}}) {
106 next if $id eq $vnetid;
107 my $othervnet = $vnet_cfg->{ids
}->{$id};
108 my $other_tag = $othervnet->{tag
};
109 my $other_zoneid = $othervnet->{zone
};
110 my $other_zone = $zone_cfg->{ids
}->{$other_zoneid};
111 next if $other_zone->{type
} ne 'vxlan' && $other_zone->{type
} ne 'evpn';
112 raise_param_exc
({ tag
=> "vxlan tag $tag already exist in vnet $id in zone $other_zoneid "}) if $other_tag && $tag eq $other_tag;