Ticket #85: 0001-Print-helpful-error-message-on-mktun-rmtun-if-not-av.patch

File 0001-Print-helpful-error-message-on-mktun-rmtun-if-not-av.patch, 2.6 KB (added by Gert Döring, 9 years ago)

print helpful message on --mktun on non-linux

  • src/openvpn/init.c

    From eb47066238189b1fded887ffce25e6ff57c86a0d Mon Sep 17 00:00:00 2001
    From: Gert Doering <gert@greenie.muc.de>
    Date: Tue, 28 Apr 2015 13:01:41 +0200
    Subject: [PATCH] Print helpful error message on --mktun/--rmtun if not
     available.
    
    OpenVPN only supports --mktun/--rmtun to create/destroy persistant
    tunnels on Linux.  On BSD OSes, "ifconfig tun0 create" can do the
    same job, so we do not actually need to support it - but the previous
    error message ("unknown option") wasn't helpful.  So always accept
    the option now, and on non-supported systems, direct user to manpage.
    
    Trac #85
    
    Signed-off-by: Gert Doering <gert@greenie.muc.de>
    ---
     src/openvpn/init.c    | 10 ++++++++--
     src/openvpn/options.c |  2 --
     2 files changed, 8 insertions(+), 4 deletions(-)
    
    diff --git a/src/openvpn/init.c b/src/openvpn/init.c
    index b97d2da..42cb3e2 100644
    a b do_genkey (const struct options * options) 
    887887bool
    888888do_persist_tuntap (const struct options *options)
    889889{
    890 #ifdef ENABLE_FEATURE_TUN_PERSIST
    891890  if (options->persist_config)
    892891    {
    893892      /* sanity check on options for --mktun or --rmtun */
    do_persist_tuntap (const struct options *options) 
    901900        )
    902901        msg (M_FATAL|M_OPTERR,
    903902             "options --mktun or --rmtun should only be used together with --dev");
     903#ifdef ENABLE_FEATURE_TUN_PERSIST
    904904      tuncfg (options->dev, options->dev_type, options->dev_node,
    905905              options->persist_mode,
    906906              options->username, options->groupname, &options->tuntap_options);
    907907      if (options->persist_mode && options->lladdr)
    908908        set_lladdr(options->dev, options->lladdr, NULL);
    909909      return true;
    910     }
     910#else
     911      msg( M_FATAL|M_OPTERR,
     912        "options --mktun and --rmtun are not available on your operating "
     913        "system.  Please check 'man tun' (or 'tap'), whether your system "
     914        "supports using 'ifconfig %s create' / 'destroy' to create/remove "
     915        "persistant tunnel interfaces.", options->dev );
    911916#endif
     917    }
    912918  return false;
    913919}
    914920
  • src/openvpn/options.c

    diff --git a/src/openvpn/options.c b/src/openvpn/options.c
    index e8cf06a..4f27336 100644
    a b add_option (struct options *options, 
    70237023      options->pkcs11_id_management = true;
    70247024    }
    70257025#endif
    7026 #ifdef ENABLE_FEATURE_TUN_PERSIST
    70277026  else if (streq (p[0], "rmtun"))
    70287027    {
    70297028      VERIFY_PERMISSION (OPT_P_GENERAL);
    add_option (struct options *options, 
    70367035      options->persist_config = true;
    70377036      options->persist_mode = 1;
    70387037    }
    7039 #endif
    70407038  else if (streq (p[0], "peer-id"))
    70417039    {
    70427040      VERIFY_PERMISSION (OPT_P_PEER_ID);