PacketRecvBlocker.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * @file PacketRecvBlocker.h
  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. * @section DESCRIPTION
  23. *
  24. * {@link PacketRecvInterface} layer which blocks all output recv calls and only
  25. * passes a single blocked call on to input when the user wants so.
  26. */
  27. #ifndef BADVPN_FLOW_PACKETRECVBLOCKER_H
  28. #define BADVPN_FLOW_PACKETRECVBLOCKER_H
  29. #include <stdint.h>
  30. #include <misc/dead.h>
  31. #include <system/DebugObject.h>
  32. #include <flow/PacketRecvInterface.h>
  33. /**
  34. * {@link PacketRecvInterface} layer which blocks all output recv calls and only
  35. * passes a single blocked call on to input when the user wants so.
  36. */
  37. typedef struct {
  38. DebugObject d_obj;
  39. dead_t dead;
  40. PacketRecvInterface output;
  41. int out_have;
  42. uint8_t *out;
  43. int out_input_blocking;
  44. PacketRecvInterface *input;
  45. } PacketRecvBlocker;
  46. /**
  47. * Initializes the object.
  48. *
  49. * @param o the object
  50. * @param input input interface
  51. */
  52. void PacketRecvBlocker_Init (PacketRecvBlocker *o, PacketRecvInterface *input);
  53. /**
  54. * Frees the object.
  55. *
  56. * @param o the object
  57. */
  58. void PacketRecvBlocker_Free (PacketRecvBlocker *o);
  59. /**
  60. * Returns the output interface.
  61. * The MTU of the output interface will be the same as of the input interface.
  62. *
  63. * @param o the object
  64. * @return output interface
  65. */
  66. PacketRecvInterface * PacketRecvBlocker_GetOutput (PacketRecvBlocker *o);
  67. /**
  68. * Passes a blocked output recv call to input if there is one and it has not
  69. * been passed yet. Otherwise it does nothing.
  70. * Must not be called from input Recv calls.
  71. * This function may invoke I/O.
  72. *
  73. * @param o the object
  74. */
  75. void PacketRecvBlocker_AllowBlockedPacket (PacketRecvBlocker *o);
  76. #endif