@@ -1059,26 +1059,18 @@ func (ns *Impl) acceptUDP(r *udp.ForwarderRequest) {
10591059 go ns .forwardUDP (c , srcAddr , dstAddr )
10601060}
10611061
1062- // Buffer pool for forwarding UDP packets.
1063- var udpBufPool = & sync.Pool {
1064- New : func () any {
1065- b := make ([]byte , maxUDPPacketSize )
1066- return & b
1067- },
1068- }
1069-
10701062func (ns * Impl ) handleMagicDNSUDP (srcAddr netip.AddrPort , c * gonet.UDPConn ) {
1063+ // In practice, implementations are advised not to exceed 512 bytes
1064+ // due to fragmenting. Just to be sure, we bump all the way to the MTU.
1065+ var maxUDPReqSize = tstun .DefaultMTU ()
10711066 // Packets are being generated by the local host, so there should be
10721067 // very, very little latency. 150ms was chosen as something of an upper
10731068 // bound on resource usage, while hopefully still being long enough for
10741069 // a heavily loaded system.
10751070 const readDeadline = 150 * time .Millisecond
10761071
10771072 defer c .Close ()
1078-
1079- bufp := udpBufPool .Get ().(* []byte )
1080- defer udpBufPool .Put (bufp )
1081- q := * bufp
1073+ q := make ([]byte , maxUDPReqSize )
10821074
10831075 // libresolv from glibc is quite adamant that transmitting multiple DNS
10841076 // requests down the same UDP socket is valid. To support this, we read
@@ -1191,11 +1183,7 @@ func startPacketCopy(ctx context.Context, cancel context.CancelFunc, dst net.Pac
11911183 }
11921184 go func () {
11931185 defer cancel () // tear down the other direction's copy
1194-
1195- bufp := udpBufPool .Get ().(* []byte )
1196- defer udpBufPool .Put (bufp )
1197- pkt := * bufp
1198-
1186+ pkt := make ([]byte , maxUDPPacketSize )
11991187 for {
12001188 select {
12011189 case <- ctx .Done ():
0 commit comments