Skip to contentSkip to conversation

Inline function tls_get_peer_info

PATCH In review Arne Schwabe 3 participants 15 messages Oct 23, 2020 – Mar 31, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 Inline function tls_get_peer_info

All other places in our code also directly access peer_info and this function does not contribute to code clarity.

---
 src/openvpn/multi.c | 2 +-
 src/openvpn/ssl.h   | 8 --------
 2 files changed, 1 insertion(+), 9 deletions(-)
src/openvpn/multi.c +1 -1
index a5862020..009b46fa 100644
@@ -3993,7 +3993,7 @@ management_get_peer_info(void *arg, const unsigned long cid)
 
     if (mi)
     {
-        ret = tls_get_peer_info(mi->context.c2.tls_multi);
+        ret = mi->context.c2.tls_multi->peer_info;
     }
 
     return ret;
src/openvpn/ssl.h +0 -8
index f00f8abd..f3032dab 100644
@@ -499,14 +499,6 @@ bool tls_session_update_crypto_params(struct tls_session *session,
                                       struct frame *frame,
                                       struct frame *frame_fragment);
 
-#ifdef MANAGEMENT_DEF_AUTH
-static inline char *
-tls_get_peer_info(const struct tls_multi *multi)
-{
-    return multi->peer_info;
-}
-#endif
-
 /*
  * inline functions
  */
Signature · 1 line
2.26.2
#1 lore raw

PATCH 2/5 xmit_hold is only required for port_share

Make options.c only set xmit_hold when port_share is active to least document this dependency. I have not actually tested if this dependency is actually true (or if port_share could work without xmit_hold).

---
 src/openvpn/init.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/openvpn/init.c +4 -1
index 034edba0..fdd9a6cc 100644
@@ -2908,12 +2908,15 @@ do_init_crypto_tls(struct context *c, const unsigned int flags)
         to.push_peer_info_detail = 0;
     }
 
+#ifdef ENABLE_PORT_SHARE
     /* should we not xmit any packets until we get an initial
      * response from client? */
-    if (to.server && options->ce.proto == PROTO_TCP_SERVER)
+    if (to.server && options->ce.proto == PROTO_TCP_SERVER
+        && options->port_share_host)
     {
         to.xmit_hold = true;
     }
+#endif
 
     to.disable_occ = !options->occ;
 
Signature · 1 line
2.26.2
#8 lore raw

PATCH 3/5 Align reliable_free with other free methods to accept NULL

In reply to Arne Schwabe

The semantic of most free methods is to free a pointer and all its contents and also free the pointer itself. Align reliable_free to this semantic.

Also clean up the other free uses in key_state_free.

---
 src/openvpn/reliable.c |  5 +++++
 src/openvpn/reliable.h |  4 +++-
 src/openvpn/ssl.c      | 24 ++++--------------------
 3 files changed, 12 insertions(+), 21 deletions(-)
