BTap.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. /**
  2. * @file BTap.c
  3. * @author Ambroz Bizjak <[email protected]>
  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. DebugObject_Access(&o->d_obj);
  109. // disable handle event
  110. BReactor_DisableHandle(o->reactor, &o->input_bhandle);
  111. // read result
  112. DWORD bytes;
  113. if (!GetOverlappedResult(o->device, &o->input_ol, &bytes, FALSE)) {
  114. DEBUG("WARNING: GetOverlappedResult (input) failed (%u)", GetLastError());
  115. } else if (bytes != o->input_packet_len) {
  116. DEBUG("WARNING: written %d expected %d", (int)bytes, o->input_packet_len);
  117. }
  118. // set no input packet
  119. o->input_packet_len = -1;
  120. // reset event
  121. ASSERT_FORCE(ResetEvent(o->input_event))
  122. // inform sender we finished the packet
  123. PacketPassInterface_Done(&o->input);
  124. }
  125. static void read_handle_handler (BTap *o)
  126. {
  127. ASSERT(o->output_packet)
  128. DebugObject_Access(&o->d_obj);
  129. int bytes;
  130. // read result
  131. DWORD dbytes;
  132. if (!GetOverlappedResult(o->device, &o->output_ol, &dbytes, FALSE)) {
  133. DWORD error = GetLastError();
  134. DEBUG("GetOverlappedResult (output) failed (%u)", error);
  135. // handle accidental cancelation from input_handler_cancel
  136. if (error == ERROR_OPERATION_ABORTED) {
  137. DEBUG("retrying read");
  138. // reset event
  139. ASSERT_FORCE(ResetEvent(o->output_event))
  140. // try receiving
  141. int res;
  142. if ((res = try_recv(o, o->output_packet, &bytes)) < 0) {
  143. goto fatal_error;
  144. }
  145. if (!res) {
  146. // keep waiting
  147. return;
  148. }
  149. goto done;
  150. }
  151. fatal_error:
  152. // set no output packet (so that BTap_Free doesn't try getting the result again)
  153. o->output_packet = NULL;
  154. // report fatal error
  155. report_error(o);
  156. return;
  157. }
  158. // reset event
  159. ASSERT_FORCE(ResetEvent(o->output_event))
  160. bytes = dbytes;
  161. done:
  162. ASSERT_FORCE(bytes <= o->frame_mtu)
  163. // disable handle event
  164. BReactor_DisableHandle(o->reactor, &o->output_bhandle);
  165. // set no output packet
  166. o->output_packet = NULL;
  167. // inform receiver we finished the packet
  168. PacketRecvInterface_Done(&o->output, bytes);
  169. }
  170. #else
  171. static void fd_handler (BTap *o, int events)
  172. {
  173. DebugObject_Access(&o->d_obj);
  174. DEAD_DECLARE
  175. if (events&BREACTOR_ERROR) {
  176. DEBUG("WARNING: device fd reports error?");
  177. }
  178. if (events&BREACTOR_WRITE) do {
  179. ASSERT(o->input_packet_len >= 0)
  180. int bytes = write(o->fd, o->input_packet, o->input_packet_len);
  181. if (bytes < 0) {
  182. if (errno == EAGAIN || errno == EWOULDBLOCK) {
  183. // retry later
  184. break;
  185. }
  186. // malformed packets will cause errors, ignore them and act like
  187. // the packet was accepeted
  188. } else {
  189. if (bytes != o->input_packet_len) {
  190. DEBUG("WARNING: written %d expected %d", bytes, o->input_packet_len);
  191. }
  192. }
  193. // set no input packet
  194. o->input_packet_len = -1;
  195. // update events
  196. o->poll_events &= ~BREACTOR_WRITE;
  197. BReactor_SetFileDescriptorEvents(o->reactor, &o->bfd, o->poll_events);
  198. // inform sender we finished the packet
  199. PacketPassInterface_Done(&o->input);
  200. } while (0);
  201. if (events&BREACTOR_READ) do {
  202. ASSERT(o->output_packet)
  203. // try reading into the buffer
  204. int bytes = read(o->fd, o->output_packet, o->frame_mtu);
  205. if (bytes < 0) {
  206. if (errno == EAGAIN || errno == EWOULDBLOCK) {
  207. // retry later
  208. break;
  209. }
  210. // report fatal error
  211. report_error(o);
  212. return;
  213. }
  214. ASSERT_FORCE(bytes <= o->frame_mtu)
  215. // set no output packet
  216. o->output_packet = NULL;
  217. // update events
  218. o->poll_events &= ~BREACTOR_READ;
  219. BReactor_SetFileDescriptorEvents(o->reactor, &o->bfd, o->poll_events);
  220. // inform receiver we finished the packet
  221. PacketRecvInterface_Done(&o->output, bytes);
  222. } while (0);
  223. }
  224. #endif
  225. void report_error (BTap *o)
  226. {
  227. #ifndef NDEBUG
  228. DEAD_ENTER(o->dead)
  229. #endif
  230. o->handler_error(o->handler_error_user);
  231. #ifndef NDEBUG
  232. ASSERT(DEAD_KILLED)
  233. DEAD_LEAVE(o->dead);
  234. #endif
  235. }
  236. void input_handler_send (BTap *o, uint8_t *data, int data_len)
  237. {
  238. ASSERT(data_len >= 0)
  239. ASSERT(data_len <= o->frame_mtu)
  240. ASSERT(o->input_packet_len == -1)
  241. DebugObject_Access(&o->d_obj);
  242. #ifdef BADVPN_USE_WINAPI
  243. // ignore frames without an Ethernet header, or we get errors in WriteFile
  244. if (data_len >= 14) {
  245. if (!try_send(o, data, data_len)) {
  246. // write pending
  247. o->input_packet = data;
  248. o->input_packet_len = data_len;
  249. BReactor_EnableHandle(o->reactor, &o->input_bhandle);
  250. return;
  251. }
  252. }
  253. #else
  254. int bytes = write(o->fd, data, data_len);
  255. if (bytes < 0) {
  256. if (errno == EAGAIN || errno == EWOULDBLOCK) {
  257. // retry later in fd_handler
  258. // remember packet
  259. o->input_packet = data;
  260. o->input_packet_len = data_len;
  261. // update events
  262. o->poll_events |= BREACTOR_WRITE;
  263. BReactor_SetFileDescriptorEvents(o->reactor, &o->bfd, o->poll_events);
  264. return;
  265. }
  266. // malformed packets will cause errors, ignore them and act like
  267. // the packet was accepeted
  268. } else {
  269. if (bytes != data_len) {
  270. DEBUG("WARNING: written %d expected %d", bytes, data_len);
  271. }
  272. }
  273. #endif
  274. PacketPassInterface_Done(&o->input);
  275. }
  276. void input_handler_cancel (BTap *o)
  277. {
  278. DebugObject_Access(&o->d_obj);
  279. ASSERT(o->input_packet_len >= 0)
  280. #ifdef BADVPN_USE_WINAPI
  281. // disable handle event
  282. BReactor_DisableHandle(o->reactor, &o->input_bhandle);
  283. // cancel I/O on the device
  284. // this also cancels reading, so handle the aborted error code in read_handle_handler
  285. ASSERT_FORCE(CancelIo(o->device))
  286. // wait for it
  287. DWORD bytes;
  288. if (!GetOverlappedResult(o->device, &o->input_ol, &bytes, TRUE)) {
  289. DWORD error = GetLastError();
  290. if (error != ERROR_OPERATION_ABORTED) {
  291. DEBUG("WARNING: GetOverlappedResult (input) failed (%u)", error);
  292. }
  293. } else if (bytes != o->input_packet_len) {
  294. DEBUG("WARNING: written %d expected %d", (int)bytes, o->input_packet_len);
  295. }
  296. // reset event
  297. ASSERT_FORCE(ResetEvent(o->input_event))
  298. #else
  299. // update events
  300. o->poll_events &= ~BREACTOR_WRITE;
  301. BReactor_SetFileDescriptorEvents(o->reactor, &o->bfd, o->poll_events);
  302. #endif
  303. // set no input packet
  304. o->input_packet_len = -1;
  305. }
  306. void output_handler_recv (BTap *o, uint8_t *data)
  307. {
  308. ASSERT(data)
  309. ASSERT(!o->output_packet)
  310. DebugObject_Access(&o->d_obj);
  311. #ifdef BADVPN_USE_WINAPI
  312. int bytes;
  313. int res;
  314. if ((res = try_recv(o, data, &bytes)) < 0) {
  315. // report fatal error
  316. report_error(o);
  317. return;
  318. }
  319. if (!res) {
  320. // read pending
  321. o->output_packet = data;
  322. BReactor_EnableHandle(o->reactor, &o->output_bhandle);
  323. return;
  324. }
  325. #else
  326. // attempt read
  327. int bytes = read(o->fd, data, o->frame_mtu);
  328. if (bytes < 0) {
  329. if (errno == EAGAIN || errno == EWOULDBLOCK) {
  330. // retry later in fd_handler
  331. // remember packet
  332. o->output_packet = data;
  333. // update events
  334. o->poll_events |= BREACTOR_READ;
  335. BReactor_SetFileDescriptorEvents(o->reactor, &o->bfd, o->poll_events);
  336. return;
  337. }
  338. // report fatal error
  339. report_error(o);
  340. return;
  341. }
  342. #endif
  343. ASSERT_FORCE(bytes <= o->frame_mtu)
  344. PacketRecvInterface_Done(&o->output, bytes);
  345. }
  346. int BTap_Init (BTap *o, BReactor *reactor, char *devname, BTap_handler_error handler_error, void *handler_error_user, int tun)
  347. {
  348. ASSERT(tun == 0 || tun == 1)
  349. // init arguments
  350. o->reactor = reactor;
  351. o->handler_error = handler_error;
  352. o->handler_error_user = handler_error_user;
  353. #ifdef BADVPN_USE_WINAPI
  354. // parse device specification
  355. if (!devname) {
  356. DEBUG("no device specification provided");
  357. return 0;
  358. }
  359. int devname_len = strlen(devname);
  360. char device_component_id[devname_len + 1];
  361. char device_name[devname_len + 1];
  362. uint32_t tun_addrs[3];
  363. if (tun) {
  364. if (!tapwin32_parse_tun_spec(devname, device_component_id, device_name, tun_addrs)) {
  365. DEBUG("failed to parse TUN device specification");
  366. return 0;
  367. }
  368. } else {
  369. if (!tapwin32_parse_tap_spec(devname, device_component_id, device_name)) {
  370. DEBUG("failed to parse TAP device specification");
  371. return 0;
  372. }
  373. }
  374. // locate device path
  375. char device_path[TAPWIN32_MAX_REG_SIZE];
  376. DEBUG("Looking for TAP-Win32 with component ID %s, name %s", device_component_id, device_name);
  377. if (!tapwin32_find_device(device_component_id, device_name, &device_path)) {
  378. DEBUG("Could not find device");
  379. goto fail0;
  380. }
  381. // open device
  382. DEBUG("Opening device %s", device_path);
  383. o->device = CreateFile(device_path, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM|FILE_FLAG_OVERLAPPED, 0);
  384. if (o->device == INVALID_HANDLE_VALUE) {
  385. DEBUG("CreateFile failed");
  386. goto fail0;
  387. }
  388. // set TUN if needed
  389. DWORD len;
  390. if (tun) {
  391. if (!DeviceIoControl(o->device, TAP_IOCTL_CONFIG_TUN, tun_addrs, sizeof(tun_addrs), tun_addrs, sizeof(tun_addrs), &len, NULL)) {
  392. DEBUG("DeviceIoControl(TAP_IOCTL_CONFIG_TUN) failed");
  393. goto fail1;
  394. }
  395. }
  396. // get MTU
  397. if (tun) {
  398. o->frame_mtu = 65535;
  399. } else {
  400. ULONG umtu;
  401. if (!DeviceIoControl(o->device, TAP_IOCTL_GET_MTU, NULL, 0, &umtu, sizeof(umtu), &len, NULL)) {
  402. DEBUG("DeviceIoControl(TAP_IOCTL_GET_MTU) failed");
  403. goto fail1;
  404. }
  405. o->frame_mtu = umtu + BTAP_ETHERNET_HEADER_LENGTH;
  406. }
  407. // set connected
  408. ULONG upstatus = TRUE;
  409. if (!DeviceIoControl(o->device, TAP_IOCTL_SET_MEDIA_STATUS, &upstatus, sizeof(upstatus), &upstatus, sizeof(upstatus), &len, NULL)) {
  410. DEBUG("DeviceIoControl(TAP_IOCTL_SET_MEDIA_STATUS) failed");
  411. goto fail1;
  412. }
  413. DEBUG("Device opened");
  414. // init input/output
  415. if (!(o->input_event = CreateEvent(NULL, TRUE, FALSE, NULL))) {
  416. DEBUG("CreateEvent failed");
  417. goto fail1;
  418. }
  419. if (!(o->output_event = CreateEvent(NULL, TRUE, FALSE, NULL))) {
  420. DEBUG("CreateEvent failed");
  421. goto fail2;
  422. }
  423. BHandle_Init(&o->input_bhandle, o->input_event, (BHandle_handler)write_handle_handler, o);
  424. BHandle_Init(&o->output_bhandle, o->output_event, (BHandle_handler)read_handle_handler, o);
  425. if (!BReactor_AddHandle(o->reactor, &o->input_bhandle)) {
  426. goto fail3;
  427. }
  428. if (!BReactor_AddHandle(o->reactor, &o->output_bhandle)) {
  429. goto fail4;
  430. }
  431. goto success;
  432. fail4:
  433. BReactor_RemoveHandle(o->reactor, &o->input_bhandle);
  434. fail3:
  435. ASSERT_FORCE(CloseHandle(o->output_event))
  436. fail2:
  437. ASSERT_FORCE(CloseHandle(o->input_event))
  438. fail1:
  439. ASSERT_FORCE(CloseHandle(o->device))
  440. fail0:
  441. return 0;
  442. #else
  443. // open device
  444. if ((o->fd = open("/dev/net/tun", O_RDWR)) < 0) {
  445. DEBUG("error opening device");
  446. goto fail0;
  447. }
  448. // configure device
  449. struct ifreq ifr;
  450. memset(&ifr, 0, sizeof(ifr));
  451. ifr.ifr_flags |= IFF_NO_PI;
  452. if (tun) {
  453. ifr.ifr_flags |= IFF_TUN;
  454. } else {
  455. ifr.ifr_flags |= IFF_TAP;
  456. }
  457. if (devname) {
  458. snprintf(ifr.ifr_name, IFNAMSIZ, "%s", devname);
  459. }
  460. if (ioctl(o->fd, TUNSETIFF, (void *)&ifr) < 0) {
  461. DEBUG("error configuring device");
  462. goto fail1;
  463. }
  464. strcpy(o->devname, ifr.ifr_name);
  465. // get MTU
  466. if (tun) {
  467. o->frame_mtu = 65535;
  468. } else {
  469. // open dummy socket for ioctls
  470. int sock = socket(AF_INET, SOCK_DGRAM, 0);
  471. if (sock < 0) {
  472. DEBUG("socket failed");
  473. goto fail1;
  474. }
  475. memset(&ifr, 0, sizeof(ifr));
  476. strcpy(ifr.ifr_name, o->devname);
  477. if (ioctl(sock, SIOCGIFMTU, (void *)&ifr) < 0) {
  478. DEBUG("error getting MTU");
  479. close(sock);
  480. goto fail1;
  481. }
  482. o->frame_mtu = ifr.ifr_mtu + BTAP_ETHERNET_HEADER_LENGTH;
  483. close(sock);
  484. }
  485. // set non-blocking
  486. if (fcntl(o->fd, F_SETFL, O_NONBLOCK) < 0) {
  487. DEBUG("cannot set non-blocking");
  488. goto fail1;
  489. }
  490. // init file descriptor object
  491. BFileDescriptor_Init(&o->bfd, o->fd, (BFileDescriptor_handler)fd_handler, o);
  492. if (!BReactor_AddFileDescriptor(o->reactor, &o->bfd)) {
  493. DEBUG("BReactor_AddFileDescriptor failed");
  494. goto fail1;
  495. }
  496. o->poll_events = 0;
  497. goto success;
  498. fail1:
  499. ASSERT_FORCE(close(o->fd) == 0)
  500. fail0:
  501. return 0;
  502. #endif
  503. success:
  504. // init dead var
  505. DEAD_INIT(o->dead);
  506. // init input
  507. PacketPassInterface_Init(&o->input, o->frame_mtu, (PacketPassInterface_handler_send)input_handler_send, o, BReactor_PendingGroup(o->reactor));
  508. PacketPassInterface_EnableCancel(&o->input, (PacketPassInterface_handler_cancel)input_handler_cancel);
  509. // init output
  510. PacketRecvInterface_Init(&o->output, o->frame_mtu, (PacketRecvInterface_handler_recv)output_handler_recv, o, BReactor_PendingGroup(o->reactor));
  511. // set no input packet
  512. o->input_packet_len = -1;
  513. // set no output packet
  514. o->output_packet = NULL;
  515. DebugObject_Init(&o->d_obj);
  516. return 1;
  517. }
  518. void BTap_Free (BTap *o)
  519. {
  520. DebugObject_Free(&o->d_obj);
  521. // free output
  522. PacketRecvInterface_Free(&o->output);
  523. // free input
  524. PacketPassInterface_Free(&o->input);
  525. // kill dead variable
  526. DEAD_KILL(o->dead);
  527. #ifdef BADVPN_USE_WINAPI
  528. // wait for pending i/o
  529. ASSERT_FORCE(CancelIo(o->device))
  530. DWORD bytes;
  531. DWORD error;
  532. if (o->input_packet_len >= 0) {
  533. if (!GetOverlappedResult(o->device, &o->input_ol, &bytes, TRUE)) {
  534. error = GetLastError();
  535. if (error != ERROR_OPERATION_ABORTED) {
  536. DEBUG("WARNING: GetOverlappedResult (input) failed (%u)", error);
  537. }
  538. }
  539. }
  540. if (o->output_packet) {
  541. if (!GetOverlappedResult(o->device, &o->output_ol, &bytes, TRUE)) {
  542. error = GetLastError();
  543. if (error != ERROR_OPERATION_ABORTED) {
  544. DEBUG("WARNING: GetOverlappedResult (output) failed (%u)", error);
  545. }
  546. }
  547. }
  548. // free stuff
  549. BReactor_RemoveHandle(o->reactor, &o->input_bhandle);
  550. BReactor_RemoveHandle(o->reactor, &o->output_bhandle);
  551. ASSERT_FORCE(CloseHandle(o->output_event))
  552. ASSERT_FORCE(CloseHandle(o->input_event))
  553. ASSERT_FORCE(CloseHandle(o->device))
  554. #else
  555. // free BFileDescriptor
  556. BReactor_RemoveFileDescriptor(o->reactor, &o->bfd);
  557. // close file descriptor
  558. ASSERT_FORCE(close(o->fd) == 0)
  559. #endif
  560. }
  561. int BTap_GetMTU (BTap *o)
  562. {
  563. DebugObject_Access(&o->d_obj);
  564. return o->frame_mtu;
  565. }
  566. PacketPassInterface * BTap_GetInput (BTap *o)
  567. {
  568. DebugObject_Access(&o->d_obj);
  569. return &o->input;
  570. }
  571. PacketRecvInterface * BTap_GetOutput (BTap *o)
  572. {
  573. DebugObject_Access(&o->d_obj);
  574. return &o->output;
  575. }