Skip to content

Commit

Permalink
add support for routers that don't originate prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Nov 3, 2020
1 parent 54d1185 commit a33b96c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 26 deletions.
41 changes: 21 additions & 20 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
Expand Down
11 changes: 9 additions & 2 deletions templates/global.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
15 changes: 11 additions & 4 deletions templates/peer.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,36 @@ 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 }}
};

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") -}}
Expand Down

0 comments on commit a33b96c

Please sign in to comment.