Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support direct sniffing on gre interface #884

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ GO_DNSTAP_PROTOBUF := 1.2.0
GO_FRAMESTREAM := 1.0.1
GO_CLIENTSYSLOG := 1.0.1
GO_TOPMAP := 1.0.2
GO_NETUTILS := 1.3.0
GO_NETUTILS := 1.5.0

BUILD_TIME := $(shell LANG=en_US date +"%F_%T_%z")
COMMIT := $(shell git rev-parse --short HEAD)
Expand Down
27 changes: 26 additions & 1 deletion docs/collectors/collector_afpacket.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Options:
* `device` (str)
> Interface name to sniff. If value is empty, bind on all interfaces.

* `enable-rawip` (bool)
> Enable the decoding of raw IP traffic (without ethernet layer), enable this option to sniff gre interface

* `enable-gre` (bool)
> Enable GRE decoding protocol support

Expand All @@ -31,14 +34,36 @@ Options:
> Specifies the maximum number of packets that can be buffered before discard additional packets.
> Set to zero to use the default global value.

Defaults:
Defaults values:

```yaml
- name: sniffer
afpacket-sniffer:
port: 53
device: wlp2s0
enable-rawip: false
enable-gre: false
enable-defrag-ip: true
chan-buffer-size: 0
```

This configuration is designed to enable traffic capture on a GRE interface (e.g., gre1) in Raw IP mode,
meaning Ethernet headers will not be present.

```yaml
- name: sniffer_gre
afpacket-sniffer:
port: 53
device: gre1
enable-rawip: true
```

This configuration is used to capture and decode GRE traffic passing through a physical interface:

```yaml
- name: sniffer_gre
afpacket-sniffer:
port: 53
device: wlp2s0
enable-gre: true
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/dmachard/go-dnstap-protobuf v1.2.0
github.com/dmachard/go-framestream v1.0.1
github.com/dmachard/go-logger v1.1.1
github.com/dmachard/go-netutils v1.3.0
github.com/dmachard/go-netutils v1.5.0
github.com/dmachard/go-powerdns-protobuf v1.3.0
github.com/dmachard/go-topmap v1.0.2
github.com/farsightsec/golang-framestream v0.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ github.com/dmachard/go-framestream v1.0.1 h1:/v93w0No5g+CTdwhlbiLbopvnKUdc9kDscK
github.com/dmachard/go-framestream v1.0.1/go.mod h1:p0gyuQSA4IfiyyhSy2grFc1oR8Tk5ewNvTMcQHzcnGs=
github.com/dmachard/go-logger v1.1.1 h1:H4mQAAyhZ6u1E8kFezz7o6PsDqhsdFbO5pZGnoNuRYI=
github.com/dmachard/go-logger v1.1.1/go.mod h1:vg6cMQBmx+SgH45XsqEyqScXp9eJhS6yuvvJZOgBbvU=
github.com/dmachard/go-netutils v1.3.0 h1:KA6NRYvJ0wqqFWvWFsO7+I1I+GHFX4MJD00GIPOS0Bs=
github.com/dmachard/go-netutils v1.3.0/go.mod h1:q7HROzGkcEONODNNAtxOtrUxVY/MACLAVzsvmyYAAMo=
github.com/dmachard/go-netutils v1.5.0 h1:JVDz3g0JhTGMf7iTrMQh0CcMI/sJK88JSWT2KnXBAdw=
github.com/dmachard/go-netutils v1.5.0/go.mod h1:q7HROzGkcEONODNNAtxOtrUxVY/MACLAVzsvmyYAAMo=
github.com/dmachard/go-powerdns-protobuf v1.3.0 h1:NlCNXNUukZjklzpvihRLMY40fDmLtYOsAkg48ozYOA0=
github.com/dmachard/go-powerdns-protobuf v1.3.0/go.mod h1:KAQfdV6BE2gI19aRv3HNBQzzGGCnNFwgCWMg1o6TpH8=
github.com/dmachard/go-topmap v1.0.2 h1:ph4qBu2qoiA6l5hrYjkyYFTFGHO/8/NE49IHME2u068=
Expand Down
1 change: 1 addition & 0 deletions pkgconfig/collectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type ConfigCollectors struct {
ChannelBufferSize int `yaml:"chan-buffer-size" default:"0"`
FragmentSupport bool `yaml:"enable-defrag-ip" default:"true"`
GreSupport bool `yaml:"enable-gre" default:"false"`
RawIPSupport bool `yaml:"enable-rawip" default:"false"`
} `yaml:"afpacket-sniffer"`
XdpLiveCapture struct {
Enable bool `yaml:"enable" default:"false"`
Expand Down
15 changes: 12 additions & 3 deletions workers/sniffer_afpacket_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ func (w *AfpacketSniffer) Listen() error {
}

var filter []bpf.Instruction
isEthernet := true
if w.GetConfig().Collectors.AfpacketLiveCapture.RawIPSupport {
isEthernet = false
}
filter, err = netutils.GetBpfDnsFilterPort(w.GetConfig().Collectors.AfpacketLiveCapture.Port, isEthernet)

if w.GetConfig().Collectors.AfpacketLiveCapture.GreSupport {
filter, err = netutils.GetBpfGreDnsFilterPort(w.GetConfig().Collectors.AfpacketLiveCapture.Port)
} else {
filter, err = netutils.GetBpfDnsFilterPort(w.GetConfig().Collectors.AfpacketLiveCapture.Port)
}
if err != nil {
return err
Expand Down Expand Up @@ -113,7 +117,12 @@ func (w *AfpacketSniffer) StartCollect() {
fragIP4Chan := make(chan gopacket.Packet)
fragIP6Chan := make(chan gopacket.Packet)

netDecoder := &netutils.NetDecoder{}
var netDecoder netutils.PacketDecoder
if w.GetConfig().Collectors.AfpacketLiveCapture.RawIPSupport {
netDecoder = &netutils.RawIPDecoder{}
} else {
netDecoder = &netutils.NetDecoder{}
}

// defrag ipv4
go netutils.IPDefragger(fragIP4Chan, udpChan, tcpChan, w.GetConfig().Collectors.AfpacketLiveCapture.Port)
Expand Down