From f354fa8a4ffc9ea009ac67f034983d6e11043e2b Mon Sep 17 00:00:00 2001 From: Trekkie Coder Date: Tue, 15 Oct 2024 13:58:06 +0900 Subject: [PATCH] Added check AF_INET/AF_INET6 for dual-stack environments --- api/loxinlp/nlp.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/api/loxinlp/nlp.go b/api/loxinlp/nlp.go index 331fc2e57..1fa8f6902 100644 --- a/api/loxinlp/nlp.go +++ b/api/loxinlp/nlp.go @@ -1188,10 +1188,19 @@ func DelNeigh(neigh nlp.Neigh, link nlp.Link) int { func AddRoute(route nlp.Route) int { var ipNet net.IPNet if route.Dst == nil { - r := net.IPv4(0, 0, 0, 0) - m := net.CIDRMask(0, 32) - r = r.Mask(m) - ipNet = net.IPNet{IP: r, Mask: m} + if route.Family == 2 { + r := net.IPv4(0, 0, 0, 0) + m := net.CIDRMask(0, 32) + r = r.Mask(m) + ipNet = net.IPNet{IP: r, Mask: m} + } else if route.Family == 10 { + r := net.ParseIP("::") + m := net.CIDRMask(0, 128) + r = r.Mask(m) + ipNet = net.IPNet{IP: r, Mask: m} + } else { + return -1 + } } else { ipNet = *route.Dst }