src/openvpn/reliable.c +5 -0
index eae1e0cb..6c1f2da1 100644
@@ -326,12 +326,17 @@ reliable_init(struct reliable *rel, int buf_size, int offset, int array_size, bo
 void
 reliable_free(struct reliable *rel)
 {
+    if (!rel)
+    {
+        return;
+    }
     int i;
     for (i = 0; i < rel->size; ++i)
     {
         struct reliable_entry *e = &rel->array[i];
         free_buf(&e->buf);
     }
+    free(rel);
 }
 
 /* no active buffers? */
src/openvpn/reliable.h +3 -1
index 688c65c8..a84d4290 100644
@@ -192,7 +192,9 @@ bool reliable_ack_write(struct reliable_ack *ack,
 void reliable_init(struct reliable *rel, int buf_size, int offset, int array_size, bool hold);
 
 /**
- * Free allocated memory associated with a reliable structure.
+ * Free allocated memory associated with a reliable structure and the pointer
+ * itself.
+ * Does nothing if rel is NULL.
  *
  * @param rel The reliable structured to clean up.
  */
src/openvpn/ssl.c +4 -20
index 87b51d96..7a3eb146 100644
@@ -969,27 +969,11 @@ key_state_free(struct key_state *ks, bool clear)
     free_buf(&ks->ack_write_buf);
     buffer_list_free(ks->paybuf);
 
-    if (ks->send_reliable)
-    {
-        reliable_free(ks->send_reliable);
-        free(ks->send_reliable);
-    }
-
-    if (ks->rec_reliable)
-    {
-        reliable_free(ks->rec_reliable);
-        free(ks->rec_reliable);
-    }
+    reliable_free(ks->send_reliable);
+    reliable_free(ks->rec_reliable);
 
-    if (ks->rec_ack)
-    {
-        free(ks->rec_ack);
-    }
-
-    if (ks->key_src)
-    {
-        free(ks->key_src);
-    }
+    free(ks->rec_ack);
+    free(ks->key_src);
 
     packet_id_free(&ks->crypto_options.packet_id);
 
Signature · 1 line
2.26.2
#10 lore raw

PATCH 4/5 Remove explicit setting of peer_id to false

In reply to Arne Schwabe

Almost everywhere in OpenVPN we rely on zero initialisation to initialise all bool attributes to false.

ret is cleared by ALLOC_OBJ_CLEAR(ret, struct tls_multi);

Having this one variable treated different is a bit confusing.

---
 src/openvpn/ssl.c | 3 ---
 1 file changed, 3 deletions(-)
src/openvpn/ssl.c +0 -3
index 7a3eb146..f6f06fa9 100644
@@ -1219,9 +1219,6 @@ tls_multi_init(struct tls_options *tls_options)
     ret->key_scan[1] = &ret->session[TM_ACTIVE].key[KS_LAME_DUCK];
     ret->key_scan[2] = &ret->session[TM_LAME_DUCK].key[KS_LAME_DUCK];
 
-    /* By default not use P_DATA_V2 */
-    ret->use_peer_id = false;
-
     return ret;
 }
 
Signature · 1 line
2.26.2
#12 lore raw

PATCH 5/5 Remove NULL checks before calling free

In reply to Arne Schwabe

We (and OpenSSL) already use calling free on null pointers in a number of places and also C99 standards says free(NULL) does nothing.

The if (x) free(x) calls more often make code harder to read, instead of easier, remove these NULL checks in favour of directly calling free(x).

The OpenSSL *_free methods are also safe to call with NULL and pkcs11h_certificate_freeCertificateIdList is also safe to be called with NULL.

---
 .../client-connect/sample-client-connect.c    |  5 +-
 src/openvpn/buffer.c                          |  5 +-
 src/openvpn/error.c                           |  7 +--
 src/openvpn/init.c                            | 11 ++---
 src/openvpn/manage.c                          | 37 +++++---------
 src/openvpn/mtcp.c                            |  5 +-
 src/openvpn/multi.c                           | 10 +---
 src/openvpn/packet_id.c                       |  5 +-
 src/openvpn/pkcs11.c                          | 49 ++++++-------------
 src/openvpn/pkcs11_openssl.c                  | 28 +++--------
 src/openvpn/proxy.c                           |  5 +-
 src/openvpn/ssl.c                             | 17 ++-----
 src/openvpn/ssl_mbedtls.c                     | 36 +++-----------
 src/openvpn/ssl_openssl.c                     | 47 ++++--------------
 src/openvpn/ssl_verify.c                      |  8 ++-
 src/openvpn/ssl_verify_openssl.c              |  6 +--
 src/openvpn/status.c                          |  6 +--
 src/openvpn/tun.c                             | 16 ++----
 src/plugins/auth-pam/auth-pam.c               |  5 +-
 src/plugins/down-root/down-root.c             |  5 +-
 20 files changed, 79 insertions(+), 234 deletions(-)
sample/sample-plugins/client-connect/sample-client-connect.c +1 -4
index 6168076f..7ed2f72c 100644
@@ -173,10 +173,7 @@ openvpn_plugin_open_v3(const int v3structver,
     return OPENVPN_PLUGIN_FUNC_SUCCESS;
 
 error:
-    if (context)
-    {
-        free(context);
-    }
+    free(context);
     return OPENVPN_PLUGIN_FUNC_ERROR;
 }
 
src/openvpn/buffer.c +1 -4
index b32bc8b2..35d9ecdc 100644
@@ -184,10 +184,7 @@ buf_assign(struct buffer *dest, const struct buffer *src)
 void
 free_buf(struct buffer *buf)
 {
-    if (buf->data)
-    {
-        free(buf->data);
-    }
+    free(buf->data);
     CLEAR(*buf);
 }
 
src/openvpn/error.c +2 -5
index d6247fec..7d0fcb2d 100644
@@ -488,11 +488,8 @@ close_syslog(void)
     {
         closelog();
         use_syslog = false;
-        if (pgmname_syslog)
-        {
-            free(pgmname_syslog);
-            pgmname_syslog = NULL;
-        }
+        free(pgmname_syslog);
+        pgmname_syslog = NULL;
     }
 #endif
 }
