From 0f9ca57fad2adf06223c710bcb2c3330b3a7abe2 Mon Sep 17 00:00:00 2001 From: Van Hau TRAN Date: Thu, 9 Jan 2025 20:54:53 +0100 Subject: [PATCH] IfaSelect return at least ip of same protocol of dest addr Signed-off-by: Van Hau TRAN --- pkg/loxinet/layer3.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/loxinet/layer3.go b/pkg/loxinet/layer3.go index 207e56bcf..69df15394 100644 --- a/pkg/loxinet/layer3.go +++ b/pkg/loxinet/layer3.go @@ -281,6 +281,12 @@ func (l3 *L3H) IfaSelect(Obj string, addr net.IP, findAny bool) (int, net.IP, st continue } if len(ifa.Ifas) > 0 { + for _, ifaEnt := range ifa.Ifas { + if (tk.IsNetIPv4(addr.String()) && tk.IsNetIPv4(ifaEnt.IfaNet.IP.String())) || + (tk.IsNetIPv6(addr.String()) && tk.IsNetIPv6(ifaEnt.IfaNet.IP.String())) { + return 0, ifaEnt.IfaAddr, Obj + } + } return 0, ifa.Ifas[0].IfaAddr, Obj } } @@ -309,6 +315,12 @@ func (l3 *L3H) IfaSelect(Obj string, addr net.IP, findAny bool) (int, net.IP, st // Select first IP if len(ifa.Ifas) > 0 { + for _, ifaEnt := range ifa.Ifas { + if (tk.IsNetIPv4(addr.String()) && tk.IsNetIPv4(ifaEnt.IfaNet.IP.String())) || + (tk.IsNetIPv6(addr.String()) && tk.IsNetIPv6(ifaEnt.IfaNet.IP.String())) { + return 0, ifaEnt.IfaAddr, Obj + } + } return 0, ifa.Ifas[0].IfaAddr, Obj }