[M] Change in openvpn[master]: Introduce CM_PEER_TCP and CM_PEER_UDP
"plaisthos \(Code Review\) via Openvpn-devel" <[email protected]> Sun, 26 Jul 2026 00:06:48 +0000
| Newsgroups | gmane.network.openvpn.devel |
|---|---|
| Message-ID | <[email protected]> |
plaisthos has uploaded this change for review. ( http://gerrit.openvpn.net/c/openvpn/+/1822?usp=email ) Change subject: Introduce CM_PEER_TCP and CM_PEER_UDP ...................................................................... Introduce CM_PEER_TCP and CM_PEER_UDP These new context modes will be used by the peer connections initiated in the multipeer context. Currently these are not yet used. This also adds inline functions to make the checks better readable instead of having long list of x == CM_a || x == CM_b in all the statements. Change-Id: I2dd3bad7acbf6a70b3b7f4aa0b0f6b902797f46d Signed-off-by: Arne Schwabe <[email protected]> --- M doc/doxygen/doc_tunnel_state.h M src/openvpn/dco.c M src/openvpn/init.c M src/openvpn/openvpn.h M src/openvpn/socket.c 5 files changed, 69 insertions(+), 35 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/22/1822/1 diff --git a/doc/doxygen/doc_tunnel_state.h b/doc/doxygen/doc_tunnel_state.h index 296e804..4a8b91e 100644 --- a/doc/doxygen/doc_tunnel_state.h +++ b/doc/doxygen/doc_tunnel_state.h @@ -127,8 +127,9 @@ * To distinguish this object from other instances of the same type, its * \c context.mode value is set to \c CM_TOP. Other \c context objects, * which do represent active VPN tunnels, have a \c context.mode set to \c - * CM_CHILD_UDP or \c CM_CHILD_TCP, depending on the external transport - * protocol. + * CM_CHILD_UDP, \c CM_CHILD_TCP, \C CM_PEER_UDP, or \c CM_PEER_TCP, + * depending on the external transport protocol and which side initiated + * the tunnel. * * Both \c tunnel_server_udp_single_threaded() and \c tunnel_server_tcp() * perform similar initialization. In either case, a \c multi_context diff --git a/src/openvpn/dco.c b/src/openvpn/dco.c index ce73701..d4beb04 100644 --- a/src/openvpn/dco.c +++ b/src/openvpn/dco.c @@ -633,7 +633,7 @@ const socket_descriptor_t sd = c->c2.link_sockets[0]->sd; - if (c->mode == CM_CHILD_TCP) + if (cm_mode_child_tcp(c->mode)) { /* the remote address will be inferred from the TCP socket endpoint */ remoteaddr = NULL; diff --git a/src/openvpn/init.c b/src/openvpn/init.c index e300af1..0e649f8 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -2770,16 +2770,13 @@ int sec = 2; int backoff = 0; - switch (c->mode) + if (c->mode == CM_TOP) { - case CM_TOP: - sec = 1; - break; - - case CM_CHILD_UDP: - case CM_CHILD_TCP: - sec = c->options.ce.connect_retry_seconds; - break; + sec = 1; + } + else if (cm_mode_child(c->mode)) + { + sec = c->options.ce.connect_retry_seconds; } #ifdef ENABLE_DEBUG @@ -2795,7 +2792,7 @@ } /* Slow down reconnection after 5 retries per remote -- for TCP client or UDP tls-client only */ - if (c->mode == CM_CHILD_TCP || (c->options.ce.proto == PROTO_UDP && c->options.tls_client)) + if (cm_mode_child_tcp(c->mode) || (c->options.ce.proto == PROTO_UDP && c->options.tls_client)) { backoff = (c->options.unsuccessful_attempts / c->options.connection_list->len) - 4; if (backoff > 0) @@ -3317,6 +3314,11 @@ { to.push_peer_info_detail = 2; } + else if (c->mode == CM_PEER_TCP || c->mode == CM_PEER_UDP) + { + /* connection initiated by us that requires pushing some information */ + to.push_peer_info_detail = 1; + } else if (options->mode == MODE_SERVER) /* server: no peer info at all */ { to.push_peer_info_detail = 0; @@ -4438,7 +4440,6 @@ init_instance(struct context *c, const struct env_set *env, const unsigned int flags) { const struct options *options = &c->options; - const bool child = (c->mode == CM_CHILD_TCP || c->mode == CM_CHILD_UDP); /* init garbage collection level */ gc_init(&c->c2.gc); @@ -4530,7 +4531,7 @@ } /* reset OCC state */ - if (c->mode == CM_P2P || child) + if (c->mode == CM_P2P || cm_mode_child(c->mode)) { c->c2.occ_op = occ_reset_op(); } @@ -4540,7 +4541,7 @@ { do_event_set_init(c, SHAPER_DEFINED(&c->options)); } - else if (c->mode == CM_CHILD_TCP) + else if (cm_mode_child_tcp(c->mode)) { do_event_set_init(c, false); } @@ -4549,14 +4550,14 @@ init_proxy(c); /* allocate our socket object */ - if (c->mode == CM_P2P || c->mode == CM_TOP || c->mode == CM_CHILD_TCP) + if (c->mode == CM_P2P || c->mode == CM_TOP || cm_mode_child_tcp(c->mode)) { do_link_socket_new(c); } #ifdef ENABLE_FRAGMENT /* initialize internal fragmentation object */ - if (options->ce.fragment && (c->mode == CM_P2P || child)) + if (options->ce.fragment && (c->mode == CM_P2P || cm_mode_child(c->mode))) { c->c2.fragment = fragment_init(&c->c2.frame); } @@ -4573,12 +4574,12 @@ { crypto_flags = CF_LOAD_PERSISTED_PACKET_ID | CF_INIT_TLS_MULTI; } - else if (child) + else if (cm_mode_child(c->mode)) { crypto_flags = CF_INIT_TLS_MULTI; } do_init_crypto(c, crypto_flags); - if (IS_SIG(c) && !child) + if (IS_SIG(c) && !cm_mode_child(c->mode)) { goto sig; } @@ -4586,7 +4587,7 @@ #ifdef USE_COMP /* initialize compression library. */ - if (comp_enabled(&options->comp) && (c->mode == CM_P2P || child)) + if (comp_enabled(&options->comp) && (c->mode == CM_P2P || cm_mode_child(c->mode))) { c->c2.comp_context = comp_init(&options->comp); } @@ -4599,21 +4600,21 @@ do_init_frame_tls(c); /* init workspace buffers whose size is derived from frame size */ - if (c->mode == CM_P2P || c->mode == CM_CHILD_TCP) + if (c->mode == CM_P2P || cm_mode_child_tcp(c->mode)) { do_init_buffers(c); } #ifdef ENABLE_FRAGMENT /* initialize internal fragmentation capability with known frame size */ - if (options->ce.fragment && (c->mode == CM_P2P || child)) + if (options->ce.fragment && (c->mode == CM_P2P || cm_mode_child(c->mode))) { do_init_fragment(c); } #endif /* bind the TCP/UDP socket */ - if (c->mode == CM_P2P || c->mode == CM_TOP || c->mode == CM_CHILD_TCP) + if (c->mode == CM_P2P || c->mode == CM_TOP || cm_mode_child_tcp(c->mode)) { do_init_socket_phase1(c); } @@ -4630,7 +4631,7 @@ do_print_data_channel_mtu_parms(c); /* get local and remote options compatibility strings */ - if (c->mode == CM_P2P || child) + if (c->mode == CM_P2P || cm_mode_child(c->mode)) { do_compute_occ_strings(c); } @@ -4656,7 +4657,7 @@ do_init_server_poll_timeout(c); /* finalize the TCP/UDP socket */ - if (c->mode == CM_P2P || c->mode == CM_TOP || c->mode == CM_CHILD_TCP) + if (c->mode == CM_P2P || c->mode == CM_TOP || cm_mode_child_tcp(c->mode)) { do_init_socket_phase2(c); @@ -4679,7 +4680,7 @@ do_uid_gid_chroot(c, c->c2.did_open_tun); /* initialize timers */ - if (c->mode == CM_P2P || child) + if (c->mode == CM_P2P || cm_mode_child(c->mode)) { do_init_timers(c, false); } @@ -4749,7 +4750,7 @@ /* close event objects */ do_close_event_set(c); - if (c->mode == CM_P2P || c->mode == CM_CHILD_TCP || c->mode == CM_CHILD_UDP + if (c->mode == CM_P2P || cm_mode_child(c->mode) || c->mode == CM_TOP) { #ifdef USE_COMP @@ -4875,7 +4876,7 @@ dest->c1.tuntap = src->c1.tuntap; /* UDP inherits some extra things which TCP does not */ - if (dest->mode == CM_CHILD_UDP) + if (cm_mode_child_udp(dest->mode)) { ASSERT(!dest->c2.link_sockets); ASSERT(dest->options.ce.local_list); diff --git a/src/openvpn/openvpn.h b/src/openvpn/openvpn.h index fa00822..d5a9bea 100644 --- a/src/openvpn/openvpn.h +++ b/src/openvpn/openvpn.h @@ -479,12 +479,16 @@ #define CM_P2P 0 /* standalone point-to-point session or client */ #define CM_TOP 1 /* top level of a multi-client or point-to-multipoint server */ #define CM_TOP_CLONE 2 /* clone of a CM_TOP context for one thread */ -#define CM_CHILD_UDP 3 /* child context of a CM_TOP or CM_THREAD */ -#define CM_CHILD_TCP 4 /* child context of a CM_TOP or CM_THREAD */ +#define CM_CHILD_UDP 3 /* child context of a CM_TOP */ +#define CM_CHILD_TCP 4 /* child context of a CM_TOP */ +#define CM_PEER_UDP 5 /* child context of a CM_TOP initiated by us */ +#define CM_PEER_TCP 6 /* child context of a CM_TOP initiated by us */ + int mode; /**< Role of this context within the * OpenVPN process. Valid values are \c * CM_P2P, \c CM_TOP, \c CM_TOP_CLONE, - * \c CM_CHILD_UDP, and \c CM_CHILD_TCP. */ + * \c CM_CHILD_UDP, \c CM_CHILD_TCP. + * \c CM_PEER_UDP, \c CM_PEER_TCP. */ struct multi_context *multi; /**< Pointer to the main P2MP context. * Non-NULL only when mode == CM_TOP. */ @@ -514,6 +518,34 @@ struct context_2 c2; /**< Level 2 %context. */ }; +static inline bool +cm_mode_child_tcp(int mode) +{ + return mode == CM_CHILD_TCP || mode == CM_PEER_TCP; +} + +static inline bool +cm_mode_child_udp(int mode) +{ + return mode == CM_CHILD_UDP || mode == CM_PEER_UDP; +} + +static inline bool +cm_mode_child(int mode) +{ + return cm_mode_child_udp(mode) || cm_mode_child_tcp(mode); +} + +/** + * Return true if the mode context is a connection initiated by this + * server (peer) + */ +static inline bool +cm_mode_peer(int mode) +{ + return mode == CM_PEER_UDP || mode == CM_PEER_TCP; +} + /* * Check for a signal when inside an event loop */ diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c index b73a5df..6f49d1b 100644 --- a/src/openvpn/socket.c +++ b/src/openvpn/socket.c @@ -1336,14 +1336,14 @@ port = o->ce.local_port; } - if (c->mode == CM_CHILD_TCP || c->mode == CM_CHILD_UDP) + if (cm_mode_child(c->mode)) { struct link_socket *tmp_sock = NULL; - if (c->mode == CM_CHILD_TCP) + if (cm_mode_child_tcp(c->mode)) { tmp_sock = (struct link_socket *)c->c2.accept_from; } - else if (c->mode == CM_CHILD_UDP) + else if (cm_mode_child_udp(c->mode)) { tmp_sock = c->c2.link_sockets[0]; } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1822?usp=email To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I2dd3bad7acbf6a70b3b7f4aa0b0f6b902797f46d Gerrit-Change-Number: 1822 Gerrit-PatchSet: 1 Gerrit-Owner: plaisthos <[email protected]> Gerrit-CC: openvpn-devel <[email protected]> _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel