Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding --pppd-keepalive option. #802

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
#define PPPD_USAGE \
" [--pppd-use-peerdns=<0|1>] [--pppd-log=<file>]\n" \
" [--pppd-ifname=<string>] [--pppd-ipparam=<string>]\n" \
" [--pppd-call=<name>] [--pppd-plugin=<file>]\n"
" [--pppd-call=<name>] [--pppd-plugin=<file>]\n" \
" [--pppd-keepalive=<interval>]\n"

#define PPPD_HELP \
" --pppd-use-peerdns=[01] Whether to ask peer ppp server for DNS server\n" \
Expand All @@ -54,7 +55,9 @@
" and ip-down scripts. See man (8) pppd.\n" \
" --pppd-call=<name> Move most pppd options from pppd cmdline to\n" \
" /etc/ppp/peers/<name> and invoke pppd with\n" \
" 'call <name>'.\n"
" 'call <name>'.\n" \
" --pppd-keepalive=<interval> Keep connection alive using LCP echo-request frames\n" \
" sent by pppd every <interval> seconds.\n"
#elif HAVE_USR_SBIN_PPP
#define PPPD_USAGE \
" [--ppp-system=<system>]\n"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions src/tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down