Skip to contentSkip to conversation

Restore ability to compile on macOS/FreeBSD with Cmake

PATCH In review Arne Schwabe 4 participants 22 messages Jun 29, 2023 – Jul 17, 2023

lore
Share & tools
lore
#0 lore raw

cover Restore ability to compile on macOS/FreeBSD with Cmake

The patches to the cmake files did a lot of improvements but broke compiling on macOS and FreeBSD. This patch set restores the ability to compile again with these two platforms.

Arne Schwabe (4):
Do not blindly assume python3 is also the interpreter that runs
rst2html
[CMake] Only add -Wno-stringop-truncation on supported compilers Check if the -wrap argument is actually supported by the platform's ld Avoid unused function warning/error on FreeBSD

 CMakeLists.txt      | 33 +++++++++++++++++++++------------
 doc/CMakeLists.txt  |  8 ++++----
 src/openvpn/route.c |  4 +++-
 3 files changed, 28 insertions(+), 17 deletions(-)
Signature · 1 line
2.39.2 (Apple Git-143)
#1 lore raw

PATCH 1/4 Do not blindly assume python3 is also the interpreter that runs rst2html

On my system python3 is the macOS system python3 while rst2html has

#!/opt/homebrew/opt/[email protected].../bin/python3.9

as its first line. Running that with a different python results in missing python modules. So directly execute the rst2html script instead.

Change-Id I7e27ae031179c91cc1bca8122caf2453d6396ec0
---
 doc/CMakeLists.txt | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