src/openvpn/init.c +3 -8
index fdd9a6cc..7a4bac58 100644
@@ -3600,14 +3600,9 @@ do_close_tls(struct context *c)
     }
 
     /* free options compatibility strings */
-    if (c->c2.options_string_local)
-    {
-        free(c->c2.options_string_local);
-    }
-    if (c->c2.options_string_remote)
-    {
-        free(c->c2.options_string_remote);
-    }
+    free(c->c2.options_string_local);
+    free(c->c2.options_string_remote);
+
     c->c2.options_string_local = c->c2.options_string_remote = NULL;
 
     if (c->c2.pulled_options_state)
src/openvpn/manage.c +13 -24
index ac142177..85bd1227 100644
@@ -826,14 +826,8 @@ man_pkcs11_id_get(struct management *man, const int index)
         msg(M_CLIENT, ">PKCS11ID-ENTRY:'%d'", index);
     }
 
-    if (id != NULL)
-    {
-        free(id);
-    }
-    if (base64 != NULL)
-    {
-        free(base64);
-    }
+    free(id);
+    free(base64);
 }
 
 #endif /* ifdef ENABLE_PKCS11 */
@@ -2613,10 +2607,7 @@ man_connection_close(struct management *man)
 {
     struct man_connection *mc = &man->connection;
 
-    if (mc->es)
-    {
-        event_free(mc->es);
-    }
+    event_free(mc->es);
 #ifdef _WIN32
     net_event_win32_close(&mc->ne32);
 #endif
@@ -2629,14 +2620,10 @@ man_connection_close(struct management *man)
     {
         man_close_socket(man, mc->sd_cli);
     }
-    if (mc->in)
-    {
-        command_line_free(mc->in);
-    }
-    if (mc->out)
-    {
-        buffer_list_free(mc->out);
-    }
+
+    command_line_free(mc->in);
+    buffer_list_free(mc->out);
+
     in_extra_reset(&man->connection, IER_RESET);
     buffer_list_free(mc->ext_key_input);
     man_connection_clear(mc);
@@ -3896,6 +3883,10 @@ command_line_reset(struct command_line *cl)
 void
 command_line_free(struct command_line *cl)
 {
+    if (!cl)
+    {
+        return;
+    }
     command_line_reset(cl);
     free_buf(&cl->buf);
     free_buf(&cl->residual);
@@ -4015,10 +4006,8 @@ log_entry_print(const struct log_entry *e, unsigned int flags, struct gc_arena *
 static void
 log_entry_free_contents(struct log_entry *e)
 {
-    if (e->string)
-    {
-        free((char *)e->string);
-    }
+    /* Cast away constness of const char* */
+    free((char *)e->string);
     CLEAR(*e);
 }
 
src/openvpn/mtcp.c +1 -4
index 458e6e4c..22c824aa 100644
@@ -229,10 +229,7 @@ multi_tcp_free(struct multi_tcp *mtcp)
     if (mtcp)
     {
         event_free(mtcp->es);
-        if (mtcp->esr)
-        {
-            free(mtcp->esr);
-        }
+        free(mtcp->esr);
         free(mtcp);
     }
 }
src/openvpn/multi.c +2 -8
index 009b46fa..ad4ec1c2 100644
@@ -73,10 +73,7 @@ id(struct multi_instance *mi)
 static void
 set_cc_config(struct multi_instance *mi, struct buffer_list *cc_config)
 {
-    if (mi->cc_config)
-    {
-        buffer_list_free(mi->cc_config);
-    }
+    buffer_list_free(mi->cc_config);
     mi->cc_config = cc_config;
 }
 #endif
@@ -4016,10 +4013,7 @@ management_client_pf(void *arg,
         ret = pf_load_from_buffer_list(&mi->context, pf_config);
     }
 
-    if (pf_config)
-    {
-        buffer_list_free(pf_config);
-    }
+    buffer_list_free(pf_config);
     return ret;
 }
 #endif /* ifdef MANAGEMENT_PF */
src/openvpn/packet_id.c +1 -4
index 0c744875..2b9ef079 100644
@@ -103,10 +103,7 @@ packet_id_free(struct packet_id *p)
     if (p)
     {
         dmsg(D_PID_DEBUG, "PID packet_id_free");
-        if (p->rec.seq_list)
-        {
-            free(p->rec.seq_list);
-        }
+        free(p->rec.seq_list);
         CLEAR(*p);
     }
 }
