summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/stack
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-09-22 19:43:15 +0000
committergVisor bot <gvisor-bot@google.com>2021-09-22 19:43:15 +0000
commit852cf32441b5923efb72c34280094f9a7de7acac (patch)
tree6344240c1aecf3ae94d2593ae367f6a38f862010 /pkg/tcpip/stack
parentb39716d116fda92cbb332d317cd8e6079266be3f (diff)
parent5768a147b124efbeff2800794da7ba961146af19 (diff)
Merge release-20210906.0-57-g5768a147b (automated)
Diffstat (limited to 'pkg/tcpip/stack')
-rw-r--r--pkg/tcpip/stack/packet_buffer.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/pkg/tcpip/stack/packet_buffer.go b/pkg/tcpip/stack/packet_buffer.go
index 29c22bfd4..b9280c2de 100644
--- a/pkg/tcpip/stack/packet_buffer.go
+++ b/pkg/tcpip/stack/packet_buffer.go
@@ -341,6 +341,37 @@ func (pk *PacketBuffer) CloneToInbound() *PacketBuffer {
return newPk
}
+// DeepCopyForForwarding creates a deep copy of the packet buffer for
+// forwarding.
+//
+// The returned packet buffer will have the network and transport headers
+// set if the original packet buffer did.
+func (pk *PacketBuffer) DeepCopyForForwarding(reservedHeaderBytes int) *PacketBuffer {
+ newPkt := NewPacketBuffer(PacketBufferOptions{
+ ReserveHeaderBytes: reservedHeaderBytes,
+ Data: PayloadSince(pk.NetworkHeader()).ToVectorisedView(),
+ IsForwardedPacket: true,
+ })
+
+ {
+ consumeBytes := pk.NetworkHeader().View().Size()
+ if _, consumed := newPkt.NetworkHeader().Consume(consumeBytes); !consumed {
+ panic(fmt.Sprintf("expected to consume network header %d bytes from new packet", consumeBytes))
+ }
+ newPkt.NetworkProtocolNumber = pk.NetworkProtocolNumber
+ }
+
+ {
+ consumeBytes := pk.TransportHeader().View().Size()
+ if _, consumed := newPkt.TransportHeader().Consume(consumeBytes); !consumed {
+ panic(fmt.Sprintf("expected to consume transport header %d bytes from new packet", consumeBytes))
+ }
+ newPkt.TransportProtocolNumber = pk.TransportProtocolNumber
+ }
+
+ return newPkt
+}
+
// headerInfo stores metadata about a header in a packet.
type headerInfo struct {
// offset is the offset of the header in pk.buf relative to