CI / changes (push) Successful in 5s
CI / openapi (push) Has been skipped
CI / go (push) Successful in 25s
CI / docker-web (deploy/docker/evobgp-web/Dockerfile, , evobgp-web) (push) Successful in 1m9s
CI / docker-web (deploy/docker/evobgp-web/Dockerfile, evobgp-all, evobgp-web-all) (push) Successful in 1m2s
CI / docker-bird (push) Has been skipped
CI / bird2 (push) Successful in 14s
CI / docker-go (deploy/docker/evobgp-agent/Dockerfile, , evobgp-agent) (push) Successful in 1m1s
CI / docker-go (evobgp-all, 1, deploy/docker/gobinary/Dockerfile, , evobgp-all) (push) Successful in 1m24s
CI / docker-go (evobgp-api, 1, deploy/docker/gobinary/Dockerfile, , evobgp-api) (push) Successful in 1m28s
CI / docker-go (evobgp-deploy, 0, deploy/docker/gobinary/Dockerfile, , evobgp-deploy) (push) Successful in 1m21s
CI / docker-go (evobgp-ingest, 0, deploy/docker/gobinary/Dockerfile, , evobgp-ingest) (push) Successful in 1m24s
CI / docker-go (evobgp-node, 0, deploy/docker/gobinary/Dockerfile, , evobgp-node) (push) Successful in 1m10s
CI / docker-go (evobgp-render, 0, deploy/docker/gobinary/Dockerfile, , evobgp-render) (push) Successful in 1m19s
CI / docker-go (evobgp-scheduler, 0, deploy/docker/gobinary/Dockerfile, , evobgp-scheduler) (push) Has been cancelled
54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package store
|
|
|
|
import (
|
|
"net/netip"
|
|
"strings"
|
|
)
|
|
|
|
// EffectivePeerEnabledOnCreate matches API/JSON decoding: omitted "enabled" unmarshals as false in Go,
|
|
// but new peers should be enabled by default. If session_state is non-empty, false is preserved
|
|
// (agent-managed rows may be intentionally disabled).
|
|
func EffectivePeerEnabledOnCreate(inEnabled bool, sessionState string) bool {
|
|
if inEnabled {
|
|
return true
|
|
}
|
|
if strings.TrimSpace(sessionState) != "" {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
// ParsePeerNeighbor parses a BGP neighbor value for BIRD output: a plain IPv4/IPv6
|
|
// address, or a host prefix (/32 or /128) which is a common input mistake.
|
|
func ParsePeerNeighbor(s string) (netip.Addr, bool) {
|
|
s = strings.TrimSpace(s)
|
|
if s == "" {
|
|
return netip.Addr{}, false
|
|
}
|
|
if addr, err := netip.ParseAddr(s); err == nil {
|
|
return addr, true
|
|
}
|
|
pfx, err := netip.ParsePrefix(s)
|
|
if err != nil {
|
|
return netip.Addr{}, false
|
|
}
|
|
addr := pfx.Addr()
|
|
if addr.Is4() && pfx.Bits() == 32 {
|
|
return addr, true
|
|
}
|
|
if addr.Is6() && pfx.Bits() == 128 {
|
|
return addr, true
|
|
}
|
|
return netip.Addr{}, false
|
|
}
|
|
|
|
// NormalizePeerNeighborString returns the canonical host address string for storage
|
|
// and BIRD, or false if s is not a usable neighbor.
|
|
func NormalizePeerNeighborString(s string) (string, bool) {
|
|
addr, ok := ParsePeerNeighbor(s)
|
|
if !ok {
|
|
return "", false
|
|
}
|
|
return addr.String(), true
|
|
}
|