udpgw_proto.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * @file udpgw_proto.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. * Protocol for forwarding UDP over TCP. Messages should be carried with PacketProto.
  25. */
  26. #ifndef BADVPN_PROTOCOL_UDPGW_PROTO_H
  27. #define BADVPN_PROTOCOL_UDPGW_PROTO_H
  28. #include <stdint.h>
  29. #include <misc/bsize.h>
  30. #define UDPGW_CLIENT_FLAG_KEEPALIVE (1 << 0)
  31. #define UDPGW_CLIENT_FLAG_REBIND (1 << 1)
  32. struct udpgw_header {
  33. uint8_t flags;
  34. uint16_t conid;
  35. uint32_t addr_ip;
  36. uint16_t addr_port;
  37. } __attribute__((packed));
  38. static int udpgw_compute_mtu (int dgram_mtu)
  39. {
  40. bsize_t bs = bsize_add(
  41. bsize_fromsize(sizeof(struct udpgw_header)),
  42. bsize_fromint(dgram_mtu)
  43. );
  44. int s;
  45. if (!bsize_toint(bs, &s)) {
  46. return -1;
  47. }
  48. return s;
  49. }
  50. #endif