Skip to content

Commit b289293

Browse files
authored
Merge pull request #158 from natesales/roles
feat: RFC 9234 BGP role support (#156)
2 parents 697a7d1 + fe270a5 commit b289293

5 files changed

Lines changed: 36 additions & 0 deletions

File tree

docs/docs/configuration.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,22 @@ AS set members (For filter-as-set)
12471247
|------|---------|------------|
12481248
| []uint32 | | |
12491249

1250+
### `role`
1251+
1252+
RFC 9234 Local BGP role
1253+
1254+
| Type | Default | Validation |
1255+
|------|---------|------------|
1256+
| string | | |
1257+
1258+
### `require-roles`
1259+
1260+
Require RFC 9234 BGP roles
1261+
1262+
| Type | Default | Validation |
1263+
|------|---------|------------|
1264+
| bool | false | |
1265+
12501266
### `announce-default`
12511267

12521268
Should a default route be exported to this peer?

pkg/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ type Peer struct {
195195
Prefixes *[]string `yaml:"prefixes" description:"Prefixes to accept" default:"-"`
196196
ASSetMembers *[]uint32 `yaml:"as-set-members" description:"AS set members (For filter-as-set)" default:"-"`
197197

198+
Role *string `yaml:"role" description:"RFC 9234 Local BGP role" default:"-"`
199+
RequireRoles *bool `yaml:"require-roles" description:"Require RFC 9234 BGP roles" default:"false"`
200+
198201
// Export options
199202
AnnounceDefault *bool `yaml:"announce-default" description:"Should a default route be exported to this peer?" default:"false"`
200203
AnnounceOriginated *bool `yaml:"announce-originated" description:"Should locally originated routes be announced to this peer?" default:"true"`

pkg/embed/templates/peer.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ protocol bgp {{ UniqueProtocolName $peer.ProtocolName $af $peer.ASN }} {
5252
{{ if BoolDeref $peer.AllowLocalAS }}allow local as ASN;{{ end }}
5353
{{ if BoolDeref $peer.TTLSecurity }}ttl security on;{{ end }}
5454
{{ if BoolDeref $peer.ConfederationMember }}confederation member yes;{{ end }}
55+
{{ if StrDeref $peer.Role }}local role {{ StrDeref $peer.Role }};{{ end }}
56+
{{ if BoolDeref $peer.RequireRoles }}require roles;{{ end }}
5557
{{ if not (BoolDeref $peer.InterpretCommunities) }}interpret communities off;{{ end }}
5658
{{ if IntDeref $peer.Confederation }}confederation {{ IntDeref $peer.Confederation }};{{ end }}
5759
{{ if IntDeref $peer.DefaultLocalPref }}default bgp_local_pref {{ IntDeref $peer.DefaultLocalPref }};{{ end }}

pkg/process/process.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,19 @@ func Load(configBlob []byte) (*config.Config, error) {
286286
}
287287
}
288288
}
289+
290+
// Validate RFC 9234 BGP role
291+
if peerData.Role != nil {
292+
peerData.Role = util.Ptr(strings.ReplaceAll(*peerData.Role, "-", "_"))
293+
if *peerData.Role != "rs_server" && *peerData.Role != "rs_client" && *peerData.Role != "customer" && *peerData.Role != "peer" {
294+
return nil, fmt.Errorf("[%s] Invalid BGP role: %s (must be one of rs-server, rs-client, customer, peer)", *peerData.Role, peerName)
295+
}
296+
}
297+
requireRoles := peerData.RequireRoles != nil && *peerData.RequireRoles
298+
if requireRoles && peerData.Role == nil {
299+
return nil, fmt.Errorf("[%s] require-roles set but no role specified", peerName)
300+
}
301+
289302
} // end peer list
290303

291304
// Parse origin routes by assembling OriginIPv{4,6} lists by address family

tests/generate-complex.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,5 @@ peers:
9797
- 65510
9898
- 65530
9999
filter-aspa: true
100+
require-roles: true
101+
role: peer

0 commit comments

Comments
 (0)