diff --git a/parser.go b/parser.go index bcc664fb..3626b8ff 100644 --- a/parser.go +++ b/parser.go @@ -338,29 +338,30 @@ func main() { } log.Debug("Finished writing global config") - log.Debug("Building origin sets") if len(config.Prefixes) == 0 { - log.Fatal("There are no origin prefixes defined") - } + log.Info("There are no origin prefixes defined") + } else { + log.Debug("Building origin sets") - // Assemble originIpv{4,6} lists by address family - var originIpv4, originIpv6 []string - for _, prefix := range config.Prefixes { - if strings.Contains(prefix, ":") { - originIpv6 = append(originIpv6, prefix) - } else { - originIpv4 = append(originIpv4, prefix) + // Assemble originIpv{4,6} lists by address family + var originIpv4, originIpv6 []string + for _, prefix := range config.Prefixes { + if strings.Contains(prefix, ":") { + originIpv6 = append(originIpv6, prefix) + } else { + originIpv4 = append(originIpv4, prefix) + } } - } - log.Debug("Finished building origin sets") + log.Debug("Finished building origin sets") - log.Debug("OriginIpv4: ", originIpv4) - log.Debug("OriginIpv6: ", originIpv6) + log.Debug("OriginIpv4: ", originIpv4) + log.Debug("OriginIpv6: ", originIpv6) - config.OriginSet4 = originIpv4 - config.OriginSet6 = originIpv6 + config.OriginSet4 = originIpv4 + config.OriginSet6 = originIpv6 + } // Render the global template and write to disk if !*dryRun { @@ -438,19 +439,19 @@ func main() { // Update the "latest operation" timestamp peerData.QueryTime = time.Now().Format(time.RFC1123) } else if peerData.Type == "upstream" || peerData.Type == "import-valid" { - + //Check if upstream has MaxPrefix4/6 set, if not set sensible defaults and if they are configured too low, warn the user if peerData.ImportLimit4 == 0 { peerData.ImportLimit4 = 1000000 // 1M routes log.Infof("Upstream %s has no IPv4 import limit configured. Setting to 1000000", peerName) - } else if peerData.ImportLimit4 <=900000 { + } else if peerData.ImportLimit4 <= 900000 { log.Infof("Upstream %s has a low IPv4 import limit configured. You may want to increase the MaxPrefix4 limit.", peerName) } if peerData.ImportLimit6 == 0 { - peerData.ImportLimit6 = 100000 // 100k routes + peerData.ImportLimit6 = 100000 // 100k routes log.Infof("Upstream %s has no IPv6 import limit configured. Setting to 100000", peerName) - } else if peerData.ImportLimit6 <=98000 { + } else if peerData.ImportLimit6 <= 98000 { log.Infof("Upstream %s has a low IPv6 import limit configured. You may want to increase the MaxPrefix6 limit.", peerName) } } diff --git a/templates/global.tmpl b/templates/global.tmpl index 891f971e..371fa79a 100644 --- a/templates/global.tmpl +++ b/templates/global.tmpl @@ -204,8 +204,15 @@ function strip_communities() { bgp_large_community.delete([(ASN, *, *)]); } -function accept_local() { - if (net ~ LOCAL_v4 || net ~ LOCAL_v6) then { +function accept_local4() { + if (net ~ LOCAL_v4 ) then { + bgp_large_community.add((ASN,0,100)); # Originated + accept; + } +} + +function accept_local6() { + if (net ~ LOCAL_v6 ) then { bgp_large_community.add((ASN,0,100)); # Originated accept; } diff --git a/templates/peer.tmpl b/templates/peer.tmpl index 2c9628f7..31b6e92c 100644 --- a/templates/peer.tmpl +++ b/templates/peer.tmpl @@ -46,21 +46,21 @@ protocol bgp {{ $peer.Name }}v{{ $af }}_{{ $i }} { {{- if eq $peer.Type "upstream" -}} bgp_large_community.add((ASN,0,101)); # Learned from upstream accept; - {{ else if eq $peer.Type "peer" -}} + {{- else if eq $peer.Type "peer" -}} reject_transit_paths(); if (net ~ AS{{ $peer.Asn }}_PFX_v{{ $af }}) then { bgp_large_community.add((ASN,0,102)); # Learned from peer accept; } reject; - {{ else if eq $peer.Type "downstream" -}} + {{- else if eq $peer.Type "downstream" -}} reject_transit_paths(); if (net ~ AS{{ $peer.Asn }}_PFX_v{{ $af }}) then { bgp_large_community.add((ASN,0,103)); # Learned from downstream accept; } reject; - {{ else if eq $peer.Type "import-valid" -}} + {{- else if eq $peer.Type "import-valid" -}} bgp_large_community.add((ASN,0,102)); # Learned from peer accept; {{ end }} @@ -68,7 +68,14 @@ protocol bgp {{ $peer.Name }}v{{ $af }}_{{ $i }} { export filter { {{ $peer.PreExport -}} - accept_local(); # Originated + + {{- if $global.OriginSet4 }} + accept_local4(); # Originated + {{ end -}} + {{- if $global.OriginSet6 }} + accept_local6(); # Originated + {{ end -}} + {{ if eq $peer.Type "upstream" -}} if ((ASN,0,103) ~ bgp_large_community) then accept; # Downstream {{ else if or (eq $peer.Type "peer") (eq $peer.Type "import-valid") -}}