Commit b33815b6 authored by Kevin Cernekee's avatar Kevin Cernekee

Add OC_CMD_DETACH for "reconnectable abort"

OC_CMD_DETACH is similar to OC_CMD_CANCEL, except it does not tell the
server to invalidate the cookie when exiting.  So it is possible to
reconnect to the same session with "openconnect --cookie <foo>" later.
Signed-off-by: default avatarKevin Cernekee <cernekee@gmail.com>
parent 3e373ae5
......@@ -105,7 +105,8 @@ int tun_mainloop(struct openconnect_info *vpninfo, int *timeout)
/* Return value:
* = 0, when successfully paused (may call again)
* = -EINTR, if aborted locally via cmd_fd
* = -EINTR, if aborted locally via OC_CMD_CANCEL
* = -ECONNABORTED, if aborted locally via OC_CMD_DETACH
* = -EPIPE, if the remote end explicitly terminated the session
* = -EPERM, if the gateway sent 401 Unauthorized (cookie expired)
* < 0, for any other error
......@@ -157,8 +158,12 @@ int openconnect_mainloop(struct openconnect_info *vpninfo,
poll_cmd_fd(vpninfo, 0);
if (vpninfo->got_cancel_cmd) {
vpninfo->quit_reason = "Aborted by caller";
ret = -EINTR;
if (vpninfo->cancel_type == OC_CMD_CANCEL) {
vpninfo->quit_reason = "Aborted by caller";
ret = -EINTR;
} else {
ret = -ECONNABORTED;
}
break;
}
if (vpninfo->got_pause_cmd) {
......@@ -215,7 +220,8 @@ int openconnect_mainloop(struct openconnect_info *vpninfo,
#endif
}
cstp_bye(vpninfo, vpninfo->quit_reason);
if (vpninfo->quit_reason)
cstp_bye(vpninfo, vpninfo->quit_reason);
os_shutdown_tun(vpninfo);
return ret < 0 ? ret : -EIO;
......
......@@ -305,6 +305,7 @@ struct openconnect_info {
int cmd_fd_write;
int got_cancel_cmd;
int got_pause_cmd;
char cancel_type;
struct pkt *incoming_queue;
struct pkt *outgoing_queue;
......
......@@ -225,9 +225,21 @@ struct oc_stats {
#define PRG_DEBUG 2
#define PRG_TRACE 3
/* byte commands to write into the cmd_fd */
/* Byte commands to write into the cmd_fd:
*
* CANCEL closes network connections, logs off the session (cookie)
* and shuts down the tun device.
* PAUSE closes network connections and returns. The caller is expected
* to call openconnect_mainloop() again soon.
* DETACH closes network connections and shuts down the tun device.
* It is not legal to call openconnect_mainloop() again after this,
* but a new instance of openconnect can be started using the same
* cookie.
* STATS calls the stats_handler.
*/
#define OC_CMD_CANCEL 'x'
#define OC_CMD_PAUSE 'p'
#define OC_CMD_DETACH 'd'
#define OC_CMD_STATS 's'
#define RECONNECT_INTERVAL_MIN 10
......
......@@ -587,7 +587,9 @@ void check_cmd_fd(struct openconnect_info *vpninfo, fd_set *fds)
switch (cmd) {
case OC_CMD_CANCEL:
case OC_CMD_DETACH:
vpninfo->got_cancel_cmd = 1;
vpninfo->cancel_type = cmd;
break;
case OC_CMD_PAUSE:
vpninfo->got_pause_cmd = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment