SocksUdpClient.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. /*
  2. * Copyright (C) 2018 Jigsaw Operations LLC
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. * 1. Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * 2. Redistributions in binary form must reproduce the above copyright
  9. * notice, this list of conditions and the following disclaimer in the
  10. * documentation and/or other materials provided with the distribution.
  11. * 3. Neither the name of the author nor the
  12. * names of its contributors may be used to endorse or promote products
  13. * derived from this software without specific prior written permission.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  19. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <misc/balloc.h>
  29. #include <misc/offset.h>
  30. #include <misc/byteorder.h>
  31. #include <misc/compare.h>
  32. #include <base/BLog.h>
  33. #include <socks_udp_client/SocksUdpClient.h>
  34. #include <generated/blog_channel_SocksUdpClient.h>
  35. #define DNS_PORT 53
  36. static int addr_comparator (void *unused, BAddr *v1, BAddr *v2);
  37. static struct SocksUdpClient_connection * find_connection_by_addr (SocksUdpClient *o, BAddr addr);
  38. static void init_localhost4(uint32_t *ip4);
  39. static void init_localhost6(uint8_t ip6[16]);
  40. static void socks_state_handler(struct SocksUdpClient_connection *con, int event);
  41. static void datagram_state_handler(struct SocksUdpClient_connection *con, int event);
  42. static void send_monitor_handler (struct SocksUdpClient_connection *con);
  43. static void recv_if_handler_send (struct SocksUdpClient_connection *con, uint8_t *data, int data_len);
  44. static struct SocksUdpClient_connection * connection_init(SocksUdpClient *o, BAddr local_addr,
  45. BAddr first_remote_addr,
  46. const uint8_t *first_data,
  47. int first_data_len);
  48. static void connection_free (struct SocksUdpClient_connection *con);
  49. static void connection_send (struct SocksUdpClient_connection *con, BAddr remote_addr, const uint8_t *data, int data_len);
  50. static void first_job_handler(struct SocksUdpClient_connection *con);
  51. static int compute_mtu(int udp_mtu);
  52. static int get_dns_id(BAddr *remote_addr, const uint8_t *data, int data_len);
  53. int addr_comparator (void *unused, BAddr *v1, BAddr *v2)
  54. {
  55. return BAddr_CompareOrder(v1, v2);
  56. }
  57. struct SocksUdpClient_connection * find_connection_by_addr (SocksUdpClient *o, BAddr addr)
  58. {
  59. BAVLNode *tree_node = BAVL_LookupExact(&o->connections_tree, &addr);
  60. if (!tree_node) {
  61. return NULL;
  62. }
  63. return UPPER_OBJECT(tree_node, struct SocksUdpClient_connection, connections_tree_node);
  64. }
  65. void init_localhost4(uint32_t *ip4)
  66. {
  67. *ip4 = 1<<24 | 127;
  68. }
  69. void init_localhost6(uint8_t ip6[16])
  70. {
  71. memset(ip6, 0, 16);
  72. ip6[15] = 1;
  73. }
  74. void socks_state_handler(struct SocksUdpClient_connection *con, int event)
  75. {
  76. switch (event) {
  77. case BSOCKSCLIENT_EVENT_UP: {
  78. BIPAddr localhost;
  79. localhost.type = con->client->server_addr.type;
  80. if (localhost.type == BADDR_TYPE_IPV4) {
  81. init_localhost4(&localhost.ipv4);
  82. } else if (localhost.type == BADDR_TYPE_IPV6) {
  83. init_localhost6(localhost.ipv6);
  84. } else {
  85. BLog(BLOG_ERROR, "Bad address type");
  86. }
  87. // This will unblock the queue of pending packets.
  88. BDatagram_SetSendAddrs(&con->socket, con->socks.bind_addr, localhost);
  89. } break;
  90. case BSOCKSCLIENT_EVENT_ERROR: {
  91. BLog(BLOG_ERROR, "Socks error event");
  92. } // Fallthrough
  93. case BSOCKSCLIENT_EVENT_ERROR_CLOSED: {
  94. connection_free(con);
  95. } break;
  96. default: {
  97. BLog(BLOG_ERROR, "Unknown event");
  98. }
  99. }
  100. }
  101. void datagram_state_handler(struct SocksUdpClient_connection *con, int event)
  102. {
  103. if (event == BDATAGRAM_EVENT_ERROR) {
  104. char local_buffer[BADDR_MAX_PRINT_LEN];
  105. BAddr_Print(&con->local_addr, local_buffer);
  106. BLog(BLOG_ERROR, "Failing connection for %s due to a datagram send error", local_buffer);
  107. connection_free(con);
  108. }
  109. }
  110. void send_monitor_handler (struct SocksUdpClient_connection *con)
  111. {
  112. // The connection has passed its idle timeout. Remove it.
  113. connection_free(con);
  114. }
  115. void recv_if_handler_send(struct SocksUdpClient_connection *con, uint8_t *data, int data_len)
  116. {
  117. SocksUdpClient *o = con->client;
  118. DebugObject_Access(&con->client->d_obj);
  119. ASSERT(data_len >= 0)
  120. ASSERT(data_len <= compute_mtu(o->udp_mtu))
  121. // accept packet
  122. PacketPassInterface_Done(&con->recv_if);
  123. // check header
  124. if (data_len < sizeof(struct socks_udp_header)) {
  125. BLog(BLOG_ERROR, "missing header");
  126. return;
  127. }
  128. struct socks_udp_header *header = (struct socks_udp_header *)data;
  129. uint8_t *addr_data = data + sizeof(struct socks_udp_header);
  130. // parse address
  131. BAddr remote_addr;
  132. size_t addr_size;
  133. switch (header->atyp) {
  134. case SOCKS_ATYP_IPV4: {
  135. remote_addr.type = BADDR_TYPE_IPV4;
  136. struct socks_addr_ipv4 *addr_ipv4 = (struct socks_addr_ipv4 *)addr_data;
  137. remote_addr.ipv4.ip = addr_ipv4->addr;
  138. remote_addr.ipv4.port = addr_ipv4->port;
  139. addr_size = sizeof(*addr_ipv4);
  140. } break;
  141. case SOCKS_ATYP_IPV6: {
  142. remote_addr.type = BADDR_TYPE_IPV6;
  143. struct socks_addr_ipv6 *addr_ipv6 = (struct socks_addr_ipv6 *)addr_data;
  144. memcpy(remote_addr.ipv6.ip, addr_ipv6->addr, sizeof(remote_addr.ipv6.ip));
  145. remote_addr.ipv6.port = addr_ipv6->port;
  146. addr_size = sizeof(*addr_ipv6);
  147. } break;
  148. default: {
  149. BLog(BLOG_ERROR, "Bad address type");
  150. return;
  151. }
  152. }
  153. uint8_t *body_data = addr_data + addr_size;
  154. size_t body_len = data_len - (body_data - data);
  155. // check remaining data
  156. if (body_len > o->udp_mtu) {
  157. BLog(BLOG_ERROR, "too much data");
  158. return;
  159. }
  160. // pass packet to user
  161. SocksUdpClient *client = con->client;
  162. client->handler_received(client->user, con->local_addr, remote_addr, body_data, body_len);
  163. if (con->dns_id >= 0) {
  164. // This connection has only been used for a single DNS query.
  165. int recv_dns_id = get_dns_id(&remote_addr, body_data, body_len);
  166. if (recv_dns_id == con->dns_id) {
  167. // We have now forwarded the response, so this connection is no longer needed.
  168. connection_free(con);
  169. } else {
  170. BLog(BLOG_INFO,
  171. "DNS client port received an unexpected non-DNS packet. "
  172. "Disabling DNS optimization.");
  173. con->dns_id = -1;
  174. }
  175. }
  176. }
  177. struct SocksUdpClient_connection *connection_init(SocksUdpClient *o, BAddr local_addr,
  178. BAddr first_remote_addr,
  179. const uint8_t *first_data,
  180. int first_data_len)
  181. {
  182. DebugObject_Access(&o->d_obj);
  183. ASSERT(o->num_connections <= o->max_connections)
  184. ASSERT(!find_connection_by_addr(o, local_addr))
  185. char buffer[BADDR_MAX_PRINT_LEN];
  186. BAddr_Print(&local_addr, buffer);
  187. BLog(BLOG_DEBUG, "Creating new connection for %s", buffer);
  188. // allocate structure
  189. struct SocksUdpClient_connection *con = (struct SocksUdpClient_connection *)malloc(sizeof(*con));
  190. if (!con) {
  191. BLog(BLOG_ERROR, "malloc failed");
  192. goto fail0;
  193. }
  194. // init arguments
  195. con->client = o;
  196. con->local_addr = local_addr;
  197. con->first_data = BAlloc(first_data_len);
  198. con->first_data_len = first_data_len;
  199. con->first_remote_addr = first_remote_addr;
  200. memcpy(con->first_data, first_data, first_data_len);
  201. con->dns_id = get_dns_id(&first_remote_addr, first_data, first_data_len);
  202. BPendingGroup *pg = BReactor_PendingGroup(o->reactor);
  203. // init first job, to send the first packet asynchronously. This has to happen asynchronously
  204. // because con->send_writer (a BufferWriter) cannot accept writes until after it is linked with
  205. // its PacketBuffer (con->send_buffer), which happens asynchronously.
  206. BPending_Init(&con->first_job, pg, (BPending_handler)first_job_handler, con);
  207. // Add the first job to the pending set. BPending acts as a LIFO stack, and first_job_handler
  208. // needs to run after async actions that occur in PacketBuffer_Init, so we need to put first_job
  209. // on the stack first.
  210. BPending_Set(&con->first_job);
  211. // Create a datagram socket
  212. if (!BDatagram_Init(&con->socket, con->local_addr.type, o->reactor, con,
  213. (BDatagram_handler)datagram_state_handler)) {
  214. BLog(BLOG_ERROR, "Failed to create a UDP socket");
  215. goto fail1;
  216. }
  217. // Bind to 127.0.0.1:0 (or [::1]:0). Port 0 signals the kernel to choose an open port.
  218. BAddr socket_addr;
  219. socket_addr.type = local_addr.type;
  220. if (local_addr.type == BADDR_TYPE_IPV4) {
  221. init_localhost4(&socket_addr.ipv4.ip);
  222. socket_addr.ipv4.port = 0;
  223. } else if (local_addr.type == BADDR_TYPE_IPV6) {
  224. init_localhost6(socket_addr.ipv6.ip);
  225. socket_addr.ipv6.port = 0;
  226. } else {
  227. BLog(BLOG_ERROR, "Unknown local address type");
  228. goto fail2;
  229. }
  230. if (!BDatagram_Bind(&con->socket, socket_addr)) {
  231. BLog(BLOG_ERROR, "Bind to localhost failed");
  232. goto fail2;
  233. }
  234. // Bind succeeded, so the kernel has found an open port.
  235. // Update socket_addr to the actual port that was bound.
  236. uint16_t port;
  237. if (!BDatagram_GetLocalPort(&con->socket, &port)) {
  238. BLog(BLOG_ERROR, "Failed to get bound port");
  239. goto fail2;
  240. }
  241. if (socket_addr.type == BADDR_TYPE_IPV4) {
  242. socket_addr.ipv4.port = port;
  243. } else {
  244. socket_addr.ipv6.port = port;
  245. }
  246. // Initiate connection to socks server
  247. if (!BSocksClient_Init(&con->socks, o->server_addr, o->auth_info, o->num_auth_info, socket_addr,
  248. true, (BSocksClient_handler)socks_state_handler, con, o->reactor)) {
  249. BLog(BLOG_ERROR, "Failed to initialize SOCKS client");
  250. goto fail2;
  251. }
  252. // Ensure that the UDP handling pipeline can handle queries big enough to include
  253. // all data plus the SOCKS-UDP header.
  254. int socks_mtu = compute_mtu(o->udp_mtu);
  255. // Send pipeline: send_writer -> send_buffer -> send_monitor -> send_if -> socket.
  256. BDatagram_SendAsync_Init(&con->socket, socks_mtu);
  257. PacketPassInterface *send_if = BDatagram_SendAsync_GetIf(&con->socket);
  258. PacketPassInactivityMonitor_Init(&con->send_monitor, send_if, o->reactor, o->keepalive_time,
  259. (PacketPassInactivityMonitor_handler)send_monitor_handler, con);
  260. BufferWriter_Init(&con->send_writer, compute_mtu(o->udp_mtu), pg);
  261. if (!PacketBuffer_Init(&con->send_buffer, BufferWriter_GetOutput(&con->send_writer),
  262. PacketPassInactivityMonitor_GetInput(&con->send_monitor),
  263. SOCKS_UDP_SEND_BUFFER_PACKETS, pg)) {
  264. BLog(BLOG_ERROR, "Send buffer init failed");
  265. goto fail3;
  266. }
  267. // Receive pipeline: socket -> recv_buffer -> recv_if
  268. BDatagram_RecvAsync_Init(&con->socket, socks_mtu);
  269. PacketPassInterface_Init(&con->recv_if, socks_mtu,
  270. (PacketPassInterface_handler_send)recv_if_handler_send, con, pg);
  271. if (!SinglePacketBuffer_Init(&con->recv_buffer, BDatagram_RecvAsync_GetIf(&con->socket),
  272. &con->recv_if, pg)) {
  273. BLog(BLOG_ERROR, "Receive buffer init failed");
  274. goto fail4;
  275. }
  276. // insert to connections tree
  277. ASSERT_EXECUTE(BAVL_Insert(&o->connections_tree, &con->connections_tree_node, NULL))
  278. o->num_connections++;
  279. return con;
  280. fail4:
  281. PacketPassInterface_Free(&con->recv_if);
  282. BDatagram_RecvAsync_Free(&con->socket);
  283. PacketBuffer_Free(&con->send_buffer);
  284. fail3:
  285. BufferWriter_Free(&con->send_writer);
  286. PacketPassInactivityMonitor_Free(&con->send_monitor);
  287. BDatagram_SendAsync_Free(&con->socket);
  288. fail2:
  289. BDatagram_Free(&con->socket);
  290. fail1:
  291. BPending_Free(&con->first_job);
  292. BFree(con->first_data);
  293. free(con);
  294. fail0:
  295. return NULL;
  296. }
  297. void connection_free (struct SocksUdpClient_connection *con)
  298. {
  299. SocksUdpClient *o = con->client;
  300. DebugObject_Access(&o->d_obj);
  301. // decrement number of connections
  302. o->num_connections--;
  303. // remove from connections tree
  304. BAVL_Remove(&o->connections_tree, &con->connections_tree_node);
  305. // Free UDP send pipeline components
  306. PacketBuffer_Free(&con->send_buffer);
  307. BufferWriter_Free(&con->send_writer);
  308. PacketPassInactivityMonitor_Free(&con->send_monitor);
  309. BDatagram_SendAsync_Free(&con->socket);
  310. // Free UDP receive pipeline components
  311. SinglePacketBuffer_Free(&con->recv_buffer);
  312. PacketPassInterface_Free(&con->recv_if);
  313. BDatagram_RecvAsync_Free(&con->socket);
  314. // Free UDP socket
  315. BDatagram_Free(&con->socket);
  316. // Free SOCKS client
  317. BSocksClient_Free(&con->socks);
  318. BPending_Free(&con->first_job);
  319. if (con->first_data) {
  320. BFree(con->first_data);
  321. }
  322. // free structure
  323. free(con);
  324. }
  325. void connection_send (struct SocksUdpClient_connection *con, BAddr remote_addr,
  326. const uint8_t *data, int data_len)
  327. {
  328. SocksUdpClient *o = con->client;
  329. DebugObject_Access(&o->d_obj);
  330. ASSERT(data_len >= 0)
  331. ASSERT(data_len <= o->udp_mtu)
  332. if (con->dns_id >= 0) {
  333. // So far, this connection has only sent a single DNS query.
  334. int new_dns_id = get_dns_id(&remote_addr, data, data_len);
  335. if (new_dns_id != con->dns_id) {
  336. BLog(BLOG_DEBUG, "Client reused DNS query port. Disabling DNS optimization.");
  337. con->dns_id = -1;
  338. }
  339. }
  340. // Check if we're sending to an IPv4 or IPv6 destination.
  341. int atyp;
  342. size_t address_size;
  343. // write address
  344. switch (remote_addr.type) {
  345. case BADDR_TYPE_IPV4: {
  346. atyp = SOCKS_ATYP_IPV4;
  347. address_size = sizeof(struct socks_addr_ipv4);
  348. } break;
  349. case BADDR_TYPE_IPV6: {
  350. atyp = SOCKS_ATYP_IPV6;
  351. address_size = sizeof(struct socks_addr_ipv6);
  352. } break;
  353. default: {
  354. BLog(BLOG_ERROR, "bad address type");
  355. return;
  356. }
  357. }
  358. // Wrap the payload in a UDP SOCKS header.
  359. size_t socks_data_len = sizeof(struct socks_udp_header) + address_size + data_len;
  360. if (socks_data_len > compute_mtu(o->udp_mtu)) {
  361. BLog(BLOG_ERROR, "Packet is too big: %d > %d", socks_data_len, compute_mtu(o->udp_mtu));
  362. return;
  363. }
  364. uint8_t *socks_data;
  365. if (!BufferWriter_StartPacket(&con->send_writer, &socks_data)) {
  366. BLog(BLOG_ERROR, "Send buffer is full");
  367. return;
  368. }
  369. // Write header
  370. struct socks_udp_header *header = (struct socks_udp_header *)socks_data;
  371. header->rsv = 0;
  372. header->frag = 0;
  373. header->atyp = atyp;
  374. uint8_t *addr_data = socks_data + sizeof(struct socks_udp_header);
  375. switch (atyp) {
  376. case SOCKS_ATYP_IPV4: {
  377. struct socks_addr_ipv4 *addr_ipv4 = (struct socks_addr_ipv4 *)addr_data;
  378. addr_ipv4->addr = remote_addr.ipv4.ip;
  379. addr_ipv4->port = remote_addr.ipv4.port;
  380. } break;
  381. case SOCKS_ATYP_IPV6: {
  382. struct socks_addr_ipv6 *addr_ipv6 = (struct socks_addr_ipv6 *)addr_data;
  383. memcpy(addr_ipv6->addr, remote_addr.ipv6.ip, sizeof(addr_ipv6->addr));
  384. addr_ipv6->port = remote_addr.ipv6.port;
  385. } break;
  386. }
  387. // write packet to buffer
  388. memcpy(addr_data + address_size, data, data_len);
  389. BufferWriter_EndPacket(&con->send_writer, socks_data_len);
  390. }
  391. void first_job_handler(struct SocksUdpClient_connection *con)
  392. {
  393. connection_send(con, con->first_remote_addr, con->first_data, con->first_data_len);
  394. BFree(con->first_data);
  395. con->first_data = NULL;
  396. con->first_data_len = 0;
  397. }
  398. int compute_mtu(int udp_mtu)
  399. {
  400. return udp_mtu + sizeof(struct socks_udp_header) + sizeof(struct socks_addr_ipv6);
  401. }
  402. int get_dns_id(BAddr *remote_addr, const uint8_t *data, int data_len)
  403. {
  404. if (BAddr_GetPort(remote_addr) == htons(DNS_PORT) && data_len >= 2) {
  405. return (data[0] << 8) + data[1];
  406. }
  407. return -1;
  408. }
  409. void SocksUdpClient_Init (SocksUdpClient *o, int udp_mtu, int max_connections, btime_t keepalive_time,
  410. BAddr server_addr, const struct BSocksClient_auth_info *auth_info, size_t num_auth_info,
  411. BReactor *reactor, void *user,
  412. SocksUdpClient_handler_received handler_received)
  413. {
  414. ASSERT(udp_mtu >= 0)
  415. ASSERT(compute_mtu(udp_mtu) >= 0)
  416. ASSERT(max_connections > 0)
  417. // init arguments
  418. o->server_addr = server_addr;
  419. o->auth_info = auth_info;
  420. o->num_auth_info = num_auth_info;
  421. o->udp_mtu = udp_mtu;
  422. o->max_connections = max_connections;
  423. o->num_connections = 0;
  424. o->keepalive_time = keepalive_time;
  425. o->reactor = reactor;
  426. o->user = user;
  427. o->handler_received = handler_received;
  428. // limit max connections to number of conid's
  429. if (o->max_connections > UINT16_MAX + 1) {
  430. o->max_connections = UINT16_MAX + 1;
  431. }
  432. // init connections tree
  433. BAVL_Init(&o->connections_tree, OFFSET_DIFF(struct SocksUdpClient_connection, local_addr, connections_tree_node), (BAVL_comparator)addr_comparator, NULL);
  434. DebugObject_Init(&o->d_obj);
  435. }
  436. void SocksUdpClient_Free (SocksUdpClient *o)
  437. {
  438. // free connections
  439. while (!BAVL_IsEmpty(&o->connections_tree)) {
  440. struct SocksUdpClient_connection *con = UPPER_OBJECT(BAVL_GetFirst(&o->connections_tree), struct SocksUdpClient_connection, connections_tree_node);
  441. connection_free(con);
  442. }
  443. DebugObject_Free(&o->d_obj);
  444. }
  445. void SocksUdpClient_SubmitPacket (SocksUdpClient *o, BAddr local_addr, BAddr remote_addr, const uint8_t *data, int data_len)
  446. {
  447. DebugObject_Access(&o->d_obj);
  448. ASSERT(local_addr.type == BADDR_TYPE_IPV4 || local_addr.type == BADDR_TYPE_IPV6)
  449. ASSERT(remote_addr.type == BADDR_TYPE_IPV4 || remote_addr.type == BADDR_TYPE_IPV6)
  450. ASSERT(data_len >= 0)
  451. // lookup connection
  452. struct SocksUdpClient_connection *con = find_connection_by_addr(o, local_addr);
  453. if (!con) {
  454. if (o->num_connections == o->max_connections) {
  455. // Drop the packet.
  456. BLog(BLOG_ERROR, "Dropping UDP packet, reached max number of connections.");
  457. return;
  458. }
  459. // create new connection and enqueue the packet
  460. connection_init(o, local_addr, remote_addr, data, data_len);
  461. } else {
  462. // send packet
  463. connection_send(con, remote_addr, data, data_len);
  464. }
  465. }