From e289ba60076d5e6cfbe30aa4ac03b8132814c67e Mon Sep 17 00:00:00 2001 From: Trekkie Coder Date: Wed, 1 Jan 2025 11:57:57 +0900 Subject: [PATCH] support modification of cnodes --- pkg/loxinet/dpbroker.go | 52 ++++++++++++++++++------------ pkg/loxinet/dpebpf_linux.go | 64 +++++++++++++++++++++++++++---------- 2 files changed, 80 insertions(+), 36 deletions(-) diff --git a/pkg/loxinet/dpbroker.go b/pkg/loxinet/dpbroker.go index 11022702..f4b7c6a0 100644 --- a/pkg/loxinet/dpbroker.go +++ b/pkg/loxinet/dpbroker.go @@ -18,15 +18,13 @@ package loxinet import ( "fmt" + cmn "github.com/loxilb-io/loxilb/common" + tk "github.com/loxilb-io/loxilib" "net" "os" "runtime/debug" "sync" "time" - - tk "github.com/loxilb-io/loxilib" - - cmn "github.com/loxilb-io/loxilb/common" ) // man names constants @@ -43,6 +41,10 @@ const ( MapNameFw4 = "FW4" ) +const ( + UseRPCPeer = false +) + // error codes const ( DpErrBase = iota - 103000 @@ -448,6 +450,8 @@ type DpHookInterface interface { DpCtDel(w *DpCtInfo) int DpSockVIPAdd(w *SockVIPDpWorkQ) int DpSockVIPDel(w *SockVIPDpWorkQ) int + DpCnodeAdd(w *PeerDpWorkQ) int + DpCnodeDel(w *PeerDpWorkQ) int DpTableGC() DpCtGetAsync() DpGetLock() @@ -770,27 +774,35 @@ func (dp *DpH) DpWorkOnSockVIP(vsWq *SockVIPDpWorkQ) DpRetT { // DpWorkOnPeerOp - routine to work on a peer request for clustering func (dp *DpH) DpWorkOnPeerOp(pWq *PeerDpWorkQ) DpRetT { if pWq.Work == DpCreate { - var newPeer DpPeer - for _, pe := range dp.Peers { - if pe.Peer.Equal(pWq.PeerIP) { - return DpCreateErr + if UseRPCPeer { + var newPeer DpPeer + for _, pe := range dp.Peers { + if pe.Peer.Equal(pWq.PeerIP) { + return DpCreateErr + } } + newPeer.Peer = pWq.PeerIP + dp.Peers = append(dp.Peers, newPeer) + tk.LogIt(tk.LogInfo, "Added cluster-peer %s\n", newPeer.Peer.String()) + return 0 + } else { + return dp.DpHooks.DpCnodeAdd(pWq) } - newPeer.Peer = pWq.PeerIP - dp.Peers = append(dp.Peers, newPeer) - tk.LogIt(tk.LogInfo, "Added cluster-peer %s\n", newPeer.Peer.String()) - return 0 } else if pWq.Work == DpRemove { - for idx := range dp.Peers { - pe := &dp.Peers[idx] - if pe.Peer.Equal(pWq.PeerIP) { - if pe.Client != nil { - dp.RPC.RPCHooks.RPCClose(pe) + if UseRPCPeer { + for idx := range dp.Peers { + pe := &dp.Peers[idx] + if pe.Peer.Equal(pWq.PeerIP) { + if pe.Client != nil { + dp.RPC.RPCHooks.RPCClose(pe) + } + dp.Peers = append(dp.Peers[:idx], dp.Peers[idx+1:]...) + tk.LogIt(tk.LogInfo, "Deleted cluster-peer %s\n", pWq.PeerIP.String()) + return 0 } - dp.Peers = append(dp.Peers[:idx], dp.Peers[idx+1:]...) - tk.LogIt(tk.LogInfo, "Deleted cluster-peer %s\n", pWq.PeerIP.String()) - return 0 } + } else { + return dp.DpHooks.DpCnodeDel(pWq) } } diff --git a/pkg/loxinet/dpebpf_linux.go b/pkg/loxinet/dpebpf_linux.go index 87b0dbfb..f3a5d2ac 100644 --- a/pkg/loxinet/dpebpf_linux.go +++ b/pkg/loxinet/dpebpf_linux.go @@ -271,23 +271,23 @@ func DpEbpfSetLogLevel(logLevel tk.LogLevelT) { func DpEbpfInit(clusterNodes string, rssEn, egrHooks, localSockPolicy, sockMapEn bool, nodeNum int, disBPF bool, logLevel tk.LogLevelT) *DpEbpfH { var cfg C.struct_ebpfcfg - cNodes := strings.Split(clusterNodes, ",") - for i, cNode := range cNodes { - addr := net.ParseIP(cNode) - if addr == nil { - continue - } - if utils.IsIPHostAddr(cNode) { - continue - } - if i == 0 { - cfg.cluster1 = C.CString(cNode) - } else if i == 1 { - cfg.cluster2 = C.CString(cNode) - } - } + //cNodes := strings.Split(clusterNodes, ",") + //for i, cNode := range cNodes { + // addr := net.ParseIP(cNode) + // if addr == nil { + // continue + // } + // if utils.IsIPHostAddr(cNode) { + // continue + // } + // if i == 0 { + // cfg.cluster1 = C.CString(cNode) + // } else if i == 1 { + // cfg.cluster2 = C.CString(cNode) + // } + //} - //if clusterEn { + //if len(clusterEn) > 0 { // cfg.have_mtrace = 1 //} else { // cfg.have_mtrace = 0 @@ -1939,6 +1939,38 @@ func (e *DpEbpfH) DpSockVIPDel(w *SockVIPDpWorkQ) int { return ec } +// DpCnodeAdd - routine to work on adding a cnode +func (e *DpEbpfH) DpCnodeAdd(w *PeerDpWorkQ) int { + cnode := w.PeerIP.String() + + cnodeStr := C.CString(cnode) + defer C.free(unsafe.Pointer(cnodeStr)) + + ec := int(C.llb_add_cnode(cnodeStr)) + if ec != 0 { + *w.Status = DpCreateErr + } else { + *w.Status = 0 + } + return ec +} + +// DpCnodeDel - routine to work on deleting a cnode +func (e *DpEbpfH) DpCnodeDel(w *PeerDpWorkQ) int { + cnode := w.PeerIP.String() + + cnodeStr := C.CString(cnode) + defer C.free(unsafe.Pointer(cnodeStr)) + + ec := int(C.llb_delete_cnode(cnodeStr)) + if ec != 0 { + *w.Status = DpRemoveErr + } else { + *w.Status = 0 + } + return ec +} + //export goMapNotiHandler func goMapNotiHandler(m *mapNoti) {