MCPcopy Index your code
hub / github.com/tailscale/tailscale / DeliverLoopback

Method DeliverLoopback

wgengine/netstack/link_endpoint.go:211–237  ·  view source on GitHub ↗

DeliverLoopback delivers pkt back into gVisor's network stack as if it arrived from the network, for self-addressed (loopback) packets. It takes ownership of one reference count on pkt. The caller must not use pkt after calling this method. It returns false if the dispatcher is not attached. Outbou

(pkt *stack.PacketBuffer)

Source from the content-addressed store, hash-verified

209// a raw unparsed packet, so we must re-serialize the packet into a new
210// PacketBuffer with all bytes in the payload for gVisor to parse on inbound.
211func (ep *linkEndpoint) DeliverLoopback(pkt *stack.PacketBuffer) bool {
212 ep.mu.RLock()
213 d := ep.dispatcher
214 ep.mu.RUnlock()
215 if d == nil {
216 pkt.DecRef()
217 return false
218 }
219
220 // Serialize the outbound packet back to raw bytes.
221 raw := stack.PayloadSince(pkt.NetworkHeader()).AsSlice()
222 proto := pkt.NetworkProtocolNumber
223
224 // We're done with the original outbound packet.
225 pkt.DecRef()
226
227 // Create a new PacketBuffer from the raw bytes for inbound delivery.
228 newPkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
229 Payload: buffer.MakeWithData(raw),
230 })
231 newPkt.NetworkProtocolNumber = proto
232 newPkt.RXChecksumValidated = true
233
234 d.DeliverNetworkPacket(proto, newPkt)
235 newPkt.DecRef()
236 return true
237}
238
239// Attach saves the stack network-layer dispatcher for use later when packets
240// are injected.

Callers 2

TestDeliverLoopbackFunction · 0.80
injectMethod · 0.80

Calls 4

DecRefMethod · 0.80
NetworkHeaderMethod · 0.80
DeliverNetworkPacketMethod · 0.80
AsSliceMethod · 0.45

Tested by 1

TestDeliverLoopbackFunction · 0.64