udp.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. /*
  2. * Copyright (c) 2016, Psiphon Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. package server
  20. import (
  21. "bytes"
  22. "encoding/binary"
  23. "fmt"
  24. "io"
  25. "net"
  26. "strconv"
  27. "sync"
  28. "sync/atomic"
  29. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
  30. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/crypto/ssh"
  31. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/errors"
  32. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/monotime"
  33. )
  34. // handleUdpgwChannel implements UDP port forwarding. A single UDP
  35. // SSH channel follows the udpgw protocol, which multiplexes many
  36. // UDP port forwards.
  37. //
  38. // The udpgw protocol and original server implementation:
  39. // Copyright (c) 2009, Ambroz Bizjak <ambrop7@gmail.com>
  40. // https://github.com/ambrop72/badvpn
  41. //
  42. func (sshClient *sshClient) handleUdpgwChannel(newChannel ssh.NewChannel) {
  43. // Accept this channel immediately. This channel will replace any
  44. // previously existing udpgw channel for this client.
  45. sshChannel, requests, err := newChannel.Accept()
  46. if err != nil {
  47. if !isExpectedTunnelIOError(err) {
  48. log.WithTraceFields(LogFields{"error": err}).Warning("accept new channel failed")
  49. }
  50. return
  51. }
  52. go ssh.DiscardRequests(requests)
  53. defer sshChannel.Close()
  54. multiplexer := &udpgwPortForwardMultiplexer{
  55. sshClient: sshClient,
  56. sshChannel: sshChannel,
  57. portForwards: make(map[uint16]*udpgwPortForward),
  58. portForwardLRU: common.NewLRUConns(),
  59. relayWaitGroup: new(sync.WaitGroup),
  60. runWaitGroup: new(sync.WaitGroup),
  61. }
  62. multiplexer.runWaitGroup.Add(1)
  63. // setUdpgwChannelHandler will close any existing
  64. // udpgwPortForwardMultiplexer, waiting for all run/relayDownstream
  65. // goroutines to first terminate and all UDP socket resources to be
  66. // cleaned up.
  67. //
  68. // This synchronous shutdown also ensures that the
  69. // concurrentPortForwardCount is reduced to 0 before installing the new
  70. // udpgwPortForwardMultiplexer and its LRU object. If the older handler
  71. // were to dangle with open port forwards, and concurrentPortForwardCount
  72. // were to hit the max, the wrong LRU, the new one, would be used to
  73. // close the LRU port forward.
  74. //
  75. // Call setUdpgwHandler only after runWaitGroup is initialized, to ensure
  76. // runWaitGroup.Wait() cannot be invoked (by some subsequent new udpgw
  77. // channel) before initialized.
  78. if !sshClient.setUdpgwChannelHandler(multiplexer) {
  79. // setUdpgwChannelHandler returns false if some other SSH channel
  80. // calls setUdpgwChannelHandler in the middle of this call. In that
  81. // case, discard this channel: the client's latest udpgw channel is
  82. // retained.
  83. return
  84. }
  85. multiplexer.run()
  86. multiplexer.runWaitGroup.Done()
  87. }
  88. type udpgwPortForwardMultiplexer struct {
  89. sshClient *sshClient
  90. sshChannelWriteMutex sync.Mutex
  91. sshChannel ssh.Channel
  92. portForwardsMutex sync.Mutex
  93. portForwards map[uint16]*udpgwPortForward
  94. portForwardLRU *common.LRUConns
  95. relayWaitGroup *sync.WaitGroup
  96. runWaitGroup *sync.WaitGroup
  97. }
  98. func (mux *udpgwPortForwardMultiplexer) stop() {
  99. // udpgwPortForwardMultiplexer must be initialized by handleUdpgwChannel.
  100. //
  101. // stop closes the udpgw SSH channel, which will cause the run goroutine
  102. // to exit its message read loop and await closure of all relayDownstream
  103. // goroutines. Closing all port forward UDP conns will cause all
  104. // relayDownstream to exit.
  105. _ = mux.sshChannel.Close()
  106. mux.portForwardsMutex.Lock()
  107. for _, portForward := range mux.portForwards {
  108. _ = portForward.conn.Close()
  109. }
  110. mux.portForwardsMutex.Unlock()
  111. mux.runWaitGroup.Wait()
  112. }
  113. func (mux *udpgwPortForwardMultiplexer) run() {
  114. // In a loop, read udpgw messages from the client to this channel. Each
  115. // message contains a UDP packet to send upstream either via a new port
  116. // forward, or on an existing port forward.
  117. //
  118. // A goroutine is run to read downstream packets for each UDP port forward. All read
  119. // packets are encapsulated in udpgw protocol and sent down the channel to the client.
  120. //
  121. // When the client disconnects or the server shuts down, the channel will close and
  122. // readUdpgwMessage will exit with EOF.
  123. buffer := make([]byte, udpgwProtocolMaxMessageSize)
  124. for {
  125. // Note: message.packet points to the reusable memory in "buffer".
  126. // Each readUdpgwMessage call will overwrite the last message.packet.
  127. message, err := readUdpgwMessage(mux.sshChannel, buffer)
  128. if err != nil {
  129. if err != io.EOF {
  130. // Debug since I/O errors occur during normal operation
  131. log.WithTraceFields(LogFields{"error": err}).Debug("readUdpgwMessage failed")
  132. }
  133. break
  134. }
  135. mux.portForwardsMutex.Lock()
  136. portForward := mux.portForwards[message.connID]
  137. mux.portForwardsMutex.Unlock()
  138. // In the udpgw protocol, an existing port forward is closed when
  139. // either the discard flag is set or the remote address has changed.
  140. if portForward != nil &&
  141. (message.discardExistingConn ||
  142. !bytes.Equal(portForward.remoteIP, message.remoteIP) ||
  143. portForward.remotePort != message.remotePort) {
  144. // The port forward's goroutine will complete cleanup, including
  145. // tallying stats and calling sshClient.closedPortForward.
  146. // portForward.conn.Close() will signal this shutdown.
  147. portForward.conn.Close()
  148. // Synchronously await the termination of the relayDownstream
  149. // goroutine. This ensures that the previous goroutine won't
  150. // invoke removePortForward, with the connID that will be reused
  151. // for the new port forward, after this point.
  152. //
  153. // Limitation: this synchronous shutdown cannot prevent a "wrong
  154. // remote address" error on the badvpn udpgw client, which occurs
  155. // when the client recycles a port forward (setting discard) but
  156. // receives, from the server, a udpgw message containing the old
  157. // remote address for the previous port forward with the same
  158. // conn ID. That downstream message from the server may be in
  159. // flight in the SSH channel when the client discard message arrives.
  160. portForward.relayWaitGroup.Wait()
  161. portForward = nil
  162. }
  163. if portForward == nil {
  164. // Create a new port forward
  165. dialIP := net.IP(message.remoteIP)
  166. dialPort := int(message.remotePort)
  167. // Validate DNS packets and check the domain blocklist both when the client
  168. // indicates DNS or when DNS is _not_ indicated and the destination port is
  169. // 53.
  170. if message.forwardDNS || message.remotePort == 53 {
  171. domain, err := common.ParseDNSQuestion(message.packet)
  172. if err != nil {
  173. log.WithTraceFields(LogFields{"error": err}).Debug("ParseDNSQuestion failed")
  174. // Drop packet
  175. continue
  176. }
  177. if domain != "" {
  178. ok, _ := mux.sshClient.isDomainPermitted(domain)
  179. if !ok {
  180. // Drop packet
  181. continue
  182. }
  183. }
  184. }
  185. if message.forwardDNS {
  186. // Transparent DNS forwarding. In this case, isPortForwardPermitted
  187. // traffic rules checks are bypassed, since DNS is essential.
  188. dialIP = mux.sshClient.sshServer.support.DNSResolver.Get()
  189. dialPort = DNS_RESOLVER_PORT
  190. } else if !mux.sshClient.isPortForwardPermitted(
  191. portForwardTypeUDP, dialIP, int(message.remotePort)) {
  192. // The udpgw protocol has no error response, so
  193. // we just discard the message and read another.
  194. continue
  195. }
  196. // Note: UDP port forward counting has no dialing phase
  197. // establishedPortForward increments the concurrent UDP port
  198. // forward counter and closes the LRU existing UDP port forward
  199. // when already at the limit.
  200. mux.sshClient.establishedPortForward(portForwardTypeUDP, mux.portForwardLRU)
  201. // Can't defer sshClient.closedPortForward() here;
  202. // relayDownstream will call sshClient.closedPortForward()
  203. // Pre-check log level to avoid overhead of rendering log for
  204. // every DNS query and other UDP port forward.
  205. if IsLogLevelDebug() {
  206. log.WithTraceFields(
  207. LogFields{
  208. "remoteAddr": net.JoinHostPort(dialIP.String(), strconv.Itoa(dialPort)),
  209. "connID": message.connID}).Debug("dialing")
  210. }
  211. udpConn, err := net.DialUDP(
  212. "udp", nil, &net.UDPAddr{IP: dialIP, Port: dialPort})
  213. if err != nil {
  214. mux.sshClient.closedPortForward(portForwardTypeUDP, 0, 0)
  215. // Monitor for low resource error conditions
  216. mux.sshClient.sshServer.monitorPortForwardDialError(err)
  217. // Note: Debug level, as logMessage may contain user traffic destination address information
  218. log.WithTraceFields(LogFields{"error": err}).Debug("DialUDP failed")
  219. continue
  220. }
  221. lruEntry := mux.portForwardLRU.Add(udpConn)
  222. // Can't defer lruEntry.Remove() here;
  223. // relayDownstream will call lruEntry.Remove()
  224. // ActivityMonitoredConn monitors the TCP port forward I/O and updates
  225. // its LRU status. ActivityMonitoredConn also times out I/O on the port
  226. // forward if both reads and writes have been idle for the specified
  227. // duration.
  228. var activityUpdaters []common.ActivityUpdater
  229. // Don't incur activity monitor overhead for DNS requests
  230. if !message.forwardDNS {
  231. activityUpdaters = mux.sshClient.getActivityUpdaters(portForwardTypeUDP, dialIP)
  232. }
  233. conn, err := common.NewActivityMonitoredConn(
  234. udpConn,
  235. mux.sshClient.idleUDPPortForwardTimeout(),
  236. true,
  237. lruEntry,
  238. activityUpdaters...)
  239. if err != nil {
  240. lruEntry.Remove()
  241. mux.sshClient.closedPortForward(portForwardTypeUDP, 0, 0)
  242. log.WithTraceFields(LogFields{"error": err}).Error("NewActivityMonitoredConn failed")
  243. continue
  244. }
  245. portForward = &udpgwPortForward{
  246. connID: message.connID,
  247. preambleSize: message.preambleSize,
  248. remoteIP: message.remoteIP,
  249. remotePort: message.remotePort,
  250. dialIP: dialIP,
  251. conn: conn,
  252. lruEntry: lruEntry,
  253. bytesUp: 0,
  254. bytesDown: 0,
  255. relayWaitGroup: new(sync.WaitGroup),
  256. mux: mux,
  257. }
  258. if message.forwardDNS {
  259. portForward.dnsFirstWriteTime = int64(monotime.Now())
  260. }
  261. mux.portForwardsMutex.Lock()
  262. mux.portForwards[portForward.connID] = portForward
  263. mux.portForwardsMutex.Unlock()
  264. portForward.relayWaitGroup.Add(1)
  265. mux.relayWaitGroup.Add(1)
  266. go portForward.relayDownstream()
  267. }
  268. // Note: assumes UDP writes won't block (https://golang.org/pkg/net/#UDPConn.WriteToUDP)
  269. _, err = portForward.conn.Write(message.packet)
  270. if err != nil {
  271. // Debug since errors such as "write: operation not permitted" occur during normal operation
  272. log.WithTraceFields(LogFields{"error": err}).Debug("upstream UDP relay failed")
  273. // The port forward's goroutine will complete cleanup
  274. portForward.conn.Close()
  275. }
  276. portForward.lruEntry.Touch()
  277. atomic.AddInt64(&portForward.bytesUp, int64(len(message.packet)))
  278. }
  279. // Cleanup all udpgw port forward workers when exiting
  280. mux.portForwardsMutex.Lock()
  281. for _, portForward := range mux.portForwards {
  282. // The port forward's goroutine will complete cleanup
  283. portForward.conn.Close()
  284. }
  285. mux.portForwardsMutex.Unlock()
  286. mux.relayWaitGroup.Wait()
  287. }
  288. func (mux *udpgwPortForwardMultiplexer) removePortForward(connID uint16) {
  289. mux.portForwardsMutex.Lock()
  290. delete(mux.portForwards, connID)
  291. mux.portForwardsMutex.Unlock()
  292. }
  293. type udpgwPortForward struct {
  294. // Note: 64-bit ints used with atomic operations are placed
  295. // at the start of struct to ensure 64-bit alignment.
  296. // (https://golang.org/pkg/sync/atomic/#pkg-note-BUG)
  297. dnsFirstWriteTime int64
  298. dnsFirstReadTime int64
  299. bytesUp int64
  300. bytesDown int64
  301. connID uint16
  302. preambleSize int
  303. remoteIP []byte
  304. remotePort uint16
  305. dialIP net.IP
  306. conn net.Conn
  307. lruEntry *common.LRUConnsEntry
  308. relayWaitGroup *sync.WaitGroup
  309. mux *udpgwPortForwardMultiplexer
  310. }
  311. func (portForward *udpgwPortForward) relayDownstream() {
  312. defer portForward.relayWaitGroup.Done()
  313. defer portForward.mux.relayWaitGroup.Done()
  314. // Downstream UDP packets are read into the reusable memory
  315. // in "buffer" starting at the offset past the udpgw message
  316. // header and address, leaving enough space to write the udpgw
  317. // values into the same buffer and use for writing to the ssh
  318. // channel.
  319. //
  320. // Note: there is one downstream buffer per UDP port forward,
  321. // while for upstream there is one buffer per client.
  322. // TODO: is the buffer size larger than necessary?
  323. buffer := make([]byte, udpgwProtocolMaxMessageSize)
  324. packetBuffer := buffer[portForward.preambleSize:udpgwProtocolMaxMessageSize]
  325. for {
  326. // TODO: if read buffer is too small, excess bytes are discarded?
  327. packetSize, err := portForward.conn.Read(packetBuffer)
  328. if packetSize > udpgwProtocolMaxPayloadSize {
  329. err = fmt.Errorf("unexpected packet size: %d", packetSize)
  330. }
  331. if err != nil {
  332. if err != io.EOF {
  333. // Debug since errors such as "use of closed network connection" occur during normal operation
  334. log.WithTraceFields(LogFields{"error": err}).Debug("downstream UDP relay failed")
  335. }
  336. break
  337. }
  338. if atomic.LoadInt64(&portForward.dnsFirstWriteTime) > 0 &&
  339. atomic.LoadInt64(&portForward.dnsFirstReadTime) == 0 { // Check if already set before invoking Now.
  340. atomic.CompareAndSwapInt64(&portForward.dnsFirstReadTime, 0, int64(monotime.Now()))
  341. }
  342. err = writeUdpgwPreamble(
  343. portForward.preambleSize,
  344. 0,
  345. portForward.connID,
  346. portForward.remoteIP,
  347. portForward.remotePort,
  348. uint16(packetSize),
  349. buffer)
  350. if err == nil {
  351. // ssh.Channel.Write cannot be called concurrently.
  352. // See: https://github.com/Psiphon-Inc/crypto/blob/82d98b4c7c05e81f92545f6fddb45d4541e6da00/ssh/channel.go#L272,
  353. // https://codereview.appspot.com/136420043/diff/80002/ssh/channel.go
  354. portForward.mux.sshChannelWriteMutex.Lock()
  355. _, err = portForward.mux.sshChannel.Write(buffer[0 : portForward.preambleSize+packetSize])
  356. portForward.mux.sshChannelWriteMutex.Unlock()
  357. }
  358. if err != nil {
  359. // Close the channel, which will interrupt the main loop.
  360. portForward.mux.sshChannel.Close()
  361. log.WithTraceFields(LogFields{"error": err}).Debug("downstream UDP relay failed")
  362. break
  363. }
  364. portForward.lruEntry.Touch()
  365. atomic.AddInt64(&portForward.bytesDown, int64(packetSize))
  366. }
  367. portForward.mux.removePortForward(portForward.connID)
  368. portForward.lruEntry.Remove()
  369. portForward.conn.Close()
  370. bytesUp := atomic.LoadInt64(&portForward.bytesUp)
  371. bytesDown := atomic.LoadInt64(&portForward.bytesDown)
  372. portForward.mux.sshClient.closedPortForward(portForwardTypeUDP, bytesUp, bytesDown)
  373. dnsStartTime := monotime.Time(atomic.LoadInt64(&portForward.dnsFirstWriteTime))
  374. if dnsStartTime > 0 {
  375. // Record DNS metrics using a heuristic: if a UDP packet was written and
  376. // then a packet was read, assume the DNS request successfully received a
  377. // valid response; failure occurs when the resolver fails to provide a
  378. // response; a "no such host" response is still a success. Limitations: we
  379. // assume a resolver will not respond when, e.g., rate limiting; we ignore
  380. // subsequent requests made via the same UDP port forward.
  381. dnsEndTime := monotime.Time(atomic.LoadInt64(&portForward.dnsFirstReadTime))
  382. dnsSuccess := true
  383. if dnsEndTime == 0 {
  384. dnsSuccess = false
  385. dnsEndTime = monotime.Now()
  386. }
  387. resolveElapsedTime := dnsEndTime.Sub(dnsStartTime)
  388. portForward.mux.sshClient.updateQualityMetricsWithDNSResult(
  389. dnsSuccess,
  390. resolveElapsedTime,
  391. net.IP(portForward.dialIP))
  392. }
  393. log.WithTraceFields(
  394. LogFields{
  395. "remoteAddr": net.JoinHostPort(
  396. net.IP(portForward.remoteIP).String(), strconv.Itoa(int(portForward.remotePort))),
  397. "bytesUp": bytesUp,
  398. "bytesDown": bytesDown,
  399. "connID": portForward.connID}).Debug("exiting")
  400. }
  401. // TODO: express and/or calculate udpgwProtocolMaxPayloadSize as function of MTU?
  402. const (
  403. udpgwProtocolFlagKeepalive = 1 << 0
  404. udpgwProtocolFlagRebind = 1 << 1
  405. udpgwProtocolFlagDNS = 1 << 2
  406. udpgwProtocolFlagIPv6 = 1 << 3
  407. udpgwProtocolMaxPreambleSize = 23
  408. udpgwProtocolMaxPayloadSize = 32768
  409. udpgwProtocolMaxMessageSize = udpgwProtocolMaxPreambleSize + udpgwProtocolMaxPayloadSize
  410. )
  411. type udpgwProtocolMessage struct {
  412. connID uint16
  413. preambleSize int
  414. remoteIP []byte
  415. remotePort uint16
  416. discardExistingConn bool
  417. forwardDNS bool
  418. packet []byte
  419. }
  420. func readUdpgwMessage(
  421. reader io.Reader, buffer []byte) (*udpgwProtocolMessage, error) {
  422. // udpgw message layout:
  423. //
  424. // | 2 byte size | 3 byte header | 6 or 18 byte address | variable length packet |
  425. for {
  426. // Read message
  427. _, err := io.ReadFull(reader, buffer[0:2])
  428. if err != nil {
  429. if err != io.EOF {
  430. err = errors.Trace(err)
  431. }
  432. return nil, err
  433. }
  434. size := binary.LittleEndian.Uint16(buffer[0:2])
  435. if size < 3 || int(size) > len(buffer)-2 {
  436. return nil, errors.TraceNew("invalid udpgw message size")
  437. }
  438. _, err = io.ReadFull(reader, buffer[2:2+size])
  439. if err != nil {
  440. if err != io.EOF {
  441. err = errors.Trace(err)
  442. }
  443. return nil, err
  444. }
  445. flags := buffer[2]
  446. connID := binary.LittleEndian.Uint16(buffer[3:5])
  447. // Ignore udpgw keep-alive messages -- read another message
  448. if flags&udpgwProtocolFlagKeepalive == udpgwProtocolFlagKeepalive {
  449. continue
  450. }
  451. // Read address
  452. var remoteIP []byte
  453. var remotePort uint16
  454. var packetStart, packetEnd int
  455. if flags&udpgwProtocolFlagIPv6 == udpgwProtocolFlagIPv6 {
  456. if size < 21 {
  457. return nil, errors.TraceNew("invalid udpgw message size")
  458. }
  459. remoteIP = make([]byte, 16)
  460. copy(remoteIP, buffer[5:21])
  461. remotePort = binary.BigEndian.Uint16(buffer[21:23])
  462. packetStart = 23
  463. packetEnd = 23 + int(size) - 21
  464. } else {
  465. if size < 9 {
  466. return nil, errors.TraceNew("invalid udpgw message size")
  467. }
  468. remoteIP = make([]byte, 4)
  469. copy(remoteIP, buffer[5:9])
  470. remotePort = binary.BigEndian.Uint16(buffer[9:11])
  471. packetStart = 11
  472. packetEnd = 11 + int(size) - 9
  473. }
  474. // Assemble message
  475. // Note: udpgwProtocolMessage.packet references memory in the input buffer
  476. message := &udpgwProtocolMessage{
  477. connID: connID,
  478. preambleSize: packetStart,
  479. remoteIP: remoteIP,
  480. remotePort: remotePort,
  481. discardExistingConn: flags&udpgwProtocolFlagRebind == udpgwProtocolFlagRebind,
  482. forwardDNS: flags&udpgwProtocolFlagDNS == udpgwProtocolFlagDNS,
  483. packet: buffer[packetStart:packetEnd],
  484. }
  485. return message, nil
  486. }
  487. }
  488. func writeUdpgwPreamble(
  489. preambleSize int,
  490. flags uint8,
  491. connID uint16,
  492. remoteIP []byte,
  493. remotePort uint16,
  494. packetSize uint16,
  495. buffer []byte) error {
  496. if preambleSize != 7+len(remoteIP) {
  497. return errors.TraceNew("invalid udpgw preamble size")
  498. }
  499. size := uint16(preambleSize-2) + packetSize
  500. // size
  501. binary.LittleEndian.PutUint16(buffer[0:2], size)
  502. // flags
  503. buffer[2] = flags
  504. // connID
  505. binary.LittleEndian.PutUint16(buffer[3:5], connID)
  506. // addr
  507. copy(buffer[5:5+len(remoteIP)], remoteIP)
  508. binary.BigEndian.PutUint16(buffer[5+len(remoteIP):7+len(remoteIP)], remotePort)
  509. return nil
  510. }