PacketCopier.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * @file PacketCopier.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. * Object which copies packets.
  25. */
  26. #ifndef BADVPN_FLOW_PACKETCOPIER_H
  27. #define BADVPN_FLOW_PACKETCOPIER_H
  28. #include <stdint.h>
  29. #include <misc/dead.h>
  30. #include <system/BPending.h>
  31. #include <flow/PacketPassInterface.h>
  32. #include <flow/PacketRecvInterface.h>
  33. /**
  34. * Object which copies packets.
  35. * Input is via {@link PacketPassInterface}.
  36. * Output is via {@link PacketRecvInterface}.
  37. */
  38. typedef struct {
  39. DebugObject d_obj;
  40. dead_t dead;
  41. PacketPassInterface input;
  42. PacketRecvInterface output;
  43. int in_len;
  44. uint8_t *in;
  45. int in_got;
  46. int out_have;
  47. uint8_t *out;
  48. int out_got_len;
  49. BPending continue_job_input;
  50. BPending continue_job_output;
  51. } PacketCopier;
  52. /**
  53. * Initializes the object.
  54. *
  55. * @param o the object
  56. * @param mtu maximum packet size. Must be >=0.
  57. * @param pg pending group
  58. */
  59. void PacketCopier_Init (PacketCopier *o, int mtu, BPendingGroup *pg);
  60. /**
  61. * Frees the object.
  62. *
  63. * @param o the object
  64. */
  65. void PacketCopier_Free (PacketCopier *o);
  66. /**
  67. * Returns the input interface.
  68. * The MTU of the interface will as in {@link PacketCopier_Init}.
  69. * The interface will support cancel functionality.
  70. *
  71. * @return input interface
  72. */
  73. PacketPassInterface * PacketCopier_GetInput (PacketCopier *o);
  74. /**
  75. * Returns the output interface.
  76. * The MTU of the interface will be as in {@link PacketCopier_Init}.
  77. *
  78. * @return output interface
  79. */
  80. PacketRecvInterface * PacketCopier_GetOutput (PacketCopier *o);
  81. #endif