Skip to content

Commit 3d7ebe2

Browse files
authored
Merge pull request #6 from ti-mo/bump-deps-1222
December 2022 maintenance
2 parents e8114e1 + f329510 commit 3d7ebe2

18 files changed

+162
-202
lines changed

.builds/integration-edge.yml

Lines changed: 0 additions & 42 deletions
This file was deleted.

.builds/integration-stable-1.12.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.github/workflows/lint.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Lint
2+
3+
on:
4+
pull_request: {}
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
build:
11+
strategy:
12+
matrix:
13+
go-version: [1.18, 1.19]
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Set up Go
18+
uses: actions/setup-go@v3
19+
with:
20+
go-version: ${{ matrix.go-version }}
21+
id: go
22+
23+
- name: Check out Go module
24+
uses: actions/checkout@v3
25+
26+
- name: golangci-lint
27+
uses: golangci/golangci-lint-action@v3
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Linux Integration Test
2+
3+
on:
4+
pull_request: {}
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
build:
11+
strategy:
12+
matrix:
13+
go-version: [1.18, 1.19]
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Set up Go
18+
uses: actions/setup-go@v3
19+
with:
20+
go-version: ${{ matrix.go-version }}
21+
id: go
22+
23+
- name: Check out Go module
24+
uses: actions/checkout@v3
25+
26+
- name: Run integration tests
27+
run: make integration
28+
29+
- name: goveralls
30+
uses: shogo82148/actions-goveralls@v1
31+
with:
32+
path-to-profile: cover-int.out

.github/workflows/linux-test.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Linux Test
2+
3+
on:
4+
pull_request: {}
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
build:
11+
strategy:
12+
matrix:
13+
go-version: [1.18, 1.19]
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Set up Go
18+
uses: actions/setup-go@v3
19+
with:
20+
go-version: ${{ matrix.go-version }}
21+
id: go
22+
23+
- name: Check out Go module
24+
uses: actions/checkout@v3
25+
26+
- name: Run tests
27+
run: make test

.golangci.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
linters-settings:
2+
staticcheck:
3+
go: "1.19"
4+
unused:
5+
go: "1.19"
6+
7+
linters:
8+
enable:
9+
- goerr113
10+
- gofmt
11+
- goimports
12+
- govet
13+
- ineffassign
14+
- misspell
15+
- staticcheck
16+
- unused
17+
- goheader
18+
- errcheck
19+
- gocyclo
20+
- revive
21+
- gosec
22+
- gosimple
23+
- lll
24+
- misspell
25+
- prealloc
26+
- typecheck

