Skip to content

Commit

Permalink
Bump up golangci-bin version (antrea-io#33)
Browse files Browse the repository at this point in the history
1. Bump up golangci-bin version to v1.50.0
2. Removed invalid configurations in golangci.yml
3. Formated several files
4. Removed unused code which is for padding messages

Signed-off-by: wenyingd <[email protected]>
  • Loading branch information
wenyingd authored Dec 2, 2022
1 parent 2ade3b2 commit 22a944c
Show file tree
Hide file tree
Showing 21 changed files with 363 additions and 322 deletions.
5 changes: 1 addition & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ linters-settings:
linters:
disable-all: true
enable: # see https://golangci-lint.run/usage/linters/
- deadcode
- unused
- staticcheck
- govet
- gofmt
- goimports
- gosec
- misspell

run:
deadline: 5m
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test:
# code linting
.golangci-bin:
@echo "===> Installing Golangci-lint <==="
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $@ v1.41.1
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $@ v1.50.0

.PHONY: golangci
golangci: .golangci-bin
Expand Down
55 changes: 50 additions & 5 deletions openflow13/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,31 @@ func (a *ActionGroup) UnmarshalBinary(data []byte) error {
type ActionMplsTtl struct {
ActionHeader
MplsTtl uint8
pad []byte // 3bytes
}

func (a *ActionMplsTtl) Len() uint16 {
return a.ActionHeader.Len() + 4
}

func (a *ActionMplsTtl) MarshalBinary() (data []byte, err error) {
data, err = a.ActionHeader.MarshalBinary()
if err != nil {
return
}
n := int(a.ActionHeader.Len())
data[n] = a.MplsTtl
return
}

func (a *ActionMplsTtl) UnmarshalBinary(data []byte) error {
n := 0
err := a.ActionHeader.UnmarshalBinary(data[n:])
if err != nil {
return err
}
n += int(a.ActionHeader.Len())
a.MplsTtl = data[n]
return nil
}

type ActionDecNwTtl struct {
Expand Down Expand Up @@ -315,13 +339,36 @@ func (a *ActionDecNwTtl) UnmarshalBinary(data []byte) error {
type ActionNwTtl struct {
ActionHeader
NwTtl uint8
pad []byte // 3bytes
}

func (a *ActionNwTtl) Len() uint16 {
return a.ActionHeader.Len() + 4
}

func (a *ActionNwTtl) MarshalBinary() (data []byte, err error) {
data, err = a.ActionHeader.MarshalBinary()
if err != nil {
return
}
n := int(a.ActionHeader.Len())
data[n] = a.NwTtl
return
}

func (a *ActionNwTtl) UnmarshalBinary(data []byte) error {
n := 0
err := a.ActionHeader.UnmarshalBinary(data[n:])
if err != nil {
return err
}
n += int(a.ActionHeader.Len())
a.NwTtl = data[n]
return nil
}

type ActionPush struct {
ActionHeader
EtherType uint16
pad []byte // 2bytes
}

func NewActionPushVlan(etherType uint16) *ActionPush {
Expand Down Expand Up @@ -362,7 +409,6 @@ func (a *ActionPush) UnmarshalBinary(data []byte) error {

type ActionPopVlan struct {
ActionHeader
pad []byte // 4bytes
}

func NewActionPopVlan() *ActionPopVlan {
Expand Down Expand Up @@ -395,7 +441,6 @@ func (a *ActionPopVlan) UnmarshalBinary(data []byte) error {
type ActionPopMpls struct {
ActionHeader
EtherType uint16
pad []byte // 2bytes
}

func NewActionPopMpls(etherType uint16) *ActionPopMpls {
Expand Down
4 changes: 2 additions & 2 deletions openflow13/bundles.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ func NewBundlePropertyExperimenter() *BundlePropertyExperimenter {
// it, if the added messages are not wanted to realize on the switch.
type BundleAdd struct {
BundleID uint32
pad [2]byte
Flags uint16
Message util.Message
Properties []BundlePropertyExperimenter
}

func (b *BundleAdd) Len() (n uint16) {
length := uint16(unsafe.Sizeof(b.BundleID) + unsafe.Sizeof(b.Flags))
length += uint16(len(b.pad))
// 2 bytes for padding
length += 2
length += b.Message.Len()
if b.Properties != nil {
for _, p := range b.Properties {
Expand Down
2 changes: 0 additions & 2 deletions openflow13/flowmod.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ type FlowMod struct {
OutGroup uint32
Flags uint16

pad []byte // 2bytes

Match Match // Fields to match
Instructions []Instruction // Instruction set - 0 or more.
}
Expand Down
4 changes: 2 additions & 2 deletions openflow13/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (m *MatchField) MarshalBinary() (data []byte, err error) {
if m.HasMask {
fld = (m.Field << 1) | 0x1
} else {
fld = (m.Field << 1) | 0x0
fld = m.Field << 1
}
data[n] = fld
n += 1
Expand Down Expand Up @@ -477,7 +477,7 @@ func DecodeMatchField(class uint16, field uint8, length uint8, hasMask bool, dat
return nil, nil
}

// ofp_match_type 1.3
// ofp_match_type 1.3
const (
MatchType_Standard = iota /* Deprecated. */
MatchType_OXM
Expand Down
2 changes: 0 additions & 2 deletions openflow13/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ func (m *MeterBandHeader) UnmarshalBinary(data []byte) error {

type MeterBandDrop struct {
MeterBandHeader /* Type: OFPMBT13_DROP. */
pad [4]uint8
}

func (m *MeterBandDrop) Len() (n uint16) {
Expand Down Expand Up @@ -111,7 +110,6 @@ func (m *MeterBandDrop) UnmarshalBinary(data []byte) error {
type MeterBandDSCP struct {
MeterBandHeader /* Type: OFPMBT13_DSCP_REMARK. */
PrecLevel uint8 /* Number of drop precedence level to add. */
pad [3]uint8
}

func (m *MeterBandDSCP) Len() (n uint16) {
Expand Down
4 changes: 1 addition & 3 deletions openflow13/multipart.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type MultipartRequest struct {
common.Header
Type uint16
Flags uint16
pad []byte // 4 bytes
Body []util.Message
}

Expand Down Expand Up @@ -103,7 +102,6 @@ type MultipartReply struct {
common.Header
Type uint16
Flags uint16
pad []byte // 4 bytes
Body []util.Message
}

Expand Down Expand Up @@ -1324,7 +1322,6 @@ type OFPTableFeatures struct {
Length uint16
TableID uint8
Command uint8
pad [4]uint8
Name [32]byte
MetadataMatch uint64
MetadataWrite uint64
Expand All @@ -1350,6 +1347,7 @@ func (f *OFPTableFeatures) MarshalBinary() (data []byte, err error) {
n += 1
data[n] = f.Command
n += 1
// 4 bytes for padding
n += 4
copy(data[n:], f.Name[:32])
n += 32
Expand Down
15 changes: 4 additions & 11 deletions openflow13/nx_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -1218,11 +1218,9 @@ type NXActionLearn struct {
Cookie uint64
Flags uint16
TableID uint8
pad uint8
FinIdleTimeout uint16
FinHardTimeout uint16
LearnSpecs []*NXLearnSpec
pad2 []byte
}

func (a *NXActionLearn) Len() uint16 {
Expand Down Expand Up @@ -1252,7 +1250,9 @@ func (a *NXActionLearn) MarshalBinary() (data []byte, err error) {
binary.BigEndian.PutUint16(data[n:], a.Flags)
n += 2
data[n] = a.TableID
n += 2
n += 1
// 1 byte for padding
n += 1
binary.BigEndian.PutUint16(data[n:], a.FinIdleTimeout)
n += 2
binary.BigEndian.PutUint16(data[n:], a.FinHardTimeout)
Expand Down Expand Up @@ -1364,7 +1364,6 @@ func NewNXActionNote() *NXActionNote {
type NXActionRegLoad2 struct {
*NXActionHeader
DstField *MatchField
pad []byte
}

func NewNXActionRegLoad2(dstField *MatchField) *NXActionRegLoad2 {
Expand Down Expand Up @@ -1417,7 +1416,6 @@ type NXActionController struct {
MaxLen uint16
ControllerID uint16
Reason uint8
pad uint8
}

func (a *NXActionController) Len() uint16 {
Expand Down Expand Up @@ -1487,7 +1485,6 @@ const (
type NXActionController2PropMaxLen struct {
*PropHeader /* Type: NXAC2PT_MAX_LEN */
MaxLen uint16
pad [2]uint8
}

func (a *NXActionController2PropMaxLen) Len() uint16 {
Expand Down Expand Up @@ -1539,7 +1536,6 @@ func NewMaxLen(maxLen uint16) *NXActionController2PropMaxLen {
type NXActionController2PropControllerID struct {
*PropHeader /* Type: NXAC2PT_CONTROLLER_ID */
ControllerID uint16
pad [2]uint8
}

func (a *NXActionController2PropControllerID) Len() uint16 {
Expand Down Expand Up @@ -1591,7 +1587,6 @@ func NewControllerID(controllerID uint16) *NXActionController2PropControllerID {
type NXActionController2PropReason struct {
*PropHeader /* Type: NXAC2PT_REASON */
Reason uint8
pad [3]uint8
}

func (a *NXActionController2PropReason) Len() uint16 {
Expand Down Expand Up @@ -1643,7 +1638,6 @@ func NewReason(reason uint8) *NXActionController2PropReason {
type NXActionController2PropUserdata struct {
*PropHeader /* Type: NXAC2PT_USERDATA */
Userdata []byte
pad []uint8
}

func (a *NXActionController2PropUserdata) Len() uint16 {
Expand Down Expand Up @@ -1695,7 +1689,6 @@ func NewUserdata(userdata []byte) *NXActionController2PropUserdata {

type NXActionController2PropPause struct {
*PropHeader /* Type: NXAC2PT_PAUSE */
pad [4]uint8
}

func (a *NXActionController2PropPause) Len() uint16 {
Expand Down Expand Up @@ -1818,7 +1811,6 @@ func DecodeController2Prop(data []byte) (Property, error) {
// NXActionController2 is NX action to output packet to the Controller set with a specified ID.
type NXActionController2 struct {
*NXActionHeader
pad [6]uint8

props []Property
}
Expand All @@ -1843,6 +1835,7 @@ func (a *NXActionController2) MarshalBinary() (data []byte, err error) {
}
copy(data[n:], b)
n += int(a.NXActionHeader.Len())
// 6 bytes for padding
n += 6

for _, prop := range a.props {
Expand Down
Loading

0 comments on commit 22a944c

Please sign in to comment.