Skip to content

Commit

Permalink
Add MTU option
Browse files Browse the repository at this point in the history
  • Loading branch information
madeye committed Aug 3, 2016
1 parent b65e63e commit 34b9036
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 46 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ config.log
config.status
libtool
pid
ss.*
src/ss-*
!src/ss-nat
stamp-h1
Expand Down
5 changes: 4 additions & 1 deletion doc/ss-local.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SYNOPSIS
[-s <server_host>] [-p <server_port>] [-l <local_port>]
[-k <password>] [-m <encrypt_method>] [-f <pid_file>] [-t <timeout>]
[-c <config_file>] [-b <interface>] [-a <user_name>]
[-n <nofile>] [--fast-open] [--acl <acl_config>]
[-n <nofile>] [--fast-open] [--acl <acl_config>] [--mtu <MTU>]

DESCRIPTION
-----------
Expand Down Expand Up @@ -102,6 +102,9 @@ Only available with Linux kernel > 3.7.0.
--acl <acl_config>::
Enable ACL (Access Control List) and specify config file.

--mtu <MTU>::
Specify the MTU of your network interface.

-v::
Enable verbose mode.

Expand Down
5 changes: 4 additions & 1 deletion doc/ss-redir.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SYNOPSIS
[-s <server_host>] [-p <server_port>] [-l <local_port>]
[-k <password>] [-m <encrypt_method>] [-f <pid_file>]
[-t <timeout>] [-c <config_file>] [-b <local_address>]
[-a <user_name>] [-n <nofile>]
[-a <user_name>] [-n <nofile>] [--mtu <MTU>]

DESCRIPTION
-----------
Expand Down Expand Up @@ -89,6 +89,9 @@ Enable UDP relay and disable TCP relay.
-A::
Enable onetime authentication.

--mtu <MTU>::
Specify the MTU of your network interface.

-v::
Enable verbose mode.

Expand Down
5 changes: 4 additions & 1 deletion doc/ss-server.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SYNOPSIS
[-k <password>] [-m <encrypt_method>] [-f <pid_file>]
[-t <timeout>] [-c <config_file>] [-i <interface>]
[-a <user_name>] [-d <addr>] [-n <nofile>]
[--fast-open] [--acl <acl_config>]
[--fast-open] [--acl <acl_config>] [--mtu <MTU>]
[--manager-address <path_to_unix_domain>]

DESCRIPTION
Expand Down Expand Up @@ -115,6 +115,9 @@ Specify UNIX domain socket address for the communication between ss-manager(1) a
+
Only available in server and manager mode.

--mtu <MTU>::
Specify the MTU of your network interface.

-v::
Enable verbose mode.

Expand Down
5 changes: 4 additions & 1 deletion doc/ss-tunnel.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SYNOPSIS
[-k <password>] [-m <encrypt_method>] [-f <pid_file>]
[-t <timeout>] [-c <config_file>] [-i <interface>]
[-b <local_addr>] [-a <user_name>] [-n <nofile>]
[-L addr:port]
[-L addr:port] [--mtu <MTU>]

DESCRIPTION
-----------
Expand Down Expand Up @@ -100,6 +100,9 @@ Specify destination server address and port for local port forwarding.
+
Only used and available in tunnel mode.

--mtu <MTU>::
Specify the MTU of your network interface.

-v::
Enable verbose mode.

Expand Down
2 changes: 1 addition & 1 deletion src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int init_udprelay(const char *server_host, const char *server_port,
const ss_addr_t tunnel_addr,
#endif
#endif
int method, int auth, int timeout, const char *iface);
int mtu, int method, int auth, int timeout, const char *iface);

void free_udprelay(void);

Expand Down
10 changes: 8 additions & 2 deletions src/local.c
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,7 @@ int main(int argc, char **argv)
{
int i, c;
int pid_flags = 0;
int mtu = 0;
char *user = NULL;
char *local_port = NULL;
char *local_addr = NULL;
Expand All @@ -1002,6 +1003,7 @@ int main(int argc, char **argv)
static struct option long_options[] = {
{ "fast-open", no_argument , 0, 0 },
{ "acl" , required_argument, 0, 0 },
{ "mtu" , required_argument, 0, 0 },
{ "help" , no_argument , 0, 0 },
{ 0, 0, 0, 0 }
};
Expand All @@ -1025,6 +1027,9 @@ int main(int argc, char **argv)
LOGI("initializing acl...");
acl = !init_acl(optarg, BLACK_LIST);
} else if (option_index == 2) {
mtu = atoi(optarg);
LOGI("Set MTU to %d", mtu);
} else if (option_index == 3) {
usage();
exit(EXIT_SUCCESS);
}
Expand Down Expand Up @@ -1258,7 +1263,7 @@ int main(int argc, char **argv)
if (mode != TCP_ONLY) {
LOGI("udprelay enabled");
init_udprelay(local_addr, local_port, listen_ctx.remote_addr[0],
get_sockaddr_len(listen_ctx.remote_addr[0]), m, auth, listen_ctx.timeout, iface);
get_sockaddr_len(listen_ctx.remote_addr[0]), mtu, m, auth, listen_ctx.timeout, iface);
}

