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-428 : Associate service name with LB rule and connection entries #429

Merged
merged 2 commits into from
Nov 5, 2023
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
3 changes: 3 additions & 0 deletions api/models/conntrack_entry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions api/models/loadbalance_entry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions api/restapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion api/restapi/handler/conntrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package handler

import (

"github.com/loxilb-io/loxilb/api/models"
"github.com/loxilb-io/loxilb/api/restapi/operations"
tk "github.com/loxilb-io/loxilib"
Expand Down Expand Up @@ -44,7 +45,7 @@ func ConfigGetConntrack(params operations.GetConfigConntrackAllParams) middlewar
tmpResult.Protocol = conntrack.Proto
tmpResult.SourceIP = conntrack.Sip.String()
tmpResult.SourcePort = int64(conntrack.Sport)

tmpResult.ServName = conntrack.ServiceName
result = append(result, &tmpResult)
}
return operations.NewGetConfigConntrackAllOK().WithPayload(&operations.GetConfigConntrackAllOKBody{CtAttr: result})
Expand Down
6 changes: 5 additions & 1 deletion api/restapi/handler/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func ConfigPostLoadbalancer(params operations.PostConfigLoadbalancerParams) midd
lbRules.Serv.ProbePort = params.Attr.ServiceArguments.Probeport
lbRules.Serv.ProbeReq = params.Attr.ServiceArguments.Probereq
lbRules.Serv.ProbeResp = params.Attr.ServiceArguments.Proberesp
lbRules.Serv.Name = params.Attr.ServiceArguments.Name

