diff --git a/common/common.go b/common/common.go index 01358d5e..1f6ab554 100644 --- a/common/common.go +++ b/common/common.go @@ -242,10 +242,10 @@ const ( type PolInfo struct { PolType int ColorAware bool - CommittedInfoRate uint64 - PeakInfoRate uint64 - CommittedBlkSize uint64 - ExcessBlkSize uint64 + CommittedInfoRate uint64 // CIR in Mbps + PeakInfoRate uint64 // PIR in Mbps + CommittedBlkSize uint64 // CBS in bytes + ExcessBlkSize uint64 // EBS in bytes } type PolObjType uint diff --git a/loxinet/dpebpf_windows.go b/loxinet/dpebpf_windows.go index 546222b6..d2c34331 100644 --- a/loxinet/dpebpf_windows.go +++ b/loxinet/dpebpf_windows.go @@ -19,6 +19,9 @@ import ( "fmt" ) +// This file implements the interface DpHookInterface +// The implementation is specific to loxilb ebpf datapath for windows (in-progress) + const ( EBPF_ERR_BASE = iota - DP_ERR_BASE - 1000 ) @@ -26,56 +29,6 @@ const ( type DpEbpfH struct { } -func (e *DpEbpfH) DpPortPropAdd(w *portDpWorkQ) int { - fmt.Println(*w) - return 0 -} - -func (e *DpEbpfH) DpPortPropDel(w *portDpWorkQ) int { - fmt.Println(*w) - return 0 -} - -func (e *DpEbpfH) DpL2AddrAdd(w *l2AddrDpWorkQ) int { - fmt.Println(*w) - return 0 -} - -func (e *DpEbpfH) DpL2AddrDel(w *l2AddrDpWorkQ) int { - fmt.Println(*w) - return 0 -} - -func (e *DpEbpfH) DpRouterMacAdd(w *routerMacDpWorkQ) int { - fmt.Println(*w) - return 0 -} - -func (e *DpEbpfH) DpRouterMacDel(w *routerMacDpWorkQ) int { - fmt.Println(*w) - return 0 -} - -func (e *DpEbpfH) DpNextHopAdd(w *nextHopDpWorkQ) int { - fmt.Println(*w) - return 0 -} - -func (e *DpEbpfH) DpNextHopDel(w *nextHopDpWorkQ) int { - fmt.Println(*w) - return 0 -} - -func (e *DpEbpfH) DpRouteAdd(w *RouteDpWorkQ) int { - fmt.Println(*w) - return 0 -} - -func (e *DpEbpfH) DpRouteDel(w *RouteDpWorkQ) int { - fmt.Println(*w) - return 0 -} - func DpEbpfInit() *DpEbpfH { ne := new(DpEbpfH) return ne diff --git a/loxinet/rules.go b/loxinet/rules.go index 734e622d..7a15e9db 100644 --- a/loxinet/rules.go +++ b/loxinet/rules.go @@ -189,6 +189,7 @@ const ( RT_MAX_LB = (2 * 1024) ) +// Tunable parameters related to inactive rules type RuleCfg struct { RuleInactTries int RuleInactChkTime int @@ -200,6 +201,7 @@ type RuleH struct { Tables [RT_MAX]ruleTable } +// Initialize the Rules subsystem func RulesInit(zone *Zone) *RuleH { var nRh = new(RuleH) nRh.Zone = zone @@ -479,6 +481,7 @@ func (a *ruleAct) String() string { return ks } +// Output all rules into json and write to the byte array func (R *RuleH) Rules2Json() ([]byte, error) { var t cmn.LbServiceArg var eps []cmn.LbEndPointArg @@ -526,6 +529,7 @@ func (R *RuleH) Rules2Json() ([]byte, error) { return bret, nil } +// Get all rules and pack them into a cmn.LbRuleMod slice func (R *RuleH) GetNatLbRule() ([]cmn.LbRuleMod, error) { var res []cmn.LbRuleMod @@ -564,20 +568,26 @@ func (R *RuleH) GetNatLbRule() ([]cmn.LbRuleMod, error) { return res, nil } +// Add a service LB nat rule. The service details are passed in serv argument, +// and end-point information is passed in the slice servEntdPoints. On success, +// it will return 0 and nil error, else appropriate return code and error string will be set func (R *RuleH) AddNatLbRule(serv cmn.LbServiceArg, servEndPoints []cmn.LbEndPointArg) (int, error) { var natActs ruleNatActs var ipProto uint8 + // Vaildate service args service := serv.ServIP + "/32" _, sNetAddr, err := net.ParseCIDR(service) if err != nil { return RULE_UNK_SERV_ERR, errors.New("malformed-service error") } + // Currently support a maximum of MAX_NAT_EPS if len(servEndPoints) <= 0 || len(servEndPoints) > MAX_NAT_EPS { return RULE_EP_COUNT_ERR, errors.New("endpoints-range error") } + // For ICMP service, non-zero port can't be specified if serv.Proto == "icmp" && serv.ServPort != 0 { return RULE_UNK_SERV_ERR, errors.New("malformed-service error") } @@ -666,6 +676,7 @@ func (R *RuleH) AddNatLbRule(serv cmn.LbServiceArg, servEndPoints []cmn.LbEndPoi return RULE_EXISTS_ERR, errors.New("lbrule-exists error") } + // Update the rule eRule.act.action.(*ruleNatActs).sel = natActs.sel eRule.act.action.(*ruleNatActs).endPoints = eEps eRule.sT = time.Now() @@ -700,6 +711,9 @@ func (R *RuleH) AddNatLbRule(serv cmn.LbServiceArg, servEndPoints []cmn.LbEndPoi return 0, nil } +// Delete a service LB nat rule. The service details are passed in serv argument. +// On success, it will return 0 and nil error, else appropriate return code and +// error string will be set func (R *RuleH) DeleteNatLbRule(serv cmn.LbServiceArg) (int, error) { var ipProto uint8 @@ -742,7 +756,7 @@ func (R *RuleH) DeleteNatLbRule(serv cmn.LbServiceArg) (int, error) { return 0, nil } -// This is periodic routine which does two main things : +// This is periodic ticker routine which does two main things : // 1. Syncs rule statistics counts // 2. Check health of lb-rule end-points func (R *RuleH) RulesSync() { @@ -816,6 +830,7 @@ func (R *RuleH) RulesTicker() { R.RulesSync() } +// Destructor routine for all rules func (R *RuleH) RuleDestructAll() { var lbs cmn.LbServiceArg for _, r := range R.Tables[RT_LB].eMap { @@ -839,7 +854,7 @@ func (R *RuleH) RuleDestructAll() { return } -// Sync state of nat-rule entities to data-path +// Sync state of nat-rule entity to data-path func (r *ruleEnt) Nat2DP(work DpWorkT) int { nWork := new(NatDpWorkQ) @@ -890,7 +905,7 @@ func (r *ruleEnt) Nat2DP(work DpWorkT) int { return 0 } -// Sync state of rule entities to data-path +// Sync state of rule entity to data-path func (r *ruleEnt) DP(work DpWorkT) int { if work == DP_TABLE_GET { diff --git a/main.go b/main.go index d5f07edd..97c430bc 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,6 @@ import ( const ( MKFS_SCRIPT = "/usr/local/sbin/mkllb_bpffs" - RUNNING_FLAG_FILE = "/var/run/loxilb" BPF_FS_CHK_FILE = "/opt/loxilb/dp/bpf/intf_map" ) @@ -53,6 +52,7 @@ var buildInfo string = "" func main() { fmt.Printf("loxilb start\n") + // Parse command-line arguments _, err := flags.Parse(&opts.Opts) if err != nil { fmt.Println(err) @@ -64,6 +64,8 @@ func main() { os.Exit(0) } + // It is important to make sure loxilb's eBPF filesystem + // is in place and mounted to make sure maps are pinned properly if fileExists(BPF_FS_CHK_FILE) == false { if fileExists(MKFS_SCRIPT) { _, err := exec.Command("/bin/bash", MKFS_SCRIPT).Output()