1 package PVE
::Network
::SDN
::Controllers
::BgpPlugin
;
7 use PVE
::JSONSchema
qw(get_standard_option);
8 use PVE
::Tools
qw(run_command file_set_contents file_get_contents);
10 use PVE
::Network
::SDN
::Controllers
::Plugin
;
11 use PVE
::Network
::SDN
::Zones
::Plugin
;
14 use base
('PVE::Network::SDN::Controllers::Plugin');
25 description
=> "Enable ebgp. (remote-as external)",
28 description
=> "source loopback interface.",
31 node
=> get_standard_option
('pve-node'),
37 'node' => { optional
=> 0 },
38 'asn' => { optional
=> 0 },
39 'peers' => { optional
=> 0 },
40 'ebgp' => { optional
=> 1 },
41 'loopback' => { optional
=> 1 },
45 # Plugin implementation
46 sub generate_controller_config
{
47 my ($class, $plugin_config, $controller, $id, $uplinks, $config) = @_;
50 @peers = PVE
::Tools
::split_list
($plugin_config->{'peers'}) if $plugin_config->{'peers'};
52 my $asn = $plugin_config->{asn
};
53 my $ebgp = $plugin_config->{ebgp
};
54 my $loopback = $plugin_config->{loopback
};
55 my $local_node = PVE
::INotify
::nodename
();
59 return if $local_node ne $plugin_config->{node
};
61 my $bgp = $config->{frr
}->{router
}->{"bgp $asn"} //= {};
63 my ($ifaceip, $interface) = PVE
::Network
::SDN
::Zones
::Plugin
::find_local_ip_interface_peers
(\
@peers, $loopback);
65 my $remoteas = $ebgp ?
"external" : $asn;
68 my @controller_config = (
69 "bgp router-id $ifaceip",
70 "no bgp default ipv4-unicast",
72 "bgp network import-check"
75 push(@{$bgp->{""}}, @controller_config) if keys %{$bgp} == 0;
77 @controller_config = ();
79 push @controller_config, "no bgp ebgp-requires-policy";
80 push @controller_config, "bgp disable-ebgp-connected-route-check" if $loopback;
85 push @controller_config, "neighbor BGP peer-group";
86 push @controller_config, "neighbor BGP remote-as $remoteas";
87 push @controller_config, "neighbor BGP bfd";
91 foreach my $address (@peers) {
92 push @controller_config, "neighbor $address peer-group BGP";
94 push(@{$bgp->{""}}, @controller_config);
96 # address-family unicast
98 my $ipversion = Net
::IP
::ip_is_ipv6
($ifaceip) ?
"ipv6" : "ipv4";
99 my $mask = Net
::IP
::ip_is_ipv6
($ifaceip) ?
"/128" : "32";
101 push(@{$bgp->{"address-family"}->{"$ipversion unicast"}}, "network $ifaceip/$mask") if $loopback;
102 push(@{$bgp->{"address-family"}->{"$ipversion unicast"}}, "neighbor BGP activate");
103 push(@{$bgp->{"address-family"}->{"$ipversion unicast"}}, "neighbor BGP soft-reconfiguration inbound");
109 sub generate_controller_zone_config
{
110 my ($class, $plugin_config, $controller, $controller_cfg, $id, $uplinks, $config) = @_;
115 my ($class, $controllerid, $zone_cfg) = @_;
117 # verify that zone is associated to this controller
118 foreach my $id (keys %{$zone_cfg->{ids
}}) {
119 my $zone = $zone_cfg->{ids
}->{$id};
120 die "controller $controllerid is used by $id"
121 if (defined($zone->{controller
}) && $zone->{controller
} eq $controllerid);
126 my ($class, $controllerid, $controller_cfg) = @_;
128 # we can only have 1 bgp controller by node
129 my $local_node = PVE
::INotify
::nodename
();
130 my $controllernb = 0;
131 foreach my $id (keys %{$controller_cfg->{ids
}}) {
132 next if $id eq $controllerid;
133 my $controller = $controller_cfg->{ids
}->{$id};
134 next if $controller->{type
} ne "bgp";
135 next if $controller->{node
} ne $local_node;
137 die "only 1 bgp controller can be defined" if $controllernb > 1;
141 sub generate_controller_rawconfig
{
142 my ($class, $plugin_config, $config) = @_;
146 sub write_controller_config
{
147 my ($class, $plugin_config, $config) = @_;
151 sub reload_controller
{