From 297e93ed543d8c51cc90600460f7a0bed36b3e58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Thu, 16 Nov 2017 15:52:30 +0000 Subject: [PATCH] Add persist option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adrien Gallouët --- src/main.c | 5 ++++- src/tun.c | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 864ef80..50cbeec 100644 --- a/src/main.c +++ b/src/main.c @@ -52,6 +52,7 @@ static struct { int chacha20; int version; int keygen; + int persist; struct { unsigned char *data; long size; @@ -193,6 +194,7 @@ gt_setup_option(int argc, char **argv) { "bind-backup", >.bind.backup, option_str }, { "bind-port", >.bind.port, option_long }, { "dev", >.dev, option_str }, + { "persist", NULL, option_option }, { "mtu", >.mtu, option_long }, { "mtu-auto", NULL, option_option }, { "keyfile", >.keyfile, option_str }, @@ -244,6 +246,7 @@ gt_setup_option(int argc, char **argv) gt.chacha20 = option_is_set(opts, "chacha20"); gt.version = option_is_set(opts, "version"); gt.keygen = option_is_set(opts, "keygen"); + gt.persist = option_is_set(opts, "persist"); gt.buf.data = malloc(gt.buf.size); @@ -327,7 +330,7 @@ main(int argc, char **argv) return 1; } - if (tun_set_persist(tun_fd, 0) == -1) + if (tun_set_persist(tun_fd, gt.persist) == -1) perror("tun_set_persist"); if (str_empty(gt.keyfile)) { diff --git a/src/tun.c b/src/tun.c index f2b8532..6afd6d1 100644 --- a/src/tun.c +++ b/src/tun.c @@ -245,6 +245,7 @@ tun_set_persist(int fd, int on) #ifdef TUNSETPERSIST return ioctl(fd, TUNSETPERSIST, on); #else - return 0; + errno = ENOSYS; + return -1; #endif }