diff options
-rw-r--r-- | pkg/tcpip/header/gre.go | 2 | ||||
-rw-r--r-- | pkg/tcpip/header/parse/parse.go | 2 | ||||
-rw-r--r-- | pkg/tcpip/sample/tun_tcp_connect/main.go | 5 | ||||
-rw-r--r-- | pkg/tcpip/transport/gre/protocol.go | 3 |
4 files changed, 8 insertions, 4 deletions
diff --git a/pkg/tcpip/header/gre.go b/pkg/tcpip/header/gre.go index 326d03ba8..f5c52cd1b 100644 --- a/pkg/tcpip/header/gre.go +++ b/pkg/tcpip/header/gre.go @@ -14,6 +14,8 @@ const ( type GRE []byte const ( + GREHeaderSize = 4 + // GREProtocolNumber is GRE's transport protocol number. GREProtocolNumber tcpip.TransportProtocolNumber = 47 ) diff --git a/pkg/tcpip/header/parse/parse.go b/pkg/tcpip/header/parse/parse.go index de3a91227..7ac5168c7 100644 --- a/pkg/tcpip/header/parse/parse.go +++ b/pkg/tcpip/header/parse/parse.go @@ -175,7 +175,7 @@ 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) + _, ok := pkt.TransportHeader().Consume(header.GREHeaderSize) pkt.TransportProtocolNumber = header.GREProtocolNumber return ok } diff --git a/pkg/tcpip/sample/tun_tcp_connect/main.go b/pkg/tcpip/sample/tun_tcp_connect/main.go index 138941afd..06ee5110b 100644 --- a/pkg/tcpip/sample/tun_tcp_connect/main.go +++ b/pkg/tcpip/sample/tun_tcp_connect/main.go @@ -156,7 +156,7 @@ func (info *GreHandlerInfo) greRead(ep *channel.Endpoint) { for { pi, err := ep.ReadContext(context.Background()); linkHdr := pi.Pkt.LinkHeader() - greHdr := header.GRE(linkHdr.Push(4)) //header.IPv4MinimumSize + 4) + greHdr := header.GRE(linkHdr.Push(header.GREHeaderSize)) greHdr.SetProtocolType(pi.Proto) log.Printf("greRead %d %v %v %v", pi.Proto, pi, err, greHdr) opts := tcpip.WriteOptions{ @@ -253,7 +253,8 @@ func main() { // Create GRE greEP := grelink.New(mtu - 24) chEP := greEP.GetChannel() - greEP.NMaxHeaderLength = 4 + 20 + // TODO detect IPv4/IPv6 + greEP.NMaxHeaderLength = header.IPv6FixedHeaderSize + header.GREHeaderSize greInfo := GreHandlerInfo{ // Ep: loEP, diff --git a/pkg/tcpip/transport/gre/protocol.go b/pkg/tcpip/transport/gre/protocol.go index a2182cfe4..b98b5df93 100644 --- a/pkg/tcpip/transport/gre/protocol.go +++ b/pkg/tcpip/transport/gre/protocol.go @@ -69,7 +69,8 @@ func (p *protocol) NewRawEndpoint(netProto tcpip.NetworkProtocolNumber, waiterQu // MinimumPacketSize returns the minimum valid gre packet size. func (*protocol) MinimumPacketSize() int { - return 4 //header.GREMinimumSize + // TODO ? + return header.GREHeaderSize } // ParsePorts returns the source and destination ports stored in the given gre |