Skip to content

Commit

Permalink
IfaSelect return at least ip of same protocol of dest addr
Browse files Browse the repository at this point in the history
Signed-off-by: Van Hau TRAN <[email protected]>
  • Loading branch information
vanonox committed Jan 9, 2025
1 parent 3678f70 commit 0f9ca57
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/loxinet/layer3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 0f9ca57

Please sign in to comment.