Skip to content

Commit

Permalink
add strip-private-asns
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Feb 21, 2021
1 parent c1805a6 commit ddaf542
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ objects will not have sessions of that address family configured.
bcg uses RFC 8092 BGP Large Communities
#### Private ASNs
bcg strips private ASNs before exporting to upstream sessions in range `[64512..65534, 4200000000..4294967294]`.
#### "Peerlock Lite"
Peers with type `peer` or `downstream` reject any route with a Tier 1 ASN in
Expand Down Expand Up @@ -182,6 +178,7 @@ path ([Peerlock Lite](https://github.com/job/peerlock)).
| export-default | Should a default route be sent over the session? (default false) |
| no-specifics | Don't send specific routes (default false, make sure to enable export-default or else no routes will be exported) |
| allow-blackholes | Accept community (ASN,0,666) to blackhole /32 and /128 prefixes |
| strip-private-asns | Should private ASNs be stripped from path before exporting? (in range `[64512..65534, 4200000000..4294967294]`) |
<details>
<summary>Remarks</summary>
Expand Down
48 changes: 25 additions & 23 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,30 @@ var release = "devel" // This is set by go build

// Peer contains all information specific to a single peer network
type Peer struct {
Asn uint `yaml:"asn" toml:"ASN" json:"asn"`
Type string `yaml:"type" toml:"Type" json:"type"`
Prepends uint `yaml:"prepends" toml:"Prepends" json:"prepends"`
LocalPref uint `yaml:"local-pref" toml:"LocalPref" json:"local-pref"`
Multihop bool `yaml:"multihop" toml:"Multihop" json:"multihop"`
Passive bool `yaml:"passive" toml:"Passive" json:"passive"`
Disabled bool `yaml:"disabled" toml:"Disabled" json:"disabled"`
Password string `yaml:"password" toml:"Password" json:"password"`
Port uint16 `yaml:"port" toml:"Port" json:"port"`
PreImport string `yaml:"pre-import" toml:"PreImport" json:"pre-import"`
PreExport string `yaml:"pre-export" toml:"PreExport" json:"pre-export"`
NeighborIps []string `yaml:"neighbors" toml:"Neighbors" json:"neighbors"`
ImportLimit4 uint `yaml:"import-limit4" toml:"ImportLimit4" json:"import-limit4"`
ImportLimit6 uint `yaml:"import-limit6" toml:"ImportLimit6" json:"import-limit6"`
SkipFilter bool `yaml:"skip-filter" toml:"SkipFilter" json:"skip-filter"`
RsClient bool `yaml:"rs-client" toml:"RSClient" json:"rs-client"`
RrClient bool `yaml:"rr-client" toml:"RRClient" json:"rr-client"`
Bfd bool `yaml:"bfd" toml:"BFD" json:"bfd"`
EnforceFirstAs bool `yaml:"enforce-first-as" toml:"EnforceFirstAS" json:"enforce-first-as"`
SessionGlobal string `yaml:"session-global" toml:"SessionGlobal" json:"session-global"`
ExportDefault bool `yaml:"export-default" toml:"ExportDefault" json:"export-default"`
NoSpecifics bool `yaml:"no-specifics" toml:"NoSpecifics" json:"no-specifics"`
AllowBlackholes bool `yaml:"allow-blackholes" toml:"AllowBlackholes" json:"allow-blackholes"`
Asn uint `yaml:"asn" toml:"ASN" json:"asn"`
Type string `yaml:"type" toml:"Type" json:"type"`
Prepends uint `yaml:"prepends" toml:"Prepends" json:"prepends"`
LocalPref uint `yaml:"local-pref" toml:"LocalPref" json:"local-pref"`
Multihop bool `yaml:"multihop" toml:"Multihop" json:"multihop"`
Passive bool `yaml:"passive" toml:"Passive" json:"passive"`
Disabled bool `yaml:"disabled" toml:"Disabled" json:"disabled"`
Password string `yaml:"password" toml:"Password" json:"password"`
Port uint16 `yaml:"port" toml:"Port" json:"port"`
PreImport string `yaml:"pre-import" toml:"PreImport" json:"pre-import"`
PreExport string `yaml:"pre-export" toml:"PreExport" json:"pre-export"`
NeighborIps []string `yaml:"neighbors" toml:"Neighbors" json:"neighbors"`
ImportLimit4 uint `yaml:"import-limit4" toml:"ImportLimit4" json:"import-limit4"`
ImportLimit6 uint `yaml:"import-limit6" toml:"ImportLimit6" json:"import-limit6"`
SkipFilter bool `yaml:"skip-filter" toml:"SkipFilter" json:"skip-filter"`
RsClient bool `yaml:"rs-client" toml:"RSClient" json:"rs-client"`
RrClient bool `yaml:"rr-client" toml:"RRClient" json:"rr-client"`
Bfd bool `yaml:"bfd" toml:"BFD" json:"bfd"`
EnforceFirstAs bool `yaml:"enforce-first-as" toml:"EnforceFirstAS" json:"enforce-first-as"`
SessionGlobal string `yaml:"session-global" toml:"SessionGlobal" json:"session-global"`
ExportDefault bool `yaml:"export-default" toml:"ExportDefault" json:"export-default"`
NoSpecifics bool `yaml:"no-specifics" toml:"NoSpecifics" json:"no-specifics"`
AllowBlackholes bool `yaml:"allow-blackholes" toml:"AllowBlackholes" json:"allow-blackholes"`
StripPrivateASNs bool `yaml:"strip-private-asns" toml:"StripPrivateASNs" json:"strip-private-asns"`

AsSet string `yaml:"-" toml:"-" json:"-"`
QueryTime string `yaml:"-" toml:"-" json:"-"`
Expand Down Expand Up @@ -537,6 +538,7 @@ func main() {
log.Infof("[%s] export-default: %v", peerName, peerData.ExportDefault)
log.Infof("[%s] no-specifics: %v", peerName, peerData.NoSpecifics)
log.Infof("[%s] allow-blackholes: %v", peerName, peerData.AllowBlackholes)
log.Infof("[%s] strip-private-asns: %v", peerName, peerData.StripPrivateASNs)

// Check for additional options
if peerData.AsSet != "" {
Expand Down
5 changes: 5 additions & 0 deletions templates/peer.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ protocol bgp {{ $peer.Name }}v{{ $af }}_{{ $i }} {

export filter {
{{ $peer.PreExport }}

{{ if $peer.StripPrivateASNs }}
bgp_path.delete([64512..65534, 4200000000..4294967294]); # Strip private ASNs
{{ end }}

{{ if or $global.OriginSet4 $global.OriginSet6 -}}
accept_local(); # Originated
process_prepends();
Expand Down

0 comments on commit ddaf542

Please sign in to comment.