Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-784 Probing in AWS w/VIP support env fixed #869

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 1 addition & 27 deletions pkg/loxinet/layer3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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) {
Expand Down
29 changes: 17 additions & 12 deletions pkg/loxinet/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}
Expand Down
28 changes: 27 additions & 1 deletion pkg/loxinet/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ package loxinet

import (
"fmt"
tk "github.com/loxilb-io/loxilib"
"net"
"net/http"
"os"
"os/exec"
"strconv"
"strings"
"time"

tk "github.com/loxilb-io/loxilib"
nl "github.com/vishvananda/netlink"
)

// IterIntf - interface implementation to iterate various loxinet
Expand Down Expand Up @@ -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
}
Loading