src/openvpn/pkcs11.c +14 -35

73 lines not on this page · raw message

src/openvpn/pkcs11_openssl.c +8 -20
index 642769cc..a84bc635 100644
@@ -102,17 +102,11 @@ cleanup:
      * openssl objects have reference
      * count, so release them
      */
-    if (x509 != NULL)
-    {
-        X509_free(x509);
-        x509 = NULL;
-    }
+    X509_free(x509);
+    x509 = NULL;
 
-    if (evp != NULL)
-    {
-        EVP_PKEY_free(evp);
-        evp = NULL;
-    }
+    EVP_PKEY_free(evp);
+    evp = NULL;
 
     if (openssl_session != NULL)
     {
@@ -138,11 +132,8 @@ pkcs11_certificate_dn(pkcs11h_certificate_t certificate, struct gc_arena *gc)
     dn = x509_get_subject(x509, gc);
 
 cleanup:
-    if (x509 != NULL)
-    {
-        X509_free(x509);
-        x509 = NULL;
-    }
+    X509_free(x509);
+    x509 = NULL;
 
     return dn;
 }
@@ -183,12 +174,9 @@ pkcs11_certificate_serial(pkcs11h_certificate_t certificate, char *serial,
     ret = 0;
 
 cleanup:
+    X509_free(x509);
+    x509 = NULL;
 
-    if (x509 != NULL)
-    {
-        X509_free(x509);
-        x509 = NULL;
-    }
     return ret;
 }
 #endif /* defined(ENABLE_PKCS11) && defined(ENABLE_OPENSSL) */
src/openvpn/proxy.c +1 -4
index 9998623a..f390daed 100644
@@ -366,10 +366,7 @@ get_proxy_authenticate(socket_descriptor_t sd,
 static void
 store_proxy_authenticate(struct http_proxy_info *p, char *data)
 {
-    if (p->proxy_authenticate)
-    {
-        free(p->proxy_authenticate);
-    }
+    free(p->proxy_authenticate);
     p->proxy_authenticate = data;
 }
 
src/openvpn/ssl.c +3 -14
index f6f06fa9..53dad9ff 100644
@@ -1105,10 +1105,7 @@ tls_session_free(struct tls_session *session, bool clear)
         key_state_free(&session->key[i], false);
     }
 
-    if (session->common_name)
-    {
-        free(session->common_name);
-    }
+    free(session->common_name);
 
     cert_hash_free(session->cert_hash_set);
 
@@ -1297,16 +1294,8 @@ tls_multi_free(struct tls_multi *multi, bool clear)
     auth_set_client_reason(multi, NULL);
 
     free(multi->peer_info);
