Bound negotited MTU between RFC 791 defined minumum and configured maximum.

Resolves: #247

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
This commit is contained in:
Alan Jowett
2020-02-18 09:20:21 -07:00
parent 9bd3c136e1
commit 87b1dc65ba
2 changed files with 16 additions and 0 deletions

View File

@@ -26,6 +26,10 @@
#include <netinet/in.h>
#define MAX_IP_STR 46
// Lower MTU bound is the value defined in RFC 791
#define RFC_791_MTU (68)
// Upper bound is the maximum DTLS frame size
#define MAX_DTLS_MTU (1<<14)
void set_mtu_disc(int fd, int family, int val);
int ip_route_sanity_check(void *pool, char **_route);

View File

@@ -317,6 +317,11 @@ int handle_worker_commands(main_server_st * s, struct proc_st *proc)
break;
case CMD_TUN_MTU:{
TunMtuMsg *tmsg;
unsigned minimum_mtu = RFC_791_MTU;
unsigned maximum_mtu =
proc->vhost->perm_config.config->default_mtu != 0 ?
proc->vhost->perm_config.config->default_mtu :
MAX_DTLS_MTU;
if (proc->status != PS_AUTH_COMPLETED) {
mslog(s, proc, LOG_ERR,
@@ -332,6 +337,13 @@ int handle_worker_commands(main_server_st * s, struct proc_st *proc)
goto cleanup;
}
if (tmsg->mtu < minimum_mtu || tmsg->mtu > maximum_mtu) {
mslog(s, proc, LOG_ERR,
"worker process invalid MTU %d", (int)tmsg->mtu);
ret = ERR_BAD_COMMAND;
goto cleanup;
}
set_tun_mtu(s, proc, tmsg->mtu);
tun_mtu_msg__free_unpacked(tmsg, &pa);