Honour client's MTU choice.

This commit is contained in:
Nikos Mavrogiannopoulos
2013-02-07 18:19:10 +01:00
parent 2478c519b2
commit 534ddfbfcc
3 changed files with 23 additions and 0 deletions

View File

@@ -22,6 +22,7 @@
extern int syslog_open;
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
/* the first is generic, for the methods that require a username password */
#define AUTH_TYPE_USERNAME_PASS (1<<0)

View File

@@ -133,6 +133,10 @@ int header_field_cb(http_parser* parser, const char *at, size_t length)
req->next_header = HEADER_COOKIE;
} else if (strncmp(at, "X-DTLS-Master-Secret:", length) == 0) {
req->next_header = HEADER_MASTER_SECRET;
} else if (strncmp(at, "X-DTLS-MTU:", length) == 0) {
req->next_header = HEADER_DTLS_MTU;
} else if (strncmp(at, "X-CSTP-MTU:", length) == 0) {
req->next_header = HEADER_CSTP_MTU;
} else if (strncmp(at, "X-CSTP-Hostname:", length) == 0) {
req->next_header = HEADER_HOSTNAME;
} else {
@@ -171,6 +175,12 @@ size_t nlen;
memcpy(req->hostname, at, length);
req->hostname[length] = 0;
break;
case HEADER_CSTP_MTU:
req->cstp_mtu = atoi(at);
break;
case HEADER_DTLS_MTU:
req->dtls_mtu = atoi(at);
break;
case HEADER_COOKIE:
p = memmem(at, length, "webvpn=", 7);
@@ -721,6 +731,10 @@ unsigned mtu_overhead, dtls_mtu = 0;
tls_puts(ws->session, "X-Reason: Server configuration error\r\n\r\n");
return -1;
}
if (req->cstp_mtu > 0) {
vinfo.mtu = MIN(vinfo.mtu, req->cstp_mtu);
}
tls_puts(ws->session, "HTTP/1.1 200 CONNECTED\r\n");
@@ -782,6 +796,10 @@ unsigned mtu_overhead, dtls_mtu = 0;
mtu_overhead = 40+8;
dtls_mtu = vinfo.mtu - mtu_overhead;
if (req->dtls_mtu > 0) {
dtls_mtu = MIN(req->dtls_mtu, dtls_mtu);
}
tls_printf(ws->session, "X-DTLS-MTU: %u\r\n", dtls_mtu);
}

View File

@@ -30,6 +30,8 @@ enum {
HEADER_COOKIE = 1,
HEADER_MASTER_SECRET,
HEADER_HOSTNAME,
HEADER_CSTP_MTU,
HEADER_DTLS_MTU,
};
typedef struct worker_st {
@@ -87,6 +89,8 @@ struct req_data_st {
char *body;
unsigned int headers_complete;
unsigned int message_complete;
unsigned dtls_mtu;
unsigned cstp_mtu;
};
void __attribute__ ((format(printf, 3, 4)))