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'
38 nodes
=> { optional
=> 1},
39 peers
=> { optional
=> 0 },
40 mtu
=> { optional
=> 1 },
41 dns
=> { optional
=> 1 },
42 reversedns
=> { optional
=> 1 },
43 dnszone
=> { optional
=> 1 },
44 ipam
=> { optional
=> 0 },
48 # Plugin implementation
49 sub generate_sdn_config
{
50 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $subnet_cfg, $interfaces_config, $config) = @_;
52 my $tag = $vnet->{tag
};
53 my $alias = $vnet->{alias
};
54 my $multicastaddress = $plugin_config->{'multicast-address'};
56 @peers = PVE
::Tools
::split_list
($plugin_config->{'peers'}) if $plugin_config->{'peers'};
57 my $vxlan_iface = "vxlan_$vnetid";
59 die "missing vxlan tag" if !$tag;
61 my ($ifaceip, $iface) = PVE
::Network
::SDN
::Zones
::Plugin
::find_local_ip_interface_peers
(\
@peers);
64 $mtu = $interfaces_config->{$iface}->{mtu
} - 50 if $interfaces_config->{$iface}->{mtu
};
65 $mtu = $plugin_config->{mtu
} if $plugin_config->{mtu
};
68 my @iface_config = ();
69 push @iface_config, "vxlan-id $tag";
71 foreach my $address (@peers) {
72 next if $address eq $ifaceip;
73 push @iface_config, "vxlan_remoteip $address";
77 push @iface_config, "mtu $mtu" if $mtu;
78 push(@{$config->{$vxlan_iface}}, @iface_config) if !$config->{$vxlan_iface};
82 push @iface_config, "bridge_ports $vxlan_iface";
83 push @iface_config, "bridge_stp off";
84 push @iface_config, "bridge_fd 0";
85 if($vnet->{vlanaware
}) {
86 push @iface_config, "bridge-vlan-aware yes";
87 push @iface_config, "bridge-vids 2-4094";
89 push @iface_config, "mtu $mtu" if $mtu;
90 push @iface_config, "alias $alias" if $alias;
91 push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
96 sub vnet_update_hook
{
97 my ($class, $vnet_cfg, $vnetid, $zone_cfg) = @_;
99 my $vnet = $vnet_cfg->{ids
}->{$vnetid};
100 my $tag = $vnet->{tag
};
102 raise_param_exc
({ tag
=> "missing vxlan tag"}) if !defined($tag);
103 raise_param_exc
({ tag
=> "vxlan tag max value is 16777216"}) if $tag > 16777216;
105 # verify that tag is not already defined globally (vxlan-id are unique)
106 foreach my $id (keys %{$vnet_cfg->{ids
}}) {
107 next if $id eq $vnetid;
108 my $othervnet = $vnet_cfg->{ids
}->{$id};
109 my $other_tag = $othervnet->{tag
};
110 my $other_zoneid = $othervnet->{zone
};
111 my $other_zone = $zone_cfg->{ids
}->{$other_zoneid};
112 next if $other_zone->{type
} ne 'vxlan' && $other_zone->{type
} ne 'evpn';
113 raise_param_exc
({ tag
=> "vxlan tag $tag already exist in vnet $id in zone $other_zoneid "}) if $other_tag && $tag eq $other_tag;