PacketProtoEncoder.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * @file PacketProtoEncoder.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 encodes packets according to PacketProto.
  25. */
  26. #ifndef BADVPN_FLOW_PACKETPROTOENCODER_H
  27. #define BADVPN_FLOW_PACKETPROTOENCODER_H
  28. #include <stdint.h>
  29. #include <base/DebugObject.h>
  30. #include <flow/PacketRecvInterface.h>
  31. /**
  32. * Object which encodes packets according to PacketProto.
  33. *
  34. * Input is with {@link PacketRecvInterface}.
  35. * Output is with {@link PacketRecvInterface}.
  36. */
  37. typedef struct {
  38. PacketRecvInterface *input;
  39. PacketRecvInterface output;
  40. uint8_t *output_packet;
  41. DebugObject d_obj;
  42. } PacketProtoEncoder;
  43. /**
  44. * Initializes the object.
  45. *
  46. * @param enc the object
  47. * @param input input interface. Its MTU must be <=PACKETPROTO_MAXPAYLOAD.
  48. * @param pg pending group
  49. */
  50. void PacketProtoEncoder_Init (PacketProtoEncoder *enc, PacketRecvInterface *input, BPendingGroup *pg);
  51. /**
  52. * Frees the object.
  53. *
  54. * @param enc the object
  55. */
  56. void PacketProtoEncoder_Free (PacketProtoEncoder *enc);
  57. /**
  58. * Returns the output interface.
  59. * The MTU of the output interface is PACKETPROTO_ENCLEN(MTU of input interface).
  60. *
  61. * @param enc the object
  62. * @return output interface
  63. */
  64. PacketRecvInterface * PacketProtoEncoder_GetOutput (PacketProtoEncoder *enc);
  65. #endif