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

added --loop option for automatic reconnects #190

Merged
merged 6 commits into from
Feb 20, 2018

Conversation

mrbaseman
Copy link
Collaborator

No description provided.

src/main.c Outdated
"\"%s\"\n", optarg);
break;
}
cfg.loop = loop;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A long is cast into an int. I'm not programming much in C these days, but couldn't this be an issue if loop is insanely large?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very large values don't make much sense here. The value is used as argument for sleep(unsigned int), so even in this call, negative values are (probably) cast to large positive numbers. The worst that can happen is that openfortivpn waits a very long time before trying to reconnect, which gives a user experience nearly as if loop was left with the default value of 0.

I don't feel that a code change is needed here, but I'm open for suggestions. Maybe some comments of this discussion are helpful

Copy link
Collaborator

@DimitriPapadopoulos DimitriPapadopoulos Oct 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK with me, that's not an important issue.

Let's reconsider in case it raises a Coverity issue.

src/main.c Outdated
sleep(cfg.loop);
if (run_tunnel(&cfg) != 0)
ret = EXIT_FAILURE;
}
Copy link
Collaborator

@DimitriPapadopoulos DimitriPapadopoulos Oct 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer something like this (run_tunnel() is called from a single place). What do you think?

	while (get_sig_received() == 0) {
		if (run_tunnel(&cfg) != 0) {
			ret = EXIT_FAILURE;
			break;
		} else
			ret = EXIT_SUCCESS;
		if (cfg.loop == 0)
			break;
		sleep(cfg.loop);
	}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I was looking for something like this, but first didn't get the signal handling right and after I had introduced get_sig_received() I forgot to come back to this loop condition. Something with do { ... } while ( ) might be another solution that doesn't need a break;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, do { ... } while ( ) might be better. But don't we need a break anyway to avoid the last sleep() call which should occur after the run_tunnel() call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have just updated the branch with d489dd7 which addresses this (not sure if my ifs are nicer than your breaks though...)

@mrbaseman
Copy link
Collaborator Author

A general remark: Supporting automatic reconnect was an idea which came up in one of the issues about unstable connections. I think they can mostly be ascribed MTU problems or other problems in the lower layers. Connections that are dropped after hours most probably hit the idle timeout configured on the vpn gateway. Does it still make sense to implement automatic reconnects from the client side?

@DimitriPapadopoulos
Copy link
Collaborator

DimitriPapadopoulos commented Oct 10, 2017

I'm not so fond of automatically reconnecting either. Sure, it might make sense when you hit the gateway timeout - which I believe is ~8 hours by default whether the connection is idle or not. On the other hand many FortiGate devices are configured to accept only tokens / one-time passwords. Reconnecting doesn't make sense in such cases.

Whether the feature is useful or not, I think I'd rather keep it outside openfortivpn and write a simple shell wrapper that restarts openfortivpn, or use a crontab, or use the respawn facility of SysV init / upstart / systemd. To that purpose:

  • We should verify that openfortivpn exit values are meaningful. But then I don't think it's possible to discriminate between a FortiGate timeout and MTU issues for example.
  • We could start a wiki and provide a sample script, or describe how to use the init system and respawn for that purpose.

@mrbaseman
Copy link
Collaborator Author

A wiki that provides some extra hints and helper scripts is a good idea. I have seen the request for init scripts or ipup scripts for pppd several times already. But I'm using two factor authentication with Tokens as well, so I can't run it purely script based either...

@mrbaseman mrbaseman force-pushed the reauthentication branch 8 times, most recently from 41cf497 to db11494 Compare October 19, 2017 13:02
@mrbaseman mrbaseman force-pushed the reauthentication branch 2 times, most recently from 85fa836 to 7ff6de2 Compare October 23, 2017 19:39
@mrbaseman mrbaseman force-pushed the reauthentication branch 2 times, most recently from 5fef8a4 to 863e892 Compare November 27, 2017 14:13
@mrbaseman
Copy link
Collaborator Author

the reauthentication feature was requested and successfully tested in #92. @DimitriPapadopoulos I have just seen that I hadn't yet properly addressed the cast of a long to an unsigned int. Now I have done so and also a bit of cleanup. Are you ok with merging this small patch into master (after rebasing and squashing it into a single commit)?

@DimitriPapadopoulos
Copy link
Collaborator

Looks good to me.

To tell the truth I would prefer to keep the reconnection mechanism outside of openfortivpn (a shell wrapper ?) but if there is a widespread need it's OK with me - I am of course biased by my own experience and needs.

@mrbaseman
Copy link
Collaborator Author

I think we have a couple of requests for this feature. Only, I'm not so happy with calling the command line option "--loop". Maybe there are better proposals? If not, I would rebase and merge this in the near future. (I was ill and on vacation and had a considerable backlog in my mailbox, now I'm ill again, so my activities here are a bit slowed down... )

@adrienverge
Copy link
Owner

Like Dimitri I'd rather use a wrapper to relaunch openfortivpn, but since there are multiple demands for this, let's do it!

Only, I'm not so happy with calling the command line option "--loop". Maybe there are better proposals?

Maybe --auto-reconnect?

@DimitriPapadopoulos
Copy link
Collaborator

Perhaps --persistent as suggested in #251? Here are a few links to other synonyms:

Most probably we should reuse the vocabulary used in systemd and other init systems. See for example How To Configure a Linux Service to Start Automatically After a Crash or Reboot, Autostart using systemd or Ensure systemd services restart on failure:

  • respawn
  • restart
  • reload
  • auto...

@adrienverge
Copy link
Owner

Perhaps --persistent as suggested in #251?

Sounds good too 👍

@mrbaseman mrbaseman merged commit a926b34 into adrienverge:master Feb 20, 2018
@adrienverge
Copy link
Owner

Nice job!

Should I release v1.7.0? Or do you guys plan to merge other features soon?

@mrbaseman
Copy link
Collaborator Author

I would wait with the new release for the 2fa issue in #255 to land, and maybe #254 as well. Both are not very big changes, but at least the 2fa in combination with network manager applet is an important one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants