Skip to contentSkip to conversation

Various clean up patches

PATCH In review Arne Schwabe 4 participants 39 messages Apr 1, 2021 – May 2, 2021

lore
Share & tools
lore
#0 lore raw

cover Various clean up patches

These are a number of patches that do various cleanups that I did as part of implementing DCO but are good on their own.

Arne Schwabe (14):
Remove code for aligning non-swapped compression Remove superflous ifdefs around enum like defines Rename tunnel_server_udp_single_threaded to tunnel_server_udp Add documentation on EVENT_READ/EVENT_WRITE constants Remove unused variable pass_config_info
Remove pointless tun_adjust_frame_parameters function Remove unused field txqueuelen from struct tuntap Remove unused function tls_test_auth_deferred_interval Move is_proto function to the socket.h header Remove thread_mode field of multi_context
Remove P2MP mode and check for gettimeofday
Extract multi_assign_peer_id into its own function log file descriptor in more socket related error messages Remove do_init_socket_2 and do_init_socket_1 wrapper function

 doc/doxygen/doc_eventloop.h      |   2 +-
 doc/doxygen/doc_tunnel_state.h   |   2 +-
 src/compat/compat-gettimeofday.c |   2 +-
 src/openvpn/comp.h               |   6 --
 src/openvpn/error.c              |   8 +-
 src/openvpn/event.c              |   8 +-
 src/openvpn/forward.c            |  26 +-----
 src/openvpn/forward.h            |   6 --
 src/openvpn/helper.c             |   3 -
 src/openvpn/init.c               | 122 +-------------------------
 src/openvpn/manage.c             |   4 -
 src/openvpn/mbuf.c               |   3 -
 src/openvpn/mbuf.h               |   3 -
 src/openvpn/mtcp.c               |   7 +-
 src/openvpn/mtu.h                |   6 --
 src/openvpn/mudp.c               |  45 +---------
 src/openvpn/mudp.h               |   7 +-
 src/openvpn/multi.c              |  95 +++++++++++---------
 src/openvpn/multi.h              |  20 +++--
 src/openvpn/openvpn.h            |  25 +++---
 src/openvpn/options.c            |  55 ++----------
 src/openvpn/options.h            |  49 ++++++-----
 src/openvpn/otime.c              |   4 -
 src/openvpn/pool.c               |   4 -
 src/openvpn/pool.h               |   3 -
 src/openvpn/push.c               |   3 -
 src/openvpn/push.h               |   3 -
 src/openvpn/pushlist.h           |   4 +-
 src/openvpn/route.h              |   2 -
 src/openvpn/shaper.c             |   5 +-
 src/openvpn/shaper.h             |   4 -
 src/openvpn/socket.c             | 145 ++++++++++---------------------
 src/openvpn/socket.h             |  90 +++++++++----------
 src/openvpn/ssl.h                |  11 ---
 src/openvpn/ssl_common.h         |   4 -
 src/openvpn/syshead.h            |  32 -------
 src/openvpn/tun.h                |  13 ---
 37 files changed, 234 insertions(+), 597 deletions(-)
Signature · 1 line
2.30.1
#1 lore raw

PATCH 1/14 Remove code for aligning non-swapped compression

This is an optimisation for memory alignment for lzo. Compression is deprecated so this optimisation is not very important anymore.

Furthermore it is conditionally compiled on !defined(ENABLE_LZ4), which makes the code not compiled in by default anyway.

---
 src/openvpn/comp.h |  6 ------
 src/openvpn/init.c | 31 -------------------------------
 src/openvpn/mtu.h  |  6 ------
 3 files changed, 43 deletions(-)
src/openvpn/comp.h +0 -6
index 5c0322ca6..5c9d77fe1 100644
@@ -198,11 +198,5 @@ comp_non_stub_enabled(const struct compress_options *info)
            && info->alg != COMP_ALG_UNDEF;
 }
 
-static inline bool
-comp_unswapped_prefix(const struct compress_options *info)
-{
-    return !(info->flags & COMP_F_SWAP);
-}
-
 #endif /* USE_COMP */
 #endif /* ifndef OPENVPN_COMP_H */
src/openvpn/init.c +0 -31
index 132d47e4e..1a6015452 100644
@@ -3082,37 +3082,6 @@ do_init_frame(struct context *c)
     {
         comp_add_to_extra_frame(&c->c2.frame);
 
-#if !defined(ENABLE_LZ4)
-        /*
-         * Compression usage affects buffer alignment when non-swapped algs
-         * such as LZO is used.
-         * Newer algs like LZ4 and comp-stub with COMP_F_SWAP don't need
-         * any special alignment because of the control-byte swap approach.
-         * LZO alignment (on the other hand) is problematic because
-         * the presence of the control byte means that either the output of
-         * decryption must be written to an unaligned buffer, or the input
-         * to compression (or packet dispatch if packet is uncompressed)
-         * must be read from an unaligned buffer.
-         * This code tries to align the input to compression (or packet
-         * dispatch if packet is uncompressed) at the cost of requiring
-         * decryption output to be written to an unaligned buffer, so
-         * it's more of a tradeoff than an optimal solution and we don't
-         * include it when we are doing a modern build with LZ4.
-         * Strictly speaking, on the server it would be better to execute
-         * this code for every connection after we decide the compression
-         * method, but currently the frame code doesn't appear to be
-         * flexible enough for this, since the frame is already established
-         * before it is known which compression options will be pushed.
-         */
-        if (comp_unswapped_prefix(&c->options.comp) && CIPHER_ENABLED(c))
-        {
-            frame_add_to_align_adjust(&c->c2.frame, COMP_PREFIX_LEN);
-            frame_or_align_flags(&c->c2.frame,
-                                 FRAME_HEADROOM_MARKER_FRAGMENT
-                                 |FRAME_HEADROOM_MARKER_DECRYPT);
-        }
-#endif
-
 #ifdef ENABLE_FRAGMENT
         comp_add_to_extra_frame(&c->c2.frame_fragment_omit); /* omit compression frame delta from final frame_fragment */
 #endif
src/openvpn/mtu.h +0 -6
index 0c8bdf8ba..92cbe1874 100644
@@ -300,12 +300,6 @@ frame_add_to_extra_buffer(struct frame *frame, const int increment)
     frame->extra_buffer += increment;
 }
 
-static inline void
-frame_add_to_align_adjust(struct frame *frame, const int increment)
-{
-    frame->align_adjust += increment;
-}
-
 static inline void
 frame_align_to_extra_frame(struct frame *frame)
 {
Signature · 1 line
2.30.1
#3 lore raw

PATCH 2/14 Remove superflous ifdefs around enum like defines

In reply to Arne Schwabe

The variables are not used without the configured options but the ifdef around them does not help readibility either.

---
 src/openvpn/mtcp.c    | 5 -----
 src/openvpn/mudp.c    | 2 --
 src/openvpn/openvpn.h | 4 ----
 3 files changed, 11 deletions(-)
src/openvpn/mtcp.c +0 -5
index 22c824aaa..7d2a69b99 100644
@@ -59,13 +59,8 @@
 #define MTCP_SOCKET      ((void *)1)
 #define MTCP_TUN         ((void *)2)
 #define MTCP_SIG         ((void *)3) /* Only on Windows */
-#ifdef ENABLE_MANAGEMENT
 #define MTCP_MANAGEMENT ((void *)4)
-#endif
-
-#ifdef ENABLE_ASYNC_PUSH
 #define MTCP_FILE_CLOSE_WRITE ((void *)5)
-#endif
 
 #define MTCP_N           ((void *)16) /* upper bound on MTCP_x */
 
src/openvpn/mudp.c +0 -2
index e95a7ac81..5af1081fc 100644
@@ -195,12 +195,10 @@ multi_process_io_udp(struct multi_context *m)
     {
         strcat(buf, "TW/");
     }
-#ifdef ENABLE_ASYNC_PUSH
     else if (status & FILE_CLOSED)
     {
         strcat(buf, "FC/");
     }
-#endif
     printf("IO %s\n", buf);
 #endif /* ifdef MULTI_DEBUG_EVENT_LOOP */
 
src/openvpn/openvpn.h +0 -4
index 3cef26381..1063351d3 100644
@@ -252,13 +252,9 @@ struct context_2
 #define TUN_WRITE         (1<<3)
 #define ES_ERROR          (1<<4)
 #define ES_TIMEOUT        (1<<5)
-#ifdef ENABLE_MANAGEMENT
 #define MANAGEMENT_READ  (1<<6)
 #define MANAGEMENT_WRITE (1<<7)
-#endif
-#ifdef ENABLE_ASYNC_PUSH
 #define FILE_CLOSED       (1<<8)
-#endif
 
     unsigned int event_set_status;
 
Signature · 1 line
2.30.1
#5 lore raw

PATCH 3/14 Rename tunnel_server_udp_single_threaded to tunnel_server_udp

In reply to Arne Schwabe

This also eliminates the confusing name and eliminates tunnel_server_udp as wrapper that only calls tunnel_server_udp_single_threaded

---
 doc/doxygen/doc_eventloop.h    |  2 +-
 doc/doxygen/doc_tunnel_state.h |  2 +-
 src/openvpn/mudp.c             | 21 ++-------------------
 src/openvpn/mudp.h             |  7 +++----
 src/openvpn/openvpn.h          |  2 +-
 5 files changed, 8 insertions(+), 26 deletions(-)
doc/doxygen/doc_eventloop.h +1 -1
index 8bd26355e..e9f7ea6f4 100644
@@ -61,6 +61,6 @@
  * event loop function is called to drive the event processing.  The
  * following implementations are available:
  * - Client mode using UDP or TCP: \c tunnel_point_to_point()
- * - Server mode using UDP: \c tunnel_server_udp_single_threaded()
+ * - Server mode using UDP: \c tunnel_server_udp()
  * - Server mode using TCP: \c tunnel_server_tcp()
  */
doc/doxygen/doc_tunnel_state.h +1 -1
index 46e750fda..104df2e91 100644
@@ -118,7 +118,7 @@
  * tunnel_point_to_point() or \c tunnel_server().
  *
  * In server-mode, \c main() calls the \c tunnel_server() function, which
- * transfers control to \c tunnel_server_udp_single_threaded() or \c
+ * transfers control to \c tunnel_server_udp() or \c
  * tunnel_server_tcp() depending on the external transport protocol.
  *
  * These functions receive the \c context created in \c main().  This
src/openvpn/mudp.c +2 -19
index 5af1081fc..7977ece5d 100644
@@ -284,19 +284,8 @@ p2mp_iow_flags(const struct multi_context *m)
 }
 
 
-/**************************************************************************/
-/**
- * Main event loop for OpenVPN in UDP server mode.
- * @ingroup eventloop
- *
- * This function implements OpenVPN's main event loop for UDP server mode.
- *  At this time, OpenVPN does not yet support multithreading.  This
- * function's name is therefore slightly misleading.
- *
- * @param top - Top-level context structure.
- */
-static void
-tunnel_server_udp_single_threaded(struct context *top)
+void
+tunnel_server_udp(struct context *top)
 {
     struct multi_context multi;
 
@@ -374,9 +363,3 @@ tunnel_server_udp_single_threaded(struct context *top)
     close_instance(top);
 }
 
-void
-tunnel_server_udp(struct context *top)
-{
-    tunnel_server_udp_single_threaded(top);
-}
-
src/openvpn/mudp.h +3 -4
index 460a768b3..340381e08 100644
@@ -32,14 +32,13 @@ struct context;
 struct multi_context;
 
 
-/**************************************************************************/
 /**
- * Main event loop wrapper function for OpenVPN in UDP server mode.
+ * Main event loop for OpenVPN in UDP server mode.
  * @ingroup eventloop
  *
- * This function simply calls \c tunnel_server_udp_single_threaded().
+ * This function implements OpenVPN's main event loop for UDP server mode.
  *
- * @param top          - Top-level context structure.
+ * @param top - Top-level context structure.
  */
 void tunnel_server_udp(struct context *top);
 
src/openvpn/openvpn.h +1 -1
index 1063351d3..0ddaeb730 100644
@@ -230,7 +230,7 @@ is_cas_pending(enum client_connect_status cas)
  * \c SIGUSR1 restarts.
  *
  * This structure is initialized at the top of the \c
- * tunnel_point_to_point(), \c tunnel_server_udp_single_threaded(), and \c
+ * tunnel_point_to_point(), \c tunnel_server_udp(), and \c
  * tunnel_server_tcp() functions.  In other words, it is reset for every
  * iteration of the \c main() function's inner \c SIGUSR1 loop.
  */
Signature · 1 line
2.30.1
#7 lore raw

PATCH 4/14 Add documentation on EVENT_READ/EVENT_WRITE constants

In reply to Arne Schwabe
---
 src/openvpn/forward.c |  3 ++-
 src/openvpn/openvpn.h | 12 +++++++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)
src/openvpn/forward.c +2 -1
index 6f7a50048..98caf6651 100644
@@ -1880,7 +1880,8 @@ io_wait_dowork(struct context *c, const unsigned int flags)
     unsigned int tuntap = 0;
     struct event_set_return esr[4];
 
-    /* These shifts all depend on EVENT_READ and EVENT_WRITE */
+    /* These shifts all depend on EVENT_READ (=1) and EVENT_WRITE (=2) */
+    /* and are added to the shift. */
     static int socket_shift = 0;   /* depends on SOCKET_READ and SOCKET_WRITE */
     static int tun_shift = 2;      /* depends on TUN_READ and TUN_WRITE */
     static int err_shift = 4;      /* depends on ES_ERROR */
src/openvpn/openvpn.h +11 -1
index 0ddaeb730..322ab3ee1 100644
@@ -245,7 +245,17 @@ struct context_2
     int event_set_max;
     bool event_set_owned;
 
-    /* event flags returned by io_wait */
+    /* event flags returned by io_wait,
+     * All these event are their respective shift as defined in io_wait_dowork
+     * adding a shift of 0 for the READ event and 1 for the write event.
+     *
+     * E.g. management_shift = 6;
+     * MANAGMENT_READ = (1<<(6+0)),
+     * MANAGEMNET_WRITE = (1<<(6+1))
+     *
+     * Some shifts (error, file_close) are using read/write for diferent
+     * signals.
+     */
 #define SOCKET_READ       (1<<0)
 #define SOCKET_WRITE      (1<<1)
 #define TUN_READ          (1<<2)
Signature · 1 line
2.30.1
#17 lore raw

PATCH 5/14 Remove unused variable pass_config_info

In reply to Arne Schwabe
---
 src/openvpn/ssl_common.h | 4 ----
 1 file changed, 4 deletions(-)
src/openvpn/ssl_common.h +0 -4
index 4e1ff6c84..18bce403a 100644
@@ -293,10 +293,6 @@ struct tls_options
     char *x509_username_field[2];
 #endif
 
-    /* allow openvpn config info to be
-     * passed over control channel */
-    bool pass_config_info;
-
     /* struct crypto_option flags */
     unsigned int crypto_flags;
 
Signature · 1 line
2.30.1
#19 lore raw

PATCH 6/14 Remove pointless tun_adjust_frame_parameters function

In reply to Arne Schwabe

This functions seem to serve no purpose other than to add confusion.

---
 src/openvpn/init.c |  2 +-
 src/openvpn/tun.h  | 10 ----------
 2 files changed, 1 insertion(+), 11 deletions(-)
src/openvpn/init.c +1 -1
index 1a6015452..f0ae0b7f1 100644
@@ -3101,7 +3101,7 @@ do_init_frame(struct context *c)
      */
     if (c->options.ce.tun_mtu_extra_defined)
     {
-        tun_adjust_frame_parameters(&c->c2.frame, c->options.ce.tun_mtu_extra);
+        frame_add_to_extra_tun(&c->c2.frame, c->options.ce.tun_mtu_extra);
     }
 
     /*
src/openvpn/tun.h +0 -10
index 902665cc6..7e8fb7647 100644
@@ -315,16 +315,6 @@ void check_subnet_conflict(const in_addr_t ip,
 
 void warn_on_use_of_common_subnets(openvpn_net_ctx_t *ctx);
 
-/*
- * Inline functions
- */
-
-static inline void
-tun_adjust_frame_parameters(struct frame *frame, int size)
-{
-    frame_add_to_extra_tun(frame, size);
-}
-
 /*
  * Should ifconfig be called before or after
  * tun dev open?
Signature · 1 line
2.30.1
#21 lore raw

PATCH 7/14 Remove unused field txqueuelen from struct tuntap

In reply to Arne Schwabe

The code uses tuntap->options.txqueuelen instead.

---
 src/openvpn/tun.h | 3 ---
 1 file changed, 3 deletions(-)
src/openvpn/tun.h +0 -3
index 7e8fb7647..60ebfdcba 100644
@@ -165,9 +165,6 @@ struct tuntap
 
     char *actual_name; /* actual name of TUN/TAP dev, usually including unit number */
 
-    /* number of TX buffers */
-    int txqueuelen;
-
     /* ifconfig parameters */
     in_addr_t local;
     in_addr_t remote_netmask;
Signature · 1 line
2.30.1
#23 lore raw

PATCH 8/14 Remove unused function tls_test_auth_deferred_interval

In reply to Arne Schwabe

This function appears to completely unused and has not been touched since 2008.

---
 src/openvpn/ssl.h | 11 -----------
 1 file changed, 11 deletions(-)
src/openvpn/ssl.h +0 -11
index 8c8cbe028..300a70d35 100644
@@ -530,17 +530,6 @@ tls_initial_packet_received(const struct tls_multi *multi)
     return multi->n_sessions > 0;
 }
 
-static inline bool
-tls_test_auth_deferred_interval(const struct tls_multi *multi)
-{
-    if (multi)
-    {
-        const struct key_state *ks = &multi->session[TM_ACTIVE].key[KS_PRIMARY];
-        return now < ks->auth_deferred_expire;
-    }
-    return false;
-}
-
 static inline int
 tls_test_payload_len(const struct tls_multi *multi)
 {
Signature · 1 line
2.30.1
#25 lore raw

PATCH 9/14 Move is_proto function to the socket.h header

In reply to Arne Schwabe

These functions are small enough to be inlined and also avoids dependency on socket.c from unit_tests using those functions.

---
 src/openvpn/socket.c | 36 -------------------------------
 src/openvpn/socket.h | 50 +++++++++++++++++++++++++++++++++-----------
 2 files changed, 38 insertions(+), 48 deletions(-)
src/openvpn/socket.c +0 -36
index 0d9b793cd..6fed4b660 100644
@@ -3101,42 +3101,6 @@ static const struct proto_names proto_names[] = {
     {"tcp6",        "TCPv6", AF_INET6, PROTO_TCP},
 };
 
-bool
-proto_is_net(int proto)
-{
-    if (proto < 0 || proto >= PROTO_N)
-    {
-        ASSERT(0);
-    }
-    return proto != PROTO_NONE;
-}
-
-bool
-proto_is_dgram(int proto)
-{
-    return proto_is_udp(proto);
-}
-
-bool
-proto_is_udp(int proto)
-{
-    if (proto < 0 || proto >= PROTO_N)
-    {
-        ASSERT(0);
-    }
-    return proto == PROTO_UDP;
-}
-
-bool
-proto_is_tcp(int proto)
-{
-    if (proto < 0 || proto >= PROTO_N)
-    {
-        ASSERT(0);
-    }
-    return proto == PROTO_TCP_CLIENT || proto == PROTO_TCP_SERVER;
-}
-
 int
 ascii2proto(const char *proto_name)
 {
src/openvpn/socket.h +38 -12

62 lines not on this page · raw message

Signature · 1 line
2.30.1
#27 lore raw

PATCH 10/14 Remove thread_mode field of multi_context

In reply to Arne Schwabe

This is leftover of a never functional multi threaded openvpn implementation attempt. It serves no purposes anymore.

---
 src/openvpn/mtcp.c  |  2 +-
 src/openvpn/mudp.c  |  2 +-
 src/openvpn/multi.c | 67 +++++++++++++++++++--------------------------
 src/openvpn/multi.h | 10 +------
 4 files changed, 31 insertions(+), 50 deletions(-)
src/openvpn/mtcp.c +1 -1
index 7d2a69b99..babed29ef 100644
@@ -789,7 +789,7 @@ tunnel_server_tcp(struct context *top)
     }
 
     /* initialize global multi_context object */
-    multi_init(&multi, top, true, MC_SINGLE_THREADED);
+    multi_init(&multi, top, true);
 
     /* initialize our cloned top object */
     multi_top_init(&multi, top);
src/openvpn/mudp.c +1 -1
index 7977ece5d..90e32a8ec 100644
@@ -300,7 +300,7 @@ tunnel_server_udp(struct context *top)
     }
 
     /* initialize global multi_context object */
-    multi_init(&multi, top, false, MC_SINGLE_THREADED);
+    multi_init(&multi, top, false);
 
     /* initialize our cloned top object */
     multi_top_init(&multi, top);
src/openvpn/multi.c +28 -39

96 lines not on this page · raw message

