From 761832fdc3dcb94e430e2b62abf5a10d8aaf7fc2 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Thu, 13 Feb 2014 23:21:29 +0000 Subject: [PATCH] Split out os_shutdown_tun() for Windows vs. sane platforms Signed-off-by: David Woodhouse --- mainloop.c | 2 +- openconnect-internal.h | 2 +- tun-win32.c | 9 +++++++++ tun.c | 12 +++--------- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/mainloop.c b/mainloop.c index 28358c5f..eca89190 100644 --- a/mainloop.c +++ b/mainloop.c @@ -219,7 +219,7 @@ int openconnect_mainloop(struct openconnect_info *vpninfo, cstp_bye(vpninfo, vpninfo->quit_reason); - shutdown_tun(vpninfo); + os_shutdown_tun(vpninfo); return ret < 0 ? ret : -EIO; } diff --git a/openconnect-internal.h b/openconnect-internal.h index dffba1be..6a1ff579 100644 --- a/openconnect-internal.h +++ b/openconnect-internal.h @@ -454,7 +454,7 @@ void set_script_env(struct openconnect_info *vpninfo); int script_config_tun(struct openconnect_info *vpninfo, const char *reason); /* tun.c */ -void shutdown_tun(struct openconnect_info *vpninfo); +void os_shutdown_tun(struct openconnect_info *vpninfo); int os_read_tun(struct openconnect_info *vpninfo, struct pkt *pkt, int new_pkt); int os_write_tun(struct openconnect_info *vpninfo, struct pkt *pkt); diff --git a/tun-win32.c b/tun-win32.c index 1f212428..a4f8bb79 100644 --- a/tun-win32.c +++ b/tun-win32.c @@ -264,3 +264,12 @@ int os_write_tun(struct openconnect_info *vpninfo, struct pkt *pkt) _("Failed to write to TAP device: %lx\n"), err); return -1; } + +void os_shutdown_tun(struct openconnect_info *vpninfo) +{ + script_config_tun(vpninfo, "disconnect"); + CloseHandle(vpninfo->tun_fh); + vpninfo->tun_fh = NULL; + CloseHandle(vpninfo->tun_rd_overlap.hEvent); + vpninfo->tun_rd_overlap.hEvent = NULL; +} diff --git a/tun.c b/tun.c index b5208e0d..a5ab1a0b 100644 --- a/tun.c +++ b/tun.c @@ -467,15 +467,9 @@ int openconnect_setup_tun_device(struct openconnect_info *vpninfo, char *vpnc_sc return openconnect_setup_tun_fd(vpninfo, tun_fd); } -void shutdown_tun(struct openconnect_info *vpninfo) +#ifndef _WIN32 +void os_shutdown_tun(struct openconnect_info *vpninfo) { -#ifdef _WIN32 - script_config_tun(vpninfo, "disconnect"); - CloseHandle(vpninfo->tun_fh); - vpninfo->tun_fh = NULL; - CloseHandle(vpninfo->tun_rd_overlap.hEvent); - vpninfo->tun_rd_overlap.hEvent = NULL; -#else if (vpninfo->script_tun) { /* nuke the whole process group */ kill(-vpninfo->script_tun, SIGHUP); @@ -494,5 +488,5 @@ void shutdown_tun(struct openconnect_info *vpninfo) if (vpninfo->vpnc_script) close(vpninfo->tun_fd); vpninfo->tun_fd = -1; -#endif } +#endif