Skip to content

Commit

Permalink
add prepend communities
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Dec 8, 2020
1 parent 0b000e6 commit 0ba36dc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ bcg strips private ASNs before exporting to upstream sessions in range `[64512..
| ASN,0,101 | Learned from upstream |
| ASN,0,102 | Learned from peer |
| ASN,0,103 | Learned from downstream |
| ASN,0,200 | Don't export to upstreams |
| ASN,1,200 | Don't export to upstreams |
| ASN,1,301 | Prepend once |
| ASN,1,302 | Prepend twice |
| ASN,1,303 | Prepend three times |
#### Global Configuration Options
Expand Down
34 changes: 18 additions & 16 deletions templates/global.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ function reject_transit_paths() {
if (bgp_path ~ TRANSIT_ASNS) then _reject("transit path");
}

function strip_communities() {
bgp_large_community.delete([(ASN, *, *)]);
function strip_info_communities() {
bgp_large_community.delete([(ASN, 0, *)]);
}

function accept_local() {
Expand All @@ -228,22 +228,24 @@ function accept_local() {
}

function process_prepends() {
if ((ASN,0,401) ~ bgp_community) then {
print "Adding single prepend for ", net;
bgp_path.prepend(ASN);
}
if ((ASN,0,103) ~ bgp_community) then { # Learned from downstream
if ((ASN,1,401) ~ bgp_community) then {
print "Adding single prepend for ", net;
bgp_path.prepend(ASN);
}

if ((ASN,0,402) ~ bgp_community) then {
print "Adding double prepend for ", net;
bgp_path.prepend(ASN);
bgp_path.prepend(ASN);
}
if ((ASN,1,402) ~ bgp_community) then {
print "Adding double prepend for ", net;
bgp_path.prepend(ASN);
bgp_path.prepend(ASN);
}

if ((ASN,0,403) ~ bgp_community) then {
print "Adding triple prepend for ", net;
bgp_path.prepend(ASN);
bgp_path.prepend(ASN);
bgp_path.prepend(ASN);
if ((ASN,1,403) ~ bgp_community) then {
print "Adding triple prepend for ", net;
bgp_path.prepend(ASN);
bgp_path.prepend(ASN);
bgp_path.prepend(ASN);
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions templates/peer.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protocol bgp {{ $peer.Name }}v{{ $af }}_{{ $i }} {
{{ if eq $peer.Asn $global.Asn }}next hop self;{{ end }}
import filter {
{{ if not $peer.SkipFilter }}reject_bogons();{{ end }}
strip_communities();
strip_info_communities();
bgp_local_pref = {{ $peer.LocalPref }};
honor_graceful_shutdown();
{{ $peer.PreImport }}
Expand Down Expand Up @@ -80,9 +80,10 @@ protocol bgp {{ $peer.Name }}v{{ $af }}_{{ $i }} {
{{ $peer.PreExport }}
{{ if or $global.OriginSet4 $global.OriginSet6 -}}
accept_local(); # Originated
process_prepends();
{{ end -}}
{{ if eq $peer.Type "upstream" -}}
if ((ASN,0,200) ~ bgp_large_community) then reject; # Don't export to upstreams
if ((ASN,1,200) ~ bgp_large_community) then reject; # Don't export to upstreams
if ((ASN,0,103) ~ bgp_large_community) then accept; # Downstream
{{ else if or (eq $peer.Type "peer") (eq $peer.Type "import-valid") -}}
if ((ASN,0,103) ~ bgp_large_community) then accept; # Downstream
Expand Down

0 comments on commit 0ba36dc

Please sign in to comment.