if lbRules.Serv.Proto == "sctp" {
for _, data := range params.Attr.SecondaryIPs {
Expand Down Expand Up @@ -101,6 +102,7 @@ func ConfigGetLoadbalancer(params operations.GetConfigLoadbalancerAllParams) mid
// Get LB rules
tk.LogIt(tk.LogDebug, "[API] Load balancer %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)


res, err := ApiHooks.NetLbRuleGet()
if err != nil {
tk.LogIt(tk.LogDebug, "[API] Error occur : %v\n", err)
Expand All @@ -111,7 +113,7 @@ func ConfigGetLoadbalancer(params operations.GetConfigLoadbalancerAllParams) mid
for _, lb := range res {
var tmpLB models.LoadbalanceEntry
var tmpSvc models.LoadbalanceEntryServiceArguments

// Service Arg match
tmpSvc.ExternalIP = lb.Serv.ServIP
tmpSvc.Bgp = lb.Serv.Bgp
Expand All @@ -125,6 +127,7 @@ func ConfigGetLoadbalancer(params operations.GetConfigLoadbalancerAllParams) mid
tmpSvc.Managed = lb.Serv.Managed
tmpSvc.Probetype = lb.Serv.ProbeType
tmpSvc.Probeport = lb.Serv.ProbePort
tmpSvc.Name = lb.Serv.Name

tmpLB.ServiceArguments = &tmpSvc

Expand All @@ -149,6 +152,7 @@ func ConfigGetLoadbalancer(params operations.GetConfigLoadbalancerAllParams) mid
}
return operations.NewGetConfigLoadbalancerAllOK().WithPayload(&operations.GetConfigLoadbalancerAllOKBody{LbAttr: result})
}

func ConfigDeleteAllLoadbalancer(params operations.DeleteConfigLoadbalancerAllParams) middleware.Responder {
tk.LogIt(tk.LogDebug, "[API] Load balancer %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)

Expand Down
8 changes: 6 additions & 2 deletions api/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ paths:
description: Maintanence mode
schema:
$ref: '#/definitions/Error'

#----------------------------------------------
# Conntrack
#----------------------------------------------
Expand Down Expand Up @@ -224,7 +223,6 @@ paths:
schema:
$ref: '#/definitions/Error'


#----------------------------------------------
# Port Dump
#----------------------------------------------
Expand Down Expand Up @@ -2331,6 +2329,9 @@ definitions:
type: integer
format: int32
description: value for inactivity timeout (in seconds)
name:
type: string
description: service name

endpoints:
type: array
Expand Down Expand Up @@ -2435,6 +2436,9 @@ definitions:
bytes:
type: integer
description: Packet bytes of the conntrack
servName:
type: string
description: Connection's Service Name

PortEntry:
type: object
Expand Down
4 changes: 4 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@ type LbServiceArg struct {
ProbeReq string `json:"probereq"`
// ProbeResp - Response string for liveness check
ProbeResp string `json:"proberesp"`
// Name - Service name
Name string `json:"name"`
}

// LbEndPointArg - Information related to load-balancer end-point
Expand Down Expand Up @@ -566,6 +568,8 @@ type CtInfo struct {
Pkts uint64 `json:"packets"`
// Bytes - bytes tracked by ct entry
Bytes uint64 `json:"bytes"`
// ServiceName - Connection's service name
ServiceName string `json:"servName"`
}

// UlClArg - ulcl argument information
Expand Down
12 changes: 11 additions & 1 deletion loxinet/dpbroker.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ type DpCtInfo struct {
ServProto string `json:"servproto"`
L4ServPort uint16 `json:"l4servproto"`
BlockNum uint16 `json:"blocknum"`
RuleID uint32 `json:"ruleid"`
}

const (
Expand Down Expand Up @@ -802,6 +803,8 @@ func DpWorker(dp *DpH, f chan int, ch chan interface{}) {
// DpMapGetCt4 - get DP conntrack information as a map
func (dp *DpH) DpMapGetCt4() []cmn.CtInfo {
var CtInfoArr []cmn.CtInfo
var servName string

nTable := new(TableDpWorkQ)
nTable.Work = DpMapGet
nTable.Name = MapNameCt4
Expand All @@ -814,9 +817,16 @@ func (dp *DpH) DpMapGetCt4() []cmn.CtInfo {
switch r := ret.(type) {
case map[string]*DpCtInfo:
for _, dCti := range r {

mh.mtx.Lock()
rule := mh.zr.Rules.GetNatLbRuleByID(dCti.RuleID)
mh.mtx.Unlock()
if rule != nil {
servName = rule.name
}
cti := cmn.CtInfo{Dip: dCti.DIP, Sip: dCti.SIP, Dport: dCti.Dport, Sport: dCti.Sport,
Proto: dCti.Proto, CState: dCti.CState, CAct: dCti.CAct,
Pkts: dCti.Packets, Bytes: dCti.Bytes}
Pkts: dCti.Packets, Bytes: dCti.Bytes, ServiceName: servName}
CtInfoArr = append(CtInfoArr, cti)
}
}
Expand Down
1 change: 1 addition & 0 deletions loxinet/dpebpf_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,7 @@ func (e *DpEbpfH) DpTableGet(w *TableDpWorkQ) (DpRetT, error) {
goCt4Ent.Bytes += b
goCt4Ent.Packets += p
}
goCt4Ent.RuleID = uint32(act.rid)
//fmt.Println(goCt4Ent)
ctMap[goCt4Ent.Key()] = goCt4Ent
}
Expand Down
3 changes: 3 additions & 0 deletions loxinet/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ type ruleEnt struct {
act ruleAct
secIP []ruleNatSIP
stat ruleStat
name string
}

type ruleTable struct {
Expand Down Expand Up @@ -743,6 +744,7 @@ func (R *RuleH) GetNatLbRule() ([]cmn.LbRuleMod, error) {
ret.Serv.ProbePort = data.hChk.prbPort
ret.Serv.ProbeReq = data.hChk.prbReq
ret.Serv.ProbeResp = data.hChk.prbResp
ret.Serv.Name = data.name

for _, sip := range data.secIP {
ret.SecIPs = append(ret.SecIPs, cmn.LbSecIPArg{SecIP: sip.sIP.String()})
Expand Down Expand Up @@ -1257,6 +1259,7 @@ func (R *RuleH) AddNatLbRule(serv cmn.LbServiceArg, servSecIPs []cmn.LbSecIPArg,
r := new(ruleEnt)
r.tuples = rt
r.zone = R.zone
r.name = serv.Name
if serv.Mode == cmn.LBModeFullNAT || serv.Mode == cmn.LBModeOneArm {
r.act.actType = RtActFullNat
} else {
Expand Down
Loading