diff --git a/actions/duplicate_action.go b/actions/duplicate_action.go index 7512144..84ed13d 100644 --- a/actions/duplicate_action.go +++ b/actions/duplicate_action.go @@ -1,3 +1,4 @@ +//nolint:depguard package actions import ( @@ -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), ) } @@ -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), ) } diff --git a/actions/fragment_packet.go b/actions/fragment_packet.go index 0124cec..195ac1d 100644 --- a/actions/fragment_packet.go +++ b/actions/fragment_packet.go @@ -1,3 +1,4 @@ +//nolint:depguard package actions import ( @@ -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) } @@ -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) } @@ -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), ) } diff --git a/actions/tamper_action.go b/actions/tamper_action.go index bfff1af..8c8f9a2 100644 --- a/actions/tamper_action.go +++ b/actions/tamper_action.go @@ -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 ( @@ -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 } } @@ -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) @@ -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 } @@ -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) } } @@ -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 } diff --git a/actions/tamper_action_test.go b/actions/tamper_action_test.go index fabbb41..5254154 100644 --- a/actions/tamper_action_test.go +++ b/actions/tamper_action_test.go @@ -95,6 +95,7 @@ func TestTamperTCP(t *testing.T) { valueGen tamperValueGen } + //nolint:forcetypeassert tests := []struct { name string args args