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

make Geneve implement DecodingLayer #1202

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions layers/geneve.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ type GeneveOption struct {
Data []byte
}

// ensure Geneve implements DecodingLayer.
var _ gopacket.DecodingLayer = (*Geneve)(nil)

// LayerType returns LayerTypeGeneve
func (gn *Geneve) LayerType() gopacket.LayerType { return LayerTypeGeneve }

Expand Down Expand Up @@ -176,3 +179,8 @@ func (gn *Geneve) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.Serializ

return nil
}

// CanDecode implements DecodingLayer.
func (gn *Geneve) CanDecode() gopacket.LayerClass {
return LayerTypeGeneve
}
6 changes: 5 additions & 1 deletion layers/geneve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ func TestIsomorphicPacketGeneve(t *testing.T) {
gnTranslated.BaseLayer = BaseLayer{}

if !reflect.DeepEqual(gn, gnTranslated) {
t.Errorf("VXLAN isomorph mismatch, \nwant %#v\ngot %#v\n", gn, gnTranslated)
t.Errorf("Geneve isomorph mismatch, \nwant %#v\ngot %#v\n", gn, gnTranslated)
}
}

func TestGeneveAsDecodingLayer(t *testing.T) {
_ = gopacket.NewDecodingLayerParser(LayerTypeGeneve, &Geneve{})
}