Skip to content

Commit

Permalink
add remove-communities attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Jul 5, 2021
1 parent 16504cc commit 898b412
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
22 changes: 22 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type peer struct {
ImportCommunities *[]string `yaml:"import-communities" description:"List of communities to add to all imported routes" default:"-"`
ExportCommunities *[]string `yaml:"export-communities" description:"List of communities to add to all exported routes" default:"-"`
AnnounceCommunities *[]string `yaml:"announce-communities" description:"Announce all routes matching these communities to the peer" default:"-"`
RemoveCommunities *[]string `yaml:"remove-communities" description:"List of communities to remove before from routes announced by this peer" default:"-"`

// Filtering
ASSet *string `yaml:"as-set" description:"Peer's as-set for filtering" default:"-"`
Expand Down Expand Up @@ -115,6 +116,8 @@ type peer struct {
ExportLargeCommunities *[]string `yaml:"-" description:"-" default:"-"`
AnnounceStandardCommunities *[]string `yaml:"-" description:"-" default:"-"`
AnnounceLargeCommunities *[]string `yaml:"-" description:"-" default:"-"`
RemoveStandardCommunities *[]string `yaml:"-" description:"-" default:"-"`
RemoveLargeCommunities *[]string `yaml:"-" description:"-" default:"-"`
}

type vrrpInstance struct {
Expand Down Expand Up @@ -429,6 +432,25 @@ func loadConfig(configBlob []byte) (*config, error) {
}
}
}
if peerData.RemoveCommunities != nil {
for _, community := range *peerData.RemoveCommunities {
communityType := categorizeCommunity(community)

if communityType == "standard" {
if peerData.RemoveStandardCommunities == nil {
peerData.RemoveStandardCommunities = &[]string{}
}
*peerData.RemoveStandardCommunities = append(*peerData.RemoveStandardCommunities, community)
} else if communityType == "large" {
if peerData.RemoveLargeCommunities == nil {
peerData.RemoveLargeCommunities = &[]string{}
}
*peerData.RemoveLargeCommunities = append(*peerData.RemoveLargeCommunities, strings.ReplaceAll(community, ":", ","))
} else {
return nil, errors.New("Invalid remove community: " + community)
}
}
}

// Check for no originated prefixes but announce-originated enabled
if len(c.Prefixes) < 1 && *peerData.AnnounceOriginated {
Expand Down
7 changes: 7 additions & 0 deletions templates/peer.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ protocol bgp {{ UniqueProtocolName $peer.ProtocolName $af }} {
{{ if BoolDeref $peer.EnforcePeerNexthop }}enforce_peer_nexthop({{ $neighbor }});{{ end }}
{{ if BoolDeref $peer.FilterTransitASNs }}reject_transit_paths();{{ end }}

{{ range $i, $pattern := StringSliceIter $peer.RemoveStandardCommunities }}
bgp_community.delete([({{ $pattern }})]);
{{ end }}
{{ range $i, $pattern := StringSliceIter $peer.RemoveLargeCommunities }}
bgp_large_community.delete([({{ $pattern }})]);
{{ end }}

{{ if BoolDeref $peer.AllowBlackholeCommunity }}process_blackholes();{{ end }}

bgp_local_pref = {{ $peer.LocalPref }};
Expand Down

0 comments on commit 898b412

Please sign in to comment.