Skip to content

Commit

Permalink
linter: move to staticcheck
Browse files Browse the repository at this point in the history
As golint is now deprecated, this patch proposes to
switch to staticcheck [0] as an alternative, in addition
to `go vet`.
This patch contains fixes addressing the linter's reported
issues, with two added exceptions :
- The MemoryStats deprectated fields are still for us to update
- In `gen_encoding.go` we need to add an extra comment
to account for the unused variable. This is probably worth
addressing in another patch to not generate a variable we don't use.

[0] https://staticcheck.io/

Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
Change-Id: I0562f290fb908bc610c44d675e21e466d0badc27
  • Loading branch information
sknat committed Aug 11, 2022
1 parent 0eff8d0 commit 34379e1
Show file tree
Hide file tree
Showing 42 changed files with 281 additions and 293 deletions.
8 changes: 4 additions & 4 deletions Makefile
Expand Up @@ -82,10 +82,10 @@ test-integration: ## Run integration tests
@echo "# running integration tests"
go test -tags="integration ${GO_BUILD_TAGS}" ./test/integration

.PHONY: lint
lint: ## Run code linter
@echo "# running linter"
@golint ./...
.PHONY: lint ## Run code linter
lint:
@go vet ./...
@staticcheck ./...

.PHONY: install
install: install-generator install-proxy ## Install all
Expand Down
18 changes: 11 additions & 7 deletions adapter/socketclient/socketclient.go
Expand Up @@ -108,7 +108,8 @@ func NewVppClient(socket string) *Client {
connectTimeout: DefaultConnectTimeout,
disconnectTimeout: DefaultDisconnectTimeout,
headerPool: &sync.Pool{New: func() interface{} {
return make([]byte, 16)
x := make([]byte, 16)
return &x
}},
msgCallback: func(msgID uint16, data []byte) {
log.Debugf("no callback set, dropping message: ID=%v len=%d", msgID, len(data))
Expand Down Expand Up @@ -375,12 +376,12 @@ func (c *Client) writeMsg(msg []byte) error {
c.writeMu.Lock()
defer c.writeMu.Unlock()

header := c.headerPool.Get().([]byte)
err := writeMsgHeader(c.writer, header, len(msg))
header := c.headerPool.Get().(*[]byte)
err := writeMsgHeader(c.writer, *header, len(msg))
if err != nil {
return err
}
c.headerPool.Put(header)
c.headerPool.Put(&header)

if err := writeMsgData(c.writer, msg, c.writer.Size()); err != nil {
return err
Expand Down Expand Up @@ -499,14 +500,17 @@ func (c *Client) readMsgTimeout(buf []byte, timeout time.Duration) ([]byte, erro
func (c *Client) readMsg(buf []byte) ([]byte, error) {
log.Debug("reading msg..")

header := c.headerPool.Get().([]byte)
msgLen, err := readMsgHeader(c.reader, header)
header := c.headerPool.Get().(*[]byte)
msgLen, err := readMsgHeader(c.reader, *header)
if err != nil {
return nil, err
}
c.headerPool.Put(header)
c.headerPool.Put(&header)

msg, err := readMsgData(c.reader, buf, msgLen)
if err != nil {
return nil, err
}

log.Debugf(" -- readMsg done (buffered: %d)", c.reader.Buffered())

Expand Down
2 changes: 1 addition & 1 deletion adapter/statsclient/statsclient.go
Expand Up @@ -607,7 +607,7 @@ func (sc *StatsClient) updateStatOnIndex(entry *adapter.StatEntry, vector dirVec
return nil
}
if err := sc.UpdateEntryData(dirPtr, &entry.Data); err != nil {
err = fmt.Errorf("updating stat data for entry %s failed: %v", dirName, err)
return fmt.Errorf("updating stat data for entry %s failed: %v", dirName, err)
}
return
}
5 changes: 0 additions & 5 deletions adapter/statsclient/statseg_v1.go
Expand Up @@ -15,7 +15,6 @@
package statsclient

import (
"fmt"
"sync/atomic"
"unsafe"

Expand Down Expand Up @@ -71,10 +70,6 @@ func (ss *statSegmentV1) GetDirectoryVector() dirVector {
return dirVector(&ss.sharedHeader[dirOffset])
}

func (ss *statSegmentV1) getErrorVector() (unsafe.Pointer, error) {
return nil, fmt.Errorf("error vector is not defined for stats API v1")
}

func (ss *statSegmentV1) GetStatDirOnIndex(v dirVector, index uint32) (dirSegment, dirName, adapter.StatType) {
statSegDir := dirSegment(uintptr(v) + uintptr(index)*unsafe.Sizeof(statSegDirectoryEntryV1{}))
dir := (*statSegDirectoryEntryV1)(statSegDir)
Expand Down
254 changes: 127 additions & 127 deletions api/errors.go
Expand Up @@ -42,133 +42,133 @@ func (e VPPApiError) Error() string {

// definitions from: vpp/src/vnet/api_errno.h
const (
_ VPPApiError = 0
UNSPECIFIED = -1
INVALID_SW_IF_INDEX = -2
NO_SUCH_FIB = -3
NO_SUCH_INNER_FIB = -4
NO_SUCH_LABEL = -5
NO_SUCH_ENTRY = -6
INVALID_VALUE = -7
INVALID_VALUE_2 = -8
UNIMPLEMENTED = -9
INVALID_SW_IF_INDEX_2 = -10
SYSCALL_ERROR_1 = -11
SYSCALL_ERROR_2 = -12
SYSCALL_ERROR_3 = -13
SYSCALL_ERROR_4 = -14
SYSCALL_ERROR_5 = -15
SYSCALL_ERROR_6 = -16
SYSCALL_ERROR_7 = -17
SYSCALL_ERROR_8 = -18
SYSCALL_ERROR_9 = -19
SYSCALL_ERROR_10 = -20
FEATURE_DISABLED = -30
INVALID_REGISTRATION = -31
NEXT_HOP_NOT_IN_FIB = -50
UNKNOWN_DESTINATION = -51
PREFIX_MATCHES_NEXT_HOP = -52
NEXT_HOP_NOT_FOUND_MP = -53
NO_MATCHING_INTERFACE = -54
INVALID_VLAN = -55
VLAN_ALREADY_EXISTS = -56
INVALID_SRC_ADDRESS = -57
INVALID_DST_ADDRESS = -58
ADDRESS_LENGTH_MISMATCH = -59
ADDRESS_NOT_FOUND_FOR_INTERFACE = -60
ADDRESS_NOT_DELETABLE = -61
IP6_NOT_ENABLED = -62
IN_PROGRESS = 10
NO_SUCH_NODE = -63
NO_SUCH_NODE2 = -64
NO_SUCH_TABLE = -65
NO_SUCH_TABLE2 = -66
NO_SUCH_TABLE3 = -67
SUBIF_ALREADY_EXISTS = -68
SUBIF_CREATE_FAILED = -69
INVALID_MEMORY_SIZE = -70
INVALID_INTERFACE = -71
INVALID_VLAN_TAG_COUNT = -72
INVALID_ARGUMENT = -73
UNEXPECTED_INTF_STATE = -74
TUNNEL_EXIST = -75
INVALID_DECAP_NEXT = -76
RESPONSE_NOT_READY = -77
NOT_CONNECTED = -78
IF_ALREADY_EXISTS = -79
BOND_SLAVE_NOT_ALLOWED = -80
VALUE_EXIST = -81
SAME_SRC_DST = -82
IP6_MULTICAST_ADDRESS_NOT_PRESENT = -83
SR_POLICY_NAME_NOT_PRESENT = -84
NOT_RUNNING_AS_ROOT = -85
ALREADY_CONNECTED = -86
UNSUPPORTED_JNI_VERSION = -87
FAILED_TO_ATTACH_TO_JAVA_THREAD = -88
INVALID_WORKER = -89
LISP_DISABLED = -90
CLASSIFY_TABLE_NOT_FOUND = -91
INVALID_EID_TYPE = -92
CANNOT_CREATE_PCAP_FILE = -93
INCORRECT_ADJACENCY_TYPE = -94
EXCEEDED_NUMBER_OF_RANGES_CAPACITY = -95
EXCEEDED_NUMBER_OF_PORTS_CAPACITY = -96
INVALID_ADDRESS_FAMILY = -97
INVALID_SUB_SW_IF_INDEX = -98
TABLE_TOO_BIG = -99
CANNOT_ENABLE_DISABLE_FEATURE = -100
BFD_EEXIST = -101
BFD_ENOENT = -102
BFD_EINUSE = -103
BFD_NOTSUPP = -104
ADDRESS_IN_USE = -105
ADDRESS_NOT_IN_USE = -106
QUEUE_FULL = -107
APP_UNSUPPORTED_CFG = -108
URI_FIFO_CREATE_FAILED = -109
LISP_RLOC_LOCAL = -110
BFD_EAGAIN = -111
INVALID_GPE_MODE = -112
LISP_GPE_ENTRIES_PRESENT = -113
ADDRESS_FOUND_FOR_INTERFACE = -114
SESSION_CONNECT = -115
ENTRY_ALREADY_EXISTS = -116
SVM_SEGMENT_CREATE_FAIL = -117
APPLICATION_NOT_ATTACHED = -118
BD_ALREADY_EXISTS = -119
BD_IN_USE = -120
BD_NOT_MODIFIABLE = -121
BD_ID_EXCEED_MAX = -122
SUBIF_DOESNT_EXIST = -123
L2_MACS_EVENT_CLINET_PRESENT = -124
INVALID_QUEUE = -125
UNSUPPORTED = -126
DUPLICATE_IF_ADDRESS = -127
APP_INVALID_NS = -128
APP_WRONG_NS_SECRET = -129
APP_CONNECT_SCOPE = -130
APP_ALREADY_ATTACHED = -131
SESSION_REDIRECT = -132
ILLEGAL_NAME = -133
NO_NAME_SERVERS = -134
NAME_SERVER_NOT_FOUND = -135
NAME_RESOLUTION_NOT_ENABLED = -136
NAME_SERVER_FORMAT_ERROR = -137
NAME_SERVER_NO_SUCH_NAME = -138
NAME_SERVER_NO_ADDRESSES = -139
NAME_SERVER_NEXT_SERVER = -140
APP_CONNECT_FILTERED = -141
ACL_IN_USE_INBOUND = -142
ACL_IN_USE_OUTBOUND = -143
INIT_FAILED = -144
NETLINK_ERROR = -145
BIER_BSL_UNSUP = -146
INSTANCE_IN_USE = -147
INVALID_SESSION_ID = -148
ACL_IN_USE_BY_LOOKUP_CONTEXT = -149
INVALID_VALUE_3 = -150
NON_ETHERNET = -151
BD_ALREADY_HAS_BVI = -152
_ VPPApiError = 0
UNSPECIFIED VPPApiError = -1
INVALID_SW_IF_INDEX VPPApiError = -2
NO_SUCH_FIB VPPApiError = -3
NO_SUCH_INNER_FIB VPPApiError = -4
NO_SUCH_LABEL VPPApiError = -5
NO_SUCH_ENTRY VPPApiError = -6
INVALID_VALUE VPPApiError = -7
INVALID_VALUE_2 VPPApiError = -8
UNIMPLEMENTED VPPApiError = -9
INVALID_SW_IF_INDEX_2 VPPApiError = -10
SYSCALL_ERROR_1 VPPApiError = -11
SYSCALL_ERROR_2 VPPApiError = -12
SYSCALL_ERROR_3 VPPApiError = -13
SYSCALL_ERROR_4 VPPApiError = -14
SYSCALL_ERROR_5 VPPApiError = -15
SYSCALL_ERROR_6 VPPApiError = -16
SYSCALL_ERROR_7 VPPApiError = -17
SYSCALL_ERROR_8 VPPApiError = -18
SYSCALL_ERROR_9 VPPApiError = -19
SYSCALL_ERROR_10 VPPApiError = -20
FEATURE_DISABLED VPPApiError = -30
INVALID_REGISTRATION VPPApiError = -31
NEXT_HOP_NOT_IN_FIB VPPApiError = -50
UNKNOWN_DESTINATION VPPApiError = -51
PREFIX_MATCHES_NEXT_HOP VPPApiError = -52
NEXT_HOP_NOT_FOUND_MP VPPApiError = -53
NO_MATCHING_INTERFACE VPPApiError = -54
INVALID_VLAN VPPApiError = -55
VLAN_ALREADY_EXISTS VPPApiError = -56
INVALID_SRC_ADDRESS VPPApiError = -57
INVALID_DST_ADDRESS VPPApiError = -58
ADDRESS_LENGTH_MISMATCH VPPApiError = -59
ADDRESS_NOT_FOUND_FOR_INTERFACE VPPApiError = -60
ADDRESS_NOT_DELETABLE VPPApiError = -61
IP6_NOT_ENABLED VPPApiError = -62
IN_PROGRESS VPPApiError = 10
NO_SUCH_NODE VPPApiError = -63
NO_SUCH_NODE2 VPPApiError = -64
NO_SUCH_TABLE VPPApiError = -65
NO_SUCH_TABLE2 VPPApiError = -66
NO_SUCH_TABLE3 VPPApiError = -67
SUBIF_ALREADY_EXISTS VPPApiError = -68
SUBIF_CREATE_FAILED VPPApiError = -69
INVALID_MEMORY_SIZE VPPApiError = -70
INVALID_INTERFACE VPPApiError = -71
INVALID_VLAN_TAG_COUNT VPPApiError = -72
INVALID_ARGUMENT VPPApiError = -73
UNEXPECTED_INTF_STATE VPPApiError = -74
TUNNEL_EXIST VPPApiError = -75
INVALID_DECAP_NEXT VPPApiError = -76
RESPONSE_NOT_READY VPPApiError = -77
NOT_CONNECTED VPPApiError = -78
IF_ALREADY_EXISTS VPPApiError = -79
BOND_SLAVE_NOT_ALLOWED VPPApiError = -80
VALUE_EXIST VPPApiError = -81
SAME_SRC_DST VPPApiError = -82
IP6_MULTICAST_ADDRESS_NOT_PRESENT VPPApiError = -83
SR_POLICY_NAME_NOT_PRESENT VPPApiError = -84
NOT_RUNNING_AS_ROOT VPPApiError = -85
ALREADY_CONNECTED VPPApiError = -86
UNSUPPORTED_JNI_VERSION VPPApiError = -87
FAILED_TO_ATTACH_TO_JAVA_THREAD VPPApiError = -88
INVALID_WORKER VPPApiError = -89
LISP_DISABLED VPPApiError = -90
CLASSIFY_TABLE_NOT_FOUND VPPApiError = -91
INVALID_EID_TYPE VPPApiError = -92
CANNOT_CREATE_PCAP_FILE VPPApiError = -93
INCORRECT_ADJACENCY_TYPE VPPApiError = -94
EXCEEDED_NUMBER_OF_RANGES_CAPACITY VPPApiError = -95
EXCEEDED_NUMBER_OF_PORTS_CAPACITY VPPApiError = -96
INVALID_ADDRESS_FAMILY VPPApiError = -97
INVALID_SUB_SW_IF_INDEX VPPApiError = -98
TABLE_TOO_BIG VPPApiError = -99
CANNOT_ENABLE_DISABLE_FEATURE VPPApiError = -100
BFD_EEXIST VPPApiError = -101
BFD_ENOENT VPPApiError = -102
BFD_EINUSE VPPApiError = -103
BFD_NOTSUPP VPPApiError = -104
ADDRESS_IN_USE VPPApiError = -105
ADDRESS_NOT_IN_USE VPPApiError = -106
QUEUE_FULL VPPApiError = -107
APP_UNSUPPORTED_CFG VPPApiError = -108
URI_FIFO_CREATE_FAILED VPPApiError = -109
LISP_RLOC_LOCAL VPPApiError = -110
BFD_EAGAIN VPPApiError = -111
INVALID_GPE_MODE VPPApiError = -112
LISP_GPE_ENTRIES_PRESENT VPPApiError = -113
ADDRESS_FOUND_FOR_INTERFACE VPPApiError = -114
SESSION_CONNECT VPPApiError = -115
ENTRY_ALREADY_EXISTS VPPApiError = -116
SVM_SEGMENT_CREATE_FAIL VPPApiError = -117
APPLICATION_NOT_ATTACHED VPPApiError = -118
BD_ALREADY_EXISTS VPPApiError = -119
BD_IN_USE VPPApiError = -120
BD_NOT_MODIFIABLE VPPApiError = -121
BD_ID_EXCEED_MAX VPPApiError = -122
SUBIF_DOESNT_EXIST VPPApiError = -123
L2_MACS_EVENT_CLINET_PRESENT VPPApiError = -124
INVALID_QUEUE VPPApiError = -125
UNSUPPORTED VPPApiError = -126
DUPLICATE_IF_ADDRESS VPPApiError = -127
APP_INVALID_NS VPPApiError = -128
APP_WRONG_NS_SECRET VPPApiError = -129
APP_CONNECT_SCOPE VPPApiError = -130
APP_ALREADY_ATTACHED VPPApiError = -131
SESSION_REDIRECT VPPApiError = -132
ILLEGAL_NAME VPPApiError = -133
NO_NAME_SERVERS VPPApiError = -134
NAME_SERVER_NOT_FOUND VPPApiError = -135
NAME_RESOLUTION_NOT_ENABLED VPPApiError = -136
NAME_SERVER_FORMAT_ERROR VPPApiError = -137
NAME_SERVER_NO_SUCH_NAME VPPApiError = -138
NAME_SERVER_NO_ADDRESSES VPPApiError = -139
NAME_SERVER_NEXT_SERVER VPPApiError = -140
APP_CONNECT_FILTERED VPPApiError = -141
ACL_IN_USE_INBOUND VPPApiError = -142
ACL_IN_USE_OUTBOUND VPPApiError = -143
INIT_FAILED VPPApiError = -144
NETLINK_ERROR VPPApiError = -145
BIER_BSL_UNSUP VPPApiError = -146
INSTANCE_IN_USE VPPApiError = -147
INVALID_SESSION_ID VPPApiError = -148
ACL_IN_USE_BY_LOOKUP_CONTEXT VPPApiError = -149
INVALID_VALUE_3 VPPApiError = -150
NON_ETHERNET VPPApiError = -151
BD_ALREADY_HAS_BVI VPPApiError = -152
)

var vppApiErrors = map[VPPApiError]string{
Expand Down
2 changes: 2 additions & 0 deletions binapi/abf/abf.ba.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 34379e1

Please sign in to comment.