Skip to contentSkip to conversation

generic code clean-up

PATCH In review Antonio Quartulli 6 participants 18 messages Aug 11, 2017 – Aug 20, 2017

lore
Share & tools
lore
#0 lore raw

cover generic code clean-up

These 5 patches contain basic clean-up work about
issues highlighted by static analyzers during
some test-runs.

All the patches except "ensure function declarations are compiled with their definitions" should be straightforward. For the latter
I can imagine there might be some arguments against it.

Cheers,

Antonio Quartulli (5):
make function declarations C99 compliant
ensure function declarations are compiled with their definitions add missing static attribute to functions
remove unused functions
use NULL instead of 0 when assigning pointers

 src/openvpn/buffer.c             |  2 +-
 src/openvpn/comp-lz4.c           |  2 +-
 src/openvpn/console.c            |  2 +-
 src/openvpn/console.h            |  8 ++++----
 src/openvpn/console_builtin.c    |  2 +-
 src/openvpn/console_systemd.c    |  4 ++--
 src/openvpn/crypto.c             |  4 ++--
 src/openvpn/crypto.h             |  5 ++++-
 src/openvpn/crypto_mbedtls.c     | 10 +++++-----
 src/openvpn/crypto_mbedtls.h     |  4 ++--
 src/openvpn/crypto_openssl.c     |  6 +++---
 src/openvpn/error.c              |  9 ++++-----
 src/openvpn/error.h              |  2 +-
 src/openvpn/forward-inline.h     | 28 ++--------------------------
 src/openvpn/forward.c            |  2 +-
 src/openvpn/forward.h            | 35 +++++++++++++++++++++++++++++++++++
 src/openvpn/init.c               |  2 +-
 src/openvpn/init.h               |  2 ++
 src/openvpn/interval.h           |  2 +-
 src/openvpn/lladdr.c             |  1 +
 src/openvpn/manage.c             |  8 ++++----
 src/openvpn/manage.h             | 11 ++++++-----
 src/openvpn/mbuf.h               |  4 ++--
 src/openvpn/misc.c               | 23 -----------------------
 src/openvpn/mroute.h             | 21 +++++++++++----------
 src/openvpn/mtcp.c               |  2 +-
 src/openvpn/multi.c              |  4 ++--
 src/openvpn/multi.h              |  7 +++----
 src/openvpn/ntlm.c               |  2 +-
 src/openvpn/occ-inline.h         | 10 +++-------
 src/openvpn/occ.h                |  6 ++++++
 src/openvpn/options.c            |  8 ++++----
 src/openvpn/packet_id.c          |  2 +-
 src/openvpn/packet_id.h          |  2 +-
 src/openvpn/pf-inline.h          |  6 ++----
 src/openvpn/pf.h                 |  6 ++++++
 src/openvpn/ping-inline.h        |  6 ++----
 src/openvpn/ping.h               |  4 ++++
 src/openvpn/pkcs11.c             |  6 +++---
 src/openvpn/platform.c           |  2 +-
 src/openvpn/plugin.h             |  2 ++
 src/openvpn/proxy.c              |  2 +-
 src/openvpn/ps.c                 |  4 ++--
 src/openvpn/route.c              |  4 ++--
 src/openvpn/socket.c             |  2 +-
 src/openvpn/socket.h             | 13 +++++++------
 src/openvpn/ssl.c                | 16 +++-------------
 src/openvpn/ssl_backend.h        |  6 +++---
 src/openvpn/ssl_mbedtls.c        |  6 +++---
 src/openvpn/ssl_openssl.c        | 20 +++++++-------------
 src/openvpn/ssl_verify_openssl.c |  4 ++--
 src/openvpn/win32.c              |  6 +++---
 src/openvpn/win32.h              |  4 ++--
 53 files changed, 175 insertions(+), 186 deletions(-)
Signature · 1 line
2.14.0
#1 lore raw

PATCH 1/5 make function declarations C99 compliant

From: Antonio Quartulli <[email protected]...>

In the attempt of adhering to the C99 standard as much as possible, ensure that all the function declarations with no parameter contain the "void" keyword[1].

Defects identified with sparse[2].

[1] ISO/IEC 9899:1999 spec, TC3 - section 6.7.5.3
[1] https://sparse.wiki.kernel.org/index.php/Main_Page

---
 src/openvpn/buffer.c          |  2 +-
 src/openvpn/console.c         |  2 +-
 src/openvpn/console.h         |  8 ++++----
 src/openvpn/console_builtin.c |  2 +-
 src/openvpn/console_systemd.c |  4 ++--
 src/openvpn/crypto.c          |  4 ++--
 src/openvpn/crypto.h          |  2 +-
 src/openvpn/crypto_mbedtls.c  | 10 +++++-----
 src/openvpn/crypto_mbedtls.h  |  4 ++--
 src/openvpn/crypto_openssl.c  |  6 +++---
 src/openvpn/error.c           |  6 +++---
 src/openvpn/error.h           |  2 +-
 src/openvpn/init.c            |  2 +-
 src/openvpn/interval.h        |  2 +-
 src/openvpn/manage.c          |  2 +-
 src/openvpn/occ-inline.h      |  2 +-
 src/openvpn/packet_id.c       |  2 +-
 src/openvpn/packet_id.h       |  2 +-
 src/openvpn/pkcs11.c          |  6 +++---
 src/openvpn/platform.c        |  2 +-
 src/openvpn/ps.c              |  2 +-
 src/openvpn/ssl.c             |  4 ++--
 src/openvpn/ssl_backend.h     |  6 +++---
 src/openvpn/ssl_mbedtls.c     |  6 +++---
 src/openvpn/ssl_openssl.c     | 12 ++++++------
 src/openvpn/win32.c           |  6 +++---
 src/openvpn/win32.h           |  4 ++--
 27 files changed, 56 insertions(+), 56 deletions(-)
src/openvpn/buffer.c +1 -1
index 87e27ec0..a63ce14a 100644
@@ -180,7 +180,7 @@ buf_assign(struct buffer *dest, const struct buffer *src)
 }
 
 struct buffer
