reality: конфиг [client] для REALITY-клиентов (server_name/short_id/public_key/version/fingerprint) + TCP-линки через NCD
This commit is contained in:
1 parent
58d55dd56e
commit
abb9ff5441
10 files changed
+228
-332
No files matched your search
+57
-23
@@ -700,7 +700,7 @@ static int parse_server(const char *key, const char *value, struct CFG_SERVER *s
|
||||
return 0;
|
||||
}
|
||||
if (strcmp(key, "reality") == 0) {
|
||||
srv->reality_enabled = atoi(value) ? 1 : 0;
|
||||
srv->reality_enabled = strcasecmp(value, "yes") == 0 || strcasecmp(value, "1") == 0 || strcasecmp(value, "true") == 0;
|
||||
return 0;
|
||||
}
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "%s:%d: Unknown server option '%s'. Valid: addr, so_mark, fib, netif, type, mtu, only_local, transport, reality", filename, line_num, key);
|
||||
@@ -712,40 +712,73 @@ static int parse_client(const char *key, const char *value, struct CFG_CLIENT *c
|
||||
char link_copy[MAX_CONN_NAME_LEN + MAX_ADDR_LEN];
|
||||
if (strlen(value) >= sizeof(link_copy)) return -1;
|
||||
strcpy(link_copy, value);
|
||||
|
||||
// Find first colon (separator between server and ip:port)
|
||||
|
||||
// Первый ':' отделяет (опциональное) имя локального сокета от ip:port.
|
||||
// Если токен до ':' не является именем [server] — трактуем всю строку как
|
||||
// ip:port (remote-only, без локального bind-сокета).
|
||||
char *first_colon = strchr(link_copy, ':');
|
||||
if (!first_colon) return -1;
|
||||
|
||||
*first_colon = '\0';
|
||||
|
||||
// Find server by name
|
||||
struct CFG_SERVER *local_srv = find_server_by_name(servers, link_copy);
|
||||
if (!local_srv) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "parse_client: server '%s' not found for client link", link_copy);
|
||||
return -1;
|
||||
struct CFG_SERVER *local_srv = NULL;
|
||||
const char *remote = value;
|
||||
if (first_colon) {
|
||||
*first_colon = '\0';
|
||||
local_srv = find_server_by_name(servers, link_copy);
|
||||
if (local_srv) remote = first_colon + 1;
|
||||
}
|
||||
|
||||
struct CFG_CLIENT_LINK *new_link = create_client_link(local_srv, first_colon + 1);
|
||||
|
||||
struct CFG_CLIENT_LINK *new_link = create_client_link(local_srv, remote);
|
||||
if (!new_link) return -1;
|
||||
|
||||
|
||||
// Add to linked list (prepend)
|
||||
new_link->next = cli->links;
|
||||
cli->links = new_link;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (strcmp(key, "peer_public_key") == 0) {
|
||||
return assign_string(cli->peer_public_key_hex, MAX_KEY_LEN, value);
|
||||
}
|
||||
|
||||
|
||||
if (strcmp(key, "keepalive") == 0) {
|
||||
cli->keepalive = atoi(value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "%s:%d: Unknown client option '%s'. Valid: link, peer_public_key, keepalive", filename, line_num, key);
|
||||
|
||||
if (strcmp(key, "reality") == 0) {
|
||||
cli->reality_enabled = strcasecmp(value, "yes") == 0 || strcasecmp(value, "1") == 0 || strcasecmp(value, "true") == 0;
|
||||
return 0;
|
||||
}
|
||||
if (strcmp(key, "server_name") == 0) { return assign_string(cli->reality.server_name, sizeof(cli->reality.server_name), value); }
|
||||
if (strcmp(key, "short_id") == 0) {
|
||||
if (hex_to_binary(value, cli->reality.short_id, REALITY_SHORT_ID_SIZE) < 0) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "%s:%d: client reality short_id must be %d hex chars", filename, line_num, REALITY_SHORT_ID_SIZE * 2);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (strcmp(key, "public_key") == 0) {
|
||||
if (hex_to_binary(value, cli->reality.server_static_pubkey, REALITY_AUTH_KEY_SIZE) < 0) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "%s:%d: client reality public_key must be %d hex chars", filename, line_num, REALITY_AUTH_KEY_SIZE * 2);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (strcmp(key, "version") == 0) {
|
||||
int x = 0, y = 0, z = 0;
|
||||
if (sscanf(value, "%d.%d.%d", &x, &y, &z) != 3 || x < 0 || x > 255 || y < 0 || y > 255 || z < 0 || z > 255) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "%s:%d: bad client reality version '%s' (expected x.y.z)", filename, line_num, value);
|
||||
return -1;
|
||||
}
|
||||
cli->reality.version[0] = (uint8_t)x; cli->reality.version[1] = (uint8_t)y; cli->reality.version[2] = (uint8_t)z;
|
||||
return 0;
|
||||
}
|
||||
if (strcmp(key, "fingerprint") == 0) {
|
||||
if (strcmp(value, "chrome") == 0) { cli->reality.fingerprint = REALITY_FP_CHROME; return 0; }
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "%s:%d: unknown client reality fingerprint '%s' (valid: chrome)", filename, line_num, value);
|
||||
return -1;
|
||||
}
|
||||
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "%s:%d: Unknown client option '%s'. Valid: link, peer_public_key, keepalive, reality, server_name, short_id, public_key, version, fingerprint", filename, line_num, key);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1012,6 +1045,7 @@ static struct utun_config* parse_config_internal(FILE *fp, const char *filename)
|
||||
goto error;
|
||||
}
|
||||
strcpy(cur_client->name, name);
|
||||
reality_client_config_set_defaults(&cur_client->reality);
|
||||
} else if (cur_section == SECTION_NETWORK) {
|
||||
cur_network = u_calloc(1, sizeof(struct CFG_NETWORK));
|
||||
if (!cur_network) {
|
||||
@@ -1284,7 +1318,7 @@ struct utun_config* parse_config_from_buf(const char *buf, size_t len, const cha
|
||||
char name[MAX_CONN_NAME_LEN];
|
||||
cur_section = parse_section_header(trimmed, name, sizeof(name));
|
||||
if (cur_section == SECTION_SERVER) { cur_server = u_calloc(1, sizeof(struct CFG_SERVER)); if (!cur_server) goto error; strcpy(cur_server->name, name); cur_server->fib = -1; }
|
||||
else if (cur_section == SECTION_CLIENT) { cur_client = u_calloc(1, sizeof(struct CFG_CLIENT)); if (!cur_client) goto error; strcpy(cur_client->name, name); }
|
||||
else if (cur_section == SECTION_CLIENT) { cur_client = u_calloc(1, sizeof(struct CFG_CLIENT)); if (!cur_client) goto error; strcpy(cur_client->name, name); reality_client_config_set_defaults(&cur_client->reality); }
|
||||
else if (cur_section == SECTION_NETWORK) { cur_network = u_calloc(1, sizeof(struct CFG_NETWORK)); if (!cur_network) goto error; strcpy(cur_network->name, name); }
|
||||
continue;
|
||||
}
|
||||
@@ -1453,12 +1487,12 @@ void print_config(const struct utun_config *cfg) {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, "Clients:");
|
||||
struct CFG_CLIENT *c = cfg->clients;
|
||||
while (c) {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, " %s: peer_key=%s, keepalive=%d", c->name, c->peer_public_key_hex, c->keepalive);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, " %s: peer_key=%s, keepalive=%d, reality=%d", c->name, c->peer_public_key_hex, c->keepalive, c->reality_enabled);
|
||||
struct CFG_CLIENT_LINK *link = c->links;
|
||||
while (link) {
|
||||
ip_str_t addr_str = sockaddr_storage_to_str(&link->remote_addr);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, " Link: %s (via %s)",
|
||||
addr_str.str, link->local_srv->name);
|
||||
addr_str.str, link->local_srv ? link->local_srv->name : "auto");
|
||||
link = link->next;
|
||||
}
|
||||
c = c->next;
|
||||
|
||||
Reference in new issue
Block a user