-
-    if (multi->locked_cn)
-    {
-        free(multi->locked_cn);
-    }
-
-    if (multi->locked_username)
-    {
-        free(multi->locked_username);
-    }
+    free(multi->locked_cn);
+    free(multi->locked_username);
 
     cert_hash_free(multi->locked_cert_hash_set);
 
src/openvpn/ssl_mbedtls.c +7 -29
index 11fbeae4..b30b6b9d 100644
@@ -138,53 +138,31 @@ tls_ctx_free(struct tls_root_ctx *ctx)
     if (ctx)
     {
         mbedtls_pk_free(ctx->priv_key);
-        if (ctx->priv_key)
-        {
-            free(ctx->priv_key);
-        }
+        free(ctx->priv_key);
 
         mbedtls_x509_crt_free(ctx->ca_chain);
-        if (ctx->ca_chain)
-        {
-            free(ctx->ca_chain);
-        }
+        free(ctx->ca_chain);
 
         mbedtls_x509_crt_free(ctx->crt_chain);
-        if (ctx->crt_chain)
-        {
-            free(ctx->crt_chain);
-        }
+        free(ctx->crt_chain);
 
         mbedtls_dhm_free(ctx->dhm_ctx);
-        if (ctx->dhm_ctx)
-        {
-            free(ctx->dhm_ctx);
-        }
+        free(ctx->dhm_ctx);
 
         mbedtls_x509_crl_free(ctx->crl);
-        if (ctx->crl)
-        {
-            free(ctx->crl);
-        }
+        free(ctx->crl);
 
 #if defined(ENABLE_PKCS11)
         pkcs11h_certificate_freeCertificate(ctx->pkcs11_cert);
 #endif
 
-        if (ctx->allowed_ciphers)
-        {
-            free(ctx->allowed_ciphers);
-        }
+        free(ctx->allowed_ciphers);
 
-        if (ctx->groups)
-        {
-            free(ctx->groups);
-        }
+        free(ctx->groups);
 
         CLEAR(*ctx);
 
         ctx->initialised = false;
-
     }
 }
 
src/openvpn/ssl_openssl.c +10 -37

84 lines not on this page · raw message

src/openvpn/ssl_verify.c +3 -5
index 2d7abdde..95d8c918 100644
@@ -841,11 +841,9 @@ cleanup:
 void
 auth_set_client_reason(struct tls_multi *multi, const char *client_reason)
 {
-    if (multi->client_reason)
-    {
-        free(multi->client_reason);
-        multi->client_reason = NULL;
-    }
+    free(multi->client_reason);
+    multi->client_reason = NULL;
+
     if (client_reason && strlen(client_reason))
     {
         multi->client_reason = string_alloc(client_reason, NULL);
src/openvpn/ssl_verify_openssl.c +1 -5
index 39d381a1..d063aeda 100644
@@ -372,11 +372,7 @@ x509_get_subject(X509 *cert, struct gc_arena *gc)
     subject[subject_mem->length] = '\0';
 
 err:
-    if (subject_bio)
-    {
-        BIO_free(subject_bio);
-    }
-
+    BIO_free(subject_bio);
     return subject;
 }
 
src/openvpn/status.c +2 -4
index e8dcf7cd..11e24ae4 100644
@@ -203,10 +203,8 @@ status_close(struct status_output *so)
                 ret = false;
             }
         }
-        if (so->filename)
-        {
-            free(so->filename);
-        }
+        free(so->filename);
+
         if (buf_defined(&so->read_buf))
         {
             free_buf(&so->read_buf);
src/openvpn/tun.c +4 -12
index 8315a426..400a50ca 100644
@@ -1835,10 +1835,8 @@ close_tun_generic(struct tuntap *tt)
     {
         close(tt->fd);
     }
-    if (tt->actual_name)
-    {
-        free(tt->actual_name);
-    }
+
+    free(tt->actual_name);
     clear_tuntap(tt);
 }
 #endif /* !_WIN32 */
@@ -2522,10 +2520,7 @@ close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)
 
     solaris_close_tun(tt);
 
