BTap.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. /**
  2. * @file BTap.c
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. */
  22. #include <string.h>
  23. #include <stdio.h>
  24. #ifdef BADVPN_USE_WINAPI
  25. #include <windows.h>
  26. #include <winioctl.h>
  27. #include <objbase.h>
  28. #include <wtypes.h>
  29. #include "wintap-common.h"
  30. #include <tuntap/tapwin32-funcs.h>
  31. #else
  32. #include <linux/if_tun.h>
  33. #include <net/if.h>
  34. #include <net/if_arp.h>
  35. #include <sys/ioctl.h>
  36. #include <sys/types.h>
  37. #include <sys/stat.h>
  38. #include <sys/socket.h>
  39. #include <fcntl.h>
  40. #include <unistd.h>
  41. #include <errno.h>
  42. #endif
  43. #include <tuntap/BTap.h>
  44. static void report_error (BTap *o);
  45. static void input_handler_send (BTap *o, uint8_t *data, int data_len);
  46. static void input_handler_cancel (BTap *o);
  47. static void output_handler_recv (BTap *o, uint8_t *data);
  48. #ifdef BADVPN_USE_WINAPI
  49. static int try_send (BTap *o, uint8_t *data, int data_len)
  50. {
  51. // setup overlapped
  52. memset(&o->input_ol, 0, sizeof(o->input_ol));
  53. o->input_ol.hEvent = o->input_event;
  54. // attempt write
  55. if (!WriteFile(o->device, data, data_len, NULL, &o->input_ol)) {
  56. DWORD error = GetLastError();
  57. if (error == ERROR_IO_PENDING) {
  58. // write pending
  59. return 0;
  60. }
  61. DEBUG("WARNING: WriteFile failed (%u)", error);
  62. return 1;
  63. }
  64. // read result
  65. DWORD bytes;
  66. if (!GetOverlappedResult(o->device, &o->input_ol, &bytes, FALSE)) {
  67. DEBUG("WARNING: GetOverlappedResult failed (%u)", GetLastError());
  68. }
  69. else if (bytes != data_len) {
  70. DEBUG("WARNING: written %d expected %d", (int)bytes, data_len);
  71. }
  72. // reset event
  73. ASSERT_FORCE(ResetEvent(o->input_event))
  74. return 1;
  75. }
  76. static int try_recv (BTap *o, uint8_t *data, int *data_len)
  77. {
  78. // setup overlapped
  79. memset(&o->output_ol, 0, sizeof(o->output_ol));
  80. o->output_ol.hEvent = o->output_event;
  81. // attempt read
  82. if (!ReadFile(o->device, data, o->frame_mtu, NULL, &o->output_ol)) {
  83. DWORD error = GetLastError();
  84. if (error == ERROR_IO_PENDING) {
  85. // read pending
  86. return 0;
  87. }
  88. DEBUG("ReadFile failed (%u)", error);
  89. // fatal error
  90. return -1;
  91. }
  92. // read result
  93. DWORD bytes;
  94. if (!GetOverlappedResult(o->device, &o->output_ol, &bytes, FALSE)) {
  95. DEBUG("GetOverlappedResult (output) failed (%u)", GetLastError());
  96. // fatal error
  97. return -1;
  98. }
  99. ASSERT_FORCE(bytes <= o->frame_mtu)
  100. // reset event
  101. ASSERT_FORCE(ResetEvent(o->output_event))
  102. *data_len = bytes;
  103. return 1;
  104. }
  105. static void write_handle_handler (BTap *o)
  106. {
  107. ASSERT(o->input_packet_len >= 0)
  108. DebugError_AssertNoError(&o->d_err);
  109. DebugObject_Access(&o->d_obj);
  110. // disable handle event
  111. BReactor_DisableHandle(o->reactor, &o->input_bhandle);
  112. // read result
  113. DWORD bytes;
  114. if (!GetOverlappedResult(o->device, &o->input_ol, &bytes, FALSE)) {
  115. DEBUG("WARNING: GetOverlappedResult (input) failed (%u)", GetLastError());
  116. } else if (bytes != o->input_packet_len) {
  117. DEBUG("WARNING: written %d expected %d", (int)bytes, o->input_packet_len);
  118. }
  119. // set no input packet
  120. o->input_packet_len = -1;
  121. // reset event
  122. ASSERT_FORCE(ResetEvent(o->input_event))
  123. // inform sender we finished the packet
  124. PacketPassInterface_Done(&o->input);
  125. }
  126. static void read_handle_handler (BTap *o)
  127. {
  128. ASSERT(o->output_packet)
  129. DebugError_AssertNoError(&o->d_err);
  130. DebugObject_Access(&o->d_obj);
  131. int bytes;
  132. // read result
  133. DWORD dbytes;
  134. if (!GetOverlappedResult(o->device, &o->output_ol, &dbytes, FALSE)) {
  135. DWORD error = GetLastError();
  136. DEBUG("GetOverlappedResult (output) failed (%u)", error);
  137. // handle accidental cancelation from input_handler_cancel
  138. if (error == ERROR_OPERATION_ABORTED) {
  139. DEBUG("retrying read");
  140. // reset event
  141. ASSERT_FORCE(ResetEvent(o->output_event))
  142. // try receiving
  143. int res;
  144. if ((res = try_recv(o, o->output_packet, &bytes)) < 0) {
  145. goto fatal_error;
  146. }
  147. if (!res) {
  148. // keep waiting
  149. return;
  150. }
  151. goto done;
  152. }
  153. fatal_error:
  154. // set no output packet (so that BTap_Free doesn't try getting the result again)
  155. o->output_packet = NULL;
  156. // report fatal error
  157. report_error(o);
  158. return;
  159. }
  160. // reset event
  161. ASSERT_FORCE(ResetEvent(o->output_event))
  162. bytes = dbytes;
  163. done:
  164. ASSERT_FORCE(bytes <= o->frame_mtu)
  165. // disable handle event
  166. BReactor_DisableHandle(o->reactor, &o->output_bhandle);
  167. // set no output packet
  168. o->output_packet = NULL;
  169. // inform receiver we finished the packet
  170. PacketRecvInterface_Done(&o->output, bytes);
  171. }
  172. #else
  173. static void fd_handler (BTap *o, int events)
  174. {
  175. DebugError_AssertNoError(&o->d_err);
  176. DebugObject_Access(&o->d_obj);
  177. if (events&BREACTOR_ERROR) {
  178. DEBUG("WARNING: device fd reports error?");
  179. }
  180. if (events&BREACTOR_WRITE) do {
  181. ASSERT(o->input_packet_len >= 0)
  182. int bytes = write(o->fd, o->input_packet, o->input_packet_len);
  183. if (bytes < 0) {
  184. if (errno == EAGAIN || errno == EWOULDBLOCK) {
  185. // retry later
  186. break;
  187. }
  188. // malformed packets will cause errors, ignore them and act like
  189. // the packet was accepeted
  190. } else {
  191. if (bytes != o->input_packet_len) {
  192. DEBUG("WARNING: written %d expected %d", bytes, o->input_packet_len);
  193. }
  194. }
  195. // set no input packet
  196. o->input_packet_len = -1;
  197. // update events
  198. o->poll_events &= ~BREACTOR_WRITE;
  199. BReactor_SetFileDescriptorEvents(o->reactor, &o->bfd, o->poll_events);
  200. // inform sender we finished the packet
  201. PacketPassInterface_Done(&o->input);
  202. } while (0);
  203. if (events&BREACTOR_READ) do {
  204. ASSERT(o->output_packet)
  205. // try reading into the buffer
  206. int bytes = read(o->fd, o->output_packet, o->frame_mtu);
  207. if (bytes < 0) {
  208. if (errno == EAGAIN || errno == EWOULDBLOCK) {
  209. // retry later
  210. break;
  211. }
  212. // report fatal error
  213. report_error(o);
  214. return;
  215. }
  216. ASSERT_FORCE(bytes <= o->frame_mtu)
  217. // set no output packet
  218. o->output_packet = NULL;
  219. // update events
  220. o->poll_events &= ~BREACTOR_READ;
  221. BReactor_SetFileDescriptorEvents(o->reactor, &o->bfd, o->poll_events);
  222. // inform receiver we finished the packet
  223. PacketRecvInterface_Done(&o->output, bytes);
  224. } while (0);
  225. }
  226. #endif
  227. void report_error (BTap *o)
  228. {
  229. DEBUGERROR(&o->d_err, o->handler_error(o->handler_error_user));
  230. }
  231. void input_handler_send (BTap *o, uint8_t *data, int data_len)
  232. {
  233. ASSERT(data_len >= 0)
  234. ASSERT(data_len <= o->frame_mtu)
  235. ASSERT(o->input_packet_len == -1)
  236. DebugError_AssertNoError(&o->d_err);
  237. DebugObject_Access(&o->d_obj);
  238. #ifdef BADVPN_USE_WINAPI
  239. // ignore frames without an Ethernet header, or we get errors in WriteFile
  240. if (data_len >= 14) {
  241. if (!try_send(o, data, data_len)) {
  242. // write pending
  243. o->input_packet = data;
  244. o->input_packet_len = data_len;
  245. BReactor_EnableHandle(o->reactor, &o->input_bhandle);
  246. return;
  247. }
  248. }
  249. #else
  250. int bytes = write(o->fd, data, data_len);
  251. if (bytes < 0) {
  252. if (errno == EAGAIN || errno == EWOULDBLOCK) {
  253. // retry later in fd_handler
  254. // remember packet
  255. o->input_packet = data;
  256. o->input_packet_len = data_len;
  257. // update events
  258. o->poll_events |= BREACTOR_WRITE;
  259. BReactor_SetFileDescriptorEvents(o->reactor, &o->bfd, o->poll_events);
  260. return;
  261. }
  262. // malformed packets will cause errors, ignore them and act like
  263. // the packet was accepeted
  264. } else {
  265. if (bytes != data_len) {
  266. DEBUG("WARNING: written %d expected %d", bytes, data_len);
  267. }
  268. }
  269. #endif
  270. PacketPassInterface_Done(&o->input);
  271. }
  272. void input_handler_cancel (BTap *o)
  273. {
  274. DebugObject_Access(&o->d_obj);
  275. DebugError_AssertNoError(&o->d_err);
  276. ASSERT(o->input_packet_len >= 0)
  277. #ifdef BADVPN_USE_WINAPI
  278. // disable handle event
  279. BReactor_DisableHandle(o->reactor, &o->input_bhandle);
  280. // cancel I/O on the device
  281. // this also cancels reading, so handle the aborted error code in read_handle_handler
  282. ASSERT_FORCE(CancelIo(o->device))
  283. // wait for it
  284. DWORD bytes;
  285. if (!GetOverlappedResult(o->device, &o->input_ol, &bytes, TRUE)) {
  286. DWORD error = GetLastError();
  287. if (error != ERROR_OPERATION_ABORTED) {
  288. DEBUG("WARNING: GetOverlappedResult (input) failed (%u)", error);
  289. }
  290. } else if (bytes != o->input_packet_len) {
  291. DEBUG("WARNING: written %d expected %d", (int)bytes, o->input_packet_len);
  292. }
  293. // reset event
  294. ASSERT_FORCE(ResetEvent(o->input_event))
  295. #else
  296. // update events
  297. o->poll_events &= ~BREACTOR_WRITE;
  298. BReactor_SetFileDescriptorEvents(o->reactor, &o->bfd, o->poll_events);
  299. #endif
  300. // set no input packet
  301. o->input_packet_len = -1;
  302. }
  303. void output_handler_recv (BTap *o, uint8_t *data)
  304. {
  305. ASSERT(data)
  306. ASSERT(!o->output_packet)
  307. DebugError_AssertNoError(&o->d_err);
  308. DebugObject_Access(&o->d_obj);
  309. #ifdef BADVPN_USE_WINAPI
  310. int bytes;
  311. int res;
  312. if ((res = try_recv(o, data, &bytes)) < 0) {
  313. // report fatal error
  314. report_error(o);
  315. return;
  316. }
  317. if (!res) {
  318. // read pending
  319. o->output_packet = data;
  320. BReactor_EnableHandle(o->reactor, &o->output_bhandle);
  321. return;
  322. }
  323. #else
  324. // attempt read
  325. int bytes = read(o->fd, data, o->frame_mtu);
  326. if (bytes < 0) {
  327. if (errno == EAGAIN || errno == EWOULDBLOCK) {
  328. // retry later in fd_handler
  329. // remember packet
  330. o->output_packet = data;
  331. // update events
  332. o->poll_events |= BREACTOR_READ;
  333. BReactor_SetFileDescriptorEvents(o->reactor, &o->bfd, o->poll_events);
  334. return;
  335. }
  336. // report fatal error
  337. report_error(o);
  338. return;
  339. }
  340. #endif
  341. ASSERT_FORCE(bytes <= o->frame_mtu)
  342. PacketRecvInterface_Done(&o->output, bytes);
  343. }
  344. int BTap_Init (BTap *o, BReactor *reactor, char *devname, BTap_handler_error handler_error, void *handler_error_user, int tun)
  345. {
  346. ASSERT(tun == 0 || tun == 1)
  347. // init arguments
  348. o->reactor = reactor;
  349. o->handler_error = handler_error;
  350. o->handler_error_user = handler_error_user;
  351. #ifdef BADVPN_USE_WINAPI
  352. // parse device specification
  353. if (!devname) {
  354. DEBUG("no device specification provided");
  355. return 0;
  356. }
  357. int devname_len = strlen(devname);
  358. char device_component_id[devname_len + 1];
  359. char device_name[devname_len + 1];
  360. uint32_t tun_addrs[3];
  361. if (tun) {
  362. if (!tapwin32_parse_tun_spec(devname, device_component_id, device_name, tun_addrs)) {
  363. DEBUG("failed to parse TUN device specification");
  364. return 0;
  365. }
  366. } else {
  367. if (!tapwin32_parse_tap_spec(devname, device_component_id, device_name)) {
  368. DEBUG("failed to parse TAP device specification");
  369. return 0;
  370. }
  371. }
  372. // locate device path
  373. char device_path[TAPWIN32_MAX_REG_SIZE];
  374. DEBUG("Looking for TAP-Win32 with component ID %s, name %s", device_component_id, device_name);
  375. if (!tapwin32_find_device(device_component_id, device_name, &device_path)) {
  376. DEBUG("Could not find device");
  377. goto fail0;
  378. }
  379. // open device
  380. DEBUG("Opening device %s", device_path);
  381. o->device = CreateFile(device_path, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM|FILE_FLAG_OVERLAPPED, 0);
  382. if (o->device == INVALID_HANDLE_VALUE) {
  383. DEBUG("CreateFile failed");
  384. goto fail0;
  385. }
  386. // set TUN if needed
  387. DWORD len;
  388. if (tun) {
  389. if (!DeviceIoControl(o->device, TAP_IOCTL_CONFIG_TUN, tun_addrs, sizeof(tun_addrs), tun_addrs, sizeof(tun_addrs), &len, NULL)) {
  390. DEBUG("DeviceIoControl(TAP_IOCTL_CONFIG_TUN) failed");
  391. goto fail1;
  392. }
  393. }
  394. // get MTU
  395. if (tun) {
  396. o->frame_mtu = 65535;
  397. } else {
  398. ULONG umtu;
  399. if (!DeviceIoControl(o->device, TAP_IOCTL_GET_MTU, NULL, 0, &umtu, sizeof(umtu), &len, NULL)) {
  400. DEBUG("DeviceIoControl(TAP_IOCTL_GET_MTU) failed");
  401. goto fail1;
  402. }
  403. o->frame_mtu = umtu + BTAP_ETHERNET_HEADER_LENGTH;
  404. }
  405. // set connected
  406. ULONG upstatus = TRUE;
  407. if (!DeviceIoControl(o->device, TAP_IOCTL_SET_MEDIA_STATUS, &upstatus, sizeof(upstatus), &upstatus, sizeof(upstatus), &len, NULL)) {
  408. DEBUG("DeviceIoControl(TAP_IOCTL_SET_MEDIA_STATUS) failed");
  409. goto fail1;
  410. }
  411. DEBUG("Device opened");
  412. // init input/output
  413. if (!(o->input_event = CreateEvent(NULL, TRUE, FALSE, NULL))) {
  414. DEBUG("CreateEvent failed");
  415. goto fail1;
  416. }
  417. if (!(o->output_event = CreateEvent(NULL, TRUE, FALSE, NULL))) {
  418. DEBUG("CreateEvent failed");
  419. goto fail2;
  420. }
  421. BHandle_Init(&o->input_bhandle, o->input_event, (BHandle_handler)write_handle_handler, o);
  422. BHandle_Init(&o->output_bhandle, o->output_event, (BHandle_handler)read_handle_handler, o);
  423. if (!BReactor_AddHandle(o->reactor, &o->input_bhandle)) {
  424. goto fail3;
  425. }
  426. if (!BReactor_AddHandle(o->reactor, &o->output_bhandle)) {
  427. goto fail4;
  428. }
  429. goto success;
  430. fail4:
  431. BReactor_RemoveHandle(o->reactor, &o->input_bhandle);
  432. fail3:
  433. ASSERT_FORCE(CloseHandle(o->output_event))
  434. fail2:
  435. ASSERT_FORCE(CloseHandle(o->input_event))
  436. fail1:
  437. ASSERT_FORCE(CloseHandle(o->device))
  438. fail0:
  439. return 0;
  440. #else
  441. // open device
  442. if ((o->fd = open("/dev/net/tun", O_RDWR)) < 0) {
  443. DEBUG("error opening device");
  444. goto fail0;
  445. }
  446. // configure device
  447. struct ifreq ifr;
  448. memset(&ifr, 0, sizeof(ifr));
  449. ifr.ifr_flags |= IFF_NO_PI;
  450. if (tun) {
  451. ifr.ifr_flags |= IFF_TUN;
  452. } else {
  453. ifr.ifr_flags |= IFF_TAP;
  454. }
  455. if (devname) {
  456. snprintf(ifr.ifr_name, IFNAMSIZ, "%s", devname);
  457. }
  458. if (ioctl(o->fd, TUNSETIFF, (void *)&ifr) < 0) {
  459. DEBUG("error configuring device");
  460. goto fail1;
  461. }
  462. strcpy(o->devname, ifr.ifr_name);
  463. // get MTU
  464. if (tun) {
  465. o->frame_mtu = 65535;
  466. } else {
  467. // open dummy socket for ioctls
  468. int sock = socket(AF_INET, SOCK_DGRAM, 0);
  469. if (sock < 0) {
  470. DEBUG("socket failed");
  471. goto fail1;
  472. }
  473. memset(&ifr, 0, sizeof(ifr));
  474. strcpy(ifr.ifr_name, o->devname);
  475. if (ioctl(sock, SIOCGIFMTU, (void *)&ifr) < 0) {
  476. DEBUG("error getting MTU");
  477. close(sock);
  478. goto fail1;
  479. }
  480. o->frame_mtu = ifr.ifr_mtu + BTAP_ETHERNET_HEADER_LENGTH;
  481. close(sock);
  482. }
  483. // set non-blocking
  484. if (fcntl(o->fd, F_SETFL, O_NONBLOCK) < 0) {
  485. DEBUG("cannot set non-blocking");
  486. goto fail1;
  487. }
  488. // init file descriptor object
  489. BFileDescriptor_Init(&o->bfd, o->fd, (BFileDescriptor_handler)fd_handler, o);
  490. if (!BReactor_AddFileDescriptor(o->reactor, &o->bfd)) {
  491. DEBUG("BReactor_AddFileDescriptor failed");
  492. goto fail1;
  493. }
  494. o->poll_events = 0;
  495. goto success;
  496. fail1:
  497. ASSERT_FORCE(close(o->fd) == 0)
  498. fail0:
  499. return 0;
  500. #endif
  501. success:
  502. // init input
  503. PacketPassInterface_Init(&o->input, o->frame_mtu, (PacketPassInterface_handler_send)input_handler_send, o, BReactor_PendingGroup(o->reactor));
  504. PacketPassInterface_EnableCancel(&o->input, (PacketPassInterface_handler_cancel)input_handler_cancel);
  505. // init output
  506. PacketRecvInterface_Init(&o->output, o->frame_mtu, (PacketRecvInterface_handler_recv)output_handler_recv, o, BReactor_PendingGroup(o->reactor));
  507. // set no input packet
  508. o->input_packet_len = -1;
  509. // set no output packet
  510. o->output_packet = NULL;
  511. DebugObject_Init(&o->d_obj);
  512. DebugError_Init(&o->d_err, BReactor_PendingGroup(o->reactor));
  513. return 1;
  514. }
  515. void BTap_Free (BTap *o)
  516. {
  517. DebugError_Free(&o->d_err);
  518. DebugObject_Free(&o->d_obj);
  519. // free output
  520. PacketRecvInterface_Free(&o->output);
  521. // free input
  522. PacketPassInterface_Free(&o->input);
  523. #ifdef BADVPN_USE_WINAPI
  524. // wait for pending i/o
  525. ASSERT_FORCE(CancelIo(o->device))
  526. DWORD bytes;
  527. DWORD error;
  528. if (o->input_packet_len >= 0) {
  529. if (!GetOverlappedResult(o->device, &o->input_ol, &bytes, TRUE)) {
  530. error = GetLastError();
  531. if (error != ERROR_OPERATION_ABORTED) {
  532. DEBUG("WARNING: GetOverlappedResult (input) failed (%u)", error);
  533. }
  534. }
  535. }
  536. if (o->output_packet) {
  537. if (!GetOverlappedResult(o->device, &o->output_ol, &bytes, TRUE)) {
  538. error = GetLastError();
  539. if (error != ERROR_OPERATION_ABORTED) {
  540. DEBUG("WARNING: GetOverlappedResult (output) failed (%u)", error);
  541. }
  542. }
  543. }
  544. // free stuff
  545. BReactor_RemoveHandle(o->reactor, &o->input_bhandle);
  546. BReactor_RemoveHandle(o->reactor, &o->output_bhandle);
  547. ASSERT_FORCE(CloseHandle(o->output_event))
  548. ASSERT_FORCE(CloseHandle(o->input_event))
  549. ASSERT_FORCE(CloseHandle(o->device))
  550. #else
  551. // free BFileDescriptor
  552. BReactor_RemoveFileDescriptor(o->reactor, &o->bfd);
  553. // close file descriptor
  554. ASSERT_FORCE(close(o->fd) == 0)
  555. #endif
  556. }
  557. int BTap_GetMTU (BTap *o)
  558. {
  559. DebugObject_Access(&o->d_obj);
  560. return o->frame_mtu;
  561. }
  562. PacketPassInterface * BTap_GetInput (BTap *o)
  563. {
  564. DebugObject_Access(&o->d_obj);
  565. return &o->input;
  566. }
  567. PacketRecvInterface * BTap_GetOutput (BTap *o)
  568. {
  569. DebugObject_Access(&o->d_obj);
  570. return &o->output;
  571. }