NetTunnelWindows/NetTunnelSDK/tunnel.h

304 lines
10 KiB
C
Raw Normal View History

2023-06-15 01:35:37 +00:00
#pragma once
#include <Windows.h>
#ifdef NETTUNNELSDK_EXPORTS
#define TUNNEL_API __declspec(dllexport)
2023-06-15 01:35:37 +00:00
#else
#define TUNNEL_API __declspec(dllimport)
2023-06-15 01:35:37 +00:00
#endif
/**
* @brief WireGuard key
*/
constexpr auto WG_KEY_MAX = (64);
/**
* @brief
*/
#define NET_CARD_MAX (32)
2023-06-21 10:04:16 +00:00
/**
* @brief IP (IPv6)
*/
#define MAX_IP_LEN (48)
/**
* @brief
*
*/
typedef enum {
CRYPTO_NONE = 0, ///< 不加密
CRYPTO_BASE64 = 1, ///< BASE64 字符串编码
CRYPTO_AES128 = 2, ///< AES 128位秘钥 加密
CRYPTO_3DES = 3, ///< 3DES 加密
CRYPTO_AES256 = 4, ///< AES 256 位秘钥加密
2023-06-15 01:35:37 +00:00
CRYPTO_MAX,
} PROTO_CRYPTO_TYPE;
2023-06-15 01:35:37 +00:00
/**
* @brief
*
*/
enum LOG_LEVEL {
LOG_TRACE = 0, ///< TRACE 日志等级
LOG_DEBUG, ///< DEBUG 日志等级
LOG_INFO, ///< INFO 日志等级
LOG_WARN, ///< WARN 日志等级
LOG_ERROR, ///< ERROR 日志等级
LOG_CRITICAL, ///< CRITICAL 日志等级
LOG_OFF ///< 关闭日志
};
/**
*
* @brief
*/
typedef struct {
2023-06-21 10:04:16 +00:00
int InterfaceIndex; ///< 网卡索引
TCHAR NetCardUUID[260]; ///< 网卡名称, Windows标识为 UUID
TCHAR NetCardDescription[132]; ///< 网卡描述
TCHAR NetCardIpaddr[MAX_IP_LEN]; ///< 网卡 IP 地址
TCHAR NetCardNetmask[MAX_IP_LEN]; ///< 网卡子网掩码
TCHAR NetCardGateway[MAX_IP_LEN]; ///< 网卡网关
TCHAR NetCardMacAddr[20]; ///< 网卡 MAC 地址
} NIC_CONTENT, *PNIC_CONTENT;
/**
* @brief WireGuard
*/
typedef struct {
TCHAR Name[64]; ///< WireGuard 网卡名称
TCHAR Address[32]; ///< WireGuard 本地网络IP地址
TCHAR PrivateKey[64]; ///< WireGuard 本机私钥
int ListenPort; ///< WireGuard 服务端监听端口
// 根据系统设计,不支持多个客户端同时连接
TCHAR CliPubKey[64]; ///< WireGuard 客户端公钥
TCHAR AllowNet[256]; ///< WireGuard 允许对端访问本地网络的配置
} WGSERVER_CONFIG, *PWGSERVER_CONFIG;
/**
* @brief WireGuard
*/
typedef struct {
TCHAR Name[64]; ///< WireGuard 网卡名称
TCHAR PrivateKey[64]; ///< WireGuard 本机私钥
TCHAR Address[32]; ///< WireGuard 本地网络IP地址
// Peer Server
TCHAR SvrPubKey[64]; ///< WireGuard 服务端公钥
TCHAR AllowNet[256]; ///< WireGuard 允许对端访问本地网络的配置
TCHAR ServerURL[256]; ///< WireGuard 服务端IP地址和端口
} WGCLIENT_CONFIG, *PWGCLIENT_CONFIG;
2023-06-15 01:35:37 +00:00
#ifdef __cplusplus // If used by C++ code,
extern "C" {
// we need to export the C interface
#endif
/**
* @brief SDK
* @param[in] pWorkDir
* @return 0: 0 @see USER_ERRNO
* - -ERR_ITEM_EXISTS WireGuard
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl TunnelSDKInitEnv(const TCHAR *pWorkDir);
/**
* @brief CRYPTO_NONE
* @param[in] type @see PROTO_CRYPTO_TYPE
* @param[in] pProKey CRYPTO_NONE CRYPTO_BASE64
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl SetProtocolEncryptType(const PROTO_CRYPTO_TYPE type, const TCHAR *pProKey);
/**
* @brief SDK
* @param[in] pLogFile /
* @param[in] level
*/
TUNNEL_API void __cdecl InitTunnelSDKLog(const TCHAR *pLogFile, LOG_LEVEL level);
/**
* @brief / SDK
* @param enLog
* - TRUE
* - FALSE
*/
TUNNEL_API void __cdecl TunnelLogEnable(bool enLog);
/**
* @brief WireGuard
* @param[out] pFullPath wireguard.exe
* @param[in] maxSize pFullPath
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MALLOC_MEMORY
* - -ERR_FILE_NOT_EXISTS
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl FindWireguardExe(TCHAR *pFullPath, int maxSize);
/**
* @brief wireguard.exe
* @param[in] pPath wireguard.exe
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_ITEM_UNEXISTS
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl SetWireguardPath(const TCHAR *pPath);
/**
* @brief WireGuard
* @param[out] pPubKey
* @param[in] pubkeySize ()
* @param[out] pPrivKey
* @param[in] privKeySize ()
* @return 0: 0 @see USER_ERRNO
* - -ERR_ITEM_UNEXISTS WireGuard
* - -ERR_CALL_SHELL
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl GenerateWireguardKeyPairs(TCHAR *pPubKey, int pubkeySize, TCHAR *pPrivKey, int privKeySize);
/**
* @brief WireGuard
* @param pWgConfig @see WGSERVER_CONFIG
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MALLOC_MEMORY
* - -ERR_OPEN_FILE
* - -ERR_MEMORY_STR
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl WireGuardCreateServerConfig(const PWGSERVER_CONFIG pWgConfig);
/**
* @brief WireGuard
* @param pWgConfig @see WGCLIENT_CONFIG
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MALLOC_MEMORY
* - -ERR_OPEN_FILE
* - -ERR_MEMORY_STR
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl WireGuardCreateClientConfig(const PWGCLIENT_CONFIG pWgConfig);
/**
* @brief / WireGuard
* @param[in] bInstall TRUE , FALSE
* @return 0: 0 @see USER_ERRNO
*/
TUNNEL_API int __cdecl WireGuardInstallServerService(bool bInstall);
/**
* @brief SDK
*/
TUNNEL_API void __cdecl TunnelSDKUnInit();
/**
* @brief
* @param[in,out] pInfo @see NIC_CONTENT
* @param[out] pItemCounts 32
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MALLOC_MEMORY
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl GetAllNICInfo(PNIC_CONTENT pInfo, int *pItemCounts);
2023-06-15 01:35:37 +00:00
/**
2023-06-21 10:04:16 +00:00
* @brief
* @param pInterfaceName
* @param pIndex
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MALLOC_MEMORY
* - -ERR_MEMORY_STR
* - -ERR_CALL_SHELL
* - ERR_SUCCESS
*/
2023-06-21 10:04:16 +00:00
TUNNEL_API int __cdecl GetInterfaceIndexByName(const TCHAR *pInterfaceName, int *pIndex);
/**
* @brief
* @param[in] pInterfaceName
2023-06-21 10:04:16 +00:00
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MALLOC_MEMORY
* - -ERR_MEMORY_STR
* - -ERR_CALL_SHELL
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl RemoveInterfaceIpAddress(const TCHAR *pInterfaceName);
/**
* @brief IP地址
* @param[in] pInterfaceName
* @param[in] pCidrIpaddr CIDR类型IP地址
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MALLOC_MEMORY
* - -ERR_MEMORY_STR
* - -ERR_CALL_SHELL
* - ERR_SUCCESS
*/
2023-06-21 10:04:16 +00:00
TUNNEL_API int __cdecl SetInterfaceIpAddressFromCIDR(const TCHAR *pInterfaceName, const TCHAR *pCidrIpaddr);
/**
* @brief IP地址
* @param[in] pInterfaceName
* @param[in] pIpaddr IP
* @param[in] pNetmask
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MALLOC_MEMORY
* - -ERR_MEMORY_STR
* - -ERR_CALL_SHELL
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl SetInterfaceIpAddress(const TCHAR *pInterfaceName, const TCHAR *pIpaddr, const TCHAR *pNetmask);
/**
* @brief Windows Hyper-V NAT转发功能
* @param[out] pEnabled Hyper-V , TRUE , FALSE
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MEMORY_STR
* - -ERR_CALL_SHELL
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl GetWindowsHyperVStatus(int *pEnabled);
/**
* @brief / Windows Hyper-V
* @param[in] enabled TRUE , FALSE
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MEMORY_STR
* - -ERR_CALL_SHELL
* - -ERR_PROCESS_RETURN
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl EnableWindowsHyperV(bool enabled);
/**
* @brief Windows WireGuard NAT
* @param pInterfaceName
* @param pCidrIpaddr CIDR
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MEMORY_STR
* - -ERR_CALL_SHELL
* - -ERR_PROCESS_RETURN
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl SetNATRule(const TCHAR *pInterfaceName, const TCHAR *pCidrIpaddr);
2023-06-15 01:35:37 +00:00
#ifdef __cplusplus
}
#endif