feat: refine BGP template handling and documentation updates. Remove local IP requirements in BGP template options, simplifying the configuration to focus on ASN. Update OpenAPI documentation to clarify BIRD parameters and enhance user guidance on JSON settings format in the UI. Adjust tests to align with the new BGP template structure.
CI / changes (push) Successful in 5s
CI / openapi (push) Successful in 28s
CI / go (push) Successful in 25s
CI / docker-web (deploy/docker/evobgp-web/Dockerfile, , evobgp-web) (push) Successful in 1m3s
CI / docker-web (deploy/docker/evobgp-web/Dockerfile, evobgp-all, evobgp-web-all) (push) Successful in 1m21s
CI / docker-bird (push) Has been skipped
CI / bird2 (push) Successful in 16s
CI / docker-go (deploy/docker/evobgp-agent/Dockerfile, , evobgp-agent) (push) Successful in 1m4s
CI / docker-go (evobgp-all, 1, deploy/docker/gobinary/Dockerfile, , evobgp-all) (push) Successful in 2m31s
CI / docker-go (evobgp-api, 1, deploy/docker/gobinary/Dockerfile, , evobgp-api) (push) Successful in 1m35s
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 1m23s
CI / docker-go (evobgp-node, 0, deploy/docker/gobinary/Dockerfile, , evobgp-node) (push) Successful in 1m19s
CI / docker-go (evobgp-render, 0, deploy/docker/gobinary/Dockerfile, , evobgp-render) (push) Successful in 1m22s
CI / docker-go (evobgp-scheduler, 0, deploy/docker/gobinary/Dockerfile, , evobgp-scheduler) (push) Successful in 1m22s

This commit is contained in:
Denozordec
2026-04-06 11:51:47 +07:00
parent 62bf987a19
commit 6266a39aed
6 changed files with 22 additions and 25 deletions
+4 -12
View File
@@ -11,10 +11,9 @@ const (
BGPTemplateNameV6 = "bgp_template_v6"
)
// BGPTemplatesOptions holds tenant defaults for template bgp bgp_template (+ v6 mirror).
// BGPTemplatesOptions holds ASN and export filters for template bgp bgp_template (+ v6 mirror).
// Templates use "local as <asn>;" only (no local IP); peers supply source address / optional local override.
type BGPTemplatesOptions struct {
LocalIPv4 string
LocalIPv6 string
LocalASN uint32
ExportFilterV4 string
ExportFilterV6 string
@@ -22,9 +21,6 @@ type BGPTemplatesOptions struct {
// RenderBGPTemplates renders two template bgp blocks (IPv4 and IPv6 AFI).
func RenderBGPTemplates(opts BGPTemplatesOptions) (string, error) {
if strings.TrimSpace(opts.LocalIPv4) == "" || strings.TrimSpace(opts.LocalIPv6) == "" {
return "", fmt.Errorf("birdfmt: template local IPv4 and IPv6 are required")
}
if opts.LocalASN == 0 {
return "", fmt.Errorf("birdfmt: template local ASN must be non-zero")
}
@@ -38,9 +34,7 @@ func RenderBGPTemplates(opts BGPTemplatesOptions) (string, error) {
}
var b strings.Builder
fmt.Fprintf(&b, "template bgp %s {\n", BGPTemplateNameV4)
b.WriteString(" local ")
b.WriteString(strings.TrimSpace(opts.LocalIPv4))
fmt.Fprintf(&b, " as %d;\n", opts.LocalASN)
fmt.Fprintf(&b, " local as %d;\n", opts.LocalASN)
b.WriteString(" ipv4 {\n")
b.WriteString(" import all;\n")
b.WriteString(" export ")
@@ -49,9 +43,7 @@ func RenderBGPTemplates(opts BGPTemplatesOptions) (string, error) {
b.WriteString(" };\n")
b.WriteString("}\n\n")
fmt.Fprintf(&b, "template bgp %s {\n", BGPTemplateNameV6)
b.WriteString(" local ")
b.WriteString(strings.TrimSpace(opts.LocalIPv6))
fmt.Fprintf(&b, " as %d;\n", opts.LocalASN)
fmt.Fprintf(&b, " local as %d;\n", opts.LocalASN)
b.WriteString(" ipv6 {\n")
b.WriteString(" import all;\n")
b.WriteString(" export ")
-2
View File
@@ -30,8 +30,6 @@ func TestStandardLayout_GeneratorMatchesFixtures(t *testing.T) {
assertFileEquals(t, "testdata/scenarios/standard_layout/bird.d/evobgp_prefixes_v6.conf", staticV6)
tpl, err := RenderBGPTemplates(BGPTemplatesOptions{
LocalIPv4: "192.0.2.1",
LocalIPv6: "2001:db8::1",
LocalASN: 65001,
ExportFilterV4: "evobgp_export_v4",
ExportFilterV6: "evobgp_export_v6",
@@ -1,5 +1,5 @@
template bgp bgp_template {
local 192.0.2.1 as 65001;
local as 65001;
ipv4 {
import all;
export filter evobgp_export_v4;
@@ -7,7 +7,7 @@ template bgp bgp_template {
}
template bgp bgp_template_v6 {
local 2001:db8::1 as 65001;
local as 65001;
ipv6 {
import all;
export filter evobgp_export_v6;
+3 -3
View File
@@ -285,8 +285,6 @@ func buildPreviewFragments(st store.Backend, tenantID, moduleID, revisionID stri
locals := birdLocalsFromStore(st, tenantID)
tplBody, err := birdfmt.RenderBGPTemplates(birdfmt.BGPTemplatesOptions{
LocalIPv4: locals.localV4,
LocalIPv6: locals.localV6,
LocalASN: locals.localASN,
ExportFilterV4: birdFilterNameV4,
ExportFilterV6: birdFilterNameV6,
@@ -364,6 +362,8 @@ func birdLocalsFromStore(st store.Backend, tenantID string) birdLocals {
}
if s := stringFromSettingsMap(settings, "bird_bgp_source_ipv4"); s != "" {
loc.sourceV4 = s
// BIRD router id must be an IPv4 address; align with BGP source when operator sets it.
loc.routerID = strings.TrimSpace(s)
}
if s := stringFromSettingsMap(settings, "bird_bgp_source_ipv6"); s != "" {
loc.sourceV6 = s
@@ -445,7 +445,7 @@ func effectivePeerLocals(loc birdLocals, pol peerPolicyJSON) (v4, v6 string, asn
return v4, v6, asn
}
// peerNeedsLocalOverride is true when the peer's effective local IP or ASN differs from tenant defaults in the BGP template.
// peerNeedsLocalOverride is true when the peer's effective local IP or ASN should override template "local as …" (add explicit "local <addr> as …" on the peer).
func peerNeedsLocalOverride(loc birdLocals, effLocal string, effASN uint32, ipv4 bool) bool {
if ipv4 {
return strings.TrimSpace(effLocal) != strings.TrimSpace(loc.localV4) || effASN != loc.localASN