2019-11-26 10:00:24 +01:00
|
|
|
package PVE::Network::SDN::Controllers::EvpnPlugin;
|
2019-08-29 12:32:47 +02:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
2020-01-16 11:14:53 +01:00
|
|
|
|
2019-09-09 08:45:53 +02:00
|
|
|
use PVE::INotify;
|
|
|
|
use PVE::JSONSchema qw(get_standard_option);
|
2020-01-16 11:14:53 +01:00
|
|
|
use PVE::Tools qw(run_command file_set_contents file_get_contents);
|
|
|
|
|
|
|
|
use PVE::Network::SDN::Controllers::Plugin;
|
2019-11-28 09:40:27 +01:00
|
|
|
use PVE::Network::SDN::Zones::Plugin;
|
2020-11-25 10:01:36 +01:00
|
|
|
use Net::IP;
|
2020-01-16 11:14:53 +01:00
|
|
|
|
2019-11-26 10:00:16 +01:00
|
|
|
use base('PVE::Network::SDN::Controllers::Plugin');
|
2019-08-29 12:32:47 +02:00
|
|
|
|
|
|
|
sub type {
|
2019-11-26 10:00:24 +01:00
|
|
|
return 'evpn';
|
2019-09-30 11:03:32 +02:00
|
|
|
}
|
|
|
|
|
2019-08-29 12:32:47 +02:00
|
|
|
sub properties {
|
|
|
|
return {
|
2020-01-16 11:14:15 +01:00
|
|
|
asn => {
|
|
|
|
type => 'integer',
|
|
|
|
description => "autonomous system number",
|
2022-02-11 10:33:25 +01:00
|
|
|
minimum => 0,
|
|
|
|
maximum => 4294967296
|
2020-01-16 11:14:15 +01:00
|
|
|
},
|
|
|
|
peers => {
|
|
|
|
description => "peers address list.",
|
|
|
|
type => 'string', format => 'ip-list'
|
|
|
|
},
|
2019-08-29 12:32:47 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub options {
|
|
|
|
return {
|
2020-01-16 11:14:15 +01:00
|
|
|
'asn' => { optional => 0 },
|
|
|
|
'peers' => { optional => 0 },
|
2019-08-29 12:32:47 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
# Plugin implementation
|
2019-09-30 11:03:32 +02:00
|
|
|
sub generate_controller_config {
|
2020-11-25 10:01:36 +01:00
|
|
|
my ($class, $plugin_config, $controller_cfg, $id, $uplinks, $config) = @_;
|
2019-08-29 12:32:47 +02:00
|
|
|
|
2020-07-01 09:57:32 +02:00
|
|
|
my @peers;
|
|
|
|
@peers = PVE::Tools::split_list($plugin_config->{'peers'}) if $plugin_config->{'peers'};
|
2019-08-29 12:32:47 +02:00
|
|
|
|
2020-11-25 10:01:36 +01:00
|
|
|
my $local_node = PVE::INotify::nodename();
|
|
|
|
|
2019-09-09 08:45:53 +02:00
|
|
|
my $asn = $plugin_config->{asn};
|
2020-11-25 10:01:36 +01:00
|
|
|
my $ebgp = undef;
|
|
|
|
my $loopback = undef;
|
|
|
|
my $autortas = undef;
|
|
|
|
my $bgprouter = find_bgp_controller($local_node, $controller_cfg);
|
|
|
|
if($bgprouter) {
|
|
|
|
$ebgp = 1 if $plugin_config->{'asn'} ne $bgprouter->{asn};
|
|
|
|
$loopback = $bgprouter->{loopback} if $bgprouter->{loopback};
|
|
|
|
$asn = $bgprouter->{asn} if $bgprouter->{asn};
|
|
|
|
$autortas = $plugin_config->{'asn'} if $ebgp;
|
|
|
|
}
|
2019-09-09 08:45:53 +02:00
|
|
|
|
|
|
|
return if !$asn;
|
2019-08-29 12:32:47 +02:00
|
|
|
|
2020-01-16 11:14:15 +01:00
|
|
|
my $bgp = $config->{frr}->{router}->{"bgp $asn"} //= {};
|
|
|
|
|
2020-11-25 10:01:36 +01:00
|
|
|
my ($ifaceip, $interface) = PVE::Network::SDN::Zones::Plugin::find_local_ip_interface_peers(\@peers, $loopback);
|
2019-08-29 12:32:47 +02:00
|
|
|
|
2020-11-25 10:01:36 +01:00
|
|
|
my $remoteas = $ebgp ? "external" : $asn;
|
2019-09-09 08:45:50 +02:00
|
|
|
|
2020-11-25 10:01:36 +01:00
|
|
|
#global options
|
2020-01-16 11:14:15 +01:00
|
|
|
my @controller_config = (
|
|
|
|
"bgp router-id $ifaceip",
|
|
|
|
"no bgp default ipv4-unicast",
|
|
|
|
"coalesce-time 1000",
|
|
|
|
);
|
2019-08-29 12:32:47 +02:00
|
|
|
|
2020-11-25 10:01:36 +01:00
|
|
|
push(@{$bgp->{""}}, @controller_config) if keys %{$bgp} == 0;
|
|
|
|
|
|
|
|
@controller_config = ();
|
|
|
|
|
|
|
|
#VTEP neighbors
|
|
|
|
push @controller_config, "neighbor VTEP peer-group";
|
|
|
|
push @controller_config, "neighbor VTEP remote-as $remoteas";
|
|
|
|
push @controller_config, "neighbor VTEP bfd";
|
|
|
|
|
|
|
|
if($ebgp && $loopback) {
|
|
|
|
push @controller_config, "neighbor VTEP ebgp-multihop 10";
|
|
|
|
push @controller_config, "neighbor VTEP update-source $loopback";
|
|
|
|
}
|
|
|
|
|
|
|
|
# VTEP peers
|
2019-08-29 12:32:47 +02:00
|
|
|
foreach my $address (@peers) {
|
|
|
|
next if $address eq $ifaceip;
|
2020-11-25 10:01:36 +01:00
|
|
|
push @controller_config, "neighbor $address peer-group VTEP";
|
2019-09-03 08:25:00 +02:00
|
|
|
}
|
2019-09-09 08:45:53 +02:00
|
|
|
|
2020-01-16 11:14:15 +01:00
|
|
|
push(@{$bgp->{""}}, @controller_config);
|
2019-09-09 08:45:53 +02:00
|
|
|
|
2020-11-25 10:01:36 +01:00
|
|
|
# address-family l2vpn
|
2019-11-26 10:00:29 +01:00
|
|
|
@controller_config = ();
|
2022-02-11 10:33:26 +01:00
|
|
|
push @controller_config, "neighbor VTEP route-map MAP_VTEP_OUT out";
|
2020-11-25 10:01:36 +01:00
|
|
|
push @controller_config, "neighbor VTEP activate";
|
2019-11-26 10:00:29 +01:00
|
|
|
push @controller_config, "advertise-all-vni";
|
2020-11-25 10:01:36 +01:00
|
|
|
push @controller_config, "autort as $autortas" if $autortas;
|
2020-01-16 11:14:15 +01:00
|
|
|
push(@{$bgp->{"address-family"}->{"l2vpn evpn"}}, @controller_config);
|
2019-08-29 12:32:47 +02:00
|
|
|
|
2022-02-11 10:33:26 +01:00
|
|
|
push(@{$config->{frr_routemap}->{'MAP_VTEP_OUT'}}, []);
|
|
|
|
|
2019-08-29 12:32:47 +02:00
|
|
|
return $config;
|
|
|
|
}
|
|
|
|
|
2019-11-26 10:00:29 +01:00
|
|
|
sub generate_controller_zone_config {
|
2020-11-25 10:01:36 +01:00
|
|
|
my ($class, $plugin_config, $controller, $controller_cfg, $id, $uplinks, $config) = @_;
|
|
|
|
|
|
|
|
my $local_node = PVE::INotify::nodename();
|
2019-09-30 11:03:33 +02:00
|
|
|
|
2020-05-19 18:37:44 +02:00
|
|
|
my $vrf = "vrf_$id";
|
2019-09-30 11:03:33 +02:00
|
|
|
my $vrfvxlan = $plugin_config->{'vrf-vxlan'};
|
2020-11-25 10:01:36 +01:00
|
|
|
my $exitnodes = $plugin_config->{'exitnodes'};
|
2022-02-11 10:33:26 +01:00
|
|
|
my $exitnodes_primary = $plugin_config->{'exitnodes-primary'};
|
2021-08-23 15:22:15 +02:00
|
|
|
my $advertisesubnets = $plugin_config->{'advertise-subnets'};
|
2021-08-23 15:22:16 +02:00
|
|
|
my $exitnodes_local_routing = $plugin_config->{'exitnodes-local-routing'};
|
2022-02-11 10:33:28 +01:00
|
|
|
my $rt_import = [PVE::Tools::split_list($plugin_config->{'rt-import'})] if $plugin_config->{'rt-import'};
|
2020-11-25 10:01:36 +01:00
|
|
|
|
2019-11-26 10:00:29 +01:00
|
|
|
my $asn = $controller->{asn};
|
2022-02-11 10:33:27 +01:00
|
|
|
my @peers = PVE::Tools::split_list($controller->{'peers'}) if $controller->{'peers'};
|
2020-11-25 10:01:36 +01:00
|
|
|
my $ebgp = undef;
|
|
|
|
my $loopback = undef;
|
|
|
|
my $autortas = undef;
|
|
|
|
my $bgprouter = find_bgp_controller($local_node, $controller_cfg);
|
|
|
|
if($bgprouter) {
|
|
|
|
$ebgp = 1 if $controller->{'asn'} ne $bgprouter->{asn};
|
|
|
|
$loopback = $bgprouter->{loopback} if $bgprouter->{loopback};
|
|
|
|
$asn = $bgprouter->{asn} if $bgprouter->{asn};
|
|
|
|
$autortas = $controller->{'asn'} if $ebgp;
|
|
|
|
}
|
2019-09-30 11:03:33 +02:00
|
|
|
|
|
|
|
return if !$vrf || !$vrfvxlan || !$asn;
|
|
|
|
|
2022-02-11 10:33:27 +01:00
|
|
|
my ($ifaceip, $interface) = PVE::Network::SDN::Zones::Plugin::find_local_ip_interface_peers(\@peers, $loopback);
|
|
|
|
|
2020-01-16 11:14:15 +01:00
|
|
|
# vrf
|
2019-11-26 10:00:29 +01:00
|
|
|
my @controller_config = ();
|
|
|
|
push @controller_config, "vni $vrfvxlan";
|
|
|
|
push(@{$config->{frr}->{vrf}->{"$vrf"}}, @controller_config);
|
2019-09-30 11:03:33 +02:00
|
|
|
|
2020-11-25 10:01:36 +01:00
|
|
|
#main vrf router
|
|
|
|
@controller_config = ();
|
2022-02-11 10:33:27 +01:00
|
|
|
push @controller_config, "bgp router-id $ifaceip";
|
2020-11-25 10:01:36 +01:00
|
|
|
# push @controller_config, "!";
|
|
|
|
push(@{$config->{frr}->{router}->{"bgp $asn vrf $vrf"}->{""}}, @controller_config);
|
2019-11-26 10:00:30 +01:00
|
|
|
|
2020-11-25 10:01:36 +01:00
|
|
|
if ($autortas) {
|
|
|
|
push(@{$config->{frr}->{router}->{"bgp $asn vrf $vrf"}->{"address-family"}->{"l2vpn evpn"}}, "route-target import $autortas:$vrfvxlan");
|
|
|
|
push(@{$config->{frr}->{router}->{"bgp $asn vrf $vrf"}->{"address-family"}->{"l2vpn evpn"}}, "route-target export $autortas:$vrfvxlan");
|
|
|
|
}
|
2019-09-30 11:03:33 +02:00
|
|
|
|
2020-12-03 10:19:40 +01:00
|
|
|
my $is_gateway = $exitnodes->{$local_node};
|
|
|
|
|
2019-09-30 11:03:33 +02:00
|
|
|
if ($is_gateway) {
|
|
|
|
|
2022-02-11 10:33:26 +01:00
|
|
|
if($exitnodes_primary && $exitnodes_primary ne $local_node) {
|
|
|
|
my $routemap_config = ();
|
|
|
|
push @{$routemap_config}, "match evpn vni $vrfvxlan";
|
|
|
|
push @{$routemap_config}, "match evpn route-type prefix";
|
|
|
|
push @{$routemap_config}, "set metric 200";
|
|
|
|
unshift(@{$config->{frr_routemap}->{'MAP_VTEP_OUT'}}, $routemap_config);
|
|
|
|
}
|
|
|
|
|
2021-08-23 15:22:16 +02:00
|
|
|
if (!$exitnodes_local_routing) {
|
|
|
|
@controller_config = ();
|
|
|
|
#import /32 routes of evpn network from vrf1 to default vrf (for packet return)
|
|
|
|
push @controller_config, "import vrf $vrf";
|
|
|
|
push(@{$config->{frr}->{router}->{"bgp $asn"}->{"address-family"}->{"ipv4 unicast"}}, @controller_config);
|
|
|
|
push(@{$config->{frr}->{router}->{"bgp $asn"}->{"address-family"}->{"ipv6 unicast"}}, @controller_config);
|
2019-09-30 11:03:33 +02:00
|
|
|
|
2021-08-23 15:22:16 +02:00
|
|
|
@controller_config = ();
|
|
|
|
#redistribute connected to be able to route to local vms on the gateway
|
|
|
|
push @controller_config, "redistribute connected";
|
|
|
|
push(@{$config->{frr}->{router}->{"bgp $asn vrf $vrf"}->{"address-family"}->{"ipv4 unicast"}}, @controller_config);
|
|
|
|
push(@{$config->{frr}->{router}->{"bgp $asn vrf $vrf"}->{"address-family"}->{"ipv6 unicast"}}, @controller_config);
|
|
|
|
}
|
2019-09-30 11:03:33 +02:00
|
|
|
|
2019-11-26 10:00:29 +01:00
|
|
|
@controller_config = ();
|
2019-09-30 11:03:33 +02:00
|
|
|
#add default originate to announce 0.0.0.0/0 type5 route in evpn
|
2019-11-26 10:00:29 +01:00
|
|
|
push @controller_config, "default-originate ipv4";
|
|
|
|
push @controller_config, "default-originate ipv6";
|
|
|
|
push(@{$config->{frr}->{router}->{"bgp $asn vrf $vrf"}->{"address-family"}->{"l2vpn evpn"}}, @controller_config);
|
2021-08-23 15:22:15 +02:00
|
|
|
} elsif ($advertisesubnets) {
|
|
|
|
|
|
|
|
@controller_config = ();
|
|
|
|
#redistribute connected networks
|
|
|
|
push @controller_config, "redistribute connected";
|
|
|
|
push(@{$config->{frr}->{router}->{"bgp $asn vrf $vrf"}->{"address-family"}->{"ipv4 unicast"}}, @controller_config);
|
|
|
|
push(@{$config->{frr}->{router}->{"bgp $asn vrf $vrf"}->{"address-family"}->{"ipv6 unicast"}}, @controller_config);
|
|
|
|
|
|
|
|
@controller_config = ();
|
|
|
|
#advertise connected networks type5 route in evpn
|
|
|
|
push @controller_config, "advertise ipv4 unicast";
|
|
|
|
push @controller_config, "advertise ipv6 unicast";
|
|
|
|
push(@{$config->{frr}->{router}->{"bgp $asn vrf $vrf"}->{"address-family"}->{"l2vpn evpn"}}, @controller_config);
|
2019-09-30 11:03:33 +02:00
|
|
|
}
|
|
|
|
|
2022-02-11 10:33:28 +01:00
|
|
|
if($rt_import) {
|
|
|
|
@controller_config = ();
|
|
|
|
foreach my $rt (sort @{$rt_import}) {
|
|
|
|
push @controller_config, "route-target import $rt";
|
|
|
|
}
|
|
|
|
push(@{$config->{frr}->{router}->{"bgp $asn vrf $vrf"}->{"address-family"}->{"l2vpn evpn"}}, @controller_config);
|
|
|
|
}
|
|
|
|
|
2019-09-30 11:03:33 +02:00
|
|
|
return $config;
|
|
|
|
}
|
|
|
|
|
2021-08-23 15:22:16 +02:00
|
|
|
sub generate_controller_vnet_config {
|
|
|
|
my ($class, $plugin_config, $controller, $zone, $zoneid, $vnetid, $config) = @_;
|
|
|
|
|
|
|
|
my $exitnodes = $zone->{'exitnodes'};
|
|
|
|
my $exitnodes_local_routing = $zone->{'exitnodes-local-routing'};
|
|
|
|
|
|
|
|
return if !$exitnodes_local_routing;
|
|
|
|
|
|
|
|
my $local_node = PVE::INotify::nodename();
|
|
|
|
my $is_gateway = $exitnodes->{$local_node};
|
|
|
|
|
|
|
|
return if !$is_gateway;
|
|
|
|
|
|
|
|
my $subnets = PVE::Network::SDN::Vnets::get_subnets($vnetid, 1);
|
|
|
|
my @controller_config = ();
|
|
|
|
foreach my $subnetid (sort keys %{$subnets}) {
|
|
|
|
my $subnet = $subnets->{$subnetid};
|
|
|
|
my $cidr = $subnet->{cidr};
|
|
|
|
push @controller_config, "ip route $cidr 10.255.255.2 xvrf_$zoneid";
|
|
|
|
}
|
|
|
|
push(@{$config->{frr}->{''}}, @controller_config);
|
|
|
|
}
|
|
|
|
|
2019-08-29 12:32:47 +02:00
|
|
|
sub on_delete_hook {
|
2019-11-26 10:00:29 +01:00
|
|
|
my ($class, $controllerid, $zone_cfg) = @_;
|
2019-08-29 12:32:47 +02:00
|
|
|
|
2019-11-26 10:00:29 +01:00
|
|
|
# verify that zone is associated to this controller
|
|
|
|
foreach my $id (keys %{$zone_cfg->{ids}}) {
|
2020-01-16 11:14:15 +01:00
|
|
|
my $zone = $zone_cfg->{ids}->{$id};
|
|
|
|
die "controller $controllerid is used by $id"
|
|
|
|
if (defined($zone->{controller}) && $zone->{controller} eq $controllerid);
|
2019-08-29 12:32:52 +02:00
|
|
|
}
|
2019-08-29 12:32:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub on_update_hook {
|
2019-11-26 10:00:29 +01:00
|
|
|
my ($class, $controllerid, $controller_cfg) = @_;
|
2019-08-29 12:32:52 +02:00
|
|
|
|
2020-01-16 09:15:16 +01:00
|
|
|
# we can only have 1 evpn controller / 1 asn by server
|
|
|
|
|
2020-11-25 10:01:36 +01:00
|
|
|
my $controllernb = 0;
|
2019-11-26 10:00:29 +01:00
|
|
|
foreach my $id (keys %{$controller_cfg->{ids}}) {
|
|
|
|
next if $id eq $controllerid;
|
2020-01-16 11:14:15 +01:00
|
|
|
my $controller = $controller_cfg->{ids}->{$id};
|
2020-11-25 10:01:36 +01:00
|
|
|
next if $controller->{type} ne "evpn";
|
|
|
|
$controllernb++;
|
|
|
|
die "only 1 global evpn controller can be defined" if $controllernb > 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub find_bgp_controller {
|
|
|
|
my ($nodename, $controller_cfg) = @_;
|
|
|
|
|
|
|
|
my $controller = undef;
|
|
|
|
foreach my $id (keys %{$controller_cfg->{ids}}) {
|
|
|
|
$controller = $controller_cfg->{ids}->{$id};
|
|
|
|
next if $controller->{type} ne 'bgp';
|
|
|
|
next if $controller->{node} ne $nodename;
|
|
|
|
last;
|
2019-08-29 12:32:52 +02:00
|
|
|
}
|
2020-11-25 10:01:36 +01:00
|
|
|
|
|
|
|
return $controller;
|
2019-08-29 12:32:47 +02:00
|
|
|
}
|
|
|
|
|
2020-11-25 10:01:36 +01:00
|
|
|
|
2019-09-30 11:03:32 +02:00
|
|
|
sub sort_frr_config {
|
|
|
|
my $order = {};
|
|
|
|
$order->{''} = 0;
|
|
|
|
$order->{'vrf'} = 1;
|
|
|
|
$order->{'ipv4 unicast'} = 1;
|
|
|
|
$order->{'ipv6 unicast'} = 2;
|
|
|
|
$order->{'l2vpn evpn'} = 3;
|
|
|
|
|
|
|
|
my $a_val = 100;
|
|
|
|
my $b_val = 100;
|
|
|
|
|
|
|
|
$a_val = $order->{$a} if defined($order->{$a});
|
|
|
|
$b_val = $order->{$b} if defined($order->{$b});
|
|
|
|
|
2020-01-16 11:14:15 +01:00
|
|
|
if ($a =~ /bgp (\d+)$/) {
|
2019-09-30 11:03:32 +02:00
|
|
|
$a_val = 2;
|
|
|
|
}
|
|
|
|
|
2020-01-16 11:14:15 +01:00
|
|
|
if ($b =~ /bgp (\d+)$/) {
|
2019-09-30 11:03:32 +02:00
|
|
|
$b_val = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $a_val <=> $b_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub generate_frr_recurse{
|
|
|
|
my ($final_config, $content, $parentkey, $level) = @_;
|
|
|
|
|
|
|
|
my $keylist = {};
|
|
|
|
$keylist->{vrf} = 1;
|
|
|
|
$keylist->{'address-family'} = 1;
|
|
|
|
$keylist->{router} = 1;
|
|
|
|
|
|
|
|
my $exitkeylist = {};
|
|
|
|
$exitkeylist->{vrf} = 1;
|
|
|
|
$exitkeylist->{'address-family'} = 1;
|
|
|
|
|
2020-01-16 11:14:15 +01:00
|
|
|
# FIXME: make this generic
|
2019-09-30 11:03:32 +02:00
|
|
|
my $paddinglevel = undef;
|
2020-01-16 11:14:15 +01:00
|
|
|
if ($level == 1 || $level == 2) {
|
|
|
|
$paddinglevel = $level - 1;
|
2019-09-30 11:03:32 +02:00
|
|
|
} elsif ($level == 3 || $level == 4) {
|
2020-01-16 11:14:15 +01:00
|
|
|
$paddinglevel = $level - 2;
|
2019-09-30 11:03:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
my $padding = "";
|
|
|
|
$padding = ' ' x ($paddinglevel) if $paddinglevel;
|
|
|
|
|
2020-01-16 11:14:15 +01:00
|
|
|
if (ref $content eq 'HASH') {
|
2019-09-30 11:03:32 +02:00
|
|
|
foreach my $key (sort sort_frr_config keys %$content) {
|
|
|
|
if ($parentkey && defined($keylist->{$parentkey})) {
|
2020-01-16 11:14:15 +01:00
|
|
|
push @{$final_config}, $padding."!";
|
|
|
|
push @{$final_config}, $padding."$parentkey $key";
|
|
|
|
} elsif ($key ne '' && !defined($keylist->{$key})) {
|
|
|
|
push @{$final_config}, $padding."$key";
|
2019-09-30 11:03:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
my $option = $content->{$key};
|
|
|
|
generate_frr_recurse($final_config, $option, $key, $level+1);
|
|
|
|
|
|
|
|
push @{$final_config}, $padding."exit-$parentkey" if $parentkey && defined($exitkeylist->{$parentkey});
|
|
|
|
}
|
|
|
|
}
|
2019-08-29 12:32:47 +02:00
|
|
|
|
2019-09-30 11:03:32 +02:00
|
|
|
if (ref $content eq 'ARRAY') {
|
2020-01-16 11:14:15 +01:00
|
|
|
push @{$final_config}, map { $padding . "$_" } @$content;
|
2019-09-30 11:03:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-11 10:33:26 +01:00
|
|
|
sub generate_frr_routemap {
|
|
|
|
my ($final_config, $routemaps) = @_;
|
|
|
|
|
|
|
|
foreach my $id (sort keys %$routemaps) {
|
|
|
|
|
|
|
|
my $routemap = $routemaps->{$id};
|
|
|
|
my $order = 0;
|
|
|
|
foreach my $seq (@$routemap) {
|
|
|
|
$order++;
|
|
|
|
my @config = ();
|
|
|
|
push @config, "!";
|
|
|
|
push @config, "route-map $id permit $order";
|
|
|
|
push @config, map { " $_" } @$seq;
|
|
|
|
push @{$final_config}, @config;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-09 16:11:18 +01:00
|
|
|
sub generate_controller_rawconfig {
|
2019-09-30 11:03:32 +02:00
|
|
|
my ($class, $plugin_config, $config) = @_;
|
|
|
|
|
2019-11-26 10:00:30 +01:00
|
|
|
my $nodename = PVE::INotify::nodename();
|
|
|
|
|
2019-09-30 11:03:32 +02:00
|
|
|
my $final_config = [];
|
2022-02-11 10:33:31 +01:00
|
|
|
push @{$final_config}, "frr version 8.0.1";
|
2020-12-03 10:19:36 +01:00
|
|
|
push @{$final_config}, "frr defaults datacenter";
|
2019-11-26 10:00:30 +01:00
|
|
|
push @{$final_config}, "hostname $nodename";
|
2022-02-11 10:33:31 +01:00
|
|
|
push @{$final_config}, "log syslog informational";
|
|
|
|
push @{$final_config}, "service integrated-vtysh-config";
|
2019-09-30 11:03:32 +02:00
|
|
|
push @{$final_config}, "!";
|
|
|
|
|
2020-01-16 09:15:15 +01:00
|
|
|
if (-e "/etc/frr/frr.conf.local") {
|
|
|
|
generate_frr_recurse($final_config, $config->{frr}->{vrf}, "vrf", 1);
|
2022-02-11 10:33:26 +01:00
|
|
|
generate_frr_routemap($final_config, $config->{frr_routemap});
|
2020-01-16 09:15:15 +01:00
|
|
|
push @{$final_config}, "!";
|
|
|
|
|
2020-01-16 11:14:53 +01:00
|
|
|
my $local_conf = file_get_contents("/etc/frr/frr.conf.local");
|
|
|
|
chomp ($local_conf);
|
|
|
|
push @{$final_config}, $local_conf;
|
2020-01-16 09:15:15 +01:00
|
|
|
} else {
|
|
|
|
generate_frr_recurse($final_config, $config->{frr}, undef, 0);
|
2022-02-11 10:33:26 +01:00
|
|
|
generate_frr_routemap($final_config, $config->{frr_routemap});
|
2020-01-16 09:15:15 +01:00
|
|
|
}
|
2019-09-30 11:03:32 +02:00
|
|
|
|
|
|
|
push @{$final_config}, "!";
|
|
|
|
push @{$final_config}, "line vty";
|
|
|
|
push @{$final_config}, "!";
|
|
|
|
|
|
|
|
my $rawconfig = join("\n", @{$final_config});
|
|
|
|
|
2020-12-09 16:11:18 +01:00
|
|
|
return if !$rawconfig;
|
|
|
|
return $rawconfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub write_controller_config {
|
|
|
|
my ($class, $plugin_config, $config) = @_;
|
|
|
|
|
|
|
|
my $rawconfig = $class->generate_controller_rawconfig($plugin_config, $config);
|
2019-09-30 11:03:32 +02:00
|
|
|
return if !$rawconfig;
|
|
|
|
return if !-d "/etc/frr";
|
|
|
|
|
2020-01-16 11:14:53 +01:00
|
|
|
file_set_contents("/etc/frr/frr.conf", $rawconfig);
|
2019-09-30 11:03:32 +02:00
|
|
|
}
|
|
|
|
|
2019-09-30 11:03:36 +02:00
|
|
|
sub reload_controller {
|
|
|
|
my ($class) = @_;
|
|
|
|
|
|
|
|
my $conf_file = "/etc/frr/frr.conf";
|
2019-11-26 10:00:30 +01:00
|
|
|
my $bin_path = "/usr/lib/frr/frr-reload.py";
|
|
|
|
|
|
|
|
if (!-e $bin_path) {
|
|
|
|
warn "missing $bin_path. Please install frr-pythontools package";
|
|
|
|
return;
|
|
|
|
}
|
2019-09-30 11:03:36 +02:00
|
|
|
|
|
|
|
my $err = sub {
|
|
|
|
my $line = shift;
|
2019-11-26 10:00:30 +01:00
|
|
|
if ($line =~ /ERROR:/) {
|
|
|
|
warn "$line \n";
|
2019-09-30 11:03:36 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (-e $conf_file && -e $bin_path) {
|
2020-01-16 11:14:53 +01:00
|
|
|
run_command([$bin_path, '--stdout', '--reload', $conf_file], outfunc => {}, errfunc => $err);
|
2019-09-30 11:03:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-30 11:03:32 +02:00
|
|
|
1;
|
2019-08-29 12:32:47 +02:00
|
|
|
|
2019-09-30 11:03:33 +02:00
|
|
|
|