Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GetPrefixIPNet func and delete unnecessary statements in strToIPNet func #175

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions pkg/api/networkservice/ipcontext_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,16 @@ func contains(prefixes []*net.IPNet, ip net.IP) bool {

// GetPrefixIPNet - GetPrefix() converted to *net.IPNet or nil if empty or cannot be parsed
func (r *Route) GetPrefixIPNet() *net.IPNet {
return strToIPNet(r.GetPrefix())
prefix := r.GetPrefix()
if prefix == "" {
return nil
}
ip, ipNet, err := net.ParseCIDR(prefix)
if err != nil {
return nil
}
ipNet.IP = ip
return ipNet
}

// GetNextHopIP - GetNextHop() converted to net.IP or nil if empty or cannot be parsed
Expand All @@ -162,10 +171,9 @@ func strToIPNet(in string) *net.IPNet {
if in == "" {
return nil
}
ip, ipNet, err := net.ParseCIDR(in)
_, ipNet, err := net.ParseCIDR(in)
if err != nil {
return nil
}
ipNet.IP = ip
return ipNet
}
Loading