src/openvpn/multi.h +1 -9
index 7669508c3..b7078b711 100644
@@ -150,14 +150,6 @@ struct multi_instance {
  * server-mode.
  */
 struct multi_context {
-#define MC_UNDEF                      0
-#define MC_SINGLE_THREADED            (1<<0)
-#define MC_MULTI_THREADED_MASTER      (1<<1)
-#define MC_MULTI_THREADED_WORKER      (1<<2)
-#define MC_MULTI_THREADED_SCHEDULER   (1<<3)
-#define MC_WORK_THREAD                (MC_MULTI_THREADED_WORKER|MC_MULTI_THREADED_SCHEDULER)
-    int thread_mode;
-
     struct multi_instance **instances;  /**< Array of multi_instances. An instance can be
                                          * accessed using peer-id as an index. */
 
@@ -261,7 +253,7 @@ const char *multi_instance_string(const struct multi_instance *mi, bool null, st
  * Called by mtcp.c, mudp.c, or other (to be written) protocol drivers
  */
 
-void multi_init(struct multi_context *m, struct context *t, bool tcp_mode, int thread_mode);
+void multi_init(struct multi_context *m, struct context *t, bool tcp_mode);
 
 void multi_uninit(struct multi_context *m);
 
Signature · 1 line
2.30.1
#29 lore raw

PATCH 11/14 Remove P2MP mode and check for gettimeofday

In reply to Arne Schwabe

Using OpenVPN without P2MP support (pull, TLS) is unrealistic and building a binary without it is not something we realistically want to support anyway.

---
 src/compat/compat-gettimeofday.c |  2 +-
 src/openvpn/forward.c            | 23 ++-----------
 src/openvpn/forward.h            |  6 ----
 src/openvpn/helper.c             |  3 --
 src/openvpn/init.c               | 29 +----------------
 src/openvpn/manage.c             |  4 ---
 src/openvpn/mbuf.c               |  3 --
 src/openvpn/mbuf.h               |  3 --
 src/openvpn/multi.c              |  7 ++++
 src/openvpn/openvpn.h            |  7 ----
 src/openvpn/options.c            | 55 ++++----------------------------
 src/openvpn/options.h            | 49 ++++++++++++++++------------
 src/openvpn/otime.c              |  4 ---
 src/openvpn/pool.c               |  4 ---
 src/openvpn/pool.h               |  3 --
 src/openvpn/push.c               |  3 --
 src/openvpn/push.h               |  3 --
 src/openvpn/pushlist.h           |  4 +--
 src/openvpn/route.h              |  2 --
 src/openvpn/shaper.c             |  5 +--
 src/openvpn/shaper.h             |  4 ---
 src/openvpn/syshead.h            | 32 -------------------
 22 files changed, 49 insertions(+), 206 deletions(-)
src/compat/compat-gettimeofday.c +1 -1
index 117aee7d7..e63c8d7f8 100644
@@ -93,7 +93,7 @@ gettimeofday(struct timeval *tv, void *tz)
     {
         /* We try to dampen out backtracks of less than backtrack_hold_seconds.
          * Larger backtracks will be passed through and dealt with by the
-         * TIME_BACKTRACK_PROTECTION code (if enabled) */
+         * TIME_BACKTRACK_PROTECTION code */
         if (sec > last_sec - backtrack_hold_seconds)
         {
             sec = last_sec;
src/openvpn/forward.c +2 -21
index 98caf6651..01f3f3b9b 100644
@@ -189,8 +189,6 @@ check_tls_errors_nco(struct context *c)
     register_signal(c, c->c2.tls_exit_signal, "tls-error"); /* SOFT-SIGUSR1 -- TLS error */
 }
 
-#if P2MP
-
 /*
  * Handle incoming configuration
  * messages on the control channel.
@@ -269,8 +267,6 @@ check_push_request(struct context *c)
     event_timeout_modify_wakeup(&c->c2.push_request_interval, PUSH_REQUEST_INTERVAL);
 }
 
-#endif /* P2MP */
-
 /*
  * Things that need to happen immediately after connection initiation should go here.
  *
@@ -286,7 +282,6 @@ check_connection_established(struct context *c)
 
     if (CONNECTION_ESTABLISHED(c))
     {
-#if P2MP
         /* if --pull was specified, send a push request to server */
         if (c->c2.tls_multi && c->options.pull)
         {
@@ -313,7 +308,6 @@ check_connection_established(struct context *c)
             reset_coarse_timers(c);
         }
         else
-#endif /* if P2MP */
         {
             do_up(c, false, 0);
         }
@@ -428,7 +422,6 @@ get_server_poll_remaining_time(struct event_timeout *server_poll_timeout)
     int remaining = event_timeout_remaining(server_poll_timeout);
     return max_int(0, remaining);
 }
-#if P2MP
 
 void
 check_server_poll_timeout(struct context *c)
@@ -466,8 +459,6 @@ check_scheduled_exit(struct context *c)
     register_signal(c, c->c2.scheduled_exit_signal, "delayed-exit");
 }
 
-#endif /* if P2MP */
-
 /*
  * Should we write timer-triggered status file.
  */
@@ -635,13 +626,12 @@ process_coarse_timers(struct context *c)
     {
         check_connection_established(c);
     }
-#if P2MP
+
     /* see if we should send a push_request (option --pull) */
     if (event_timeout_trigger(&c->c2.push_request_interval, &c->c2.timeval, ETT_DEFAULT))
     {
         check_push_request(c);
     }
-#endif
 
 #ifdef PLUGIN_PF
     if (c->c2.pf.enabled
@@ -676,7 +666,6 @@ process_coarse_timers(struct context *c)
         return;
     }
 
-#if P2MP
     if (c->c2.tls_multi)
     {
         if (c->options.ce.connect_timeout
@@ -697,7 +686,6 @@ process_coarse_timers(struct context *c)
             return;
         }
     }
-#endif
 
     /* Should we send an OCC_REQUEST message? */
     check_send_occ_req(c);
@@ -1583,13 +1571,12 @@ process_outgoing_link(struct context *c)
              * Let the traffic shaper know how many bytes
              * we wrote.
              */
-#ifdef ENABLE_FEATURE_SHAPER
             if (c->options.shaper)
             {
                 shaper_wrote_bytes(&c->c2.shaper, BLEN(&c->c2.to_link)
                                    + datagram_overhead(c->options.ce.proto));
             }
-#endif
+
             /*
              * Let the pinger know that we sent a packet.
              */
@@ -1843,14 +1830,12 @@ pre_select(struct context *c)
         return;
     }
 
-#if P2MP
     /* check for incoming control messages on the control channel like
      * push request/reply, or authentication failure and 2FA messages */
     if (tls_test_payload_len(c->c2.tls_multi) > 0)
     {
         check_incoming_control_channel(c);
     }
-#endif
 
     /* Should we send an OCC message? */
     check_send_occ_msg(c);
@@ -1920,7 +1905,6 @@ io_wait_dowork(struct context *c, const unsigned int flags)
              * quota, don't send -- instead compute the delay we must wait
              * until it will be OK to send the packet.
              */
-#ifdef ENABLE_FEATURE_SHAPER
             int delay = 0;
 
             /* set traffic shaping delay in microseconds */
@@ -1937,9 +1921,6 @@ io_wait_dowork(struct context *c, const unsigned int flags)
             {
                 shaper_soonest_event(&c->c2.timeval, delay);
             }
-#else /* ENABLE_FEATURE_SHAPER */
-            socket |= EVENT_WRITE;
-#endif /* ENABLE_FEATURE_SHAPER */
         }
         else
         {
src/openvpn/forward.h +0 -6
index 9ce3bc1c7..2a67c1445 100644
@@ -74,15 +74,12 @@ void check_tls_errors_co(struct context *c);
 
 void check_tls_errors_nco(struct context *c);
 
-#if P2MP
 void check_incoming_control_channel(struct context *c);
 
 void check_scheduled_exit(struct context *c);
 
 void check_push_request(struct context *c);
 
-#endif /* P2MP */
-
 #ifdef ENABLE_FRAGMENT
 void check_fragment(struct context *c);
 
@@ -336,11 +333,8 @@ void reschedule_multi_process(struct context *c);
 
 void process_ip_header(struct context *c, unsigned int flags, struct buffer *buf);
 
-#if P2MP
 void schedule_exit(struct context *c, const int n_seconds, const int signal);
 
-#endif
-
 static inline struct link_socket_info *
 get_link_socket_info(struct context *c)
 {
src/openvpn/helper.c +0 -3
index a1d030706..963578d43 100644
@@ -149,7 +149,6 @@ helper_client_server(struct options *o)
 {
     struct gc_arena gc = gc_new();
 
-#if P2MP
 
 /*
  * Get tun/tap/null device type
@@ -494,8 +493,6 @@ helper_client_server(struct options *o)
         o->tls_client = true;
     }
 
-#endif /* P2MP */
-
     gc_free(&gc);
 }
 
src/openvpn/init.c +1 -28
index f0ae0b7f1..98cc1ebe9 100644
@@ -192,7 +192,6 @@ run_up_down(const char *command,
 static void
 update_options_ce_post(struct options *options)
 {
-#if P2MP
     /*
      * In pull mode, we usually import --ping/--ping-restart parameters from
      * the server.  However we should also set an initial default --ping-restart
@@ -206,7 +205,6 @@ update_options_ce_post(struct options *options)
         options->ping_rec_timeout = PRE_PULL_INITIAL_PING_RESTART;
         options->ping_rec_timeout_action = PING_RESTART;
     }
-#endif
 }
 
 #ifdef ENABLE_MANAGEMENT
@@ -592,7 +590,6 @@ init_query_passwords(const struct context *c)
         pem_password_setup(c->options.key_pass_file);
     }
 
-#if P2MP
     /* Auth user/pass input */
     if (c->options.auth_user_pass_file)
     {
@@ -602,7 +599,6 @@ init_query_passwords(const struct context *c)
         auth_user_pass_setup(c->options.auth_user_pass_file, NULL);
 #endif
     }
-#endif
 }
 
 /*
@@ -1446,14 +1442,12 @@ do_init_timers(struct context *c, bool deferred)
 static void
 do_init_traffic_shaper(struct context *c)
 {
-#ifdef ENABLE_FEATURE_SHAPER
     /* initialize traffic shaper (i.e. transmit bandwidth limiter) */
     if (c->options.shaper)
     {
         shaper_init(&c->c2.shaper, c->options.shaper);
         shaper_msg(&c->c2.shaper);
     }
-#endif
 }
 
 /*
@@ -1978,9 +1972,7 @@ do_close_tun_simple(struct context *c)
         c->c1.tuntap = NULL;
     }
     c->c1.tuntap_owned = false;
-#if P2MP
     CLEAR(c->c1.pulled_options_digest_save);
-#endif
 }
 
 static void
@@ -2131,7 +2123,6 @@ tun_abort(void)
  * Handle delayed tun/tap interface bringup due to --up-delay or --pull
  */
 
-#if P2MP
 /**
  * Helper for do_up().  Take two option hashes and return true if they are not
  * equal, or either one is all-zeroes.
@@ -2144,7 +2135,6 @@ options_hash_changed_or_zero(const struct sha256_digest *a,
     return memcmp(a, b, sizeof(struct sha256_digest))
            || !memcmp(a, &zero, sizeof(struct sha256_digest));
 }
-#endif /* P2MP */
 
 bool
 do_up(struct context *c, bool pulled_options, unsigned int option_types_found)
@@ -2168,7 +2158,6 @@ do_up(struct context *c, bool pulled_options, unsigned int option_types_found)
             c->c2.did_open_tun = do_open_tun(c);
             update_time();
 
-#if P2MP
             /*
              * Was tun interface object persisted from previous restart iteration,
              * and if so did pulled options string change from previous iteration?
@@ -2186,14 +2175,11 @@ do_up(struct context *c, bool pulled_options, unsigned int option_types_found)
                 c->c2.did_open_tun = do_open_tun(c);
                 update_time();
             }
-#endif
         }
 
         if (c->c2.did_open_tun)
         {
-#if P2MP
             c->c1.pulled_options_digest_save = c->c2.pulled_options_digest;
-#endif
 
             /* if --route-delay was specified, start timer */
             if ((route_order() == ROUTE_AFTER_TUN) && c->options.route_delay_defined)
@@ -2360,6 +2346,7 @@ do_deferred_options(struct context *c, const unsigned int found)
     /* process (potentially pushed) crypto options */
     if (c->options.pull)
     {
+
         if (!check_pull_client_ncp(c, found))
         {
             return false;
@@ -2432,12 +2419,10 @@ socket_restart_pause(struct context *c)
     }
 #endif
 
-#if P2MP
     if (auth_retry_get() == AR_NOINTERACT)
     {
         sec = 10;
     }
-#endif
 
     /* Slow down reconnection after 5 retries per remote -- for tcp only in client mode */
     if (c->options.ce.proto != PROTO_TCP_SERVER)
@@ -2721,7 +2706,6 @@ do_init_crypto_tls_c1(struct context *c)
         init_ssl(options, &(c->c1.ks.ssl_ctx));
         if (!tls_ctx_initialised(&c->c1.ks.ssl_ctx))
         {
-#if P2MP
             switch (auth_retry_get())
             {
                 case AR_NONE:
@@ -2740,9 +2724,6 @@ do_init_crypto_tls_c1(struct context *c)
             }
             c->sig->signal_text = "private-key-password-failure";
             return;
-#else  /* if P2MP */
-            msg(M_FATAL, "Error: private key password verification failed");
-#endif /* if P2MP */
         }
 
         /* Do not warn if we only have BF-CBC in options->ciphername
@@ -2938,11 +2919,9 @@ do_init_crypto_tls(struct context *c, const unsigned int flags)
 
     to.x509_track = options->x509_track;
 
-#if P2MP
 #ifdef ENABLE_MANAGEMENT
     to.sci = &options->sc_info;
 #endif
-#endif
 
 #ifdef USE_COMP
     to.comp_options = options->comp;
@@ -3207,7 +3186,6 @@ do_option_warnings(struct context *c)
         msg(M_WARN, "WARNING: you are using chroot without specifying user and group -- this may cause the chroot jail to be insecure");
     }
 
-#if P2MP
     if (o->pull && o->ifconfig_local && c->first_time)
     {
         msg(M_WARN, "WARNING: using --pull/--client and --ifconfig together is probably not what you want");
@@ -3233,7 +3211,6 @@ do_option_warnings(struct context *c)
             msg(M_WARN, "WARNING: --keepalive option is missing from server config");
         }
     }
-#endif /* if P2MP */
 
     if (!o->replay)
     {
@@ -3771,13 +3748,11 @@ do_setup_fast_io(struct context *c)
         }
         else
         {
-#ifdef ENABLE_FEATURE_SHAPER
             if (c->options.shaper)
             {
                 msg(M_INFO, "NOTE: --fast-io is disabled since we are using --shaper");
             }
             else
-#endif
             {
                 c->c2.fast_io = true;
             }
@@ -4141,13 +4116,11 @@ init_instance(struct context *c, const struct env_set *env, const unsigned int f
         platform_mlockall(true);
     }
 
-#if P2MP
     /* get passwords if undefined */
     if (auth_retry_get() == AR_INTERACT)
     {
         init_query_passwords(c);
     }
-#endif
 
     /* initialize context level 2 --verb/--mute parms */
     init_verb_mute(c, IVM_LEVEL_2);
src/openvpn/manage.c +0 -4
index df987f53c..7e61061ab 100644
@@ -1416,7 +1416,6 @@ man_dispatch_command(struct management *man, struct status_output *so, const cha
     }
     else if (streq(p[0], "auth-retry"))
     {
-#if P2MP
         if (p[1])
         {
             if (auth_retry_set(M_CLIENT, p[1]))
@@ -1432,9 +1431,6 @@ man_dispatch_command(struct management *man, struct status_output *so, const cha
         {
             msg(M_CLIENT, "SUCCESS: auth-retry=%s", auth_retry_print());
         }
-#else  /* if P2MP */
-        msg(M_CLIENT, "ERROR: auth-retry feature is unavailable");
-#endif
     }
     else if (streq(p[0], "state"))
     {
src/openvpn/mbuf.c +0 -3
index 76f478b8c..6b7db6501 100644
@@ -29,8 +29,6 @@
 
 #include "syshead.h"
 
-#if P2MP
-
 #include "buffer.h"
 #include "error.h"
 #include "integer.h"
@@ -171,4 +169,3 @@ mbuf_dereference_instance(struct mbuf_set *ms, struct multi_instance *mi)
         }
     }
 }
-#endif /* P2MP */
src/openvpn/mbuf.h +0 -3
index f37563dff..759546c6c 100644
@@ -28,8 +28,6 @@
  * Handle both multicast and broadcast functions.
  */
 
-#if P2MP
-
 /* define this to enable special test mode */
 /*#define MBUF_TEST*/
 
@@ -111,5 +109,4 @@ mbuf_peek(struct mbuf_set *ms)
     }
 }
 
-#endif /* if P2MP */
 #endif /* ifndef MBUF_H */
src/openvpn/multi.c +7 -0
index 9b4a3383f..071bd5b61 100644
@@ -2642,6 +2642,13 @@ multi_connection_established(struct multi_context *m, struct multi_instance *mi)
 
         (*cur_handler_index)++;
     }
+    /* Check if we have forbidding options in the current mode */
+    if (dco_enabled( &mi->context.options)
+        && check_option_conflict_dco(D_MULTI_ERRORS, &mi->context.options))
+    {
+        msg(D_MULTI_ERRORS, "MULTI: client has been reject due to incompatible options");
+        cc_succeeded = false;
+    }
 
     if (cc_succeeded)
     {
src/openvpn/openvpn.h +0 -7
index 322ab3ee1..c30ffacb7 100644
@@ -189,7 +189,6 @@ struct context_1
     struct socks_proxy_info *socks_proxy;
     bool socks_proxy_owned;
 
-#if P2MP
     /* persist --ifconfig-pool db to file */
     struct ifconfig_pool_persist *ifconfig_pool_persist;
     bool ifconfig_pool_persist_owned;
@@ -203,7 +202,6 @@ struct context_1
     struct user_pass *auth_user_pass;
     /**< Username and password for
      *   authentication. */
-#endif
 };
 
 
@@ -288,12 +286,10 @@ struct context_2
     struct frame frame_fragment_omit;
 #endif
 
-#ifdef ENABLE_FEATURE_SHAPER
     /*
      * Traffic shaper object.
      */
     struct shaper shaper;
-#endif
 
     /*
      * Statistics
@@ -445,8 +441,6 @@ struct context_2
     /* don't wait for TUN/TAP/UDP to be ready to accept write */
     bool fast_io;
 
-#if P2MP
-
     /* --ifconfig endpoints to be pushed to client */
     bool push_request_received;
     bool push_ifconfig_defined;
@@ -473,7 +467,6 @@ struct context_2
 
     struct event_timeout scheduled_exit;
     int scheduled_exit_signal;
-#endif /* if P2MP */
 
     /* packet filter */
 #ifdef ENABLE_PF
src/openvpn/options.c +7 -48

221 lines not on this page · raw message

src/openvpn/options.h +28 -21

111 lines not on this page · raw message

src/openvpn/otime.c +0 -4
index 640168a97..a3ca3e59d 100644
@@ -35,8 +35,6 @@
 
 time_t now = 0;            /* GLOBAL */
 
-#if TIME_BACKTRACK_PROTECTION
-
 static time_t now_adj = 0; /* GLOBAL */
 time_t now_usec = 0;       /* GLOBAL */
 
@@ -79,8 +77,6 @@ update_now_usec(struct timeval *tv)
     }
 }
 
