Skip to content

Commit

Permalink
SCTP-multihoming changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TrekkieCoder committed May 25, 2023
1 parent 72a04e3 commit 4100228
Show file tree
Hide file tree
Showing 11 changed files with 309 additions and 74 deletions.
94 changes: 94 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.

8 changes: 8 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.

14 changes: 14 additions & 0 deletions api/restapi/handler/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ func ConfigPostLoadbalancer(params operations.PostConfigLoadbalancerParams) midd
lbRules.Serv.Mode = cmn.LBMode(params.Attr.ServiceArguments.Mode)
lbRules.Serv.InactiveTimeout = uint32(params.Attr.ServiceArguments.InactiveTimeOut)

if lbRules.Serv.Proto == "sctp" {
for _, data := range params.Attr.SecondaryIPs {
lbRules.SecIPs = append(lbRules.SecIPs, cmn.LbSecIpArg{
SecIP: data.SecondaryIP,
})
}
}

for _, data := range params.Attr.Endpoints {
lbRules.Eps = append(lbRules.Eps, cmn.LbEndPointArg{
EpIP: data.EndpointIP,
Expand Down Expand Up @@ -112,6 +120,12 @@ func ConfigGetLoadbalancer(params operations.GetConfigLoadbalancerAllParams) mid

tmpLB.ServiceArguments = &tmpSvc

for _, sip := range lb.SecIPs {
tmpSIP := new(models.LoadbalanceEntrySecondaryIPsItems0)
tmpSIP.SecondaryIP = sip.SecIP
tmpLB.SecondaryIPs = append(tmpLB.SecondaryIPs, tmpSIP)
}

// Endpoints match
for _, ep := range lb.Eps {
tmpEp := new(models.LoadbalanceEntryEndpointsItems0)
Expand Down
8 changes: 8 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,18 @@ type LbEndPointArg struct {
State string `json:"state"`
}

// LbSecIpArg - Secondary IP
type LbSecIpArg struct {
// SecIP - Secondary IP address
SecIP string `json:"secondaryIP"`
}

// LbRuleMod - Info related to a load-balancer entry
type LbRuleMod struct {
// Serv - service argument of type LbServiceArg
Serv LbServiceArg `json:"serviceArguments"`
// SecIPs - Secondary IPs for SCTP multi-homed service
SecIPs []LbSecIpArg `json:"secondaryIPs"`
// Eps - slice containing LbEndPointArg
Eps []LbEndPointArg `json:"endpoints"`
}
Expand Down
14 changes: 10 additions & 4 deletions loxinet/apiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,15 @@ func (*NetAPIStruct) NetRouteDel(rm *cmn.RouteMod) (int, error) {
func (*NetAPIStruct) NetLbRuleAdd(lm *cmn.LbRuleMod) (int, error) {
mh.mtx.Lock()
defer mh.mtx.Unlock()

ret, err := mh.zr.Rules.AddNatLbRule(lm.Serv, lm.Eps[:])
var ips []string
ret, err := mh.zr.Rules.AddNatLbRule(lm.Serv, lm.SecIPs[:], lm.Eps[:])
if err == nil && lm.Serv.Bgp {
if mh.bgp != nil {
mh.bgp.AddBGPRule("default", lm.Serv.ServIP)
ips = append(ips, lm.Serv.ServIP)
for _, ip := range lm.SecIPs {
ips = append(ips, ip.SecIP)
}
mh.bgp.AddBGPRule("default", ips)
} else {
tk.LogIt(tk.LogDebug, "loxilb BGP mode is disabled \n")
}
Expand All @@ -270,10 +274,12 @@ func (*NetAPIStruct) NetLbRuleDel(lm *cmn.LbRuleMod) (int, error) {
mh.mtx.Lock()
defer mh.mtx.Unlock()

ips := mh.zr.Rules.GetNatLbRuleSecIPs(lm.Serv)
ret, err := mh.zr.Rules.DeleteNatLbRule(lm.Serv)
if lm.Serv.Bgp {
if mh.bgp != nil {
mh.bgp.DelBGPRule("default", lm.Serv.ServIP)
ips = append(ips, lm.Serv.ServIP)
mh.bgp.DelBGPRule("default", ips)
} else {
tk.LogIt(tk.LogDebug, "loxilb BGP mode is disabled \n")
}
Expand Down
1 change: 1 addition & 0 deletions loxinet/dpbroker.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ type NatDpWorkQ struct {
EpSel NatSel
InActTo uint64
endPoints []NatEP
secIP []net.IP
}

// DpCtInfo - representation of a datapath conntrack information
Expand Down
24 changes: 19 additions & 5 deletions loxinet/dpebpf_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,14 @@ func DpNatLbRuleMod(w *NatDpWorkQ) int {
// seconds to nanoseconds
dat.ito = C.uint64_t(w.InActTo * 1000000000)

/*dat.npmhh = 2
dat.pmhh[0] = 0x64646464
dat.pmhh[1] = 0x65656565*/
for i, k := range w.secIP {
dat.pmhh[i] = C.uint(tk.IPtonl(k))
}
dat.npmhh = C.uchar(len(w.secIP))

switch {
case w.EpSel == EpRR:
dat.sel_type = C.NAT_LB_SEL_RR
Expand All @@ -787,7 +795,7 @@ func DpNatLbRuleMod(w *NatDpWorkQ) int {
nxfa := (*nxfrmAct)(unsafe.Pointer(&dat.nxfrms[0]))

for _, k := range w.endPoints {
nxfa.wprio = C.ushort(k.Weight)
nxfa.wprio = C.uchar(k.Weight)
nxfa.nat_xport = C.ushort(tk.Htons(k.XPort))
if tk.IsNetIPv6(k.XIP.String()) {
convNetIP2DPv6Addr(unsafe.Pointer(&nxfa.nat_xip[0]), k.XIP)
Expand Down Expand Up @@ -1656,24 +1664,30 @@ func dpCTMapChkUpdates() {
if time.Duration(tc.Sub(cti.LTs).Seconds()) >= time.Duration(5*60) {
tk.LogIt(tk.LogInfo, "[CT] out-of-sync %s:%s:%v\n", cti.Key(), cti.CState, cti.XSync)
if C.bpf_map_lookup_elem(C.int(fd), unsafe.Pointer(&cti.PKey[0]), unsafe.Pointer(&tact)) != 0 {
tk.LogIt(tk.LogInfo, "[CT] out-of-sync not found %s:%s:%v\n", cti.Key(), cti.CState, cti.XSync)
delete(mh.dpEbpf.ctMap, cti.Key())
continue
}
cti.PVal = C.GoBytes(unsafe.Pointer(&tact), C.sizeof_struct_dp_ct_tact)
cti.LTs = tc
}

if len(cti.PVal) > 0 && cti.XSync == false {
if time.Duration(tc.Sub(cti.NTs).Seconds()) < time.Duration(60) {
continue
}
if C.bpf_map_lookup_elem(C.int(fd), unsafe.Pointer(&cti.PKey[0]), unsafe.Pointer(&tact)) != 0 {
tk.LogIt(tk.LogInfo, "[CT] ent not found %s\n", cti.Key())
delete(mh.dpEbpf.ctMap, cti.Key())
continue
}
ptact := (*C.struct_dp_ct_tact)(unsafe.Pointer(&cti.PVal[0]))
ret := C.llb_fetch_map_stats_cached(C.int(C.LL_DP_CT_STATS_MAP), C.uint(ptact.ca.cidx), C.int(0),
(unsafe.Pointer(&b)), unsafe.Pointer(&p))

if ret == 0 {
if cti.Packets != p {
cti.Bytes = b
cti.Packets = p
if cti.Packets != p+uint64(tact.ctd.pb.packets) {
cti.Bytes = b + uint64(tact.ctd.pb.bytes)
cti.Packets = p + uint64(tact.ctd.pb.packets)
cti.XSync = true
cti.NTs = tc
cti.LTs = tc
Expand Down
Loading

0 comments on commit 4100228

Please sign in to comment.