-clear_buf()
+clear_buf(void)
 {
     struct buffer buf;
     CLEAR(buf);
src/openvpn/console.c +1 -1
index eb6944d0..7e170241 100644
@@ -44,7 +44,7 @@ struct _query_user query_user[QUERY_USER_NUMSLOTS];  /* GLOBAL */
 
 
 void
-query_user_clear()
+query_user_clear(void)
 {
     int i;
 
src/openvpn/console.h +4 -4
index aa51e6f6..3f74e77e 100644
@@ -46,7 +46,7 @@ extern struct _query_user query_user[];  /**< Global variable, declared in conso
  * Wipes all data put into all of the query_user structs
  *
  */
-void query_user_clear();
+void query_user_clear(void);
 
 
 /**
@@ -72,7 +72,7 @@ void query_user_add(char *prompt, size_t prompt_len,
  *
  * @return True if executing all the defined steps completed successfully
  */
-bool query_user_exec_builtin();
+bool query_user_exec_builtin(void);
 
 
 #if defined(ENABLE_SYSTEMD)
@@ -83,7 +83,7 @@ bool query_user_exec_builtin();
  *
  * @return True if executing all the defined steps completed successfully
  */
-bool query_user_exec();
+bool query_user_exec(void);
 
 #else  /* ENABLE_SYSTEMD not defined*/
 /**
@@ -92,7 +92,7 @@ bool query_user_exec();
  *
  */
 static bool
-query_user_exec()
+query_user_exec(void)
 {
     return query_user_exec_builtin();
 }
src/openvpn/console_builtin.c +1 -1
index 7b95da9d..f005ed74 100644
@@ -267,7 +267,7 @@ get_console_input(const char *prompt, const bool echo, char *input, const int ca
  *
  */
 bool
-query_user_exec_builtin()
+query_user_exec_builtin(void)
 {
     bool ret = true; /* Presume everything goes okay */
     int i;
src/openvpn/console_systemd.c +2 -2
index 8cee8c8e..e7a72ae3 100644
@@ -41,7 +41,7 @@
  */
 
 static bool
-check_systemd_running()
+check_systemd_running(void)
 {
     struct stat c;
 
@@ -95,7 +95,7 @@ get_console_input_systemd(const char *prompt, const bool echo, char *input, cons
  *
  */
 bool
-query_user_exec()
+query_user_exec(void)
 {
     bool ret = true;  /* Presume everything goes okay */
     int i;
src/openvpn/crypto.c +2 -2
index 909e901f..692501d2 100644
@@ -1715,7 +1715,7 @@ static int nonce_secret_len = 0; /* GLOBAL */
 
 /* Reset the nonce value, also done periodically to refresh entropy */
 static void
-prng_reset_nonce()
+prng_reset_nonce(void)
 {
     const int size = md_kt_size(nonce_md) + nonce_secret_len;
 #if 1 /* Must be 1 for real usage */
@@ -1799,7 +1799,7 @@ prng_bytes(uint8_t *output, int len)
 
 /* an analogue to the random() function, but use prng_bytes */
 long int
-get_random()
+get_random(void)
 {
     long int l;
     prng_bytes((unsigned char *)&l, sizeof(l));
src/openvpn/crypto.h +1 -1
index f00a6d8f..f1b6c20a 100644
@@ -465,7 +465,7 @@ void prng_init(const char *md_name, const int nonce_secret_len_parm);
  */
 void prng_bytes(uint8_t *output, int len);
 
-void prng_uninit();
+void prng_uninit(void);
 
 void test_crypto(struct crypto_options *co, struct frame *f);
 
src/openvpn/crypto_mbedtls.c +5 -5
index 7bd69695..a387a7e9 100644
@@ -160,7 +160,7 @@ print_cipher(const cipher_kt_t *info)
 }
 
 void
-show_available_ciphers()
+show_available_ciphers(void)
 {
     const int *ciphers = mbedtls_cipher_list();
 
@@ -197,7 +197,7 @@ show_available_ciphers()
 }
 
 void
-show_available_digests()
+show_available_digests(void)
 {
     const int *digests = mbedtls_md_list();
 
@@ -224,7 +224,7 @@ show_available_digests()
 }
 
 void
-show_available_engines()
+show_available_engines(void)
 {
     printf("mbed TLS hardware crypto engine functionality is not available\n");
 }
@@ -243,7 +243,7 @@ show_available_engines()
  * entropy gathering function.
  */
 mbedtls_ctr_drbg_context *
-rand_ctx_get()
+rand_ctx_get(void)
 {
     static mbedtls_entropy_context ec = {0};
     static mbedtls_ctr_drbg_context cd_ctx = {0};
@@ -282,7 +282,7 @@ rand_ctx_get()
 
 #ifdef ENABLE_PREDICTION_RESISTANCE
 void
-rand_ctx_enable_prediction_resistance()
+rand_ctx_enable_prediction_resistance(void)
 {
     mbedtls_ctr_drbg_context *cd_ctx = rand_ctx_get();
 
src/openvpn/crypto_mbedtls.h +2 -2
index e457f3a9..18723856 100644
@@ -85,13 +85,13 @@ typedef mbedtls_md_context_t hmac_ctx_t;
  * added. During initialisation, a personalisation string will be added based
  * on the time, the PID, and a pointer to the random context.
  */
-mbedtls_ctr_drbg_context *rand_ctx_get();
+mbedtls_ctr_drbg_context *rand_ctx_get(void);
 
 #ifdef ENABLE_PREDICTION_RESISTANCE
 /**
  * Enable prediction resistance on the random number generator.
  */
-void rand_ctx_enable_prediction_resistance();
+void rand_ctx_enable_prediction_resistance(void);
 
 #endif
 
src/openvpn/crypto_openssl.c +3 -3
index 1bbdfe47..8a043a68 100644
@@ -286,7 +286,7 @@ print_cipher(const EVP_CIPHER *cipher)
 }
 
 void
-show_available_ciphers()
+show_available_ciphers(void)
 {
     int nid;
     size_t i;
@@ -347,7 +347,7 @@ show_available_ciphers()
 }
 
 void
-show_available_digests()
+show_available_digests(void)
 {
     int nid;
 
@@ -372,7 +372,7 @@ show_available_digests()
 }
 
 void
-show_available_engines()
+show_available_engines(void)
 {
 #if HAVE_OPENSSL_ENGINE /* Only defined for OpenSSL */
     ENGINE *e;
src/openvpn/error.c +3 -3
index 3817666b..04bf0da5 100644
@@ -159,7 +159,7 @@ set_machine_readable_output(bool parsable)
 }
 
 void
-error_reset()
+error_reset(void)
 {
     use_syslog = std_redir = false;
     suppress_timestamps = false;
@@ -480,7 +480,7 @@ open_syslog(const char *pgmname, bool stdio_to_null)
 }
 
 void
-close_syslog()
+close_syslog(void)
 {
 #if SYSLOG_CAPABILITY
     if (use_syslog)
@@ -635,7 +635,7 @@ unsigned int x_cs_verbose_level; /* GLOBAL */
 unsigned int x_cs_err_delay_ms;  /* GLOBAL */
 
 void
-reset_check_status()
+reset_check_status(void)
 {
     x_cs_info_level = 0;
     x_cs_verbose_level = 0;
src/openvpn/error.h +1 -1
index 14ef7e65..023cec46 100644
@@ -261,7 +261,7 @@ void msg_forked(void);
 
 void open_syslog(const char *pgmname, bool stdio_to_null);
 
-void close_syslog();
+void close_syslog(void);
 
 /* log file output */
 void redirect_stdout_stderr(const char *file, bool append);
src/openvpn/init.c +1 -1
index bc3b81e3..627da510 100644
@@ -1904,7 +1904,7 @@ do_close_tun(struct context *c, bool force)
 }
 
 void
-tun_abort()
+tun_abort(void)
 {
     struct context *c = static_context;
     if (c)
src/openvpn/interval.h +1 -1
index 8095c0b9..dd5dfbc8 100644
@@ -155,7 +155,7 @@ event_timeout_clear(struct event_timeout *et)
 }
 
 static inline struct event_timeout
-event_timeout_clear_ret()
+event_timeout_clear_ret(void)
 {
     struct event_timeout ret;
     event_timeout_clear(&ret);
src/openvpn/manage.c +1 -1
index ff948240..3bbe972e 100644
@@ -68,7 +68,7 @@ static void man_output_standalone(struct management *man, volatile int *signal_r
 static void man_reset_client_socket(struct management *man, const bool exiting);
 
 static void
-man_help()
+man_help(void)
 {
     msg(M_CLIENT, "Management Interface for %s", title_string);
     msg(M_CLIENT, "Commands:");
src/openvpn/occ-inline.h +1 -1
index 68e9098f..0fa8e5ba 100644
@@ -31,7 +31,7 @@
  */
 
 static inline int
-occ_reset_op()
+occ_reset_op(void)
 {
     return -1;
 }
src/openvpn/packet_id.c +1 -1
index 30ae8fbc..a3ff5722 100644
@@ -643,7 +643,7 @@ packet_id_debug_print(int msglevel,
 #ifdef PID_TEST
 
 void
-packet_id_interactive_test()
+packet_id_interactive_test(void)
 {
     struct packet_id pid;
     struct packet_id_net pin;
src/openvpn/packet_id.h +1 -1
index a370936c..8509e590 100644
@@ -299,7 +299,7 @@ packet_id_persist_save_obj(struct packet_id_persist *p, const struct packet_id *
 const char *packet_id_net_print(const struct packet_id_net *pin, bool print_timestamp, struct gc_arena *gc);
 
 #ifdef PID_TEST
-void packet_id_interactive_test();
+void packet_id_interactive_test(void);
 
 #endif
 
src/openvpn/pkcs11.c +3 -3
index 60418280..a0d0906a 100644
@@ -356,7 +356,7 @@ cleanup:
 }
 
 void
-pkcs11_terminate()
+pkcs11_terminate(void)
 {
     dmsg(
         D_PKCS11_DEBUG,
@@ -422,13 +422,13 @@ pkcs11_addProvider(
 }
 
 int
-pkcs11_logout()
+pkcs11_logout(void)
 {
     return pkcs11h_logout() == CKR_OK;
 }
 
 int
-pkcs11_management_id_count()
+pkcs11_management_id_count(void)
 {
     pkcs11h_certificate_id_list_t id_list = NULL;
     pkcs11h_certificate_id_list_t t = NULL;
src/openvpn/platform.c +1 -1
index d936890e..e942ba94 100644
@@ -173,7 +173,7 @@ platform_nice(int niceval)
 
 /* Get current PID */
 unsigned int
-platform_getpid()
+platform_getpid(void)
 {
 #ifdef _WIN32
     return (unsigned int) GetCurrentProcessId();
src/openvpn/ps.c +1 -1
index c2b05cd9..45e24ded 100644
@@ -172,7 +172,7 @@ send_control(const socket_descriptor_t fd, int code)
 }
 
 static int
-cmsg_size()
+cmsg_size(void)
 {
     return CMSG_SPACE(sizeof(socket_descriptor_t));
 }
src/openvpn/ssl.c +2 -2
index 44a5ee0a..f5c59b77 100644
@@ -347,7 +347,7 @@ tls_init_control_channel_frame_parameters(const struct frame *data_channel_frame
 }
 
 void
-init_ssl_lib()
+init_ssl_lib(void)
 {
     tls_init_lib();
 
@@ -355,7 +355,7 @@ init_ssl_lib()
 }
 
 void
-free_ssl_lib()
+free_ssl_lib(void)
 {
     crypto_uninit_lib();
     prng_uninit();
src/openvpn/ssl_backend.h +3 -3
index 0b822ae3..02f64057 100644
@@ -88,17 +88,17 @@ int pem_password_callback(char *buf, int size, int rwflag, void *u);
  * Perform any static initialisation necessary by the library.
  * Called on OpenVPN initialisation
  */
-void tls_init_lib();
+void tls_init_lib(void);
 
 /**
  * Free any global SSL library-specific data structures.
  */
-void tls_free_lib();
+void tls_free_lib(void);
 
 /**
  * Clear the underlying SSL library's error state.
  */
-void tls_clear_error();
+void tls_clear_error(void);
 
 /**
  * Parse a TLS version specifier
src/openvpn/ssl_mbedtls.c +3 -3
index 86d65e17..dd5b9854 100644
@@ -63,17 +63,17 @@
 #include <mbedtls/sha256.h>
 
 void
-tls_init_lib()
+tls_init_lib(void)
 {
 }
 
 void
-tls_free_lib()
+tls_free_lib(void)
 {
 }
 
 void
-tls_clear_error()
+tls_clear_error(void)
 {
 }
 
src/openvpn/ssl_openssl.c +6 -6
index dbaeb803..7ad6414e 100644
@@ -69,7 +69,7 @@
 int mydata_index; /* GLOBAL */
 
 void
-tls_init_lib()
+tls_init_lib(void)
 {
     SSL_library_init();
 #ifndef ENABLE_SMALL
@@ -82,7 +82,7 @@ tls_init_lib()
 }
 
 void
-tls_free_lib()
+tls_free_lib(void)
 {
     EVP_cleanup();
 #ifndef ENABLE_SMALL
@@ -91,7 +91,7 @@ tls_free_lib()
 }
 
 void
-tls_clear_error()
+tls_clear_error(void)
 {
     ERR_clear_error();
 }
@@ -1320,7 +1320,7 @@ static time_t biofp_last_open;                 /* GLOBAL */
 static const int biofp_reopen_interval = 600;  /* GLOBAL */
 
 static void
-close_biofp()
+close_biofp(void)
 {
     if (biofp)
     {
@@ -1330,7 +1330,7 @@ close_biofp()
 }
 
 static void
-open_biofp()
+open_biofp(void)
 {
     const time_t current = time(NULL);
     const pid_t pid = getpid();
@@ -1748,7 +1748,7 @@ show_available_tls_ciphers(const char *cipher_list)
  * in the OpenSSL library.
  */
 void
-show_available_curves()
+show_available_curves(void)
 {
 #ifndef OPENSSL_NO_EC
     EC_builtin_curve *curves = NULL;
src/openvpn/win32.c +3 -3
index d0b10bad..95fea5df 100644
@@ -1235,7 +1235,7 @@ set_win_sys_path_via_env(struct env_set *es)
 
 
 const char *
-win_get_tempdir()
+win_get_tempdir(void)
 {
     static char tmpdir[MAX_PATH];
     WCHAR wtmpdir[MAX_PATH];
@@ -1398,7 +1398,7 @@ win_wfp_uninit(const NET_IFINDEX index, const HANDLE msg_channel)
 }
 
 int
-win32_version_info()
+win32_version_info(void)
 {
     if (!IsWindowsXPOrGreater())
     {
@@ -1426,7 +1426,7 @@ win32_version_info()
 }
 
 bool
-win32_is_64bit()
+win32_is_64bit(void)
 {
 #if defined(_WIN64)
     return true;  /* 64-bit programs run only on Win64 */
src/openvpn/win32.h +2 -2
index 21a1021a..7fc57ccc 100644
@@ -285,7 +285,7 @@ char *get_win_sys_path(void);
 void fork_to_self(const char *cmdline);
 
 /* Find temporary directory */
-const char *win_get_tempdir();
+const char *win_get_tempdir(void);
 
 /* Convert a string from UTF-8 to UCS-2 */
 WCHAR *wide_string(const char *utf8, struct gc_arena *gc);
@@ -299,7 +299,7 @@ bool win_wfp_uninit(const NET_IFINDEX index, const HANDLE msg_channel);
 #define WIN_7 2
 #define WIN_8 3
 
-int win32_version_info();
+int win32_version_info(void);
 
 /*
  * String representation of Windows version number and name, see
Signature · 1 line
2.14.0
#2 lore raw

Re: [Openvpn-devel] [PATCH 1/5] make function declarations C99 compliant

Quoted 631 lines · Antonio Quartulli

From: Antonio Quartulli <[email protected]...>

In the attempt of adhering to the C99 standard as much as possible, ensure that all the function declarations with no parameter contain the "void" keyword[1].

Defects identified with sparse[2].

[1] ISO/IEC 9899:1999 spec, TC3 - section 6.7.5.3
[1] https://sparse.wiki.kernel.org/index.php/Main_Page

---
 src/openvpn/buffer.c          |  2 +-
 src/openvpn/console.c         |  2 +-
 src/openvpn/console.h         |  8 ++++----
 src/openvpn/console_builtin.c |  2 +-
 src/openvpn/console_systemd.c |  4 ++--
 src/openvpn/crypto.c          |  4 ++--
 src/openvpn/crypto.h          |  2 +-
 src/openvpn/crypto_mbedtls.c  | 10 +++++-----
 src/openvpn/crypto_mbedtls.h  |  4 ++--
 src/openvpn/crypto_openssl.c  |  6 +++---
 src/openvpn/error.c           |  6 +++---
 src/openvpn/error.h           |  2 +-
 src/openvpn/init.c            |  2 +-
 src/openvpn/interval.h        |  2 +-
 src/openvpn/manage.c          |  2 +-
 src/openvpn/occ-inline.h      |  2 +-
 src/openvpn/packet_id.c       |  2 +-
 src/openvpn/packet_id.h       |  2 +-
 src/openvpn/pkcs11.c          |  6 +++---
 src/openvpn/platform.c        |  2 +-
 src/openvpn/ps.c              |  2 +-
 src/openvpn/ssl.c             |  4 ++--
 src/openvpn/ssl_backend.h     |  6 +++---
 src/openvpn/ssl_mbedtls.c     |  6 +++---
 src/openvpn/ssl_openssl.c     | 12 ++++++------
 src/openvpn/win32.c           |  6 +++---
 src/openvpn/win32.h           |  4 ++--
 27 files changed, 56 insertions(+), 56 deletions(-)
src/openvpn/buffer.c +1 -1
index 87e27ec0..a63ce14a 100644
@@ -180,7 +180,7 @@ buf_assign(struct buffer *dest, const struct buffer *src)
 }
 
 struct buffer
-clear_buf()
+clear_buf(void)
 {
     struct buffer buf;
     CLEAR(buf);
src/openvpn/console.c +1 -1
index eb6944d0..7e170241 100644
@@ -44,7 +44,7 @@ struct _query_user query_user[QUERY_USER_NUMSLOTS];  /* GLOBAL */
 
 
 void
-query_user_clear()
+query_user_clear(void)
 {
     int i;
 
src/openvpn/console.h +4 -4
index aa51e6f6..3f74e77e 100644
@@ -46,7 +46,7 @@ extern struct _query_user query_user[];  /**< Global variable, declared in conso
  * Wipes all data put into all of the query_user structs
  *
  */
-void query_user_clear();
+void query_user_clear(void);
 
 
 /**
@@ -72,7 +72,7 @@ void query_user_add(char *prompt, size_t prompt_len,
  *
  * @return True if executing all the defined steps completed successfully
  */
-bool query_user_exec_builtin();
+bool query_user_exec_builtin(void);
 
 
 #if defined(ENABLE_SYSTEMD)
@@ -83,7 +83,7 @@ bool query_user_exec_builtin();
  *
  * @return True if executing all the defined steps completed successfully
  */
-bool query_user_exec();
+bool query_user_exec(void);
 
 #else  /* ENABLE_SYSTEMD not defined*/
 /**
@@ -92,7 +92,7 @@ bool query_user_exec();
  *
  */
 static bool
-query_user_exec()
+query_user_exec(void)
 {
     return query_user_exec_builtin();
 }
src/openvpn/console_builtin.c +1 -1
index 7b95da9d..f005ed74 100644
@@ -267,7 +267,7 @@ get_console_input(const char *prompt, const bool echo, char *input, const int ca
  *
  */
 bool
-query_user_exec_builtin()
+query_user_exec_builtin(void)
 {
     bool ret = true; /* Presume everything goes okay */
     int i;
src/openvpn/console_systemd.c +2 -2
index 8cee8c8e..e7a72ae3 100644
@@ -41,7 +41,7 @@
  */
 
 static bool
-check_systemd_running()
+check_systemd_running(void)
 {
     struct stat c;
 
@@ -95,7 +95,7 @@ get_console_input_systemd(const char *prompt, const bool echo, char *input, cons
  *
  */
 bool
-query_user_exec()
+query_user_exec(void)
 {
     bool ret = true;  /* Presume everything goes okay */
     int i;
src/openvpn/crypto.c +2 -2
index 909e901f..692501d2 100644
@@ -1715,7 +1715,7 @@ static int nonce_secret_len = 0; /* GLOBAL */
 
 /* Reset the nonce value, also done periodically to refresh entropy */
 static void
-prng_reset_nonce()
+prng_reset_nonce(void)
 {
     const int size = md_kt_size(nonce_md) + nonce_secret_len;
 #if 1 /* Must be 1 for real usage */
@@ -1799,7 +1799,7 @@ prng_bytes(uint8_t *output, int len)
 
 /* an analogue to the random() function, but use prng_bytes */
 long int
-get_random()
+get_random(void)
 {
     long int l;
     prng_bytes((unsigned char *)&l, sizeof(l));
src/openvpn/crypto.h +1 -1
index f00a6d8f..f1b6c20a 100644
@@ -465,7 +465,7 @@ void prng_init(const char *md_name, const int nonce_secret_len_parm);
  */
 void prng_bytes(uint8_t *output, int len);
 
-void prng_uninit();
+void prng_uninit(void);
 
 void test_crypto(struct crypto_options *co, struct frame *f);
 
src/openvpn/crypto_mbedtls.c +5 -5
index 7bd69695..a387a7e9 100644
@@ -160,7 +160,7 @@ print_cipher(const cipher_kt_t *info)
 }
 
 void
-show_available_ciphers()
+show_available_ciphers(void)
 {
     const int *ciphers = mbedtls_cipher_list();
 
@@ -197,7 +197,7 @@ show_available_ciphers()
 }
 
 void
-show_available_digests()
+show_available_digests(void)
 {
     const int *digests = mbedtls_md_list();
 
@@ -224,7 +224,7 @@ show_available_digests()
 }
 
 void
-show_available_engines()
+show_available_engines(void)
 {
     printf("mbed TLS hardware crypto engine functionality is not available\n");
 }
@@ -243,7 +243,7 @@ show_available_engines()
  * entropy gathering function.
  */
 mbedtls_ctr_drbg_context *
-rand_ctx_get()
+rand_ctx_get(void)
 {
     static mbedtls_entropy_context ec = {0};
     static mbedtls_ctr_drbg_context cd_ctx = {0};
@@ -282,7 +282,7 @@ rand_ctx_get()
 
 #ifdef ENABLE_PREDICTION_RESISTANCE
 void
-rand_ctx_enable_prediction_resistance()
+rand_ctx_enable_prediction_resistance(void)
 {
     mbedtls_ctr_drbg_context *cd_ctx = rand_ctx_get();
 
src/openvpn/crypto_mbedtls.h +2 -2
index e457f3a9..18723856 100644
@@ -85,13 +85,13 @@ typedef mbedtls_md_context_t hmac_ctx_t;
  * added. During initialisation, a personalisation string will be added based
  * on the time, the PID, and a pointer to the random context.
  */
-mbedtls_ctr_drbg_context *rand_ctx_get();
+mbedtls_ctr_drbg_context *rand_ctx_get(void);
 
 #ifdef ENABLE_PREDICTION_RESISTANCE
 /**
  * Enable prediction resistance on the random number generator.
  */
-void rand_ctx_enable_prediction_resistance();
+void rand_ctx_enable_prediction_resistance(void);
 
 #endif
 
src/openvpn/crypto_openssl.c +3 -3
index 1bbdfe47..8a043a68 100644
@@ -286,7 +286,7 @@ print_cipher(const EVP_CIPHER *cipher)
 }
 
 void
-show_available_ciphers()
+show_available_ciphers(void)
 {
     int nid;
     size_t i;
@@ -347,7 +347,7 @@ show_available_ciphers()
 }
 
 void
-show_available_digests()
+show_available_digests(void)
 {
     int nid;
 
@@ -372,7 +372,7 @@ show_available_digests()
 }
 
 void
-show_available_engines()
+show_available_engines(void)
 {
 #if HAVE_OPENSSL_ENGINE /* Only defined for OpenSSL */
     ENGINE *e;
src/openvpn/error.c +3 -3
index 3817666b..04bf0da5 100644
@@ -159,7 +159,7 @@ set_machine_readable_output(bool parsable)
 }
 
 void
-error_reset()
+error_reset(void)
 {
     use_syslog = std_redir = false;
     suppress_timestamps = false;
@@ -480,7 +480,7 @@ open_syslog(const char *pgmname, bool stdio_to_null)
 }
 
 void
-close_syslog()
+close_syslog(void)
 {
 #if SYSLOG_CAPABILITY
     if (use_syslog)
@@ -635,7 +635,7 @@ unsigned int x_cs_verbose_level; /* GLOBAL */
 unsigned int x_cs_err_delay_ms;  /* GLOBAL */
 
 void
-reset_check_status()
+reset_check_status(void)
 {
     x_cs_info_level = 0;
     x_cs_verbose_level = 0;
src/openvpn/error.h +1 -1
index 14ef7e65..023cec46 100644
@@ -261,7 +261,7 @@ void msg_forked(void);
 
 void open_syslog(const char *pgmname, bool stdio_to_null);
 
-void close_syslog();
+void close_syslog(void);
 
 /* log file output */
 void redirect_stdout_stderr(const char *file, bool append);
src/openvpn/init.c +1 -1
index bc3b81e3..627da510 100644
@@ -1904,7 +1904,7 @@ do_close_tun(struct context *c, bool force)
 }
 
 void
-tun_abort()
+tun_abort(void)
 {
     struct context *c = static_context;
     if (c)
src/openvpn/interval.h +1 -1
index 8095c0b9..dd5dfbc8 100644
@@ -155,7 +155,7 @@ event_timeout_clear(struct event_timeout *et)
 }
 
 static inline struct event_timeout
-event_timeout_clear_ret()
+event_timeout_clear_ret(void)
 {
     struct event_timeout ret;
     event_timeout_clear(&ret);
src/openvpn/manage.c +1 -1
index ff948240..3bbe972e 100644
@@ -68,7 +68,7 @@ static void man_output_standalone(struct management *man, volatile int *signal_r
 static void man_reset_client_socket(struct management *man, const bool exiting);
 
 static void
-man_help()
+man_help(void)
 {
     msg(M_CLIENT, "Management Interface for %s", title_string);
     msg(M_CLIENT, "Commands:");
src/openvpn/occ-inline.h +1 -1
index 68e9098f..0fa8e5ba 100644
@@ -31,7 +31,7 @@
  */
 
 static inline int
-occ_reset_op()
+occ_reset_op(void)
 {
     return -1;
 }
src/openvpn/packet_id.c +1 -1
index 30ae8fbc..a3ff5722 100644
@@ -643,7 +643,7 @@ packet_id_debug_print(int msglevel,
 #ifdef PID_TEST
 
 void
-packet_id_interactive_test()
+packet_id_interactive_test(void)
 {
     struct packet_id pid;
     struct packet_id_net pin;
src/openvpn/packet_id.h +1 -1
index a370936c..8509e590 100644
@@ -299,7 +299,7 @@ packet_id_persist_save_obj(struct packet_id_persist *p, const struct packet_id *
 const char *packet_id_net_print(const struct packet_id_net *pin, bool print_timestamp, struct gc_arena *gc);
 
 #ifdef PID_TEST
-void packet_id_interactive_test();
+void packet_id_interactive_test(void);
 
 #endif
 
src/openvpn/pkcs11.c +3 -3
index 60418280..a0d0906a 100644
@@ -356,7 +356,7 @@ cleanup:
 }
 
 void
-pkcs11_terminate()
+pkcs11_terminate(void)
 {
     dmsg(
         D_PKCS11_DEBUG,
@@ -422,13 +422,13 @@ pkcs11_addProvider(
 }
 
 int
-pkcs11_logout()
+pkcs11_logout(void)
 {
     return pkcs11h_logout() == CKR_OK;
 }
 
 int
-pkcs11_management_id_count()
+pkcs11_management_id_count(void)
 {
     pkcs11h_certificate_id_list_t id_list = NULL;
     pkcs11h_certificate_id_list_t t = NULL;
src/openvpn/platform.c +1 -1
index d936890e..e942ba94 100644
@@ -173,7 +173,7 @@ platform_nice(int niceval)
 
 /* Get current PID */
 unsigned int
-platform_getpid()
+platform_getpid(void)
 {
 #ifdef _WIN32
     return (unsigned int) GetCurrentProcessId();
src/openvpn/ps.c +1 -1
index c2b05cd9..45e24ded 100644
@@ -172,7 +172,7 @@ send_control(const socket_descriptor_t fd, int code)
 }
 
 static int
-cmsg_size()
+cmsg_size(void)
 {
     return CMSG_SPACE(sizeof(socket_descriptor_t));
 }
src/openvpn/ssl.c +2 -2
index 44a5ee0a..f5c59b77 100644
@@ -347,7 +347,7 @@ tls_init_control_channel_frame_parameters(const struct frame *data_channel_frame
 }
 
 void
-init_ssl_lib()
+init_ssl_lib(void)
 {
     tls_init_lib();
 
@@ -355,7 +355,7 @@ init_ssl_lib()
 }
 
 void
-free_ssl_lib()
+free_ssl_lib(void)
 {
     crypto_uninit_lib();
     prng_uninit();
src/openvpn/ssl_backend.h +3 -3
index 0b822ae3..02f64057 100644
@@ -88,17 +88,17 @@ int pem_password_callback(char *buf, int size, int rwflag, void *u);
  * Perform any static initialisation necessary by the library.
  * Called on OpenVPN initialisation
  */
-void tls_init_lib();
+void tls_init_lib(void);
 
 /**
  * Free any global SSL library-specific data structures.
  */
-void tls_free_lib();
+void tls_free_lib(void);
 
 /**
  * Clear the underlying SSL library's error state.
  */
-void tls_clear_error();
+void tls_clear_error(void);
 
 /**
  * Parse a TLS version specifier
src/openvpn/ssl_mbedtls.c +3 -3
index 86d65e17..dd5b9854 100644
@@ -63,17 +63,17 @@
 #include <mbedtls/sha256.h>
 
 void
-tls_init_lib()
+tls_init_lib(void)
 {
 }
 
 void
-tls_free_lib()
+tls_free_lib(void)
 {
 }
 
 void
-tls_clear_error()
+tls_clear_error(void)
 {
 }
 
src/openvpn/ssl_openssl.c +6 -6
index dbaeb803..7ad6414e 100644
@@ -69,7 +69,7 @@
 int mydata_index; /* GLOBAL */
 
 void
-tls_init_lib()
+tls_init_lib(void)
 {
     SSL_library_init();
 #ifndef ENABLE_SMALL
@@ -82,7 +82,7 @@ tls_init_lib()
 }
 
 void
-tls_free_lib()
+tls_free_lib(void)
 {
     EVP_cleanup();
 #ifndef ENABLE_SMALL
@@ -91,7 +91,7 @@ tls_free_lib()
 }
 
 void
-tls_clear_error()
+tls_clear_error(void)
 {
     ERR_clear_error();
 }
@@ -1320,7 +1320,7 @@ static time_t biofp_last_open;                 /* GLOBAL */
 static const int biofp_reopen_interval = 600;  /* GLOBAL */
 
 static void
-close_biofp()
+close_biofp(void)
 {
     if (biofp)
     {
@@ -1330,7 +1330,7 @@ close_biofp()
 }
 
 static void
-open_biofp()
+open_biofp(void)
 {
     const time_t current = time(NULL);
     const pid_t pid = getpid();
@@ -1748,7 +1748,7 @@ show_available_tls_ciphers(const char *cipher_list)
  * in the OpenSSL library.
  */
 void
-show_available_curves()
+show_available_curves(void)
 {
 #ifndef OPENSSL_NO_EC
     EC_builtin_curve *curves = NULL;
src/openvpn/win32.c +3 -3
index d0b10bad..95fea5df 100644
@@ -1235,7 +1235,7 @@ set_win_sys_path_via_env(struct env_set *es)
 
 
 const char *
-win_get_tempdir()
+win_get_tempdir(void)
 {
     static char tmpdir[MAX_PATH];
     WCHAR wtmpdir[MAX_PATH];
@@ -1398,7 +1398,7 @@ win_wfp_uninit(const NET_IFINDEX index, const HANDLE msg_channel)
 }
 
 int
-win32_version_info()
+win32_version_info(void)
 {
     if (!IsWindowsXPOrGreater())
     {
@@ -1426,7 +1426,7 @@ win32_version_info()
 }
 
 bool
-win32_is_64bit()
+win32_is_64bit(void)
 {
 #if defined(_WIN64)
     return true;  /* 64-bit programs run only on Win64 */
src/openvpn/win32.h +1 -1
index 21a1021a..7fc57ccc 100644
@@ -285,7 +285,7 @@ char *get_win_sys_path(void);
 void fork_to_self(const char *cmdline);
 
 /* Find temporary directory */
-const char *win_get_tempdir();
+const char *win_get_tempdir(void);
 
 /* Convert a string from UTF-8 to UCS-2 */
 WCHAR *wide_string(const char *utf8, struct gc_arena *gc);

src/openvpn/win32.h bool win_wfp_uninit(const NET_IFINDEX index, const HANDLE msg_channel); · line 305

Quoted 8 lines
src/openvpn/win32.h +1 -1
@@ -299,7 +299,7 @@ bool win_wfp_uninit(const NET_IFINDEX index, const HANDLE msg_channel);
 #define WIN_7 2
 #define WIN_8 3
 
-int win32_version_info();
+int win32_version_info(void);
 
 /*
  * String representation of Windows version number and name, see

ACK

-Steffan

#3 lore raw

Re: [Openvpn-devel] [PATCH applied] make function declarations C99 compliant

In reply to Antonio Quartulli

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Your patch has been applied to the following branches

commit e2a0cad46e8f98399387c334fec912b7bb7097fc (master) commit b5d7474822c89ff18d1005d4e90064051f160ce4 (release/2.4)

Author: Antonio Quartulli
Date:   Fri Aug 11 17:07:40 2017 +0800
     make function declarations C99 compliant

     Signed-off-by: Antonio Quartulli <[email protected]...>
     Acked-by: Steffan Karger <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg15203.html
     Signed-off-by: David Sommerseth <[email protected]...>

- --
kind regards,

David Sommerseth

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)

iQIcBAEBCgAGBQJZjg/eAAoJEIbPlEyWcf3yRnwP/10HUlYwyVR5cLSwVj474ypR 8IdOabXBDkXnI13n7GVfaT4VpANljlhrtLHJqOi8J9DesV8DJri/BF7Jq34bpUNS 5N3oXn7dj7rzZEUnGLIjWsgJTvYaI2thrrUMMZ/YvDhn6pIWNUhdcesFJQz3a0Eo MDwD0KGcT+EpYX/m6adGmyCo9nwE9INFFEnjNBC8o3bvg8fLpBO5MDDDYnDvoX8Q 5AipW+9eebiHs0U05rHUgFA9clajp9wqajvykLI6bqT9HzgGNBLo2uT+UOFsnaX0 /3lx0JcEdoaWjhxM5CoonZ0j7fgauXQR3RcWDiQfd39HTT3S/fo0QxKm8yh7nN/V 5bemVVKibHwcGf6krVCa4GUK5EyJFMngjogOOaddhsrN2xkOCNt44zuIHUIXcQAa TkzqEqSbOi4FuU4OqzSyelxC65yVRC/FROo/Fg0K41fM6TqoSfXwSG5goqb1GPtT GTMLHQpSq+Oayfam9ytjtqx8tnMII65JzkxRFmg0oHIdkbQoXELAf9OVTV1h+jkk Pdlz3+DYrXzHetzGKlueRfTMRnr2cTmWH1oNOP3bxe/PkQdAy1FYVWfj+TrVkloL /fV6KhhVRVnquMUtF4m+9yxStvM/8rtnj2AWid6Dco72WSNGcMJOkTh5ymeQ9st7 nmNYwsP4Nz5r5BtfyXX1
=VsJ4
-----END PGP SIGNATURE-----

#4 lore raw

PATCH 2/5 ensure function declarations are compiled with their definitions

In reply to Antonio Quartulli

From: Antonio Quartulli <[email protected]...>

Function prototypes should be included when compiling their definitions so that it is clear to compilers and static analyzers that they are not static.

This means that several declarations have to be moved to the related header files which in turn have to be included by the source files implementing them.

Generally speaking this also improves the coding style and makes this code more consistent with the rest that already follows this rule.

---
 src/openvpn/crypto.h         |  3 +++
 src/openvpn/error.c          |  3 +--
 src/openvpn/forward-inline.h | 28 ++--------------------------
 src/openvpn/forward.h        | 35 +++++++++++++++++++++++++++++++++++
 src/openvpn/init.h           |  2 ++
 src/openvpn/lladdr.c         |  1 +
 src/openvpn/manage.h         | 11 ++++++-----
 src/openvpn/mbuf.h           |  4 ++--
 src/openvpn/mroute.h         | 21 +++++++++++----------
 src/openvpn/multi.h          |  7 +++----
 src/openvpn/occ-inline.h     |  8 ++------
 src/openvpn/occ.h            |  6 ++++++
 src/openvpn/pf-inline.h      |  6 ++----
 src/openvpn/pf.h             |  6 ++++++
 src/openvpn/ping-inline.h    |  6 ++----
 src/openvpn/ping.h           |  4 ++++
 src/openvpn/plugin.h         |  2 ++
 src/openvpn/socket.h         | 13 +++++++------
 18 files changed, 97 insertions(+), 69 deletions(-)
src/openvpn/crypto.h +3 -0
index f1b6c20a..5f0790a6 100644
@@ -467,6 +467,9 @@ void prng_bytes(uint8_t *output, int len);
 
 void prng_uninit(void);
 
+/* an analogue to the random() function, but use prng_bytes */
+long int get_random(void);
+
 void test_crypto(struct crypto_options *co, struct frame *f);
 
 
src/openvpn/error.c +1 -2
index 04bf0da5..e885ec3b 100644
@@ -31,6 +31,7 @@
 
 #include "error.h"
 #include "buffer.h"
+#include "init.h"
 #include "misc.h"
 #include "win32.h"
 #include "socket.h"
@@ -734,8 +735,6 @@ openvpn_exit(const int status)
 {
     if (!forked)
     {
-        void tun_abort();
-
 #ifdef ENABLE_PLUGIN
         void plugin_abort(void);
 
src/openvpn/forward-inline.h +2 -26
index ab83ea40..04601e8c 100644
@@ -24,6 +24,8 @@
 #ifndef FORWARD_INLINE_H
 #define FORWARD_INLINE_H
 
+#include "forward.h"
+
 /*
  * Inline functions
  */
@@ -35,8 +37,6 @@ static inline void
 check_tls(struct context *c)
 {
 #if defined(ENABLE_CRYPTO)
-    void check_tls_dowork(struct context *c);
-
     if (c->c2.tls_multi)
     {
         check_tls_dowork(c);
@@ -52,10 +52,6 @@ static inline void
 check_tls_errors(struct context *c)
 {
 #if defined(ENABLE_CRYPTO)
-    void check_tls_errors_co(struct context *c);
-
-    void check_tls_errors_nco(struct context *c);
-
     if (c->c2.tls_multi && c->c2.tls_exit_signal)
     {
         if (link_socket_connection_oriented(c->c2.link_socket))
@@ -84,8 +80,6 @@ static inline void
 check_incoming_control_channel(struct context *c)
 {
 #if P2MP
-    void check_incoming_control_channel_dowork(struct context *c);
-
     if (tls_test_payload_len(c->c2.tls_multi) > 0)
     {
         check_incoming_control_channel_dowork(c);
@@ -100,8 +94,6 @@ check_incoming_control_channel(struct context *c)
 static inline void
 check_connection_established(struct context *c)
 {
-    void check_connection_established_dowork(struct context *c);
-
     if (event_timeout_defined(&c->c2.wait_for_connect))
     {
         check_connection_established_dowork(c);
@@ -114,8 +106,6 @@ check_connection_established(struct context *c)
 static inline void
 check_add_routes(struct context *c)
 {
-    void check_add_routes_dowork(struct context *c);
-
     if (event_timeout_trigger(&c->c2.route_wakeup, &c->c2.timeval, ETT_DEFAULT))
     {
         check_add_routes_dowork(c);
@@ -128,8 +118,6 @@ check_add_routes(struct context *c)
 static inline void
 check_inactivity_timeout(struct context *c)
 {
-    void check_inactivity_timeout_dowork(struct context *c);
-
     if (c->options.inactivity_timeout
         && event_timeout_trigger(&c->c2.inactivity_interval, &c->c2.timeval, ETT_DEFAULT))
     {
@@ -142,8 +130,6 @@ check_inactivity_timeout(struct context *c)
 static inline void
 check_server_poll_timeout(struct context *c)
 {
-    void check_server_poll_timeout_dowork(struct context *c);
-
     if (c->options.ce.connect_timeout
         && event_timeout_trigger(&c->c2.server_poll_interval, &c->c2.timeval, ETT_DEFAULT))
     {
@@ -157,8 +143,6 @@ check_server_poll_timeout(struct context *c)
 static inline void
 check_scheduled_exit(struct context *c)
 {
-    void check_scheduled_exit_dowork(struct context *c);
-
     if (event_timeout_defined(&c->c2.scheduled_exit))
     {
         if (event_timeout_trigger(&c->c2.scheduled_exit, &c->c2.timeval, ETT_DEFAULT))
@@ -175,8 +159,6 @@ check_scheduled_exit(struct context *c)
 static inline void
 check_status_file(struct context *c)
 {
-    void check_status_file_dowork(struct context *c);
-
     if (c->c1.status_output)
     {
         if (status_trigger_tv(c->c1.status_output, &c->c2.timeval))
@@ -193,8 +175,6 @@ check_status_file(struct context *c)
 static inline void
 check_fragment(struct context *c)
 {
-    void check_fragment_dowork(struct context *c);
-
     if (c->c2.fragment)
     {
         check_fragment_dowork(c);
@@ -210,8 +190,6 @@ check_fragment(struct context *c)
 static inline void
 check_push_request(struct context *c)
 {
-    void check_push_request_dowork(struct context *c);
-
     if (event_timeout_trigger(&c->c2.push_request_interval, &c->c2.timeval, ETT_DEFAULT))
     {
         check_push_request_dowork(c);
@@ -313,8 +291,6 @@ p2p_iow_flags(const struct context *c)
 static inline void
 io_wait(struct context *c, const unsigned int flags)
 {
-    void io_wait_dowork(struct context *c, const unsigned int flags);
-
     if (c->c2.fast_io && (flags & (IOW_TO_TUN|IOW_TO_LINK|IOW_MBUF)))
     {
         /* fast path -- only for TUN/TAP/UDP writes */
src/openvpn/forward.h +35 -0
index 9fde5a30..bc016e5d 100644
@@ -60,6 +60,41 @@
 
 #define IOW_READ            (IOW_READ_TUN|IOW_READ_LINK)
 
+extern counter_type link_read_bytes_global;
+
+extern counter_type link_write_bytes_global;
+
+#ifdef ENABLE_CRYPTO
+void check_tls_dowork(struct context *c);
+
+void check_tls_errors_co(struct context *c);
+
+void check_tls_errors_nco(struct context *c);
+#endif /* ENABLE_CRYPTO */
+
+#if P2MP
+void check_incoming_control_channel_dowork(struct context *c);
+
+void check_scheduled_exit_dowork(struct context *c);
+
+void check_push_request_dowork(struct context *c);
+#endif /* P2MP */
+
+#ifdef ENABLE_FRAGMENT
+void check_fragment_dowork(struct context *c);
+#endif /* ENABLE_FRAGMENT */
+
+void check_connection_established_dowork(struct context *c);
+
+void check_add_routes_dowork(struct context *c);
+
+void check_inactivity_timeout_dowork(struct context *c);
+
+void check_server_poll_timeout_dowork(struct context *c);
+
+void check_status_file_dowork(struct context *c);
+
+void io_wait_dowork(struct context *c, const unsigned int flags);
 
 void pre_select(struct context *c);
 
src/openvpn/init.h +2 -0
index 15feb677..b681cd9d 100644
@@ -140,4 +140,6 @@ void open_plugins(struct context *c, const bool import_options, int init_point);
 
 #endif
 
+void tun_abort(void);
+
 #endif /* ifndef INIT_H */
src/openvpn/lladdr.c +1 -0
index ff71e48c..ea35e4d9 100644
@@ -11,6 +11,7 @@
 #include "syshead.h"
 #include "error.h"
 #include "misc.h"
+#include "lladdr.h"
 
 int
 set_lladdr(const char *ifname, const char *lladdr,
src/openvpn/manage.h +6 -5
index 676be640..d77e5f18 100644
@@ -581,6 +581,12 @@ management_bytes_in(struct management *man, const int size)
     }
 }
 
+
+void man_bytecount_output_server(struct management *man,
+                                 const counter_type *bytes_in_total,
+                                 const counter_type *bytes_out_total,
+                                 struct man_def_auth_context *mdac);
+
 #ifdef MANAGEMENT_DEF_AUTH
 
 static inline void
@@ -589,11 +595,6 @@ management_bytes_server(struct management *man,
                         const counter_type *bytes_out_total,
                         struct man_def_auth_context *mdac)
 {
-    void man_bytecount_output_server(struct management *man,
-                                     const counter_type *bytes_in_total,
-                                     const counter_type *bytes_out_total,
-                                     struct man_def_auth_context *mdac);
-
     if (man->connection.bytecount_update_seconds > 0
         && now >= mdac->bytecount_last_update + man->connection.bytecount_update_seconds
         && (mdac->flags & (DAF_CONNECTION_ESTABLISHED|DAF_CONNECTION_CLOSED)) == DAF_CONNECTION_ESTABLISHED)
src/openvpn/mbuf.h +2 -2
index e0643de1..1c35432f 100644
@@ -96,11 +96,11 @@ mbuf_maximum_queued(const struct mbuf_set *ms)
     return (int) ms->max_queued;
 }
 
+struct multi_instance *mbuf_peek_dowork(struct mbuf_set *ms);
+
 static inline struct multi_instance *
 mbuf_peek(struct mbuf_set *ms)
 {
-    struct multi_instance *mbuf_peek_dowork(struct mbuf_set *ms);
-
     if (mbuf_defined(ms))
     {
         return mbuf_peek_dowork(ms);
src/openvpn/mroute.h +11 -10
index cf3be509..19d2899d 100644
@@ -170,6 +170,17 @@ void mroute_helper_add_iroute46(struct mroute_helper *mh, int netbits);
 
 void mroute_helper_del_iroute46(struct mroute_helper *mh, int netbits);
 
+
+unsigned int mroute_extract_addr_ipv4(struct mroute_addr *src,
+                                      struct mroute_addr *dest,
+                                      const struct buffer *buf);
+
+unsigned int mroute_extract_addr_ether(struct mroute_addr *src,
+                                       struct mroute_addr *dest,
+                                       struct mroute_addr *esrc,
+                                       struct mroute_addr *edest,
+                                       const struct buffer *buf);
+
 /*
  * Given a raw packet in buf, return the src and dest
  * addresses of the packet.
@@ -182,16 +193,6 @@ mroute_extract_addr_from_packet(struct mroute_addr *src,
                                 const struct buffer *buf,
                                 int tunnel_type)
 {
-    unsigned int mroute_extract_addr_ipv4(struct mroute_addr *src,
-                                          struct mroute_addr *dest,
-                                          const struct buffer *buf);
-
-    unsigned int mroute_extract_addr_ether(struct mroute_addr *src,
-                                           struct mroute_addr *dest,
-                                           struct mroute_addr *esrc,
-                                           struct mroute_addr *edest,
-                                           const struct buffer *buf);
-
     unsigned int ret = 0;
     verify_align_4(buf);
     if (tunnel_type == DEV_TYPE_TUN)
src/openvpn/multi.h +3 -4
index 63afbaf0..5892ac07 100644
@@ -536,11 +536,12 @@ clear_prefix(void)
  */
 #define MULTI_CACHE_ROUTE_TTL 60
 
+void multi_reap_process_dowork(const struct multi_context *m);
+void multi_process_per_second_timers_dowork(struct multi_context *m);
+
 static inline void
 multi_reap_process(const struct multi_context *m)
 {
-    void multi_reap_process_dowork(const struct multi_context *m);
-
     if (m->reaper->last_call != now)
     {
         multi_reap_process_dowork(m);
@@ -552,8 +553,6 @@ multi_process_per_second_timers(struct multi_context *m)
 {
     if (m->per_second_trigger != now)
     {
-        void multi_process_per_second_timers_dowork(struct multi_context *m);
-
         multi_process_per_second_timers_dowork(m);
         m->per_second_trigger = now;
     }
src/openvpn/occ-inline.h +2 -6
index 0fa8e5ba..7ca2a26f 100644
@@ -26,6 +26,8 @@
 
 #ifdef ENABLE_OCC
 
+#include "occ.h"
+
 /*
  * Inline functions
  */
@@ -42,8 +44,6 @@ occ_reset_op(void)
 static inline void
 check_send_occ_req(struct context *c)
 {
-    void check_send_occ_req_dowork(struct context *c);
-
     if (event_timeout_defined(&c->c2.occ_interval)
         && event_timeout_trigger(&c->c2.occ_interval,
                                  &c->c2.timeval,
@@ -59,8 +59,6 @@ check_send_occ_req(struct context *c)
 static inline void
 check_send_occ_load_test(struct context *c)
 {
-    void check_send_occ_load_test_dowork(struct context *c);
-
     if (event_timeout_defined(&c->c2.occ_mtu_load_test_interval)
         && event_timeout_trigger(&c->c2.occ_mtu_load_test_interval,
                                  &c->c2.timeval,
@@ -76,8 +74,6 @@ check_send_occ_load_test(struct context *c)
 static inline void
 check_send_occ_msg(struct context *c)
 {
-    void check_send_occ_msg_dowork(struct context *c);
-
     if (c->c2.occ_op >= 0)
     {
         if (!TO_LINK_DEF(c))
src/openvpn/occ.h +6 -0
index 12d7bc57..29de99c2 100644
@@ -90,5 +90,11 @@ is_occ_msg(const struct buffer *buf)
 
 void process_received_occ_msg(struct context *c);
 
+void check_send_occ_req_dowork(struct context *c);
+
+void check_send_occ_load_test_dowork(struct context *c);
+
+void check_send_occ_msg_dowork(struct context *c);
+
 #endif /* ifdef ENABLE_OCC */
 #endif /* ifndef OCC_H */
src/openvpn/pf-inline.h +2 -4
index ac19ac4c..0db7b262 100644
@@ -24,6 +24,8 @@
 #if defined(ENABLE_PF) && !defined(PF_INLINE_H)
 #define PF_INLINE_H
 
+#include "pf.h"
+
 /*
  * Inline functions
  */
@@ -33,8 +35,6 @@
 static inline bool
 pf_c2c_test(const struct context *src, const struct context *dest, const char *prefix)
 {
-    bool pf_cn_test(struct pf_set *pfs, const struct tls_multi *tm, const int type, const char *prefix);
-
     return (!src->c2.pf.enabled  || pf_cn_test(src->c2.pf.pfs,  dest->c2.tls_multi, PCT_DEST, prefix))
            && (!dest->c2.pf.enabled || pf_cn_test(dest->c2.pf.pfs, src->c2.tls_multi,  PCT_SRC,  prefix));
 }
@@ -42,8 +42,6 @@ pf_c2c_test(const struct context *src, const struct context *dest, const char *p
 static inline bool
 pf_addr_test(const struct context *src, const struct mroute_addr *dest, const char *prefix)
 {
-    bool pf_addr_test_dowork(const struct context *src, const struct mroute_addr *dest, const char *prefix);
-
     if (src->c2.pf.enabled)
     {
         return pf_addr_test_dowork(src, dest, prefix);
src/openvpn/pf.h +6 -0
index 414c85b8..f6a3b61e 100644
@@ -101,4 +101,10 @@ void pf_context_print(const struct pf_context *pfc, const char *prefix, const in
 
 #endif
 
+bool pf_cn_test(struct pf_set *pfs, const struct tls_multi *tm, const int type,
+                const char *prefix);
+
+bool pf_addr_test_dowork(const struct context *src,
+                         const struct mroute_addr *dest, const char *prefix);
+
 #endif /* if defined(ENABLE_PF) && !defined(OPENVPN_PF_H) */
src/openvpn/ping-inline.h +2 -4
index 0642b851..9d590dc4 100644
@@ -24,6 +24,8 @@
 #ifndef PING_INLINE_H
 #define PING_INLINE_H
 
+#include "ping.h"
+
 /*
  * Should we exit or restart due to ping (or other authenticated packet)
  * not received in n seconds?
@@ -31,8 +33,6 @@
 static inline void
 check_ping_restart(struct context *c)
 {
-    void check_ping_restart_dowork(struct context *c);
-
     if (c->options.ping_rec_timeout
         && event_timeout_trigger(&c->c2.ping_rec_interval,
                                  &c->c2.timeval,
@@ -50,8 +50,6 @@ check_ping_restart(struct context *c)
 static inline void
 check_ping_send(struct context *c)
 {
-    void check_ping_send_dowork(struct context *c);
-
     if (c->options.ping_send_timeout
         && event_timeout_trigger(&c->c2.ping_send_interval,
                                  &c->c2.timeval,
src/openvpn/ping.h +4 -0
index 5bd5c089..66c3a54f 100644
@@ -43,4 +43,8 @@ is_ping_msg(const struct buffer *buf)
     return buf_string_match(buf, ping_string, PING_STRING_SIZE);
 }
 
+void check_ping_restart_dowork(struct context *c);
+
+void check_ping_send_dowork(struct context *c);
+
 #endif
src/openvpn/plugin.h +2 -0
index 818b6285..67549cda 100644
@@ -216,4 +216,6 @@ plugin_call(const struct plugin_list *pl,
                            );
 }
 
+void plugin_abort(void);
+
 #endif /* OPENVPN_PLUGIN_H */
src/openvpn/socket.h +7 -6
index 81e9e9ae..13b94606 100644
@@ -1021,11 +1021,11 @@ void stream_buf_close(struct stream_buf *sb);
 
 bool stream_buf_added(struct stream_buf *sb, int length_added);
 
+bool stream_buf_read_setup_dowork(struct link_socket *sock);
+
 static inline bool
 stream_buf_read_setup(struct link_socket *sock)
 {
-    bool stream_buf_read_setup_dowork(struct link_socket *sock);
-
     if (link_socket_connection_oriented(sock))
     {
         return stream_buf_read_setup_dowork(sock);
@@ -1130,16 +1130,17 @@ link_socket_write_win32(struct link_socket *sock,
 
 #else  /* ifdef _WIN32 */
 
+size_t link_socket_write_udp_posix_sendmsg(struct link_socket *sock,
+                                           struct buffer *buf,
+                                           struct link_socket_actual *to);
+
+
 static inline size_t
 link_socket_write_udp_posix(struct link_socket *sock,
                             struct buffer *buf,
                             struct link_socket_actual *to)
 {
 #if ENABLE_IP_PKTINFO
-    size_t link_socket_write_udp_posix_sendmsg(struct link_socket *sock,
-                                               struct buffer *buf,
-                                               struct link_socket_actual *to);
-
     if (proto_is_udp(sock->info.proto) && (sock->sockflags & SF_USE_IP_PKTINFO)
         && addr_defined_ipi(to))
     {
Signature · 1 line
2.14.0
#5 lore raw

PATCH v2 1/1 ensure function declarations are compiled with their definitions

From: Antonio Quartulli <[email protected]...>

Function prototypes should be included when compiling their definitions so that it is clear to compilers and static analyzers that they are not static.

This means that several declarations have to be moved to the related header files which in turn have to be included by the source files implementing them.

Generally speaking this also improves the coding style and makes this code more consistent with the rest that already follows this rule.

---

v2: rebased on top of latest master to avoid conflict

 src/openvpn/crypto.h         |  3 +++
 src/openvpn/error.c          |  3 +--
 src/openvpn/forward-inline.h | 28 ++--------------------------
 src/openvpn/forward.h        | 35 +++++++++++++++++++++++++++++++++++
 src/openvpn/init.h           |  2 ++
 src/openvpn/lladdr.c         |  1 +
 src/openvpn/manage.h         | 11 ++++++-----
 src/openvpn/mbuf.h           |  4 ++--
 src/openvpn/mroute.h         | 21 +++++++++++----------
 src/openvpn/multi.h          |  7 +++----
 src/openvpn/occ-inline.h     |  8 ++------
 src/openvpn/occ.h            |  6 ++++++
 src/openvpn/pf-inline.h      |  6 ++----
 src/openvpn/pf.h             |  6 ++++++
 src/openvpn/ping-inline.h    |  6 ++----
 src/openvpn/ping.h           |  4 ++++
 src/openvpn/plugin.h         |  2 ++
 src/openvpn/socket.h         | 13 +++++++------
 18 files changed, 97 insertions(+), 69 deletions(-)
src/openvpn/crypto.h +3 -0
index f1b6c20a..5f0790a6 100644
@@ -467,6 +467,9 @@ void prng_bytes(uint8_t *output, int len);
 
 void prng_uninit(void);
 
+/* an analogue to the random() function, but use prng_bytes */
+long int get_random(void);
+
 void test_crypto(struct crypto_options *co, struct frame *f);
 
 
src/openvpn/error.c +1 -2
index 04bf0da5..e885ec3b 100644
@@ -31,6 +31,7 @@
 
 #include "error.h"
 #include "buffer.h"
+#include "init.h"
 #include "misc.h"
 #include "win32.h"
 #include "socket.h"
@@ -734,8 +735,6 @@ openvpn_exit(const int status)
 {
     if (!forked)
     {
-        void tun_abort();
-
 #ifdef ENABLE_PLUGIN
         void plugin_abort(void);
 
src/openvpn/forward-inline.h +2 -26
index ab83ea40..04601e8c 100644
@@ -24,6 +24,8 @@
 #ifndef FORWARD_INLINE_H
 #define FORWARD_INLINE_H
 
+#include "forward.h"
+
 /*
  * Inline functions
  */
@@ -35,8 +37,6 @@ static inline void
 check_tls(struct context *c)
 {
 #if defined(ENABLE_CRYPTO)
-    void check_tls_dowork(struct context *c);
-
     if (c->c2.tls_multi)
     {
         check_tls_dowork(c);
@@ -52,10 +52,6 @@ static inline void
 check_tls_errors(struct context *c)
 {
 #if defined(ENABLE_CRYPTO)
-    void check_tls_errors_co(struct context *c);
-
-    void check_tls_errors_nco(struct context *c);
-
     if (c->c2.tls_multi && c->c2.tls_exit_signal)
     {
         if (link_socket_connection_oriented(c->c2.link_socket))
@@ -84,8 +80,6 @@ static inline void
 check_incoming_control_channel(struct context *c)
 {
 #if P2MP
-    void check_incoming_control_channel_dowork(struct context *c);
-
     if (tls_test_payload_len(c->c2.tls_multi) > 0)
     {
         check_incoming_control_channel_dowork(c);
@@ -100,8 +94,6 @@ check_incoming_control_channel(struct context *c)
 static inline void
 check_connection_established(struct context *c)
 {
-    void check_connection_established_dowork(struct context *c);
-
     if (event_timeout_defined(&c->c2.wait_for_connect))
     {
         check_connection_established_dowork(c);
@@ -114,8 +106,6 @@ check_connection_established(struct context *c)
 static inline void
 check_add_routes(struct context *c)
 {
-    void check_add_routes_dowork(struct context *c);
-
     if (event_timeout_trigger(&c->c2.route_wakeup, &c->c2.timeval, ETT_DEFAULT))
     {
         check_add_routes_dowork(c);
@@ -128,8 +118,6 @@ check_add_routes(struct context *c)
 static inline void
 check_inactivity_timeout(struct context *c)
 {
-    void check_inactivity_timeout_dowork(struct context *c);
-
     if (c->options.inactivity_timeout
         && event_timeout_trigger(&c->c2.inactivity_interval, &c->c2.timeval, ETT_DEFAULT))
     {
@@ -142,8 +130,6 @@ check_inactivity_timeout(struct context *c)
 static inline void
 check_server_poll_timeout(struct context *c)
 {
-    void check_server_poll_timeout_dowork(struct context *c);
-
     if (c->options.ce.connect_timeout
         && event_timeout_trigger(&c->c2.server_poll_interval, &c->c2.timeval, ETT_DEFAULT))
     {
@@ -157,8 +143,6 @@ check_server_poll_timeout(struct context *c)
 static inline void
 check_scheduled_exit(struct context *c)
 {
-    void check_scheduled_exit_dowork(struct context *c);
-
     if (event_timeout_defined(&c->c2.scheduled_exit))
     {
         if (event_timeout_trigger(&c->c2.scheduled_exit, &c->c2.timeval, ETT_DEFAULT))
@@ -175,8 +159,6 @@ check_scheduled_exit(struct context *c)
 static inline void
 check_status_file(struct context *c)
 {
-    void check_status_file_dowork(struct context *c);
-
     if (c->c1.status_output)
     {
         if (status_trigger_tv(c->c1.status_output, &c->c2.timeval))
@@ -193,8 +175,6 @@ check_status_file(struct context *c)
 static inline void
 check_fragment(struct context *c)
 {
-    void check_fragment_dowork(struct context *c);
-
     if (c->c2.fragment)
     {
         check_fragment_dowork(c);
@@ -210,8 +190,6 @@ check_fragment(struct context *c)
 static inline void
 check_push_request(struct context *c)
 {
-    void check_push_request_dowork(struct context *c);
-
     if (event_timeout_trigger(&c->c2.push_request_interval, &c->c2.timeval, ETT_DEFAULT))
     {
         check_push_request_dowork(c);
@@ -313,8 +291,6 @@ p2p_iow_flags(const struct context *c)
 static inline void
 io_wait(struct context *c, const unsigned int flags)
 {
-    void io_wait_dowork(struct context *c, const unsigned int flags);
-
     if (c->c2.fast_io && (flags & (IOW_TO_TUN|IOW_TO_LINK|IOW_MBUF)))
     {
         /* fast path -- only for TUN/TAP/UDP writes */
src/openvpn/forward.h +35 -0
index 9fde5a30..bc016e5d 100644
@@ -60,6 +60,41 @@
 
 #define IOW_READ            (IOW_READ_TUN|IOW_READ_LINK)
 
+extern counter_type link_read_bytes_global;
+
+extern counter_type link_write_bytes_global;
+
+#ifdef ENABLE_CRYPTO
+void check_tls_dowork(struct context *c);
+
+void check_tls_errors_co(struct context *c);
+
+void check_tls_errors_nco(struct context *c);
+#endif /* ENABLE_CRYPTO */
+
+#if P2MP
+void check_incoming_control_channel_dowork(struct context *c);
+
+void check_scheduled_exit_dowork(struct context *c);
+
+void check_push_request_dowork(struct context *c);
+#endif /* P2MP */
+
+#ifdef ENABLE_FRAGMENT
+void check_fragment_dowork(struct context *c);
+#endif /* ENABLE_FRAGMENT */
+
+void check_connection_established_dowork(struct context *c);
+
+void check_add_routes_dowork(struct context *c);
+
+void check_inactivity_timeout_dowork(struct context *c);
+
+void check_server_poll_timeout_dowork(struct context *c);
+
+void check_status_file_dowork(struct context *c);
+
+void io_wait_dowork(struct context *c, const unsigned int flags);
 
 void pre_select(struct context *c);
 
src/openvpn/init.h +2 -0
index 15feb677..b681cd9d 100644
@@ -140,4 +140,6 @@ void open_plugins(struct context *c, const bool import_options, int init_point);
 
 #endif
 
+void tun_abort(void);
+
 #endif /* ifndef INIT_H */
src/openvpn/lladdr.c +1 -0
index ff71e48c..ea35e4d9 100644
@@ -11,6 +11,7 @@
 #include "syshead.h"
 #include "error.h"
 #include "misc.h"
+#include "lladdr.h"
 
 int
 set_lladdr(const char *ifname, const char *lladdr,
src/openvpn/manage.h +6 -5
index 676be640..d77e5f18 100644
@@ -581,6 +581,12 @@ management_bytes_in(struct management *man, const int size)
     }
 }
 
+
+void man_bytecount_output_server(struct management *man,
+                                 const counter_type *bytes_in_total,
+                                 const counter_type *bytes_out_total,
+                                 struct man_def_auth_context *mdac);
+
 #ifdef MANAGEMENT_DEF_AUTH
 
 static inline void
@@ -589,11 +595,6 @@ management_bytes_server(struct management *man,
                         const counter_type *bytes_out_total,
                         struct man_def_auth_context *mdac)
 {
-    void man_bytecount_output_server(struct management *man,
-                                     const counter_type *bytes_in_total,
-                                     const counter_type *bytes_out_total,
-                                     struct man_def_auth_context *mdac);
-
     if (man->connection.bytecount_update_seconds > 0
         && now >= mdac->bytecount_last_update + man->connection.bytecount_update_seconds
         && (mdac->flags & (DAF_CONNECTION_ESTABLISHED|DAF_CONNECTION_CLOSED)) == DAF_CONNECTION_ESTABLISHED)
src/openvpn/mbuf.h +2 -2
index e0643de1..1c35432f 100644
@@ -96,11 +96,11 @@ mbuf_maximum_queued(const struct mbuf_set *ms)
     return (int) ms->max_queued;
 }
 
+struct multi_instance *mbuf_peek_dowork(struct mbuf_set *ms);
+
 static inline struct multi_instance *
 mbuf_peek(struct mbuf_set *ms)
 {
-    struct multi_instance *mbuf_peek_dowork(struct mbuf_set *ms);
-
     if (mbuf_defined(ms))
     {
         return mbuf_peek_dowork(ms);
src/openvpn/mroute.h +11 -10
index 26421f88..3c06346f 100644
@@ -170,6 +170,17 @@ void mroute_helper_add_iroute46(struct mroute_helper *mh, int netbits);
 
 void mroute_helper_del_iroute46(struct mroute_helper *mh, int netbits);
 
+
+unsigned int mroute_extract_addr_ip(struct mroute_addr *src,
+                                    struct mroute_addr *dest,
+                                    const struct buffer *buf);
+
+unsigned int mroute_extract_addr_ether(struct mroute_addr *src,
+                                       struct mroute_addr *dest,
+                                       struct mroute_addr *esrc,
+                                       struct mroute_addr *edest,
+                                       const struct buffer *buf);
+
 /*
  * Given a raw packet in buf, return the src and dest
  * addresses of the packet.
@@ -182,16 +193,6 @@ mroute_extract_addr_from_packet(struct mroute_addr *src,
                                 const struct buffer *buf,
                                 int tunnel_type)
 {
-    unsigned int mroute_extract_addr_ip(struct mroute_addr *src,
-                                     struct mroute_addr *dest,
-                                     const struct buffer *buf);
-
-    unsigned int mroute_extract_addr_ether(struct mroute_addr *src,
-                                           struct mroute_addr *dest,
-                                           struct mroute_addr *esrc,
-                                           struct mroute_addr *edest,
-                                           const struct buffer *buf);
-
     unsigned int ret = 0;
     verify_align_4(buf);
     if (tunnel_type == DEV_TYPE_TUN)
src/openvpn/multi.h +3 -4
index 63afbaf0..5892ac07 100644
@@ -536,11 +536,12 @@ clear_prefix(void)
  */
 #define MULTI_CACHE_ROUTE_TTL 60
 
+void multi_reap_process_dowork(const struct multi_context *m);
+void multi_process_per_second_timers_dowork(struct multi_context *m);
+
 static inline void
 multi_reap_process(const struct multi_context *m)
 {
-    void multi_reap_process_dowork(const struct multi_context *m);
-
     if (m->reaper->last_call != now)
     {
         multi_reap_process_dowork(m);
@@ -552,8 +553,6 @@ multi_process_per_second_timers(struct multi_context *m)
 {
     if (m->per_second_trigger != now)
     {
-        void multi_process_per_second_timers_dowork(struct multi_context *m);
-
         multi_process_per_second_timers_dowork(m);
         m->per_second_trigger = now;
     }
src/openvpn/occ-inline.h +2 -6
index 0fa8e5ba..7ca2a26f 100644
@@ -26,6 +26,8 @@
 
 #ifdef ENABLE_OCC
 
+#include "occ.h"
+
 /*
  * Inline functions
  */
@@ -42,8 +44,6 @@ occ_reset_op(void)
 static inline void
 check_send_occ_req(struct context *c)
 {
-    void check_send_occ_req_dowork(struct context *c);
-
     if (event_timeout_defined(&c->c2.occ_interval)
         && event_timeout_trigger(&c->c2.occ_interval,
                                  &c->c2.timeval,
@@ -59,8 +59,6 @@ check_send_occ_req(struct context *c)
 static inline void
 check_send_occ_load_test(struct context *c)
 {
-    void check_send_occ_load_test_dowork(struct context *c);
-
     if (event_timeout_defined(&c->c2.occ_mtu_load_test_interval)
         && event_timeout_trigger(&c->c2.occ_mtu_load_test_interval,
                                  &c->c2.timeval,
@@ -76,8 +74,6 @@ check_send_occ_load_test(struct context *c)
 static inline void
 check_send_occ_msg(struct context *c)
 {
-    void check_send_occ_msg_dowork(struct context *c);
-
     if (c->c2.occ_op >= 0)
     {
         if (!TO_LINK_DEF(c))
src/openvpn/occ.h +6 -0
index 12d7bc57..29de99c2 100644
@@ -90,5 +90,11 @@ is_occ_msg(const struct buffer *buf)
 
 void process_received_occ_msg(struct context *c);
 
+void check_send_occ_req_dowork(struct context *c);
+
+void check_send_occ_load_test_dowork(struct context *c);
+
+void check_send_occ_msg_dowork(struct context *c);
+
 #endif /* ifdef ENABLE_OCC */
 #endif /* ifndef OCC_H */
src/openvpn/pf-inline.h +2 -4
index ac19ac4c..0db7b262 100644
@@ -24,6 +24,8 @@
 #if defined(ENABLE_PF) && !defined(PF_INLINE_H)
 #define PF_INLINE_H
 
+#include "pf.h"
+
 /*
  * Inline functions
  */
@@ -33,8 +35,6 @@
 static inline bool
 pf_c2c_test(const struct context *src, const struct context *dest, const char *prefix)
 {
-    bool pf_cn_test(struct pf_set *pfs, const struct tls_multi *tm, const int type, const char *prefix);
-
     return (!src->c2.pf.enabled  || pf_cn_test(src->c2.pf.pfs,  dest->c2.tls_multi, PCT_DEST, prefix))
            && (!dest->c2.pf.enabled || pf_cn_test(dest->c2.pf.pfs, src->c2.tls_multi,  PCT_SRC,  prefix));
 }
@@ -42,8 +42,6 @@ pf_c2c_test(const struct context *src, const struct context *dest, const char *p
 static inline bool
 pf_addr_test(const struct context *src, const struct mroute_addr *dest, const char *prefix)
 {
-    bool pf_addr_test_dowork(const struct context *src, const struct mroute_addr *dest, const char *prefix);
-
     if (src->c2.pf.enabled)
     {
         return pf_addr_test_dowork(src, dest, prefix);
src/openvpn/pf.h +6 -0
index 414c85b8..f6a3b61e 100644
@@ -101,4 +101,10 @@ void pf_context_print(const struct pf_context *pfc, const char *prefix, const in
 
 #endif
 
+bool pf_cn_test(struct pf_set *pfs, const struct tls_multi *tm, const int type,
+                const char *prefix);
+
+bool pf_addr_test_dowork(const struct context *src,
+                         const struct mroute_addr *dest, const char *prefix);
+
 #endif /* if defined(ENABLE_PF) && !defined(OPENVPN_PF_H) */
src/openvpn/ping-inline.h +2 -4
index 0642b851..9d590dc4 100644
@@ -24,6 +24,8 @@
 #ifndef PING_INLINE_H
 #define PING_INLINE_H
 
+#include "ping.h"
+
 /*
  * Should we exit or restart due to ping (or other authenticated packet)
  * not received in n seconds?
@@ -31,8 +33,6 @@
 static inline void
 check_ping_restart(struct context *c)
 {
-    void check_ping_restart_dowork(struct context *c);
-
     if (c->options.ping_rec_timeout
         && event_timeout_trigger(&c->c2.ping_rec_interval,
                                  &c->c2.timeval,
@@ -50,8 +50,6 @@ check_ping_restart(struct context *c)
 static inline void
 check_ping_send(struct context *c)
 {
-    void check_ping_send_dowork(struct context *c);
-
     if (c->options.ping_send_timeout
         && event_timeout_trigger(&c->c2.ping_send_interval,
                                  &c->c2.timeval,
src/openvpn/ping.h +4 -0
index 5bd5c089..66c3a54f 100644
@@ -43,4 +43,8 @@ is_ping_msg(const struct buffer *buf)
     return buf_string_match(buf, ping_string, PING_STRING_SIZE);
 }
 
+void check_ping_restart_dowork(struct context *c);
+
+void check_ping_send_dowork(struct context *c);
+
 #endif
src/openvpn/plugin.h +2 -0
index 818b6285..67549cda 100644
@@ -216,4 +216,6 @@ plugin_call(const struct plugin_list *pl,
                            );
 }
 
+void plugin_abort(void);
+
 #endif /* OPENVPN_PLUGIN_H */
src/openvpn/socket.h +7 -6
index 81e9e9ae..13b94606 100644
@@ -1021,11 +1021,11 @@ void stream_buf_close(struct stream_buf *sb);
 
 bool stream_buf_added(struct stream_buf *sb, int length_added);
 
+bool stream_buf_read_setup_dowork(struct link_socket *sock);
+
 static inline bool
 stream_buf_read_setup(struct link_socket *sock)
 {
-    bool stream_buf_read_setup_dowork(struct link_socket *sock);
-
     if (link_socket_connection_oriented(sock))
     {
         return stream_buf_read_setup_dowork(sock);
@@ -1130,16 +1130,17 @@ link_socket_write_win32(struct link_socket *sock,
 
 #else  /* ifdef _WIN32 */
 
+size_t link_socket_write_udp_posix_sendmsg(struct link_socket *sock,
+                                           struct buffer *buf,
+                                           struct link_socket_actual *to);
+
+
 static inline size_t
 link_socket_write_udp_posix(struct link_socket *sock,
                             struct buffer *buf,
                             struct link_socket_actual *to)
 {
 #if ENABLE_IP_PKTINFO
-    size_t link_socket_write_udp_posix_sendmsg(struct link_socket *sock,
-                                               struct buffer *buf,
-                                               struct link_socket_actual *to);
-
     if (proto_is_udp(sock->info.proto) && (sock->sockflags & SF_USE_IP_PKTINFO)
         && addr_defined_ipi(to))
     {
Signature · 1 line
2.14.1
#6 lore raw

Re: [Openvpn-devel] [PATCH v2] ensure function declarations are compiled with their definitions

Hi,

Quoted 44 lines · Antonio Quartulli

From: Antonio Quartulli <[email protected]...>

Function prototypes should be included when compiling their definitions so that it is clear to compilers and static analyzers that they are not static.

This means that several declarations have to be moved to the related header files which in turn have to be included by the source files implementing them.

Generally speaking this also improves the coding style and makes this code more consistent with the rest that already follows this rule.

---

v2: rebased on top of latest master to avoid conflict

 src/openvpn/crypto.h         |  3 +++
 src/openvpn/error.c          |  3 +--
 src/openvpn/forward-inline.h | 28 ++--------------------------
 src/openvpn/forward.h        | 35 +++++++++++++++++++++++++++++++++++
 src/openvpn/init.h           |  2 ++
 src/openvpn/lladdr.c         |  1 +
 src/openvpn/manage.h         | 11 ++++++-----
 src/openvpn/mbuf.h           |  4 ++--
 src/openvpn/mroute.h         | 21 +++++++++++----------
 src/openvpn/multi.h          |  7 +++----
 src/openvpn/occ-inline.h     |  8 ++------
 src/openvpn/occ.h            |  6 ++++++
 src/openvpn/pf-inline.h      |  6 ++----
 src/openvpn/pf.h             |  6 ++++++
 src/openvpn/ping-inline.h    |  6 ++----
 src/openvpn/ping.h           |  4 ++++
 src/openvpn/plugin.h         |  2 ++
 src/openvpn/socket.h         | 13 +++++++------
 18 files changed, 97 insertions(+), 69 deletions(-)
src/openvpn/crypto.h +0 -0
index f1b6c20a..5f0790a6 100644

src/openvpn/crypto.h void prng_bytes(uint8_t *output, int len); · line 472

Quoted 6 lines
src/openvpn/crypto.h +3 -0
@@ -467,6 +467,9 @@ void prng_bytes(uint8_t *output, int len);
 
 void prng_uninit(void);
 
+/* an analogue to the random() function, but use prng_bytes */
+long int get_random(void);
+

Though I agree that crypto.h is a better place for get_random() than misc.h, we already have one in misc.h. So if you move this here, remove it from misc.h.

Quoted 29 lines
src/openvpn/crypto.h +0 -0
 void test_crypto(struct crypto_options *co, struct frame *f);
 
 
src/openvpn/error.c +1 -2
index 04bf0da5..e885ec3b 100644
@@ -31,6 +31,7 @@
 
 #include "error.h"
 #include "buffer.h"
+#include "init.h"
 #include "misc.h"
 #include "win32.h"
 #include "socket.h"
@@ -734,8 +735,6 @@ openvpn_exit(const int status)
 {
     if (!forked)
     {
-        void tun_abort();
-
 #ifdef ENABLE_PLUGIN
         void plugin_abort(void);
 
src/openvpn/forward-inline.h +0 -0
index ab83ea40..04601e8c 100644

src/openvpn/forward-inline.h line 28

Quoted 5 lines
src/openvpn/forward-inline.h +2 -0
@@ -24,6 +24,8 @@
 #ifndef FORWARD_INLINE_H
 #define FORWARD_INLINE_H
 
+#include "forward.h"
+

If we do this, I think we should better merge forward_inline.h into forward.h. It seems someone was trying to prevent including forward.h, adding all these forward declarations into forward-inline.h. But looking at the current code, everything that includes forward-inline.h now somehow also includes forward.h. So I see no reason to keep these separate.

If you agree with me, and decide to merge there, could you please do that in a separate patch? That makes it a bit easier to review.

Quoted 146 lines
src/openvpn/forward-inline.h +0 -26
 /*
  * Inline functions
  */
@@ -35,8 +37,6 @@ static inline void
 check_tls(struct context *c)
 {
 #if defined(ENABLE_CRYPTO)
-    void check_tls_dowork(struct context *c);
-
     if (c->c2.tls_multi)
     {
         check_tls_dowork(c);
@@ -52,10 +52,6 @@ static inline void
 check_tls_errors(struct context *c)
 {
 #if defined(ENABLE_CRYPTO)
-    void check_tls_errors_co(struct context *c);
-
-    void check_tls_errors_nco(struct context *c);
-
     if (c->c2.tls_multi && c->c2.tls_exit_signal)
     {
         if (link_socket_connection_oriented(c->c2.link_socket))
@@ -84,8 +80,6 @@ static inline void
 check_incoming_control_channel(struct context *c)
 {
 #if P2MP
-    void check_incoming_control_channel_dowork(struct context *c);
-
     if (tls_test_payload_len(c->c2.tls_multi) > 0)
     {
         check_incoming_control_channel_dowork(c);
@@ -100,8 +94,6 @@ check_incoming_control_channel(struct context *c)
 static inline void
 check_connection_established(struct context *c)
 {
-    void check_connection_established_dowork(struct context *c);
-
     if (event_timeout_defined(&c->c2.wait_for_connect))
     {
         check_connection_established_dowork(c);
@@ -114,8 +106,6 @@ check_connection_established(struct context *c)
 static inline void
 check_add_routes(struct context *c)
 {
-    void check_add_routes_dowork(struct context *c);
-
     if (event_timeout_trigger(&c->c2.route_wakeup, &c->c2.timeval, ETT_DEFAULT))
     {
         check_add_routes_dowork(c);
@@ -128,8 +118,6 @@ check_add_routes(struct context *c)
 static inline void
 check_inactivity_timeout(struct context *c)
 {
-    void check_inactivity_timeout_dowork(struct context *c);
-
     if (c->options.inactivity_timeout
         && event_timeout_trigger(&c->c2.inactivity_interval, &c->c2.timeval, ETT_DEFAULT))
     {
@@ -142,8 +130,6 @@ check_inactivity_timeout(struct context *c)
 static inline void
 check_server_poll_timeout(struct context *c)
 {
-    void check_server_poll_timeout_dowork(struct context *c);
-
     if (c->options.ce.connect_timeout
         && event_timeout_trigger(&c->c2.server_poll_interval, &c->c2.timeval, ETT_DEFAULT))
     {
@@ -157,8 +143,6 @@ check_server_poll_timeout(struct context *c)
 static inline void
 check_scheduled_exit(struct context *c)
 {
-    void check_scheduled_exit_dowork(struct context *c);
-
     if (event_timeout_defined(&c->c2.scheduled_exit))
     {
         if (event_timeout_trigger(&c->c2.scheduled_exit, &c->c2.timeval, ETT_DEFAULT))
@@ -175,8 +159,6 @@ check_scheduled_exit(struct context *c)
 static inline void
 check_status_file(struct context *c)
 {
-    void check_status_file_dowork(struct context *c);
-
     if (c->c1.status_output)
     {
         if (status_trigger_tv(c->c1.status_output, &c->c2.timeval))
@@ -193,8 +175,6 @@ check_status_file(struct context *c)
 static inline void
 check_fragment(struct context *c)
 {
-    void check_fragment_dowork(struct context *c);
-
     if (c->c2.fragment)
     {
         check_fragment_dowork(c);
@@ -210,8 +190,6 @@ check_fragment(struct context *c)
 static inline void
 check_push_request(struct context *c)
 {
-    void check_push_request_dowork(struct context *c);
-
     if (event_timeout_trigger(&c->c2.push_request_interval, &c->c2.timeval, ETT_DEFAULT))
     {
         check_push_request_dowork(c);
@@ -313,8 +291,6 @@ p2p_iow_flags(const struct context *c)
 static inline void
 io_wait(struct context *c, const unsigned int flags)
 {
-    void io_wait_dowork(struct context *c, const unsigned int flags);
-
     if (c->c2.fast_io && (flags & (IOW_TO_TUN|IOW_TO_LINK|IOW_MBUF)))
     {
         /* fast path -- only for TUN/TAP/UDP writes */
src/openvpn/forward.h +25 -0
index 9fde5a30..bc016e5d 100644
@@ -60,6 +60,41 @@
 
 #define IOW_READ            (IOW_READ_TUN|IOW_READ_LINK)
 
+extern counter_type link_read_bytes_global;
+
+extern counter_type link_write_bytes_global;
+
+#ifdef ENABLE_CRYPTO
+void check_tls_dowork(struct context *c);
+
+void check_tls_errors_co(struct context *c);
+
+void check_tls_errors_nco(struct context *c);
+#endif /* ENABLE_CRYPTO */
+
+#if P2MP
+void check_incoming_control_channel_dowork(struct context *c);
+
+void check_scheduled_exit_dowork(struct context *c);
+
+void check_push_request_dowork(struct context *c);
+#endif /* P2MP */
+
+#ifdef ENABLE_FRAGMENT
+void check_fragment_dowork(struct context *c);
+#endif /* ENABLE_FRAGMENT */
+
+void check_connection_established_dowork(struct context *c);

src/openvpn/forward.h line 97

Quoted 10 lines
src/openvpn/forward.h +10 -0
+
+void check_add_routes_dowork(struct context *c);
+
+void check_inactivity_timeout_dowork(struct context *c);
+
+void check_server_poll_timeout_dowork(struct context *c);
+
+void check_status_file_dowork(struct context *c);
+
+void io_wait_dowork(struct context *c, const unsigned int flags);

These are already declared in forward-inline.h. I don't see why we need extra declarations here. But, if you follow my suggestion to merge these files, we don't have to discuss that any further :)

Quoted 31 lines
src/openvpn/forward.h +0 -0
 void pre_select(struct context *c);
 
src/openvpn/init.h +2 -0
index 15feb677..b681cd9d 100644
@@ -140,4 +140,6 @@ void open_plugins(struct context *c, const bool import_options, int init_point);
 
 #endif
 
+void tun_abort(void);
+
 #endif /* ifndef INIT_H */
src/openvpn/lladdr.c +1 -0
index ff71e48c..ea35e4d9 100644
@@ -11,6 +11,7 @@
 #include "syshead.h"
 #include "error.h"
 #include "misc.h"
+#include "lladdr.h"
 
 int
 set_lladdr(const char *ifname, const char *lladdr,
src/openvpn/manage.h +0 -0
index 676be640..d77e5f18 100644

src/openvpn/manage.h management_bytes_in(struct management *man, const int size) · line 589

Quoted 9 lines
src/openvpn/manage.h +6 -0
@@ -581,6 +581,12 @@ management_bytes_in(struct management *man, const int size)
     }
 }
 
+
+void man_bytecount_output_server(struct management *man,
+                                 const counter_type *bytes_in_total,
+                                 const counter_type *bytes_out_total,
+                                 struct man_def_auth_context *mdac);
+

This function is defined inside #ifdef MANAGEMENT_DEF_AUTH, so the declaration should be moved down after:

Quoted 38 lines
src/openvpn/manage.h +0 -5
 #ifdef MANAGEMENT_DEF_AUTH
 
 static inline void
@@ -589,11 +595,6 @@ management_bytes_server(struct management *man,
                         const counter_type *bytes_out_total,
                         struct man_def_auth_context *mdac)
 {
-    void man_bytecount_output_server(struct management *man,
-                                     const counter_type *bytes_in_total,
-                                     const counter_type *bytes_out_total,
-                                     struct man_def_auth_context *mdac);
-
     if (man->connection.bytecount_update_seconds > 0
         && now >= mdac->bytecount_last_update + man->connection.bytecount_update_seconds
         && (mdac->flags & (DAF_CONNECTION_ESTABLISHED|DAF_CONNECTION_CLOSED)) == DAF_CONNECTION_ESTABLISHED)
src/openvpn/mbuf.h +2 -2
index e0643de1..1c35432f 100644
@@ -96,11 +96,11 @@ mbuf_maximum_queued(const struct mbuf_set *ms)
     return (int) ms->max_queued;
 }
 
+struct multi_instance *mbuf_peek_dowork(struct mbuf_set *ms);
+
 static inline struct multi_instance *
 mbuf_peek(struct mbuf_set *ms)
 {
-    struct multi_instance *mbuf_peek_dowork(struct mbuf_set *ms);
-
     if (mbuf_defined(ms))
     {
         return mbuf_peek_dowork(ms);
src/openvpn/mroute.h +0 -0
index 26421f88..3c06346f 100644

src/openvpn/mroute.h void mroute_helper_add_iroute46(struct mroute_helper *mh, int netbits); · line 173

Quoted 4 lines
src/openvpn/mroute.h +1 -0
@@ -170,6 +170,17 @@ void mroute_helper_add_iroute46(struct mroute_helper *mh, int netbits);
 
 void mroute_helper_del_iroute46(struct mroute_helper *mh, int netbits);
 
+

Nit: one newline too many?

Quoted 63 lines
src/openvpn/mroute.h +10 -10
+unsigned int mroute_extract_addr_ip(struct mroute_addr *src,
+                                    struct mroute_addr *dest,
+                                    const struct buffer *buf);
+
+unsigned int mroute_extract_addr_ether(struct mroute_addr *src,
+                                       struct mroute_addr *dest,
+                                       struct mroute_addr *esrc,
+                                       struct mroute_addr *edest,
+                                       const struct buffer *buf);
+
 /*
  * Given a raw packet in buf, return the src and dest
  * addresses of the packet.
@@ -182,16 +193,6 @@ mroute_extract_addr_from_packet(struct mroute_addr *src,
                                 const struct buffer *buf,
                                 int tunnel_type)
 {
-    unsigned int mroute_extract_addr_ip(struct mroute_addr *src,
-                                     struct mroute_addr *dest,
-                                     const struct buffer *buf);
-
-    unsigned int mroute_extract_addr_ether(struct mroute_addr *src,
-                                           struct mroute_addr *dest,
-                                           struct mroute_addr *esrc,
-                                           struct mroute_addr *edest,
-                                           const struct buffer *buf);
-
     unsigned int ret = 0;
     verify_align_4(buf);
     if (tunnel_type == DEV_TYPE_TUN)
src/openvpn/multi.h +3 -4
index 63afbaf0..5892ac07 100644
@@ -536,11 +536,12 @@ clear_prefix(void)
  */
 #define MULTI_CACHE_ROUTE_TTL 60
 
+void multi_reap_process_dowork(const struct multi_context *m);
+void multi_process_per_second_timers_dowork(struct multi_context *m);
+
 static inline void
 multi_reap_process(const struct multi_context *m)
 {
-    void multi_reap_process_dowork(const struct multi_context *m);
-
     if (m->reaper->last_call != now)
     {
         multi_reap_process_dowork(m);
@@ -552,8 +553,6 @@ multi_process_per_second_timers(struct multi_context *m)
 {
     if (m->per_second_trigger != now)
     {
-        void multi_process_per_second_timers_dowork(struct multi_context *m);
-
         multi_process_per_second_timers_dowork(m);
         m->per_second_trigger = now;
     }
src/openvpn/occ-inline.h +0 -0
index 0fa8e5ba..7ca2a26f 100644

src/openvpn/occ-inline.h line 30

Quoted 5 lines
src/openvpn/occ-inline.h +2 -0
@@ -26,6 +26,8 @@
 
 #ifdef ENABLE_OCC
 
+#include "occ.h"
+

Same as for forward-inline.h: everything that includes occ-inline.h also seems to include occ.h somehow. I suggest to merge these files (in a separate commit).

Quoted 51 lines
src/openvpn/occ-inline.h +0 -6
 /*
  * Inline functions
  */
@@ -42,8 +44,6 @@ occ_reset_op(void)
 static inline void
 check_send_occ_req(struct context *c)
 {
-    void check_send_occ_req_dowork(struct context *c);
-
     if (event_timeout_defined(&c->c2.occ_interval)
         && event_timeout_trigger(&c->c2.occ_interval,
                                  &c->c2.timeval,
@@ -59,8 +59,6 @@ check_send_occ_req(struct context *c)
 static inline void
 check_send_occ_load_test(struct context *c)
 {
-    void check_send_occ_load_test_dowork(struct context *c);
-
     if (event_timeout_defined(&c->c2.occ_mtu_load_test_interval)
         && event_timeout_trigger(&c->c2.occ_mtu_load_test_interval,
                                  &c->c2.timeval,
@@ -76,8 +74,6 @@ check_send_occ_load_test(struct context *c)
 static inline void
 check_send_occ_msg(struct context *c)
 {
-    void check_send_occ_msg_dowork(struct context *c);
-
     if (c->c2.occ_op >= 0)
     {
         if (!TO_LINK_DEF(c))
src/openvpn/occ.h +6 -0
index 12d7bc57..29de99c2 100644
@@ -90,5 +90,11 @@ is_occ_msg(const struct buffer *buf)
 
 void process_received_occ_msg(struct context *c);
 
+void check_send_occ_req_dowork(struct context *c);
+
+void check_send_occ_load_test_dowork(struct context *c);
+
+void check_send_occ_msg_dowork(struct context *c);
+
 #endif /* ifdef ENABLE_OCC */
 #endif /* ifndef OCC_H */
src/openvpn/pf-inline.h +0 -0
index ac19ac4c..0db7b262 100644

src/openvpn/pf-inline.h line 28

Quoted 5 lines
src/openvpn/pf-inline.h +2 -0
@@ -24,6 +24,8 @@
 #if defined(ENABLE_PF) && !defined(PF_INLINE_H)
 #define PF_INLINE_H
 
+#include "pf.h"
+

This one seems to still be somewhat independent of pf.h, but let's merge these too.

Quoted 41 lines
src/openvpn/pf-inline.h +0 -4
 /*
  * Inline functions
  */
@@ -33,8 +35,6 @@
 static inline bool
 pf_c2c_test(const struct context *src, const struct context *dest, const char *prefix)
 {
-    bool pf_cn_test(struct pf_set *pfs, const struct tls_multi *tm, const int type, const char *prefix);
-
     return (!src->c2.pf.enabled  || pf_cn_test(src->c2.pf.pfs,  dest->c2.tls_multi, PCT_DEST, prefix))
            && (!dest->c2.pf.enabled || pf_cn_test(dest->c2.pf.pfs, src->c2.tls_multi,  PCT_SRC,  prefix));
 }
@@ -42,8 +42,6 @@ pf_c2c_test(const struct context *src, const struct context *dest, const char *p
 static inline bool
 pf_addr_test(const struct context *src, const struct mroute_addr *dest, const char *prefix)
 {
-    bool pf_addr_test_dowork(const struct context *src, const struct mroute_addr *dest, const char *prefix);
-
     if (src->c2.pf.enabled)
     {
         return pf_addr_test_dowork(src, dest, prefix);
src/openvpn/pf.h +6 -0
index 414c85b8..f6a3b61e 100644
@@ -101,4 +101,10 @@ void pf_context_print(const struct pf_context *pfc, const char *prefix, const in
 
 #endif
 
+bool pf_cn_test(struct pf_set *pfs, const struct tls_multi *tm, const int type,
+                const char *prefix);
+
+bool pf_addr_test_dowork(const struct context *src,
+                         const struct mroute_addr *dest, const char *prefix);
+
 #endif /* if defined(ENABLE_PF) && !defined(OPENVPN_PF_H) */
src/openvpn/ping-inline.h +0 -0
index 0642b851..9d590dc4 100644

src/openvpn/ping-inline.h line 28

Quoted 5 lines
src/openvpn/ping-inline.h +2 -0
@@ -24,6 +24,8 @@
 #ifndef PING_INLINE_H
 #define PING_INLINE_H
 
+#include "ping.h"
+

As for pf.h

Quoted 76 lines
src/openvpn/ping-inline.h +0 -4
 /*
  * Should we exit or restart due to ping (or other authenticated packet)
  * not received in n seconds?
@@ -31,8 +33,6 @@
 static inline void
 check_ping_restart(struct context *c)
 {
-    void check_ping_restart_dowork(struct context *c);
-
     if (c->options.ping_rec_timeout
         && event_timeout_trigger(&c->c2.ping_rec_interval,
                                  &c->c2.timeval,
@@ -50,8 +50,6 @@ check_ping_restart(struct context *c)
 static inline void
 check_ping_send(struct context *c)
 {
-    void check_ping_send_dowork(struct context *c);
-
     if (c->options.ping_send_timeout
         && event_timeout_trigger(&c->c2.ping_send_interval,
                                  &c->c2.timeval,
src/openvpn/ping.h +4 -0
index 5bd5c089..66c3a54f 100644
@@ -43,4 +43,8 @@ is_ping_msg(const struct buffer *buf)
     return buf_string_match(buf, ping_string, PING_STRING_SIZE);
 }
 
+void check_ping_restart_dowork(struct context *c);
+
+void check_ping_send_dowork(struct context *c);
+
 #endif
src/openvpn/plugin.h +2 -0
index 818b6285..67549cda 100644
@@ -216,4 +216,6 @@ plugin_call(const struct plugin_list *pl,
                            );
 }
 
+void plugin_abort(void);
+
 #endif /* OPENVPN_PLUGIN_H */
src/openvpn/socket.h +7 -2
index 81e9e9ae..13b94606 100644
@@ -1021,11 +1021,11 @@ void stream_buf_close(struct stream_buf *sb);
 
 bool stream_buf_added(struct stream_buf *sb, int length_added);
 
+bool stream_buf_read_setup_dowork(struct link_socket *sock);
+
 static inline bool
 stream_buf_read_setup(struct link_socket *sock)
 {
-    bool stream_buf_read_setup_dowork(struct link_socket *sock);
-
     if (link_socket_connection_oriented(sock))
     {
         return stream_buf_read_setup_dowork(sock);
@@ -1130,16 +1130,17 @@ link_socket_write_win32(struct link_socket *sock,
 
 #else  /* ifdef _WIN32 */
 
+size_t link_socket_write_udp_posix_sendmsg(struct link_socket *sock,
+                                           struct buffer *buf,
+                                           struct link_socket_actual *to);
+
+
 static inline size_t
 link_socket_write_udp_posix(struct link_socket *sock,
                             struct buffer *buf,

src/openvpn/socket.h link_socket_write_win32(struct link_socket *sock, · line 1146

Quoted 10 lines
src/openvpn/socket.h +0 -4
                             struct link_socket_actual *to)
 {
 #if ENABLE_IP_PKTINFO
-    size_t link_socket_write_udp_posix_sendmsg(struct link_socket *sock,
-                                               struct buffer *buf,
-                                               struct link_socket_actual *to);
-
     if (proto_is_udp(sock->info.proto) && (sock->sockflags & SF_USE_IP_PKTINFO)
         && addr_defined_ipi(to))
     {

Curious whether you agree with me.

-Steffan

#7 lore raw

Re: [Openvpn-devel] [PATCH v2] ensure function declarations are compiled with their definitions

Hi,

Quoted 50 lines · Steffan Karger

Hi,

Quoted 47 lines · Antonio Quartulli

From: Antonio Quartulli <[email protected]...>

Function prototypes should be included when compiling their definitions so that it is clear to compilers and static analyzers that they are not static.

This means that several declarations have to be moved to the related header files which in turn have to be included by the source files implementing them.

Generally speaking this also improves the coding style and makes this code more consistent with the rest that already follows this rule.

---

v2: rebased on top of latest master to avoid conflict

 src/openvpn/crypto.h         |  3 +++
 src/openvpn/error.c          |  3 +--
 src/openvpn/forward-inline.h | 28 ++--------------------------
 src/openvpn/forward.h        | 35 +++++++++++++++++++++++++++++++++++
 src/openvpn/init.h           |  2 ++
 src/openvpn/lladdr.c         |  1 +
 src/openvpn/manage.h         | 11 ++++++-----
 src/openvpn/mbuf.h           |  4 ++--
 src/openvpn/mroute.h         | 21 +++++++++++----------
 src/openvpn/multi.h          |  7 +++----
 src/openvpn/occ-inline.h     |  8 ++------
 src/openvpn/occ.h            |  6 ++++++
 src/openvpn/pf-inline.h      |  6 ++----
 src/openvpn/pf.h             |  6 ++++++
 src/openvpn/ping-inline.h    |  6 ++----
 src/openvpn/ping.h           |  4 ++++
 src/openvpn/plugin.h         |  2 ++
 src/openvpn/socket.h         | 13 +++++++------
 18 files changed, 97 insertions(+), 69 deletions(-)
src/openvpn/crypto.h +0 -0
index f1b6c20a..5f0790a6 100644
@@ -467,6 +467,9 @@ void prng_bytes(uint8_t *output, int len);
 
 void prng_uninit(void);
 
Quoted 7 lines

src/openvpn/crypto.h void prng_bytes(uint8_t *output, int len); · line 472

Quoted 3 lines
src/openvpn/crypto.h +3 -0
+/* an analogue to the random() function, but use prng_bytes */
+long int get_random(void);
+

Though I agree that crypto.h is a better place for get_random() than misc.h, we already have one in misc.h. So if you move this here, remove it from misc.h.

Oh I hadn't realized we had a declaration for get_random() in misc.h. The function is defined in crypto.c therefore I expected its declaration in crypto.h.

I'll remove it from misc.h then.

Quoted 43 lines
Quoted 30 lines
src/openvpn/crypto.h +0 -0
 void test_crypto(struct crypto_options *co, struct frame *f);
 
 
src/openvpn/error.c +1 -2
index 04bf0da5..e885ec3b 100644
@@ -31,6 +31,7 @@
 
 #include "error.h"
 #include "buffer.h"
+#include "init.h"
 #include "misc.h"
 #include "win32.h"
 #include "socket.h"
@@ -734,8 +735,6 @@ openvpn_exit(const int status)
 {
     if (!forked)
     {
-        void tun_abort();
-
 #ifdef ENABLE_PLUGIN
         void plugin_abort(void);
 
src/openvpn/forward-inline.h +0 -0
index ab83ea40..04601e8c 100644

src/openvpn/forward-inline.h line 28

Quoted 5 lines
src/openvpn/forward-inline.h +2 -0
@@ -24,6 +24,8 @@
 #ifndef FORWARD_INLINE_H
 #define FORWARD_INLINE_H
 
+#include "forward.h"
+

If we do this, I think we should better merge forward_inline.h into forward.h. It seems someone was trying to prevent including forward.h, adding all these forward declarations into forward-inline.h. But looking at the current code, everything that includes forward-inline.h now somehow also includes forward.h. So I see no reason to keep these separate.

Quoted 2 lines

If you agree with me, and decide to merge there, could you please do that in a separate patch? That makes it a bit easier to review.

Agreed. In the past there was a reason for having the -inline.h header files, but now I think this reason is gone (or at least I can't see it anymore).

Quoted 196 lines
Quoted 147 lines
src/openvpn/forward-inline.h +0 -26
 /*
  * Inline functions
  */
@@ -35,8 +37,6 @@ static inline void
 check_tls(struct context *c)
 {
 #if defined(ENABLE_CRYPTO)
-    void check_tls_dowork(struct context *c);
-
     if (c->c2.tls_multi)
     {
         check_tls_dowork(c);
@@ -52,10 +52,6 @@ static inline void
 check_tls_errors(struct context *c)
 {
 #if defined(ENABLE_CRYPTO)
-    void check_tls_errors_co(struct context *c);
-
-    void check_tls_errors_nco(struct context *c);
-
     if (c->c2.tls_multi && c->c2.tls_exit_signal)
     {
         if (link_socket_connection_oriented(c->c2.link_socket))
@@ -84,8 +80,6 @@ static inline void
 check_incoming_control_channel(struct context *c)
 {
 #if P2MP
-    void check_incoming_control_channel_dowork(struct context *c);
-
     if (tls_test_payload_len(c->c2.tls_multi) > 0)
     {
         check_incoming_control_channel_dowork(c);
@@ -100,8 +94,6 @@ check_incoming_control_channel(struct context *c)
 static inline void
 check_connection_established(struct context *c)
 {
-    void check_connection_established_dowork(struct context *c);
-
     if (event_timeout_defined(&c->c2.wait_for_connect))
     {
         check_connection_established_dowork(c);
@@ -114,8 +106,6 @@ check_connection_established(struct context *c)
 static inline void
 check_add_routes(struct context *c)
 {
-    void check_add_routes_dowork(struct context *c);
-
     if (event_timeout_trigger(&c->c2.route_wakeup, &c->c2.timeval, ETT_DEFAULT))
     {
         check_add_routes_dowork(c);
@@ -128,8 +118,6 @@ check_add_routes(struct context *c)
 static inline void
 check_inactivity_timeout(struct context *c)
 {
-    void check_inactivity_timeout_dowork(struct context *c);
-
     if (c->options.inactivity_timeout
         && event_timeout_trigger(&c->c2.inactivity_interval, &c->c2.timeval, ETT_DEFAULT))
     {
@@ -142,8 +130,6 @@ check_inactivity_timeout(struct context *c)
 static inline void
 check_server_poll_timeout(struct context *c)
 {
-    void check_server_poll_timeout_dowork(struct context *c);
-
     if (c->options.ce.connect_timeout
         && event_timeout_trigger(&c->c2.server_poll_interval, &c->c2.timeval, ETT_DEFAULT))
     {
@@ -157,8 +143,6 @@ check_server_poll_timeout(struct context *c)
 static inline void
 check_scheduled_exit(struct context *c)
 {
-    void check_scheduled_exit_dowork(struct context *c);
-
     if (event_timeout_defined(&c->c2.scheduled_exit))
     {
         if (event_timeout_trigger(&c->c2.scheduled_exit, &c->c2.timeval, ETT_DEFAULT))
@@ -175,8 +159,6 @@ check_scheduled_exit(struct context *c)
 static inline void
 check_status_file(struct context *c)
 {
-    void check_status_file_dowork(struct context *c);
-
     if (c->c1.status_output)
     {
         if (status_trigger_tv(c->c1.status_output, &c->c2.timeval))
@@ -193,8 +175,6 @@ check_status_file(struct context *c)
 static inline void
 check_fragment(struct context *c)
 {
-    void check_fragment_dowork(struct context *c);
-
     if (c->c2.fragment)
     {
         check_fragment_dowork(c);
@@ -210,8 +190,6 @@ check_fragment(struct context *c)
 static inline void
 check_push_request(struct context *c)
 {
-    void check_push_request_dowork(struct context *c);
-
     if (event_timeout_trigger(&c->c2.push_request_interval, &c->c2.timeval, ETT_DEFAULT))
     {
         check_push_request_dowork(c);
@@ -313,8 +291,6 @@ p2p_iow_flags(const struct context *c)
 static inline void
 io_wait(struct context *c, const unsigned int flags)
 {
-    void io_wait_dowork(struct context *c, const unsigned int flags);
-
     if (c->c2.fast_io && (flags & (IOW_TO_TUN|IOW_TO_LINK|IOW_MBUF)))
     {
         /* fast path -- only for TUN/TAP/UDP writes */
src/openvpn/forward.h +25 -0
index 9fde5a30..bc016e5d 100644
@@ -60,6 +60,41 @@
 
 #define IOW_READ            (IOW_READ_TUN|IOW_READ_LINK)
 
+extern counter_type link_read_bytes_global;
+
+extern counter_type link_write_bytes_global;
+
+#ifdef ENABLE_CRYPTO
+void check_tls_dowork(struct context *c);
+
+void check_tls_errors_co(struct context *c);
+
+void check_tls_errors_nco(struct context *c);
+#endif /* ENABLE_CRYPTO */
+
+#if P2MP
+void check_incoming_control_channel_dowork(struct context *c);
+
+void check_scheduled_exit_dowork(struct context *c);
+
+void check_push_request_dowork(struct context *c);
+#endif /* P2MP */
+
+#ifdef ENABLE_FRAGMENT
+void check_fragment_dowork(struct context *c);
+#endif /* ENABLE_FRAGMENT */
+
+void check_connection_established_dowork(struct context *c);

src/openvpn/forward.h line 97

Quoted 10 lines
src/openvpn/forward.h +10 -0
+
+void check_add_routes_dowork(struct context *c);
+
+void check_inactivity_timeout_dowork(struct context *c);
+
+void check_server_poll_timeout_dowork(struct context *c);
+
+void check_status_file_dowork(struct context *c);
+
+void io_wait_dowork(struct context *c, const unsigned int flags);

These are already declared in forward-inline.h. I don't see why we need extra declarations here. But, if you follow my suggestion to merge these files, we don't have to discuss that any further :)

Quoted 34 lines
src/openvpn/forward.h +0 -0
 void pre_select(struct context *c);
 
src/openvpn/init.h +2 -0
index 15feb677..b681cd9d 100644
@@ -140,4 +140,6 @@ void open_plugins(struct context *c, const bool import_options, int init_point);
 
 #endif
 
+void tun_abort(void);
+
 #endif /* ifndef INIT_H */
src/openvpn/lladdr.c +1 -0
index ff71e48c..ea35e4d9 100644
@@ -11,6 +11,7 @@
 #include "syshead.h"
 #include "error.h"
 #include "misc.h"
+#include "lladdr.h"
 
 int
 set_lladdr(const char *ifname, const char *lladdr,
src/openvpn/manage.h +0 -0
index 676be640..d77e5f18 100644
@@ -581,6 +581,12 @@ management_bytes_in(struct management *man, const int size)
     }
 }
 
Quoted 9 lines

src/openvpn/manage.h management_bytes_in(struct management *man, const int size) · line 589

Quoted 6 lines
src/openvpn/manage.h +6 -0
+
+void man_bytecount_output_server(struct management *man,
+                                 const counter_type *bytes_in_total,
+                                 const counter_type *bytes_out_total,
+                                 struct man_def_auth_context *mdac);
+

This function is defined inside #ifdef MANAGEMENT_DEF_AUTH, so the declaration should be moved down after:

ops..thanks!

Quoted 40 lines
Quoted 40 lines
src/openvpn/manage.h +0 -5
 #ifdef MANAGEMENT_DEF_AUTH
 
 static inline void
@@ -589,11 +595,6 @@ management_bytes_server(struct management *man,
                         const counter_type *bytes_out_total,
                         struct man_def_auth_context *mdac)
 {
-    void man_bytecount_output_server(struct management *man,
-                                     const counter_type *bytes_in_total,
-                                     const counter_type *bytes_out_total,
-                                     struct man_def_auth_context *mdac);
-
     if (man->connection.bytecount_update_seconds > 0
         && now >= mdac->bytecount_last_update + man->connection.bytecount_update_seconds
         && (mdac->flags & (DAF_CONNECTION_ESTABLISHED|DAF_CONNECTION_CLOSED)) == DAF_CONNECTION_ESTABLISHED)
src/openvpn/mbuf.h +2 -2
index e0643de1..1c35432f 100644
@@ -96,11 +96,11 @@ mbuf_maximum_queued(const struct mbuf_set *ms)
     return (int) ms->max_queued;
 }
 
+struct multi_instance *mbuf_peek_dowork(struct mbuf_set *ms);
+
 static inline struct multi_instance *
 mbuf_peek(struct mbuf_set *ms)
 {
-    struct multi_instance *mbuf_peek_dowork(struct mbuf_set *ms);
-
     if (mbuf_defined(ms))
     {
         return mbuf_peek_dowork(ms);
src/openvpn/mroute.h +0 -0
index 26421f88..3c06346f 100644
@@ -170,6 +170,17 @@ void mroute_helper_add_iroute46(struct mroute_helper *mh, int netbits);
 
Quoted 5 lines

src/openvpn/mroute.h void mroute_helper_add_iroute46(struct mroute_helper *mh, int netbits); · line 173

Quoted 3 lines
src/openvpn/mroute.h +1 -0
 void mroute_helper_del_iroute46(struct mroute_helper *mh, int netbits);
 
+

Nit: one newline too many?

Yes. We need only one empty line.

Quoted 128 lines
Quoted 64 lines
src/openvpn/mroute.h +10 -10
+unsigned int mroute_extract_addr_ip(struct mroute_addr *src,
+                                    struct mroute_addr *dest,
+                                    const struct buffer *buf);
+
+unsigned int mroute_extract_addr_ether(struct mroute_addr *src,
+                                       struct mroute_addr *dest,
+                                       struct mroute_addr *esrc,
+                                       struct mroute_addr *edest,
+                                       const struct buffer *buf);
+
 /*
  * Given a raw packet in buf, return the src and dest
  * addresses of the packet.
@@ -182,16 +193,6 @@ mroute_extract_addr_from_packet(struct mroute_addr *src,
                                 const struct buffer *buf,
                                 int tunnel_type)
 {
-    unsigned int mroute_extract_addr_ip(struct mroute_addr *src,
-                                     struct mroute_addr *dest,
-                                     const struct buffer *buf);
-
-    unsigned int mroute_extract_addr_ether(struct mroute_addr *src,
-                                           struct mroute_addr *dest,
-                                           struct mroute_addr *esrc,
-                                           struct mroute_addr *edest,
-                                           const struct buffer *buf);
-
     unsigned int ret = 0;
     verify_align_4(buf);
     if (tunnel_type == DEV_TYPE_TUN)
src/openvpn/multi.h +3 -4
index 63afbaf0..5892ac07 100644
@@ -536,11 +536,12 @@ clear_prefix(void)
  */
 #define MULTI_CACHE_ROUTE_TTL 60
 
+void multi_reap_process_dowork(const struct multi_context *m);
+void multi_process_per_second_timers_dowork(struct multi_context *m);
+
 static inline void
 multi_reap_process(const struct multi_context *m)
 {
-    void multi_reap_process_dowork(const struct multi_context *m);
-
     if (m->reaper->last_call != now)
     {
         multi_reap_process_dowork(m);
@@ -552,8 +553,6 @@ multi_process_per_second_timers(struct multi_context *m)
 {
     if (m->per_second_trigger != now)
     {
-        void multi_process_per_second_timers_dowork(struct multi_context *m);
-
         multi_process_per_second_timers_dowork(m);
         m->per_second_trigger = now;
     }
src/openvpn/occ-inline.h +0 -0
index 0fa8e5ba..7ca2a26f 100644

src/openvpn/occ-inline.h line 30

Quoted 5 lines
src/openvpn/occ-inline.h +2 -0
@@ -26,6 +26,8 @@
 
 #ifdef ENABLE_OCC
 
+#include "occ.h"
+

Same as for forward-inline.h: everything that includes occ-inline.h also seems to include occ.h somehow. I suggest to merge these files (in a separate commit).

Quoted 54 lines
src/openvpn/occ-inline.h +0 -6
 /*
  * Inline functions
  */
@@ -42,8 +44,6 @@ occ_reset_op(void)
 static inline void
 check_send_occ_req(struct context *c)
 {
-    void check_send_occ_req_dowork(struct context *c);
-
     if (event_timeout_defined(&c->c2.occ_interval)
         && event_timeout_trigger(&c->c2.occ_interval,
                                  &c->c2.timeval,
@@ -59,8 +59,6 @@ check_send_occ_req(struct context *c)
 static inline void
 check_send_occ_load_test(struct context *c)
 {
-    void check_send_occ_load_test_dowork(struct context *c);
-
     if (event_timeout_defined(&c->c2.occ_mtu_load_test_interval)
         && event_timeout_trigger(&c->c2.occ_mtu_load_test_interval,
                                  &c->c2.timeval,
@@ -76,8 +74,6 @@ check_send_occ_load_test(struct context *c)
 static inline void
 check_send_occ_msg(struct context *c)
 {
-    void check_send_occ_msg_dowork(struct context *c);
-
     if (c->c2.occ_op >= 0)
     {
         if (!TO_LINK_DEF(c))
src/openvpn/occ.h +6 -0
index 12d7bc57..29de99c2 100644
@@ -90,5 +90,11 @@ is_occ_msg(const struct buffer *buf)
 
 void process_received_occ_msg(struct context *c);
 
+void check_send_occ_req_dowork(struct context *c);
+
+void check_send_occ_load_test_dowork(struct context *c);
+
+void check_send_occ_msg_dowork(struct context *c);
+
 #endif /* ifdef ENABLE_OCC */
 #endif /* ifndef OCC_H */
src/openvpn/pf-inline.h +0 -0
index ac19ac4c..0db7b262 100644
@@ -24,6 +24,8 @@
 #if defined(ENABLE_PF) && !defined(PF_INLINE_H)
 #define PF_INLINE_H
 
Quoted 5 lines

src/openvpn/pf-inline.h line 28

Quoted 2 lines
src/openvpn/pf-inline.h +2 -0
+#include "pf.h"
+

This one seems to still be somewhat independent of pf.h, but let's merge these too.

Yeah.

Quoted 130 lines
Quoted 42 lines
src/openvpn/pf-inline.h +0 -4
 /*
  * Inline functions
  */
@@ -33,8 +35,6 @@
 static inline bool
 pf_c2c_test(const struct context *src, const struct context *dest, const char *prefix)
 {
-    bool pf_cn_test(struct pf_set *pfs, const struct tls_multi *tm, const int type, const char *prefix);
-
     return (!src->c2.pf.enabled  || pf_cn_test(src->c2.pf.pfs,  dest->c2.tls_multi, PCT_DEST, prefix))
            && (!dest->c2.pf.enabled || pf_cn_test(dest->c2.pf.pfs, src->c2.tls_multi,  PCT_SRC,  prefix));
 }
@@ -42,8 +42,6 @@ pf_c2c_test(const struct context *src, const struct context *dest, const char *p
 static inline bool
 pf_addr_test(const struct context *src, const struct mroute_addr *dest, const char *prefix)
 {
-    bool pf_addr_test_dowork(const struct context *src, const struct mroute_addr *dest, const char *prefix);
-
     if (src->c2.pf.enabled)
     {
         return pf_addr_test_dowork(src, dest, prefix);
src/openvpn/pf.h +6 -0
index 414c85b8..f6a3b61e 100644
@@ -101,4 +101,10 @@ void pf_context_print(const struct pf_context *pfc, const char *prefix, const in
 
 #endif
 
+bool pf_cn_test(struct pf_set *pfs, const struct tls_multi *tm, const int type,
+                const char *prefix);
+
+bool pf_addr_test_dowork(const struct context *src,
+                         const struct mroute_addr *dest, const char *prefix);
+
 #endif /* if defined(ENABLE_PF) && !defined(OPENVPN_PF_H) */
src/openvpn/ping-inline.h +0 -0
index 0642b851..9d590dc4 100644

src/openvpn/ping-inline.h line 28

Quoted 5 lines
src/openvpn/ping-inline.h +2 -0
@@ -24,6 +24,8 @@
 #ifndef PING_INLINE_H
 #define PING_INLINE_H
 
+#include "ping.h"
+

As for pf.h

Quoted 80 lines
src/openvpn/ping-inline.h +0 -4
 /*
  * Should we exit or restart due to ping (or other authenticated packet)
  * not received in n seconds?
@@ -31,8 +33,6 @@
 static inline void
 check_ping_restart(struct context *c)
 {
-    void check_ping_restart_dowork(struct context *c);
-
     if (c->options.ping_rec_timeout
         && event_timeout_trigger(&c->c2.ping_rec_interval,
                                  &c->c2.timeval,
@@ -50,8 +50,6 @@ check_ping_restart(struct context *c)
 static inline void
 check_ping_send(struct context *c)
 {
-    void check_ping_send_dowork(struct context *c);
-
     if (c->options.ping_send_timeout
         && event_timeout_trigger(&c->c2.ping_send_interval,
                                  &c->c2.timeval,
src/openvpn/ping.h +4 -0
index 5bd5c089..66c3a54f 100644
@@ -43,4 +43,8 @@ is_ping_msg(const struct buffer *buf)
     return buf_string_match(buf, ping_string, PING_STRING_SIZE);
 }
 
+void check_ping_restart_dowork(struct context *c);
+
+void check_ping_send_dowork(struct context *c);
+
 #endif
src/openvpn/plugin.h +2 -0
index 818b6285..67549cda 100644
@@ -216,4 +216,6 @@ plugin_call(const struct plugin_list *pl,
                            );
 }
 
+void plugin_abort(void);
+
 #endif /* OPENVPN_PLUGIN_H */
src/openvpn/socket.h +7 -4
index 81e9e9ae..13b94606 100644
@@ -1021,11 +1021,11 @@ void stream_buf_close(struct stream_buf *sb);
 
 bool stream_buf_added(struct stream_buf *sb, int length_added);
 
+bool stream_buf_read_setup_dowork(struct link_socket *sock);
+
 static inline bool
 stream_buf_read_setup(struct link_socket *sock)
 {
-    bool stream_buf_read_setup_dowork(struct link_socket *sock);
-
     if (link_socket_connection_oriented(sock))
     {
         return stream_buf_read_setup_dowork(sock);
@@ -1130,16 +1130,17 @@ link_socket_write_win32(struct link_socket *sock,
 
 #else  /* ifdef _WIN32 */
 
+size_t link_socket_write_udp_posix_sendmsg(struct link_socket *sock,
+                                           struct buffer *buf,
+                                           struct link_socket_actual *to);
+
+
 static inline size_t
 link_socket_write_udp_posix(struct link_socket *sock,
                             struct buffer *buf,
                             struct link_socket_actual *to)
 {
 #if ENABLE_IP_PKTINFO
-    size_t link_socket_write_udp_posix_sendmsg(struct link_socket *sock,
-                                               struct buffer *buf,
Quoted 8 lines

src/openvpn/socket.h link_socket_write_win32(struct link_socket *sock, · line 1146

Quoted 6 lines
src/openvpn/socket.h +0 -2
-                                               struct link_socket_actual *to);
-
     if (proto_is_udp(sock->info.proto) && (sock->sockflags & SF_USE_IP_PKTINFO)
         && addr_defined_ipi(to))
     {

Curious whether you agree with me.

Yeah, I do. As I said above, in the past there was a reason for having the -forward.h files that did not depend on the plain .h. I remember I have tried to get rid of the -forward.h already but something exploded. Now it seems merging should just work.

I'll send two new patches soon.

Thanks for reviewing!

Cheers,

Quoted 11 lines

-Steffan

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openvpn-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Signature · 1 line
Antonio Quartulli
#8 lore raw

PATCH 3/5 add missing static attribute to functions

In reply to Antonio Quartulli

From: Antonio Quartulli <[email protected]...>

Functions used only in the file where they are defined and not exported in any header, should always defined as static in order to make the scope clear to the compiler and the developers.

Add the static attribute where missing.

---
 src/openvpn/comp-lz4.c | 2 +-
 src/openvpn/forward.c  | 2 +-
 src/openvpn/manage.c   | 6 +++---
 src/openvpn/mtcp.c     | 2 +-
 src/openvpn/multi.c    | 4 ++--
 src/openvpn/ntlm.c     | 2 +-
 src/openvpn/options.c  | 8 ++++----
 src/openvpn/proxy.c    | 2 +-
 src/openvpn/route.c    | 4 ++--
 src/openvpn/socket.c   | 2 +-
 src/openvpn/ssl.c      | 2 +-
 11 files changed, 18 insertions(+), 18 deletions(-)
src/openvpn/comp-lz4.c +1 -1
index 6e40c325..e056caa8 100644
@@ -185,7 +185,7 @@ lz4v2_compress(struct buffer *buf, struct buffer work,
     }
 }
 
-void
+static void
 do_lz4_decompress(size_t zlen_max,
                   struct buffer *work,
                   struct buffer *buf,
src/openvpn/forward.c +1 -1
index c45d1259..6cc59383 100644
@@ -1007,7 +1007,7 @@ process_incoming_link_part2(struct context *c, struct link_socket_info *lsi, con
     }
 }
 
-void
+static void
 process_incoming_link(struct context *c)
 {
     perf_push(PERF_PROC_IN_LINK);
src/openvpn/manage.c +3 -3
index 3bbe972e..88121a38 100644
@@ -3515,7 +3515,7 @@ management_query_user_pass(struct management *man,
 
 #ifdef MANAGMENT_EXTERNAL_KEY
 
-int
+static int
 management_query_multiline(struct management *man,
                            const char *b64_data, const char *prompt, const char *cmd, int *state, struct buffer_list **input)
 {
@@ -3591,7 +3591,7 @@ done:
     return ret;
 }
 
-char *
+static char *
 /* returns allocated base64 signature */
 management_query_multiline_flatten_newline(struct management *man,
                                            const char *b64_data, const char *prompt, const char *cmd, int *state, struct buffer_list **input)
@@ -3620,7 +3620,7 @@ management_query_multiline_flatten_newline(struct management *man,
     return result;
 }
 
-char *
+static char *
 /* returns allocated base64 signature */
 management_query_multiline_flatten(struct management *man,
                                    const char *b64_data, const char *prompt, const char *cmd, int *state, struct buffer_list **input)
src/openvpn/mtcp.c +1 -1
index 851643a9..3cb52113 100644
@@ -521,7 +521,7 @@ multi_tcp_dispatch(struct multi_context *m, struct multi_instance *mi, const int
     return touched;
 }
 
-int
+static int
 multi_tcp_post(struct multi_context *m, struct multi_instance *mi, const int action)
 {
     struct context *c = multi_tcp_context(m, mi);
src/openvpn/multi.c +2 -2
index f5df58fa..fc20e0f9 100644
@@ -485,7 +485,7 @@ multi_instance_string(const struct multi_instance *mi, bool null, struct gc_aren
     }
 }
 
-void
+static void
 generate_prefix(struct multi_instance *mi)
 {
     struct gc_arena gc = gc_new();
@@ -2966,7 +2966,7 @@ gremlin_flood_clients(struct multi_context *m)
 }
 #endif /* ifdef ENABLE_DEBUG */
 
-bool
+static bool
 stale_route_check_trigger(struct multi_context *m)
 {
     struct timeval null;
src/openvpn/ntlm.c +1 -1
index a251c11d..b43c0058 100644
@@ -131,7 +131,7 @@ gen_nonce(unsigned char *nonce)
     }
 }
 
-void
+static void
 my_strupr(char *str)
 {
     /* converts string to uppercase in place */
src/openvpn/options.c +4 -4
index 9f2ceea2..b1e04310 100644
@@ -959,7 +959,7 @@ pull_filter_type_name(int type)
 
 #endif
 
-void
+static void
 setenv_connection_entry(struct env_set *es,
                         const struct connection_entry *e,
                         const int i)
@@ -1378,7 +1378,7 @@ rol_check_alloc(struct options *options)
     }
 }
 
-void
+static void
 rol6_check_alloc(struct options *options)
 {
     if (!options->routes_ipv6)
@@ -1808,7 +1808,7 @@ parse_http_proxy_override(const char *server,
     }
 }
 
-void
+static void
 options_postprocess_http_proxy_override(struct options *o)
 {
     const struct connection_list *l = o->connection_list;
@@ -1925,7 +1925,7 @@ alloc_pull_filter(struct options *o, const int msglevel)
     return f;
 }
 
-void
+static void
 connection_entry_load_re(struct connection_entry *ce, const struct remote_entry *re)
 {
     if (re->remote)
src/openvpn/proxy.c +1 -1
index 1ae93ad5..fdc73b4a 100644
@@ -549,7 +549,7 @@ http_proxy_close(struct http_proxy_info *hp)
     free(hp);
 }
 
-bool
+static bool
 add_proxy_headers(struct http_proxy_info *p,
                   socket_descriptor_t sd, /* already open to proxy */
                   const char *host,       /* openvpn server remote */
src/openvpn/route.c +2 -2
index 5994cdca..762f489c 100644
@@ -518,14 +518,14 @@ add_route_ipv6_to_option_list(struct route_ipv6_option_list *l,
     l->routes_ipv6 = ro;
 }
 
-void
+static void
 clear_route_list(struct route_list *rl)
 {
     gc_free(&rl->gc);
     CLEAR(*rl);
 }
 
-void
+static void
 clear_route_ipv6_list(struct route_ipv6_list *rl6)
 {
     gc_free(&rl6->gc);
src/openvpn/socket.c +1 -1
index 09973d61..c8ab2f8d 100644
@@ -1533,7 +1533,7 @@ set_actual_address(struct link_socket_actual *actual, struct addrinfo *ai)
 
 }
 
-void
+static void
 socket_connect(socket_descriptor_t *sd,
                const struct sockaddr *dest,
                const int connect_timeout,
src/openvpn/ssl.c +1 -1
index f5c59b77..45b20e56 100644
@@ -1607,7 +1607,7 @@ key_source2_print(const struct key_source2 *k)
  * @param out           Output buffer
  * @param olen          Length of the output buffer
  */
-void
+static void
 tls1_P_hash(const md_kt_t *md_kt,
             const uint8_t *sec,
             int sec_len,
Signature · 1 line
2.14.0
#9 lore raw

Re: [Openvpn-devel] [PATCH 3/5] add missing static attribute to functions

Quoted 222 lines · Antonio Quartulli

From: Antonio Quartulli <[email protected]...>

Functions used only in the file where they are defined and not exported in any header, should always defined as static in order to make the scope clear to the compiler and the developers.

Add the static attribute where missing.

---
 src/openvpn/comp-lz4.c | 2 +-
 src/openvpn/forward.c  | 2 +-
 src/openvpn/manage.c   | 6 +++---
 src/openvpn/mtcp.c     | 2 +-
 src/openvpn/multi.c    | 4 ++--
 src/openvpn/ntlm.c     | 2 +-
 src/openvpn/options.c  | 8 ++++----
 src/openvpn/proxy.c    | 2 +-
 src/openvpn/route.c    | 4 ++--
 src/openvpn/socket.c   | 2 +-
 src/openvpn/ssl.c      | 2 +-
 11 files changed, 18 insertions(+), 18 deletions(-)
src/openvpn/comp-lz4.c +1 -1
index 6e40c325..e056caa8 100644
@@ -185,7 +185,7 @@ lz4v2_compress(struct buffer *buf, struct buffer work,
     }
 }
 
-void
+static void
 do_lz4_decompress(size_t zlen_max,
                   struct buffer *work,
                   struct buffer *buf,
src/openvpn/forward.c +1 -1
index c45d1259..6cc59383 100644
@@ -1007,7 +1007,7 @@ process_incoming_link_part2(struct context *c, struct link_socket_info *lsi, con
     }
 }
 
-void
+static void
 process_incoming_link(struct context *c)
 {
     perf_push(PERF_PROC_IN_LINK);
src/openvpn/manage.c +3 -3
index 3bbe972e..88121a38 100644
@@ -3515,7 +3515,7 @@ management_query_user_pass(struct management *man,
 
 #ifdef MANAGMENT_EXTERNAL_KEY
 
-int
+static int
 management_query_multiline(struct management *man,
                            const char *b64_data, const char *prompt, const char *cmd, int *state, struct buffer_list **input)
 {
@@ -3591,7 +3591,7 @@ done:
     return ret;
 }
 
-char *
+static char *
 /* returns allocated base64 signature */
 management_query_multiline_flatten_newline(struct management *man,
                                            const char *b64_data, const char *prompt, const char *cmd, int *state, struct buffer_list **input)
@@ -3620,7 +3620,7 @@ management_query_multiline_flatten_newline(struct management *man,
     return result;
 }
 
-char *
+static char *
 /* returns allocated base64 signature */
 management_query_multiline_flatten(struct management *man,
                                    const char *b64_data, const char *prompt, const char *cmd, int *state, struct buffer_list **input)
src/openvpn/mtcp.c +1 -1
index 851643a9..3cb52113 100644
@@ -521,7 +521,7 @@ multi_tcp_dispatch(struct multi_context *m, struct multi_instance *mi, const int
     return touched;
 }
 
-int
+static int
 multi_tcp_post(struct multi_context *m, struct multi_instance *mi, const int action)
 {
     struct context *c = multi_tcp_context(m, mi);
src/openvpn/multi.c +2 -2
index f5df58fa..fc20e0f9 100644
@@ -485,7 +485,7 @@ multi_instance_string(const struct multi_instance *mi, bool null, struct gc_aren
     }
 }
 
-void
+static void
 generate_prefix(struct multi_instance *mi)
 {
     struct gc_arena gc = gc_new();
@@ -2966,7 +2966,7 @@ gremlin_flood_clients(struct multi_context *m)
 }
 #endif /* ifdef ENABLE_DEBUG */
 
-bool
+static bool
 stale_route_check_trigger(struct multi_context *m)
 {
     struct timeval null;
src/openvpn/ntlm.c +1 -1
index a251c11d..b43c0058 100644
@@ -131,7 +131,7 @@ gen_nonce(unsigned char *nonce)
     }
 }
 
-void
+static void
 my_strupr(char *str)
 {
     /* converts string to uppercase in place */
src/openvpn/options.c +4 -4
index 9f2ceea2..b1e04310 100644
@@ -959,7 +959,7 @@ pull_filter_type_name(int type)
 
 #endif
 
-void
+static void
 setenv_connection_entry(struct env_set *es,
                         const struct connection_entry *e,
                         const int i)
@@ -1378,7 +1378,7 @@ rol_check_alloc(struct options *options)
     }
 }
 
-void
+static void
 rol6_check_alloc(struct options *options)
 {
     if (!options->routes_ipv6)
@@ -1808,7 +1808,7 @@ parse_http_proxy_override(const char *server,
     }
 }
 
-void
+static void
 options_postprocess_http_proxy_override(struct options *o)
 {
     const struct connection_list *l = o->connection_list;
@@ -1925,7 +1925,7 @@ alloc_pull_filter(struct options *o, const int msglevel)
     return f;
 }
 
-void
+static void
 connection_entry_load_re(struct connection_entry *ce, const struct remote_entry *re)
 {
     if (re->remote)
src/openvpn/proxy.c +1 -1
index 1ae93ad5..fdc73b4a 100644
@@ -549,7 +549,7 @@ http_proxy_close(struct http_proxy_info *hp)
     free(hp);
 }
 
-bool
+static bool
 add_proxy_headers(struct http_proxy_info *p,
                   socket_descriptor_t sd, /* already open to proxy */
                   const char *host,       /* openvpn server remote */
src/openvpn/route.c +2 -2
index 5994cdca..762f489c 100644
@@ -518,14 +518,14 @@ add_route_ipv6_to_option_list(struct route_ipv6_option_list *l,
     l->routes_ipv6 = ro;
 }
 
-void
+static void
 clear_route_list(struct route_list *rl)
 {
     gc_free(&rl->gc);
     CLEAR(*rl);
 }
 
-void
+static void
 clear_route_ipv6_list(struct route_ipv6_list *rl6)
 {
     gc_free(&rl6->gc);
src/openvpn/socket.c +1 -1
index 09973d61..c8ab2f8d 100644
@@ -1533,7 +1533,7 @@ set_actual_address(struct link_socket_actual *actual, struct addrinfo *ai)
 
 }
 
-void
+static void
 socket_connect(socket_descriptor_t *sd,
                const struct sockaddr *dest,
                const int connect_timeout,
src/openvpn/ssl.c +0 -0
index f5c59b77..45b20e56 100644

src/openvpn/ssl.c key_source2_print(const struct key_source2 *k) · line 1613

Quoted 8 lines
src/openvpn/ssl.c +1 -1
@@ -1607,7 +1607,7 @@ key_source2_print(const struct key_source2 *k)
  * @param out           Output buffer
  * @param olen          Length of the output buffer
  */
-void
+static void
 tls1_P_hash(const md_kt_t *md_kt,
             const uint8_t *sec,
             int sec_len,

ACK

-Steffan

#10 lore raw

Re: [Openvpn-devel] [PATCH applied] add missing static attribute to functions

In reply to Antonio Quartulli

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Your patch has been applied to the following branches

commit 72bcdfdc19243c1ed6cb8568f62f0c35e8b70f5f (master) commit d1e18d89d9ff4ce946f27d5b019c407bf750fe4b (release/2.4)

Author: Antonio Quartulli
Date:   Fri Aug 11 17:07:42 2017 +0800
     add missing static attribute to functions

     Signed-off-by: Antonio Quartulli <[email protected]...>
     Acked-by: Steffan Karger <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg15202.html
     Signed-off-by: David Sommerseth <[email protected]...>

- --
kind regards,

David Sommerseth

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)

iQIcBAEBCgAGBQJZkarWAAoJEIbPlEyWcf3ykp8P/jZX5e+B8le3+hfEqpKHuaE1 739gAXun6mrVjbxQOcFrhBp68igoNzRNmZ6mTJYfhIfksgJGscZJ5y9RygLvHNHm XnHRFLwwdGiU1H+Cw28io1Z5mmLlbeFavvb3H2JaeDRNyZy3MqEF1U/G46zlJ93E 1lPVlqRj+ANkThw7VKKs0EBcW5cEQfTR4UkzSTT4anwDVqjBe970hYZnLevSLMVG mNzbPaUl+zON6z14RbnDqvVNxt53hccDJbxL4bLgNmEAJYBbxuwVc0/teYw1c0Mv bD7ACZXIW+8hFQIno+GxwOpCSamOF+g58x0peyTdKa5vBzNsgwTzktwgnux+4NFl 5rXR6vM88W5AtXnwXzGNYHkVTYVieNjunnUbV6Oo2KUwLLLPX7jh5/9lbmqBt2q0 ZuUABlnisIcNWsjpnQPdMhGlRjqaFBGN6Ww7/ozgaSev83xjughDpXoJfgybPcf1 jvZexEUrlasO50cdVvlbkRoXamFxUU3QgDRT/QY6qi95x67jrZP7cV/ThfAZLWfr qM7c5zN9uKaepy7m5Hmy9698VL+aotgUl+qsD8TfaO5cfzUc3mItIA538Tla9vAJ USGIaVrQQVHNBBESWg26mDBa2z0s++X1gjH6HrYxRDUqFNlaQyHulpl1atwy7iYL tGbxLS4+bA+n/HGEDU9b
=lkM2
-----END PGP SIGNATURE-----

#11 lore raw

PATCH 4/5 remove unused functions

In reply to Antonio Quartulli

From: Antonio Quartulli <[email protected]...>

---
 src/openvpn/misc.c        | 23 -----------------------
 src/openvpn/ssl.c         | 10 ----------
 src/openvpn/ssl_openssl.c |  6 ------
 3 files changed, 39 deletions(-)
src/openvpn/misc.c +0 -23
index 07775992..a599fd70 100644
@@ -448,29 +448,6 @@ construct_name_value(const char *name, const char *value, struct gc_arena *gc)
     return BSTR(&out);
 }
 
-bool
-deconstruct_name_value(const char *str, const char **name, const char **value, struct gc_arena *gc)
-{
-    char *cp;
-
-    ASSERT(str);
-    ASSERT(name && value);
-
-    *name = cp = string_alloc(str, gc);
-    *value = NULL;
-
-    while ((*cp))
-    {
-        if (*cp == '=' && !*value)
-        {
-            *cp = 0;
-            *value = cp + 1;
-        }
-        ++cp;
-    }
-    return *name && *value;
-}
-
 static bool
 env_string_equal(const char *s1, const char *s2)
 {
src/openvpn/ssl.c +0 -10
index 45b20e56..460ef9e8 100644
@@ -2177,16 +2177,6 @@ read_string_alloc(struct buffer *buf)
     return str;
 }
 
-void
-read_string_discard(struct buffer *buf)
-{
-    char *data = read_string_alloc(buf);
-    if (data)
-    {
-        free(data);
-    }
-}
-
 /*
  * Handle the reading and writing of key data to and from
  * the TLS control channel (cleartext).
src/openvpn/ssl_openssl.c +0 -6
index 7ad6414e..fa06f068 100644
@@ -797,12 +797,6 @@ tls_ctx_load_cert_file(struct tls_root_ctx *ctx, const char *cert_file,
     tls_ctx_load_cert_file_and_copy(ctx, cert_file, cert_file_inline, NULL);
 }
 
-void
-tls_ctx_free_cert_file(X509 *x509)
-{
-    X509_free(x509);
-}
-
 int
 tls_ctx_load_priv_file(struct tls_root_ctx *ctx, const char *priv_key_file,
                        bool priv_key_file_inline)
Signature · 1 line
2.14.0
#12 lore raw

Re: [Openvpn-devel] [PATCH 4/5] remove unused functions

Hi,

Quoted 72 lines · Antonio Quartulli

From: Antonio Quartulli <[email protected]...>

---
 src/openvpn/misc.c        | 23 -----------------------
 src/openvpn/ssl.c         | 10 ----------
 src/openvpn/ssl_openssl.c |  6 ------
 3 files changed, 39 deletions(-)
src/openvpn/misc.c +0 -23
index 07775992..a599fd70 100644
@@ -448,29 +448,6 @@ construct_name_value(const char *name, const char *value, struct gc_arena *gc)
     return BSTR(&out);
 }
 
-bool
-deconstruct_name_value(const char *str, const char **name, const char **value, struct gc_arena *gc)
-{
-    char *cp;
-
-    ASSERT(str);
-    ASSERT(name && value);
-
-    *name = cp = string_alloc(str, gc);
-    *value = NULL;
-
-    while ((*cp))
-    {
-        if (*cp == '=' && !*value)
-        {
-            *cp = 0;
-            *value = cp + 1;
-        }
-        ++cp;
-    }
-    return *name && *value;
-}
-
 static bool
 env_string_equal(const char *s1, const char *s2)
 {
src/openvpn/ssl.c +0 -10
index 45b20e56..460ef9e8 100644
@@ -2177,16 +2177,6 @@ read_string_alloc(struct buffer *buf)
     return str;
 }
 
-void
-read_string_discard(struct buffer *buf)
-{
-    char *data = read_string_alloc(buf);
-    if (data)
-    {
-        free(data);
-    }
-}
-
 /*
  * Handle the reading and writing of key data to and from
  * the TLS control channel (cleartext).
src/openvpn/ssl_openssl.c +0 -0
index 7ad6414e..fa06f068 100644
@@ -797,12 +797,6 @@ tls_ctx_load_cert_file(struct tls_root_ctx *ctx, const char *cert_file,
     tls_ctx_load_cert_file_and_copy(ctx, cert_file, cert_file_inline, NULL);
 }

src/openvpn/ssl_openssl.c tls_ctx_load_cert_file(struct tls_root_ctx *ctx, const char *cert_file, · line 802

Quoted 10 lines
src/openvpn/ssl_openssl.c +0 -6
 
-void
-tls_ctx_free_cert_file(X509 *x509)
-{
-    X509_free(x509);
-}
-
 int
 tls_ctx_load_priv_file(struct tls_root_ctx *ctx, const char *priv_key_file,
                        bool priv_key_file_inline)

Verified that these are indeed not used, and safe to remove. ACK.

-Steffan

#13 lore raw

Re: [Openvpn-devel] [PATCH applied] remove unused functions

In reply to Antonio Quartulli

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Your patch has been applied to the following branches

commit 4158f46f6474447520ebc7440050411eb8be8cb9 (master) commit e096613927ee814c8e4ecb1219cfe2ece9bf26bc (release/2.4)

Author: Antonio Quartulli
Date:   Fri Aug 11 17:07:43 2017 +0800
     remove unused functions

     Signed-off-by: Antonio Quartulli <[email protected]...>
     Acked-by: Steffan Karger <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg15205.html
     Signed-off-by: David Sommerseth <[email protected]...>

- --
kind regards,

David Sommerseth

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)

iQIcBAEBCgAGBQJZjg/1AAoJEIbPlEyWcf3yzugP+gP0wPkoOvnhvaPoetdmmjxP aOUnArkRg9LfivX2K4xXhK2Tv/Ay1sajxhojqESLY2PX0dkWCUbvGcPaGV+MGatB h25umgQl//T2+9C7cc3eecyC/BToVaHM4/liWuaq6Ebq0mqoC3Wuk9P3LuXAozo7 Mt4SD6YAo0LTHNjeWesK81840UU/1QFDaS4uIGpYbj16iJE7KkuJK+L750tReLbg 115+Kd8tixdIjTfZguC5GbKfTdY0kiEbBGRjQ39ObqCBSzjOn6JDZS1oEzKebQyh Lb2QlNEtpvNta/FBlTxqCnRkEjbDF6yJTTbt962CMpG2kEz+X9VNuMNGx3FdYq4l n0Nd3S0WvfQIM+Z5Q1GRq4xNlPj0NSubPLIVWGF6XuZGx8S+qHRPdZjyJeFEBeSD VDzoOL43DPR6ikgFvtaWSD/xrObYWY0VaTONR3vwfq37dbmP4QYdPSk3d7upVBPx 0H+VsoZCYbfJwifuFskrDCLrC+rZdU+XIZ2ZYj27PjSsrt6gYWa3updX0Ptdkgmh m1CkZgsN22dmxtOitKhKnqZeF015TcHkKK8oJ5EVTtwXkUswvXxyxfZzTjkuV7DL N1+TSmP/gjNdGjos7QD8WZq0d6VWfm/5qCJXtESilw9e5CBJSwBdFAsy1Z6GNJXW DOnmIcTtmWh7sBDAsQSI
=6A3v
-----END PGP SIGNATURE-----

#14 lore raw

PATCH 5/5 use NULL instead of 0 when assigning pointers

In reply to Antonio Quartulli

From: Antonio Quartulli <[email protected]...>

---
 src/openvpn/ps.c                 | 2 +-
 src/openvpn/ssl_openssl.c        | 2 +-
 src/openvpn/ssl_verify_openssl.c | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
src/openvpn/ps.c +1 -1
index 45e24ded..5136a20c 100644
@@ -922,7 +922,7 @@ port_share_open(const char *host,
         openvpn_close_socket(fd[1]);
 
         exit(0);
-        return 0; /* NOTREACHED */
+        return NULL; /* NOTREACHED */
     }
 
 error:
src/openvpn/ssl_openssl.c +1 -1
index fa06f068..c977b9e2 100644
@@ -703,7 +703,7 @@ tls_ctx_add_extra_certs(struct tls_root_ctx *ctx, BIO *bio)
     for (;; )
     {
         cert = NULL;
-        if (!PEM_read_bio_X509(bio, &cert, 0, NULL)) /* takes ownership of cert */
+        if (!PEM_read_bio_X509(bio, &cert, NULL, NULL)) /* takes ownership of cert */
         {
             break;
         }
src/openvpn/ssl_verify_openssl.c +2 -2
index ea474955..2f3b10b9 100644
@@ -202,8 +202,8 @@ extract_x509_field_ssl(X509_NAME *x509, const char *field_name, char *out,
 {
     int lastpos = -1;
     int tmp = -1;
-    X509_NAME_ENTRY *x509ne = 0;
-    ASN1_STRING *asn1 = 0;
+    X509_NAME_ENTRY *x509ne = NULL;
+    ASN1_STRING *asn1 = NULL;
     unsigned char *buf = NULL;
     ASN1_OBJECT *field_name_obj = OBJ_txt2obj(field_name, 0);
 
Signature · 1 line
2.14.0
#15 lore raw

Re: [Openvpn-devel] [PATCH 5/5] use NULL instead of 0 when assigning pointers

Quoted 14 lines · Antonio Quartulli

From: Antonio Quartulli <[email protected]...>

---
 src/openvpn/ps.c                 | 2 +-
 src/openvpn/ssl_openssl.c        | 2 +-
 src/openvpn/ssl_verify_openssl.c | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
src/openvpn/ps.c +0 -0
index 45e24ded..5136a20c 100644

src/openvpn/ps.c port_share_open(const char *host, · line 925

Quoted 5 lines
src/openvpn/ps.c +1 -1
@@ -922,7 +922,7 @@ port_share_open(const char *host,
         openvpn_close_socket(fd[1]);
 
         exit(0);
-        return 0; /* NOTREACHED */
+        return NULL; /* NOTREACHED */
     }
Quoted 24 lines
src/openvpn/ps.c +0 -0
 error:
src/openvpn/ssl_openssl.c +0 -1
index fa06f068..c977b9e2 100644
@@ -703,7 +703,7 @@ tls_ctx_add_extra_certs(struct tls_root_ctx *ctx, BIO
 *bio)
     for (;; )
     {
         cert = NULL;
-        if (!PEM_read_bio_X509(bio, &cert, 0, NULL)) /* takes ownership

of cert */
+ if (!PEM_read_bio_X509(bio, &cert, NULL, NULL)) /* takes
ownership of cert */

         {
             break;
         }
src/openvpn/ssl_verify_ renamed from src/openvpn/ssl_verify_openssl.c +0 -0

openssl.c
index ea474955..2f3b10b9 100644

src/openvpn/ssl_verify_openssl.c extract_x509_field_ssl(X509_NAME *x509, const char · line 208

Quoted 9 lines
src/openvpn/ssl_verify_openssl.c +2 -2
@@ -202,8 +202,8 @@ extract_x509_field_ssl(X509_NAME *x509, const char
 *field_name, char *out,
 {
     int lastpos = -1;
     int tmp = -1;
-    X509_NAME_ENTRY *x509ne = 0;
-    ASN1_STRING *asn1 = 0;
+    X509_NAME_ENTRY *x509ne = NULL;
+    ASN1_STRING *asn1 = NULL;
 

Constant 0 or (void *) 0 assigned to a pointer are the same as NULL pointer, so why bother?

int *a = 0; is perfectly valid in my view.

Of course,
int i = 0; int *a = i;
would be bad style and error-prone, and the compiler would warn, but not the use of literal 0.

Selva

#16 lore raw

Re: [Openvpn-devel] [PATCH 5/5] use NULL instead of 0 when assigning pointers

Hi,

Quoted 2 lines · Selva Nair

Constant 0 or (void *) 0 assigned to a pointer are the same as NULL pointer, so why bother?

Technically, it is (and NULL is quite often defined to be "(void *)0L" or the like).

Personally, I like using NULL - and seeing NULL being used - when in pointer context and "0" when in numeric context - it's more a visual thing.

Since we use NULL about everywhere else in OpenVPN, I think this change to get the few remaining places in line is a good thing. Thus, ACK :)

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#17 lore raw

Re: [Openvpn-devel] [PATCH applied] use NULL instead of 0 when assigning pointers

In reply to Antonio Quartulli

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Your patch has been applied to the following branches

commit 280150a02a117eb0cc9c34e69ebe9ec3f4ded0f4 (master) commit a5c2cb6046e7e23554b7bd71a52079b559129e0d (release/2.4)

Author: Antonio Quartulli
Date:   Fri Aug 11 17:07:44 2017 +0800
     use NULL instead of 0 when assigning pointers

     Signed-off-by: Antonio Quartulli <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg15204.html
     Signed-off-by: David Sommerseth <[email protected]...>

- --
kind regards,

David Sommerseth

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)

iQIcBAEBCgAGBQJZjg/+AAoJEIbPlEyWcf3yXZgQAMJeK4kkVnxAPzS0bR3FxPQ6 d/y1gMGbJV/tEkhx17gkJwwERhxI3/S7bwsQZlGt3HUQyUU/SGS0ffB8EazbPrNm +0+cHC583d5ZJojXJLVfTPOjWv1z1H2zBAPrgRU3lfh4gBb0EM//0SswcVlSgPpU XugIauevSg6NE1wITatlh2ukHmPQsyXQvkKCm5vHyCbNsH/cDG5R1PGlk+edZNJ5 4LP6COpYc0oqQbsydBUDuSHRs8noIzjt7c79XNWUhQNZD5ABctLwJbOqwSyuK5N8 YazMHJLYLj8VChmykxLV7rUONhmF+BsDWjWsy1zxq3IbOrCh2CmkorrVAPa90o6q y0jGEe+rSd5EgkZ1DdJ8l2WXLLlpOroBjUvx8bh53zXNr5go0IX1+AYevVagVANP 4eWRArZI9pwihRBRTyLKNl+TQwiMrzQeKJycjRaknhuT9MQqZBJcCREImBxur4Px 3cYfl8iDvndw5V1PROpiqCeQ+rKYbMGvnBkAVGWeJWFCLAmnzYx4mTkKKlEkNaPA jpWmL+AKRoKMZ/TMEeLsXut5qe7/uE9/SeJiF0ZHsr5RwkTzpNz+l1ylSG76PXdW GD4XCrY+ZM847Asp6HFMPFgLOw+H3Vw7vZItplmSg8RG58rV6jpl8VQqHpFrV8k0 UgwRh9HpgqYLQxfcm6Cu
=yQCv
-----END PGP SIGNATURE-----