Skip to content

Commit

Permalink
[8.0](backport #29167) libbeat,packetbeat,x-pack/filebeat/input/netfl…
Browse files Browse the repository at this point in the history
…ow: unify gopacket dependencies (#29283)

* libbeat,packetbeat,x-pack/filebeat/input/netflow: unify gopacket dependencies (#29167)

(cherry picked from commit c3d31a4)

# Conflicts:
#	go.sum

* fix go.sum

Co-authored-by: Dan Kortschak <90160302+efd6@users.noreply.github.com>
Co-authored-by: Dan Kortschak <dan.kortschak@elastic.co>
  • Loading branch information
3 people committed Dec 6, 2021
1 parent 96a2a2a commit 274ccac
Show file tree
Hide file tree
Showing 25 changed files with 98 additions and 132 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- `event.category` no longer contains the value `network_traffic` because this is not a valid ECS event category value. {pull}20556[20556]
- Remove deprecated TLS fields in favor of tls.server.x509 and tls.client.x509 ECS fields. {pull}28487[28487]
- HTTP: The field `http.request.method` will maintain its original case. {pull}28620[28620]
- Unify gopacket dependencies. {pull}29167[29167]

*Winlogbeat*

Expand Down
44 changes: 3 additions & 41 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9926,12 +9926,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


--------------------------------------------------------------------------------
Dependency : github.com/adriansr/gopacket
Version: v1.1.18-0.20200327165309-dd62abfa8a41
Dependency : github.com/elastic/gopacket
Version: v1.1.20-0.20211202005954-d412fca7f83a
Licence type (autodetected): BSD-3-Clause
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/adriansr/gopacket@v1.1.18-0.20200327165309-dd62abfa8a41/LICENSE:
Contents of probable licence file $GOMODCACHE/github.com/elastic/gopacket@v1.1.20-0.20211202005954-d412fca7f83a/LICENSE:

Copyright (c) 2012 Google, Inc. All rights reserved.
Copyright (c) 2009-2011 Andreas Krennmair. All rights reserved.
Expand Down Expand Up @@ -14621,44 +14621,6 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


--------------------------------------------------------------------------------
Dependency : github.com/tsg/gopacket
Version: v0.0.0-20200626092518-2ab8e397a786
Licence type (autodetected): BSD-3-Clause
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/tsg/gopacket@v0.0.0-20200626092518-2ab8e397a786/LICENSE:

Copyright (c) 2012 Google, Inc. All rights reserved.
Copyright (c) 2009-2011 Andreas Krennmair. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Andreas Krennmair, Google, nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


--------------------------------------------------------------------------------
Dependency : github.com/ugorji/go/codec
Version: v1.1.8
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ require (
github.com/gomodule/redigo v1.8.3
github.com/google/flatbuffers v1.12.1
github.com/google/go-cmp v0.5.6
github.com/google/gopacket v1.1.18-0.20191009163724-0ad7f2610e34
github.com/google/gopacket v1.1.19
github.com/google/uuid v1.3.0
github.com/gorhill/cronexpr v0.0.0-20180427100037-88b0669f7d75
github.com/gorilla/mux v1.7.3
Expand Down Expand Up @@ -147,7 +147,6 @@ require (
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
github.com/tsg/go-daemon v0.0.0-20200207173439-e704b93fd89b
github.com/tsg/gopacket v0.0.0-20200626092518-2ab8e397a786
github.com/ugorji/go/codec v1.1.8
github.com/urso/sderr v0.0.0-20210525210834-52b04e8f5c71
github.com/vmware/govmomi v0.0.0-20170802214208-2cad15190b41
Expand Down Expand Up @@ -293,7 +292,7 @@ replace (
github.com/fsnotify/fsevents => github.com/elastic/fsevents v0.0.0-20181029231046-e1d381a4d270
github.com/fsnotify/fsnotify => github.com/adriansr/fsnotify v1.4.8-0.20211018144411-a81f2b630e7c
github.com/golang/glog => github.com/elastic/glog v1.0.1-0.20210831205241-7d8b5c89dfc4
github.com/google/gopacket => github.com/adriansr/gopacket v1.1.18-0.20200327165309-dd62abfa8a41
github.com/google/gopacket => github.com/elastic/gopacket v1.1.20-0.20211202005954-d412fca7f83a
github.com/insomniacslk/dhcp => github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3 // indirect
github.com/tonistiigi/fifo => github.com/containerd/fifo v0.0.0-20190816180239-bda0ff6ed73c
)
7 changes: 3 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ github.com/StackExchange/wmi v0.0.0-20170221213301-9f32b5905fd6 h1:2Gl9Tray0NEjP
github.com/StackExchange/wmi v0.0.0-20170221213301-9f32b5905fd6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/adriansr/fsnotify v1.4.8-0.20211018144411-a81f2b630e7c h1:LpOCwE9oTg0+1Dm8rB06dKxQs7yu5tdnM6A/Zm/juQQ=
github.com/adriansr/fsnotify v1.4.8-0.20211018144411-a81f2b630e7c/go.mod h1:onXS6zmTa1LJcurVsOkzywEV/Q3pdEqqu362/8OQzAI=
github.com/adriansr/gopacket v1.1.18-0.20200327165309-dd62abfa8a41 h1:9OmEpkkO4vm8Wz+JKWHDLZdzYrqXr4dovxIJDkTltKE=
github.com/adriansr/gopacket v1.1.18-0.20200327165309-dd62abfa8a41/go.mod h1:UdDNZ1OO62aGYVnPhxT1U6aI7ukYtA/kB8vaU0diBUM=
github.com/aerospike/aerospike-client-go v1.27.1-0.20170612174108-0f3b54da6bdc h1:9iW/Fbn/R/nyUOiqo6AgwBe8uirqUIoTGF3vKG8qjoc=
github.com/aerospike/aerospike-client-go v1.27.1-0.20170612174108-0f3b54da6bdc/go.mod h1:zj8LBEnWBDOVEIJt8LvaRvDG5ARAoa5dBeHaB472NRc=
github.com/akavel/rsrc v0.8.0 h1:zjWn7ukO9Kc5Q62DOJCcxGpXC18RawVtYAGdz2aLlfw=
Expand Down Expand Up @@ -450,6 +448,8 @@ github.com/elastic/go-ucfg v0.8.3/go.mod h1:iaiY0NBIYeasNgycLyTvhJftQlQEUO2hpF+F
github.com/elastic/go-windows v1.0.0/go.mod h1:TsU0Nrp7/y3+VwE82FoZF8gC/XFg/Elz6CcloAxnPgU=
github.com/elastic/go-windows v1.0.1 h1:AlYZOldA+UJ0/2nBuqWdo90GFCgG9xuyw9SYzGUtJm0=
github.com/elastic/go-windows v1.0.1/go.mod h1:FoVvqWSun28vaDQPbj2Elfc0JahhPB7WQEGa3c814Ss=
github.com/elastic/gopacket v1.1.20-0.20211202005954-d412fca7f83a h1:8WfL/X6fK11iyX5t3Dd9dDMMNqPfEZNc//JsWGIhEgQ=
github.com/elastic/gopacket v1.1.20-0.20211202005954-d412fca7f83a/go.mod h1:riddUzxTSBpJXk3qBHtYr4qOhFhT6k/1c0E3qkQjQpA=
github.com/elastic/gosigar v0.14.2 h1:Dg80n8cr90OZ7x+bAax/QjoW/XqTI11RmA79ZwIm9/4=
github.com/elastic/gosigar v0.14.2/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs=
github.com/elastic/sarama v1.19.1-0.20210823122811-11c3ef800752 h1:5/RUNg7rkIvayjPhAIoI3v8p45NfWcfWs5DZSElycis=
Expand Down Expand Up @@ -1061,8 +1061,6 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tsg/go-daemon v0.0.0-20200207173439-e704b93fd89b h1:X/8hkb4rQq3+QuOxpJK7gWmAXmZucF0EI1s1BfBLq6U=
github.com/tsg/go-daemon v0.0.0-20200207173439-e704b93fd89b/go.mod h1:jAqhj/JBVC1PwcLTWd6rjQyGyItxxrhpiBl8LSuAGmw=
github.com/tsg/gopacket v0.0.0-20200626092518-2ab8e397a786 h1:B/IVHYiI0d04dudYw+CvCAGqSMq8d0yWy56eD6p85BQ=
github.com/tsg/gopacket v0.0.0-20200626092518-2ab8e397a786/go.mod h1:RIkfovP3Y7my19aXEjjbNd9E5TlHozzAyt7B8AaEcwg=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/ugorji/go v1.1.8 h1:/D9x7IRpfMHDlizVOgxrag5Fh+/NY+LtI8bsr+AswRA=
github.com/ugorji/go v1.1.8/go.mod h1:0lNM99SwWUIRhCXnigEMClngXBk/EmpTXa7mgiewYWA=
Expand All @@ -1084,6 +1082,7 @@ github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852/go.mod h1:tw
github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc/go.mod h1:ZjcWmFBXmLKZu9Nxj3WKYEafiSqer2rnvPr0en9UNpI=
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
github.com/vmware/govmomi v0.0.0-20170802214208-2cad15190b41 h1:NeNpIvfvaFOh0BH7nMEljE5Rk/VJlxhm58M41SeOD20=
github.com/vmware/govmomi v0.0.0-20170802214208-2cad15190b41/go.mod h1:URlwyTFZX72RmxtxuaFL2Uj3fD1JTvZdx59bHWk6aFU=
github.com/willf/bitset v1.1.11-0.20200630133818-d5bec3311243/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
Expand Down
11 changes: 5 additions & 6 deletions libbeat/common/flowhash/communityid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,19 @@ import (
"testing"
"time"

"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/google/gopacket/pcap"

"github.com/stretchr/testify/assert"
"github.com/tsg/gopacket"
"github.com/tsg/gopacket/layers"
"github.com/tsg/gopacket/pcap"
)

const (
pcapDir = "testdata/pcap"
goldenDir = "testdata/golden"
)

var (
update = flag.Bool("update", false, "updates the golden files")
)
var update = flag.Bool("update", false, "updates the golden files")

func TestPCAPFiles(t *testing.T) {
pcaps, err := filepath.Glob(filepath.Join(pcapDir, "*.pcap"))
Expand Down
2 changes: 1 addition & 1 deletion libbeat/common/seccomp/seccomp-profiler-allow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ access
open
stat

# cgo tsg/gopacket
# cgo google/gopacket
poll
fcntl64

Expand Down
2 changes: 1 addition & 1 deletion packetbeat/beater/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package beater

import (
"github.com/tsg/gopacket/layers"
"github.com/google/gopacket/layers"

"github.com/elastic/beats/v7/packetbeat/config"
"github.com/elastic/beats/v7/packetbeat/decoder"
Expand Down
11 changes: 8 additions & 3 deletions packetbeat/decoder/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ package decoder
import (
"fmt"

"github.com/google/gopacket"
"github.com/google/gopacket/layers"

"github.com/elastic/beats/v7/libbeat/logp"
"github.com/elastic/beats/v7/packetbeat/flows"
"github.com/elastic/beats/v7/packetbeat/protos"
"github.com/elastic/beats/v7/packetbeat/protos/icmp"
"github.com/elastic/beats/v7/packetbeat/protos/tcp"
"github.com/elastic/beats/v7/packetbeat/protos/udp"

"github.com/tsg/gopacket"
"github.com/tsg/gopacket/layers"
)

var debugf = logp.MakeDebug("decoder")
Expand Down Expand Up @@ -313,6 +313,11 @@ func (d *Decoder) onICMPv6(packet *protos.Packet) {
}

if d.icmp6Proc != nil {
// google/gopacket treats the first four bytes
// after the typo, code and checksum as part of
// the payload. So drop those bytes.
// See https://github.com/google/gopacket/pull/423/
d.icmp6.Payload = d.icmp6.Payload[4:]
packet.Payload = d.icmp6.Payload
packet.Tuple.ComputeHashables()
d.icmp6Proc.ProcessICMPv6(d.flowID, &d.icmp6, packet)
Expand Down
4 changes: 2 additions & 2 deletions packetbeat/decoder/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
"github.com/elastic/beats/v7/packetbeat/flows"
"github.com/elastic/beats/v7/packetbeat/protos"

"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/stretchr/testify/assert"
"github.com/tsg/gopacket"
"github.com/tsg/gopacket/layers"
)

type TestIcmp4Processor struct {
Expand Down
2 changes: 1 addition & 1 deletion packetbeat/decoder/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package decoder

import "github.com/tsg/gopacket"
import "github.com/google/gopacket"

// implement DecodingLayer with support of switching between multiple layers to
// remember outter layer results
Expand Down
4 changes: 2 additions & 2 deletions packetbeat/protos/icmp/icmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"net"
"time"

"github.com/google/gopacket/layers"

"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/ecs"
"github.com/elastic/beats/v7/libbeat/logp"
Expand All @@ -30,8 +32,6 @@ import (
"github.com/elastic/beats/v7/packetbeat/pb"
"github.com/elastic/beats/v7/packetbeat/procs"
"github.com/elastic/beats/v7/packetbeat/protos"

"github.com/tsg/gopacket/layers"
)

type icmpPlugin struct {
Expand Down
6 changes: 3 additions & 3 deletions packetbeat/protos/icmp/icmp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ import (
"net"
"testing"

"github.com/google/gopacket"
"github.com/google/gopacket/layers"

"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/logp"

"github.com/elastic/beats/v7/packetbeat/procs"
"github.com/elastic/beats/v7/packetbeat/protos"

"github.com/tsg/gopacket"
"github.com/tsg/gopacket/layers"

"github.com/stretchr/testify/assert"
)

Expand Down
2 changes: 1 addition & 1 deletion packetbeat/protos/icmp/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"encoding/binary"
"time"

"github.com/tsg/gopacket/layers"
"github.com/google/gopacket/layers"

"github.com/elastic/beats/v7/libbeat/logp"
)
Expand Down
4 changes: 2 additions & 2 deletions packetbeat/protos/icmp/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package icmp
import (
"testing"

"github.com/tsg/gopacket/layers"
"github.com/google/gopacket/layers"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -113,5 +113,5 @@ func TestIcmpMessageHumanReadableICMPv6(t *testing.T) {
tuple := &icmpTuple{icmpVersion: 6}
msg := &icmpMessage{Type: layers.ICMPv6TypeDestinationUnreachable, code: 3}

assert.Equal(t, "DestinationUnreachable(Address)", humanReadable(tuple, msg))
assert.Equal(t, "DestinationUnreachable(AddressUnreachable)", humanReadable(tuple, msg))
}
2 changes: 1 addition & 1 deletion packetbeat/protos/icmp/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package icmp
import (
"testing"

"github.com/tsg/gopacket/layers"
"github.com/google/gopacket/layers"

"github.com/stretchr/testify/assert"
)
Expand Down
4 changes: 2 additions & 2 deletions packetbeat/protos/tcp/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import (
"sync"
"time"

"github.com/google/gopacket/layers"

"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/logp"
"github.com/elastic/beats/v7/libbeat/monitoring"

"github.com/elastic/beats/v7/packetbeat/flows"
"github.com/elastic/beats/v7/packetbeat/protos"

"github.com/tsg/gopacket/layers"
)

const TCPMaxDataInStream = 10 * (1 << 20)
Expand Down
3 changes: 2 additions & 1 deletion packetbeat/protos/tcp/tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ import (
"testing"
"time"

"github.com/google/gopacket/layers"

"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/packetbeat/procs"
"github.com/elastic/beats/v7/packetbeat/protos"

"github.com/stretchr/testify/assert"
"github.com/tsg/gopacket/layers"
)

// Test Constants
Expand Down
29 changes: 23 additions & 6 deletions packetbeat/sniffer/afpacket_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ import (
"time"
"unsafe"

"github.com/elastic/beats/v7/libbeat/logp"
"github.com/google/gopacket"
"github.com/google/gopacket/afpacket"
"github.com/google/gopacket/layers"
"github.com/google/gopacket/pcap"
"golang.org/x/net/bpf"

"github.com/tsg/gopacket"
"github.com/tsg/gopacket/afpacket"
"github.com/tsg/gopacket/layers"
"github.com/elastic/beats/v7/libbeat/logp"
)

type afpacketHandle struct {
TPacket *afpacket.TPacket
frameSize int
promiscPreviousState bool
promiscPreviousStateDetected bool
device string
Expand All @@ -61,6 +64,7 @@ func newAfpacketHandle(device string, snaplen int, block_size int, num_blocks in

h := &afpacketHandle{
promiscPreviousState: promiscEnabled,
frameSize: snaplen,
device: device,
promiscPreviousStateDetected: autoPromiscMode && err == nil,
}
Expand All @@ -87,8 +91,21 @@ func (h *afpacketHandle) ReadPacketData() (data []byte, ci gopacket.CaptureInfo,
return h.TPacket.ReadPacketData()
}

func (h *afpacketHandle) SetBPFFilter(expr string) (_ error) {
return h.TPacket.SetBPFFilter(expr)
func (h *afpacketHandle) SetBPFFilter(expr string) error {
prog, err := pcap.CompileBPFFilter(layers.LinkTypeEthernet, h.frameSize, expr)
if err != nil {
return err
}
p := make([]bpf.RawInstruction, len(prog))
for i, ins := range prog {
p[i] = bpf.RawInstruction{
Op: ins.Code,
Jt: ins.Jt,
Jf: ins.Jf,
K: ins.K,
}
}
return h.TPacket.SetBPF(p)
}

func (h *afpacketHandle) LinkType() layers.LinkType {
Expand Down
4 changes: 2 additions & 2 deletions packetbeat/sniffer/afpacket_nonlinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"fmt"
"time"

"github.com/tsg/gopacket"
"github.com/tsg/gopacket/layers"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
)

type afpacketHandle struct{}
Expand Down
Loading

0 comments on commit 274ccac

Please sign in to comment.