From 2ce080f581556f9512a481e7fcddecaed0ae7be7 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Sat, 23 Jan 2021 01:14:51 +0100 Subject: WIP GRE tunnel --- pkg/tcpip/header/gre.go | 19 +++++++++++++++++++ pkg/tcpip/header/parse/parse.go | 10 ++++++++++ 2 files changed, 29 insertions(+) create mode 100644 pkg/tcpip/header/gre.go (limited to 'pkg/tcpip/header') diff --git a/pkg/tcpip/header/gre.go b/pkg/tcpip/header/gre.go new file mode 100644 index 000000000..3d1cc97d9 --- /dev/null +++ b/pkg/tcpip/header/gre.go @@ -0,0 +1,19 @@ +package header + +import ( + "encoding/binary" + + "gvisor.dev/gvisor/pkg/tcpip" +) + +const ( + greProtocolType = 2 +) + +// GRE represents a GRE header stored in a byte array. +type GRE []byte + +// SetLength sets the "length" field of the udp header. +func (b GRE) SetProtocolType(protocol tcpip.NetworkProtocolNumber) { + binary.BigEndian.PutUint16(b[greProtocolType:], uint16(protocol)) +} diff --git a/pkg/tcpip/header/parse/parse.go b/pkg/tcpip/header/parse/parse.go index 2042f214a..3e5336c04 100644 --- a/pkg/tcpip/header/parse/parse.go +++ b/pkg/tcpip/header/parse/parse.go @@ -169,3 +169,13 @@ func TCP(pkt *stack.PacketBuffer) bool { pkt.TransportProtocolNumber = header.TCPProtocolNumber return ok } + +// GRE parses a GRE packet found in pkt.Data and populates pkt's transport +// header with the GRE header. +// +// Returns true if the header was successfully parsed. +func GRE(pkt *stack.PacketBuffer) bool { + _, ok := pkt.TransportHeader().Consume(4) + pkt.TransportProtocolNumber = 47 + return ok +} -- cgit v1.2.3