-#endif /* TIME_BACKTRACK_PROTECTION */
-
 /*
  * Return a numerical string describing a struct timeval.
  */
src/openvpn/pool.c +0 -4
index ece0784ff..4a300abbc 100644
@@ -37,8 +37,6 @@
 
 #include "memdbg.h"
 
-#if P2MP
-
 static void
 ifconfig_pool_entry_free(struct ifconfig_pool_entry *ipe, bool hard)
 {
@@ -835,5 +833,3 @@ ifconfig_pool_test(in_addr_t start, in_addr_t end)
 }
 
 #endif /* ifdef IFCONFIG_POOL_TEST */
-
-#endif /* if P2MP */
src/openvpn/pool.h +0 -3
index b06424c95..0e3055969 100644
@@ -24,8 +24,6 @@
 #ifndef POOL_H
 #define POOL_H
 
-#if P2MP
-
 /*#define IFCONFIG_POOL_TEST*/
 
 #include "basic.h"
@@ -102,5 +100,4 @@ void ifconfig_pool_test(in_addr_t start, in_addr_t end);
 
 #endif
 
-#endif /* if P2MP */
 #endif /* ifndef POOL_H */
src/openvpn/push.c +0 -3
index 18d7c1e00..47a67e503 100644
@@ -39,8 +39,6 @@
 #include "memdbg.h"
 #include "ssl_util.h"
 
-#if P2MP
-
 static char push_reply_cmd[] = "PUSH_REPLY";
 
 /*
@@ -1053,4 +1051,3 @@ remove_iroutes_from_push_route_list(struct options *o)
         gc_free(&gc);
     }
 }
-#endif /* if P2MP */
src/openvpn/push.h +0 -3
index bb787a62a..b6388fcd7 100644
@@ -24,8 +24,6 @@
 #ifndef PUSH_H
 #define PUSH_H
 
-#if P2MP
-
 #include "forward.h"
 
 #define PUSH_MSG_ERROR            0
@@ -100,5 +98,4 @@ void send_push_reply_auth_token(struct tls_multi *multi);
 void
 receive_auth_pending(struct context *c, const struct buffer *buffer);
 
-#endif /* if P2MP */
 #endif /* ifndef PUSH_H */
src/openvpn/pushlist.h +2 -2
index 967eda22a..6e682684d 100644
@@ -21,7 +21,7 @@
  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#if !defined(PUSHLIST_H) && P2MP
+#if !defined(PUSHLIST_H)
 #define PUSHLIST_H
 
 /* parameters to be pushed to peer */
@@ -37,4 +37,4 @@ struct push_list {
     struct push_entry *tail;
 };
 
-#endif /* if !defined(PUSHLIST_H) && P2MP */
+#endif /* if !defined(PUSHLIST_H) */
src/openvpn/route.h +0 -2
index 7dd960914..935e14713 100644
@@ -230,7 +230,6 @@ struct route_ipv6_list {
     struct gc_arena gc;
 };
 
-#if P2MP
 /* internal OpenVPN route */
 struct iroute {
     in_addr_t network;
@@ -243,7 +242,6 @@ struct iroute_ipv6 {
     unsigned int netbits;
     struct iroute_ipv6 *next;
 };
-#endif
 
 struct route_option_list *new_route_option_list(struct gc_arena *a);
 
src/openvpn/shaper.c +1 -4
index 57a242416..d29b3b3ae 100644
@@ -31,8 +31,6 @@
 #include "shaper.h"
 #include "memdbg.h"
 
-#ifdef ENABLE_FEATURE_SHAPER
-
 /*
  * We want to wake up in delay microseconds.  If timeval is larger
  * than delay, set timeval to delay.
@@ -93,5 +91,4 @@ shaper_msg(struct shaper *s)
 {
     msg(M_INFO, "Output Traffic Shaping initialized at %d bytes per second",
         s->bytes_per_second);
-}
-#endif /* ENABLE_FEATURE_SHAPER */
+}
\ No newline at end of file
src/openvpn/shaper.h +0 -4
index bcdb5e365..d9b9daf57 100644
@@ -26,8 +26,6 @@
 
 /*#define SHAPER_DEBUG*/
 
-#ifdef ENABLE_FEATURE_SHAPER
-
 #include "basic.h"
 #include "integer.h"
 #include "misc.h"
@@ -173,6 +171,4 @@ shaper_change_pct(struct shaper *s, int pct)
 }
 #endif
 
-#endif /* ENABLE_FEATURE_SHAPER */
-
 #endif /* ifndef SHAPER_H */
src/openvpn/syshead.h +0 -32
index cf9714593..de4fbbf94 100644
@@ -405,13 +405,6 @@ typedef int MIB_TCP_STATE;
 #define PASSTOS_CAPABILITY 0
 #endif
 
-/*
- * Do we have nanoseconds gettimeofday?
- */
-#if defined(HAVE_GETTIMEOFDAY) || defined(_WIN32)
-#define HAVE_GETTIMEOFDAY_NANOSECONDS 1
-#endif
-
 /*
  * Do we have the capability to report extended socket errors?
  */
@@ -509,16 +502,6 @@ socket_defined(const socket_descriptor_t sd)
 #define ENABLE_FEATURE_EXECVE
 #endif
 
-/*
- * Do we have point-to-multipoint capability?
- */
-
-#if defined(HAVE_GETTIMEOFDAY_NANOSECONDS)
-#define P2MP 1
-#else
-#define P2MP 0
-#endif
-
 /*
  * HTTPS port sharing capability
  */
@@ -596,21 +579,6 @@ socket_defined(const socket_descriptor_t sd)
 #define EPOLL 0
 #endif
 
-/*
- * Reduce sensitivity to system clock instability
- * and backtracks.
- */
-#if defined(HAVE_GETTIMEOFDAY_NANOSECONDS)
-#define TIME_BACKTRACK_PROTECTION 1
-#endif
-
-/*
- * Enable traffic shaper.
- */
-#if defined(HAVE_GETTIMEOFDAY_NANOSECONDS)
-#define ENABLE_FEATURE_SHAPER 1
-#endif
-
 /*
  * Is non-blocking connect() supported?
  */
Signature · 1 line
2.30.1
#33 lore raw

PATCH 12/14 Extract multi_assign_peer_id into its own function

In reply to Arne Schwabe

This makes multi_get_create_instance_udp a bit shorter and better structured and also prepares this method to be called from the mutlti TCP context with DCO which will also need to assign unique peer ids to instances.

---
 src/openvpn/mudp.c  | 20 +-------------------
 src/openvpn/multi.c | 21 +++++++++++++++++++++
 src/openvpn/multi.h | 10 ++++++++++
 3 files changed, 32 insertions(+), 19 deletions(-)
src/openvpn/mudp.c +1 -19
index 90e32a8ec..9225d42de 100644
@@ -103,27 +103,9 @@ multi_get_create_instance_udp(struct multi_context *m, bool *floated)
                     mi = multi_create_instance(m, &real);
                     if (mi)
                     {
-                        int i;
-
                         hash_add_fast(hash, bucket, &mi->real, hv, mi);
                         mi->did_real_hash = true;
-
-                        /* max_clients must be less then max peer-id value */
-                        ASSERT(m->max_clients < MAX_PEER_ID);
-
-                        for (i = 0; i < m->max_clients; ++i)
-                        {
-                            if (!m->instances[i])
-                            {
-                                mi->context.c2.tls_multi->peer_id = i;
-                                m->instances[i] = mi;
-                                break;
-                            }
-                        }
-
-                        /* should not really end up here, since multi_create_instance returns null
-                         * if amount of clients exceeds max_clients */
-                        ASSERT(i < m->max_clients);
+                        multi_assign_peer_id(m, mi);
                     }
                 }
                 else
src/openvpn/multi.c +21 -0
index 071bd5b61..d4c5304cb 100644
@@ -4016,6 +4016,27 @@ init_management_callback_multi(struct multi_context *m)
 #endif /* ifdef ENABLE_MANAGEMENT */
 }
 
+void multi_assign_peer_id(struct multi_context *m, struct multi_instance *mi)
+{
+    /* max_clients must be less then max peer-id value */
+    ASSERT(m->max_clients < MAX_PEER_ID);
+
+    for (int i = 0; i < m->max_clients; ++i)
+    {
+        if (!m->instances[i])
+        {
+            mi->context.c2.tls_multi->peer_id = i;
+            m->instances[i] = mi;
+            break;
+        }
+    }
+
+    /* should not really end up here, since multi_create_instance returns null
+     * if amount of clients exceeds max_clients */
+    ASSERT(mi->context.c2.tls_multi->peer_id < m->max_clients);
+}
+
+
 /*
  * Top level event loop.
  */
src/openvpn/multi.h +10 -0
index b7078b711..9d771f537 100644
@@ -676,5 +676,15 @@ multi_set_pending(struct multi_context *m, struct multi_instance *mi)
 {
     m->pending = mi;
 }
