summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/link/tun
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-06-29 17:54:17 -0700
committergVisor bot <gvisor-bot@google.com>2021-06-29 17:54:17 -0700
commit3e5a6981d65c5e658bc4e8ed3b01aa9b6d2adfb7 (patch)
tree98931d8ebed6d141841629e69d829f7412e63c3b /pkg/tcpip/link/tun
parent57095bd3bd75338fd6a95a7478c9cb444b5e9980 (diff)
parentddbc27365978a7c634354000094f86022d3ecd2f (diff)
Merge pull request #6085 from liornm:fix-tun-no_pi
PiperOrigin-RevId: 382202462
Diffstat (limited to 'pkg/tcpip/link/tun')
-rw-r--r--pkg/tcpip/link/tun/device.go16
1 files changed, 9 insertions, 7 deletions
diff --git a/pkg/tcpip/link/tun/device.go b/pkg/tcpip/link/tun/device.go
index 575a084e2..59ac5cb8c 100644
--- a/pkg/tcpip/link/tun/device.go
+++ b/pkg/tcpip/link/tun/device.go
@@ -208,6 +208,15 @@ func (d *Device) Write(data []byte) (int64, error) {
protocol = pktInfoHdr.Protocol()
case ethHdr != nil:
protocol = ethHdr.Type()
+ case d.flags.TUN:
+ // TUN interface with IFF_NO_PI enabled, thus
+ // we need to determine protocol from version field
+ version := data[0] >> 4
+ if version == 4 {
+ protocol = header.IPv4ProtocolNumber
+ } else if version == 6 {
+ protocol = header.IPv6ProtocolNumber
+ }
}
// Try to determine remote link address, default zero.
@@ -265,13 +274,6 @@ func (d *Device) encodePkt(info *channel.PacketInfo) (buffer.View, bool) {
vv.AppendView(buffer.View(hdr))
}
- // If the packet does not already have link layer header, and the route
- // does not exist, we can't compute it. This is possibly a raw packet, tun
- // device doesn't support this at the moment.
- if info.Pkt.LinkHeader().View().IsEmpty() && len(info.Route.RemoteLinkAddress) == 0 {
- return nil, false
- }
-
// Ethernet header (TAP only).
if d.flags.TAP {
// Add ethernet header if not provided.