diff --git a/README.md b/README.md index fd2d7965c..8734d78f4 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ loxilb is an open source hyper-scale software load-balancer for cloud-native wor * Support for TCP, UDP, SCTP (w/ multi-homing), QUIC, FTP, TFTP etc * High-availability support with hitless/maglev/cgnat clustering * Full compliance for K8s loadbalancer Spec - * Multi-cluster support + * Multi-cluster, in-cluster or ext-cluster deployment support - Extensive and scalable liveness probes for cloud-native environments - High-perf replacement for the *aging* iptables/ipvs - L7 proxy support - HTTP1.0, 1.1, 2.0 etc diff --git a/api/loxinlp/nlp.go b/api/loxinlp/nlp.go index a0c734924..8deaae1ae 100644 --- a/api/loxinlp/nlp.go +++ b/api/loxinlp/nlp.go @@ -94,6 +94,11 @@ func NlpRegister(hook cmn.NetHookInterface) { hooks = hook } +func iSBlackListedIntf(name string, masterIdx int) bool { + filter := nNl.BLRgx.MatchString(name) + return filter +} + func applyAllConfig(name string) bool { command := "loxicmd apply --per-intf " + name + " -c /etc/loxilb/ipconfig/" cmd := exec.Command("bash", "-c", command) @@ -1196,8 +1201,7 @@ func DelRoute(route nlp.Route) int { func LUWorkSingle(m nlp.LinkUpdate) int { var ret int - filter := nNl.BLRgx.MatchString(m.Link.Attrs().Name) - if filter { + if iSBlackListedIntf(m.Link.Attrs().Name, m.Link.Attrs().MasterIndex) { return -1 } @@ -1213,8 +1217,7 @@ func AUWorkSingle(m nlp.AddrUpdate) int { return -1 } - filter := nNl.BLRgx.MatchString(link.Attrs().Name) - if filter { + if iSBlackListedIntf(link.Attrs().Name, link.Attrs().MasterIndex) { return -1 } @@ -1251,8 +1254,7 @@ func NUWorkSingle(m nlp.NeighUpdate) int { return -1 } - filter := nNl.BLRgx.MatchString(link.Attrs().Name) - if filter { + if iSBlackListedIntf(link.Attrs().Name, link.Attrs().MasterIndex) { return -1 } @@ -1276,8 +1278,7 @@ func RUWorkSingle(m nlp.RouteUpdate) int { return -1 } - filter := nNl.BLRgx.MatchString(link.Attrs().Name) - if filter { + if iSBlackListedIntf(link.Attrs().Name, link.Attrs().MasterIndex) { return -1 } @@ -1362,8 +1363,7 @@ func GetBridges() { return } for _, link := range links { - filter := nNl.BLRgx.MatchString(link.Attrs().Name) - if filter { + if iSBlackListedIntf(link.Attrs().Name, link.Attrs().MasterIndex) { continue } switch link.(type) { @@ -1389,8 +1389,7 @@ func NlpGet(ch chan bool) int { for _, link := range links { - filter := nNl.BLRgx.MatchString(link.Attrs().Name) - if filter { + if iSBlackListedIntf(link.Attrs().Name, link.Attrs().MasterIndex) { continue } diff --git a/api/models/loadbalance_entry.go b/api/models/loadbalance_entry.go index 5cd573bae..e2c1c1fcd 100644 --- a/api/models/loadbalance_entry.go +++ b/api/models/loadbalance_entry.go @@ -223,6 +223,9 @@ func (m *LoadbalanceEntry) UnmarshalBinary(b []byte) error { // swagger:model LoadbalanceEntryEndpointsItems0 type LoadbalanceEntryEndpointsItems0 struct { + // traffic counters of the endpoint + Counter string `json:"counter,omitempty"` + // IP address for external access EndpointIP string `json:"endpointIP,omitempty"` diff --git a/api/restapi/embedded_spec.go b/api/restapi/embedded_spec.go index 3b52eaa51..63efa87b0 100644 --- a/api/restapi/embedded_spec.go +++ b/api/restapi/embedded_spec.go @@ -3671,6 +3671,10 @@ func init() { "type": "array", "items": { "properties": { + "counter": { + "description": "traffic counters of the endpoint", + "type": "string" + }, "endpointIP": { "description": "IP address for external access", "type": "string" @@ -8120,6 +8124,10 @@ func init() { }, "LoadbalanceEntryEndpointsItems0": { "properties": { + "counter": { + "description": "traffic counters of the endpoint", + "type": "string" + }, "endpointIP": { "description": "IP address for external access", "type": "string" diff --git a/api/restapi/handler/loadbalancer.go b/api/restapi/handler/loadbalancer.go index bd4c5f19c..d56d079e8 100644 --- a/api/restapi/handler/loadbalancer.go +++ b/api/restapi/handler/loadbalancer.go @@ -141,6 +141,7 @@ func ConfigGetLoadbalancer(params operations.GetConfigLoadbalancerAllParams) mid tmpEp.TargetPort = int64(ep.EpPort) tmpEp.Weight = int64(ep.Weight) tmpEp.State = ep.State + tmpEp.Counter = ep.Counters tmpLB.Endpoints = append(tmpLB.Endpoints, tmpEp) } diff --git a/api/swagger.yml b/api/swagger.yml index 34a36f9fd..1c64a999b 100644 --- a/api/swagger.yml +++ b/api/swagger.yml @@ -2349,6 +2349,9 @@ definitions: state: type: string description: state of the endpoint + counter: + type: string + description: traffic counters of the endpoint secondaryIPs: type: array diff --git a/common/common.go b/common/common.go index 57b61be40..dd6ae1d8d 100644 --- a/common/common.go +++ b/common/common.go @@ -526,6 +526,8 @@ type LbEndPointArg struct { Weight uint8 `json:"weight"` // State - current state of the end-point State string `json:"state"` + // Counters - traffic counters of the end-point + Counters string `json:"counters"` } // LbSecIPArg - Secondary IP diff --git a/loxilb-ebpf b/loxilb-ebpf index 8d6e6f82a..9137e240d 160000 --- a/loxilb-ebpf +++ b/loxilb-ebpf @@ -1 +1 @@ -Subproject commit 8d6e6f82a66bcd31312542ae7f1baa7dbe10f867 +Subproject commit 9137e240dccf00ee41c7c8ab3b20b479e1989735 diff --git a/loxinet/rules.go b/loxinet/rules.go index 1ae88db5d..76166610e 100644 --- a/loxinet/rules.go +++ b/loxinet/rules.go @@ -211,7 +211,8 @@ type ruleNatEp struct { inActTries int inActive bool noService bool - mark bool + chkVal bool + stat ruleStat } type ruleNatSIP struct { @@ -759,11 +760,14 @@ func (R *RuleH) GetNatLbRule() ([]cmn.LbRuleMod, error) { continue } + counterStr := fmt.Sprintf("%v:%v", ep.stat.packets, ep.stat.bytes) + ret.Eps = append(ret.Eps, cmn.LbEndPointArg{ - EpIP: ep.xIP.String(), - EpPort: ep.xPort, - Weight: ep.weight, - State: state, + EpIP: ep.xIP.String(), + EpPort: ep.xPort, + Weight: ep.weight, + State: state, + Counters: counterStr, }) } // Make LB rule @@ -1157,7 +1161,7 @@ func (R *RuleH) AddNatLbRule(serv cmn.LbServiceArg, servSecIPs []cmn.LbSecIPArg, if natActs.mode == cmn.LBModeDSR && k.EpPort != serv.ServPort { return RuleUnknownServiceErr, errors.New("malformed-service dsr-port error") } - ep := ruleNatEp{pNetAddr, xNetAddr, k.EpPort, k.Weight, 0, false, false, false} + ep := ruleNatEp{pNetAddr, xNetAddr, k.EpPort, k.Weight, 0, false, false, false, ruleStat{0, 0}} natActs.endPoints = append(natActs.endPoints, ep) } @@ -1194,8 +1198,8 @@ func (R *RuleH) AddNatLbRule(serv cmn.LbServiceArg, servSecIPs []cmn.LbSecIPArg, ruleChg = true e.inActive = false } - e.mark = true - n.mark = true + e.chkVal = true + n.chkVal = true break } } @@ -1203,20 +1207,20 @@ func (R *RuleH) AddNatLbRule(serv cmn.LbServiceArg, servSecIPs []cmn.LbSecIPArg, for i, nEp := range natActs.endPoints { n := &natActs.endPoints[i] - if nEp.mark == false { + if nEp.chkVal == false { ruleChg = true - n.mark = true + n.chkVal = true eEps = append(eEps, *n) } } for i, eEp := range eEps { e := &eEps[i] - if eEp.mark == false { + if eEp.chkVal == false { ruleChg = true e.inActive = true } - e.mark = false + e.chkVal = false } if eRule.hChk.prbType != serv.ProbeType || eRule.hChk.prbPort != serv.ProbePort || @@ -1987,12 +1991,27 @@ func (R *RuleH) RulesSync() { if rule.sync != 0 || rChg { rule.DP(DpCreate) } - rule.DP(DpStatsGet) + + bytes := uint64(0) + packets := uint64(0) + switch at := rule.act.action.(type) { + case *ruleNatActs: + for _, natActs := range at.endPoints { + bytes += natActs.stat.bytes + packets += natActs.stat.packets + } + } + + rule.stat.bytes = bytes + rule.stat.packets = packets + tk.LogIt(-1, "%d:%s,%s pc %v bc %v \n", rule.ruleNum, ruleKeys, ruleActs, rule.stat.packets, rule.stat.bytes) - if rule.hChk.actChk == false { + rule.DP(DpStatsGet) + + if !rule.hChk.actChk { continue } @@ -2303,18 +2322,30 @@ func (r *ruleEnt) DP(work DpWorkT) int { } if work == DpStatsGet { - nStat := new(StatDpWorkQ) - nStat.Work = work - nStat.Mark = uint32(r.ruleNum) - if isNat == true { - nStat.Name = MapNameNat4 + if isNat { + switch at := r.act.action.(type) { + case *ruleNatActs: + for i := range at.endPoints { + nEP := &at.endPoints[i] + nStat := new(StatDpWorkQ) + nStat.Work = work + nStat.Mark = (((uint32(r.ruleNum)) & 0xfff) << 4) | (uint32(i) & 0xf) + nStat.Name = MapNameNat4 + nStat.Bytes = &nEP.stat.bytes + nStat.Packets = &nEP.stat.packets + mh.dp.ToDpCh <- nStat + } + } } else { + nStat := new(StatDpWorkQ) + nStat.Work = work + nStat.Mark = uint32(r.ruleNum) nStat.Name = MapNameFw4 - } - nStat.Bytes = &r.stat.bytes - nStat.Packets = &r.stat.packets + nStat.Bytes = &r.stat.bytes + nStat.Packets = &r.stat.packets - mh.dp.ToDpCh <- nStat + mh.dp.ToDpCh <- nStat + } return 0 }