From e84a0da649b9205d5f8ab3756e22169e56ea6fec Mon Sep 17 00:00:00 2001 From: NikitaSkrynnik Date: Thu, 22 Aug 2024 10:20:56 +1100 Subject: [PATCH] fix GetPrefixIPNet func and delete unnecessary statements in strToIPNet func Signed-off-by: NikitaSkrynnik --- pkg/api/networkservice/ipcontext_helpers.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/api/networkservice/ipcontext_helpers.go b/pkg/api/networkservice/ipcontext_helpers.go index fb9dad6..fb01b9d 100644 --- a/pkg/api/networkservice/ipcontext_helpers.go +++ b/pkg/api/networkservice/ipcontext_helpers.go @@ -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 @@ -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 }