From 05ea175965d0ef9a91571f2a83702647683ac4eb Mon Sep 17 00:00:00 2001 From: Trekkie Coder Date: Thu, 31 Oct 2024 18:22:37 +0900 Subject: [PATCH] eks: Better support for incluster mode --- api/loxinlp/nlp.go | 2 +- pkg/loxinet/apiclient.go | 2 +- pkg/loxinet/loxinettest.go | 2 +- pkg/loxinet/neighbor.go | 23 ++++++++++++----------- pkg/loxinet/route.go | 6 +++--- pkg/loxinet/rules.go | 5 +++++ 6 files changed, 23 insertions(+), 17 deletions(-) diff --git a/api/loxinlp/nlp.go b/api/loxinlp/nlp.go index 003916b3d..ff9d119a1 100644 --- a/api/loxinlp/nlp.go +++ b/api/loxinlp/nlp.go @@ -1115,7 +1115,7 @@ func DelNeigh(neigh nlp.Neigh, link nlp.Link) int { if neigh.Family == unix.AF_INET || neigh.Family == unix.AF_INET6 { - ret, err = hooks.NetNeighDel(&cmn.NeighMod{IP: neigh.IP}) + ret, err = hooks.NetNeighDel(&cmn.NeighMod{IP: neigh.IP, LinkIndex: neigh.LinkIndex}) if err != nil { tk.LogIt(tk.LogError, "nlp: NH %v %v del failed\n", neigh.IP.String(), name) ret = -1 diff --git a/pkg/loxinet/apiclient.go b/pkg/loxinet/apiclient.go index a93815a45..cfaf068b3 100644 --- a/pkg/loxinet/apiclient.go +++ b/pkg/loxinet/apiclient.go @@ -234,7 +234,7 @@ func (na *NetAPIStruct) NetNeighDel(nm *cmn.NeighMod) (int, error) { mh.mtx.Lock() defer mh.mtx.Unlock() - ret, err := mh.zr.Nh.NeighDelete(nm.IP, RootZone) + ret, err := mh.zr.Nh.NeighDelete(nm.IP, RootZone, nm.LinkIndex) return ret, err } diff --git a/pkg/loxinet/loxinettest.go b/pkg/loxinet/loxinettest.go index 238a31c18..0b98318c6 100644 --- a/pkg/loxinet/loxinettest.go +++ b/pkg/loxinet/loxinettest.go @@ -236,7 +236,7 @@ func TestLoxinet(t *testing.T) { t.Errorf("NHAdd fail 1.1.1.1/24 via 8.8.8.8") } - _, err = mh.zr.Nh.NeighDelete(net.IPv4(8, 8, 8, 8), "default") + _, err = mh.zr.Nh.NeighDelete(net.IPv4(8, 8, 8, 8), "default", 12) if err != nil { t.Errorf("NHAdd fail 8.8.8.8") } diff --git a/pkg/loxinet/neighbor.go b/pkg/loxinet/neighbor.go index a01cd6d74..94bf24eb7 100644 --- a/pkg/loxinet/neighbor.go +++ b/pkg/loxinet/neighbor.go @@ -51,6 +51,7 @@ const ( type NeighKey struct { NhString string Zone string + Link int } // NeighAttr - attributes of a neighbor @@ -357,7 +358,7 @@ func (n *NeighH) NeighGet() ([]cmn.NeighMod, error) { func (n *NeighH) NeighAdd(Addr net.IP, Zone string, Attr NeighAttr) (int, error) { var idx uint64 var err error - key := NeighKey{Addr.String(), Zone} + key := NeighKey{Addr.String(), Zone, Attr.OSLinkIndex} zeroHwAddr, _ := net.ParseMAC("00:00:00:00:00:00") ne, found := n.NeighMap[key] @@ -448,7 +449,7 @@ NhExist: // Add a host specific to this neighbor ec, err := n.Zone.Rt.RtAdd(ipnet, Zone, ra, na) if err != nil && ec != RtExistsErr { - n.NeighDelete(Addr, Zone) + n.NeighDelete(Addr, Zone, Attr.OSLinkIndex) tk.LogIt(tk.LogError, "neigh add - %s:%s host-rt fail(%s)\n", Addr.String(), Zone, err) return NeighHostRtErr, errors.New("nh-hostrt error") } @@ -466,7 +467,7 @@ NhExist: code, err := n.Zone.L2.L2FdbAdd(fdbKey, fdbAttr) if err != nil && code != L2SameFdbErr { n.Zone.Rt.RtDeleteHost(ipnet, Zone) - n.NeighDelete(Addr, Zone) + n.NeighDelete(Addr, Zone, Attr.OSLinkIndex) tk.LogIt(tk.LogError, "neigh add - %s:%s mac fail\n", Addr.String(), Zone) return NeighMacErr, errors.New("nh-mac error") } @@ -480,8 +481,8 @@ NhExist: } // NeighDelete - delete a neigh entry -func (n *NeighH) NeighDelete(Addr net.IP, Zone string) (int, error) { - key := NeighKey{Addr.String(), Zone} +func (n *NeighH) NeighDelete(Addr net.IP, Zone string, Link int) (int, error) { + key := NeighKey{Addr.String(), Zone, Link} ne, found := n.NeighMap[key] if !found { @@ -561,14 +562,14 @@ func (n *NeighH) NeighDelete(Addr net.IP, Zone string) (int, error) { func (n *NeighH) NeighDeleteByPort(port string) { for _, ne := range n.NeighMap { if ne.OifPort != nil && ne.OifPort.Name == port { - n.NeighDelete(ne.Addr, ne.Key.Zone) + n.NeighDelete(ne.Addr, ne.Key.Zone, ne.Key.Link) } } } // NeighFind - Find a neighbor entry -func (n *NeighH) NeighFind(Addr net.IP, Zone string) (*Neigh, int) { - key := NeighKey{Addr.String(), Zone} +func (n *NeighH) NeighFind(Addr net.IP, Zone string, Link int) (*Neigh, int) { + key := NeighKey{Addr.String(), Zone, Link} ne, found := n.NeighMap[key] if found == false { @@ -608,7 +609,7 @@ func (n *NeighH) NeighUnPairRt(ne *Neigh, rt *Rt) int { if len(ne.NhRtm) < 1 && ne.Inactive { // Safely remove tk.LogIt(tk.LogDebug, "neigh rt unpair - %s->%s\n", rt.Key.RtCidr, ne.Key.NhString) - n.NeighDelete(ne.Addr, ne.Key.Zone) + n.NeighDelete(ne.Addr, ne.Key.Zone, ne.Key.Link) ne.DP(DpRemove) } @@ -638,7 +639,7 @@ func (n *NeighH) PortNotifier(name string, osID int, evType PortEvent) { if evType&PortEvDown|PortEvDelete|PortEvLowerDown != 0 { for _, ne := range n.NeighMap { if ne.OifPort != nil && ne.OifPort.Name == name { - n.NeighDelete(net.ParseIP(ne.Key.NhString), ne.Key.Zone) + n.NeighDelete(net.ParseIP(ne.Key.NhString), ne.Key.Zone, ne.Key.Link) } } } @@ -681,7 +682,7 @@ func (n *NeighH) NeighsTicker() { func (n *NeighH) NeighDestructAll() { for _, ne := range n.NeighMap { addr := net.ParseIP(ne.Key.NhString) - n.NeighDelete(addr, ne.Key.NhString) + n.NeighDelete(addr, ne.Key.Zone, ne.Key.Link) } return } diff --git a/pkg/loxinet/route.go b/pkg/loxinet/route.go index dbf01b3c3..5a911ce4a 100644 --- a/pkg/loxinet/route.go +++ b/pkg/loxinet/route.go @@ -275,7 +275,7 @@ func (r *RtH) RtAdd(Dst net.IPNet, Zone string, Ra RtAttr, Na []RtNhAttr) (int, hwmac, _ := net.ParseMAC("00:00:00:00:00:00") for i := range Na { - nh, _ := r.Zone.Nh.NeighFind(Na[i].NhAddr, Zone) + nh, _ := r.Zone.Nh.NeighFind(Na[i].NhAddr, Zone, Na[i].LinkIndex) if nh == nil { // If this is a host route then neighbor has to exist @@ -288,7 +288,7 @@ func (r *RtH) RtAdd(Dst net.IPNet, Zone string, Ra RtAttr, Na []RtNhAttr) (int, } r.Zone.Nh.NeighAdd(Na[i].NhAddr, Zone, NeighAttr{Na[i].LinkIndex, 0, hwmac}) - nh, _ = r.Zone.Nh.NeighFind(Na[i].NhAddr, Zone) + nh, _ = r.Zone.Nh.NeighFind(Na[i].NhAddr, Zone, Na[i].LinkIndex) if nh == nil { delete(r.RtMap, rt.Key) r.Mark.PutCounter(rt.Mark) @@ -329,7 +329,7 @@ func (r *RtH) RtAdd(Dst net.IPNet, Zone string, Ra RtAttr, Na []RtNhAttr) (int, if tret != 0 { // Delete any neigbors created here for i := 0; i < len(newNhs); i++ { - r.Zone.Nh.NeighDelete(newNhs[i].Addr, Zone) + r.Zone.Nh.NeighDelete(newNhs[i].Addr, Zone, newNhs[i].Attr.OSLinkIndex) } delete(r.RtMap, rt.Key) r.Mark.PutCounter(rt.Mark) diff --git a/pkg/loxinet/rules.go b/pkg/loxinet/rules.go index 4efe066f9..b13a77108 100644 --- a/pkg/loxinet/rules.go +++ b/pkg/loxinet/rules.go @@ -2948,6 +2948,11 @@ func (R *RuleH) AdvRuleVIPIfL2(IP net.IP, eIP net.IP, inst string) error { if inst == "" { inst = cmn.CIDefault } + + if IP.String() == "0.0.0.0" { + return nil + } + ciState, _ := mh.has.CIStateGetInst(inst) if ciState == "MASTER" { dev := fmt.Sprintf("llb-rule-%s", IP.String())