+/**
+ * Assigns a peer-id to a a client and adds the instance to the
+ * the instances array of the \c multi_context structure.
+ *
+ * @param m            - The single \c multi_context structure.
+ * @param mi           - The \c multi_instance of the VPN tunnel to be
+ *                       postprocessed.
+ */
+void multi_assign_peer_id(struct multi_context *m, struct multi_instance *mi);
+
 
 #endif /* MULTI_H */
Signature · 1 line
2.30.1
#35 lore raw

PATCH 13/14 log file descriptor in more socket related error messages

In reply to Arne Schwabe

This add the fd to the epoll event error message and the x_check_status message. This helps debugging when thing go wrong with event handling.

Also add logging when ep_del fails to remove a socket from the structure. In constract to ep_ctl that has this as a FATAL message (M_ERR), we only log here since the code has been ignoring the status forever there might be corner cases where a FATAL message could trigger an unintened regression.

---
 src/openvpn/error.c | 8 ++++----
 src/openvpn/event.c | 8 ++++++--
 2 files changed, 10 insertions(+), 6 deletions(-)
src/openvpn/error.c +4 -4
index e6f7ff0ff..4eebf41a9 100644
@@ -690,15 +690,15 @@ x_check_status(int status,
         {
             if (extended_msg)
             {
-                msg(x_cs_info_level, "%s %s [%s]: %s (code=%d)", description,
+                msg(x_cs_info_level, "%s %s [%s]: %s (fd=%d,code=%d)", description,
                     sock ? proto2ascii(sock->info.proto, sock->info.af, true) : "",
-                    extended_msg, strerror(my_errno), my_errno);
+                    extended_msg, strerror(my_errno), my_errno, sock ? sock->sd : -1);
             }
             else
             {
-                msg(x_cs_info_level, "%s %s: %s (code=%d)", description,
+                msg(x_cs_info_level, "%s %s: %s (fd=%d,code=%d)", description,
                     sock ? proto2ascii(sock->info.proto, sock->info.af, true) : "",
-                    strerror(my_errno), my_errno);
+                    strerror(my_errno), my_errno, sock ? sock->sd : -1);
             }
 
             if (x_cs_err_delay_ms)
src/openvpn/event.c +6 -2
index 49dfa861c..14a25155c 100644
@@ -555,7 +555,10 @@ ep_del(struct event_set *es, event_t event)
 
     ASSERT(!eps->fast);
     CLEAR(ev);
-    epoll_ctl(eps->epfd, EPOLL_CTL_DEL, event, &ev);
+    if (epoll_ctl(eps->epfd, EPOLL_CTL_DEL, event, &ev) < 0)
+    {
+        msg(M_WARN|M_ERRNO, "EVENT: epoll_ctl EPOLL_CTL_DEL failed, sd=%d", (int)event);
+    }
 }
 
 static void
@@ -844,7 +847,8 @@ po_wait(struct event_set *es, const struct timeval *tv, struct event_set_return
             }
             else if (pfdp->revents)
             {
-                msg(D_EVENT_ERRORS, "Error: poll: unknown revents=0x%04x", (unsigned int)pfdp->revents);
+                msg(D_EVENT_ERRORS, "Error: poll: unknown revents=0x%04x for fd=%d",
+                    (unsigned int)pfdp->revents, pfdp->fd);
             }
             ++pfdp;
         }
Signature · 1 line
2.30.1
#37 lore raw

PATCH 14/14 Remove do_init_socket_2 and do_init_socket_1 wrapper function

In reply to Arne Schwabe

These two function basically just pass a number of fields of context to the linit_socket_init1/2 functions. This wrapper add little to no value in understanding the code, especially since the linit_socket_init1 will just copy them to yet another structure.

Remove these wrapper functions and pass context directly to the called function.

---
 src/openvpn/init.c   |  60 +-----------------------
 src/openvpn/socket.c | 109 +++++++++++++++++++------------------------
 src/openvpn/socket.h |  40 ++--------------
 3 files changed, 52 insertions(+), 157 deletions(-)
src/openvpn/init.c +2 -58
index 98cc1ebe9..d6dd8675c 100644
@@ -3339,62 +3339,6 @@ do_link_socket_new(struct context *c)
     c->c2.link_socket_owned = true;
 }
 
-/*
- * bind the TCP/UDP socket
- */
-static void
-do_init_socket_1(struct context *c, const int mode)
-{
-    unsigned int sockflags = c->options.sockflags;
-
-#if PORT_SHARE
-    if (c->options.port_share_host && c->options.port_share_port)
-    {
-        sockflags |= SF_PORT_SHARE;
-    }
-#endif
-
-    link_socket_init_phase1(c->c2.link_socket,
-                            c->options.ce.local,
-                            c->options.ce.local_port,
-                            c->options.ce.remote,
-                            c->options.ce.remote_port,
-                            c->c1.dns_cache,
-                            c->options.ce.proto,
-                            c->options.ce.af,
-                            c->options.ce.bind_ipv6_only,
-                            mode,
-                            c->c2.accept_from,
-                            c->c1.http_proxy,
-                            c->c1.socks_proxy,
-#ifdef ENABLE_DEBUG
-                            c->options.gremlin,
-#endif
-                            c->options.ce.bind_local,
-                            c->options.ce.remote_float,
-                            &c->c1.link_socket_addr,
-                            c->options.ipchange,
-                            c->plugins,
-                            c->options.resolve_retry_seconds,
-                            c->options.ce.mtu_discover_type,
-                            c->options.rcvbuf,
-                            c->options.sndbuf,
-                            c->options.mark,
-                            c->options.bind_dev,
-                            &c->c2.server_poll_interval,
-                            sockflags);
-}
-
-/*
- * finalize the TCP/UDP socket
- */
-static void
-do_init_socket_2(struct context *c)
-{
-    link_socket_init_phase2(c->c2.link_socket, &c->c2.frame,
-                            c->sig);
-}
-
 /*
  * Print MTU INFO
  */
@@ -4255,7 +4199,7 @@ init_instance(struct context *c, const struct env_set *env, const unsigned int f
     /* bind the TCP/UDP socket */
     if (c->mode == CM_P2P || c->mode == CM_TOP || c->mode == CM_CHILD_TCP)
     {
-        do_init_socket_1(c, link_socket_mode);
+        link_socket_init_phase1(c, link_socket_mode);
     }
 
     /* initialize tun/tap device object,
@@ -4299,7 +4243,7 @@ init_instance(struct context *c, const struct env_set *env, const unsigned int f
     /* finalize the TCP/UDP socket */
     if (c->mode == CM_P2P || c->mode == CM_TOP || c->mode == CM_CHILD_TCP)
     {
-        do_init_socket_2(c);
+        link_socket_init_phase2(c);
     }
 
     /*
src/openvpn/socket.c +47 -62

150 lines not on this page · raw message

src/openvpn/socket.h +3 -37
index d58fda4d3..6a86ee054 100644
@@ -292,43 +292,9 @@ int openvpn_connect(socket_descriptor_t sd,
 /*
  * Initialize link_socket object.
  */
-/* *INDENT-OFF* uncrustify misparses this function declarion because of
- * embedded #if/#endif tell it to skip this section */
-void
-link_socket_init_phase1(struct link_socket *sock,
-                        const char *local_host,
-                        const char *local_port,
-                        const char *remote_host,
-                        const char *remote_port,
-                        struct cached_dns_entry *dns_cache,
-                        int proto,
-                        sa_family_t af,
-                        bool bind_ipv6_only,
-                        int mode,
-                        const struct link_socket *accept_from,
-                        struct http_proxy_info *http_proxy,
-                        struct socks_proxy_info *socks_proxy,
-#ifdef ENABLE_DEBUG
-                        int gremlin,
-#endif
-                        bool bind_local,
-                        bool remote_float,
-                        struct link_socket_addr *lsa,
-                        const char *ipchange_command,
-                        const struct plugin_list *plugins,
-                        int resolve_retry_seconds,
-                        int mtu_discover_type,
-                        int rcvbuf,
-                        int sndbuf,
-                        int mark,
-                        const char *bind_dev,
-                        struct event_timeout *server_poll_timeout,
-                        unsigned int sockflags);
-/* Reenable uncrustify *INDENT-ON* */
-
-void link_socket_init_phase2(struct link_socket *sock,
-                             const struct frame *frame,
-                             struct signal_info *sig_info);
+void link_socket_init_phase1(struct context *c, int mode);
+
+void link_socket_init_phase2(struct context *c);
 
 void do_preresolve(struct context *c);
 
Signature · 1 line
2.30.1
Acked-by on v1 2/14
#4 lore raw

[Openvpn-devel] [PATCH applied] Re: Remove superflous ifdefs around enum like defines

In reply to Arne Schwabe

Totally untested, but stared-at-code for a bit. (This will increase binary for "no management" by some 10-20 bytes, but makes the code easier to understand by not getting distracted by #ifdefs all over the place).

Your patch has been applied to the master branch.

commit 213fd3ee49e670124d911634c2f52061a82357af

Author: Arne Schwabe
Date:   Thu Apr 1 15:13:25 2021 +0200
     Remove superflous ifdefs around enum like defines

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

--
kind regards,

Gert Doering

Acked-by on v1 3/14
#6 lore raw

[Openvpn-devel] [PATCH applied] Re: Rename tunnel_server_udp_single_threaded to tunnel_server_udp

In reply to Arne Schwabe

"Because it makes sense". There's no threads here, and with DCO and all the asyncness, there might never be... so, admit that fact :-)

Lightly client-side tested on linux.

Your patch has been applied to the master branch.

commit bdc11ae462d61f0cdee5f539c7f028f58513a914

Author: Arne Schwabe
Date:   Thu Apr 1 15:13:26 2021 +0200
     Rename tunnel_server_udp_single_threaded to tunnel_server_udp

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

--
kind regards,

Gert Doering

Acked-by on v1 1/14
#2 lore raw

[Openvpn-devel] [PATCH applied] Re: Remove code for aligning non-swapped compression

In reply to Arne Schwabe

I was a bit worried about this breaking existing setups, and then Arne remarked that "this is dead code anyway" - it is only compiled if built with --disable-lz4, which we do for testing on some buildbots, but not for production builds. So, ripping out dead code is not going to break anything.

Still, lightly client side tested on Linux. With compression :)

Your patch has been applied to the master branch.

commit 137eb6705e57d3324fe45367419413e34a424976

Author: Arne Schwabe
Date:   Thu Apr 1 15:13:24 2021 +0200
     Remove code for aligning non-swapped compression

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

--
kind regards,

Gert Doering

Acked-by on v1 6/14
#20 lore raw

[Openvpn-devel] [PATCH applied] Re: Remove pointless tun_adjust_frame_parameters function

In reply to Arne Schwabe

.. indeed!

Your patch has been applied to the master branch.

commit 14061e3e06075065fba1939d3716fbd09f9adf70

Author: Arne Schwabe
Date:   Thu Apr 1 15:13:29 2021 +0200
     Remove pointless tun_adjust_frame_parameters function

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

--
kind regards,

Gert Doering

Acked-by on v1 7/14
#22 lore raw

[Openvpn-devel] [PATCH applied] Re: Remove unused field txqueuelen from struct tuntap

In reply to Arne Schwabe

As far as I can see, only Linux uses txqueuelen at all, and that one still compiles with this patch applied. Out it goes!

Your patch has been applied to the master branch.

commit 3667df1d668420374d91607685b67a0efbcee328

Author: Arne Schwabe
Date:   Thu Apr 1 15:13:30 2021 +0200
     Remove unused field txqueuelen from struct tuntap

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

--
kind regards,

Gert Doering

Acked-by on v1 8/14
#24 lore raw

[Openvpn-devel] [PATCH applied] Re: Remove unused function tls_test_auth_deferred_interval

In reply to Arne Schwabe

"git grep" confirms

Your patch has been applied to the master branch.

commit c0b36e9f29c9849892909a7e377e13db6aa59f95

Author: Arne Schwabe
Date:   Thu Apr 1 15:13:31 2021 +0200
     Remove unused function tls_test_auth_deferred_interval

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

--
kind regards,

Gert Doering

Acked-by on v1 5/14
#18 lore raw

[Openvpn-devel] [PATCH applied] Re: Remove unused variable pass_config_info

In reply to Arne Schwabe

"git grep" confirms.

Your patch has been applied to the master branch.

commit 9eb285f42f73bcfb270adbae527947951615df7d

Author: Arne Schwabe
Date:   Thu Apr 1 15:13:28 2021 +0200
     Remove unused variable pass_config_info

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

--
kind regards,

Gert Doering

Acked-by on v1 9/14
#26 lore raw

[Openvpn-devel] [PATCH applied] Re: Move is_proto function to the socket.h header

In reply to Arne Schwabe

Moved and compacted somewhat, but "the same functions".

Having a "proto_is_dgram()" sounds a bit silly since we're not doing "openvpn over IPX" or anything other dgram based, but who knows... maybe we'll grow IPX/SPX support and "proto_is_stream()" one day... :-)

