Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
chdxD1 committed Nov 28, 2023
1 parent afaa439 commit c52d5ce
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 @@ -28,20 +28,16 @@ type templateConfig struct {

func (m *Manager) Configure(in Configuration) (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)
Expand Down Expand Up @@ -70,6 +66,14 @@ func (m *Manager) Configure(in Configuration) (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) (*templateConfig, error) {
vrfRouterID, err := (&nl.NetlinkManager{}).GetUnderlayIP()
if err != nil {
Expand Down Expand Up @@ -105,11 +109,7 @@ func (m *Manager) renderSubtemplates(in Configuration) (*templateConfig, error)
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 @@ -70,7 +70,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 @@ -88,18 +88,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 c52d5ce

Please sign in to comment.