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:
parent
94c2f82867
commit
bf0e83862f
12 changed files with 331 additions and 18 deletions
38
internal/config/agent/bgp.go
Normal file
38
internal/config/agent/bgp.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package configuration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
||||
type BGP struct {
|
||||
ASN uint32 `mapstructure:"asn"`
|
||||
RouteReflectors []string `mapstructure:"route_reflectors"`
|
||||
}
|
||||
|
||||
func (b BGP) Enabled() bool {
|
||||
return b.ASN != 0 || len(b.RouteReflectors) > 0
|
||||
}
|
||||
|
||||
func (b BGP) Reflectors() ([]net.IP, error) {
|
||||
if b.ASN == 0 {
|
||||
return nil, fmt.Errorf("bgp.asn must be set")
|
||||
}
|
||||
if len(b.RouteReflectors) == 0 {
|
||||
return nil, fmt.Errorf("bgp.route_reflectors must list at least one address")
|
||||
}
|
||||
seen := make(map[string]bool, len(b.RouteReflectors))
|
||||
ips := make([]net.IP, 0, len(b.RouteReflectors))
|
||||
for _, rr := range b.RouteReflectors {
|
||||
ip := net.ParseIP(rr).To4()
|
||||
if ip == nil {
|
||||
return nil, fmt.Errorf("bgp.route_reflectors: %q is not an IPv4 address", rr)
|
||||
}
|
||||
if seen[ip.String()] {
|
||||
return nil, fmt.Errorf("bgp.route_reflectors: %s is listed twice", ip)
|
||||
}
|
||||
seen[ip.String()] = true
|
||||
ips = append(ips, ip)
|
||||
}
|
||||
return ips, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue