From b9db93d60492d7816fd6cc4201228ee35820a36d Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Sat, 23 Jan 2021 02:18:03 +0100 Subject: fix gre protocol number --- pkg/tcpip/header/gre.go | 5 +++++ pkg/tcpip/header/parse/parse.go | 2 +- pkg/tcpip/link/gre/gre.go | 4 ++-- pkg/tcpip/sample/tun_tcp_connect/main.go | 4 ++-- pkg/tcpip/transport/gre/protocol.go | 6 +++--- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pkg/tcpip/header/gre.go b/pkg/tcpip/header/gre.go index 3d1cc97d9..65f5c1894 100644 --- a/pkg/tcpip/header/gre.go +++ b/pkg/tcpip/header/gre.go @@ -13,6 +13,11 @@ const ( // GRE represents a GRE header stored in a byte array. type GRE []byte +const ( + // GREProtocolNumber is GRE's transport protocol number. + GREProtocolNumber tcpip.TransportProtocolNumber = 47 +) + // 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 3e5336c04..de3a91227 100644 --- a/pkg/tcpip/header/parse/parse.go +++ b/pkg/tcpip/header/parse/parse.go @@ -176,6 +176,6 @@ func TCP(pkt *stack.PacketBuffer) bool { // Returns true if the header was successfully parsed. func GRE(pkt *stack.PacketBuffer) bool { _, ok := pkt.TransportHeader().Consume(4) - pkt.TransportProtocolNumber = 47 + pkt.TransportProtocolNumber = header.GREProtocolNumber return ok } diff --git a/pkg/tcpip/link/gre/gre.go b/pkg/tcpip/link/gre/gre.go index cd05f39d7..04f8f8da7 100644 --- a/pkg/tcpip/link/gre/gre.go +++ b/pkg/tcpip/link/gre/gre.go @@ -7,6 +7,7 @@ import ( "os" "gvisor.dev/gvisor/pkg/tcpip" + "gvisor.dev/gvisor/pkg/tcpip/header" "gvisor.dev/gvisor/pkg/tcpip/link/channel" "gvisor.dev/gvisor/pkg/tcpip/network/ipv4" "gvisor.dev/gvisor/pkg/tcpip/transport/raw" @@ -15,7 +16,6 @@ import ( ) var SIZE = 16 -var ProtocolNumber tcpip.TransportProtocolNumber = 47 type Endpoint struct { channel.Endpoint @@ -41,7 +41,7 @@ func (e *Endpoint) Bind(s *stack.Stack, laddr tcpip.FullAddress) { // Create TCP endpoint. var wq waiter.Queue - ep, err := raw.NewEndpoint(s, ipv4.ProtocolNumber, ProtocolNumber, &wq) + ep, err := raw.NewEndpoint(s, ipv4.ProtocolNumber, header.GREProtocolNumber, &wq) if err != nil { log.Fatal(err) } diff --git a/pkg/tcpip/sample/tun_tcp_connect/main.go b/pkg/tcpip/sample/tun_tcp_connect/main.go index f44237295..19276aca7 100644 --- a/pkg/tcpip/sample/tun_tcp_connect/main.go +++ b/pkg/tcpip/sample/tun_tcp_connect/main.go @@ -233,7 +233,7 @@ func main() { // Create TCP endpoint. var rawWq waiter.Queue - rawEp, tcperr := raw.NewEndpoint(s, ipv4.ProtocolNumber, 47, &rawWq) + rawEp, tcperr := raw.NewEndpoint(s, ipv4.ProtocolNumber, header.GREProtocolNumber, &rawWq) if tcperr != nil { log.Fatal(tcperr) } @@ -260,7 +260,7 @@ func main() { Raddr: fraddr, } greFwd := gre.NewForwarder(s, greInfo.greHandler) - s.SetTransportProtocolHandler(47, greFwd.HandlePacket) + s.SetTransportProtocolHandler(header.GREProtocolNumber, greFwd.HandlePacket) go greInfo.greRead(chEP) //greEP.Bind(s, greIP) diff --git a/pkg/tcpip/transport/gre/protocol.go b/pkg/tcpip/transport/gre/protocol.go index c1a49d042..a2182cfe4 100644 --- a/pkg/tcpip/transport/gre/protocol.go +++ b/pkg/tcpip/transport/gre/protocol.go @@ -20,7 +20,7 @@ import ( "gvisor.dev/gvisor/pkg/tcpip" "gvisor.dev/gvisor/pkg/tcpip/buffer" -// "gvisor.dev/gvisor/pkg/tcpip/header" + "gvisor.dev/gvisor/pkg/tcpip/header" "gvisor.dev/gvisor/pkg/tcpip/header/parse" "gvisor.dev/gvisor/pkg/tcpip/stack" "gvisor.dev/gvisor/pkg/tcpip/transport/raw" @@ -29,7 +29,7 @@ import ( const ( // ProtocolNumber is the gre protocol number. - ProtocolNumber = 47 //header.GREProtocolNumber + ProtocolNumber = header.GREProtocolNumber // MinBufferSize is the smallest size of a receive or send buffer. MinBufferSize = 4 << 10 // 4KiB bytes. @@ -64,7 +64,7 @@ func (p *protocol) NewEndpoint(netProto tcpip.NetworkProtocolNumber, waiterQueue // NewRawEndpoint creates a new raw GRE endpoint. It implements // stack.TransportProtocol.NewRawEndpoint. func (p *protocol) NewRawEndpoint(netProto tcpip.NetworkProtocolNumber, waiterQueue *waiter.Queue) (tcpip.Endpoint, *tcpip.Error) { - return raw.NewEndpoint(p.stack, netProto, /*header.GREProtocolNumber*/ 47, waiterQueue) + return raw.NewEndpoint(p.stack, netProto, ProtocolNumber, waiterQueue) } // MinimumPacketSize returns the minimum valid gre packet size. -- cgit v1.2.3