Skip to content

Commit 10d0dd1

Browse files
committed
fix: allow comma or colon delimited communities
1 parent ce6ae38 commit 10d0dd1

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

pkg/process/process.go

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ func Load(configBlob []byte) (*config.Config, error) {
271271

272272
for prefix, communities := range *peerData.PrefixCommunities {
273273
for _, community := range communities {
274+
community = strings.ReplaceAll(community, ":", ",")
274275
communityType := categorizeCommunity(community)
275276
if communityType == "standard" {
276277
if _, ok := (*peerData.PrefixStandardCommunities)[prefix]; !ok {
@@ -281,7 +282,7 @@ func Load(configBlob []byte) (*config.Config, error) {
281282
if _, ok := (*peerData.PrefixLargeCommunities)[prefix]; !ok {
282283
(*peerData.PrefixLargeCommunities)[prefix] = []string{}
283284
}
284-
(*peerData.PrefixLargeCommunities)[prefix] = append((*peerData.PrefixLargeCommunities)[prefix], strings.ReplaceAll(community, ":", ","))
285+
(*peerData.PrefixLargeCommunities)[prefix] = append((*peerData.PrefixLargeCommunities)[prefix], community)
285286
} else {
286287
return nil, errors.New("Invalid prefix community: " + community)
287288
}
@@ -347,6 +348,7 @@ func Load(configBlob []byte) (*config.Config, error) {
347348
// Categorize communities
348349
if c.Kernel.SRDCommunities != nil {
349350
for _, community := range c.Kernel.SRDCommunities {
351+
community = strings.ReplaceAll(community, ":", ",")
350352
communityType := categorizeCommunity(community)
351353
if communityType == "standard" {
352354
if c.Kernel.SRDStandardCommunities == nil {
@@ -357,7 +359,7 @@ func Load(configBlob []byte) (*config.Config, error) {
357359
if c.Kernel.SRDLargeCommunities == nil {
358360
c.Kernel.SRDLargeCommunities = []string{}
359361
}
360-
c.Kernel.SRDLargeCommunities = append(c.Kernel.SRDLargeCommunities, strings.ReplaceAll(community, ":", ","))
362+
c.Kernel.SRDLargeCommunities = append(c.Kernel.SRDLargeCommunities, community)
361363
} else {
362364
return nil, errors.New("Invalid SRD community: " + community)
363365
}
@@ -366,17 +368,18 @@ func Load(configBlob []byte) (*config.Config, error) {
366368

367369
if c.OriginCommunities != nil {
368370
for _, community := range c.OriginCommunities {
371+
community = strings.ReplaceAll(community, ":", ",")
369372
communityType := categorizeCommunity(community)
370373
if communityType == "standard" {
371374
if c.OriginStandardCommunities == nil {
372375
c.OriginStandardCommunities = []string{}
373376
}
374-
c.OriginStandardCommunities = append(c.OriginStandardCommunities, strings.ReplaceAll(community, ":", ","))
377+
c.OriginStandardCommunities = append(c.OriginStandardCommunities, community)
375378
} else if communityType == "large" {
376379
if c.OriginLargeCommunities == nil {
377380
c.OriginLargeCommunities = []string{}
378381
}
379-
c.OriginLargeCommunities = append(c.OriginLargeCommunities, strings.ReplaceAll(community, ":", ","))
382+
c.OriginLargeCommunities = append(c.OriginLargeCommunities, community)
380383
} else {
381384
return nil, errors.New("Invalid origin community: " + community)
382385
}
@@ -385,17 +388,18 @@ func Load(configBlob []byte) (*config.Config, error) {
385388

386389
if c.LocalCommunities != nil {
387390
for _, community := range c.LocalCommunities {
391+
community = strings.ReplaceAll(community, ":", ",")
388392
communityType := categorizeCommunity(community)
389393
if communityType == "standard" {
390394
if c.LocalStandardCommunities == nil {
391395
c.LocalStandardCommunities = []string{}
392396
}
393-
c.LocalStandardCommunities = append(c.LocalStandardCommunities, strings.ReplaceAll(community, ":", ","))
397+
c.LocalStandardCommunities = append(c.LocalStandardCommunities, community)
394398
} else if communityType == "large" {
395399
if c.LocalLargeCommunities == nil {
396400
c.LocalLargeCommunities = []string{}
397401
}
398-
c.LocalLargeCommunities = append(c.LocalLargeCommunities, strings.ReplaceAll(community, ":", ","))
402+
c.LocalLargeCommunities = append(c.LocalLargeCommunities, community)
399403
} else {
400404
return nil, errors.New("Invalid local community: " + community)
401405
}
@@ -404,17 +408,18 @@ func Load(configBlob []byte) (*config.Config, error) {
404408

405409
if c.ImportCommunities != nil {
406410
for _, community := range c.ImportCommunities {
411+
community = strings.ReplaceAll(community, ":", ",")
407412
communityType := categorizeCommunity(community)
408413
if communityType == "standard" {
409414
if c.ImportStandardCommunities == nil {
410415
c.ImportStandardCommunities = []string{}
411416
}
412-
c.ImportStandardCommunities = append(c.ImportStandardCommunities, strings.ReplaceAll(community, ":", ","))
417+
c.ImportStandardCommunities = append(c.ImportStandardCommunities, community)
413418
} else if communityType == "large" {
414419
if c.ImportLargeCommunities == nil {
415420
c.ImportLargeCommunities = []string{}
416421
}
417-
c.ImportLargeCommunities = append(c.ImportLargeCommunities, strings.ReplaceAll(community, ":", ","))
422+
c.ImportLargeCommunities = append(c.ImportLargeCommunities, community)
418423
} else {
419424
return nil, errors.New("Invalid global import community: " + community)
420425
}
@@ -423,17 +428,18 @@ func Load(configBlob []byte) (*config.Config, error) {
423428

424429
if c.ExportCommunities != nil {
425430
for _, community := range c.ExportCommunities {
431+
community = strings.ReplaceAll(community, ":", ",")
426432
communityType := categorizeCommunity(community)
427433
if communityType == "standard" {
428434
if c.ExportStandardCommunities == nil {
429435
c.ExportStandardCommunities = []string{}
430436
}
431-
c.ExportStandardCommunities = append(c.ExportStandardCommunities, strings.ReplaceAll(community, ":", ","))
437+
c.ExportStandardCommunities = append(c.ExportStandardCommunities, community)
432438
} else if communityType == "large" {
433439
if c.ExportLargeCommunities == nil {
434440
c.ExportLargeCommunities = []string{}
435441
}
436-
c.ExportLargeCommunities = append(c.ExportLargeCommunities, strings.ReplaceAll(community, ":", ","))
442+
c.ExportLargeCommunities = append(c.ExportLargeCommunities, community)
437443
} else {
438444
return nil, errors.New("Invalid global export community: " + community)
439445
}
@@ -541,17 +547,18 @@ func Load(configBlob []byte) (*config.Config, error) {
541547
// Categorize communities
542548
if peerData.ImportCommunities != nil {
543549
for _, community := range *peerData.ImportCommunities {
550+
community = strings.ReplaceAll(community, ":", ",")
544551
communityType := categorizeCommunity(community)
545552
if communityType == "standard" {
546553
if peerData.ImportStandardCommunities == nil {
547554
peerData.ImportStandardCommunities = &[]string{}
548555
}
549-
*peerData.ImportStandardCommunities = append(*peerData.ImportStandardCommunities, strings.ReplaceAll(community, ":", ","))
556+
*peerData.ImportStandardCommunities = append(*peerData.ImportStandardCommunities, community)
550557
} else if communityType == "large" {
551558
if peerData.ImportLargeCommunities == nil {
552559
peerData.ImportLargeCommunities = &[]string{}
553560
}
554-
*peerData.ImportLargeCommunities = append(*peerData.ImportLargeCommunities, strings.ReplaceAll(community, ":", ","))
561+
*peerData.ImportLargeCommunities = append(*peerData.ImportLargeCommunities, community)
555562
} else {
556563
return nil, errors.New("Invalid import community: " + community)
557564
}
@@ -560,6 +567,7 @@ func Load(configBlob []byte) (*config.Config, error) {
560567

561568
if peerData.ExportCommunities != nil {
562569
for _, community := range *peerData.ExportCommunities {
570+
community = strings.ReplaceAll(community, ":", ",")
563571
communityType := categorizeCommunity(community)
564572
if communityType == "standard" {
565573
if peerData.ExportStandardCommunities == nil {
@@ -570,14 +578,15 @@ func Load(configBlob []byte) (*config.Config, error) {
570578
if peerData.ExportLargeCommunities == nil {
571579
peerData.ExportLargeCommunities = &[]string{}
572580
}
573-
*peerData.ExportLargeCommunities = append(*peerData.ExportLargeCommunities, strings.ReplaceAll(community, ":", ","))
581+
*peerData.ExportLargeCommunities = append(*peerData.ExportLargeCommunities, community)
574582
} else {
575583
return nil, errors.New("Invalid export community: " + community)
576584
}
577585
}
578586
}
579587
if peerData.AnnounceCommunities != nil {
580588
for _, community := range *peerData.AnnounceCommunities {
589+
community = strings.ReplaceAll(community, ":", ",")
581590
communityType := categorizeCommunity(community)
582591

583592
if communityType == "standard" {
@@ -589,14 +598,15 @@ func Load(configBlob []byte) (*config.Config, error) {
589598
if peerData.AnnounceLargeCommunities == nil {
590599
peerData.AnnounceLargeCommunities = &[]string{}
591600
}
592-
*peerData.AnnounceLargeCommunities = append(*peerData.AnnounceLargeCommunities, strings.ReplaceAll(community, ":", ","))
601+
*peerData.AnnounceLargeCommunities = append(*peerData.AnnounceLargeCommunities, community)
593602
} else {
594603
return nil, errors.New("Invalid announce community: " + community)
595604
}
596605
}
597606
}
598607
if peerData.RemoveCommunities != nil {
599608
for _, community := range *peerData.RemoveCommunities {
609+
community = strings.ReplaceAll(community, ":", ",")
600610
communityType := categorizeCommunity(community)
601611

602612
if communityType == "standard" {
@@ -608,7 +618,7 @@ func Load(configBlob []byte) (*config.Config, error) {
608618
if peerData.RemoveLargeCommunities == nil {
609619
peerData.RemoveLargeCommunities = &[]string{}
610620
}
611-
*peerData.RemoveLargeCommunities = append(*peerData.RemoveLargeCommunities, strings.ReplaceAll(community, ":", ","))
621+
*peerData.RemoveLargeCommunities = append(*peerData.RemoveLargeCommunities, community)
612622
} else {
613623
return nil, errors.New("Invalid remove community: " + community)
614624
}

0 commit comments

Comments
 (0)