-    if (tt->actual_name)
-    {
-        free(tt->actual_name);
-    }
+    free(tt->actual_name);
 
     clear_tuntap(tt);
     free(tt);
@@ -6901,10 +6896,7 @@ close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)
         }
     }
 
-    if (tt->actual_name)
-    {
-        free(tt->actual_name);
-    }
+    free(tt->actual_name);
 
     if (tt->windows_driver == WINDOWS_DRIVER_WINTUN)
     {
src/plugins/auth-pam/auth-pam.c +1 -4
index f537652e..3d167233 100644
@@ -506,10 +506,7 @@ openvpn_plugin_open_v3(const int v3structver,
     }
 
 error:
-    if (context)
-    {
-        free(context);
-    }
+    free(context);
     return OPENVPN_PLUGIN_FUNC_ERROR;
 }
 
src/plugins/down-root/down-root.c +1 -4
index da445c61..7a3d34a0 100644
@@ -238,10 +238,7 @@ free_context(struct down_root_context *context)
 {
     if (context)
     {
-        if (context->command)
-        {
-            free(context->command);
-        }
+        free(context->command);
         free(context);
     }
 }
Signature · 1 line
2.26.2
Acked-by on v1 1/5
#14 lore raw
In reply to Arne Schwabe

"obviously correct" and a reasonable change.

Just a quick client side test (passed).

Your patch has been applied to the master branch.

commit 0d5aab889b0209cab9bb65f8bebf2adab5b1ff52

Author: Arne Schwabe
Date:   Fri Oct 23 13:34:27 2020 +0200
     Inline function tls_get_peer_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]/msg21217.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#2 lore raw

Re: [Openvpn-devel] [PATCH 2/5] xmit_hold is only required for port_share

In reply to Arne Schwabe

Hi,

Quoted 3 lines · Arne Schwabe

Make options.c only set xmit_hold when port_share is active to least document this dependency. I have not actually tested if this dependency is actually true (or if port_share could work without xmit_hold).

I'm not sure I understand this patch, or the flow. Before this patch, xmit_hold is always set to "true" for TCP_SERVER, after this patch, only for server *and* port_share.

What am I overlooking?

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 3/5
#9 lore raw

[Openvpn-devel] [PATCH applied] Re: Align reliable_free with other free methods to accept NULL

In reply to Arne Schwabe

Change brings this more in line with other code parts, so easier to understand.

Your patch has been applied to the master branch.

commit 2c8a9877617727438cdd874ecd38c04adebf53ad

Author: Arne Schwabe
Date:   Fri Oct 23 13:34:29 2020 +0200
     Align reliable_free with other free methods to accept NULL

     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]/msg21215.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

Acked-by on v1 5/5
#13 lore raw

[Openvpn-devel] [PATCH applied] Re: Remove NULL checks before calling free

In reply to Arne Schwabe

I have not verified the OpenSSL and pkcs11 free() functions, but the changes to our source tree (event_free() etc.) are consistent and make the code easier to read.

Passed a client side test (for good measure).

Your patch has been applied to the master branch.

commit cb70cf51889ee96446ba77a406bb2ac0f01dc174

Author: Arne Schwabe
Date:   Fri Oct 23 13:34:31 2020 +0200
     Remove NULL checks before calling free

     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]/msg21216.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

Acked-by on v1 4/5
#11 lore raw

[Openvpn-devel] [PATCH applied] Re: Remove explicit setting of peer_id to false

In reply to Arne Schwabe

I can see why this initalization was put there, initially, to make clear "P_DATA_V2 is not enabled by default" - but since we do not do this for all other "do not enable this $bool by default" initializations either, it is indeed an oddball and confuses more than it helps.

(If Lev yells at me that he really likes this particular line I can put it back, though :-) )

Your patch has been applied to the master branch.

commit 0d4ca79d4fc3c42b3970190f96781ed4f2552b32

Author: Arne Schwabe
Date:   Fri Oct 23 13:34:30 2020 +0200
     Remove explicit setting of peer_id to false

     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]/msg21218.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#3 lore raw

