1 package PVE
::Network
::SDN
::Zones
::EvpnPlugin
;
5 use PVE
::Network
::SDN
::Zones
::VxlanPlugin
;
6 use PVE
::Exception
qw(raise raise_param_exc);
7 use PVE
::JSONSchema
qw(get_standard_option);
8 use PVE
::Tools
qw($IPV4RE);
14 use PVE
::Network
::SDN
::Controllers
::EvpnPlugin
;
16 use base
('PVE::Network::SDN::Zones::VxlanPlugin');
26 description
=> "l3vni.",
30 description
=> "Frr router name",
34 description
=> "Anycast logical router mac address",
35 optional
=> 1, format
=> 'mac-addr'
37 'exitnodes' => get_standard_option
('pve-node-list'),
44 nodes
=> { optional
=> 1},
45 'vrf-vxlan' => { optional
=> 0 },
46 controller
=> { optional
=> 0 },
47 exitnodes
=> { optional
=> 1 },
48 mtu
=> { optional
=> 1 },
49 mac
=> { optional
=> 1 },
50 dns
=> { optional
=> 1 },
51 reversedns
=> { optional
=> 1 },
52 dnszone
=> { optional
=> 1 },
53 ipam
=> { optional
=> 0 },
57 # Plugin implementation
58 sub generate_sdn_config
{
59 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $controller_cfg, $subnet_cfg, $interfaces_config, $config) = @_;
61 my $tag = $vnet->{tag
};
62 my $alias = $vnet->{alias
};
63 my $mac = $plugin_config->{'mac'};
65 my $vrf_iface = "vrf_$zoneid";
66 my $vrfvxlan = $plugin_config->{'vrf-vxlan'};
67 my $local_node = PVE
::INotify
::nodename
();
69 die "missing vxlan tag" if !$tag;
70 die "missing controller" if !$controller;
71 warn "vlan-aware vnet can't be enabled with evpn plugin" if $vnet->{vlanaware
};
73 my @peers = PVE
::Tools
::split_list
($controller->{'peers'});
74 my $bgprouter = PVE
::Network
::SDN
::Controllers
::EvpnPlugin
::find_bgp_controller
($local_node, $controller_cfg);
75 my $loopback = $bgprouter->{loopback
} if $bgprouter->{loopback
};
76 my ($ifaceip, $iface) = PVE
::Network
::SDN
::Zones
::Plugin
::find_local_ip_interface_peers
(\
@peers, $loopback);
79 $mtu = $interfaces_config->{$iface}->{mtu
} - 50 if $interfaces_config->{$iface}->{mtu
};
80 $mtu = $plugin_config->{mtu
} if $plugin_config->{mtu
};
83 my $vxlan_iface = "vxlan_$vnetid";
84 my @iface_config = ();
85 push @iface_config, "vxlan-id $tag";
86 push @iface_config, "vxlan-local-tunnelip $ifaceip" if $ifaceip;
87 push @iface_config, "bridge-learning off";
88 push @iface_config, "bridge-arp-nd-suppress on";
90 push @iface_config, "mtu $mtu" if $mtu;
91 push(@{$config->{$vxlan_iface}}, @iface_config) if !$config->{$vxlan_iface};
99 my $subnets = PVE
::Network
::SDN
::Vnets
::get_subnets
($vnetid, 1);
100 foreach my $subnetid (sort keys %{$subnets}) {
101 my $subnet = $subnets->{$subnetid};
102 my $cidr = $subnet->{cidr
};
103 my $mask = $subnet->{mask
};
105 my $gateway = $subnet->{gateway
};
107 push @iface_config, "address $gateway/$mask" if !defined($address->{$gateway});
108 $address->{$gateway} = 1;
111 my $iptables = undef;
112 my $checkrouteip = undef;
113 my $ipversion = Net
::IP
::ip_is_ipv6
($gateway) ?
6 : 4;
115 if ($ipversion == 6) {
117 $iptables = "ip6tables";
118 $checkrouteip = '2001:4860:4860::8888';
121 $iptables = "iptables";
122 $checkrouteip = '8.8.8.8';
125 if ($subnet->{snat
}) {
127 my $is_evpn_gateway = $plugin_config->{'exitnodes'}->{$local_node};
129 #find outgoing interface
130 my ($outip, $outiface) = PVE
::Network
::SDN
::Zones
::Plugin
::get_local_route_ip
($checkrouteip);
131 if ($outip && $outiface && $is_evpn_gateway) {
132 #use snat, faster than masquerade
133 push @iface_config, "post-up $iptables -t nat -A POSTROUTING -s '$cidr' -o $outiface -j SNAT --to-source $outip";
134 push @iface_config, "post-down $iptables -t nat -D POSTROUTING -s '$cidr' -o $outiface -j SNAT --to-source $outip";
135 #add conntrack zone once on outgoing interface
136 push @iface_config, "post-up $iptables -t raw -I PREROUTING -i fwbr+ -j CT --zone 1";
137 push @iface_config, "post-down $iptables -t raw -D PREROUTING -i fwbr+ -j CT --zone 1";
142 push @iface_config, "hwaddress $mac" if $mac;
143 push @iface_config, "bridge_ports $vxlan_iface";
144 push @iface_config, "bridge_stp off";
145 push @iface_config, "bridge_fd 0";
146 push @iface_config, "mtu $mtu" if $mtu;
147 push @iface_config, "alias $alias" if $alias;
148 push @iface_config, "ip-forward on" if $ipv4;
149 push @iface_config, "ip6-forward on" if $ipv6;
150 push @iface_config, "arp-accept on" if $ipv4||$ipv6;
151 push @iface_config, "vrf $vrf_iface" if $vrf_iface;
152 push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
157 push @iface_config, "vrf-table auto";
158 push @iface_config, "post-up ip route add vrf $vrf_iface unreachable default metric 4278198272";
159 push(@{$config->{$vrf_iface}}, @iface_config) if !$config->{$vrf_iface};
162 #l3vni vxlan interface
163 my $iface_vrf_vxlan = "vrfvx_$zoneid";
165 push @iface_config, "vxlan-id $vrfvxlan";
166 push @iface_config, "vxlan-local-tunnelip $ifaceip" if $ifaceip;
167 push @iface_config, "bridge-learning off";
168 push @iface_config, "bridge-arp-nd-suppress on";
169 push @iface_config, "mtu $mtu" if $mtu;
170 push(@{$config->{$iface_vrf_vxlan}}, @iface_config) if !$config->{$iface_vrf_vxlan};
173 my $brvrf = "vrfbr_$zoneid";
175 push @iface_config, "bridge-ports $iface_vrf_vxlan";
176 push @iface_config, "bridge_stp off";
177 push @iface_config, "bridge_fd 0";
178 push @iface_config, "mtu $mtu" if $mtu;
179 push @iface_config, "vrf $vrf_iface";
180 push(@{$config->{$brvrf}}, @iface_config) if !$config->{$brvrf};
188 my ($class, $zoneid, $zone_cfg, $controller_cfg) = @_;
190 # verify that controller exist
191 my $controller = $zone_cfg->{ids
}->{$zoneid}->{controller
};
192 if (!defined($controller_cfg->{ids
}->{$controller})) {
193 die "controller $controller don't exist";
195 die "$controller is not a evpn controller type" if $controller_cfg->{ids
}->{$controller}->{type
} ne 'evpn';
198 #vrf-vxlan need to be defined
200 my $vrfvxlan = $zone_cfg->{ids
}->{$zoneid}->{'vrf-vxlan'};
201 # verify that vrf-vxlan is not already declared in another zone
202 foreach my $id (keys %{$zone_cfg->{ids
}}) {
203 next if $id eq $zoneid;
204 die "vrf-vxlan $vrfvxlan is already declared in $id"
205 if (defined($zone_cfg->{ids
}->{$id}->{'vrf-vxlan'}) && $zone_cfg->{ids
}->{$id}->{'vrf-vxlan'} eq $vrfvxlan);
208 if (!defined($zone_cfg->{ids
}->{$zoneid}->{'mac'})) {
209 my $dc = PVE
::Cluster
::cfs_read_file
('datacenter.cfg');
210 $zone_cfg->{ids
}->{$zoneid}->{'mac'} = PVE
::Tools
::random_ether_addr
($dc->{mac_prefix
});
215 sub vnet_update_hook
{
216 my ($class, $vnet_cfg, $vnetid, $zone_cfg) = @_;
218 my $vnet = $vnet_cfg->{ids
}->{$vnetid};
219 my $tag = $vnet->{tag
};
221 raise_param_exc
({ tag
=> "missing vxlan tag"}) if !defined($tag);
222 raise_param_exc
({ tag
=> "vxlan tag max value is 16777216"}) if $tag > 16777216;
224 # verify that tag is not already defined globally (vxlan-id are unique)
225 foreach my $id (keys %{$vnet_cfg->{ids
}}) {
226 next if $id eq $vnetid;
227 my $othervnet = $vnet_cfg->{ids
}->{$id};
228 my $other_tag = $othervnet->{tag
};
229 my $other_zoneid = $othervnet->{zone
};
230 my $other_zone = $zone_cfg->{ids
}->{$other_zoneid};
231 next if $other_zone->{type
} ne 'vxlan' && $other_zone->{type
} ne 'evpn';
232 raise_param_exc
({ tag
=> "vxlan tag $tag already exist in vnet $id in zone $other_zoneid "}) if $other_tag && $tag eq $other_tag;