LOGI("listening at %s:%s", local_addr, local_port);
Expand Down Expand Up @@ -1318,6 +1323,7 @@ int start_ss_local_server(profile_t profile)
int remote_port = profile.remote_port;
int local_port = profile.local_port;
int timeout = profile.timeout;
int mtu = 0;

auth = profile.auth;
mode = profile.mode;
Expand Down Expand Up @@ -1406,7 +1412,7 @@ int start_ss_local_server(profile_t profile)
LOGI("udprelay enabled");
struct sockaddr *addr = (struct sockaddr *)storage;
init_udprelay(local_addr, local_port_str, addr,
get_sockaddr_len(addr), m, auth, timeout, NULL);
get_sockaddr_len(addr), mtu, m, auth, timeout, NULL);
}

LOGI("listening at %s:%s", local_addr, local_port_str);
Expand Down
11 changes: 8 additions & 3 deletions src/redir.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ int main(int argc, char **argv)

int i, c;
int pid_flags = 0;
int mtu = 0;
char *user = NULL;
char *local_port = NULL;
char *local_addr = NULL;
Expand All @@ -698,8 +699,9 @@ int main(int argc, char **argv)

int option_index = 0;
static struct option long_options[] = {
{ "help", no_argument, 0, 0 },
{ 0, 0, 0, 0 }
{ "mtu", required_argument, 0, 0 },
{ "help", no_argument , 0, 0 },
{ 0, 0 , 0, 0 }
};

opterr = 0;
Expand All @@ -709,6 +711,9 @@ int main(int argc, char **argv)
switch (c) {
case 0:
if (option_index == 0) {
mtu = atoi(optarg);
LOGI("Set MTU to %d", mtu);
} else if (option_index == 1) {
usage();
exit(EXIT_SUCCESS);
}
Expand Down Expand Up @@ -905,7 +910,7 @@ int main(int argc, char **argv)
if (mode != TCP_ONLY) {
LOGI("UDP relay enabled");
init_udprelay(local_addr, local_port, listen_ctx.remote_addr[0],
get_sockaddr_len(listen_ctx.remote_addr[0]), m, auth, listen_ctx.timeout, NULL);
get_sockaddr_len(listen_ctx.remote_addr[0]), mtu, m, auth, listen_ctx.timeout, NULL);
}

if (mode == UDP_ONLY) {
Expand Down
9 changes: 7 additions & 2 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,7 @@ int main(int argc, char **argv)
{
int i, c;
int pid_flags = 0;
int mtu = 0;
char *user = NULL;
char *password = NULL;
char *timeout = NULL;
Expand All @@ -1358,6 +1359,7 @@ int main(int argc, char **argv)
{ "fast-open" , no_argument , 0, 0 },
{ "acl" , required_argument, 0, 0 },
{ "manager-address", required_argument, 0, 0 },
{ "mtu" , required_argument, 0, 0 },
{ "help" , no_argument , 0, 0 },
{ 0, 0, 0, 0 }
};
Expand All @@ -1379,6 +1381,9 @@ int main(int argc, char **argv)
} else if (option_index == 2) {
manager_address = optarg;
} else if (option_index == 3) {
mtu = atoi(optarg);
LOGI("Set MTU to %d", mtu);
} else if (option_index == 4) {
usage();
exit(EXIT_SUCCESS);
}
Expand Down Expand Up @@ -1636,8 +1641,8 @@ int main(int argc, char **argv)

// Setup UDP
if (mode != TCP_ONLY) {
init_udprelay(server_host[index], server_port, m, auth, atoi(timeout),
iface);
init_udprelay(server_host[index], server_port, mtu, m,
auth, atoi(timeout), iface);
}

LOGI("listening at %s:%s", host ? host : "*", server_port);
Expand Down
11 changes: 8 additions & 3 deletions src/tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ int main(int argc, char **argv)

int i, c;
int pid_flags = 0;
int mtu = 0;
char *user = NULL;
char *local_port = NULL;
char *local_addr = NULL;
Expand All @@ -711,8 +712,9 @@ int main(int argc, char **argv)

int option_index = 0;
static struct option long_options[] = {
{ "help", no_argument, 0, 0 },
{ 0, 0, 0, 0 }
{ "mtu", required_argument, 0, 0 },
{ "help", no_argument, 0, 0 },
{ 0, 0, 0, 0 }
};

opterr = 0;
Expand All @@ -729,6 +731,9 @@ int main(int argc, char **argv)
switch (c) {
case 0:
if (option_index == 0) {
mtu = atoi(optarg);
LOGI("Set MTU to %d", mtu);
} else if (option_index == 1) {
usage();
exit(EXIT_SUCCESS);
}
Expand Down Expand Up @@ -959,7 +964,7 @@ int main(int argc, char **argv)
LOGI("UDP relay enabled");
init_udprelay(local_addr, local_port, listen_ctx.remote_addr[0],
get_sockaddr_len(listen_ctx.remote_addr[0]),
tunnel_addr, m, auth, listen_ctx.timeout, iface);
tunnel_addr, mtu, m, auth, listen_ctx.timeout, iface);
}

if (mode == UDP_ONLY) {
Expand Down
Loading

0 comments on commit 34b9036

Please sign in to comment.