attribute.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ type Attribute struct {
5151

5252
func (a Attribute) String() string {
5353
if a.Nested {
54-
return fmt.Sprintf("<Length %d, Type %d, Nested %t, %d Children (%v)>", len(a.Data), a.Type, a.Nested, len(a.Children), a.Children)
54+
return fmt.Sprintf("<Length %d, Type %d, Nested %t, %d Children (%v)>",
55+
len(a.Data), a.Type, a.Nested, len(a.Children), a.Children)
5556
}
5657

57-
return fmt.Sprintf("<Length %d, Type %d, Nested %t, NetByteOrder %t, %v>", len(a.Data), a.Type, a.Nested, a.NetByteOrder, a.Data)
58-
58+
return fmt.Sprintf("<Length %d, Type %d, Nested %t, NetByteOrder %t, %v>",
59+
len(a.Data), a.Type, a.Nested, a.NetByteOrder, a.Data)
5960
}
6061

6162
// Uint16 interprets a non-nested Netfilter attribute in network byte order as a uint16.
@@ -84,7 +85,6 @@ func (a *Attribute) PutUint16(v uint16) {
8485

8586
// Uint32 interprets a non-nested Netfilter attribute in network byte order as a uint32.
8687
func (a Attribute) Uint32() uint32 {
87-
8888
if a.Nested {
8989
panic("Uint32: unexpected Nested attribute")
9090
}
@@ -98,7 +98,6 @@ func (a Attribute) Uint32() uint32 {
9898

9999
// PutUint32 sets the Attribute's data field to a Uint32 encoded in net byte order.
100100
func (a *Attribute) PutUint32(v uint32) {
101-
102101
if len(a.Data) != 4 {
103102
a.Data = make([]byte, 4)
104103
}
@@ -113,7 +112,6 @@ func (a Attribute) Int32() int32 {
113112

114113
// Uint64 interprets a non-nested Netfilter attribute in network byte order as a uint64.
115114
func (a Attribute) Uint64() uint64 {
116-
117115
if a.Nested {
118116
panic("Uint64: unexpected Nested attribute")
119117
}
@@ -127,7 +125,6 @@ func (a Attribute) Uint64() uint64 {
127125

128126
// PutUint64 sets the Attribute's data field to a Uint64 encoded in net byte order.
129127
func (a *Attribute) PutUint64(v uint64) {
130-
131128
if len(a.Data) != 8 {
132129
a.Data = make([]byte, 8)
133130
}
@@ -164,9 +161,7 @@ func Uint64Bytes(u uint64) []byte {
164161
// decode fills the Attribute's Children field with Attributes
165162
// obtained by exhausting ad.
166163
func (a *Attribute) decode(ad *netlink.AttributeDecoder) error {
167-
168164
for ad.Next() {
169-
170165
// Copy the netlink attribute's fields into the netfilter attribute.
171166
nfa := Attribute{
172167
// Only consider the rightmost 14 bits for Type.
@@ -198,11 +193,8 @@ func (a *Attribute) decode(ad *netlink.AttributeDecoder) error {
198193
// This function can be passed to AttributeEncoder.Nested for recursively
199194
// encoding Attributes.
200195
func (a *Attribute) encode(attrs []Attribute) func(*netlink.AttributeEncoder) error {
201-
202196
return func(ae *netlink.AttributeEncoder) error {
203-
204197
for _, nfa := range attrs {
205-
206198
if nfa.NetByteOrder && nfa.Nested {
207199
return errInvalidAttributeFlags
208200
}
@@ -227,7 +219,6 @@ func (a *Attribute) encode(attrs []Attribute) func(*netlink.AttributeEncoder) er
227219
// a byte array. This byte array should be taken from the netlink.Message's
228220
// Data payload after the nfHeaderLen offset.
229221
func decodeAttributes(ad *netlink.AttributeDecoder) ([]Attribute, error) {
230-
231222
// Use the Children element of the Attribute to decode into.
232223
// Attribute already has nested decoding implemented on the type.
233224
var a Attribute
@@ -247,7 +238,6 @@ func decodeAttributes(ad *netlink.AttributeDecoder) ([]Attribute, error) {
247238

248239
// encodeAttributes encodes a list of Attributes into the given netlink.AttributeEncoder.
249240
func encodeAttributes(ae *netlink.AttributeEncoder, attrs []Attribute) error {
250-
251241
if ae == nil {
252242
return errNilAttributeEncoder
253243
}
@@ -260,9 +250,7 @@ func encodeAttributes(ae *netlink.AttributeEncoder, attrs []Attribute) error {
260250
// This byte slice can then be copied into a netlink.Message's Data field after
261251
// the nfHeaderLen offset.
262252
func MarshalAttributes(attrs []Attribute) ([]byte, error) {
263-
264253
ae := NewAttributeEncoder()
265-
266254
if err := encodeAttributes(ae, attrs); err != nil {
267255
return nil, err
268256
}
@@ -277,7 +265,6 @@ func MarshalAttributes(attrs []Attribute) ([]byte, error) {
277265

278266
// UnmarshalAttributes unmarshals a byte slice into a list of Attributes.
279267
func UnmarshalAttributes(b []byte) ([]Attribute, error) {
280-
281268
ad, err := NewAttributeDecoder(b)
282269
if err != nil {
283270
return nil, err

attribute_test.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package netfilter
22

33
import (
4-
"errors"
54
"strings"
65
"testing"
76

@@ -103,10 +102,8 @@ func TestAttributeString(t *testing.T) {
103102
{
104103
name: "attribute w/ nested attribute",
105104
attr: Attribute{
106-
Nested: true,
107-
Children: []Attribute{
108-
Attribute{},
109-
},
105+
Nested: true,
106+
Children: []Attribute{{}},
110107
},
111108
txt: "<Length 0, Type 0, Nested true, 1 Children ([<Length 0, Type 0, Nested false, NetByteOrder false, []>])>",
112109
},
@@ -223,7 +220,6 @@ func TestAttributeDecoderErrors(t *testing.T) {
223220
8, 0, 0, 192, // 192 = nested + netByteOrder
224221
0, 0, 0, 0,
225222
},
226-
err: errInvalidAttributeFlags,
227223
},
228224
{
229225
name: "invalid attribute flags on nested attribute",
@@ -232,21 +228,17 @@ func TestAttributeDecoderErrors(t *testing.T) {
232228
8, 0, 0, 192, // 192 = nested + netByteOrder
233229
0, 0, 0, 0,
234230
},
235-
err: errInvalidAttributeFlags,
236231
},
237232
{
238233
name: "decoding invalid attribute",
239234
b: []byte{4, 0, 0},
240-
err: errors.New("invalid attribute; length too short or too large"),
241235
},
242236
}
243237

244238
for _, tt := range tests {
245239
t.Run(tt.name, func(t *testing.T) {
246240
_, err := UnmarshalAttributes(tt.b)
247241
require.Error(t, err)
248-
require.Error(t, tt.err)
249-
require.EqualError(t, err, tt.err.Error())
250242
})
251243
}
252244
}

0 commit comments

Comments
 (0)