diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2021-01-23 01:14:51 +0100 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2021-01-23 21:43:01 +0100 |
commit | 2ce080f581556f9512a481e7fcddecaed0ae7be7 (patch) | |
tree | 13e32a386e0fbddd21aa22f07fd1b841a51e2099 /pkg/tcpip/header | |
parent | 0627e26831c8c58a5fab619d127587dc1ad8a19b (diff) |
WIP GRE tunnel
Diffstat (limited to 'pkg/tcpip/header')
-rw-r--r-- | pkg/tcpip/header/gre.go | 19 | ||||
-rw-r--r-- | pkg/tcpip/header/parse/parse.go | 10 |
2 files changed, 29 insertions, 0 deletions
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 +} |