[M] Change in openvpn[master]: multipeer: Add support for peer entries in config
"plaisthos \(Code Review\) via Openvpn-devel" <[email protected]> Sun, 26 Jul 2026 00:06:49 +0000
| Newsgroups | gmane.network.openvpn.devel |
|---|---|
| Message-ID | <[email protected]> |
plaisthos has uploaded this change for review. ( http://gerrit.openvpn.net/c/openvpn/+/1823?usp=email ) Change subject: multipeer: Add support for peer entries in config ...................................................................... multipeer: Add support for peer entries in config This only adds support for parsing the peer section and the scaffolding around it. Change-Id: I88143b503be3394b96639d0566d084a208f4770b Signed-off-by: Arne Schwabe <[email protected]> --- M src/openvpn/options.c M src/openvpn/options.h 2 files changed, 80 insertions(+), 13 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/23/1823/1 diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 629652e..8ce86ba 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -922,6 +922,10 @@ { CLEAR(*o->connection_list); } + if (o->peer_list) + { + CLEAR(*o->peer_list); + } if (o->remote_list) { CLEAR(*o->remote_list); @@ -1582,21 +1586,26 @@ #ifndef ENABLE_SMALL static void -show_connection_entry(const struct connection_entry *o) +show_local_list(const struct connection_entry *e) { /* Display the global proto only in client mode or with no '--local'*/ - if (o->local_list->len == 1) + if (e->local_list->len == 1) { - msg(D_SHOW_PARMS, " proto = %s", proto2ascii(o->proto, o->af, false)); + msg(D_SHOW_PARMS, " proto = %s", proto2ascii(e->proto, e->af, false)); } msg(D_SHOW_PARMS, " Local Sockets:"); - for (int i = 0; i < o->local_list->len; i++) + for (int i = 0; i < e->local_list->len; i++) { - msg(D_SHOW_PARMS, " [%s]:%s-%s", o->local_list->array[i]->local, - o->local_list->array[i]->port, - proto2ascii(o->local_list->array[i]->proto, o->af, false)); + msg(D_SHOW_PARMS, " [%s]:%s-%s", e->local_list->array[i]->local, + e->local_list->array[i]->port, + proto2ascii(e->local_list->array[i]->proto, e->af, false)); } +} + +static void +show_connection_entry(const struct connection_entry *o) +{ SHOW_STR(remote); SHOW_STR(remote_port); SHOW_BOOL(remote_float); @@ -1637,6 +1646,19 @@ SHOW_STR_INLINE(tls_crypt_v2_file); } +static void +show_peer_entries(const struct options *o) +{ + if (o->peer_list) + { + const struct connection_list *l = o->peer_list; + for (int i = 0; i < l->len; ++i) + { + msg(D_SHOW_PARMS, "Peer entry [%d]:", i); + show_connection_entry(l->array[i]); + } + } +} static void show_connection_entries(const struct options *o) @@ -1648,12 +1670,14 @@ for (i = 0; i < l->len; ++i) { msg(D_SHOW_PARMS, "Connection profiles [%d]:", i); + show_local_list(l->array[i]); show_connection_entry(l->array[i]); } } else { msg(D_SHOW_PARMS, "Connection profiles [default]:"); + show_local_list(&o->ce); show_connection_entry(&o->ce); } msg(D_SHOW_PARMS, "Connection profiles END"); @@ -1702,6 +1726,7 @@ SHOW_INT(connect_retry_max); show_connection_entries(o); + show_peer_entries(o); SHOW_BOOL(remote_random); @@ -2079,20 +2104,20 @@ return e; } + static struct connection_list * -alloc_connection_list_if_undef(struct options *options) +alloc_connection_list_if_undef(struct options *options, struct connection_list **connection_list) { - if (!options->connection_list) + if (!*connection_list) { - ALLOC_OBJ_CLEAR_GC(options->connection_list, struct connection_list, &options->gc); + ALLOC_OBJ_CLEAR_GC(*connection_list, struct connection_list, &options->gc); } - return options->connection_list; + return *connection_list; } static struct connection_entry * -alloc_connection_entry(struct options *options, const msglvl_t msglevel) +alloc_connection_list_entry(struct options *options, struct connection_list *l, const msglvl_t msglevel) { - struct connection_list *l = alloc_connection_list_if_undef(options); struct connection_entry *e; if (l->len == l->capacity) @@ -2115,6 +2140,21 @@ return e; } +static struct connection_entry * +alloc_connection_entry(struct options *options, const msglvl_t msglevel) +{ + struct connection_list *l = alloc_connection_list_if_undef(options, &options->connection_list); + return alloc_connection_list_entry(options, l, msglevel); +} + +static struct connection_entry * +alloc_peer_entry(struct options *options, const msglvl_t msglevel) +{ + struct connection_list *l = alloc_connection_list_if_undef(options, &options->peer_list); + return alloc_connection_list_entry(options, l, msglevel); +} + + static struct remote_list * alloc_remote_list_if_undef(struct options *options) { @@ -6065,6 +6105,31 @@ uninit_options(&sub); } } + else if (streq(p[0], "peer") && !p[2]) + { + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INLINE); + if (is_inline) + { + struct options sub; + struct connection_entry *e; + init_options(&sub); + + read_config_string("[PEER-OPTIONS]", &sub, p[1], msglevel, OPT_P_CONNECTION, + option_types_found, es); + + if (!sub.ce.remote) + { + msg(msglevel, + "Each 'connection' block must contain exactly one 'remote' directive"); + uninit_options(&sub); + goto err; + } + e = alloc_peer_entry(options, msglevel); + *e = sub.ce; + gc_transfer(&options->gc, &sub.gc); + uninit_options(&sub); + } + } else if (streq(p[0], "ignore-unknown-option") && p[1]) { int i; diff --git a/src/openvpn/options.h b/src/openvpn/options.h index ffabba4..353a9a4 100644 --- a/src/openvpn/options.h +++ b/src/openvpn/options.h @@ -293,6 +293,7 @@ int connect_retry_max; struct connection_entry ce; struct connection_list *connection_list; + struct connection_list *peer_list; struct remote_list *remote_list; /* Do not advance the connection or remote addr list */ @@ -758,6 +759,7 @@ #define OPT_P_INLINE (1u << 29) #define OPT_P_PUSH_MTU (1u << 30) #define OPT_P_ROUTE_TABLE (1u << 31) +#define OPT_P_PEER (1u << 32) #define OPT_P_DEFAULT (~(OPT_P_INSTANCE | OPT_P_PULL_MODE)) -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1823?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: I88143b503be3394b96639d0566d084a208f4770b Gerrit-Change-Number: 1823 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