doc/CMakeLists.txt +4 -4
index d38805513..2fba80bbd 100644
@@ -50,13 +50,13 @@ if (_GENERATE_HTML_DOC)
     list(APPEND ALL_DOCS openvpn.8.html openvpn-examples.5.html)
     add_custom_command(
         OUTPUT openvpn.8.html
-        COMMAND ${PYTHON} ${RST2HTML} ${RST_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/openvpn.8.rst ${CMAKE_CURRENT_BINARY_DIR}/openvpn.8.html
+        COMMAND ${RST2HTML} ${RST_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/openvpn.8.rst ${CMAKE_CURRENT_BINARY_DIR}/openvpn.8.html
         MAIN_DEPENDENCY openvpn.8.rst
         DEPENDS ${OPENVPN_SECTIONS}
         )
     add_custom_command(
         OUTPUT openvpn-examples.5.html
-        COMMAND ${PYTHON} ${RST2HTML} ${RST_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/openvpn-examples.5.rst ${CMAKE_CURRENT_BINARY_DIR}/openvpn-examples.5.html
+        COMMAND ${RST2HTML} ${RST_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/openvpn-examples.5.rst ${CMAKE_CURRENT_BINARY_DIR}/openvpn-examples.5.html
         MAIN_DEPENDENCY openvpn-examples.5.rst
         DEPENDS ${OPENVPN_EXAMPLES_SECTIONS}
         )
@@ -65,13 +65,13 @@ if (_GENERATE_MAN_DOC)
     list(APPEND ALL_DOCS openvpn.8 openvpn-examples.5)
     add_custom_command(
         OUTPUT openvpn.8
-        COMMAND ${PYTHON} ${RST2MAN} ${RST_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/openvpn.8.rst ${CMAKE_CURRENT_BINARY_DIR}/openvpn.8
+        COMMAND ${RST2MAN} ${RST_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/openvpn.8.rst ${CMAKE_CURRENT_BINARY_DIR}/openvpn.8
         MAIN_DEPENDENCY openvpn.8.rst
         DEPENDS ${OPENVPN_SECTIONS}
         )
     add_custom_command(
         OUTPUT openvpn-examples.5
-        COMMAND ${PYTHON} ${RST2MAN} ${RST_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/openvpn-examples.5.rst ${CMAKE_CURRENT_BINARY_DIR}/openvpn-examples.5
+        COMMAND ${RST2MAN} ${RST_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/openvpn-examples.5.rst ${CMAKE_CURRENT_BINARY_DIR}/openvpn-examples.5
         MAIN_DEPENDENCY openvpn-examples.5.rst
         DEPENDS ${OPENVPN_EXAMPLES_SECTIONS}
         )
Signature · 1 line
2.39.2 (Apple Git-143)
Acked-by on v1 1/4
#2 lore raw

Re: [Openvpn-devel] [PATCH 1/4] Do not blindly assume python3 is also the interpreter that runs rst2html

Quoted 6 lines · Arne Schwabe

On my system python3 is the macOS system python3 while rst2html has

   #!/opt/homebrew/opt/[email protected].../bin/python3.9

as its first line. Running that with a different python results in missing python modules. So directly execute the rst2html script instead.

Signature · 1 line
  Frank Lichtenheld
#3 lore raw

[Openvpn-devel] [PATCH applied] Re: Do not blindly assume python3 is also the interpreter that runs rst2html

In reply to Arne Schwabe

Your patch has been applied to the master branch (cmake things are not in 2.6 yet).

commit 5dbec1c019d14880ae7bf364b062d3589c7fd9e7

Author: Arne Schwabe
Date:   Thu Jun 29 23:56:07 2023 +0200
     Do not blindly assume python3 is also the interpreter that runs rst2html

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Frank Lichtenheld <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg26790.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#4 lore raw

PATCH 2/4 Only add -Wno-stringop-truncation on supported compilers

In reply to Arne Schwabe

The -Wno-stringop-truncation flag is only supported by some GCC versions and not by Clang (macOS, FreeBSD) at all.

Move the includes to the top the file to have them available when running the check_c_compiler_flag.

Change-Id I452bc4ee935d13f8e9095d0a31805a3bbaff0cec
---
 CMakeLists.txt | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
CMakeLists.txt +14 -8
index 3cbba5a38..acebbb73c 100644
@@ -12,6 +12,14 @@ project(openvpn)
 # and OpenSSL having version 1.1.1+ and generally does not offer the same
 # configurability like autoconf
 
+find_package(PkgConfig REQUIRED)
+include(CheckSymbolExists)
+include(CheckIncludeFiles)
+include(CheckCCompilerFlag)
+include(CheckTypeSize)
+include(CheckStructHasMember)
+include(CTest)
+
 option(UNSUPPORTED_BUILDS "Allow unsupported builds" OFF)
 
 if (NOT WIN32 AND NOT ${UNSUPPORTED_BUILDS})
@@ -70,7 +78,12 @@ else ()
     set(CMAKE_CXX_FLAGS_RELEASE "-O2")
     set(CMAKE_C_FLAGS_DEBUG "-g -O1")
     set(CMAKE_CXX_FLAGS_DEBUG "-g -O1")
-    add_compile_options(-Wall -Wuninitialized -Wno-stringop-truncation)
+    add_compile_options(-Wall -Wuninitialized)
+    check_c_compiler_flag(-Wno-stringop-truncation NoStringOpTruncation)
+
+    if (${NoStringOpTruncation})
+        add_compile_options(-Wno-stringop-truncation)
+    endif()
     # We are not ready for this
     #add_compile_options(-Wconversion -Wno-sign-conversion -Wsign-compare)
     if (USE_WERROR)
@@ -78,13 +91,6 @@ else ()
     endif ()
 endif ()
 
-find_package(PkgConfig REQUIRED)
-include(CheckSymbolExists)
-include(CheckIncludeFiles)
-include(CheckTypeSize)
-include(CheckStructHasMember)
-include(CTest)
-
 find_program(PYTHON NAMES python3 python)
 execute_process(
     COMMAND ${PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/contrib/cmake/parse-version.m4.py ${CMAKE_CURRENT_SOURCE_DIR}/version.m4
Signature · 1 line
2.39.2 (Apple Git-143)
Acked-by on v1 2/4
#5 lore raw

Re: [Openvpn-devel] [PATCH 2/4] [CMake] Only add -Wno-stringop-truncation on supported compilers

Quoted 5 lines · Arne Schwabe

The -Wno-stringop-truncation flag is only supported by some GCC versions and not by Clang (macOS, FreeBSD) at all.

Move the includes to the top the file to have them available when running the check_c_compiler_flag.

Signature · 1 line
  Frank Lichtenheld
#6 lore raw

[Openvpn-devel] [PATCH applied] Re: Only add -Wno-stringop-truncation on supported compilers

In reply to Arne Schwabe

Your patch has been applied to the master branch.

commit eb3cd5ea36f9bf235da7b8a51fd6ce29780f0e39

Author: Arne Schwabe
Date:   Thu Jun 29 23:56:08 2023 +0200
     Only add -Wno-stringop-truncation on supported compilers

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Frank Lichtenheld <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg26791.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#7 lore raw

PATCH 2/2 Implement using --peer-fingerprint without CA certificates

In reply to Arne Schwabe

This is implements --peer-fingerprint command to support OpenVPN authentication without involving a PKI.

The current implementation in OpenVPN for peer fingerprint has been already extensively rewritten from the original submission from Jason [1]. The commit preserved the original author since it was based on Jason code/idea.

The current code uses two commits to prepare the --peer-fingerprint solution as which choose to use a simple to use --peer-fingerprint directive instead of using using a --tls-verify script like the v1 of the patch proposed. The two commit preparing this are:

- Extend verify-hash to allow multiple hashes
- Implement peer-fingerprint to check fingerprint of peer certificate

This perparing patches make this actual patch quite short. There are some lines in this patch that bear some similarity to the ones like

    if (!preverify_ok && !session->opt->verify_hash_no_ca)

vs

    if (!preverify_ok && !session->opt->ca_file_none)

But these similarities are one line fragments and dictated by the surrounding style and program flow, so even a complete black box implementation will likely end up with the same lines.

[1] https://www.mail-archive.com/[email protected]/msg16781.html

Change-Id Ie74c3d606c5429455c293c367462244566a936e3
---
 src/openvpn/init.c               |  1 +
 src/openvpn/options.c            | 26 +++++++++++++-------------
 src/openvpn/options.h            |  1 +
 src/openvpn/ssl_common.h         |  1 +
 src/openvpn/ssl_verify_mbedtls.c | 16 ++++++++++++++++
 src/openvpn/ssl_verify_openssl.c |  2 +-
 6 files changed, 33 insertions(+), 14 deletions(-)
src/openvpn/init.c +1 -0
index c023b33c6..d358ad003 100644
@@ -3347,6 +3347,7 @@ do_init_crypto_tls(struct context *c, const unsigned int flags)
     to.verify_hash = options->verify_hash;
     to.verify_hash_algo = options->verify_hash_algo;
     to.verify_hash_depth = options->verify_hash_depth;
+    to.verify_hash_no_ca = options->verify_hash_no_ca;
 #ifdef ENABLE_X509ALTUSERNAME
     memcpy(to.x509_username_field, options->x509_username_field, sizeof(to.x509_username_field));
 #else
src/openvpn/options.c +13 -13
index fe9285384..e4c596b89 100644
@@ -2991,21 +2991,11 @@ options_postprocess_verify_ce(const struct options *options,
         else
         {
 #ifdef ENABLE_CRYPTO_MBEDTLS
-            if (!(options->ca_file))
-            {
-                msg(M_USAGE, "You must define CA file (--ca)");
-            }
-
             if (options->ca_path)
             {
                 msg(M_USAGE, "Parameter --capath cannot be used with the mbed TLS version version of OpenVPN.");
             }
-#else  /* ifdef ENABLE_CRYPTO_MBEDTLS */
-            if ((!(options->ca_file)) && (!(options->ca_path)))
-            {
-                msg(M_USAGE, "You must define CA file (--ca) or CA path (--capath)");
-            }
-#endif
+#endif  /* ifdef ENABLE_CRYPTO_MBEDTLS */
             if (pull)
             {
 
@@ -3737,6 +3727,13 @@ options_postprocess_mutate(struct options *o, struct env_set *es)
         options_postprocess_http_proxy_override(o);
     }
 #endif
+    if (!o->ca_file && !o->ca_path && o->verify_hash
+        && o->verify_hash_depth == 0)
+    {
+        msg(M_INFO, "Using certificate fingerprint to verify peer (no CA "
+            "option set). ");
+        o->verify_hash_no_ca = true;
+    }
 
     if (o->config && streq(o->config, "stdin") && o->remap_sigusr1 == SIGHUP)
     {
@@ -4032,8 +4029,11 @@ options_postprocess_filechecks(struct options *options)
     errs |= check_file_access_inline(options->dh_file_inline, CHKACC_FILE,
                                      options->dh_file, R_OK, "--dh");
 
-    errs |= check_file_access_inline(options->ca_file_inline, CHKACC_FILE,
-                                     options->ca_file, R_OK, "--ca");
+    if (!options->verify_hash_no_ca)
+    {
+        errs |= check_file_access_inline(options->ca_file_inline, CHKACC_FILE,
+                                         options->ca_file, R_OK, "--ca");
+    }
 
     errs |= check_file_access_chroot(options->chroot_dir, CHKACC_FILE,
                                      options->ca_path, R_OK, "--capath");
src/openvpn/options.h +1 -0
index 95f1158a4..f5890b90f 100644
@@ -604,6 +604,7 @@ struct options
     struct verify_hash_list *verify_hash;
     hash_algo_type verify_hash_algo;
     int verify_hash_depth;
+    bool verify_hash_no_ca;
     unsigned int ssl_flags; /* set to SSLF_x flags from ssl.h */
 
 #ifdef ENABLE_PKCS11
src/openvpn/ssl_common.h +1 -0
index c0b3caa71..27b029479 100644
@@ -345,6 +345,7 @@ struct tls_options
     const char *remote_cert_eku;
     struct verify_hash_list *verify_hash;
     int verify_hash_depth;
+    bool verify_hash_no_ca;
     hash_algo_type verify_hash_algo;
 #ifdef ENABLE_X509ALTUSERNAME
     char *x509_username_field[MAX_PARMS];
src/openvpn/ssl_verify_mbedtls.c +16 -0
index c9ef7a171..e3437f740 100644
@@ -62,6 +62,22 @@ verify_callback(void *session_obj, mbedtls_x509_crt *cert, int cert_depth,
     struct buffer cert_fingerprint = x509_get_sha256_fingerprint(cert, &gc);
     cert_hash_remember(session, cert_depth, &cert_fingerprint);
 
+    if (session->opt->verify_hash_no_ca)
+    {
+        /*
+         * If we decide to verify the peer certificate based on the fingerprint
+         * we ignore wrong dates and the certificate not being trusted.
+         * Any other problem with the certificate (wrong key, bad cert,...)
+         * will still trigger an error.
+         * Clearing these flags relies on verify_cert will later rejecting a
+         * certificate that has no matching fingerprint.
+         */
+        uint32_t flags_ignore = MBEDTLS_X509_BADCERT_NOT_TRUSTED
+                                | MBEDTLS_X509_BADCERT_EXPIRED
+                                | MBEDTLS_X509_BADCERT_FUTURE;
+        *flags = *flags & ~flags_ignore;
+    }
+
     /* did peer present cert which was signed by our root cert? */
     if (*flags != 0)
     {
src/openvpn/ssl_verify_openssl.c +1 -1
index ac36f09db..e24ce4e4a 100644
@@ -67,7 +67,7 @@ verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
     cert_hash_remember(session, X509_STORE_CTX_get_error_depth(ctx), &cert_hash);
 
     /* did peer present cert which was signed by our root cert? */
-    if (!preverify_ok)
+    if (!preverify_ok && !session->opt->verify_hash_no_ca)
     {
         /* get the X509 name */
         char *subject = x509_get_subject(current_cert, &gc);
Signature · 1 line
2.39.2 (Apple Git-143)
#8 lore raw

Re: [Openvpn-devel] [PATCH 2/2] Implement using --peer-fingerprint without CA certificates

The grammar in the 3rd sentence in the comment below is messed up. (I think I understand it, but I'm not sure.)

Quoted 6 lines
src/openvpn/ssl_verify_mbedtls.c +6 -0
+    if (session->opt->verify_hash_no_ca)
+    {
+        /*
+         * If we decide to verify the peer certificate based on the fingerprint
+         * we ignore wrong dates and the certificate not being trusted.
+         * Any other problem with the certificate (wrong key, bad cert,...)

src/openvpn/ssl_verify_mbedtls.c verify_callback(void *session_obj, mbedtls_x509_crt *cert, int cert_depth, · line 80

Quoted 10 lines
src/openvpn/ssl_verify_mbedtls.c +10 -0
+         * will still trigger an error.
+         * Clearing these flags relies on verify_cert will later rejecting a
+         * certificate that has no matching fingerprint.
+         */
+        uint32_t flags_ignore = MBEDTLS_X509_BADCERT_NOT_TRUSTED
+                                | MBEDTLS_X509_BADCERT_EXPIRED
+                                | MBEDTLS_X509_BADCERT_FUTURE;
+        *flags = *flags & ~flags_ignore;
+    }
+

Also, this comment is copied verbatim from Jason's commit 423ced962d which has been reverted. I'm not a lawyer, but since comments are relatively easy to rephrase, I think it's better to do that. My suggestion:

/*
* If we verify the peer certificate based only on the fingerprint,
* we ignore flags regarding the certificate's validity period and
* the certificate being untrusted (because we don't have a CA to
* check against).
* Any other flags will still trigger an error.
*
* If the certificate's fingerprint doesn't match, it will be rejected
* by verify_cert later.
*/

#9 lore raw

Re: [Openvpn-devel] [PATCH 2/2] Implement using --peer-fingerprint without CA certificates

Am 30.06.23 um 15:31 schrieb Maximilian Fillinger:

Quoted 19 lines

The grammar in the 3rd sentence in the comment below is messed up. (I think I understand it, but I'm not sure.)

Quoted 6 lines
src/openvpn/ssl_verify_mbedtls.c +6 -0
+    if (session->opt->verify_hash_no_ca)
+    {
+        /*
+         * If we decide to verify the peer certificate based on the fingerprint
+         * we ignore wrong dates and the certificate not being trusted.
+         * Any other problem with the certificate (wrong key, bad cert,...)

src/openvpn/ssl_verify_mbedtls.c verify_callback(void *session_obj, mbedtls_x509_crt *cert, int cert_depth, · line 80

Quoted 10 lines
src/openvpn/ssl_verify_mbedtls.c +10 -0
+         * will still trigger an error.
+         * Clearing these flags relies on verify_cert will later rejecting a
+         * certificate that has no matching fingerprint.
+         */
+        uint32_t flags_ignore = MBEDTLS_X509_BADCERT_NOT_TRUSTED
+                                | MBEDTLS_X509_BADCERT_EXPIRED
+                                | MBEDTLS_X509_BADCERT_FUTURE;
+        *flags = *flags & ~flags_ignore;
+    }
+
Quoted 1 line

Also, this comment is copied verbatim from Jason's commit 423ced962d which has been reverted. I'm not a lawyer, but since comments are relatively easy to rephrase, I think it's better to do that. My suggestion:

The comment is already mine. Jason never included an mBed TLS implementation. I attributed the commit to Jason but some of the code and this comment is already written by me.

Arne

#10 lore raw

PATCH 3/4 Check if the -wrap argument is actually supported by the platform's ld

In reply to Arne Schwabe

This avoids build errors on macOS. Also the test_tls_crypt command works just fine on FreeBSD with its linkers, so do not make that test Linux only.

Change-Id Id26676bdc576c7d3d6726afa43fe6c7a397c579b
---
 CMakeLists.txt | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
CMakeLists.txt +7 -4
index acebbb73c..d2445b414 100644
@@ -16,6 +16,7 @@ find_package(PkgConfig REQUIRED)
 include(CheckSymbolExists)
 include(CheckIncludeFiles)
 include(CheckCCompilerFlag)
+include(CheckLinkerFlag)
 include(CheckTypeSize)
 include(CheckStructHasMember)
 include(CTest)
@@ -560,18 +561,20 @@ if (BUILD_TESTING)
             )
     endif ()
 
-    if (NOT MSVC)
-        # MSVC does not support --wrap
+    # MSVC and Apple's LLVM ld do not support --wrap
+    check_linker_flag(C -Wl,--wrap=parse_line LD_SUPPORTS_WRAP)
+
+    if (${LD_SUPPORTS_WRAP})
         list(APPEND unit_tests
             "test_argv"
+            "test_tls_crypt"
             )
     endif ()
 
-    # These tests work on only on Linux since they depend on special linker features
+    # These tests work on only on Linux since they depend on special Linux features
     if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
         list(APPEND unit_tests
             "test_networking"
-            "test_tls_crypt"
             )
     endif ()
 
Signature · 1 line
2.39.2 (Apple Git-143)
#11 lore raw

Re: [Openvpn-devel] [PATCH 3/4] Check if the -wrap argument is actually supported by the platform's ld

Quoted 2 lines · Arne Schwabe

This avoids build errors on macOS. Also the test_tls_crypt command works just fine on FreeBSD with its linkers, so do not make that test Linux only.

NAK. Breaks build on mingw. Will investigate why.

Regards,

Signature · 1 line
  Frank Lichtenheld
#12 lore raw

PATCH 4/4 Avoid unused function warning/error on FreeBSD

In reply to Arne Schwabe

the funktion is_on_link is not used on FreeBSD and triggers a warning/error (-Werror) on FreeBSD.

Change-Id I6757d6509ff3ff522d6de417372a21e73ccca3ba
---
 src/openvpn/route.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
src/openvpn/route.c +3 -1
index d18acd016..2180b7d1a 100644
@@ -1541,13 +1541,15 @@ local_route(in_addr_t network,
     return LR_NOMATCH;
 }
 
-/* Return true if the "on-link" form of the route should be used.  This is when the gateway for a
+/* Return true if the "on-link" form of the route should be used.  This is when the gateway for
  * a route is specified as an interface rather than an address. */
+#ifndef TARGET_FREEBSD
 static inline bool
 is_on_link(const int is_local_route, const unsigned int flags, const struct route_gateway_info *rgi)
 {
     return rgi && (is_local_route == LR_MATCH || ((flags & ROUTE_REF_GW) && (rgi->flags & RGI_ON_LINK)));
 }
+#endif
 
 bool
 add_route(struct route_ipv4 *r,
Signature · 1 line
2.39.2 (Apple Git-143)
#13 lore raw

Re: [Openvpn-devel] [PATCH 4/4] Avoid unused function warning/error on FreeBSD

Quoted 14 lines · Arne Schwabe

the funktion is_on_link is not used on FreeBSD and triggers a warning/error (-Werror) on FreeBSD.

Change-Id I6757d6509ff3ff522d6de417372a21e73ccca3ba
---
 src/openvpn/route.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
src/openvpn/route.c +0 -0
index d18acd016..2180b7d1a 100644

src/openvpn/route.c local_route(in_addr_t network, · line 1546

Quoted 7 lines
src/openvpn/route.c +2 -1
@@ -1541,13 +1541,15 @@ local_route(in_addr_t network,
     return LR_NOMATCH;
 }
 
-/* Return true if the "on-link" form of the route should be used.  This is when the gateway for a
+/* Return true if the "on-link" form of the route should be used.  This is when the gateway for
  * a route is specified as an interface rather than an address. */
+#ifndef TARGET_FREEBSD

The actual condition seems to be

#if defined(TARGET_LINUX) || defined(_WIN32) || defined(TARGET_DARWIN)

src/openvpn/route.c local_route(in_addr_t network, · line 1555

Quoted 9 lines
src/openvpn/route.c +1 -0
 static inline bool
 is_on_link(const int is_local_route, const unsigned int flags, const struct route_gateway_info *rgi)
 {
     return rgi && (is_local_route == LR_MATCH || ((flags & ROUTE_REF_GW) && (rgi->flags & RGI_ON_LINK)));
 }
+#endif
 
 bool
 add_route(struct route_ipv4 *r,

Regards,

Signature · 1 line
  Frank Lichtenheld
#14 lore raw

PATCH v2 3/4 Check if the -wrap argument is actually supported by the platform's ld

In reply to Arne Schwabe

This avoids build errors on macOS. Also the test_tls_crypt command works just fine on FreeBSD with its linkers, so do not make that test Linux only.

Patch v2: allow running with old cmake version (cmake 3 on RHEL7 with EPEL

          is only 3.17)
Change-Id Id26676bdc576c7d3d6726afa43fe6c7a397c579b
---
 CMakeLists.txt | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
CMakeLists.txt +11 -4
index acebbb73c..a982c478a 100644
@@ -16,6 +16,7 @@ find_package(PkgConfig REQUIRED)
 include(CheckSymbolExists)
 include(CheckIncludeFiles)
 include(CheckCCompilerFlag)
+include(CheckLinkerFlag)
 include(CheckTypeSize)
 include(CheckStructHasMember)
 include(CTest)
@@ -560,18 +561,24 @@ if (BUILD_TESTING)
             )
     endif ()
 
-    if (NOT MSVC)
-        # MSVC does not support --wrap
+    # MSVC and Apple's LLVM ld do not support --wrap
+    # This test requires cmake >= 1.17, so check if check_linker_flag is
+    # available
+    if (COMMAND check_linker_flag)
+        check_linker_flag(C -Wl,--wrap=parse_line LD_SUPPORTS_WRAP)
+    endif()
+
+    if (${LD_SUPPORTS_WRAP})
         list(APPEND unit_tests
             "test_argv"
+            "test_tls_crypt"
             )
     endif ()
 
-    # These tests work on only on Linux since they depend on special linker features
+    # These tests work on only on Linux since they depend on special Linux features
     if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
         list(APPEND unit_tests
             "test_networking"
-            "test_tls_crypt"
             )
     endif ()
 
Signature · 1 line
2.39.2 (Apple Git-143)
#15 lore raw

PATCH v2 4/4 Avoid unused function warning/error on FreeBSD (and potientially others)

the funktion is_on_link is not used on FreeBSD and triggers a warning/error (-Werror) on FreeBSD.

Patch v2: use actual platforms instead an ifndef FreeBSD

Change-Id I6757d6509ff3ff522d6de417372a21e73ccca3ba
---
 src/openvpn/route.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
src/openvpn/route.c +3 -1
index d18acd016..0d04a5a33 100644
@@ -1541,13 +1541,15 @@ local_route(in_addr_t network,
     return LR_NOMATCH;
 }
 
-/* Return true if the "on-link" form of the route should be used.  This is when the gateway for a
+/* Return true if the "on-link" form of the route should be used.  This is when the gateway for
  * a route is specified as an interface rather than an address. */
+#if defined(TARGET_LINUX) || defined(_WIN32) || defined(TARGET_DARWIN)
 static inline bool
 is_on_link(const int is_local_route, const unsigned int flags, const struct route_gateway_info *rgi)
 {
     return rgi && (is_local_route == LR_MATCH || ((flags & ROUTE_REF_GW) && (rgi->flags & RGI_ON_LINK)));
 }
+#endif
 
 bool
 add_route(struct route_ipv4 *r,
Signature · 1 line
2.39.2 (Apple Git-143)
Acked-by on v2 4/4
#16 lore raw

[Openvpn-devel] [PATCH applied] Re: Avoid unused function warning/error on FreeBSD (and potientially others)

Checked route.c: is_on_link() shows up 4 times, Linux, WIN32 and 2x DARWIN, so this should be fine. Tested by pushing to buildbot and GHA.

Your patch has been applied to the master and release/2.6 branch.

commit 99035769233fb1186b72cd8e1e9966a0d077e53d (master) commit 6cadac3cf86da918f1f83f77e9ab2129c7b60954 (release/2.6)

Author: Arne Schwabe
Date:   Sat Jul 1 22:24:53 2023 +0200
     Avoid unused function warning/error on FreeBSD (and potientially others)

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg26804.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#17 lore raw

Re: [Openvpn-devel] [PATCH v2 3/4] Check if the -wrap argument is actually supported by the platform's ld

In reply to Arne Schwabe
Quoted 17 lines · Arne Schwabe

This avoids build errors on macOS. Also the test_tls_crypt command works just fine on FreeBSD with its linkers, so do not make that test Linux only.

Patch v2: allow running with old cmake version (cmake 3 on RHEL7 with EPEL

          is only 3.17)
Change-Id Id26676bdc576c7d3d6726afa43fe6c7a397c579b
---
 CMakeLists.txt | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
CMakeLists.txt +0 -0
index acebbb73c..a982c478a 100644

CMakeLists.txt find_package(PkgConfig REQUIRED) · line 19

Quoted 4 lines
CMakeLists.txt +1 -0
@@ -16,6 +16,7 @@ find_package(PkgConfig REQUIRED)
 include(CheckSymbolExists)
 include(CheckIncludeFiles)
 include(CheckCCompilerFlag)
+include(CheckLinkerFlag)

Tested with Ubuntu 20.04 LTS (cmake 3.16) and I needed to use "include(CheckLinkerFlag OPTIONAL)", otherwise it just threw an error.

CMakeLists.txt if (BUILD_TESTING) · line 565

Quoted 11 lines
CMakeLists.txt +2 -2
 include(CheckTypeSize)
 include(CheckStructHasMember)
 include(CTest)
@@ -560,18 +561,24 @@ if (BUILD_TESTING)
             )
     endif ()
 
-    if (NOT MSVC)
-        # MSVC does not support --wrap
+    # MSVC and Apple's LLVM ld do not support --wrap
+    # This test requires cmake >= 1.17, so check if check_linker_flag is

"> 3.17" or ">= 3.18"

Quoted 11 lines
CMakeLists.txt +7 -0
+    # available
+    if (COMMAND check_linker_flag)
+        check_linker_flag(C -Wl,--wrap=parse_line LD_SUPPORTS_WRAP)
+    endif()
+
+    if (${LD_SUPPORTS_WRAP})
         list(APPEND unit_tests
             "test_argv"
+            "test_tls_crypt"
             )
     endif ()

CMakeLists.txt if (BUILD_TESTING) · line 584

Quoted 10 lines
CMakeLists.txt +1 -2
 
-    # These tests work on only on Linux since they depend on special linker features
+    # These tests work on only on Linux since they depend on special Linux features
     if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
         list(APPEND unit_tests
             "test_networking"
-            "test_tls_crypt"
             )
     endif ()
 

Regards,

Signature · 1 line
  Frank Lichtenheld
#18 lore raw

PATCH v3 3/4 Check if the -wrap argument is actually supported by the platform's ld

In reply to Arne Schwabe

This avoids build errors on macOS. Also the test_tls_crypt command works just fine on FreeBSD with its linkers, so do not make that test Linux only.

Patch v2: allow running with old cmake version (cmake 3 on RHEL7 with EPEL

          is only 3.17)

Patch v3: add OPTIONAL keyword to Incldue required by some cmake versions

Change-Id Id26676bdc576c7d3d6726afa43fe6c7a397c579b
---
 CMakeLists.txt | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
CMakeLists.txt +11 -4
index 2d0cd5dd0..7dae6655d 100644
@@ -16,6 +16,7 @@ find_package(PkgConfig REQUIRED)
 include(CheckSymbolExists)
 include(CheckIncludeFiles)
 include(CheckCCompilerFlag)
+include(CheckLinkerFlag OPTIONAL)
 include(CheckTypeSize)
 include(CheckStructHasMember)
 include(CTest)
@@ -564,18 +565,24 @@ if (BUILD_TESTING)
             )
     endif ()
 
-    if (NOT MSVC)
-        # MSVC does not support --wrap
+    # MSVC and Apple's LLVM ld do not support --wrap
+    # This test requires cmake >= 3.18, so check if check_linker_flag is
+    # available
+    if (COMMAND check_linker_flag)
+        check_linker_flag(C -Wl,--wrap=parse_line LD_SUPPORTS_WRAP)
+    endif()
+
+    if (${LD_SUPPORTS_WRAP})
         list(APPEND unit_tests
             "test_argv"
+            "test_tls_crypt"
             )
     endif ()
 
-    # These tests work on only on Linux since they depend on special linker features
+    # These tests work on only on Linux since they depend on special Linux features
     if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
         list(APPEND unit_tests
             "test_networking"
-            "test_tls_crypt"
             )
     endif ()
 
Signature · 1 line
2.39.2 (Apple Git-143)
Acked-by on v3 3/4
#19 lore raw

Re: [Openvpn-devel] [PATCH v3 3/4] Check if the -wrap argument is actually supported by the platform's ld

Quoted 6 lines · Arne Schwabe

This avoids build errors on macOS. Also the test_tls_crypt command works just fine on FreeBSD with its linkers, so do not make that test Linux only.

Patch v2: allow running with old cmake version (cmake 3 on RHEL7 with EPEL

          is only 3.17)

Patch v3: add OPTIONAL keyword to Incldue required by some cmake versions

Yeah, I also have no idea why you didn't need that for your CMake. Anyway, it is correct according to the documentation. And it is definitely required on Ubuntu 20.04.

Tested on Ubuntu 20.04 (cmake 3.16.3), Ubuntu 22.04 (cmake 3.22.1), and checked build results for GHA.

Quoted 5 lines
Change-Id Id26676bdc576c7d3d6726afa43fe6c7a397c579b
---
 CMakeLists.txt | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
Signature · 1 line
  Frank Lichtenheld
#20 lore raw

Re: [Openvpn-devel] [PATCH v3 3/4] Check if the -wrap argument is actually supported by the platform's ld

Quoted 8 lines · Frank Lichtenheld
Quoted 6 lines · Arne Schwabe

This avoids build errors on macOS. Also the test_tls_crypt command works just fine on FreeBSD with its linkers, so do not make that test Linux only.

Patch v2: allow running with old cmake version (cmake 3 on RHEL7 with EPEL

          is only 3.17)

Patch v3: add OPTIONAL keyword to Incldue required by some cmake versions

Quoted 8 lines

Yeah, I also have no idea why you didn't need that for your CMake. Anyway, it is correct according to the documentation. And it is definitely required on Ubuntu 20.04.

Tested on Ubuntu 20.04 (cmake 3.16.3), Ubuntu 22.04 (cmake 3.22.1), and checked build results for GHA.

Note: please merge after
"Mock openvpn_exece on win32 also for test_tls_crypt" to avoid broken MinGW builds.

Regards,

Signature · 1 line
  Frank Lichtenheld
#21 lore raw

[Openvpn-devel] [PATCH applied] Re: Check if the -wrap argument is actually supported by the platform's ld

In reply to Arne Schwabe

Tested with GHA mingw/msvc builds, and the resulting unit test runs - all looks green.

(As a side note, we *build* test_tls_crypt on Windows now, but the GHA "mingw unittests" runs do not seem to run it yet -> patch to build.yaml missing?)

Your patch has been applied to the master branch.

commit 4ef76f0ee4e122dcd616e1b1e2d652562ab10756

Author: Arne Schwabe
Date:   Wed Jul 12 11:55:29 2023 +0200
     Check if the -wrap argument is actually supported by the platform's ld

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Frank Lichtenheld <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg26850.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering