diff --git a/src/config.c b/src/config.c index 1e809986..990e0c83 100644 --- a/src/config.c +++ b/src/config.c @@ -65,6 +65,7 @@ const struct vpn_config invalid_cfg = { .pppd_log = NULL, .pppd_plugin = NULL, .pppd_ipparam = NULL, + .pppd_keepalive = NULL, .pppd_ifname = NULL, .pppd_call = NULL, #endif @@ -349,6 +350,9 @@ int load_config(struct vpn_config *cfg, const char *filename) } else if (strcmp(key, "pppd-ipparam") == 0) { free(cfg->pppd_ipparam); cfg->pppd_ipparam = strdup(val); + } else if (strcmp(key, "pppd-keepalive") == 0) { + free(cfg->pppd_keepalive); + cfg->pppd_keepalive = strdup(val); } else if (strcmp(key, "pppd-ifname") == 0) { free(cfg->pppd_ifname); cfg->pppd_ifname = strdup(val); @@ -475,6 +479,7 @@ void destroy_vpn_config(struct vpn_config *cfg) free(cfg->pppd_log); free(cfg->pppd_plugin); free(cfg->pppd_ipparam); + free(cfg->pppd_keepalive); free(cfg->pppd_ifname); free(cfg->pppd_call); #endif @@ -546,6 +551,10 @@ void merge_config(struct vpn_config *dst, struct vpn_config *src) free(dst->pppd_ipparam); dst->pppd_ipparam = src->pppd_ipparam; } + if (src->pppd_keepalive) { + free(dst->pppd_keepalive); + dst->pppd_keepalive = src->pppd_keepalive; + } if (src->pppd_ifname) { free(dst->pppd_ifname); dst->pppd_ifname = src->pppd_ifname; diff --git a/src/config.h b/src/config.h index 25f3863a..1b3df7c3 100644 --- a/src/config.h +++ b/src/config.h @@ -105,6 +105,7 @@ struct vpn_config { char *pppd_log; char *pppd_plugin; char *pppd_ipparam; + char *pppd_keepalive; char *pppd_ifname; char *pppd_call; #endif diff --git a/src/main.c b/src/main.c index d28e75d1..4b87aba7 100644 --- a/src/main.c +++ b/src/main.c @@ -38,7 +38,8 @@ #define PPPD_USAGE \ " [--pppd-use-peerdns=<0|1>] [--pppd-log=]\n" \ " [--pppd-ifname=] [--pppd-ipparam=]\n" \ -" [--pppd-call=] [--pppd-plugin=]\n" +" [--pppd-call=] [--pppd-plugin=]\n" \ +" [--pppd-keepalive=]\n" #define PPPD_HELP \ " --pppd-use-peerdns=[01] Whether to ask peer ppp server for DNS server\n" \ @@ -54,7 +55,9 @@ " and ip-down scripts. See man (8) pppd.\n" \ " --pppd-call= Move most pppd options from pppd cmdline to\n" \ " /etc/ppp/peers/ and invoke pppd with\n" \ -" 'call '.\n" +" 'call '.\n" \ +" --pppd-keepalive= Keep connection alive using LCP echo-request frames\n" \ +" sent by pppd every seconds.\n" #elif HAVE_USR_SBIN_PPP #define PPPD_USAGE \ " [--ppp-system=]\n" @@ -216,6 +219,7 @@ int main(int argc, char **argv) .pppd_log = NULL, .pppd_plugin = NULL, .pppd_ipparam = NULL, + .pppd_keepalive = NULL, .pppd_ifname = NULL, .pppd_call = NULL, #endif @@ -273,6 +277,7 @@ int main(int argc, char **argv) {"pppd-log", required_argument, NULL, 0}, {"pppd-plugin", required_argument, NULL, 0}, {"pppd-ipparam", required_argument, NULL, 0}, + {"pppd-keepalive", required_argument, NULL, 0}, {"pppd-ifname", required_argument, NULL, 0}, {"pppd-call", required_argument, NULL, 0}, {"plugin", required_argument, NULL, 0}, // deprecated @@ -345,6 +350,11 @@ int main(int argc, char **argv) cli_cfg.pppd_ipparam = strdup(optarg); break; } + if (strcmp(long_options[option_index].name, + "pppd-keepalive") == 0) { + cli_cfg.pppd_keepalive = strdup(optarg); + break; + } if (strcmp(long_options[option_index].name, "pppd-call") == 0) { cli_cfg.pppd_call = strdup(optarg); diff --git a/src/tunnel.c b/src/tunnel.c index 32a5e39e..51630ef4 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -302,6 +302,16 @@ static int pppd_run(struct tunnel *tunnel) return 1; } } + if (tunnel->config->pppd_keepalive) { + if (ofv_append_varr(&pppd_args, "lcp-echo-interval")) { + free(pppd_args.data); + return 1; + } + if (ofv_append_varr(&pppd_args, tunnel->config->pppd_keepalive)) { + free(pppd_args.data); + return 1; + } + } if (tunnel->config->pppd_ifname) { if (ofv_append_varr(&pppd_args, "ifname")) { free(pppd_args.data);