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)",
32 description
=> "source loopback interface.",
35 node
=> get_standard_option
('pve-node'),
41 'node' => { optional
=> 0 },
42 'asn' => { optional
=> 0 },
43 'peers' => { optional
=> 0 },
44 'ebgp' => { optional
=> 1 },
45 'ebgp-multihop' => { optional
=> 1 },
46 'loopback' => { optional
=> 1 },
50 # Plugin implementation
51 sub generate_controller_config
{
52 my ($class, $plugin_config, $controller, $id, $uplinks, $config) = @_;
55 @peers = PVE
::Tools
::split_list
($plugin_config->{'peers'}) if $plugin_config->{'peers'};
57 my $asn = $plugin_config->{asn
};
58 my $ebgp = $plugin_config->{ebgp
};
59 my $ebgp_multihop = $plugin_config->{'ebgp-multihop'};
60 my $loopback = $plugin_config->{loopback
};
61 my $local_node = PVE
::INotify
::nodename
();
65 return if $local_node ne $plugin_config->{node
};
67 my $bgp = $config->{frr
}->{router
}->{"bgp $asn"} //= {};
69 my ($ifaceip, $interface) = PVE
::Network
::SDN
::Zones
::Plugin
::find_local_ip_interface_peers
(\
@peers, $loopback);
71 my $remoteas = $ebgp ?
"external" : $asn;
74 my @controller_config = (
75 "bgp router-id $ifaceip",
76 "no bgp default ipv4-unicast",
78 "bgp network import-check"
81 push(@{$bgp->{""}}, @controller_config) if keys %{$bgp} == 0;
83 @controller_config = ();
85 push @controller_config, "no bgp ebgp-requires-policy";
86 push @controller_config, "bgp disable-ebgp-connected-route-check" if $loopback;
91 push @controller_config, "neighbor BGP peer-group";
92 push @controller_config, "neighbor BGP remote-as $remoteas";
93 push @controller_config, "neighbor BGP bfd";
94 push @controller_config, "neighbor BGP ebgp-multihop $ebgp_multihop" if $ebgp && $ebgp_multihop;
98 foreach my $address (@peers) {
99 push @controller_config, "neighbor $address peer-group BGP";
101 push(@{$bgp->{""}}, @controller_config);
103 # address-family unicast
105 my $ipversion = Net
::IP
::ip_is_ipv6
($ifaceip) ?
"ipv6" : "ipv4";
106 my $mask = Net
::IP
::ip_is_ipv6
($ifaceip) ?
"/128" : "32";
108 push(@{$bgp->{"address-family"}->{"$ipversion unicast"}}, "network $ifaceip/$mask") if $loopback;
109 push(@{$bgp->{"address-family"}->{"$ipversion unicast"}}, "neighbor BGP activate");
110 push(@{$bgp->{"address-family"}->{"$ipversion unicast"}}, "neighbor BGP soft-reconfiguration inbound");
114 push(@{$config->{frr
}->{''}}, "ip prefix-list loopbacks_ips seq 10 permit 0.0.0.0/0 le 32");
115 push(@{$config->{frr
}->{''}}, "ip protocol bgp route-map correct_src");
116 push(@{$config->{frr
}->{'route-map'}->{'correct_src permit 1'}}, "match ip address prefix-list loopbacks_ips");
117 push(@{$config->{frr
}->{'route-map'}->{'correct_src permit 1'}}, "set src $ifaceip");
123 sub generate_controller_zone_config
{
124 my ($class, $plugin_config, $controller, $controller_cfg, $id, $uplinks, $config) = @_;
129 my ($class, $controllerid, $zone_cfg) = @_;
131 # verify that zone is associated to this controller
132 foreach my $id (keys %{$zone_cfg->{ids
}}) {
133 my $zone = $zone_cfg->{ids
}->{$id};
134 die "controller $controllerid is used by $id"
135 if (defined($zone->{controller
}) && $zone->{controller
} eq $controllerid);
140 my ($class, $controllerid, $controller_cfg) = @_;
142 # we can only have 1 bgp controller by node
143 my $local_node = PVE
::INotify
::nodename
();
144 my $controllernb = 0;
145 foreach my $id (keys %{$controller_cfg->{ids
}}) {
146 next if $id eq $controllerid;
147 my $controller = $controller_cfg->{ids
}->{$id};
148 next if $controller->{type
} ne "bgp";
149 next if $controller->{node
} ne $local_node;
151 die "only 1 bgp controller can be defined" if $controllernb > 1;
155 sub generate_controller_rawconfig
{
156 my ($class, $plugin_config, $config) = @_;
160 sub write_controller_config
{
161 my ($class, $plugin_config, $config) = @_;
165 sub reload_controller
{