tcp_proxy_server: add fib/so_mark/netif/bind_ip socket options
This commit is contained in:
1 parent
544c77efff
commit
5a404fbc97
4 files changed
+51
-1
No files matched your search
@@ -13,6 +13,7 @@
|
||||
#include "../lib/ll_queue.h"
|
||||
#include "../lib/mem.h"
|
||||
#include "../lib/tcp_io.h"
|
||||
#include "../lib/socket_compat.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
@@ -21,6 +22,7 @@
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <net/if.h>
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
@@ -372,6 +374,29 @@ int tcp_proxy_server_handle_connect(struct UTUN_INSTANCE* inst, struct ll_entry*
|
||||
(int)sock, stream_id, dest_ip[0],dest_ip[1],dest_ip[2],dest_ip[3],ntohs(dest_port), ctx->conn_count);
|
||||
socket_set_nonblocking(sock);
|
||||
|
||||
struct global_config* g = &inst->config->global;
|
||||
if (g->tcp_proxy_server_bind_ip[0]) {
|
||||
struct sockaddr_in local_addr = {.sin_family = AF_INET, .sin_port = 0};
|
||||
if (inet_pton(AF_INET, g->tcp_proxy_server_bind_ip, &local_addr.sin_addr) == 1) {
|
||||
if (bind(sock, (struct sockaddr*)&local_addr, sizeof(local_addr)) < 0) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_PROXY, "TCP proxy server: bind(%s) failed: %s", g->tcp_proxy_server_bind_ip, strerror(errno));
|
||||
socket_close_wrapper(sock); ctx->conn_count--; u_free(rc); queue_dgram_free(entry); queue_entry_free(entry); return -1;
|
||||
}
|
||||
} else {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_PROXY, "TCP proxy server: invalid bind_ip=%s", g->tcp_proxy_server_bind_ip);
|
||||
}
|
||||
}
|
||||
if (g->tcp_proxy_server_so_mark > 0) socket_set_mark(sock, g->tcp_proxy_server_so_mark);
|
||||
#ifdef __FreeBSD__
|
||||
if (g->tcp_proxy_server_fib > 0) {
|
||||
setsockopt(sock, SOL_SOCKET, SO_SETFIB, &g->tcp_proxy_server_fib, sizeof(g->tcp_proxy_server_fib));
|
||||
}
|
||||
#endif
|
||||
if (g->tcp_proxy_server_netif_index > 0) {
|
||||
char ifname[IF_NAMESIZE];
|
||||
if (if_indextoname(g->tcp_proxy_server_netif_index, ifname)) socket_bind_to_device(sock, ifname);
|
||||
}
|
||||
|
||||
rc->tc = tcp_conn_create(inst->ua, sock, 1500, 8192, 4, 0, inst->config->global.tcp_recv_buf, on_fin_cb, on_error_cb, rc);
|
||||
if (!rc->tc) { DEBUG_ERROR(DEBUG_CATEGORY_PROXY, "TCP proxy server: tcp_conn_create failed"); socket_close_wrapper(sock); ctx->conn_count--; u_free(rc); queue_dgram_free(entry); queue_entry_free(entry); return -1; }
|
||||
rc->tc->on_closed = on_closed_cb;
|
||||
|
||||
Reference in new issue
Block a user