PacketCopier.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 <flow/PacketPassInterface.h>
  31. #include <flow/PacketRecvInterface.h>
  32. /**
  33. * Object which copies packets.
  34. * Input is via {@link PacketPassInterface}.
  35. * Output is via {@link PacketRecvInterface}.
  36. */
  37. typedef struct {
  38. DebugObject d_obj;
  39. dead_t dead;
  40. PacketPassInterface input;
  41. PacketRecvInterface output;
  42. int in_len;
  43. uint8_t *in;
  44. int out_have;
  45. uint8_t *out;
  46. } PacketCopier;
  47. /**
  48. * Initializes the object.
  49. *
  50. * @param o the object
  51. * @param mtu maximum packet size. Must be >=0.
  52. */
  53. void PacketCopier_Init (PacketCopier *o, int mtu);
  54. /**
  55. * Frees the object.
  56. *
  57. * @param o the object
  58. */
  59. void PacketCopier_Free (PacketCopier *o);
  60. /**
  61. * Returns the input interface.
  62. * The MTU of the interface will as in {@link PacketCopier_Init}.
  63. * The interface will support cancel functionality.
  64. *
  65. * @return input interface
  66. */
  67. PacketPassInterface * PacketCopier_GetInput (PacketCopier *o);
  68. /**
  69. * Returns the output interface.
  70. * The MTU of the interface will be as in {@link PacketCopier_Init}.
  71. *
  72. * @return output interface
  73. */
  74. PacketRecvInterface * PacketCopier_GetOutput (PacketCopier *o);
  75. #endif