summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/stack/packet_buffer.go
diff options
context:
space:
mode:
authorKevin Krakauer <krakauer@google.com>2020-09-30 16:02:46 -0700
committergVisor bot <gvisor-bot@google.com>2020-09-30 16:04:26 -0700
commit6f8d64f4229be58814319003a397b971ca9b4e1b (patch)
tree5ce3e40ad5e76617e288bbd89fa385b8fddcfdd1 /pkg/tcpip/stack/packet_buffer.go
parent7f9e13053e84b82c67c12a4964fa4703ebaa571f (diff)
ip6tables: redirect support
Adds support for the IPv6-compatible redirect target. Redirection is a limited form of DNAT, where the destination is always the localhost. Updates #3549. PiperOrigin-RevId: 334698344
Diffstat (limited to 'pkg/tcpip/stack/packet_buffer.go')
-rw-r--r--pkg/tcpip/stack/packet_buffer.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/pkg/tcpip/stack/packet_buffer.go b/pkg/tcpip/stack/packet_buffer.go
index a7d9d59fa..105583c49 100644
--- a/pkg/tcpip/stack/packet_buffer.go
+++ b/pkg/tcpip/stack/packet_buffer.go
@@ -19,6 +19,7 @@ import (
"gvisor.dev/gvisor/pkg/sync"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/buffer"
+ "gvisor.dev/gvisor/pkg/tcpip/header"
)
type headerType int
@@ -255,6 +256,20 @@ func (pk *PacketBuffer) Clone() *PacketBuffer {
return newPk
}
+// Network returns the network header as a header.Network.
+//
+// Network should only be called when NetworkHeader has been set.
+func (pk *PacketBuffer) Network() header.Network {
+ switch netProto := pk.NetworkProtocolNumber; netProto {
+ case header.IPv4ProtocolNumber:
+ return header.IPv4(pk.NetworkHeader().View())
+ case header.IPv6ProtocolNumber:
+ return header.IPv6(pk.NetworkHeader().View())
+ default:
+ panic(fmt.Sprintf("unknown network protocol number %d", netProto))
+ }
+}
+
// headerInfo stores metadata about a header in a packet.
type headerInfo struct {
// buf is the memorized slice for both prepended and consumed header.