Skip to content

Commit

Permalink
Decode erspan
Browse files Browse the repository at this point in the history
  • Loading branch information
negbie committed Feb 13, 2018
1 parent be7b470 commit 6ffa236
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type InterfacesConfig struct {
RotationTime int `config:"rotation_time"`
PortRange string `config:"port_range"`
WithVlan bool `config:"with_vlan"`
WithErspan bool `config:"with_erspan"`
Snaplen int `config:"snaplen"`
BufferSizeMb int `config:"buffer_size_mb"`
ReadSpeed bool `config:"top_speed"`
Expand Down
14 changes: 14 additions & 0 deletions decoder/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ func (d *Decoder) Process(data []byte, ci *gopacket.CaptureInfo) (*Packet, error
packet := gopacket.NewPacket(data, d.LayerType, gopacket.DecodeOptions{Lazy: true, NoCopy: true})
logp.Debug("layer", "\n%v", packet)

if greLayer := packet.Layer(layers.LayerTypeGRE); greLayer != nil {
gre, ok := greLayer.(*layers.GRE)
if !ok {
return nil, nil
}

if config.Cfg.Iface.WithErspan {
packet = gopacket.NewPacket(gre.Payload[8:], d.LayerType, gopacket.DecodeOptions{Lazy: true, NoCopy: true})
} else {
packet = gopacket.NewPacket(gre.Payload, d.LayerType, gopacket.DecodeOptions{Lazy: true, NoCopy: true})
}
logp.Debug("layer", "\nlayer inside GRE\n%v", packet)
}

if dot1qLayer := packet.Layer(layers.LayerTypeDot1Q); dot1qLayer != nil {
dot1q, ok := dot1qLayer.(*layers.Dot1Q)
if !ok {
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ func parseFlags() {
flag.BoolVar(&ifaceConfig.ReadSpeed, "rs", false, "Maximum pcap read speed. Doesn't use packet timestamps")
flag.IntVar(&ifaceConfig.Snaplen, "s", 16384, "Snaplength")
flag.StringVar(&ifaceConfig.PortRange, "pr", "5060-5090", "Portrange to capture SIP")
flag.BoolVar(&ifaceConfig.WithVlan, "vl", false, "Vlan")
flag.BoolVar(&ifaceConfig.WithVlan, "vlan", false, "vlan")
flag.BoolVar(&ifaceConfig.WithErspan, "erspan", false, "erspan")
flag.IntVar(&ifaceConfig.BufferSizeMb, "b", 32, "Interface buffersize (MB)")
flag.StringVar(&logging.Level, "l", "info", "Log level [debug, info, warning, error]")
flag.BoolVar(&ifaceConfig.OneAtATime, "o", false, "Read packet for packet")
Expand Down
3 changes: 3 additions & 0 deletions sniffer/sniffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ func (sniffer *SnifferSetup) setFromConfig() error {
if sniffer.config.WithVlan {
sniffer.filter = fmt.Sprintf("%s or (vlan and (%s))", sniffer.filter, sniffer.filter)
}
if sniffer.config.WithErspan {
sniffer.filter = fmt.Sprintf("%s or proto GRE", sniffer.filter)
}

logp.Info("Sniffer [type:%s, device:%s, mode:%s] OS [type:%s, arch:%s]",
sniffer.config.Type, sniffer.config.Device, sniffer.mode, runtime.GOOS, runtime.GOARCH)
Expand Down

0 comments on commit 6ffa236

Please sign in to comment.