PacketPassConnector.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * @file PacketPassConnector.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. * A {@link PacketPassInterface} layer which allows the output to be
  25. * connected and disconnected on the fly.
  26. */
  27. #ifndef BADVPN_FLOW_PACKETPASSCONNECTOR_H
  28. #define BADVPN_FLOW_PACKETPASSCONNECTOR_H
  29. #include <stdint.h>
  30. #include <misc/dead.h>
  31. #include <system/DebugObject.h>
  32. #include <system/BPending.h>
  33. #include <flow/PacketPassInterface.h>
  34. /**
  35. * A {@link PacketPassInterface} layer which allows the output to be
  36. * connected and disconnected on the fly.
  37. */
  38. typedef struct {
  39. DebugObject d_obj;
  40. dead_t dead;
  41. PacketPassInterface input;
  42. int input_mtu;
  43. int in_len;
  44. uint8_t *in;
  45. PacketPassInterface *output;
  46. dead_t output_dead;
  47. int out_blocking;
  48. BPending continue_job;
  49. } PacketPassConnector;
  50. /**
  51. * Initializes the object.
  52. * The object is initialized in not connected state.
  53. *
  54. * @param o the object
  55. * @param mtu maximum input packet size. Must be >=0.
  56. * @param pg pending group
  57. */
  58. void PacketPassConnector_Init (PacketPassConnector *o, int mtu, BPendingGroup *pg);
  59. /**
  60. * Frees the object.
  61. *
  62. * @param o the object
  63. */
  64. void PacketPassConnector_Free (PacketPassConnector *o);
  65. /**
  66. * Returns the input interface.
  67. * The MTU of the interface will be as in {@link PacketPassConnector_Init}.
  68. *
  69. * @param o the object
  70. * @return input interface
  71. */
  72. PacketPassInterface * PacketPassConnector_GetInput (PacketPassConnector *o);
  73. /**
  74. * Connects output.
  75. * The object must be in not connected state.
  76. * The object enters connected state.
  77. *
  78. * @param o the object
  79. * @param output output to connect. Its MTU must be >= MTU specified in
  80. * {@link PacketPassConnector_Init}.
  81. */
  82. void PacketPassConnector_ConnectOutput (PacketPassConnector *o, PacketPassInterface *output);
  83. /**
  84. * Disconnects output.
  85. * The object must be in connected state.
  86. * The object enters not connected state.
  87. *
  88. * @param o the object
  89. */
  90. void PacketPassConnector_DisconnectOutput (PacketPassConnector *o);
  91. #endif