transport: SOCKS5-прокси для ETCP-линков (CONNECT + UDP ASSOCIATE + пинги)
This commit is contained in:
1 parent
7c8d65db78
commit
d0dfa97a47
14 files changed
+1360
-54
No files matched your search
+39
-3
@@ -53,7 +53,8 @@ typedef enum {
|
||||
SECTION_GUI,
|
||||
SECTION_NTP,
|
||||
SECTION_LOG_UDP,
|
||||
SECTION_REALITY
|
||||
SECTION_REALITY,
|
||||
SECTION_SOCKS
|
||||
} section_type_t;
|
||||
|
||||
static char* trim(char *str) {
|
||||
@@ -703,7 +704,11 @@ static int parse_server(const char *key, const char *value, struct CFG_SERVER *s
|
||||
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);
|
||||
if (strcmp(key, "socks") == 0) {
|
||||
srv->socks_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, socks", filename, line_num, key);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -912,9 +917,35 @@ static int parse_reality(const char *key, const char *value, struct reality_conf
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Разбор [socks] секции: прокси для исходящих ETCP-линков.
|
||||
static int parse_socks(const char *key, const char *value, struct global_config *global, const char *filename, int line_num) {
|
||||
if (strcmp(key, "enabled") == 0) {
|
||||
global->socks_enabled = strcasecmp(value, "yes") == 0 || strcasecmp(value, "1") == 0 || strcasecmp(value, "true") == 0;
|
||||
return 0;
|
||||
}
|
||||
if (strcmp(key, "addr") == 0) {
|
||||
const char *colon = strrchr(value, ':');
|
||||
if (!colon) { DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "%s:%d: socks addr must be 'host:port'", filename, line_num); return -1; }
|
||||
int port = atoi(colon + 1);
|
||||
if (port <= 0 || port > 65535) { DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "%s:%d: bad socks port '%s'", filename, line_num, colon + 1); return -1; }
|
||||
char host[64];
|
||||
size_t hlen = (size_t)(colon - value);
|
||||
if (hlen >= sizeof(host)) hlen = sizeof(host) - 1;
|
||||
memcpy(host, value, hlen); host[hlen] = '\0';
|
||||
if (hlen >= 2 && host[0] == '[' && host[hlen - 1] == ']') { host[hlen - 1] = '\0'; memmove(host, host + 1, strlen(host)); }
|
||||
strncpy(global->socks_host, host, sizeof(global->socks_host) - 1);
|
||||
global->socks_host[sizeof(global->socks_host) - 1] = '\0';
|
||||
global->socks_port = (uint16_t)port;
|
||||
return 0;
|
||||
}
|
||||
if (strcmp(key, "username") == 0) return assign_string(global->socks_username, sizeof(global->socks_username), value);
|
||||
if (strcmp(key, "password") == 0) return assign_string(global->socks_password, sizeof(global->socks_password), value);
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "%s:%d: Unknown socks option '%s'. Valid: enabled, addr, username, password", filename, line_num, key);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static section_type_t parse_section_header(const char *line, char *name, size_t name_len) {
|
||||
if (line[0] != '[') return SECTION_UNKNOWN;
|
||||
|
||||
size_t line_len = strlen(line);
|
||||
if (line[line_len - 1] != ']') return SECTION_UNKNOWN;
|
||||
|
||||
@@ -940,6 +971,7 @@ static section_type_t parse_section_header(const char *line, char *name, size_t
|
||||
if (strcasecmp(section, "gui") == 0) return SECTION_GUI;
|
||||
if (strcasecmp(section, "log_udp") == 0) return SECTION_LOG_UDP;
|
||||
if (strcasecmp(section, "reality") == 0) return SECTION_REALITY;
|
||||
if (strcasecmp(section, "socks") == 0) return SECTION_SOCKS;
|
||||
|
||||
char *colon = strchr(section, ':');
|
||||
if (!colon) return SECTION_UNKNOWN;
|
||||
@@ -1208,6 +1240,9 @@ static struct utun_config* parse_config_internal(FILE *fp, const char *filename)
|
||||
case SECTION_REALITY:
|
||||
parse_reality(key, value, &cfg->global.reality, filename, line_num);
|
||||
break;
|
||||
case SECTION_SOCKS:
|
||||
parse_socks(key, value, &cfg->global, filename, line_num);
|
||||
break;
|
||||
default:
|
||||
DEBUG_WARN(DEBUG_CATEGORY_CONFIG, "%s:%d: Key outside section: %s", filename, line_num, key);
|
||||
break;
|
||||
@@ -1359,6 +1394,7 @@ struct utun_config* parse_config_from_buf(const char *buf, size_t len, const cha
|
||||
case SECTION_CHATSERVER: cfg->global.chatserver_enabled = 1; cfg->global.db_sync_enabled = 1; if (strcmp(key, "db_path") == 0) assign_string(cfg->global.db_path, sizeof(cfg->global.db_path), value); else if (parse_chatserver(key, value, &cfg->global, filename, line_num) < 0 && chat_setting_set(key, value) < 0) { DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "%s:%d: Unknown chatserver option '%s'. Valid: db_path, join_password, allowed_groups, storage_total_size, storage_unit_size, storage_autoload, opus_codec_preset, compressor_enabled, compressor_max_gain_db, compressor_rise_rate, media_download_max_peers", filename, line_num, key); } break;
|
||||
case SECTION_GUI: break;
|
||||
case SECTION_REALITY: parse_reality(key, value, &cfg->global.reality, filename, line_num); break;
|
||||
case SECTION_SOCKS: parse_socks(key, value, &cfg->global, filename, line_num); break;
|
||||
case SECTION_LOG_UDP:
|
||||
if (strcmp(key, "ip") == 0) strncpy(cfg->global.log_udp_ip, value, sizeof(cfg->global.log_udp_ip) - 1);
|
||||
else if (strcmp(key, "port") == 0) cfg->global.log_udp_port = atoi(value);
|
||||
|
||||
Reference in new issue
Block a user