Re: [Openvpn-devel] [PATCH 2/5] xmit_hold is only required for port_share

In reply to Gert Doering

Am 24.10.20 um 21:43 schrieb Gert Doering:

Quoted 7 lines

Hi,

Quoted 3 lines · Arne Schwabe

Make options.c only set xmit_hold when port_share is active to least document this dependency. I have not actually tested if this dependency is actually true (or if port_share could work without xmit_hold).

Quoted 6 lines

I'm not sure I understand this patch, or the flow. Before this patch, xmit_hold is always set to "true" for TCP_SERVER, after this patch, only for server *and* port_share.

What am I overlooking?

No. This feature was introduced as part of port-share and I am not even sure it is really required for port-share. Normally we do not send anything unless there is a valid OpenVPN RESET packet. So I want to limit it again to part-share before I can really reliable say that even port-share doesn't need it.

Arne

#4 lore raw

Re: [Openvpn-devel] [PATCH 2/5] xmit_hold is only required for port_share

Hi,

Quoted 12 lines · Arne Schwabe

Am 24.10.20 um 21:43 schrieb Gert Doering:

Quoted 11 lines

Hi,

Quoted 3 lines · Arne Schwabe

Make options.c only set xmit_hold when port_share is active to least document this dependency. I have not actually tested if this dependency is actually true (or if port_share could work without xmit_hold).

I'm not sure I understand this patch, or the flow. Before this patch, xmit_hold is always set to "true" for TCP_SERVER, after this patch, only for server *and* port_share.

Quoted 9 lines
Quoted 2 lines

What am I overlooking?

No. This feature was introduced as part of port-share and I am not even sure it is really required for port-share. Normally we do not send anything unless there is a valid OpenVPN RESET packet. So I want to limit it again to part-share before I can really reliable say that even port-share doesn't need it.

To add some more meat to the discussion...
The xmit_hold option member was introduced by 6add6b2fe78c549d174729869e26cee917e31d5f ("Added --port-share option..."), so like Arne said it was added as aid of the port-share feature.

My understanding is that setting this member to true will prevent a peer from sending any control packet until reliable_schedule_now() is called for the first time.

Any idea why this could be helpful with port-share?
Maybe in 2006 an OpenVPN server could decide to send something even before having received the opening packet from the connecting client? If that's the case, then I understand the hold.

However, in the current code, reliable_schedule_now() is invoked when we do the first "burst" upon client connection.
This seems to happen right after receiving the first valid HARD_RESET packet.

For this reason I tend to agree with Arne that this "xmit_hold" knob is not really doing anything useful.

Anybody can see why we need that for port-share?
I'd rather try to understand the above and ditch this member entirely, if the answer is "we don't need it".

Cheers,

Signature · 1 line
Antonio Quartulli
#5 lore raw

Re: [Openvpn-devel] [PATCH 2/5] xmit_hold is only required for port_share

Hi,

Quoted 3 lines · Antonio Quartulli

Anybody can see why we need that for port-share?
I'd rather try to understand the above and ditch this member entirely, if the answer is "we don't need it".

After more tests I indeed recovered the reason why this is needed with port-share.

If we don't "hold back", upon connection the server will send its own SERVER_HARD_RESET, regardless of the client having sent a CLIENT_HARD_RESET or not.

This behaviour indeed breaks port-share because the non-OpenVPN application on the other side will receive an unexpected packet and will most likely kill the connection.

For this reason we need to hold any control channel packet until we have confirmed that the first packet is indeed a CLIENT_HARD_RESET.

Regarding TCP, the only thing I can think about is that this flag helps mimicking UDP: instead of sending the HARD_RESET right after a TCP Connection is opened, the server will wait for the client packet first.

In UDP I presume this is standard behaviour as we have no connection opening event.

My guess is that this behaviour may be useful to avoid race conditions on the client where the SERVER_HARD_RESET is received when still unexpected?

But maybe the code has evolved enough to not requiring this sequence of events anymore.

Cheers,

Signature · 1 line
Antonio Quartulli
#6 lore raw

Re: [Openvpn-devel] [PATCH 2/5] xmit_hold is only required for port_share

