Skip to content

Commit e183d55

Browse files
committed
Fix origin-communities description + add local-communities
1 parent 7be2cf6 commit e183d55

4 files changed

Lines changed: 40 additions & 2 deletions

File tree

pkg/config/config.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ type Config struct {
224224
WebUIFile string `yaml:"web-ui-file" description:"File to write web UI to (disabled if empty)" default:""`
225225
LogFile string `yaml:"log-file" description:"Log file location" default:"syslog"`
226226
GlobalConfig string `yaml:"global-config" description:"Global BIRD configuration" default:""`
227-
OriginCommunities []string `yaml:"origin-communities" description:"List of communities to add to locally originated routes" default:""`
227+
OriginCommunities []string `yaml:"origin-communities" description:"List of communities to accept as locally originated routes" default:""`
228+
LocalCommunities []string `yaml:"local-communities" description:"List of communities to add to locally originated prefixes" default:""`
228229

229230
Hostname string `yaml:"hostname" description:"Router hostname (default system hostname)" default:""`
230231

@@ -264,6 +265,8 @@ type Config struct {
264265
NVRSASNs []uint32 `yaml:"-" description:"-"`
265266
OriginStandardCommunities []string `yaml:"-" description:"-"`
266267
OriginLargeCommunities []string `yaml:"-" description:"-"`
268+
LocalStandardCommunities []string `yaml:"-" description:"-"`
269+
LocalLargeCommunities []string `yaml:"-" description:"-"`
267270
}
268271

269272
// Init initializes a Config with embedded structs prior to calling config.Default

pkg/embed/templates/global.tmpl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,24 @@ function accept_local() {
390390

391391
{{ if .Prefixes4 -}}
392392
if (net ~ LOCALv4) then {
393+
{{ range $i, $community := StringSliceIter .LocalStandardCommunities }}
394+
bgp_community.add(({{ $community }}));
395+
{{ end }}
396+
{{ range $i, $community := StringSliceIter .LocalLargeCommunities }}
397+
bgp_large_community.add(({{ $community }}));
398+
{{ end }}
393399
accept;
394400
}
395401
{{- end }}
396402

397403
{{ if .Prefixes6 -}}
398404
if (net ~ LOCALv6) then {
405+
{{ range $i, $community := StringSliceIter .LocalStandardCommunities }}
406+
bgp_community.add(({{ $community }}));
407+
{{ end }}
408+
{{ range $i, $community := StringSliceIter .LocalLargeCommunities }}
409+
bgp_large_community.add(({{ $community }}));
410+
{{ end }}
399411
accept;
400412
}
401413
{{- end }}

pkg/process/process.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ func Load(configBlob []byte) (*config.Config, error) {
300300
if c.OriginStandardCommunities == nil {
301301
c.OriginStandardCommunities = []string{}
302302
}
303-
c.OriginStandardCommunities = append(c.OriginStandardCommunities, community)
303+
c.OriginStandardCommunities = append(c.OriginStandardCommunities, strings.ReplaceAll(community, ":", ","))
304304
} else if communityType == "large" {
305305
if c.OriginLargeCommunities == nil {
306306
c.OriginLargeCommunities = []string{}
@@ -312,6 +312,25 @@ func Load(configBlob []byte) (*config.Config, error) {
312312
}
313313
}
314314

315+
if c.LocalCommunities != nil {
316+
for _, community := range c.LocalCommunities {
317+
communityType := categorizeCommunity(community)
318+
if communityType == "standard" {
319+
if c.LocalStandardCommunities == nil {
320+
c.LocalStandardCommunities = []string{}
321+
}
322+
c.LocalStandardCommunities = append(c.LocalStandardCommunities, strings.ReplaceAll(community, ":", ","))
323+
} else if communityType == "large" {
324+
if c.LocalLargeCommunities == nil {
325+
c.LocalLargeCommunities = []string{}
326+
}
327+
c.LocalLargeCommunities = append(c.LocalLargeCommunities, strings.ReplaceAll(community, ":", ","))
328+
} else {
329+
return nil, errors.New("Invalid local community: " + community)
330+
}
331+
}
332+
}
333+
315334
// Parse static routes
316335
for prefix, nexthop := range c.Kernel.Statics {
317336
// Handle interface suffix

tests/generate-complex.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ origin-communities:
1212
- 34553:10
1313
- 34553:10:1
1414

15+
local-communities:
16+
- 65530:65530
17+
- 65530:100:65530
18+
1519
kernel:
1620
srd-communities:
1721
- 65530,1

0 commit comments

Comments
 (0)