Skip to content

Commit

Permalink
loxilb-iogh-61 fixes as per golint
Browse files Browse the repository at this point in the history
  • Loading branch information
PacketCrunch committed Nov 28, 2022
1 parent 7f43fc9 commit 9cbe0ed
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 71 deletions.
2 changes: 1 addition & 1 deletion api/loxinlp/nlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ func ModLink(link nlp.Link, add bool) int {
pType := cmn.PortReal
tunId := 0

if strings.Contains(name, "ipsec") || strings.Contains(name, "vti") {
if strings.Contains(name, "ipsec") || strings.Contains(name, "vti") {
pType = cmn.PortVti
} else if strings.Contains(name, "wg") {
pType = cmn.PortWg
Expand Down
6 changes: 4 additions & 2 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,14 @@ type Routev4Mod struct {
Dst net.IPNet
}

// FwRuleOpts - Information related to Firewall options
// FwRuleOpts - Information related to Firewall options
type FwOptArg struct {
// Drop - Drop any matching rule
Drop bool `json:"drop"`
// Trap - Trap anything matching rule
Trap bool `json:"trap"`
// Redirect - Redirect any matching rule
Rdr bool `json:"redirect"`
Rdr bool `json:"redirect"`
RdrPort string `json:"redirectPortName"`
// Allow - Allow any matching rule
Allow bool `json:"allow"`
Expand Down
6 changes: 3 additions & 3 deletions loxinet/apiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (*NetAPIStruct) NetIpv4AddrDel(am *cmn.Ipv4AddrMod) (int, error) {
return ret, err
}

// NetNeighGet - Get a ipv4 neighbor in loxinet
// NetNeighv4Get - Get a ipv4 neighbor in loxinet
func (*NetAPIStruct) NetNeighv4Get() ([]cmn.Neighv4Mod, error) {
ret, err := mh.zr.Nh.NeighGet()
return ret, err
Expand Down Expand Up @@ -361,14 +361,14 @@ func (*NetAPIStruct) NetPolicerDel(pm *cmn.PolMod) (int, error) {
return ret, err
}

// NetPolicerGet - Get a policer in loxinet
// NetHAStateGet - Get current node cluster state
func (*NetAPIStruct) NetHAStateGet() (string, error) {
// There is no locking requirement for this operation
ret, err := mh.has.HAStateGet()
return ret, err
}

// NetPolicerAdd - Add a policer in loxinet
// NetHAStateMod - Modify cluster state
func (*NetAPIStruct) NetHAStateMod(hm *cmn.HASMod) (int, error) {
mh.mtx.Lock()
defer mh.mtx.Unlock()
Expand Down
33 changes: 17 additions & 16 deletions loxinet/dpbroker.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,26 +200,27 @@ const (
DpFwDrop FwOpT = iota + 1
DpFwFwd
DpFwRdr
DpFwTrap
)

// FwDpWorkQ - work queue entry for fw related operation
type FwDpWorkQ struct {
Work DpWorkT
Status *DpStatusT
ZoneNum int
SrcIP net.IPNet
DstIP net.IPNet
L4SrcMin uint16
L4SrcMax uint16
L4DstMin uint16
L4DstMax uint16
Port uint16
Pref uint16
Proto uint8
HwMark int
FwType FwOpT
FwVal1 uint16
FwVal2 uint32
Work DpWorkT
Status *DpStatusT
ZoneNum int
SrcIP net.IPNet
DstIP net.IPNet
L4SrcMin uint16
L4SrcMax uint16
L4DstMin uint16
L4DstMax uint16
Port uint16
Pref uint16
Proto uint8
HwMark int
FwType FwOpT
FwVal1 uint16
FwVal2 uint32
}

// NatT - type of NAT
Expand Down
7 changes: 4 additions & 3 deletions loxinet/dpebpf_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1248,8 +1248,10 @@ func (e *DpEbpfH) DpFwRuleMod(w *FwDpWorkQ) int {
} else if w.FwType == DpFwRdr {
fwe.fwa.ca.act_type = C.DP_SET_RDR_PORT
pRdr := (*portAct)(getPtrOffset(unsafe.Pointer(&fwe.fwa),
C.sizeof_struct_dp_cmn_act))
C.sizeof_struct_dp_cmn_act))
pRdr.oport = C.ushort(w.FwVal1)
} else if w.FwType == DpFwTrap {
fwe.fwa.ca.act_type = C.DP_SET_TOCP
}
ret := C.llb_add_map_elem(C.LL_DP_FW4_MAP, unsafe.Pointer(fwe), unsafe.Pointer(nil))
if ret != 0 {
Expand All @@ -1259,7 +1261,7 @@ func (e *DpEbpfH) DpFwRuleMod(w *FwDpWorkQ) int {
} else if w.Work == DpRemove {
C.llb_del_map_elem(C.LL_DP_FW4_MAP, unsafe.Pointer(fwe))
}

return 0
}

Expand All @@ -1278,4 +1280,3 @@ func (e *DpEbpfH) DpFwRuleAdd(w *FwDpWorkQ) int {
func (e *DpEbpfH) DpFwRuleDel(w *FwDpWorkQ) int {
return e.DpFwRuleMod(w)
}

20 changes: 10 additions & 10 deletions loxinet/loxinettest.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,28 +356,28 @@ func TestLoxinet(t *testing.T) {
t.Errorf("Failed to delete mirror mirr-1\n")
}

fwR := cmn.FwRuleArg { SrcIP : "192.168.1.2/24", DstIP : "192.168.2.1/24", Pref : 100}
fwOpts := cmn.FwOptArg { Drop : true}
_, err = mh.zr.Rules.AddFwRule( fwR, fwOpts)
fwR := cmn.FwRuleArg{SrcIP: "192.168.1.2/24", DstIP: "192.168.2.1/24", Pref: 100}
fwOpts := cmn.FwOptArg{Drop: true}
_, err = mh.zr.Rules.AddFwRule(fwR, fwOpts)
if err != nil {
t.Errorf("Failed to add fw-1\n")
}

fwR1 := cmn.FwRuleArg { SrcIP : "192.169.1.2/24", DstIP : "192.169.2.1/24", Pref : 200}
fwOpts = cmn.FwOptArg { Drop : true}
_, err = mh.zr.Rules.AddFwRule( fwR1, fwOpts)
fwR1 := cmn.FwRuleArg{SrcIP: "192.169.1.2/24", DstIP: "192.169.2.1/24", Pref: 200}
fwOpts = cmn.FwOptArg{Drop: true}
_, err = mh.zr.Rules.AddFwRule(fwR1, fwOpts)
if err != nil {
t.Errorf("Failed to add fw-2\n")
}

_, err = mh.zr.Rules.AddFwRule( fwR1, fwOpts)
_, err = mh.zr.Rules.AddFwRule(fwR1, fwOpts)
if err == nil {
t.Errorf("Allowed to add duplicate fw-2\n")
}

fwR2 := cmn.FwRuleArg { SrcIP : "0.0.0.0/0", DstIP : "31.31.31.1/24", Pref : 200}
fwOpts = cmn.FwOptArg { Allow : true}
_, err = mh.zr.Rules.AddFwRule( fwR2, fwOpts)
fwR2 := cmn.FwRuleArg{SrcIP: "0.0.0.0/0", DstIP: "31.31.31.1/24", Pref: 200}
fwOpts = cmn.FwOptArg{Allow: true}
_, err = mh.zr.Rules.AddFwRule(fwR2, fwOpts)
if err != nil {
t.Errorf("Failed to add fw-3\n")
}
Expand Down
1 change: 1 addition & 0 deletions loxinet/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func MirrInfoCmp(mInfo1, mInfo2 *cmn.MirrInfo) bool {
return false
}

// MirrGet - Get mirrors in loxinet
func (M *MirrH) MirrGet() ([]cmn.MirrGetMod, error) {
var ret []cmn.MirrGetMod
for mk, me := range M.MirrMap {
Expand Down
9 changes: 5 additions & 4 deletions loxinet/neighbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ func (n *NeighH) NeighRecursiveResolve(ne *Neigh) bool {
return chg
}

// NeighGet - Get neigh entries in Neighv4Mod slice
func (n *NeighH) NeighGet() ([]cmn.Neighv4Mod, error) {
var ret []cmn.Neighv4Mod
for _, n2 := range n.NeighMap {
Expand Down Expand Up @@ -376,9 +377,9 @@ NhExist:
fdbAddr[i] = uint8(ne.Attr.HardwareAddr[i])
}
if port.SInfo.PortType&cmn.PortReal != 0 {
vid = port.PortNo + RealPortIdB
vid = port.PortNo + RealPortIDB
} else {
vid = port.PortNo + BondIdB
vid = port.PortNo + BondIDB
}

fdbKey := FdbKey{fdbAddr, vid}
Expand Down Expand Up @@ -419,9 +420,9 @@ func (n *NeighH) NeighDelete(Addr net.IP, Zone string) (int, error) {
fdbAddr[i] = uint8(ne.Attr.HardwareAddr[i])
}
if port.SInfo.PortType&cmn.PortReal != 0 {
vid = port.PortNo + RealPortIdB
vid = port.PortNo + RealPortIDB
} else {
vid = port.PortNo + BondIdB
vid = port.PortNo + BondIDB
}

fdbKey := FdbKey{fdbAddr, vid}
Expand Down
31 changes: 17 additions & 14 deletions loxinet/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ const (
MaxInterfaces = 512
MaxWgInterfaces = 8
MaxVtiInterfaces = 8
RealPortIdB = 3800
BondIdB = 4000
WgIdB = 4010
VtIdB = 4020
RealPortIDB = 3800
BondIDB = 4000
WgIDB = 4010
VtIDB = 4020
)

// PortEvent - port event type
Expand Down Expand Up @@ -248,7 +248,7 @@ func (P *PortsH) PortAdd(name string, osid int, ptype int, zone string,
p.SInfo.PortType |= ptype
p.HInfo.Master = hwi.Master
p.L2.IsPvid = true
p.L2.Vid = master.PortNo + BondIdB
p.L2.Vid = master.PortNo + BondIDB

//p.DP(DpCreate)
return 0, nil
Expand Down Expand Up @@ -284,7 +284,7 @@ func (P *PortsH) PortAdd(name string, osid int, ptype int, zone string,
if p.SInfo.PortType&(cmn.PortReal|cmn.PortBondSif) == (cmn.PortReal | cmn.PortBondSif) {
if ptype == cmn.PortReal {
p.L2.IsPvid = true
p.L2.Vid = p.PortNo + RealPortIdB
p.L2.Vid = p.PortNo + RealPortIDB
p.SInfo.PortType &= ^cmn.PortBondSif
p.HInfo.Master = ""
p.DP(DpCreate)
Expand Down Expand Up @@ -339,31 +339,31 @@ func (P *PortsH) PortAdd(name string, osid int, ptype int, zone string,
switch ptype {
case cmn.PortReal:
p.L2.IsPvid = true
p.L2.Vid = rid + RealPortIdB
p.L2.Vid = rid + RealPortIDB

/* We create an vlan BD to keep things in sync */
vstr := fmt.Sprintf("vlan%d", p.L2.Vid)
zn.Vlans.VlanAdd(p.L2.Vid, vstr, zone, -1,
PortHwInfo{vMac, true, true, 9000, "", "", 0})
case cmn.PortBond:
p.L2.IsPvid = true
p.L2.Vid = rid + BondIdB
p.L2.Vid = rid + BondIDB

/* We create an vlan BD to keep things in sync */
vstr := fmt.Sprintf("vlan%d", p.L2.Vid)
zn.Vlans.VlanAdd(p.L2.Vid, vstr, zone, -1,
PortHwInfo{vMac, true, true, 9000, "", "", 0})
case cmn.PortWg:
p.L2.IsPvid = true
p.L2.Vid = rid + WgIdB
p.L2.Vid = rid + WgIDB

/* We create an vlan BD to keep things in sync */
vstr := fmt.Sprintf("vlan%d", p.L2.Vid)
zn.Vlans.VlanAdd(p.L2.Vid, vstr, zone, -1,
PortHwInfo{vMac, true, true, 9000, "", "", 0})
case cmn.PortVti:
p.L2.IsPvid = true
p.L2.Vid = rid + VtIdB
p.L2.Vid = rid + VtIDB

/* We create an vlan BD to keep things in sync */
vstr := fmt.Sprintf("vlan%d", p.L2.Vid)
Expand Down Expand Up @@ -413,7 +413,7 @@ func (P *PortsH) PortDel(name string, ptype int) (int, error) {
p.SInfo.PortReal = nil
p.HInfo.Master = ""
p.L2.IsPvid = true
p.L2.Vid = p.PortNo + RealPortIdB
p.L2.Vid = p.PortNo + RealPortIDB
p.DP(DpCreate)
return 0, nil
}
Expand All @@ -435,7 +435,7 @@ func (P *PortsH) PortDel(name string, ptype int) (int, error) {
p.DP(DpRemove)
p.SInfo.PortType = p.SInfo.PortType & ^cmn.PortVlanSif
p.L2.IsPvid = true
p.L2.Vid = p.PortNo + BondIdB
p.L2.Vid = p.PortNo + BondIDB
p.DP(DpCreate)
return 0, nil
}
Expand All @@ -446,7 +446,7 @@ func (P *PortsH) PortDel(name string, ptype int) (int, error) {
p.SInfo.PortType = p.SInfo.PortType & ^cmn.PortBondSif
p.HInfo.Master = ""
p.L2.IsPvid = true
p.L2.Vid = p.PortNo + RealPortIdB
p.L2.Vid = p.PortNo + RealPortIDB
p.DP(DpCreate)
return 0, nil
}
Expand Down Expand Up @@ -986,16 +986,19 @@ func (p *Port) DP(work DpWorkT) int {
return 0
}

// IsLeafPort - check if the port is a leaf port (eBPF hooks need to
// attached to such ports)
func (p *Port) IsLeafPort() bool {
if p.SInfo.PortType&(cmn.PortReal|cmn.PortBond|cmn.PortVti|cmn.PortWg) != 0 {
return true
}
return false
}

// IsSlavePort - check if the port is slave of another port
func (p *Port) IsSlavePort() bool {
if p.SInfo.PortType&(cmn.PortVlanSif|cmn.PortBondSif) == 0 {
return false
}
return true
}
}
1 change: 1 addition & 0 deletions loxinet/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func (r *RtH) RouteGet() ([]cmn.Routev4Get, error) {
return ret, nil
}

// GetFlagToString - Stringify route flags
func GetFlagToString(flag int) string {
var ret string
if flag&RtTypeInd != 0 {
Expand Down
Loading

0 comments on commit 9cbe0ed

Please sign in to comment.