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

Function startPacketCopy

wgengine/netstack/netstack.go:2105–2142  ·  view source on GitHub ↗
(ctx context.Context, cancel context.CancelFunc, dst net.PacketConn, dstAddr net.Addr, src net.PacketConn, logf logger.Logf, extend func())

Source from the content-addressed store, hash-verified

2103}
2104
2105func startPacketCopy(ctx context.Context, cancel context.CancelFunc, dst net.PacketConn, dstAddr net.Addr, src net.PacketConn, logf logger.Logf, extend func()) {
2106 if debugNetstack() {
2107 logf("[v2] netstack: startPacketCopy to %v (%T) from %T", dstAddr, dst, src)
2108 }
2109 go func() {
2110 defer cancel() // tear down the other direction's copy
2111
2112 bufp := udpBufPool.Get().(*[]byte)
2113 defer udpBufPool.Put(bufp)
2114 pkt := *bufp
2115
2116 for {
2117 select {
2118 case <-ctx.Done():
2119 return
2120 default:
2121 n, srcAddr, err := src.ReadFrom(pkt)
2122 if err != nil {
2123 if ctx.Err() == nil {
2124 logf("read packet from %s failed: %v", srcAddr, err)
2125 }
2126 return
2127 }
2128 _, err = dst.WriteTo(pkt[:n], dstAddr)
2129 if err != nil {
2130 if ctx.Err() == nil {
2131 logf("write packet to %s failed: %v", dstAddr, err)
2132 }
2133 return
2134 }
2135 if debugNetstack() {
2136 logf("[v2] wrote UDP packet %s -> %s", srcAddr, dstAddr)
2137 }
2138 extend()
2139 }
2140 }
2141 }()
2142}
2143
2144func stringifyTEI(tei stack.TransportEndpointID) string {
2145 localHostPort := net.JoinHostPort(tei.LocalAddress.String(), strconv.Itoa(int(tei.LocalPort)))

Callers 1

forwardUDPMethod · 0.85

Calls 6

PutMethod · 0.80
GetMethod · 0.65
DoneMethod · 0.65
ReadFromMethod · 0.45
ErrMethod · 0.45
WriteToMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…