diff --git a/pkg/loxinet/layer3.go b/pkg/loxinet/layer3.go index 0b1f22ac9..86d52caee 100644 --- a/pkg/loxinet/layer3.go +++ b/pkg/loxinet/layer3.go @@ -81,7 +81,7 @@ func (l3 *L3H) IfaAdd(Obj string, Cidr string) (int, error) { dev := fmt.Sprintf("llb-rule-%s", addr.String()) if Obj != dev { - ret, _ := l3.IfaFind(dev, addr) + ret, _ := l3.IfaFindAddr(dev, addr) if ret == 0 { l3.IfaDelete(dev, addr.String()+"/32") } @@ -353,32 +353,6 @@ func (l3 *L3H) IfaFindAddr(Obj string, addr net.IP) (int, net.IP) { return L3AddrErr, net.IPv4(0, 0, 0, 0) } -// IfaFind - Given any ip address, check if it matches ip address from Obj's ifa list -// This is useful to determine if ip address is already assigned to some interface -func (l3 *L3H) IfaFind(Obj string, addr net.IP) (int, net.IP) { - - key := IfaKey{Obj} - ifa := l3.IfaMap[key] - - if ifa == nil { - return L3ObjErr, net.IPv4(0, 0, 0, 0) - } - - for _, ifaEnt := range ifa.Ifas { - - if (tk.IsNetIPv6(addr.String()) && tk.IsNetIPv4(ifaEnt.IfaNet.IP.String())) || - (tk.IsNetIPv4(addr.String()) && tk.IsNetIPv6(ifaEnt.IfaNet.IP.String())) { - continue - } - - if ifaEnt.IfaNet.IP.Equal(addr) { - return 0, ifaEnt.IfaAddr - } - } - - return L3AddrErr, net.IPv4(0, 0, 0, 0) -} - // IfaSelectAny - Given any dest ip address, select optimal interface source ip address // This is useful to determine source ip address when sending traffic to the given ip address func (l3 *L3H) IfaSelectAny(addr net.IP, findAny bool) (int, net.IP, string) { diff --git a/pkg/loxinet/rules.go b/pkg/loxinet/rules.go index b13a77108..2bdb1b1e6 100644 --- a/pkg/loxinet/rules.go +++ b/pkg/loxinet/rules.go @@ -2297,22 +2297,27 @@ func (R *RuleH) epCheckNow(ep *epHost) { ep.opts.probeType == HostProbeConnectSCTP { if ep.opts.probeType == HostProbeConnectTCP { sType = "tcp" - ret, sIP, _ := R.zone.L3.IfaSelectAny(net.ParseIP(ep.hostName), true) - if ret == 0 { - sHint = sIP.String() - } } else if ep.opts.probeType == HostProbeConnectUDP { sType = "udp" - ret, sIP, _ := R.zone.L3.IfaSelectAny(net.ParseIP(ep.hostName), true) - if ret == 0 { - sHint = sIP.String() - } } else { sType = "sctp" + } + + if mh.cloudHook == nil { ret, sIP, _ := R.zone.L3.IfaSelectAny(net.ParseIP(ep.hostName), true) if ret == 0 { sHint = sIP.String() } + } else { + // For AWS/EKS environments we need to rely on system tables as compared to + // internal tables due to how elastic VIPs are maintained + IfObj := FindSysOifForHost(ep.hostName) + if IfObj != "" && IfObj != "lo" { + ret, sIP, _ := R.zone.L3.IfaSelect(IfObj, net.ParseIP(ep.hostName), true) + if ret == 0 { + sHint = sIP.String() + } + } } sOk := tk.L4ServiceProber(sType, sName, sHint, ep.opts.probeReq, ep.opts.probeResp) ep.transitionEPState(sOk, inActTryThr) @@ -2528,7 +2533,7 @@ func (R *RuleH) RuleDestructAll() { for _, r := range R.tables[RtLB].eMap { lbs.ServIP = r.tuples.l3Dst.addr.IP.String() - fmt.Printf("Deleting %s\n", r.tuples.l3Dst.addr.IP.String()) + tk.LogIt(tk.LogDebug, "Deleting %s\n", r.tuples.l3Dst.addr.IP.String()) if r.tuples.l4Prot.val == 6 { lbs.Proto = "tcp" @@ -2956,7 +2961,7 @@ func (R *RuleH) AdvRuleVIPIfL2(IP net.IP, eIP net.IP, inst string) error { ciState, _ := mh.has.CIStateGetInst(inst) if ciState == "MASTER" { dev := fmt.Sprintf("llb-rule-%s", IP.String()) - ret, _ := R.zone.L3.IfaFind(dev, IP) + ret, _ := R.zone.L3.IfaFindAddr(dev, IP) if ret == 0 { R.zone.L3.IfaDelete(dev, IP.String()+"/32") } @@ -3001,7 +3006,7 @@ func (R *RuleH) AdvRuleVIPIfL2(IP net.IP, eIP net.IP, inst string) error { } else { if _, foundIP := R.zone.L3.IfaAddrLocal(IP); foundIP == nil { dev := fmt.Sprintf("llb-rule-%s", IP.String()) - ret, _ := R.zone.L3.IfaFind(dev, IP) + ret, _ := R.zone.L3.IfaFindAddr(dev, IP) if ret != 0 { _, err := R.zone.L3.IfaAdd(dev, IP.String()+"/32") if err != nil { @@ -3088,7 +3093,7 @@ func (R *RuleH) DeleteRuleVIP(VIP net.IP) { } } dev := fmt.Sprintf("llb-rule-%s", xVIP.String()) - ret, _ := mh.zr.L3.IfaFind(dev, xVIP) + ret, _ := mh.zr.L3.IfaFindAddr(dev, xVIP) if ret == 0 { mh.zr.L3.IfaDelete(dev, xVIP.String()+"/32") } diff --git a/pkg/loxinet/utils.go b/pkg/loxinet/utils.go index a3f938621..30465082c 100644 --- a/pkg/loxinet/utils.go +++ b/pkg/loxinet/utils.go @@ -18,7 +18,6 @@ package loxinet import ( "fmt" - tk "github.com/loxilb-io/loxilib" "net" "net/http" "os" @@ -26,6 +25,9 @@ import ( "strconv" "strings" "time" + + tk "github.com/loxilb-io/loxilib" + nl "github.com/vishvananda/netlink" ) // IterIntf - interface implementation to iterate various loxinet @@ -132,3 +134,27 @@ func FormatTimedelta(t time.Time) string { } return fmt.Sprintf("%dd ", days) + fmt.Sprintf("%02d:%02d:%02d", hours, mins, secs) } + +func FindSysOifForHost(host string) string { + chkIP := net.ParseIP(host) + if chkIP == nil { + return "" + } + rt, err := nl.RouteGet(chkIP) + if err != nil { + tk.LogIt(tk.LogError, " failed to get sys oif for %s\n", host) + return "" + } + + if len(rt) <= 0 { + return "" + } + + ln, err := nl.LinkByIndex(rt[0].LinkIndex) + if err != nil { + tk.LogIt(tk.LogError, " failed to get sys oif linkid for %s\n", host) + return "" + } + + return ln.Attrs().Name +}