diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2021-01-23 02:19:03 +0100 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2021-01-23 21:43:01 +0100 |
commit | 6e97bcdf505f60c362e4ba7cc648d3b6f9e3fa18 (patch) | |
tree | d3490b55665966c567c713288fefd206584b6fbd /pkg | |
parent | b9db93d60492d7816fd6cc4201228ee35820a36d (diff) |
decode gre protocol type
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/tcpip/header/gre.go | 9 | ||||
-rw-r--r-- | pkg/tcpip/sample/tun_tcp_connect/main.go | 8 |
2 files changed, 12 insertions, 5 deletions
diff --git a/pkg/tcpip/header/gre.go b/pkg/tcpip/header/gre.go index 65f5c1894..326d03ba8 100644 --- a/pkg/tcpip/header/gre.go +++ b/pkg/tcpip/header/gre.go @@ -1,8 +1,8 @@ package header import ( - "encoding/binary" - + "encoding/binary" + "gvisor.dev/gvisor/pkg/tcpip" ) @@ -18,6 +18,11 @@ const ( 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/sample/tun_tcp_connect/main.go b/pkg/tcpip/sample/tun_tcp_connect/main.go index 19276aca7..e0ab521ff 100644 --- a/pkg/tcpip/sample/tun_tcp_connect/main.go +++ b/pkg/tcpip/sample/tun_tcp_connect/main.go @@ -139,15 +139,17 @@ type GreHandlerInfo struct { func (info *GreHandlerInfo) greHandler(req *gre.ForwarderRequest) { pkt := req.Pkt log.Println("greHandler: ", req.Pkt.Size(), req.Pkt.Views()) + greHdr := header.GRE(pkt.TransportHeader().View()) + proto := greHdr.ProtocolType() views := pkt.Data.Views() size := pkt.Data.Size() data := buffer.NewVectorisedView(size, views) newPkt := stack.NewPacketBuffer(stack.PacketBufferOptions{ Data: data, }) - log.Println("greHandler cloned: ", newPkt.Views()) + log.Printf("greHandler proto: %d cloned: %v", proto, newPkt.Views()) - info.ChEp.InjectInbound(header.IPv4ProtocolNumber, newPkt) + info.ChEp.InjectInbound(proto, newPkt) } func (info *GreHandlerInfo) greRead(ep *channel.Endpoint) { @@ -155,7 +157,7 @@ func (info *GreHandlerInfo) greRead(ep *channel.Endpoint) { pi, err := ep.ReadContext(context.Background()); linkHdr := pi.Pkt.LinkHeader() greHdr := header.GRE(linkHdr.Push(4)) //header.IPv4MinimumSize + 4) - greHdr.SetProtocolType(header.IPv4ProtocolNumber) + greHdr.SetProtocolType(pi.Proto) log.Printf("greRead %d %v %v %v", pi.Proto, pi, err, greHdr) opts := tcpip.WriteOptions{ //To: &info.Raddr |