Add mptcp option

This commit is contained in:
angt
2016-02-25 14:38:51 +00:00
parent eefa7722c5
commit 030087cb27

View File

@@ -45,8 +45,11 @@
#define GT_TUNR_SIZE (GT_PKT_MAX-16-2) #define GT_TUNR_SIZE (GT_PKT_MAX-16-2)
#define GT_TUNW_SIZE (GT_PKT_MAX) #define GT_TUNW_SIZE (GT_PKT_MAX)
#define MPTCP_ENABLED (26)
static struct { static struct {
int timeout; long timeout;
int mptcp;
} gt; } gt;
struct fdbuf { struct fdbuf {
@@ -104,6 +107,7 @@ enum sk_opt {
sk_acceptfilter, sk_acceptfilter,
sk_quickack, sk_quickack,
sk_user_timeout, sk_user_timeout,
sk_mptcp,
}; };
static void sk_set (int fd, enum sk_opt opt, const void *val, socklen_t len) static void sk_set (int fd, enum sk_opt opt, const void *val, socklen_t len)
@@ -158,6 +162,11 @@ static void sk_set (int fd, enum sk_opt opt, const void *val, socklen_t len)
[sk_user_timeout] = { "TCP_USER_TIMEOUT", [sk_user_timeout] = { "TCP_USER_TIMEOUT",
#ifdef TCP_USER_TIMEOUT #ifdef TCP_USER_TIMEOUT
1, IPPROTO_TCP, TCP_USER_TIMEOUT, 1, IPPROTO_TCP, TCP_USER_TIMEOUT,
#endif
},
[sk_mptcp] = { "MPTCP_ENABLED",
#ifdef MPTCP_ENABLED
1, IPPROTO_TCP, MPTCP_ENABLED,
#endif #endif
}, },
}; };
@@ -180,6 +189,9 @@ static int sk_listen (int fd, struct addrinfo *ai)
{ {
sk_set_int(fd, sk_reuseaddr, 1); sk_set_int(fd, sk_reuseaddr, 1);
if (gt.mptcp)
sk_set_int(fd, sk_mptcp, 1);
if (bind(fd, ai->ai_addr, ai->ai_addrlen)==-1) { if (bind(fd, ai->ai_addr, ai->ai_addrlen)==-1) {
perror("bind"); perror("bind");
return -1; return -1;
@@ -204,6 +216,9 @@ static int sk_connect (int fd, struct addrinfo *ai)
{ {
fd_set_nonblock(fd); fd_set_nonblock(fd);
if (gt.mptcp)
sk_set_int(fd, sk_mptcp, 1);
int ret = connect(fd, ai->ai_addr, ai->ai_addrlen); int ret = connect(fd, ai->ai_addr, ai->ai_addrlen);
if (ret==-1) { if (ret==-1) {
@@ -1130,6 +1145,7 @@ int main (int argc, char **argv)
{ "retry", &retry_opts, option_option }, { "retry", &retry_opts, option_option },
{ "statefile", &statefile, option_str }, { "statefile", &statefile, option_str },
{ "timeout", &gt.timeout, option_long }, { "timeout", &gt.timeout, option_long },
{ "mptcp", NULL, option_option },
{ "debug", NULL, option_option }, { "debug", NULL, option_option },
{ "version", NULL, option_option }, { "version", NULL, option_option },
{ NULL }, { NULL },
@@ -1149,6 +1165,8 @@ int main (int argc, char **argv)
const int noquickack = option_is_set(opts, "noquickack"); const int noquickack = option_is_set(opts, "noquickack");
const int debug = option_is_set(opts, "debug"); const int debug = option_is_set(opts, "debug");
gt.mptcp = option_is_set(opts, "mptcp");
if (buffer_size < GT_PKT_MAX) { if (buffer_size < GT_PKT_MAX) {
buffer_size = GT_PKT_MAX; buffer_size = GT_PKT_MAX;
gt_log("buffer size must be greater than or equal to %li\n", buffer_size); gt_log("buffer size must be greater than or equal to %li\n", buffer_size);