Skip to content

Commit

Permalink
Remove duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Sep 5, 2024
1 parent cbb3540 commit a9e0c6e
Showing 1 changed file with 3 additions and 22 deletions.
25 changes: 3 additions & 22 deletions cmd/internal/switcher/types/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,9 @@ func (c *Conf) FillRouteMapsAndIPPrefixLists() error {
return err
}

ipv4, ipv6, err := addressFamilies(t.Cidrs)
if err != nil {
return fmt.Errorf("unable to parse addressfamilies from cidrs:%w", err)
}
t.Has4 = ipv4
t.Has6 = ipv6
cidrsByAf := cidrsByAddressfamily(t.Cidrs)
t.Has4 = len(cidrsByAf.ipv4Cidrs) > 0
t.Has6 = len(cidrsByAf.ipv6Cidrs) > 0
t.Assemble(vrf, []string{}, t.Cidrs)
}
return nil
Expand Down Expand Up @@ -80,22 +77,6 @@ func compactCidrs(cidrs []string) ([]string, error) {
return compacted, nil
}

func addressFamilies(cidrs []string) (ipv4, ipv6 bool, err error) {
for _, cidr := range cidrs {
parsed, err := netip.ParsePrefix(cidr)
if err != nil {
return false, false, err
}
if parsed.Addr().Is4() {
ipv4 = true
}
if parsed.Addr().Is6() {
ipv6 = true
}
}
return ipv4, ipv6, nil
}

// CapitalizeVrfName capitalizes VRF names, which is requirement for SONiC
func (c *Conf) CapitalizeVrfName() {
caser := cases.Title(language.English)
Expand Down

0 comments on commit a9e0c6e

Please sign in to comment.