Skip to content

Commit

Permalink
more linting.. fix one and 5 more pop up..
Browse files Browse the repository at this point in the history
  • Loading branch information
garmr-ulfr committed Oct 14, 2023
1 parent 0e4adba commit eab146a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
9 changes: 5 additions & 4 deletions actions/duplicate_action.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:depguard
package actions

import (
Expand Down Expand Up @@ -123,14 +124,14 @@ func ParseDuplicateAction(s *scanner.Scanner) (Action, error) {
action.Left = &SendAction{}
} else {
return nil, fmt.Errorf(
"error parsing first action of duplicate rule: %v",
"error parsing first action of duplicate rule: %w",
err)
}
}

if _, err = s.Expect(","); err != nil {
return nil, fmt.Errorf(
"unexpected token in duplicate rule: %v",
"unexpected token in duplicate rule: %w",
internal.EOFUnexpected(err),
)
}
Expand All @@ -140,14 +141,14 @@ func ParseDuplicateAction(s *scanner.Scanner) (Action, error) {
action.Right = &SendAction{}
} else {
return nil, fmt.Errorf(
"error parsing second action of duplicate rule: %v",
"error parsing second action of duplicate rule: %w",
err)
}
}

if _, err = s.Expect(")"); err != nil {
return nil, fmt.Errorf(
"unexpected token in duplicate rule: %v",
"unexpected token in duplicate rule: %w",
internal.EOFUnexpected(err),
)
}
Expand Down
9 changes: 5 additions & 4 deletions actions/fragment_packet.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:depguard
package actions

import (
Expand Down Expand Up @@ -232,7 +233,7 @@ func FragmentIPPacket(packet gopacket.Packet, fragSize int) ([]gopacket.Packet,
buf = buf[:uint16(ofs)+hdrLen+offset]

first := gopacket.NewPacket(buf, packet.Layers()[0].LayerType(), gopacket.NoCopy)
if ipv4 := first.Layer(layers.LayerTypeIPv4).(*layers.IPv4); ipv4 != nil {
if ipv4, ok := first.Layer(layers.LayerTypeIPv4).(*layers.IPv4); ok && ipv4 != nil {
common.UpdateIPv4Checksum(ipv4)
}

Expand All @@ -253,7 +254,7 @@ func FragmentIPPacket(packet gopacket.Packet, fragSize int) ([]gopacket.Packet,
binary.BigEndian.PutUint16(ipv4Buf[6:], flagsAndFrags)

second := gopacket.NewPacket(buf, packet.Layers()[0].LayerType(), gopacket.NoCopy)
if ipv4 := second.Layer(layers.LayerTypeIPv4).(*layers.IPv4); ipv4 != nil {
if ipv4, _ := second.Layer(layers.LayerTypeIPv4).(*layers.IPv4); ipv4 != nil {
common.UpdateIPv4Checksum(ipv4)
}

Expand Down Expand Up @@ -397,13 +398,13 @@ func ParseFragmentAction(s *scanner.Scanner) (Action, error) {
if c, err2 := s.Peek(); err2 == nil && c == ')' {
action.SecondFragmentAction = &SendAction{}
} else {
return nil, fmt.Errorf("error parsing second action of fragment rule: %v", err)
return nil, fmt.Errorf("error parsing second action of fragment rule: %w", err)
}
}

if _, err := s.Expect(")"); err != nil {
return nil, fmt.Errorf(
"unexpected token in fragment rule: %v",
"unexpected token in fragment rule: %w",
internal.EOFUnexpected(err),
)
}
Expand Down
16 changes: 8 additions & 8 deletions actions/tamper_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,19 @@ func (a *TamperAction) String() string {
// If the string is malformed, an error will be returned instead.
func ParseTamperAction(s *scanner.Scanner) (Action, error) {
if _, err := s.Expect("tamper{"); err != nil {
return nil, fmt.Errorf("%s: %w", ErrInvalidTamperRule, err)
return nil, fmt.Errorf("%s: %w", ErrInvalidTamperRule, err) //nolint:errorlint
}

str, err := s.Until('}')
if err != nil {
return nil, fmt.Errorf("%s: %w", ErrInvalidTamperRule, err)
return nil, fmt.Errorf("%s: %w", ErrInvalidTamperRule, err) //nolint:errorlint
}

_, _ = s.Pop()

fields := strings.Split(str, ":")
if len(fields) < 3 || len(fields) > 4 {
return nil, fmt.Errorf("%s: invalid field, %w", ErrInvalidTamperRule, err)
return nil, fmt.Errorf("%s: invalid field, %w", ErrInvalidTamperRule, err) //nolint:errorlint
}

var (
Expand Down Expand Up @@ -147,7 +147,7 @@ func ParseTamperAction(s *scanner.Scanner) (Action, error) {
if c, err2 := s.Peek(); err2 == nil && c == ')' {
tamperAction.Action = &SendAction{}
} else {
return nil, fmt.Errorf("%s: invalid action, %w", ErrInvalidTamperRule, err)
return nil, fmt.Errorf("%s: invalid action, %w", ErrInvalidTamperRule, err) //nolint:errorlint
}
}

Expand All @@ -158,7 +158,7 @@ func ParseTamperAction(s *scanner.Scanner) (Action, error) {
}

if _, err = s.Expect(")"); err != nil {
return nil, fmt.Errorf("%s: unexpected token: %w", ErrInvalidTamperRule, err)
return nil, fmt.Errorf("%s: unexpected token: %w", ErrInvalidTamperRule, err) //nolint:errorlint
}

return newTamperAction(tamperAction)
Expand Down Expand Up @@ -340,7 +340,7 @@ func NewTCPTamperAction(ta TamperAction) (*TCPTamperAction, error) {

// Apply applies the tamper action to the given packet.
func (a *TCPTamperAction) Apply(packet gopacket.Packet) ([]gopacket.Packet, error) {
tcp := packet.Layer(layers.LayerTypeTCP).(*layers.TCP)
tcp, _ := packet.Layer(layers.LayerTypeTCP).(*layers.TCP)
if tcp == nil {
return nil, errors.New("packet does not have a TCP layer") //nolint:goerr113
}
Expand All @@ -351,7 +351,7 @@ func (a *TCPTamperAction) Apply(packet gopacket.Packet) ([]gopacket.Packet, erro
if strings.HasPrefix(a.Field, "options") {
updateTCPDataOffAndChksum(tcp)

if ip := packet.Layer(layers.LayerTypeIPv4).(*layers.IPv4); ip != nil {
if ip, _ := packet.Layer(layers.LayerTypeIPv4).(*layers.IPv4); ip != nil {
updateIPv4LengthAndChksum(ip)
}
}
Expand Down Expand Up @@ -587,7 +587,7 @@ func NewIPv4TamperAction(ta TamperAction) (*IPv4TamperAction, error) {

// Apply applies the tamper action to the given packet.
func (a *IPv4TamperAction) Apply(packet gopacket.Packet) ([]gopacket.Packet, error) {
ip := packet.Layer(layers.LayerTypeIPv4).(*layers.IPv4)
ip, _ := packet.Layer(layers.LayerTypeIPv4).(*layers.IPv4)
if ip == nil {
return nil, errors.New("packet does not have a IPv4 layer") //nolint:goerr113
}
Expand Down
1 change: 1 addition & 0 deletions actions/tamper_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func TestTamperTCP(t *testing.T) {
valueGen tamperValueGen
}

//nolint:forcetypeassert
tests := []struct {
name string
args args
Expand Down

0 comments on commit eab146a

Please sign in to comment.