From 4cb3c99e35e2e77d59e929d871ae98d603eda880 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Mon, 21 Feb 2022 14:12:30 +1030 Subject: [PATCH] {,x-pack/}packetbeat: remove dead code and unused fields, vars, consts and comments This removes the majority of unused code identified by running: staticcheck -checks 'U*' ./{,x-pack/}packetbeat/... Care has been taken to not remove platform-specific code and mage-required code. --- packetbeat/flows/flowid_test.go | 8 --- packetbeat/npcap/npcap.go | 14 +---- packetbeat/npcap/npcap_other.go | 2 - packetbeat/npcap/npcap_windows.go | 2 - .../cassandra/internal/gocql/marshal.go | 63 ------------------- packetbeat/protos/memcache/errors.go | 13 ++-- packetbeat/scripts/mage/config.go | 5 -- 7 files changed, 5 insertions(+), 102 deletions(-) diff --git a/packetbeat/flows/flowid_test.go b/packetbeat/flows/flowid_test.go index 78c8919b3d8..f15ec4403f7 100644 --- a/packetbeat/flows/flowid_test.go +++ b/packetbeat/flows/flowid_test.go @@ -54,14 +54,6 @@ func addVLan(u []byte) applyAddr { } } -func addUDP(a, b []byte) applyAddr { - src := binary.LittleEndian.Uint16(a) - dst := binary.LittleEndian.Uint16(b) - return func(f *FlowID) { - f.AddUDP(src, dst) - } -} - func addTCP(a, b []byte) applyAddr { src := binary.LittleEndian.Uint16(a) dst := binary.LittleEndian.Uint16(b) diff --git a/packetbeat/npcap/npcap.go b/packetbeat/npcap/npcap.go index c81d1ce731d..1e35246b0a2 100644 --- a/packetbeat/npcap/npcap.go +++ b/packetbeat/npcap/npcap.go @@ -15,19 +15,7 @@ // specific language governing permissions and limitations // under the License. -// Package npcap handles fetching and installing Npcap fow Windows. -// -// The npcap package interacts with a registry and download server that -// provides a current_version end point that serves a JSON message that -// corresponds to the this Go type: -// -// struct { -// Version string // The semverish version of the Npcap installer. -// URL string // The location of the Npcap installer. -// Hash string // The sha256 hash of the Npcap installer. -// } -// -// The URL field will point to the location of anb Npcap installer. +// Package npcap handles fetching and installing Npcap for Windows. package npcap import ( diff --git a/packetbeat/npcap/npcap_other.go b/packetbeat/npcap/npcap_other.go index c813644d471..245b69c47fc 100644 --- a/packetbeat/npcap/npcap_other.go +++ b/packetbeat/npcap/npcap_other.go @@ -20,6 +20,4 @@ package npcap -func loadWinPCAP() error { return nil } - func reloadWinPCAP() error { return nil } diff --git a/packetbeat/npcap/npcap_windows.go b/packetbeat/npcap/npcap_windows.go index 44d0053820f..f0ad2c7ccec 100644 --- a/packetbeat/npcap/npcap_windows.go +++ b/packetbeat/npcap/npcap_windows.go @@ -22,8 +22,6 @@ package npcap import "github.com/google/gopacket/pcap" -func loadWinPCAP() error { return pcap.LoadWinPCAP() } - func reloadWinPCAP() error { err := pcap.UnloadWinPCAP() if err != nil { diff --git a/packetbeat/protos/cassandra/internal/gocql/marshal.go b/packetbeat/protos/cassandra/internal/gocql/marshal.go index 3c55781cc81..1c784eeb15d 100644 --- a/packetbeat/protos/cassandra/internal/gocql/marshal.go +++ b/packetbeat/protos/cassandra/internal/gocql/marshal.go @@ -271,60 +271,6 @@ func (t Type) String() string { } } -const ( - apacheCassandraTypePrefix = "org.apache.cassandra.db.marshal." -) - -// get Apache Cassandra types -func getApacheCassandraType(class string) Type { - switch strings.TrimPrefix(class, apacheCassandraTypePrefix) { - case "AsciiType": - return TypeASCII - case "LongType": - return TypeBigInt - case "BytesType": - return TypeBlob - case "BooleanType": - return TypeBoolean - case "CounterColumnType": - return TypeCounter - case "DecimalType": - return TypeDecimal - case "DoubleType": - return TypeDouble - case "FloatType": - return TypeFloat - case "Int32Type": - return TypeInt - case "ShortType": - return TypeSmallInt - case "ByteType": - return TypeTinyInt - case "DateType", "TimestampType": - return TypeTimestamp - case "UUIDType", "LexicalUUIDType": - return TypeUUID - case "UTF8Type": - return TypeVarchar - case "IntegerType": - return TypeVarint - case "TimeUUIDType": - return TypeTimeUUID - case "InetAddressType": - return TypeInet - case "MapType": - return TypeMap - case "ListType": - return TypeList - case "SetType": - return TypeSet - case "TupleType": - return TypeTuple - default: - return TypeCustom - } -} - // error Types type ErrType int @@ -565,15 +511,6 @@ const ( flagHasMorePages int = 0x02 flagNoMetaData int = 0x04 - // query flags - flagValues byte = 0x01 - flagSkipMetaData byte = 0x02 - flagPageSize byte = 0x04 - flagWithPagingState byte = 0x08 - flagWithSerialConsistency byte = 0x10 - flagDefaultTimestamp byte = 0x20 - flagWithNameValues byte = 0x40 - // header flags flagDefault byte = 0x00 flagCompress byte = 0x01 diff --git a/packetbeat/protos/memcache/errors.go b/packetbeat/protos/memcache/errors.go index 282812a3492..aa60b6fd8ca 100644 --- a/packetbeat/protos/memcache/errors.go +++ b/packetbeat/protos/memcache/errors.go @@ -23,16 +23,12 @@ import ( "errors" ) -var errNotImplemented = errors.New("not implemented") - // memcache text parser errors var ( errParserCaughtInError = errors.New("memcache parser caught in error loop") errParserUnknownCommand = errors.New("unknown memcache command found") errNoMoreArgument = errors.New("no more command arguments") - errExpectedNumber = errors.New("expected number value") errExpectedNoReply = errors.New("expected noreply in argument list") - errExpectedCRLF = errors.New("expected CRLF") errExpectedKeys = errors.New("message has no keys") ) @@ -49,11 +45,10 @@ var ( // memcache transaction/message errors var ( - errInvalidMessage = errors.New("message is invalid") - errMixOfBinaryAndText = errors.New("mix of binary and text in one connection") - errResponseUnknownTransaction = errors.New("response from unknown transaction") - errExpectedValueForMerge = errors.New("expected value to merge with") - errExpectedStatsForMerge = errors.New("expected stat response to merge with") + errInvalidMessage = errors.New("message is invalid") + errMixOfBinaryAndText = errors.New("mix of binary and text in one connection") + errExpectedValueForMerge = errors.New("expected value to merge with") + errExpectedStatsForMerge = errors.New("expected stat response to merge with") ) // internal notes to be published with transaction diff --git a/packetbeat/scripts/mage/config.go b/packetbeat/scripts/mage/config.go index c8b3d7242a4..1ae89d8a4f7 100644 --- a/packetbeat/scripts/mage/config.go +++ b/packetbeat/scripts/mage/config.go @@ -23,11 +23,6 @@ import ( devtools "github.com/elastic/beats/v7/dev-tools/mage" ) -const ( - // configTemplateGlob matches Packetbeat protocol config file templates. - configTemplateGlob = "protos/*/_meta/config*.yml.tmpl" -) - var defaultDevice = map[string]string{ "darwin": "en0", "linux": "any",