PacketRecvBlocker.h 2.3 KB

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