Hi,

Quoted 26 lines · Antonio Quartulli

Hi,

Quoted 3 lines · Antonio Quartulli

Anybody can see why we need that for port-share?
I'd rather try to understand the above and ditch this member entirely, if the answer is "we don't need it".

After more tests I indeed recovered the reason why this is needed with port-share.

If we don't "hold back", upon connection the server will send its own SERVER_HARD_RESET, regardless of the client having sent a CLIENT_HARD_RESET or not.

This behaviour indeed breaks port-share because the non-OpenVPN application on the other side will receive an unexpected packet and will most likely kill the connection.

For this reason we need to hold any control channel packet until we have confirmed that the first packet is indeed a CLIENT_HARD_RESET.

Regarding TCP, the only thing I can think about is that this flag helps mimicking UDP: instead of sending the HARD_RESET right after a TCP Connection is opened, the server will wait for the client packet first.

Quoted 6 lines

In UDP I presume this is standard behaviour as we have no connection opening event.

My guess is that this behaviour may be useful to avoid race conditions on the client where the SERVER_HARD_RESET is received when still unexpected?

As discussed on IRC we don't really need this "hold" behaviour in our protocol.

I may ask "why changing the current state though?", but I believe removing state variables from our code base (or some of its branches) is a good step towards simplification.

My last nitpick would be to change the commit message, since now we have clarified how this works:

----
The xmit_hold flag is used to tell OpenVPN to not send any packet out before a RESET is received from the other peer upon new connection.

The only real use case for setting this flag to true is when configuring OpenVPN with port-share (TCP).

The reason being that OpenVPN server should not send any packet until it is confirmed that the connection was established by an actual OpenVPN client. If the connection was established by a non-OpenVPN client, sending a RESET will mess up with the protocol sharing the port.
----

* Basic TCP connection tests passed.
* Compiled in my gitlab CI *WITH* issues:

MINGW32 both 32bit and 64bit failed:

i686-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I../.. -I../../include -I../../include -I../../src/compat -DWIN32_LEAN_AND_MEAN -DNTDDI_VERSION=NTDDI_VISTA -D_WIN32_WINNT=_WIN32_WINNT_VISTA -I/builds/ordex986/openvpn/tap-windows-9.21.2/include -I/root/opt/include -I/root/opt/include -I/root/opt/include -DPLUGIN_LIBDIR=\"/usr/local/lib/openvpn/plugins\" -municode -UUNICODE -Wall -Wno-unused-parameter -Wno-unused-function -Wno-stringop-truncation -g -O2 -std=c99 -MT lzo.o -MD -MP -MF .deps/lzo.Tpo -c -o lzo.o lzo.c
In file included from buffer.h:28,

                 from mtu.h:27,
                 from win32.h:30,
                 from init.c:36:

init.c: In function 'do_open_tun':
init.c:1809:62: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
msg(D_ROUTE, "interactive service msg_channel=%" PRIu64, (unsigned

long long) c->options.msg_channel);
                                                              ^

error.h:151:67: note: in definition of macro 'msg'
#define msg(flags, ...) do { if (msg_test(flags)) {x_msg((flags),
__VA_ARGS__);} EXIT_FATAL(flags); } while (false)

^~~~~~~~~~~
init.c: In function 'do_init_crypto_tls':
init.c:2889:19: error: 'const struct options' has no member named 'port_share_host'

         && options->port_share_host)
                   ^~

make[3]: *** [Makefile:743: init.o] Error 1

The first part is a warning that we can ignore for the sake of this patch.

The bottom part is the actual error.

Cheers,

Signature · 1 line
Antonio Quartulli
#7 lore raw

Re: [Openvpn-devel] [PATCH 2/5] xmit_hold is only required for port_share

Hi,

As discussed with Arne in our latest meeting, this patch will be ignored for now.
Hope was that the xmit_hold filed could be eventually removed, but it turned out it is actually needed.

For this reason there is no real interest at this point to carry on this change.

Regards,

Signature · 1 line
Antonio Quartulli