Client-side tested on Linux and FreeBSD, just to be sure.

Your patch has been applied to the master branch.

commit 72e1ecb5b5d282c591cc32bbd378efbebfb03918

Author: Arne Schwabe
Date:   Thu Apr 1 15:13:32 2021 +0200
     Move is_proto function to the socket.h header

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

--
kind regards,

Gert Doering

#30 lore raw

Re: [Openvpn-devel] [PATCH 11/14] Remove P2MP mode and check for gettimeofday

In reply to Arne Schwabe

Am 01.04.21 um 15:13 schrieb Arne Schwabe:

src/openvpn/multi.c multi_connection_established(struct multi_context *m, struct multi_instance *mi) · line 2646

Quoted 7 lines

Using OpenVPN without P2MP support (pull, TLS) is unrealistic and building a binary without it is not something we realistically want to support anyway.

     }
src/openvpn/multi.c +2 -0
+    /* Check if we have forbidding options in the current mode */
+    if (dco_enabled( &mi->context.options)

Ignore this patch for now. Rebasing worked without conflicts but somehow still pull dco bits into it (rebase is sometimes magic ....)

Arne

Acked-by on v1 10/14
#28 lore raw

[Openvpn-devel] [PATCH applied] Re: Remove thread_mode field of multi_context

In reply to Arne Schwabe

Stared at code (with "diff -w"), and since we're not doing threads and the only value that ever is used is MC_SINGLE_THREADED, which is "1", this effectively is not changing any code flow. Lightly tested on FreeBSD client.

Your patch has been applied to the master branch.

commit 18b4a8380ba3237e870e84b25edf3f6e15145296

Author: Arne Schwabe
Date:   Thu Apr 1 15:13:33 2021 +0200
     Remove thread_mode field of multi_context

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

--
kind regards,

Gert Doering

Acked-by on v1 12/14
#34 lore raw

[Openvpn-devel] [PATCH applied] Re: Extract multi_assign_peer_id into its own function

In reply to Arne Schwabe

Simple enough :-) - I have not tested this very very thoroughly, but one of my server test instances has 3 parallel clients, so I could at least see that they do get assigned different IDs (and that it compiles).

Your patch has been applied to the master branch.

commit 9fe0b2c287609cefe79aec30ff33f7a65cafd684

Author: Arne Schwabe
Date:   Thu Apr 1 15:13:35 2021 +0200
     Extract multi_assign_peer_id into its own function

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

--
kind regards,

Gert Doering

#36 lore raw

Re: [Openvpn-devel] [PATCH 13/14] log file descriptor in more socket related error messages

In reply to Arne Schwabe

Hi,

src/openvpn/error.c x_check_status(int status, · line 695

Quoted 7 lines · Arne Schwabe
             if (extended_msg)
             {
src/openvpn/error.c +2 -2
-                msg(x_cs_info_level, "%s %s [%s]: %s (code=%d)", description,
+                msg(x_cs_info_level, "%s %s [%s]: %s (fd=%d,code=%d)", description,
                     sock ? proto2ascii(sock->info.proto, sock->info.af, true) : "",
-                    extended_msg, strerror(my_errno), my_errno);
+                    extended_msg, strerror(my_errno), my_errno, sock ? sock->sd : -1);

I'm not sure if I'm misreading this, but "fd=%d" is added before "code=%d", but the "sock->fd" thingie is added at the end.

So I tentatively NAK this.

src/openvpn/event.c ep_del(struct event_set *es, event_t event) · line 562

Quoted 12 lines
src/openvpn/event.c +4 -1
@@ -555,7 +555,10 @@ ep_del(struct event_set *es, event_t event)
 
     ASSERT(!eps->fast);
     CLEAR(ev);
-    epoll_ctl(eps->epfd, EPOLL_CTL_DEL, event, &ev);
+    if (epoll_ctl(eps->epfd, EPOLL_CTL_DEL, event, &ev) < 0)
+    {
+        msg(M_WARN|M_ERRNO, "EVENT: epoll_ctl EPOLL_CTL_DEL failed, sd=%d", (int)event);
+    }
 }

The rest of the patch looks reasonable.

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
Acked-by on v1 14/14
#38 lore raw

[Openvpn-devel] [PATCH applied] Re: Remove do_init_socket_2 and do_init_socket_1 wrapper function

In reply to Arne Schwabe

Just *looking* at these functions with the insane number of arguments make my head hurt. So I can't claim to have thoroughly reviewed that every single argument goes to wherever it wanted to go before. What I saw looked good, though.

BUT - we have good test coverage on these (tcp, udp, socks, http proxy, ipv4, ipv6) in the t_client test set. So I let my machines worry :-)

Linux and FreeBSD both claim that the end result still works (it might have broken the SRV patch, but we'll see).

Your patch has been applied to the master branch.

commit 343b61195b76796632b8948674fd1068889bb6c7

Author: Arne Schwabe
Date:   Thu Apr 1 15:13:37 2021 +0200
     Remove do_init_socket_2 and do_init_socket_1 wrapper function

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

--
kind regards,

Gert Doering

#8 lore raw

Re: [Openvpn-devel] [PATCH 04/14] Add documentation on EVENT_READ/EVENT_WRITE constants

In reply to Arne Schwabe
Quoted 11 lines · Arne Schwabe
---
 src/openvpn/forward.c |  3 ++-
 src/openvpn/openvpn.h | 12 +++++++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)
src/openvpn/forward.c +0 -0
index 6f7a50048..98caf6651 100644

src/openvpn/forward.c io_wait_dowork(struct context *c, const unsigned int flags) · line 1884

Quoted 6 lines
src/openvpn/forward.c +2 -1
@@ -1880,7 +1880,8 @@ io_wait_dowork(struct context *c, const unsigned int flags)
     unsigned int tuntap = 0;
     struct event_set_return esr[4];
 
-    /* These shifts all depend on EVENT_READ and EVENT_WRITE */
+    /* These shifts all depend on EVENT_READ (=1) and EVENT_WRITE (=2) */
+    /* and are added to the shift. */

I suggest making a classic multiline comment here, instead of two single lines.

src/openvpn/openvpn.h struct context_2 · line 248

Quoted 13 lines
src/openvpn/forward.c +0 -0
     static int socket_shift = 0;   /* depends on SOCKET_READ and SOCKET_WRITE */
     static int tun_shift = 2;      /* depends on TUN_READ and TUN_WRITE */
     static int err_shift = 4;      /* depends on ES_ERROR */
src/openvpn/openvpn.h +1 -1
index 0ddaeb730..322ab3ee1 100644
@@ -245,7 +245,17 @@ struct context_2
     int event_set_max;
     bool event_set_owned;
 
-    /* event flags returned by io_wait */
+    /* event flags returned by io_wait,

colon or period instead of comma?

src/openvpn/openvpn.h struct context_2 · line 256

Quoted 8 lines
src/openvpn/openvpn.h +8 -0
+     * All these event are their respective shift as defined in io_wait_dowork
+     * adding a shift of 0 for the READ event and 1 for the write event.
+     *
+     * E.g. management_shift = 6;
+     * MANAGMENT_READ = (1<<(6+0)),
+     * MANAGEMNET_WRITE = (1<<(6+1))
+     *
+     * Some shifts (error, file_close) are using read/write for diferent

diferent -> different

src/openvpn/openvpn.h struct context_2 · line 261

Quoted 6 lines
src/openvpn/openvpn.h +2 -0
+     * signals.
+     */
 #define SOCKET_READ       (1<<0)
 #define SOCKET_WRITE      (1<<1)
 #define TUN_READ          (1<<2)

I get what you are trying to describe, but it is not easy to grasp without jumping back and forth between openvpn.h, forward.c and events.c.

Instead of talking about shifts, why not going high level and explain how the bitmask is supposed to look like (i.e. 2 bits are associated with each class of operations. The first bit is a READ event, the second one is a WRITE event..etc..).

Opinions?

In this patch you could even move the definition of all the *_shift to openvpn.h, next to the various _READ and _WRITE, since they are all related.

What do you think? Would it make sense?

Cheers,

Signature · 1 line
Antonio Quartulli
#31 lore raw

Re: [Openvpn-devel] [PATCH 11/14] Remove P2MP mode and check for gettimeofday

In reply to Arne Schwabe

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Before this goes any further, I doubt very much that Openvpn intends to "Remove P2MP mode".

Sent with ProtonMail Secure Email.

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐

Quoted 12 lines · Arne Schwabe

Am 01.04.21 um 15:13 schrieb Arne Schwabe:

Review

Quoted 9 lines

Using OpenVPN without P2MP support (pull, TLS) is unrealistic and building a binary without it is not something we realistically want to support anyway.

     }
