GoGlue.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright (c)2019 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2023-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by vergnn 2.0 of the Apache License.
  11. */
  12. /****/
  13. #ifndef ZT_GONODE_H
  14. #define ZT_GONODE_H
  15. #include <stdint.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include "../../include/ZeroTierCore.h"
  19. #include "../../node/Constants.hpp"
  20. /****************************************************************************/
  21. /* A pointer to an instance of EthernetTap */
  22. typedef void ZT_GoTap;
  23. /* ZT_GoNode is a C struct and functions that wraps ZT_Node for use via cgo. It
  24. * performs UDP and other direct I/O in C for performance but otherwise lets
  25. * the Go code control the node's behavior. */
  26. struct ZT_GoNode_Impl;
  27. typedef struct ZT_GoNode_Impl ZT_GoNode;
  28. /****************************************************************************/
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /****************************************************************************/
  33. extern const char *ZT_PLATFORM_DEFAULT_HOMEPATH;
  34. /****************************************************************************/
  35. ZT_GoNode *ZT_GoNode_new(const char *workingPath,uintptr_t userPtr);
  36. void ZT_GoNode_delete(ZT_GoNode *gn);
  37. ZT_Node *ZT_GoNode_getNode(ZT_GoNode *gn);
  38. /* This can be called more than once to start multiple listener threads */
  39. int ZT_GoNode_phyStartListen(ZT_GoNode *gn,const char *dev,const char *ip,const int port);
  40. /* Close all listener threads for a given local IP and port */
  41. int ZT_GoNode_phyStopListen(ZT_GoNode *gn,const char *dev,const char *ip,const int port);
  42. ZT_GoTap *ZT_GoNode_join(ZT_GoNode *gn,uint64_t nwid);
  43. void ZT_GoNode_leave(ZT_GoNode *gn,uint64_t nwid);
  44. /****************************************************************************/
  45. void ZT_GoTap_setEnabled(ZT_GoTap *tap,int enabled);
  46. int ZT_GoTap_addIp(ZT_GoTap *tap,int af,const void *ip,int netmaskBits);
  47. int ZT_GoTap_removeIp(ZT_GoTap *tap,int af,const void *ip,int netmaskBits);
  48. /* The buf buffer is filled with tuplies of:
  49. * uint8_t family
  50. * uint8_t ip[4 or 16]
  51. * uint8_t netmask bits (up to 32 for ipv4, 128 for ipv6)
  52. *
  53. * This function returns the number of such tuples in the result.
  54. * If the buffer isn't big enough results are incomplete.
  55. */
  56. int ZT_GoTap_ips(ZT_GoTap *tap,void *buf,unsigned int bufSize);
  57. void ZT_GoTap_deviceName(ZT_GoTap *tap,char nbuf[256]);
  58. void ZT_GoTap_setFriendlyName(ZT_GoTap *tap,const char *friendlyName);
  59. void ZT_GoTap_setMtu(ZT_GoTap *tap,unsigned int mtu);
  60. int ZT_GoTap_addRoute(ZT_GoTap *tap,int targetAf,const void *targetIp,int targetNetmaskBits,int viaAf,const void *viaIp,unsigned int metric);
  61. int ZT_GoTap_removeRoute(ZT_GoTap *tap,int targetAf,const void *targetIp,int targetNetmaskBits,int viaAf,const void *viaIp,unsigned int metric);
  62. /****************************************************************************/
  63. const char *ZT_GoIdentity_generate(int type);
  64. int ZT_GoIdentity_validate(const char *idStr);
  65. int ZT_GoIdentity_sign(const char *idStr,const void *data,unsigned int len,void *sigbuf,unsigned int sigbuflen);
  66. int ZT_GoIdentity_verify(const char *idStr,const void *data,unsigned int len,const void *sig,unsigned int siglen);
  67. /****************************************************************************/
  68. struct ZT_GoLocator_Info {
  69. char id[1024];
  70. unsigned int phyCount;
  71. unsigned int virtCount;
  72. struct sockaddr_storage phy[256];
  73. char virt[256][1024];
  74. };
  75. /* Returns length of private key stored in private key buffer on success, -1 on fail */
  76. int ZT_GoLocator_makeSecureDNSName(char name[256],unsigned int nameBufSize,uint8_t *privateKey,unsigned int privateKeyBufSize);
  77. /*
  78. * The id is the full identity described by the locator. It must include
  79. * its secret key to permit the locator to be signed.
  80. *
  81. * Physical addresses must be IPv4 or IPv6 IP/port pairs. Virtual addresses
  82. * must be full ZeroTier identities in string format.
  83. *
  84. * On success this returns the actual number of bytes stored in the buffer.
  85. * On failure -1 is returned.
  86. */
  87. int ZT_GoLocator_makeLocator(
  88. uint8_t *buf,
  89. unsigned int bufSize,
  90. int64_t ts,
  91. const char *id,
  92. const struct sockaddr_storage *physicalAddresses,
  93. unsigned int physicalAddressCount,
  94. const char **virtualAddresses,
  95. unsigned int virtualAddressCount);
  96. /* Returns >0 on success, fills info structure */
  97. int ZT_GoLocator_decodeLocator(const uint8_t *locatorBytes,unsigned int locatorSize,struct ZT_GoLocator_Info *info);
  98. /*
  99. * The privateKey and privateKeySize are those created by makeSecureDNSName.
  100. * Results is filled and the number of lines of TXT are returned. The value
  101. * -1 is returned on error.
  102. */
  103. int ZT_GoLocator_makeSignedTxtRecords(
  104. const uint8_t *locator,
  105. unsigned int locatorSize,
  106. const char *name,
  107. const uint8_t *privateKey,
  108. unsigned int privateKeySize,
  109. char results[256][256]);
  110. /****************************************************************************/
  111. #ifdef __cplusplus
  112. }
  113. #endif
  114. #endif