gnunet_vpn_service.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2012 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @author Christian Grothoff
  18. *
  19. * @file
  20. * API to access the VPN service.
  21. *
  22. * @defgroup vpn VPN service
  23. *
  24. * @{
  25. */
  26. #ifndef GNUNET_VPN_SERVICE_H
  27. #define GNUNET_VPN_SERVICE_H
  28. #include "gnunet_util_lib.h"
  29. /**
  30. * Opaque VPN handle
  31. */
  32. struct GNUNET_VPN_Handle;
  33. /**
  34. * Opaque redirection request handle.
  35. */
  36. struct GNUNET_VPN_RedirectionRequest;
  37. /**
  38. * Callback invoked from the VPN service once a redirection is
  39. * available. Provides the IP address that can now be used to
  40. * reach the requested destination.
  41. *
  42. * @param cls closure
  43. * @param af address family, AF_INET or AF_INET6; AF_UNSPEC on error;
  44. * will match 'result_af' from the request
  45. * @param address IP address (struct in_addr or struct in_addr6, depending on 'af')
  46. * that the VPN allocated for the redirection;
  47. * traffic to this IP will now be redirected to the
  48. * specified target peer; NULL on error
  49. */
  50. typedef void (*GNUNET_VPN_AllocationCallback)(void *cls,
  51. int af,
  52. const void *address);
  53. /**
  54. * Cancel redirection request with the service.
  55. *
  56. * @param rr request to cancel
  57. */
  58. void
  59. GNUNET_VPN_cancel_request (struct GNUNET_VPN_RedirectionRequest *rr);
  60. /**
  61. * Tell the VPN that a forwarding to a particular peer offering a
  62. * particular service is requested. The VPN is to reserve a
  63. * particular IP for the redirection and return it. The VPN will
  64. * begin the redirection as soon as possible and maintain it as long
  65. * as it is actively used and keeping it is feasible. Given resource
  66. * limitations, the longest inactive mappings will be destroyed.
  67. *
  68. * @param vh VPN handle
  69. * @param result_af desired address family for the returned allocation
  70. * can also be AF_UNSPEC
  71. * @param protocol protocol, IPPROTO_UDP or IPPROTO_TCP
  72. * @param peer target peer for the redirection
  73. * @param serv service descriptor to give to the peer
  74. * @param expiration_time at what time should the redirection expire?
  75. * (this should not impact connections that are active at that time)
  76. * @param cb function to call with the IP
  77. * @param cb_cls closure for cb
  78. * @return handle to cancel the request (means the callback won't be
  79. * invoked anymore; the mapping may or may not be established
  80. * anyway)
  81. */
  82. struct GNUNET_VPN_RedirectionRequest *
  83. GNUNET_VPN_redirect_to_peer (struct GNUNET_VPN_Handle *vh,
  84. int result_af,
  85. uint8_t protocol,
  86. const struct GNUNET_PeerIdentity *peer,
  87. const struct GNUNET_HashCode *serv,
  88. struct GNUNET_TIME_Absolute expiration_time,
  89. GNUNET_VPN_AllocationCallback cb,
  90. void *cb_cls);
  91. /**
  92. * Tell the VPN that forwarding to the Internet via some exit node is
  93. * requested. Note that both UDP and TCP traffic will be forwarded,
  94. * but possibly to different exit nodes. The VPN is to reserve a
  95. * particular IP for the redirection and return it. The VPN will
  96. * begin the redirection as soon as possible and maintain it as long
  97. * as it is actively used and keeping it is feasible. Given resource
  98. * limitations, the longest inactive mappings will be destroyed.
  99. *
  100. * @param vh VPN handle
  101. * @param result_af desired address family for the returned allocation,
  102. * can also be AF_UNSPEC
  103. * @param addr_af address family for 'addr', AF_INET or AF_INET6
  104. * @param addr destination IP address on the Internet; destination
  105. * port is to be taken from the VPN packet itself
  106. * @param expiration_time at what time should the redirection expire?
  107. * (this should not impact connections that are active at that time)
  108. * @param cb function to call with the IP
  109. * @param cb_cls closure for cb
  110. * @return handle to cancel the request (means the callback won't be
  111. * invoked anymore; the mapping may or may not be established
  112. * anyway)
  113. */
  114. struct GNUNET_VPN_RedirectionRequest *
  115. GNUNET_VPN_redirect_to_ip (struct GNUNET_VPN_Handle *vh,
  116. int result_af,
  117. int addr_af,
  118. const void *addr,
  119. struct GNUNET_TIME_Absolute expiration_time,
  120. GNUNET_VPN_AllocationCallback cb,
  121. void *cb_cls);
  122. /**
  123. * Connect to the VPN service
  124. *
  125. * @param cfg configuration to use
  126. * @return VPN handle
  127. */
  128. struct GNUNET_VPN_Handle *
  129. GNUNET_VPN_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
  130. /**
  131. * Disconnect from the VPN service.
  132. *
  133. * @param vh VPN handle
  134. */
  135. void
  136. GNUNET_VPN_disconnect (struct GNUNET_VPN_Handle *vh);
  137. #endif
  138. /** @} */ /* end of group */