mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-10-14 02:22:03 +08:00
Added the net-priority configuration option.
That option allows setting the protocol-defined priority (via SO_PRIORITY) for the UDP and TCP sockets, per user/group or globally.
This commit is contained in:
@@ -173,6 +173,10 @@ ping-leases = false
|
|||||||
# Setting it higher will improve throughput.
|
# Setting it higher will improve throughput.
|
||||||
output-buffer = 10
|
output-buffer = 10
|
||||||
|
|
||||||
|
# Set the protocol-defined priority (SO_PRIORITY) for packets to
|
||||||
|
# be sent. This can be set per user/group or globally.
|
||||||
|
#net-priority = 3
|
||||||
|
|
||||||
route = 192.168.1.0/255.255.255.0
|
route = 192.168.1.0/255.255.255.0
|
||||||
#route = 192.168.5.0/255.255.255.0
|
#route = 192.168.5.0/255.255.255.0
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -38,7 +38,7 @@ ocserv-args.h: ocserv-args.c
|
|||||||
|
|
||||||
ocserv_SOURCES = main.c main-auth.c worker-vpn.c worker-auth.c tlslib.c \
|
ocserv_SOURCES = main.c main-auth.c worker-vpn.c worker-auth.c tlslib.c \
|
||||||
ipc.h cookies.c worker-tun.c main-misc.c \
|
ipc.h cookies.c worker-tun.c main-misc.c \
|
||||||
main-config.c ip-lease.c ip-lease.h \
|
group-config.c ip-lease.c ip-lease.h \
|
||||||
vpn.h cookies.h tlslib.h log.c tun.c tun.h \
|
vpn.h cookies.h tlslib.h log.c tun.c tun.h \
|
||||||
config.c pam.c pam.h worker-resume.c worker.h main-resume.c main.h \
|
config.c pam.c pam.h worker-resume.c worker.h main-resume.c main.h \
|
||||||
worker-extras.c main-auth.h html.c html.h \
|
worker-extras.c main-auth.h html.c html.h \
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ static struct cfg_options available_options[] = {
|
|||||||
{ .name = "tls-priorities", .type = OPTION_STRING, .mandatory = 0 },
|
{ .name = "tls-priorities", .type = OPTION_STRING, .mandatory = 0 },
|
||||||
{ .name = "chroot-dir", .type = OPTION_STRING, .mandatory = 0 },
|
{ .name = "chroot-dir", .type = OPTION_STRING, .mandatory = 0 },
|
||||||
{ .name = "mtu", .type = OPTION_NUMERIC, .mandatory = 0 },
|
{ .name = "mtu", .type = OPTION_NUMERIC, .mandatory = 0 },
|
||||||
|
{ .name = "net-priority", .type = OPTION_NUMERIC, .mandatory = 0 },
|
||||||
{ .name = "output-buffer", .type = OPTION_NUMERIC, .mandatory = 0 },
|
{ .name = "output-buffer", .type = OPTION_NUMERIC, .mandatory = 0 },
|
||||||
{ .name = "cookie-validity", .type = OPTION_NUMERIC, .mandatory = 1 },
|
{ .name = "cookie-validity", .type = OPTION_NUMERIC, .mandatory = 1 },
|
||||||
{ .name = "auth-timeout", .type = OPTION_NUMERIC, .mandatory = 0 },
|
{ .name = "auth-timeout", .type = OPTION_NUMERIC, .mandatory = 0 },
|
||||||
@@ -317,6 +318,7 @@ unsigned prefix = 0;
|
|||||||
READ_STRING("chroot-dir", config->chroot_dir);
|
READ_STRING("chroot-dir", config->chroot_dir);
|
||||||
|
|
||||||
READ_NUMERIC("mtu", config->default_mtu);
|
READ_NUMERIC("mtu", config->default_mtu);
|
||||||
|
READ_NUMERIC("net-priority", config->net_priority);
|
||||||
READ_NUMERIC("output-buffer", config->output_buffer);
|
READ_NUMERIC("output-buffer", config->output_buffer);
|
||||||
|
|
||||||
READ_NUMERIC("rx-data-per-sec", config->rx_per_sec);
|
READ_NUMERIC("rx-data-per-sec", config->rx_per_sec);
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ static struct cfg_options available_options[] = {
|
|||||||
{ .name = "ipv6-netmask", .type = OPTION_STRING },
|
{ .name = "ipv6-netmask", .type = OPTION_STRING },
|
||||||
{ .name = "rx-data-per-sec", .type = OPTION_NUMERIC, },
|
{ .name = "rx-data-per-sec", .type = OPTION_NUMERIC, },
|
||||||
{ .name = "tx-data-per-sec", .type = OPTION_NUMERIC, },
|
{ .name = "tx-data-per-sec", .type = OPTION_NUMERIC, },
|
||||||
|
{ .name = "net-priority", .type = OPTION_NUMERIC, },
|
||||||
};
|
};
|
||||||
|
|
||||||
#define READ_RAW_MULTI_LINE(name, s_name, num) \
|
#define READ_RAW_MULTI_LINE(name, s_name, num) \
|
||||||
@@ -148,6 +149,11 @@ unsigned prefix = 0;
|
|||||||
READ_RAW_NUMERIC("tx-data-per-sec", config->tx_per_sec);
|
READ_RAW_NUMERIC("tx-data-per-sec", config->tx_per_sec);
|
||||||
config->rx_per_sec /= 1000; /* in kb */
|
config->rx_per_sec /= 1000; /* in kb */
|
||||||
config->tx_per_sec /= 1000; /* in kb */
|
config->tx_per_sec /= 1000; /* in kb */
|
||||||
|
|
||||||
|
/* net-priority will contain the actual priority + 1,
|
||||||
|
* to allow having zero as uninitialized. */
|
||||||
|
READ_RAW_NUMERIC("net-priority", config->net_priority);
|
||||||
|
config->net_priority++;
|
||||||
|
|
||||||
optionUnloadNested(pov);
|
optionUnloadNested(pov);
|
||||||
|
|
||||||
+7
-2
@@ -86,7 +86,7 @@ static int send_value_length(main_server_st* s, struct proc_st* proc, const void
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
int serialize_additional_data(main_server_st* s, struct proc_st* proc)
|
int serialize_additional_config(main_server_st* s, struct proc_st* proc)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
@@ -149,6 +149,11 @@ str_st buffer;
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
t = proc->config.net_priority;
|
||||||
|
ret = str_append_data(&buffer, &t, sizeof(t));
|
||||||
|
if (ret < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
/* routes */
|
/* routes */
|
||||||
len = proc->config.routes_size;
|
len = proc->config.routes_size;
|
||||||
ret = str_append_data(&buffer, &len, 1);
|
ret = str_append_data(&buffer, &len, 1);
|
||||||
@@ -244,7 +249,7 @@ int send_auth_reply(main_server_st* s, struct proc_st* proc,
|
|||||||
mslog(s, proc, LOG_ERR, "auth_reply: write: %s", strerror(e));
|
mslog(s, proc, LOG_ERR, "auth_reply: write: %s", strerror(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = serialize_additional_data(s, proc);
|
ret = serialize_additional_config(s, proc);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -247,6 +247,10 @@ unsigned i;
|
|||||||
proc->config.tx_per_sec = cfg.tx_per_sec;
|
proc->config.tx_per_sec = cfg.tx_per_sec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (proc->config.net_priority == 0) {
|
||||||
|
proc->config.net_priority = cfg.net_priority;
|
||||||
|
}
|
||||||
|
|
||||||
del_additional_config(&cfg);
|
del_additional_config(&cfg);
|
||||||
|
|
||||||
} else
|
} else
|
||||||
|
|||||||
@@ -271,6 +271,10 @@ ping-leases = false
|
|||||||
# Setting it higher will improve throughput.
|
# Setting it higher will improve throughput.
|
||||||
output-buffer = 10
|
output-buffer = 10
|
||||||
|
|
||||||
|
# Set the protocol-defined priority (SO_PRIORITY) for packets to
|
||||||
|
# be sent. This can be set per user/group or globally.
|
||||||
|
#net-priority = 3
|
||||||
|
|
||||||
# Routes to be forwarded to the client. If you need the
|
# Routes to be forwarded to the client. If you need the
|
||||||
# client to forward routes to the server, you may use the connect
|
# client to forward routes to the server, you may use the connect
|
||||||
# and disconnect scripts.
|
# and disconnect scripts.
|
||||||
|
|||||||
@@ -101,6 +101,8 @@ struct group_cfg_st {
|
|||||||
|
|
||||||
size_t rx_per_sec;
|
size_t rx_per_sec;
|
||||||
size_t tx_per_sec;
|
size_t tx_per_sec;
|
||||||
|
|
||||||
|
unsigned net_priority;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct vpn_st {
|
struct vpn_st {
|
||||||
@@ -165,6 +167,7 @@ struct cfg_st {
|
|||||||
|
|
||||||
size_t rx_per_sec;
|
size_t rx_per_sec;
|
||||||
size_t tx_per_sec;
|
size_t tx_per_sec;
|
||||||
|
unsigned net_priority;
|
||||||
|
|
||||||
unsigned output_buffer;
|
unsigned output_buffer;
|
||||||
unsigned default_mtu;
|
unsigned default_mtu;
|
||||||
|
|||||||
+8
-2
@@ -285,7 +285,7 @@ uint16_t len;
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
int deserialize_additional_data(worker_st* ws)
|
int deserialize_additional_config(worker_st* ws)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
@@ -347,6 +347,12 @@ uint32_t t;
|
|||||||
|
|
||||||
ws->tx_per_sec = t;
|
ws->tx_per_sec = t;
|
||||||
|
|
||||||
|
ret = str_read_data(&b, &t, sizeof(t));
|
||||||
|
if (ret < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
ws->net_priority = t;
|
||||||
|
|
||||||
ws->routes_size = b.data[0];
|
ws->routes_size = b.data[0];
|
||||||
b.length--;
|
b.length--;
|
||||||
b.data++;
|
b.data++;
|
||||||
@@ -443,7 +449,7 @@ static int recv_auth_reply(worker_st *ws, struct cmd_auth_reply_msg_st* mresp)
|
|||||||
|
|
||||||
/* Read any additional data */
|
/* Read any additional data */
|
||||||
|
|
||||||
ret = deserialize_additional_data(ws);
|
ret = deserialize_additional_config(ws);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
oclog(ws, LOG_ERR, "recv_auth_reply: deserialize failed");
|
oclog(ws, LOG_ERR, "recv_auth_reply: deserialize failed");
|
||||||
return ERR_AUTH_FAIL;
|
return ERR_AUTH_FAIL;
|
||||||
|
|||||||
+33
-7
@@ -791,6 +791,7 @@ unsigned tls_pending, dtls_pending = 0, i;
|
|||||||
time_t udp_recv_time = 0, now;
|
time_t udp_recv_time = 0, now;
|
||||||
struct timespec tnow;
|
struct timespec tnow;
|
||||||
unsigned mtu_overhead = 0;
|
unsigned mtu_overhead = 0;
|
||||||
|
int sndbuf;
|
||||||
socklen_t sl;
|
socklen_t sl;
|
||||||
bandwidth_st b_tx;
|
bandwidth_st b_tx;
|
||||||
bandwidth_st b_rx;
|
bandwidth_st b_rx;
|
||||||
@@ -850,6 +851,14 @@ bandwidth_st b_rx;
|
|||||||
alarm(0);
|
alarm(0);
|
||||||
http_req_deinit(ws);
|
http_req_deinit(ws);
|
||||||
|
|
||||||
|
/* set defaults */
|
||||||
|
if (ws->rx_per_sec == 0)
|
||||||
|
ws->rx_per_sec = ws->config->rx_per_sec;
|
||||||
|
if (ws->tx_per_sec == 0)
|
||||||
|
ws->tx_per_sec = ws->config->tx_per_sec;
|
||||||
|
if (ws->net_priority == 0)
|
||||||
|
ws->net_priority = ws->config->net_priority;
|
||||||
|
|
||||||
tls_cork(ws->session);
|
tls_cork(ws->session);
|
||||||
ret = tls_puts(ws->session, "HTTP/1.1 200 CONNECTED\r\n");
|
ret = tls_puts(ws->session, "HTTP/1.1 200 CONNECTED\r\n");
|
||||||
SEND_ERR(ret);
|
SEND_ERR(ret);
|
||||||
@@ -915,7 +924,6 @@ bandwidth_st b_rx;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (i=0;i<vinfo.routes_size;i++) {
|
for (i=0;i<vinfo.routes_size;i++) {
|
||||||
if (req->no_ipv6 != 0 && strchr(vinfo.routes[i], ':') != 0)
|
if (req->no_ipv6 != 0 && strchr(vinfo.routes[i], ':') != 0)
|
||||||
continue;
|
continue;
|
||||||
@@ -983,8 +991,22 @@ bandwidth_st b_rx;
|
|||||||
ws->conn_mtu = MIN(ws->conn_mtu, max-mtu_overhead);
|
ws->conn_mtu = MIN(ws->conn_mtu, max-mtu_overhead);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* set TCP socket options */
|
||||||
|
if (ws->config->output_buffer > 0) {
|
||||||
|
sndbuf = ws->conn_mtu * ws->config->output_buffer;
|
||||||
|
ret = setsockopt( ws->conn_fd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf));
|
||||||
|
if (ret == -1)
|
||||||
|
oclog(ws, LOG_DEBUG, "setsockopt(TCP, SO_SNDBUF) to %u, failed.", sndbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ws->net_priority != 0) {
|
||||||
|
l = ws->net_priority - 1;
|
||||||
|
ret = setsockopt( ws->conn_fd, SOL_SOCKET, SO_PRIORITY, &l, sizeof(l));
|
||||||
|
if (ret == -1)
|
||||||
|
oclog(ws, LOG_DEBUG, "setsockopt(TCP, SO_PRIORITY) to %d, failed.", l);
|
||||||
|
}
|
||||||
|
|
||||||
if (ws->udp_state != UP_DISABLED) {
|
if (ws->udp_state != UP_DISABLED) {
|
||||||
int sndbuf;
|
|
||||||
|
|
||||||
p = (char*)ws->buffer;
|
p = (char*)ws->buffer;
|
||||||
for (i=0;i<sizeof(ws->session_id);i++) {
|
for (i=0;i<sizeof(ws->session_id);i++) {
|
||||||
@@ -1032,6 +1054,15 @@ bandwidth_st b_rx;
|
|||||||
if (ws->config->output_buffer > 0) {
|
if (ws->config->output_buffer > 0) {
|
||||||
sndbuf = ws->conn_mtu * ws->config->output_buffer;
|
sndbuf = ws->conn_mtu * ws->config->output_buffer;
|
||||||
setsockopt( ws->udp_fd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf));
|
setsockopt( ws->udp_fd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf));
|
||||||
|
if (ret == -1)
|
||||||
|
oclog(ws, LOG_DEBUG, "setsockopt(UDP, SO_SNDBUF) to %u, failed.", sndbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ws->net_priority != 0) {
|
||||||
|
l = ws->net_priority - 1;
|
||||||
|
ret = setsockopt( ws->udp_fd, SOL_SOCKET, SO_PRIORITY, &l, sizeof(l));
|
||||||
|
if (ret == -1)
|
||||||
|
oclog(ws, LOG_DEBUG, "setsockopt(UDP, SO_PRIORITY) to %d, failed.", l);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
dtls_mtu = 0;
|
dtls_mtu = 0;
|
||||||
@@ -1071,11 +1102,6 @@ bandwidth_st b_rx;
|
|||||||
gettime(&tnow);
|
gettime(&tnow);
|
||||||
ws->last_msg_tcp = ws->last_msg_udp = tnow.tv_sec;
|
ws->last_msg_tcp = ws->last_msg_udp = tnow.tv_sec;
|
||||||
|
|
||||||
if (ws->rx_per_sec == 0)
|
|
||||||
ws->rx_per_sec = ws->config->rx_per_sec;
|
|
||||||
if (ws->tx_per_sec == 0)
|
|
||||||
ws->tx_per_sec = ws->config->tx_per_sec;
|
|
||||||
|
|
||||||
bandwidth_init(&b_rx, ws->rx_per_sec);
|
bandwidth_init(&b_rx, ws->rx_per_sec);
|
||||||
bandwidth_init(&b_tx, ws->tx_per_sec);
|
bandwidth_init(&b_tx, ws->tx_per_sec);
|
||||||
|
|
||||||
|
|||||||
@@ -151,6 +151,7 @@ typedef struct worker_st {
|
|||||||
|
|
||||||
size_t rx_per_sec;
|
size_t rx_per_sec;
|
||||||
size_t tx_per_sec;
|
size_t tx_per_sec;
|
||||||
|
unsigned net_priority;
|
||||||
|
|
||||||
struct http_req_st req;
|
struct http_req_st req;
|
||||||
} worker_st;
|
} worker_st;
|
||||||
|
|||||||
Reference in New Issue
Block a user