Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
chdxD1 committed Jul 8, 2024
1 parent ca35870 commit 2ce6dc0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
28 changes: 14 additions & 14 deletions pkg/frr/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,16 @@ type templateConfig struct {

func (m *Manager) Configure(in Configuration, nm *nl.Manager) (bool, error) {
// Remove permit from VRF and only allow deny rules
for i, vrf := range in.VRFs {
for i, in := range vrf.Import {
var items []PrefixedRouteItem
for _, item := range in.Items {
if item.Action != "deny" {
for i := range in.VRFs {
for j := range in.VRFs[i].Import {
for k := range in.VRFs[i].Import[j].Items {
if in.VRFs[i].Import[j].Items[k].Action != "deny" {
continue
}
// Swap deny to permit, this will be a prefix-list called from a deny route-map
item.Action = "permit"
items = append(items, item)
in.VRFs[i].Import[j].Items[k].Action = "permit"
}
vrf.Import[i].Items = items
}
in.VRFs[i] = vrf
}

config, err := m.renderSubtemplates(in, nm)
Expand Down Expand Up @@ -71,6 +67,14 @@ func (m *Manager) Configure(in Configuration, nm *nl.Manager) (bool, error) {
return false, nil
}

func (m *Manager) renderRouteMapMgmtIn() ([]byte, error) {
return render(routeMapMgmtInTpl, mgmtImportConfig{
IPv4MgmtRouteMapIn: m.ipv4MgmtRouteMapIn,
IPv6MgmtRouteMapIn: m.ipv6MgmtRouteMapIn,
MgmtVrfName: m.mgmtVrf,
})
}

func (m *Manager) renderSubtemplates(in Configuration, nlManager *nl.Manager) (*templateConfig, error) {
vrfRouterID, err := nlManager.GetUnderlayIP()
if err != nil {
Expand Down Expand Up @@ -106,11 +110,7 @@ func (m *Manager) renderSubtemplates(in Configuration, nlManager *nl.Manager) (*
if err != nil {
return nil, err
}
routemapMgmtIn, err := render(routeMapMgmtInTpl, mgmtImportConfig{
IPv4MgmtRouteMapIn: m.ipv4MgmtRouteMapIn,
IPv6MgmtRouteMapIn: m.ipv6MgmtRouteMapIn,
MgmtVrfName: m.mgmtVrf,
})
routemapMgmtIn, err := m.renderRouteMapMgmtIn()
if err != nil {
return nil, err
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/frr/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func NewFRRManager() *Manager {
}
}

func (m *Manager) Init(config *config.Config) error {
func (m *Manager) Init(cfg *config.Config) error {
if _, err := os.Stat(m.TemplatePath); errors.Is(err, os.ErrNotExist) {
err = generateTemplateConfig(m.TemplatePath, m.ConfigPath)
if err != nil {
Expand All @@ -92,18 +92,18 @@ func (m *Manager) Init(config *config.Config) error {
}
m.configTemplate = tpl

m.mgmtVrf = config.SkipVRFConfig[0]
if routeMap, err := getRouteMapName(m.ConfigPath, "ipv4", m.mgmtVrf); err != nil {
m.mgmtVrf = cfg.SkipVRFConfig[0]
routeMap, err := getRouteMapName(m.ConfigPath, "ipv4", m.mgmtVrf)
if err != nil {
return fmt.Errorf("error getting v4 mgmt route-map from FRR config: %w", err)
} else {
m.ipv4MgmtRouteMapIn = routeMap
}
m.ipv4MgmtRouteMapIn = routeMap

if routeMap, err := getRouteMapName(m.ConfigPath, "ipv6", m.mgmtVrf); err != nil {
routeMap, err = getRouteMapName(m.ConfigPath, "ipv6", m.mgmtVrf)
if err != nil {
return fmt.Errorf("error getting v6 mgmt route-map from FRR config: %w", err)
} else {
m.ipv6MgmtRouteMapIn = routeMap
}
m.ipv6MgmtRouteMapIn = routeMap

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/frr/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func getRouteMapName(file, addressFamily, mgmtVrfName string) (*string, error) {
content := string(fileContent)
re := regexp.MustCompile(`(?ms)address-family\s+` + addressFamily + `\s+unicast.*?neighbor\s+def_` + mgmtVrfName + `\s+route-map (\w*)\s+in`)
matches := re.FindStringSubmatch(content)
if len(matches) != 2 {
if len(matches) != len(re.SubexpNames()) {
return nil, nil
}
return &matches[1], nil
Expand Down

0 comments on commit 2ce6dc0

Please sign in to comment.