(quoted diff) +0 -2
-   /* Check if we have forbidding options in the current mode */
-   if (dco_enabled( &mi->context.options)
Quoted 8 lines

Ignore this patch for now. Rebasing worked without conflicts but somehow still pull dco bits into it (rebase is sometimes magic ....)

Arne

Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

-----BEGIN PGP SIGNATURE-----
Version: ProtonMail

wsBzBAEBCAAGBQJgaNsSACEJEE+XnPZrkLidFiEECbw9RGejjXJ5xVVVT5ec 9muQuJ2xqwf9EbssBV+0gW+/y0bIR+3I7DFZouZTRcO+9SCftHO6AcfTBgaD Uro0ZmOa233PaGSB3B5MbJcZQ0gnIWegVeGjN0khVOU75fv332svNc2CLZtn JHwG3XYnHWxMMVaRWkcyPp72UUfxiaooZp1FjPAnhl6D/PUAxw2tU3Cl6dp1 rgHmWhNKza2B8PzhnSZ8K0RiTjdOy3bYLSdj6hKwyQkvG1+wEGpG0qJSEnKF 1Qb2qpPNftG1BfOkTQ3QVuBcpDDusR1ip+qs9LmLo87LKD2UF8DWgZlj5Ev8 pdu8+cp7Fk7G2UrLWbKy7fTPcfncaViiNEHNbm9EMtURCioaLsQwoA== =Cr8U
-----END PGP SIGNATURE-----

#32 lore raw

Re: [Openvpn-devel] [PATCH 11/14] Remove P2MP mode and check for gettimeofday

Hi,

Quoted 2 lines · tincantech via Openvpn-devel

-----BEGIN PGP SIGNED MESSAGE-----
Before this goes any further, I doubt very much that Openvpn intends to "Remove P2MP mode".

This is about removing the P2MP *define*, which means "there is no more way to compile openvpn without P2MP".

But indeed, the commit subject could be made clearer. I'll fix this on the fly.

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#9 lore raw

PATCH v2 1/1 Add documentation on EVENT_READ/EVENT_WRITE constants

In reply to Arne Schwabe

From: Arne Schwabe <[email protected]...>

Changes from v1:
- fixed typ0s
- extended comment
- moved *_SHIFT definition to openvpn.h
- made READ/WRITE events dependant on _SHIFT definition with a macro

---

Passed all compile tests on my GitLab CI. (including enabling/disabling mgmt and async push)

 src/openvpn/forward.c | 14 +++++++-----
 src/openvpn/openvpn.h | 51 ++++++++++++++++++++++++++++++++++---------
 2 files changed, 49 insertions(+), 16 deletions(-)
src/openvpn/forward.c +8 -6
index df96d048..e302d8e0 100644
@@ -1867,15 +1867,17 @@ io_wait_dowork(struct context *c, const unsigned int flags)
     unsigned int tuntap = 0;
     struct event_set_return esr[4];
 
-    /* These shifts all depend on EVENT_READ and EVENT_WRITE */
-    static int socket_shift = 0;   /* depends on SOCKET_READ and SOCKET_WRITE */
-    static int tun_shift = 2;      /* depends on TUN_READ and TUN_WRITE */
-    static int err_shift = 4;      /* depends on ES_ERROR */
+    /* These shifts all depend on EVENT_READ (=1) and EVENT_WRITE (=2)
+     * and are added to the shift. Check openvpn.h for more details.
+     */
+    static int socket_shift = SOCKET_SHIFT;
+    static int tun_shift = TUN_SHIFT;
+    static int err_shift = ERR_SHIFT;
 #ifdef ENABLE_MANAGEMENT
-    static int management_shift = 6; /* depends on MANAGEMENT_READ and MANAGEMENT_WRITE */
+    static int management_shift = MANAGEMENT_SHIFT;
 #endif
 #ifdef ENABLE_ASYNC_PUSH
-    static int file_shift = 8;     /* listening inotify events */
+    static int file_shift = FILE_SHIFT;
 #endif
 
     /*
src/openvpn/openvpn.h +41 -10

57 lines not on this page · raw message

Signature · 1 line
2.26.3
#10 lore raw

PATCH v3 1/1 Add documentation on EVENT_READ/EVENT_WRITE constants

From: Arne Schwabe <[email protected]...>

Changes from v2:
- moved event definitions to event.h
- removed READ/WRITE_SHIFT and use EVENT_READ/WRITE
- removed ifdefs around *_SHIFTS definitions in event.h

Changes from v1:
- fixed typ0s
- extended comment
- moved *_SHIFT definition to openvpn.h
- made READ/WRITE events dependant on _SHIFT definition with a macro

---
 src/openvpn/event.h   | 37 +++++++++++++++++++++++++++++++++++++
 src/openvpn/forward.c | 14 ++++++++------
 src/openvpn/openvpn.h | 12 +-----------
 3 files changed, 46 insertions(+), 17 deletions(-)
src/openvpn/event.h +37 -0
index 4af6371e..67baea3e 100644
@@ -35,6 +35,43 @@
 #define EVENT_UNDEF    4
 #define EVENT_READ     (1<<0)
 #define EVENT_WRITE    (1<<1)
+
+/* event flags returned by io_wait.
+ *
+ * All these events are defined as bits in a bitfield.
+ * Each event type owns two bits in the bitfield: one for the READ
+ * event and one for the WRITE event.
+ *
+ * For this reason, the specific event bit is calculated by adding
+ * the event type identifier (always a multiple of 2, as defined
+ * below) to 0 for READ and 1 for WRITE.
+ *
+ * E.g.
+ * MANAGEMENT_SHIFT = 6;  <---- event type identifier
+ * MANAGEMENT_READ = (1 << (6 + 0)),  <---- READ event
+ * MANAGEMENT_WRITE = (1 << (6 + 1))  <---- WRITE event
+ *
+ * 'error' and 'file_close' are special and use read/write for different
+ * signals.
+ */
+
+#define EVENT_SHIFT(_name, _op)   (1 << (_name ## _SHIFT + EVENT_ ## _op))
+
+#define SOCKET_SHIFT        0
+#define SOCKET_READ         EVENT_SHIFT(SOCKET, READ)
+#define SOCKET_WRITE        EVENT_SHIFT(SOCKET, WRITE)
+#define TUN_SHIFT           2
+#define TUN_READ            EVENT_SHIFT(TUN, READ)
+#define TUN_WRITE           EVENT_SHIFT(TUN, WRITE)
+#define ERR_SHIFT           4
+#define ES_ERROR            EVENT_SHIFT(ERR, READ)
+#define ES_TIMEOUT          EVENT_SHIFT(ERR, WRITE)
+#define MANAGEMENT_SHIFT    6
+#define MANAGEMENT_READ     EVENT_SHIFT(MANAGEMENT, READ)
+#define MANAGEMENT_WRITE    EVENT_SHIFT(MANAGEMENT, WRITE)
+#define FILE_SHIFT          8
+#define FILE_CLOSED         EVENT_SHIFT(FILE, READ)
+
 /*
  * Initialization flags passed to event_set_init
  */
src/openvpn/forward.c +8 -6
index df96d048..e302d8e0 100644
@@ -1867,15 +1867,17 @@ io_wait_dowork(struct context *c, const unsigned int flags)
     unsigned int tuntap = 0;
     struct event_set_return esr[4];
 
-    /* These shifts all depend on EVENT_READ and EVENT_WRITE */
-    static int socket_shift = 0;   /* depends on SOCKET_READ and SOCKET_WRITE */
-    static int tun_shift = 2;      /* depends on TUN_READ and TUN_WRITE */
-    static int err_shift = 4;      /* depends on ES_ERROR */
+    /* These shifts all depend on EVENT_READ (=1) and EVENT_WRITE (=2)
+     * and are added to the shift. Check openvpn.h for more details.
+     */
+    static int socket_shift = SOCKET_SHIFT;
+    static int tun_shift = TUN_SHIFT;
+    static int err_shift = ERR_SHIFT;
 #ifdef ENABLE_MANAGEMENT
-    static int management_shift = 6; /* depends on MANAGEMENT_READ and MANAGEMENT_WRITE */
+    static int management_shift = MANAGEMENT_SHIFT;
 #endif
 #ifdef ENABLE_ASYNC_PUSH
-    static int file_shift = 8;     /* listening inotify events */
+    static int file_shift = FILE_SHIFT;
 #endif
 
     /*
src/openvpn/openvpn.h +1 -11
index a15ff08d..6e4651cf 100644
@@ -232,17 +232,7 @@ struct context_2
     int event_set_max;
     bool event_set_owned;
 
-    /* event flags returned by io_wait */
-#define SOCKET_READ       (1<<0)
-#define SOCKET_WRITE      (1<<1)
-#define TUN_READ          (1<<2)
-#define TUN_WRITE         (1<<3)
-#define ES_ERROR          (1<<4)
-#define ES_TIMEOUT        (1<<5)
-#define MANAGEMENT_READ  (1<<6)
-#define MANAGEMENT_WRITE (1<<7)
-#define FILE_CLOSED       (1<<8)
-
+    /* bitmask for event status. Check event.h for possible values */
     unsigned int event_set_status;
 
     struct link_socket *link_socket;     /* socket used for TCP/UDP connection to remote */
Signature · 1 line
2.26.3
author Acked-by on v3 1/1
#11 lore raw

Re: [Openvpn-devel] [PATCH v3] Add documentation on EVENT_READ/EVENT_WRITE constants

Am 26.04.21 um 15:26 schrieb Antonio Quartulli:

Quoted 7 lines

From: Arne Schwabe <[email protected]...>

Changes from v2:
- moved event definitions to event.h
- removed READ/WRITE_SHIFT and use EVENT_READ/WRITE
- removed ifdefs around *_SHIFTS definitions in event.h

Quoted 8 lines

Changes from v1:
- fixed typ0s
- extended comment
- moved *_SHIFT definition to openvpn.h
- made READ/WRITE events dependant on _SHIFT definition with a macro

Thanks for picking it up and getting it in shape. It probably should now say From: Antonio Quartulli <[email protected]...> as that is now most of the code. That also looks better on the commit log as it doesn't look like I acked my own patch.

#12 lore raw

Re: [Openvpn-devel] [PATCH v3] Add documentation on EVENT_READ/EVENT_WRITE constants

In reply to Antonio Quartulli

Hi,

unfortunately something is not right.
Additional tests showed that something broke after applying this patch.

Will debug and provide a new version.

Regards,

Quoted 121 lines · Antonio Quartulli

From: Arne Schwabe <[email protected]...>

Changes from v2:
- moved event definitions to event.h
- removed READ/WRITE_SHIFT and use EVENT_READ/WRITE
- removed ifdefs around *_SHIFTS definitions in event.h

Changes from v1:
- fixed typ0s
- extended comment
- moved *_SHIFT definition to openvpn.h
- made READ/WRITE events dependant on _SHIFT definition with a macro

---
 src/openvpn/event.h   | 37 +++++++++++++++++++++++++++++++++++++
 src/openvpn/forward.c | 14 ++++++++------
 src/openvpn/openvpn.h | 12 +-----------
 3 files changed, 46 insertions(+), 17 deletions(-)
src/openvpn/event.h +37 -0
index 4af6371e..67baea3e 100644
@@ -35,6 +35,43 @@
 #define EVENT_UNDEF    4
 #define EVENT_READ     (1<<0)
 #define EVENT_WRITE    (1<<1)
+
+/* event flags returned by io_wait.
+ *
+ * All these events are defined as bits in a bitfield.
+ * Each event type owns two bits in the bitfield: one for the READ
+ * event and one for the WRITE event.
+ *
+ * For this reason, the specific event bit is calculated by adding
+ * the event type identifier (always a multiple of 2, as defined
+ * below) to 0 for READ and 1 for WRITE.
+ *
+ * E.g.
+ * MANAGEMENT_SHIFT = 6;  <---- event type identifier
+ * MANAGEMENT_READ = (1 << (6 + 0)),  <---- READ event
+ * MANAGEMENT_WRITE = (1 << (6 + 1))  <---- WRITE event
+ *
+ * 'error' and 'file_close' are special and use read/write for different
+ * signals.
+ */
+
+#define EVENT_SHIFT(_name, _op)   (1 << (_name ## _SHIFT + EVENT_ ## _op))
+
+#define SOCKET_SHIFT        0
+#define SOCKET_READ         EVENT_SHIFT(SOCKET, READ)
+#define SOCKET_WRITE        EVENT_SHIFT(SOCKET, WRITE)
+#define TUN_SHIFT           2
+#define TUN_READ            EVENT_SHIFT(TUN, READ)
+#define TUN_WRITE           EVENT_SHIFT(TUN, WRITE)
+#define ERR_SHIFT           4
+#define ES_ERROR            EVENT_SHIFT(ERR, READ)
+#define ES_TIMEOUT          EVENT_SHIFT(ERR, WRITE)
+#define MANAGEMENT_SHIFT    6
+#define MANAGEMENT_READ     EVENT_SHIFT(MANAGEMENT, READ)
+#define MANAGEMENT_WRITE    EVENT_SHIFT(MANAGEMENT, WRITE)
+#define FILE_SHIFT          8
+#define FILE_CLOSED         EVENT_SHIFT(FILE, READ)
+
 /*
  * Initialization flags passed to event_set_init
  */
src/openvpn/forward.c +8 -6
index df96d048..e302d8e0 100644
@@ -1867,15 +1867,17 @@ io_wait_dowork(struct context *c, const unsigned int flags)
     unsigned int tuntap = 0;
     struct event_set_return esr[4];
 
-    /* These shifts all depend on EVENT_READ and EVENT_WRITE */
-    static int socket_shift = 0;   /* depends on SOCKET_READ and SOCKET_WRITE */
-    static int tun_shift = 2;      /* depends on TUN_READ and TUN_WRITE */
-    static int err_shift = 4;      /* depends on ES_ERROR */
+    /* These shifts all depend on EVENT_READ (=1) and EVENT_WRITE (=2)
+     * and are added to the shift. Check openvpn.h for more details.
+     */
+    static int socket_shift = SOCKET_SHIFT;
+    static int tun_shift = TUN_SHIFT;
+    static int err_shift = ERR_SHIFT;
 #ifdef ENABLE_MANAGEMENT
-    static int management_shift = 6; /* depends on MANAGEMENT_READ and MANAGEMENT_WRITE */
+    static int management_shift = MANAGEMENT_SHIFT;
 #endif
 #ifdef ENABLE_ASYNC_PUSH
-    static int file_shift = 8;     /* listening inotify events */
+    static int file_shift = FILE_SHIFT;
 #endif
 
     /*
src/openvpn/openvpn.h +1 -11
index a15ff08d..6e4651cf 100644
@@ -232,17 +232,7 @@ struct context_2
     int event_set_max;
     bool event_set_owned;
 
-    /* event flags returned by io_wait */
-#define SOCKET_READ       (1<<0)
-#define SOCKET_WRITE      (1<<1)
-#define TUN_READ          (1<<2)
-#define TUN_WRITE         (1<<3)
-#define ES_ERROR          (1<<4)
-#define ES_TIMEOUT        (1<<5)
-#define MANAGEMENT_READ  (1<<6)
-#define MANAGEMENT_WRITE (1<<7)
-#define FILE_CLOSED       (1<<8)
-
+    /* bitmask for event status. Check event.h for possible values */
     unsigned int event_set_status;
 
     struct link_socket *link_socket;     /* socket used for TCP/UDP connection to remote */
Signature · 1 line
Antonio Quartulli
#13 lore raw

PATCH v4 1/1 Add documentation on EVENT_READ/EVENT_WRITE constants

In reply to Antonio Quartulli

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

Changes from v3:
- re-introduce READ/WRITE_SHIFT because they are different from EVENT_READ/WRITE
- define also EVENT_READ/WRITE using READ/WRITE_SHIFT

Changes from v2:
- moved event definitions to event.h
- removed READ/WRITE_SHIFT and use EVENT_READ/WRITE
- removed ifdefs around *_SHIFTS definitions in event.h

Changes from v1:
- fixed typ0s
- extended comment
- moved *_SHIFT definition to openvpn.h
- made READ/WRITE events dependant on _SHIFT definition with a macro

---
 src/openvpn/event.h   | 44 +++++++++++++++++++++++++++++++++++++++++--
 src/openvpn/forward.c | 14 ++++++++------
 src/openvpn/openvpn.h | 12 +-----------
 3 files changed, 51 insertions(+), 19 deletions(-)
src/openvpn/event.h +42 -2
index 4af6371e..bfc3d51f 100644
@@ -32,9 +32,49 @@
  * rwflags passed to event_ctl and returned by
  * struct event_set_return.
  */
+#define READ_SHIFT	0
+#define WRITE_SHIFT	1
+
 #define EVENT_UNDEF    4
-#define EVENT_READ     (1<<0)
-#define EVENT_WRITE    (1<<1)
+#define EVENT_READ     (1 << READ_SHIFT)
+#define EVENT_WRITE    (1 << WRITE_SHIFT)
+
+/* event flags returned by io_wait.
+ *
+ * All these events are defined as bits in a bitfield.
+ * Each event type owns two bits in the bitfield: one for the READ
+ * event and one for the WRITE event.
+ *
+ * For this reason, the specific event bit is calculated by adding
+ * the event type identifier (always a multiple of 2, as defined
+ * below) to 0 for READ and 1 for WRITE.
+ *
+ * E.g.
+ * MANAGEMENT_SHIFT = 6;  <---- event type identifier
+ * MANAGEMENT_READ = (1 << (6 + 0)),  <---- READ event
+ * MANAGEMENT_WRITE = (1 << (6 + 1))  <---- WRITE event
+ *
+ * 'error' and 'file_close' are special and use read/write for different
+ * signals.
+ */
+
+#define EVENT_SHIFT(_name, _op)   (1 << (_name ## _SHIFT + _op ## _SHIFT))
+
+#define SOCKET_SHIFT        0
+#define SOCKET_READ         EVENT_SHIFT(SOCKET, READ)
+#define SOCKET_WRITE        EVENT_SHIFT(SOCKET, WRITE)
+#define TUN_SHIFT           2
+#define TUN_READ            EVENT_SHIFT(TUN, READ)
+#define TUN_WRITE           EVENT_SHIFT(TUN, WRITE)
+#define ERR_SHIFT           4
+#define ES_ERROR            EVENT_SHIFT(ERR, READ)
+#define ES_TIMEOUT          EVENT_SHIFT(ERR, WRITE)
+#define MANAGEMENT_SHIFT    6
+#define MANAGEMENT_READ     EVENT_SHIFT(MANAGEMENT, READ)
+#define MANAGEMENT_WRITE    EVENT_SHIFT(MANAGEMENT, WRITE)
+#define FILE_SHIFT          8
+#define FILE_CLOSED         EVENT_SHIFT(FILE, READ)
+
 /*
  * Initialization flags passed to event_set_init
  */
src/openvpn/forward.c +8 -6
index df96d048..e302d8e0 100644
@@ -1867,15 +1867,17 @@ io_wait_dowork(struct context *c, const unsigned int flags)
     unsigned int tuntap = 0;
     struct event_set_return esr[4];
 
-    /* These shifts all depend on EVENT_READ and EVENT_WRITE */
-    static int socket_shift = 0;   /* depends on SOCKET_READ and SOCKET_WRITE */
-    static int tun_shift = 2;      /* depends on TUN_READ and TUN_WRITE */
-    static int err_shift = 4;      /* depends on ES_ERROR */
+    /* These shifts all depend on EVENT_READ (=1) and EVENT_WRITE (=2)
+     * and are added to the shift. Check openvpn.h for more details.
+     */
+    static int socket_shift = SOCKET_SHIFT;
+    static int tun_shift = TUN_SHIFT;
+    static int err_shift = ERR_SHIFT;
 #ifdef ENABLE_MANAGEMENT
-    static int management_shift = 6; /* depends on MANAGEMENT_READ and MANAGEMENT_WRITE */
+    static int management_shift = MANAGEMENT_SHIFT;
 #endif
 #ifdef ENABLE_ASYNC_PUSH
-    static int file_shift = 8;     /* listening inotify events */
+    static int file_shift = FILE_SHIFT;
 #endif
 
     /*
src/openvpn/openvpn.h +1 -11
index a15ff08d..6e4651cf 100644
@@ -232,17 +232,7 @@ struct context_2
     int event_set_max;
     bool event_set_owned;
 
-    /* event flags returned by io_wait */
-#define SOCKET_READ       (1<<0)
-#define SOCKET_WRITE      (1<<1)
-#define TUN_READ          (1<<2)
-#define TUN_WRITE         (1<<3)
-#define ES_ERROR          (1<<4)
-#define ES_TIMEOUT        (1<<5)
-#define MANAGEMENT_READ  (1<<6)
-#define MANAGEMENT_WRITE (1<<7)
-#define FILE_CLOSED       (1<<8)
-
+    /* bitmask for event status. Check event.h for possible values */
     unsigned int event_set_status;
 
     struct link_socket *link_socket;     /* socket used for TCP/UDP connection to remote */
Signature · 1 line
2.26.3
#14 lore raw

PATCH v5 1/1 Add documentation on EVENT_READ/EVENT_WRITE constants

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

Changes from v4:
- get rid of the overly complex EVENT_SHIFT() macro

Changes from v3:
- re-introduce READ/WRITE_SHIFT because they are different from EVENT_READ/WRITE
- define also EVENT_READ/WRITE using READ/WRITE_SHIFT

Changes from v2:
- moved event definitions to event.h
- removed READ/WRITE_SHIFT and use EVENT_READ/WRITE
- removed ifdefs around *_SHIFTS definitions in event.h

Changes from v1:
- fixed typ0s
- extended comment
- moved *_SHIFT definition to openvpn.h
- made READ/WRITE events dependant on _SHIFT definition with a macro

---
 src/openvpn/event.h   | 44 ++++++++++++++++++++++++++++++++++++++++---
 src/openvpn/forward.c | 14 ++++++++------
 src/openvpn/openvpn.h | 12 +-----------
 3 files changed, 50 insertions(+), 20 deletions(-)
src/openvpn/event.h +41 -3
index 4af6371e..ce9c31a2 100644
@@ -32,9 +32,47 @@
  * rwflags passed to event_ctl and returned by
  * struct event_set_return.
  */
-#define EVENT_UNDEF    4
-#define EVENT_READ     (1<<0)
-#define EVENT_WRITE    (1<<1)
+#define READ_SHIFT      0
+#define WRITE_SHIFT     1
+
+#define EVENT_UNDEF     4
+#define EVENT_READ      (1 << READ_SHIFT)
+#define EVENT_WRITE     (1 << WRITE_SHIFT)
+
+/* event flags returned by io_wait.
+ *
+ * All these events are defined as bits in a bitfield.
+ * Each event 'type' owns two bits in the bitfield: one for the READ
+ * event and one for the WRITE event.
+ *
+ * For this reason, the specific event bit is calculated by adding
+ * the event type identifier (always a multiple of 2, as defined
+ * below) to 0 for READ and 1 for WRITE.
+ *
+ * E.g.
+ * MANAGEMENT_SHIFT = 6;  <---- event type identifier
+ * MANAGEMENT_READ = (1 << (6 + 0)),  <---- READ event
+ * MANAGEMENT_WRITE = (1 << (6 + 1))  <---- WRITE event
+ *
+ * 'error' and 'file_close' are special and use read/write for different
+ * signals.
+ */
+
+#define SOCKET_SHIFT        0
+#define SOCKET_READ         (1 << (SOCKET_SHIFT + READ_SHIFT))
+#define SOCKET_WRITE        (1 << (SOCKET_SHIFT + WRITE_SHIFT))
+#define TUN_SHIFT           2
+#define TUN_READ            (1 << (TUN_SHIFT + READ_SHIFT))
+#define TUN_WRITE           (1 << (TUN_SHIFT + WRITE_SHIFT))
+#define ERR_SHIFT           4
+#define ES_ERROR            (1 << (ERR_SHIFT + READ_SHIFT))
+#define ES_TIMEOUT          (1 << (ERR_SHIFT + WRITE_SHIFT))
+#define MANAGEMENT_SHIFT    6
+#define MANAGEMENT_READ     (1 << (MANAGEMENT_SHIFT + READ_SHIFT))
+#define MANAGEMENT_WRITE    (1 << (MANAGEMENT_SHIFT + WRITE_SHIFT))
+#define FILE_SHIFT          8
+#define FILE_CLOSED         (1 << (FILE_SHIFT + READ_SHIFT))
+
 /*
  * Initialization flags passed to event_set_init
  */
src/openvpn/forward.c +8 -6
index df96d048..e302d8e0 100644
@@ -1867,15 +1867,17 @@ io_wait_dowork(struct context *c, const unsigned int flags)
     unsigned int tuntap = 0;
     struct event_set_return esr[4];
 
-    /* These shifts all depend on EVENT_READ and EVENT_WRITE */
-    static int socket_shift = 0;   /* depends on SOCKET_READ and SOCKET_WRITE */
-    static int tun_shift = 2;      /* depends on TUN_READ and TUN_WRITE */
-    static int err_shift = 4;      /* depends on ES_ERROR */
+    /* These shifts all depend on EVENT_READ (=1) and EVENT_WRITE (=2)
+     * and are added to the shift. Check openvpn.h for more details.
+     */
+    static int socket_shift = SOCKET_SHIFT;
+    static int tun_shift = TUN_SHIFT;
+    static int err_shift = ERR_SHIFT;
 #ifdef ENABLE_MANAGEMENT
-    static int management_shift = 6; /* depends on MANAGEMENT_READ and MANAGEMENT_WRITE */
+    static int management_shift = MANAGEMENT_SHIFT;
 #endif
 #ifdef ENABLE_ASYNC_PUSH
-    static int file_shift = 8;     /* listening inotify events */
+    static int file_shift = FILE_SHIFT;
 #endif
 
     /*
src/openvpn/openvpn.h +1 -11
index a15ff08d..6e4651cf 100644
@@ -232,17 +232,7 @@ struct context_2
     int event_set_max;
     bool event_set_owned;
 
-    /* event flags returned by io_wait */
-#define SOCKET_READ       (1<<0)
-#define SOCKET_WRITE      (1<<1)
-#define TUN_READ          (1<<2)
-#define TUN_WRITE         (1<<3)
-#define ES_ERROR          (1<<4)
-#define ES_TIMEOUT        (1<<5)
-#define MANAGEMENT_READ  (1<<6)
-#define MANAGEMENT_WRITE (1<<7)
-#define FILE_CLOSED       (1<<8)
-
+    /* bitmask for event status. Check event.h for possible values */
     unsigned int event_set_status;
 
     struct link_socket *link_socket;     /* socket used for TCP/UDP connection to remote */
Signature · 1 line
2.26.3
author Acked-by on v5 1/1
#15 lore raw

Re: [Openvpn-devel] [PATCH v5] Add documentation on EVENT_READ/EVENT_WRITE constants

Am 27.04.21 um 21:13 schrieb Antonio Quartulli:

Quoted 14 lines

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

Changes from v4:
- get rid of the overly complex EVENT_SHIFT() macro

Changes from v3:
- re-introduce READ/WRITE_SHIFT because they are different from EVENT_READ/WRITE
- define also EVENT_READ/WRITE using READ/WRITE_SHIFT

Changes from v2:
- moved event definitions to event.h
- removed READ/WRITE_SHIFT and use EVENT_READ/WRITE
- removed ifdefs around *_SHIFTS definitions in event.h

Quoted 5 lines

Changes from v1:
- fixed typ0s
- extended comment
- moved *_SHIFT definition to openvpn.h
- made READ/WRITE events dependant on _SHIFT definition with a macro

Arne

#16 lore raw

[Openvpn-devel] [PATCH applied] Re: Add documentation on EVENT_READ/EVENT_WRITE constants

In reply to Antonio Quartulli

I've done a quick stare-on-code and ran the client side tests on FreeBSD, and all worked.

Your patch has been applied to the master branch.

commit c2912912047fdd228faedb6466672288e14dbba6

Author: Antonio Quartulli
Date:   Tue Apr 27 21:13:14 2021 +0200
     Add documentation on EVENT_READ/EVENT_WRITE constants

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

--
kind regards,

Gert Doering