тесты проходят добавлен mtu в link
This commit is contained in:
1 parent
69d33636bf
commit
35950c60f7
8 files changed
+35
-16
No files matched your search
+6
-2
@@ -368,6 +368,10 @@ static int parse_server(const char *key, const char *value, struct CFG_SERVER *s
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (strcmp(key, "mtu") == 0) {
|
||||
srv->mtu = atoi(value);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -647,9 +651,9 @@ void print_config(const struct utun_config *cfg) {
|
||||
struct CFG_SERVER *s = cfg->servers;
|
||||
while (s) {
|
||||
struct sockaddr_in *sin = (struct sockaddr_in *)&s->ip;
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, " %s: %s:%d (mark=%d, netif=%u, type=%u)",
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, " %s: %s:%d (mark=%d, netif=%u, type=%u, mtu=%d)",
|
||||
s->name, ip_to_str(&sin->sin_addr, AF_INET).str, ntohs(sin->sin_port),
|
||||
s->so_mark, s->netif_index, s->type);
|
||||
s->so_mark, s->netif_index, s->type, s->mtu);
|
||||
s = s->next;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ struct CFG_SERVER {
|
||||
uint32_t netif_index;// if_nameindex, 0 - no interface specified
|
||||
int so_mark;
|
||||
uint8_t type; // public/nat/private
|
||||
int mtu;
|
||||
};
|
||||
|
||||
struct CFG_CLIENT_LINK {
|
||||
|
||||
+4
-2
@@ -275,6 +275,7 @@ void etcp_conn_reset(struct ETCP_CONN* etcp) {
|
||||
// Reset timers (just clear the pointers - timers will expire naturally)
|
||||
etcp->retrans_timer = NULL;
|
||||
etcp->ack_resp_timer = NULL;
|
||||
DEBUG_TRACE(DEBUG_CATEGORY_ETCP, "end");
|
||||
}
|
||||
|
||||
// Update log_name when peer_node_id becomes known
|
||||
@@ -579,7 +580,7 @@ struct ETCP_DGRAM* etcp_request_pkt(struct ETCP_CONN* etcp) {
|
||||
size_t ack_q_size = queue_entry_count(etcp->ack_q);
|
||||
|
||||
if (!inf_pkt && ack_q_size == 0) {
|
||||
// DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "[%s] no data/ack to send", etcp->log_name);
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "[%s] no data/ack to send", etcp->log_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -669,7 +670,8 @@ struct ETCP_DGRAM* etcp_request_pkt(struct ETCP_CONN* etcp) {
|
||||
memcpy(&dgram->data[ptr], inf_pkt->ll.dgram, inf_pkt->ll.len); ptr+=inf_pkt->ll.len;
|
||||
}
|
||||
else {
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "[%s] only ACK packet with %d bytes total", etcp->log_name, dgram->data_len);
|
||||
int chk=queue_check_consistency(etcp->ack_q);
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "[%s] only ACK (size=%d) packet with %d bytes total (chk=%d) rem=%d", etcp->log_name, ack_q_size, ptr, chk, remain_len);
|
||||
}
|
||||
|
||||
dgram->data_len=ptr;
|
||||
|
||||
+17
-9
@@ -70,8 +70,8 @@ static void etcp_link_send_init(struct ETCP_LINK* link, uint8_t reset) {
|
||||
dgram->data[offset++] = (node_id >> 8) & 0xFF;
|
||||
dgram->data[offset++] = node_id & 0xFF;
|
||||
|
||||
dgram->data[offset++] = (link->mtu >> 8) & 0xFF;
|
||||
dgram->data[offset++] = link->mtu & 0xFF;
|
||||
dgram->data[offset++] = (link->mtu_local >> 8) & 0xFF;
|
||||
dgram->data[offset++] = link->mtu_local & 0xFF;
|
||||
|
||||
dgram->data[offset++] = (link->keepalive_interval >> 8) & 0xFF;
|
||||
dgram->data[offset++] = link->keepalive_interval & 0xFF;
|
||||
@@ -415,7 +415,7 @@ int etcp_find_free_local_link_id(struct ETCP_CONN* etcp) {
|
||||
|
||||
// ===============================
|
||||
|
||||
struct ETCP_SOCKET* etcp_socket_add(struct UTUN_INSTANCE* instance, struct sockaddr_storage* ip, uint32_t netif_index, int so_mark, uint8_t type) {
|
||||
struct ETCP_SOCKET* etcp_socket_add(struct UTUN_INSTANCE* instance, struct sockaddr_storage* ip, uint32_t netif_index, int so_mark, uint8_t type, int mtu) {
|
||||
DEBUG_TRACE(DEBUG_CATEGORY_CONNECTION, "");
|
||||
if (!instance) return NULL;
|
||||
|
||||
@@ -496,6 +496,7 @@ struct ETCP_SOCKET* etcp_socket_add(struct UTUN_INSTANCE* instance, struct socka
|
||||
e_sock->errorcode = 0;
|
||||
e_sock->pkt_format_errors = 0;
|
||||
e_sock->type = type;
|
||||
e_sock->mtu = mtu;
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Add Socket type=%d", type);
|
||||
|
||||
// Add to instance's socket list
|
||||
@@ -561,7 +562,10 @@ struct ETCP_LINK* etcp_link_new(struct ETCP_CONN* etcp, struct ETCP_SOCKET* conn
|
||||
link->conn = conn;
|
||||
link->etcp = etcp;
|
||||
link->is_server = is_server;
|
||||
link->mtu = 1500;
|
||||
int mtu = conn->mtu;
|
||||
if (mtu == 0) mtu = 1500;
|
||||
link->mtu_local = mtu;
|
||||
link->mtu = mtu;
|
||||
link->initialized = 0;
|
||||
link->init_timer = NULL;
|
||||
link->init_timeout = 0;
|
||||
@@ -921,6 +925,9 @@ static void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_CONNECTION, "set keepalive for link=%d", link->keepalive_interval);
|
||||
}
|
||||
|
||||
link->mtu_remote = (ack_hdr->mtu[0] << 8) | ack_hdr->mtu[1];
|
||||
link->mtu = link->mtu_local < link->mtu_remote ? link->mtu_local : link->mtu_remote;
|
||||
|
||||
struct {
|
||||
uint8_t code;
|
||||
uint8_t id[8];
|
||||
@@ -937,9 +944,9 @@ static void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
|
||||
ack_repl_hdr->code = ETCP_INIT_RESPONSE_NOINIT; // 0x05 - without reset
|
||||
}
|
||||
memcpy(ack_repl_hdr->id, &e_sock->instance->node_id, 8);
|
||||
int mtu=e_sock->instance->config->global.mtu;
|
||||
ack_repl_hdr->mtu[0]=mtu>>8;
|
||||
ack_repl_hdr->mtu[1]=mtu;
|
||||
|
||||
ack_repl_hdr->mtu[0]=link->mtu_local>>8;
|
||||
ack_repl_hdr->mtu[1]=link->mtu_local;
|
||||
ack_repl_hdr->link_id = link->local_link_id;
|
||||
// Add client's IP:port (so client behind NAT can know its external address)
|
||||
if (addr.ss_family == AF_INET) {
|
||||
@@ -1023,7 +1030,8 @@ process_decrypted:
|
||||
for (int i = 0; i < 8; i++) {
|
||||
server_node_id = (server_node_id << 8) | pkt->data[offset++];
|
||||
}
|
||||
link->mtu = (pkt->data[offset++] << 8) | pkt->data[offset++];
|
||||
link->mtu_remote = (pkt->data[offset++] << 8) | pkt->data[offset++];
|
||||
link->mtu = link->mtu_local < link->mtu_remote ? link->mtu_local : link->mtu_remote;
|
||||
link->remote_link_id = pkt->data[offset++];
|
||||
|
||||
// Parse NAT IP:port from response (new format includes 4+2 bytes)
|
||||
@@ -1143,7 +1151,7 @@ int init_connections(struct UTUN_INSTANCE* instance) {
|
||||
}
|
||||
}
|
||||
|
||||
struct ETCP_SOCKET* e_sock = etcp_socket_add(instance, &server->ip, server->netif_index, server->so_mark, server->type);
|
||||
struct ETCP_SOCKET* e_sock = etcp_socket_add(instance, &server->ip, server->netif_index, server->so_mark, server->type, server->mtu ? server->mtu : instance->config->global.mtu);
|
||||
if (e_sock && default_ip != 0) {
|
||||
struct in_addr addr;
|
||||
addr.s_addr = default_ip;
|
||||
|
||||
@@ -34,6 +34,7 @@ struct ETCP_SOCKET {
|
||||
struct UTUN_INSTANCE* instance;
|
||||
socket_t fd; // UDP socket (cross-platform)
|
||||
struct sockaddr_storage local_addr; // Локальный адрес
|
||||
int mtu; // MTU для этого сокета
|
||||
|
||||
// для входящих подключений (links) - массив упорядоченный по ip_port_hash
|
||||
size_t max_channels; // сколько выделено памяти
|
||||
@@ -59,7 +60,9 @@ struct ETCP_LINK {
|
||||
struct sockaddr_storage remote_addr; // Удалённый адрес
|
||||
|
||||
// Параметры соединения
|
||||
uint16_t mtu; // MTU удаленного узла
|
||||
uint16_t mtu; // MTU общий
|
||||
uint16_t mtu_local; // MTU моего зла
|
||||
uint16_t mtu_remote; // MTU удаленного узла
|
||||
uint16_t keepalive_interval; // Keepalive интервал (x1ms)
|
||||
uint32_t recovery_interval; // recovery интервал (x0.1ms)
|
||||
uint8_t is_server; // инициирует подключение клиент
|
||||
@@ -115,7 +118,7 @@ int init_connections(struct UTUN_INSTANCE* instance);
|
||||
|
||||
// SOCKET FUNCTIONS
|
||||
// добавляет новый версер (сокет для приёма и отправки кодограмм. обслуживает много подключений)
|
||||
struct ETCP_SOCKET* etcp_socket_add(struct UTUN_INSTANCE* instance, struct sockaddr_storage* ip, uint32_t netif_index, int so_mark, uint8_t type);
|
||||
struct ETCP_SOCKET* etcp_socket_add(struct UTUN_INSTANCE* instance, struct sockaddr_storage* ip, uint32_t netif_index, int so_mark, uint8_t type, int mtu);
|
||||
// удаляет сокет и освобождает ресурсы (грохает все его подключения и сокет)
|
||||
void etcp_socket_remove(struct ETCP_SOCKET* conn);
|
||||
|
||||
|
||||
Reference in new issue
Block a user