inside.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. package nebula
  2. import (
  3. "net/netip"
  4. "github.com/sirupsen/logrus"
  5. "github.com/slackhq/nebula/firewall"
  6. "github.com/slackhq/nebula/header"
  7. "github.com/slackhq/nebula/iputil"
  8. "github.com/slackhq/nebula/noiseutil"
  9. "github.com/slackhq/nebula/routing"
  10. "github.com/slackhq/nebula/udp"
  11. )
  12. // consumeInsidePacketBatched is a variant of consumeInsidePacket that queues
  13. // outgoing packets into pendingPackets instead of sending them immediately.
  14. // The caller is responsible for flushing pendingPackets with WriteBatch.
  15. func (f *Interface) consumeInsidePacketBatched(packet []byte, fwPacket *firewall.Packet, nb, out []byte, q int, localCache firewall.ConntrackCache, pendingPackets *[]udp.BatchPacket) {
  16. err := newPacket(packet, false, fwPacket)
  17. if err != nil {
  18. if f.l.Level >= logrus.DebugLevel {
  19. f.l.WithField("packet", packet).Debugf("Error while validating outbound packet: %s", err)
  20. }
  21. return
  22. }
  23. // Ignore local broadcast packets
  24. if f.dropLocalBroadcast {
  25. if f.myBroadcastAddrsTable.Contains(fwPacket.RemoteAddr) {
  26. return
  27. }
  28. }
  29. if f.myVpnAddrsTable.Contains(fwPacket.RemoteAddr) {
  30. if immediatelyForwardToSelf {
  31. _, err := f.readers[q].Write(packet)
  32. if err != nil {
  33. f.l.WithError(err).Error("Failed to forward to tun")
  34. }
  35. }
  36. return
  37. }
  38. // Ignore multicast packets
  39. if f.dropMulticast && fwPacket.RemoteAddr.IsMulticast() {
  40. return
  41. }
  42. hostinfo, ready := f.getOrHandshakeConsiderRouting(fwPacket, func(hh *HandshakeHostInfo) {
  43. hh.cachePacket(f.l, header.Message, 0, packet, f.sendMessageNow, f.cachedPacketMetrics)
  44. })
  45. if hostinfo == nil {
  46. f.rejectInside(packet, out, q)
  47. if f.l.Level >= logrus.DebugLevel {
  48. f.l.WithField("vpnAddr", fwPacket.RemoteAddr).
  49. WithField("fwPacket", fwPacket).
  50. Debugln("dropping outbound packet, vpnAddr not in our vpn networks or in unsafe networks")
  51. }
  52. return
  53. }
  54. if !ready {
  55. return
  56. }
  57. dropReason := f.firewall.Drop(*fwPacket, false, hostinfo, f.pki.GetCAPool(), localCache)
  58. if dropReason == nil {
  59. f.sendNoMetricsBatched(header.Message, 0, hostinfo.ConnectionState, hostinfo, netip.AddrPort{}, packet, nb, out, q, pendingPackets)
  60. } else {
  61. f.rejectInside(packet, out, q)
  62. if f.l.Level >= logrus.DebugLevel {
  63. hostinfo.logger(f.l).
  64. WithField("fwPacket", fwPacket).
  65. WithField("reason", dropReason).
  66. Debugln("dropping outbound packet")
  67. }
  68. }
  69. }
  70. func (f *Interface) consumeInsidePacket(packet []byte, fwPacket *firewall.Packet, nb, out []byte, q int, localCache firewall.ConntrackCache) {
  71. err := newPacket(packet, false, fwPacket)
  72. if err != nil {
  73. if f.l.Level >= logrus.DebugLevel {
  74. f.l.WithField("packet", packet).Debugf("Error while validating outbound packet: %s", err)
  75. }
  76. return
  77. }
  78. // Ignore local broadcast packets
  79. if f.dropLocalBroadcast {
  80. if f.myBroadcastAddrsTable.Contains(fwPacket.RemoteAddr) {
  81. return
  82. }
  83. }
  84. if f.myVpnAddrsTable.Contains(fwPacket.RemoteAddr) {
  85. // Immediately forward packets from self to self.
  86. // This should only happen on Darwin-based and FreeBSD hosts, which
  87. // routes packets from the Nebula addr to the Nebula addr through the Nebula
  88. // TUN device.
  89. if immediatelyForwardToSelf {
  90. _, err := f.readers[q].Write(packet)
  91. if err != nil {
  92. f.l.WithError(err).Error("Failed to forward to tun")
  93. }
  94. }
  95. // Otherwise, drop. On linux, we should never see these packets - Linux
  96. // routes packets from the nebula addr to the nebula addr through the loopback device.
  97. return
  98. }
  99. // Ignore multicast packets
  100. if f.dropMulticast && fwPacket.RemoteAddr.IsMulticast() {
  101. return
  102. }
  103. hostinfo, ready := f.getOrHandshakeConsiderRouting(fwPacket, func(hh *HandshakeHostInfo) {
  104. hh.cachePacket(f.l, header.Message, 0, packet, f.sendMessageNow, f.cachedPacketMetrics)
  105. })
  106. if hostinfo == nil {
  107. f.rejectInside(packet, out, q)
  108. if f.l.Level >= logrus.DebugLevel {
  109. f.l.WithField("vpnAddr", fwPacket.RemoteAddr).
  110. WithField("fwPacket", fwPacket).
  111. Debugln("dropping outbound packet, vpnAddr not in our vpn networks or in unsafe networks")
  112. }
  113. return
  114. }
  115. if !ready {
  116. return
  117. }
  118. dropReason := f.firewall.Drop(*fwPacket, false, hostinfo, f.pki.GetCAPool(), localCache)
  119. if dropReason == nil {
  120. f.sendNoMetrics(header.Message, 0, hostinfo.ConnectionState, hostinfo, netip.AddrPort{}, packet, nb, out, q)
  121. } else {
  122. f.rejectInside(packet, out, q)
  123. if f.l.Level >= logrus.DebugLevel {
  124. hostinfo.logger(f.l).
  125. WithField("fwPacket", fwPacket).
  126. WithField("reason", dropReason).
  127. Debugln("dropping outbound packet")
  128. }
  129. }
  130. }
  131. func (f *Interface) rejectInside(packet []byte, out []byte, q int) {
  132. if !f.firewall.InSendReject {
  133. return
  134. }
  135. out = iputil.CreateRejectPacket(packet, out)
  136. if len(out) == 0 {
  137. return
  138. }
  139. _, err := f.readers[q].Write(out)
  140. if err != nil {
  141. f.l.WithError(err).Error("Failed to write to tun")
  142. }
  143. }
  144. func (f *Interface) rejectOutside(packet []byte, ci *ConnectionState, hostinfo *HostInfo, nb, out []byte, q int) {
  145. if !f.firewall.OutSendReject {
  146. return
  147. }
  148. out = iputil.CreateRejectPacket(packet, out)
  149. if len(out) == 0 {
  150. return
  151. }
  152. if len(out) > iputil.MaxRejectPacketSize {
  153. if f.l.GetLevel() >= logrus.InfoLevel {
  154. f.l.
  155. WithField("packet", packet).
  156. WithField("outPacket", out).
  157. Info("rejectOutside: packet too big, not sending")
  158. }
  159. return
  160. }
  161. f.sendNoMetrics(header.Message, 0, ci, hostinfo, netip.AddrPort{}, out, nb, packet, q)
  162. }
  163. // Handshake will attempt to initiate a tunnel with the provided vpn address. This is a no-op if the tunnel is already established or being established
  164. // it does not check if it is within our vpn networks!
  165. func (f *Interface) Handshake(vpnAddr netip.Addr) {
  166. f.handshakeManager.GetOrHandshake(vpnAddr, nil)
  167. }
  168. // getOrHandshakeNoRouting returns nil if the vpnAddr is not routable.
  169. // If the 2nd return var is false then the hostinfo is not ready to be used in a tunnel
  170. func (f *Interface) getOrHandshakeNoRouting(vpnAddr netip.Addr, cacheCallback func(*HandshakeHostInfo)) (*HostInfo, bool) {
  171. if f.myVpnNetworksTable.Contains(vpnAddr) {
  172. return f.handshakeManager.GetOrHandshake(vpnAddr, cacheCallback)
  173. }
  174. return nil, false
  175. }
  176. // getOrHandshakeConsiderRouting will try to find the HostInfo to handle this packet, starting a handshake if necessary.
  177. // If the 2nd return var is false then the hostinfo is not ready to be used in a tunnel.
  178. func (f *Interface) getOrHandshakeConsiderRouting(fwPacket *firewall.Packet, cacheCallback func(*HandshakeHostInfo)) (*HostInfo, bool) {
  179. destinationAddr := fwPacket.RemoteAddr
  180. hostinfo, ready := f.getOrHandshakeNoRouting(destinationAddr, cacheCallback)
  181. // Host is inside the mesh, no routing required
  182. if hostinfo != nil {
  183. return hostinfo, ready
  184. }
  185. gateways := f.inside.RoutesFor(destinationAddr)
  186. switch len(gateways) {
  187. case 0:
  188. return nil, false
  189. case 1:
  190. // Single gateway route
  191. return f.handshakeManager.GetOrHandshake(gateways[0].Addr(), cacheCallback)
  192. default:
  193. // Multi gateway route, perform ECMP categorization
  194. gatewayAddr, balancingOk := routing.BalancePacket(fwPacket, gateways)
  195. if !balancingOk {
  196. // This happens if the gateway buckets were not calculated, this _should_ never happen
  197. f.l.Error("Gateway buckets not calculated, fallback from ECMP to random routing. Please report this bug.")
  198. }
  199. var handshakeInfoForChosenGateway *HandshakeHostInfo
  200. var hhReceiver = func(hh *HandshakeHostInfo) {
  201. handshakeInfoForChosenGateway = hh
  202. }
  203. // Store the handshakeHostInfo for later.
  204. // If this node is not reachable we will attempt other nodes, if none are reachable we will
  205. // cache the packet for this gateway.
  206. if hostinfo, ready = f.handshakeManager.GetOrHandshake(gatewayAddr, hhReceiver); ready {
  207. return hostinfo, true
  208. }
  209. // It appears the selected gateway cannot be reached, find another gateway to fallback on.
  210. // The current implementation breaks ECMP but that seems better than no connectivity.
  211. // If ECMP is also required when a gateway is down then connectivity status
  212. // for each gateway needs to be kept and the weights recalculated when they go up or down.
  213. // This would also need to interact with unsafe_route updates through reloading the config or
  214. // use of the use_system_route_table option
  215. if f.l.Level >= logrus.DebugLevel {
  216. f.l.WithField("destination", destinationAddr).
  217. WithField("originalGateway", gatewayAddr).
  218. Debugln("Calculated gateway for ECMP not available, attempting other gateways")
  219. }
  220. for i := range gateways {
  221. // Skip the gateway that failed previously
  222. if gateways[i].Addr() == gatewayAddr {
  223. continue
  224. }
  225. // We do not need the HandshakeHostInfo since we cache the packet in the originally chosen gateway
  226. if hostinfo, ready = f.handshakeManager.GetOrHandshake(gateways[i].Addr(), nil); ready {
  227. return hostinfo, true
  228. }
  229. }
  230. // No gateways reachable, cache the packet in the originally chosen gateway
  231. cacheCallback(handshakeInfoForChosenGateway)
  232. return hostinfo, false
  233. }
  234. }
  235. func (f *Interface) sendMessageNow(t header.MessageType, st header.MessageSubType, hostinfo *HostInfo, p, nb, out []byte) {
  236. fp := &firewall.Packet{}
  237. err := newPacket(p, false, fp)
  238. if err != nil {
  239. f.l.Warnf("error while parsing outgoing packet for firewall check; %v", err)
  240. return
  241. }
  242. // check if packet is in outbound fw rules
  243. dropReason := f.firewall.Drop(*fp, false, hostinfo, f.pki.GetCAPool(), nil)
  244. if dropReason != nil {
  245. if f.l.Level >= logrus.DebugLevel {
  246. f.l.WithField("fwPacket", fp).
  247. WithField("reason", dropReason).
  248. Debugln("dropping cached packet")
  249. }
  250. return
  251. }
  252. f.sendNoMetrics(header.Message, st, hostinfo.ConnectionState, hostinfo, netip.AddrPort{}, p, nb, out, 0)
  253. }
  254. // SendMessageToVpnAddr handles real addr:port lookup and sends to the current best known address for vpnAddr.
  255. // This function ignores myVpnNetworksTable, and will always attempt to treat the address as a vpnAddr
  256. func (f *Interface) SendMessageToVpnAddr(t header.MessageType, st header.MessageSubType, vpnAddr netip.Addr, p, nb, out []byte) {
  257. hostInfo, ready := f.handshakeManager.GetOrHandshake(vpnAddr, func(hh *HandshakeHostInfo) {
  258. hh.cachePacket(f.l, t, st, p, f.SendMessageToHostInfo, f.cachedPacketMetrics)
  259. })
  260. if hostInfo == nil {
  261. if f.l.Level >= logrus.DebugLevel {
  262. f.l.WithField("vpnAddr", vpnAddr).
  263. Debugln("dropping SendMessageToVpnAddr, vpnAddr not in our vpn networks or in unsafe routes")
  264. }
  265. return
  266. }
  267. if !ready {
  268. return
  269. }
  270. f.SendMessageToHostInfo(t, st, hostInfo, p, nb, out)
  271. }
  272. func (f *Interface) SendMessageToHostInfo(t header.MessageType, st header.MessageSubType, hi *HostInfo, p, nb, out []byte) {
  273. f.send(t, st, hi.ConnectionState, hi, p, nb, out)
  274. }
  275. func (f *Interface) send(t header.MessageType, st header.MessageSubType, ci *ConnectionState, hostinfo *HostInfo, p, nb, out []byte) {
  276. f.messageMetrics.Tx(t, st, 1)
  277. f.sendNoMetrics(t, st, ci, hostinfo, netip.AddrPort{}, p, nb, out, 0)
  278. }
  279. func (f *Interface) sendTo(t header.MessageType, st header.MessageSubType, ci *ConnectionState, hostinfo *HostInfo, remote netip.AddrPort, p, nb, out []byte) {
  280. f.messageMetrics.Tx(t, st, 1)
  281. f.sendNoMetrics(t, st, ci, hostinfo, remote, p, nb, out, 0)
  282. }
  283. // SendVia sends a payload through a Relay tunnel. No authentication or encryption is done
  284. // to the payload for the ultimate target host, making this a useful method for sending
  285. // handshake messages to peers through relay tunnels.
  286. // via is the HostInfo through which the message is relayed.
  287. // ad is the plaintext data to authenticate, but not encrypt
  288. // nb is a buffer used to store the nonce value, re-used for performance reasons.
  289. // out is a buffer used to store the result of the Encrypt operation
  290. // q indicates which writer to use to send the packet.
  291. func (f *Interface) SendVia(via *HostInfo,
  292. relay *Relay,
  293. ad,
  294. nb,
  295. out []byte,
  296. nocopy bool,
  297. ) {
  298. if noiseutil.EncryptLockNeeded {
  299. // NOTE: for goboring AESGCMTLS we need to lock because of the nonce check
  300. via.ConnectionState.writeLock.Lock()
  301. }
  302. c := via.ConnectionState.messageCounter.Add(1)
  303. out = header.Encode(out, header.Version, header.Message, header.MessageRelay, relay.RemoteIndex, c)
  304. f.connectionManager.Out(via)
  305. // Authenticate the header and payload, but do not encrypt for this message type.
  306. // The payload consists of the inner, unencrypted Nebula header, as well as the end-to-end encrypted payload.
  307. if len(out)+len(ad)+via.ConnectionState.eKey.Overhead() > cap(out) {
  308. if noiseutil.EncryptLockNeeded {
  309. via.ConnectionState.writeLock.Unlock()
  310. }
  311. via.logger(f.l).
  312. WithField("outCap", cap(out)).
  313. WithField("payloadLen", len(ad)).
  314. WithField("headerLen", len(out)).
  315. WithField("cipherOverhead", via.ConnectionState.eKey.Overhead()).
  316. Error("SendVia out buffer not large enough for relay")
  317. return
  318. }
  319. // The header bytes are written to the 'out' slice; Grow the slice to hold the header and associated data payload.
  320. offset := len(out)
  321. out = out[:offset+len(ad)]
  322. // In one call path, the associated data _is_ already stored in out. In other call paths, the associated data must
  323. // be copied into 'out'.
  324. if !nocopy {
  325. copy(out[offset:], ad)
  326. }
  327. var err error
  328. out, err = via.ConnectionState.eKey.EncryptDanger(out, out, nil, c, nb)
  329. if noiseutil.EncryptLockNeeded {
  330. via.ConnectionState.writeLock.Unlock()
  331. }
  332. if err != nil {
  333. via.logger(f.l).WithError(err).Info("Failed to EncryptDanger in sendVia")
  334. return
  335. }
  336. err = f.writers[0].WriteTo(out, via.remote)
  337. if err != nil {
  338. via.logger(f.l).WithError(err).Info("Failed to WriteTo in sendVia")
  339. }
  340. f.connectionManager.RelayUsed(relay.LocalIndex)
  341. }
  342. func (f *Interface) sendNoMetrics(t header.MessageType, st header.MessageSubType, ci *ConnectionState, hostinfo *HostInfo, remote netip.AddrPort, p, nb, out []byte, q int) {
  343. if ci.eKey == nil {
  344. return
  345. }
  346. useRelay := !remote.IsValid() && !hostinfo.remote.IsValid()
  347. fullOut := out
  348. if useRelay {
  349. if len(out) < header.Len {
  350. // out always has a capacity of mtu, but not always a length greater than the header.Len.
  351. // Grow it to make sure the next operation works.
  352. out = out[:header.Len]
  353. }
  354. // Save a header's worth of data at the front of the 'out' buffer.
  355. out = out[header.Len:]
  356. }
  357. if noiseutil.EncryptLockNeeded {
  358. // NOTE: for goboring AESGCMTLS we need to lock because of the nonce check
  359. ci.writeLock.Lock()
  360. }
  361. c := ci.messageCounter.Add(1)
  362. //l.WithField("trace", string(debug.Stack())).Error("out Header ", &Header{Version, t, st, 0, hostinfo.remoteIndexId, c}, p)
  363. out = header.Encode(out, header.Version, t, st, hostinfo.remoteIndexId, c)
  364. f.connectionManager.Out(hostinfo)
  365. // Query our LH if we haven't since the last time we've been rebound, this will cause the remote to punch against
  366. // all our addrs and enable a faster roaming.
  367. if t != header.CloseTunnel && hostinfo.lastRebindCount != f.rebindCount {
  368. //NOTE: there is an update hole if a tunnel isn't used and exactly 256 rebinds occur before the tunnel is
  369. // finally used again. This tunnel would eventually be torn down and recreated if this action didn't help.
  370. f.lightHouse.QueryServer(hostinfo.vpnAddrs[0])
  371. hostinfo.lastRebindCount = f.rebindCount
  372. if f.l.Level >= logrus.DebugLevel {
  373. f.l.WithField("vpnAddrs", hostinfo.vpnAddrs).Debug("Lighthouse update triggered for punch due to rebind counter")
  374. }
  375. }
  376. var err error
  377. out, err = ci.eKey.EncryptDanger(out, out, p, c, nb)
  378. if noiseutil.EncryptLockNeeded {
  379. ci.writeLock.Unlock()
  380. }
  381. if err != nil {
  382. hostinfo.logger(f.l).WithError(err).
  383. WithField("udpAddr", remote).WithField("counter", c).
  384. WithField("attemptedCounter", c).
  385. Error("Failed to encrypt outgoing packet")
  386. return
  387. }
  388. if remote.IsValid() {
  389. err = f.writers[q].WriteTo(out, remote)
  390. if err != nil {
  391. hostinfo.logger(f.l).WithError(err).
  392. WithField("udpAddr", remote).Error("Failed to write outgoing packet")
  393. }
  394. } else if hostinfo.remote.IsValid() {
  395. err = f.writers[q].WriteTo(out, hostinfo.remote)
  396. if err != nil {
  397. hostinfo.logger(f.l).WithError(err).
  398. WithField("udpAddr", remote).Error("Failed to write outgoing packet")
  399. }
  400. } else {
  401. // Try to send via a relay
  402. for _, relayIP := range hostinfo.relayState.CopyRelayIps() {
  403. relayHostInfo, relay, err := f.hostMap.QueryVpnAddrsRelayFor(hostinfo.vpnAddrs, relayIP)
  404. if err != nil {
  405. hostinfo.relayState.DeleteRelay(relayIP)
  406. hostinfo.logger(f.l).WithField("relay", relayIP).WithError(err).Info("sendNoMetrics failed to find HostInfo")
  407. continue
  408. }
  409. f.SendVia(relayHostInfo, relay, out, nb, fullOut[:header.Len+len(out)], true)
  410. break
  411. }
  412. }
  413. }
  414. // sendNoMetricsBatched is like sendNoMetrics but queues the packet for batched sending
  415. // instead of sending immediately. The caller must flush pendingPackets with WriteBatch.
  416. func (f *Interface) sendNoMetricsBatched(t header.MessageType, st header.MessageSubType, ci *ConnectionState, hostinfo *HostInfo, remote netip.AddrPort, p, nb, out []byte, q int, pendingPackets *[]udp.BatchPacket) {
  417. if ci.eKey == nil {
  418. return
  419. }
  420. useRelay := !remote.IsValid() && !hostinfo.remote.IsValid()
  421. fullOut := out
  422. if useRelay {
  423. if len(out) < header.Len {
  424. out = out[:header.Len]
  425. }
  426. out = out[header.Len:]
  427. }
  428. if noiseutil.EncryptLockNeeded {
  429. ci.writeLock.Lock()
  430. }
  431. c := ci.messageCounter.Add(1)
  432. out = header.Encode(out, header.Version, t, st, hostinfo.remoteIndexId, c)
  433. f.connectionManager.Out(hostinfo)
  434. if t != header.CloseTunnel && hostinfo.lastRebindCount != f.rebindCount {
  435. f.lightHouse.QueryServer(hostinfo.vpnAddrs[0])
  436. hostinfo.lastRebindCount = f.rebindCount
  437. if f.l.Level >= logrus.DebugLevel {
  438. f.l.WithField("vpnAddrs", hostinfo.vpnAddrs).Debug("Lighthouse update triggered for punch due to rebind counter")
  439. }
  440. }
  441. var err error
  442. out, err = ci.eKey.EncryptDanger(out, out, p, c, nb)
  443. if noiseutil.EncryptLockNeeded {
  444. ci.writeLock.Unlock()
  445. }
  446. if err != nil {
  447. hostinfo.logger(f.l).WithError(err).
  448. WithField("udpAddr", remote).WithField("counter", c).
  449. WithField("attemptedCounter", c).
  450. Error("Failed to encrypt outgoing packet")
  451. return
  452. }
  453. // Queue the packet for batched sending
  454. var addr netip.AddrPort
  455. if remote.IsValid() {
  456. addr = remote
  457. } else if hostinfo.remote.IsValid() {
  458. addr = hostinfo.remote
  459. } else {
  460. // Relay path - send immediately, not batched
  461. for _, relayIP := range hostinfo.relayState.CopyRelayIps() {
  462. relayHostInfo, relay, err := f.hostMap.QueryVpnAddrsRelayFor(hostinfo.vpnAddrs, relayIP)
  463. if err != nil {
  464. hostinfo.relayState.DeleteRelay(relayIP)
  465. hostinfo.logger(f.l).WithField("relay", relayIP).WithError(err).Info("sendNoMetricsBatched failed to find HostInfo")
  466. continue
  467. }
  468. f.SendVia(relayHostInfo, relay, out, nb, fullOut[:header.Len+len(out)], true)
  469. break
  470. }
  471. return
  472. }
  473. // Copy the payload since the buffer will be reused
  474. payload := make([]byte, len(out))
  475. copy(payload, out)
  476. *pendingPackets = append(*pendingPackets, udp.BatchPacket{Payload: payload, Addr: addr})
  477. }