Skip to content

Commit

Permalink
add fix for route-target in nwop
Browse files Browse the repository at this point in the history
  • Loading branch information
chdxD1 committed Jul 10, 2024
1 parent 12bdb03 commit c1e070d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/frr/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ import (
"bytes"
"fmt"
"os"
"regexp"

"github.com/telekom/das-schiff-network-operator/pkg/healthcheck"
"github.com/telekom/das-schiff-network-operator/pkg/nl"
)

var (
vrfAsnConfig = 4200065169

// Regular expressions for parsing route-target lines.
rtLinesRe = regexp.MustCompile(`(?m)^\s*route-target.*`)
rtPartsRe = regexp.MustCompile(`(?m)^(\s*route-target\s*(?:import|export)\s*)(.*)`)
rtRe = regexp.MustCompile(`(?m)(\S+)`)
)

type templateConfig struct {
Expand Down Expand Up @@ -43,6 +49,8 @@ func (m *Manager) Configure(in Configuration, nm *nl.Manager) (bool, error) {
return false, err
}

targetConfig = fixRouteTargetReload(targetConfig)

if !bytes.Equal(currentConfig, targetConfig) {
err = os.WriteFile(m.ConfigPath, targetConfig, frrPermissions)
if err != nil {
Expand Down Expand Up @@ -115,3 +123,24 @@ func renderSubtemplates(in Configuration, nlManager *nl.Manager) (*templateConfi
Hostname: hostname,
}, nil
}

// fixRouteTargetReload is a workaround for FRR's inability to reload route-targets if they are configured in a single line.
// This function splits such lines into multiple lines, each containing a single route-target.
func fixRouteTargetReload(config []byte) []byte {
return rtLinesRe.ReplaceAllFunc(config, func(s []byte) []byte {
parts := rtPartsRe.FindSubmatch(s)
if parts == nil {
return s
}
rtLine, targets := string(parts[1]), string(parts[2])
routeTargets := rtRe.FindAllString(targets, -1)
if len(routeTargets) < 2 {

Check failure on line 137 in pkg/frr/configure.go

View workflow job for this annotation

GitHub Actions / lint

mnd: Magic number: 2, in <condition> detected (gomnd)
return s
}
lines := ""
for _, rt := range routeTargets {
lines += rtLine + rt + "\n"
}
return []byte(lines[:len(lines)-1])
})
}

0 comments on commit c1e070d

Please sign in to comment.