-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathclient.h
More file actions
197 lines (161 loc) · 5.71 KB
/
Copy pathclient.h
File metadata and controls
197 lines (161 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// SPDX-License-Identifier: GPL-3.0-only
/*
* Copyright (c) 2023 Dengfeng Liu <liudf0716@gmail.com>
*/
#ifndef XFRPC_CLIENT_H
#define XFRPC_CLIENT_H
#include <stdint.h>
#include "uthash.h"
#include "common.h"
#include "tcpmux.h"
/* Forward declarations for crypto stream types */
struct crypto_ctx;
struct snappy_ctx;
/* Constants */
#define SOCKS5_ADDRES_LEN 20
/* Per-client parser buffer initial capacity */
#define SOCKS5_BUF_INIT_CAP 256
#define XDPI_BUF_INIT_CAP 4096
enum xdpi_service_type {
NO_XDPI,
SERVICE_MSTSC,
SERVICE_RDP,
SERVICE_VNC,
SERVICE_SSH,
SERVICE_TELNET,
SERVICE_HTTP,
SERVICE_HTTPS,
};
/* Data Structures */
struct socks5_addr {
uint8_t addr[SOCKS5_ADDRES_LEN];
uint16_t port;
uint8_t type;
uint8_t reserve;
};
enum socks5_state {
SOCKS5_INIT,
SOCKS5_HANDSHAKE,
SOCKS5_CONNECT,
SOCKS5_ESTABLISHED,
};
enum xdpi_state {
XDPI_INIT, /* Initial state, waiting for first data */
XDPI_VERIFIED, /* Protocol verified successfully */
XDPI_BLOCKED, /* Protocol verification failed, connection blocked */
};
struct proxy_client {
/* Event handling */
struct event_base *base;
struct bufferevent *ctl_bev; /* xfrpc proxy <---> frps */
struct bufferevent *local_proxy_bev; /* xfrpc proxy <---> local service */
/* Configuration */
struct base_conf *bconf;
struct proxy_service *ps;
void *visitor_ctx; /* visitor_session backpointer */
/* Stream handling */
struct tmux_stream stream;
uint32_t stream_id;
/* State flags */
int connected;
int work_started;
int pending_close; /* local proxy closed, waiting for WUP to send FIN */
enum xdpi_state xdpi_state; /* XDPI verification state */
/* SOCKS5 specific */
struct socks5_addr remote_addr;
enum socks5_state state;
/* Initial payload from control message (TypeStartWorkConn) */
unsigned char *data_tail;
size_t data_tail_size;
/* Encrypted-but-unsent data when the mux window is exhausted; kept
* separately so it is never re-encrypted on the next read callback */
struct evbuffer *enc_pending;
/* Per-client receive buffers (replace rx_ring for protocol parsing) */
uint8_t *socks5_buf; /* SOCKS5 parser staging buffer */
size_t socks5_buf_len;
size_t socks5_buf_cap;
uint8_t *xdpi_buf; /* XDPI pre-connect staging buffer */
size_t xdpi_buf_len;
size_t xdpi_buf_cap;
/* Hash handling */
UT_hash_handle hh;
/* Encryption state (populated from proxy_service) */
int use_encryption;
int use_compression;
struct crypto_ctx *encrypt_ctx; /* AES-128-CFB writer context */
struct crypto_ctx *decrypt_ctx; /* AES-128-CFB reader context */
/* Last UDP peer addresses from TypeUDPPacket (needed for replies) */
char *udp_laddr;
int udp_lport;
char *udp_lzone;
char *udp_raddr;
int udp_rport;
char *udp_rzone;
};
struct proxy_service {
/* Basic configuration */
char *proxy_name;
char *proxy_type;
int use_encryption;
int use_compression;
/* Network configuration */
char *local_ip;
char *bind_addr;
int remote_port;
int remote_data_port;
int local_port;
/* Time control */
int start_time; /* Start time (0-23) */
int end_time; /* End time (0-23) */
/* XDPI service type */
enum xdpi_service_type service_type;
/* HTTP/HTTPS specific */
char *custom_domains;
char *subdomain;
char *locations;
char *host_header_rewrite;
char *http_user;
char *http_pwd;
char *request_headers; /* comma-separated key=value pairs */
char *response_headers; /* comma-separated key=value pairs */
char *s_root_dir;
/* Load balancing */
char *group;
char *group_key;
/* Plugin configuration */
char *plugin;
char *plugin_user;
char *plugin_pwd;
/* TCPMux specific */
char *multiplexer; /* Multiplexer type (e.g. "httpconnect") */
char *route_by_http_user; /* Route by HTTP user for tcpmux */
/* STCP/XTCP/SUDP specific */
char *sk; /* Secret key for stcp/xtcp/sudp */
char *allow_users; /* Comma-separated list of allowed visitor users */
/* Unix Domain Socket plugin specific */
char *plugin_unix_path; /* Unix socket path for unix_domain_socket plugin */
/* Health check configuration */
char *health_check_type; /* "tcp" or "http" (NULL = disabled) */
char *health_check_url; /* URL path for HTTP health check (default "/") */
int health_check_interval; /* Seconds between checks (default 10) */
int health_check_timeout; /* Per-check timeout in seconds (default 3) */
int health_check_max_failed; /* Consecutive failures before marking down (default 1) */
/* Hash handling */
UT_hash_handle hh;
};
/* Function prototypes */
void start_xfrp_tunnel(struct proxy_client *client);
void del_proxy_client_by_stream_id(uint32_t sid);
struct proxy_client *get_proxy_client(uint32_t sid);
int send_client_data_tail(struct proxy_client *client);
int is_socks5_proxy(const struct proxy_service *ps);
int is_udp_proxy(const struct proxy_service *ps);
int is_tcpmux_proxy(const struct proxy_service *ps);
int is_stcp_proxy(const struct proxy_service *ps);
int is_uds_proxy(const struct proxy_service *ps);
int has_service_type(const struct proxy_service *ps);
struct proxy_client *new_proxy_client(void);
void clear_all_proxy_client(void);
void xfrp_proxy_event_cb(struct bufferevent *bev, short what, void *ctx);
int xdpi_engine(struct proxy_client *client, const unsigned char *data, size_t len);
#endif // XFRPC_CLIENT_H