dataproto.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * @file dataproto.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. * Definitions for DataProto, the protocol for data transport between VPN peers.
  25. *
  26. * All multi-byte integers in structs are little-endian, unless stated otherwise.
  27. *
  28. * A DataProto packet consists of:
  29. * - the header (struct {@link dataproto_header})
  30. * - between zero and DATAPROTO_MAX_PEER_IDS destination peer IDs (struct {@link dataproto_peer_id})
  31. * - the payload, e.g. Ethernet frame
  32. */
  33. #ifndef BADVPN_PROTOCOL_DATAPROTO_H
  34. #define BADVPN_PROTOCOL_DATAPROTO_H
  35. #include <stdint.h>
  36. #include <protocol/scproto.h>
  37. #define DATAPROTO_MAX_PEER_IDS 1
  38. #define DATAPROTO_FLAGS_RECEIVING_KEEPALIVES 1
  39. /**
  40. * DataProto header.
  41. */
  42. struct dataproto_header {
  43. /**
  44. * Bitwise OR of flags. Possible flags:
  45. * - DATAPROTO_FLAGS_RECEIVING_KEEPALIVES
  46. * Indicates that when the peer sent this packet, it has received at least
  47. * one packet from the other peer in the last keep-alive tolerance time.
  48. */
  49. uint8_t flags;
  50. /**
  51. * ID of the peer this frame originates from.
  52. */
  53. peerid_t from_id;
  54. /**
  55. * Number of destination peer IDs that follow.
  56. * Must be <=DATAPROTO_MAX_PEER_IDS.
  57. */
  58. peerid_t num_peer_ids;
  59. } __attribute__((packed));
  60. /**
  61. * Structure for a destination peer ID in DataProto.
  62. * Wraps a single peerid_t in a packed struct for easy access.
  63. */
  64. struct dataproto_peer_id {
  65. peerid_t id;
  66. } __attribute__((packed));
  67. #define DATAPROTO_MAX_OVERHEAD (sizeof(struct dataproto_header) + DATAPROTO_MAX_PEER_IDS * sizeof(struct dataproto_peer_id))
  68. #endif