Skip to content

Commit

Permalink
Merge pull request #93 from telekom-mms/feature/change-net-and-netip-…
Browse files Browse the repository at this point in the history
…type-conversions

internal/splitrt: change net and netip type conversions
  • Loading branch information
hwipl committed May 24, 2024
2 parents 67783f5 + a6a8a6a commit c406192
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions internal/splitrt/excludes.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ func (e *Excludes) setFilter(ctx context.Context) {
setExcludes(ctx, addresses)
}

// prefixFromIPNet returns ipnet as netip.Prefix.
func prefixFromIPNet(ipnet *net.IPNet) netip.Prefix {
addr, _ := netip.AddrFromSlice(ipnet.IP)
bits, _ := ipnet.Mask.Size()
return netip.PrefixFrom(addr.Unmap(), bits)
}

// AddStatic adds a static entry to the split excludes.
func (e *Excludes) AddStatic(ctx context.Context, address *net.IPNet) {
log.WithField("address", address).Debug("SplitRouting adding static exclude")

a, err := netip.ParsePrefix(address.String())
if err != nil {
log.WithError(err).Error("SplitRouting could not parse static exclude")
return
}
// convert address
a := prefixFromIPNet(address)

e.Lock()
defer e.Unlock()
Expand Down Expand Up @@ -98,11 +102,8 @@ func (e *Excludes) AddDynamic(ctx context.Context, address *net.IPNet, ttl uint3
"ttl": ttl,
}).Debug("SplitRouting adding dynamic exclude")

prefix, err := netip.ParsePrefix(address.String())
if err != nil {
log.WithError(err).Error("SplitRouting could not parse dynamic exclude")
return
}
// convert address
prefix := prefixFromIPNet(address)
if !prefix.IsSingleIP() {
log.Error("SplitRouting error adding dynamic exclude with multiple IPs")
return
Expand Down

0 comments on commit c406192

Please sign in to comment.