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

limit number of retries #1082

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
12 changes: 12 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const struct vpn_config invalid_cfg = {
.use_syslog = -1,
.half_internet_routes = -1,
.persistent = -1,
.retries = -1,
#if HAVE_USR_SBIN_PPPD
.pppd_log = NULL,
.pppd_plugin = NULL,
Expand Down Expand Up @@ -315,6 +316,15 @@ int load_config(struct vpn_config *cfg, const char *filename)
continue;
}
cfg->half_internet_routes = half_internet_routes;
} else if (strcmp(key, "retries") == 0) {
unsigned long retries = strtoul(val, NULL, 0);

if (retries > UINT_MAX) {
log_warn("Bad value for retries in configuration file: \"%s\".\n",
val);
continue;
}
cfg->retries = retries;
} else if (strcmp(key, "persistent") == 0) {
unsigned long persistent = strtoul(val, NULL, 0);

Expand Down Expand Up @@ -540,6 +550,8 @@ void merge_config(struct vpn_config *dst, struct vpn_config *src)
dst->use_syslog = src->use_syslog;
if (src->half_internet_routes != invalid_cfg.half_internet_routes)
dst->half_internet_routes = src->half_internet_routes;
if (src->retries != invalid_cfg.retries)
dst->retries = src->retries;
if (src->persistent != invalid_cfg.persistent)
dst->persistent = src->persistent;
#if HAVE_USR_SBIN_PPPD
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ struct vpn_config {
int half_internet_routes;

unsigned int persistent;
unsigned int retries;

#if HAVE_USR_SBIN_PPPD
char *pppd_log;
Expand Down
18 changes: 18 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ PPPD_USAGE \
" [--user-cert=<file>] [--user-key=<file>]\n" \
" [--use-syslog] [--trusted-cert=<digest>]\n" \
" [--persistent=<interval>] [-c <file>] [-v|-q]\n" \
" [--persistent=<interval>] [--retries=<count>] [-c <file>] [-v|-q]\n" \
" openfortivpn --help\n" \
" openfortivpn --version\n" \
"\n"
Expand Down Expand Up @@ -164,6 +165,7 @@ PPPD_USAGE \
" dh key." help_seclevel_1 "\n" \
" --persistent=<interval> Run the vpn persistently in a loop and try to re-\n" \
" connect every <interval> seconds when dropping out.\n" \
" --retries=<count> Limit persistent retries to <count> cycles.\n" \
" -v Increase verbosity. Can be used multiple times\n" \
" to be even more verbose.\n" \
" -q Decrease verbosity. Can be used multiple times\n" \
Expand Down Expand Up @@ -212,6 +214,7 @@ int main(int argc, char **argv)
.use_syslog = 0,
.half_internet_routes = 0,
.persistent = 0,
.retries = 0,
#if HAVE_RESOLVCONF
.use_resolvconf = USE_RESOLVCONF,
#endif
Expand Down Expand Up @@ -267,6 +270,7 @@ int main(int argc, char **argv)
{"no-dns", no_argument, &cli_cfg.set_dns, 0},
{"use-syslog", no_argument, &cli_cfg.use_syslog, 1},
{"persistent", required_argument, NULL, 0},
{"retries", required_argument, NULL, 0},
{"ca-file", required_argument, NULL, 0},
{"user-cert", required_argument, NULL, 0},
{"user-key", required_argument, NULL, 0},
Expand Down Expand Up @@ -504,6 +508,18 @@ int main(int argc, char **argv)
cli_cfg.persistent = persistent;
break;
}
if (strcmp(long_options[option_index].name,
"retries") == 0) {
long retries = strtol(optarg, NULL, 0);

if (retries < 0 || retries > UINT_MAX) {
log_warn("Bad retries option: \"%s\"\n",
optarg);
break;
}
cli_cfg.retries = retries;
break;
}
if (strcmp(long_options[option_index].name,
"set-dns") == 0) {
int set_dns = strtob(optarg);
Expand Down Expand Up @@ -671,6 +687,8 @@ int main(int argc, char **argv)
ret = EXIT_FAILURE;
else
ret = EXIT_SUCCESS;
if (cfg.retries-- == 0)
cfg.persistent = 0;
if ((cfg.persistent > 0) && (get_sig_received() == 0))
sleep(cfg.persistent);
} while ((get_sig_received() == 0) && (cfg.persistent != 0));
Expand Down