Skip to content
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
4 changes: 4 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ jobs:
steps:
- name: Check-out code
uses: actions/checkout@v4
- name: Set up Go using version from go.mod
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Run code linters
run: |
make golangci
63 changes: 41 additions & 22 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
version: "2"
run:
tests: true
timeout: 5m

linters-settings:
goimports:
local-prefixes: antrea.io/ofnet
gosec:
excludes:
# At the time of writing this, the G115 rule is not even part of an
# official release of gosec. This rule causes a lot of errors to be
# reported in the codebase. While some of the reported errors should be
# addressed, a lot can also be ignored and there are also some clear false
# positives that should not be flagged by gosec in the first place (see
# https://github.com/securego/gosec/issues/1187). We will re-enable this
# rule in the future when it becomes more accurate.
- G115 # Potential integer overflow when converting between integer types

linters:
disable-all: true
enable: # see https://golangci-lint.run/usage/linters/
- unused
- staticcheck
default: none
enable:
- gosec
- govet
- misspell
- staticcheck
- unused
settings:
gosec:
excludes:
- G115
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
rules:
- linters:
- staticcheck
# ST1005: error strings must be capitalized
# QF1008: unneccessary use of embedded struct name before field
# ST1012: error var should have name of the form ErrFoo
text: "(ST1005:|QF1008:|ST1012:)"
formatters:
enable:
- gofmt
- goimports
- gosec
- misspell
settings:
goimports:
local-prefixes:
- antrea.io/ofnet
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DOCKER_CACHE := $(CURDIR)/.cache
OVS_VERSION := $(shell head -n 1 build/images/deps/ovs-version)
GO_VERSION := $(shell head -n 1 build/images/deps/go-version)

GOLANGCI_LINT_VERSION := v1.60.3
GOLANGCI_LINT_VERSION := v2.3.1
GOLANGCI_LINT_BINDIR := .golangci-bin
GOLANGCI_LINT_BIN := $(GOLANGCI_LINT_BINDIR)/$(GOLANGCI_LINT_VERSION)/golangci-lint

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module antrea.io/ofnet

go 1.23.0
go 1.24.0

require (
antrea.io/libOpenflow v0.15.0
Expand Down
4 changes: 2 additions & 2 deletions ofctrl/fgraphEmptyElem.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ type EmptyElem struct {
}

// Fgraph element type for the NXOutput
func (self *EmptyElem) Type() string {
func (e *EmptyElem) Type() string {
return "empty"
}

// instruction set for NXOutput element
func (self *EmptyElem) GetFlowInstr() openflow15.Instruction {
func (e *EmptyElem) GetFlowInstr() openflow15.Instruction {
instr := openflow15.NewInstrApplyActions()
return instr
}
Expand Down
52 changes: 26 additions & 26 deletions ofctrl/fgraphFlood.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,76 +40,76 @@ type FloodOutput struct {
}

// Fgraph element type for the output
func (self *Flood) Type() string {
func (f *Flood) Type() string {
return "flood"
}

// instruction set for output element
func (self *Flood) GetFlowInstr() openflow15.Instruction {
func (f *Flood) GetFlowInstr() openflow15.Instruction {
// If there are no ports in the flood entry, return
if !self.isInstalled {
if !f.isInstalled {
return nil
}

groupInstr := openflow15.NewInstrApplyActions()
groupAct := openflow15.NewActionGroup(self.GroupId)
groupAct := openflow15.NewActionGroup(f.GroupId)
groupInstr.AddAction(groupAct, false)

return groupInstr
}

// Add a new Output to group element
func (self *Flood) AddOutput(out *Output) error {
self.FloodList = append(self.FloodList, FloodOutput{out, false, 0})
func (f *Flood) AddOutput(out *Output) error {
f.FloodList = append(f.FloodList, FloodOutput{out, false, 0})

// Install in the HW
return self.install()
return f.install()
}

// Add a new Output to group element
func (self *Flood) AddTunnelOutput(out *Output, tunnelId uint64) error {
self.FloodList = append(self.FloodList, FloodOutput{out, true, tunnelId})
func (f *Flood) AddTunnelOutput(out *Output, tunnelId uint64) error {
f.FloodList = append(f.FloodList, FloodOutput{out, true, tunnelId})

// Install in the HW
return self.install()
return f.install()
}

// Remove a port from flood list
func (self *Flood) RemoveOutput(out *Output) error {
func (f *Flood) RemoveOutput(out *Output) error {
// walk all flood list entries and see if it matches the output port
for idx, output := range self.FloodList {
for idx, output := range f.FloodList {
if output.outPort == out {
// Remove from the flood list. strange golang syntax to remove an element from slice
self.FloodList = append(self.FloodList[:idx], self.FloodList[idx+1:]...)
f.FloodList = append(f.FloodList[:idx], f.FloodList[idx+1:]...)

// Re-install the flood list with removed port
return self.install()
return f.install()
}
}

return errors.New("Output not found")
}

// Return number of ports in flood list
func (self *Flood) NumOutput() int {
return len(self.FloodList)
func (f *Flood) NumOutput() int {
return len(f.FloodList)
}

// Install a group entry in OF switch
func (self *Flood) install() error {
func (f *Flood) install() error {
groupMod := openflow15.NewGroupMod()
groupMod.GroupId = self.GroupId
groupMod.GroupId = f.GroupId

// Change the OP to modify if it was already installed
if self.isInstalled {
if f.isInstalled {
groupMod.Command = openflow15.OFPGC_MODIFY
}

// OF type for flood list
groupMod.Type = openflow15.GT_ALL

// Loop thru all output ports and add it to group bucket
for idx, output := range self.FloodList {
for idx, output := range f.FloodList {
// Get the output action from output entry
act := output.outPort.GetActionMessage()
if act != nil {
Expand Down Expand Up @@ -138,28 +138,28 @@ func (self *Flood) install() error {
log.Debugf("Installing Group entry: %+v", groupMod)

// Send it to the switch
if err := self.Switch.Send(groupMod); err != nil {
if err := f.Switch.Send(groupMod); err != nil {
return err
}

// Mark it as installed
self.isInstalled = true
f.isInstalled = true

return nil
}

// Delete a flood list
func (self *Flood) Delete() error {
func (f *Flood) Delete() error {
// Remove it from OVS if its installed
if self.isInstalled {
if f.isInstalled {
groupMod := openflow15.NewGroupMod()
groupMod.GroupId = self.GroupId
groupMod.GroupId = f.GroupId
groupMod.Command = openflow15.OFPGC_DELETE

log.Debugf("Deleting Group entry: %+v", groupMod)

// Send it to the switch
if err := self.Switch.Send(groupMod); err != nil {
if err := f.Switch.Send(groupMod); err != nil {
return err
}
}
Expand Down
Loading