diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2021-02-05 02:04:06 +0100 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2021-09-21 20:01:54 +0200 |
commit | b2718e250d7ef39048f03b9cc5eeeccf23d5ca8e (patch) | |
tree | f8b6b9593447ca83f46aab2ed2f08c0981d11b00 /pkg/tcpip/header | |
parent | e819029f3ad059bfc1635b7f2a196c332fa7532f (diff) |
WIP: GRE
Diffstat (limited to 'pkg/tcpip/header')
-rw-r--r-- | pkg/tcpip/header/BUILD | 1 | ||||
-rw-r--r-- | pkg/tcpip/header/arp.go | 1 | ||||
-rw-r--r-- | pkg/tcpip/header/gre.go | 45 | ||||
-rw-r--r-- | pkg/tcpip/header/parse/parse.go | 10 |
4 files changed, 57 insertions, 0 deletions
diff --git a/pkg/tcpip/header/BUILD b/pkg/tcpip/header/BUILD index 01240f5d0..20144ee85 100644 --- a/pkg/tcpip/header/BUILD +++ b/pkg/tcpip/header/BUILD @@ -8,6 +8,7 @@ go_library( "arp.go", "checksum.go", "eth.go", + "gre.go", "gue.go", "icmpv4.go", "icmpv6.go", diff --git a/pkg/tcpip/header/arp.go b/pkg/tcpip/header/arp.go index 83189676e..7cc0e2db9 100644 --- a/pkg/tcpip/header/arp.go +++ b/pkg/tcpip/header/arp.go @@ -41,6 +41,7 @@ const ( // https://www.iana.org/assignments/arp-parameters/arp-parameters.xhtml#arp-parameters-2 ARPHardwareEther ARPHardwareType = 1 ARPHardwareLoopback ARPHardwareType = 2 + ARPHardwareIPGRE ARPHardwareType = 3 ) // ARPOp is an ARP opcode. diff --git a/pkg/tcpip/header/gre.go b/pkg/tcpip/header/gre.go new file mode 100644 index 000000000..d4b1f200b --- /dev/null +++ b/pkg/tcpip/header/gre.go @@ -0,0 +1,45 @@ +// Copyright 2021 The gVisor Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +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 + +const ( + GREHeaderSize = 4 + + // GREProtocolNumber is GRE's transport protocol number. + GREProtocolNumber tcpip.TransportProtocolNumber = 47 +) + +func (b GRE) ProtocolType() tcpip.NetworkProtocolNumber { + proto := binary.BigEndian.Uint16(b[greProtocolType:]) + return tcpip.NetworkProtocolNumber(proto) +} + +// 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 1c913b5e1..107665d9d 100644 --- a/pkg/tcpip/header/parse/parse.go +++ b/pkg/tcpip/header/parse/parse.go @@ -175,3 +175,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(header.GREHeaderSize) + pkt.TransportProtocolNumber = header.GREProtocolNumber + return ok +} |