f-41: config, frr: base BGP pilotée par l'agent au démarrage #41

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-10-11 19:52:46 +02:00
commit bf0e83862f
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
12 changed files with 331 additions and 18 deletions

View file

@ -3,6 +3,7 @@ package frr
import (
"fmt"
"net"
"strings"
)
const maxVNI = 1<<24 - 1
@ -60,6 +61,31 @@ func (b Base) commands() []string {
)
}
func (b Base) staleReflectors(running string) ([]string, error) {
want := make(map[string]bool, len(b.RouteReflectors))
for _, rr := range b.RouteReflectors {
want[rr.String()] = true
}
var stale []string
in := false
for _, l := range strings.Split(running, "\n") {
l = strings.TrimRight(l, " \r")
f := strings.Fields(l)
switch {
case len(f) == 3 && f[0] == "router" && f[1] == "bgp":
if f[2] != fmt.Sprint(b.ASN) {
return nil, fmt.Errorf("frr: bgp already runs as AS %s, not %d: changing the asn requires removing that instance by hand", f[2], b.ASN)
}
in = true
case in && l == "exit":
in = false
case in && len(f) == 4 && f[0] == "neighbor" && f[2] == "peer-group" && f[3] == "fabric" && !want[f[1]]:
stale = append(stale, f[1])
}
}
return stale, nil
}
func (v VRF) Name() string {
return "vrf-" + v.ID
}