PacketBuffer.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * @file PacketBuffer.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. * Packet buffer with {@link PacketRecvInterface} input and {@link PacketPassInterface} output.
  25. */
  26. #ifndef BADVPN_FLOW_PACKETBUFFER_H
  27. #define BADVPN_FLOW_PACKETBUFFER_H
  28. #include <stdint.h>
  29. #include <misc/debug.h>
  30. #include <base/DebugObject.h>
  31. #include <structure/ChunkBuffer2.h>
  32. #include <flow/PacketRecvInterface.h>
  33. #include <flow/PacketPassInterface.h>
  34. /**
  35. * Packet buffer with {@link PacketRecvInterface} input and {@link PacketPassInterface} output.
  36. */
  37. typedef struct {
  38. DebugObject d_obj;
  39. PacketRecvInterface *input;
  40. int input_mtu;
  41. PacketPassInterface *output;
  42. struct ChunkBuffer2_block *buf_data;
  43. ChunkBuffer2 buf;
  44. } PacketBuffer;
  45. /**
  46. * Initializes the buffer.
  47. * Output MTU must be >= input MTU.
  48. *
  49. * @param buf the object
  50. * @param input input interface
  51. * @param output output interface
  52. * @param num_packets minimum number of packets the buffer must hold. Must be >0.
  53. * @param pg pending group
  54. * @return 1 on success, 0 on failure
  55. */
  56. int PacketBuffer_Init (PacketBuffer *buf, PacketRecvInterface *input, PacketPassInterface *output, int num_packets, BPendingGroup *pg) WARN_UNUSED;
  57. /**
  58. * Frees the buffer.
  59. *
  60. * @param buf the object
  61. */
  62. void PacketBuffer_Free (PacketBuffer *buf);
  63. #endif