From: "cron2 (Code Review)" Date: Tue, 21 Apr 2026 14:22:06 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, ralf@...2726... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="Y9m7DFyQ0f4="; charset=UTF-8 Subject: [Openvpn-devel] [L] Change in openvpn[release/2.6]: dco: backport immediate notification processing on Linux and FreeBSD List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: ralf_lici Cc: plaisthos , openvpn-devel --Y9m7DFyQ0f4= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/16= 32?usp=3Demail ) Change subject: dco: backport immediate notification processing on Linux an= d FreeBSD ...................................................................... dco: backport immediate notification processing on Linux and FreeBSD Backport the immediate DCO message processing model from commit 7791f53 ("dco: process messages immediately after read"). Change the core DCO API from dco_do_read() to dco_read_and_process(), and make the backend read paths own the parsing and immediate handling of kernel notifications before handing the resulting state to process_incoming_dco() or multi_process_incoming_dco(). On Linux, install a permanent netlink callback and process GET_PEER and DEL_PEER messages as they are received, instead of switching callbacks for each read and deferring handling through shared DCO message state. Also add a small guard to avoid requesting peer stats while libnl is still parsing a batch of notifications. On FreeBSD, move notification handling into dco_read_and_process() and update peer statistics directly from the backend instead of storing temporary byte counters in dco_context_t. This commit is part of a reworked backport of PR #945 originally proposed by Nikolai Shelekhov . Github: OpenVPN/openvpn#900 Github: OpenVPN/openvpn#918 Github: OpenVPN/openvpn#931 Github: fixes OpenVPN/openvpn#919 Github: closes OpenVPN/openvpn#945 Change-Id: I92c5f74a27b40fede204f714b042a6cc80b3703e Signed-off-by: Ralf Lici Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1632 Message-Id: <20260421084906.5720-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg36= 707.html Signed-off-by: Gert Doering --- M src/openvpn/dco.h M src/openvpn/dco_freebsd.c M src/openvpn/dco_freebsd.h M src/openvpn/dco_linux.c M src/openvpn/dco_linux.h M src/openvpn/dco_win.c M src/openvpn/forward.c M src/openvpn/forward.h M src/openvpn/mtcp.c M src/openvpn/mudp.c M src/openvpn/multi.c M src/openvpn/multi.h 12 files changed, 299 insertions(+), 242 deletions(-) diff --git a/src/openvpn/dco.h b/src/openvpn/dco.h index 334d468..3a36ddc 100644 --- a/src/openvpn/dco.h +++ b/src/openvpn/dco.h @@ -128,12 +128,13 @@ void close_tun_dco(struct tuntap *tt, openvpn_net_ctx_t *ctx); /** - * Read data from the DCO communication channel (i.e. a control packet) + * Read and process data from the DCO communication channel + * (i.e. a control packet) * * @param dco the DCO context * @return 0 on success or a negative error code otherwise */ -int dco_do_read(dco_context_t *dco); +int dco_read_and_process(dco_context_t *dco); /** * Install a DCO in the main event loop @@ -300,7 +301,7 @@ } static inline int -dco_do_read(dco_context_t *dco) +dco_read_and_process(dco_context_t *dco) { ASSERT(false); return 0; diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c index b164bd3..9384bf1 100644 --- a/src/openvpn/dco_freebsd.c +++ b/src/openvpn/dco_freebsd.c @@ -560,8 +560,23 @@ return ret; } +static void +dco_update_peer_stat(struct multi_context *m, uint32_t peerid, const nvlis= t_t *nvl) +{ + if (peerid >=3D m->max_clients || !m->instances[peerid]) + { + msg(M_WARN, "dco_update_peer_stat: invalid peer ID %d returned by = kernel", peerid); + return; + } + + struct multi_instance *mi =3D m->instances[peerid]; + + mi->context.c2.dco_read_bytes =3D nvlist_get_number(nvl, "in"); + mi->context.c2.dco_write_bytes =3D nvlist_get_number(nvl, "out"); +} + int -dco_do_read(dco_context_t *dco) +dco_read_and_process(dco_context_t *dco) { struct ifdrv drv; uint8_t buf[4096]; @@ -592,9 +607,13 @@ return -EINVAL; } - dco->dco_message_peer_id =3D nvlist_get_number(nvl, "peerid"); + /* dco_message_peer_id is signed int, because other parts of the + * code treat "-1" as "this is a message not specific to one peer" + */ + dco->dco_message_peer_id =3D (int)nvlist_get_number(nvl, "peerid"); - type =3D nvlist_get_number(nvl, "notification"); + type =3D (enum ovpn_notif_type)nvlist_get_number(nvl, "notification"); + switch (type) { case OVPN_NOTIF_DEL_PEER: @@ -617,8 +636,15 @@ { const nvlist_t *bytes =3D nvlist_get_nvlist(nvl, "bytes"); - dco->dco_read_bytes =3D nvlist_get_number(bytes, "in"); - dco->dco_write_bytes =3D nvlist_get_number(bytes, "out"); + if (dco->c->mode =3D=3D CM_TOP) + { + dco_update_peer_stat(dco->c->multi, dco->dco_message_p= eer_id, bytes); + } + else + { + dco->c->c2.dco_read_bytes =3D nvlist_get_number(bytes,= "in"); + dco->c->c2.dco_write_bytes =3D nvlist_get_number(bytes= , "out"); + } } dco->dco_message_type =3D OVPN_CMD_DEL_PEER; @@ -628,7 +654,8 @@ dco->dco_message_type =3D OVPN_CMD_SWAP_KEYS; break; - case OVPN_NOTIF_FLOAT: { + case OVPN_NOTIF_FLOAT: + { const nvlist_t *address; if (!nvlist_exists_nvlist(nvl, "address")) @@ -649,11 +676,21 @@ default: msg(M_WARN, "Unknown kernel notification %d", type); + dco->dco_message_type =3D OVPN_CMD_NO_MESSAGE; break; } nvlist_destroy(nvl); + if (dco->c->mode =3D=3D CM_TOP) + { + multi_process_incoming_dco(dco); + } + else + { + process_incoming_dco(dco); + } + return 0; } @@ -773,26 +810,9 @@ nvlist_destroy(nvl); } -static void -dco_update_peer_stat(struct multi_context *m, uint32_t peerid, const nvlis= t_t *nvl) -{ - - if (peerid >=3D m->max_clients || !m->instances[peerid]) - { - msg(M_WARN, "dco_update_peer_stat: invalid peer ID %d returned by = kernel", peerid); - return; - } - - struct multi_instance *mi =3D m->instances[peerid]; - - mi->context.c2.dco_read_bytes =3D nvlist_get_number(nvl, "in"); - mi->context.c2.dco_write_bytes =3D nvlist_get_number(nvl, "out"); -} - int dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m) { - struct ifdrv drv; uint8_t *buf =3D NULL; size_t buf_size =3D 4096; diff --git a/src/openvpn/dco_freebsd.h b/src/openvpn/dco_freebsd.h index e8f723e..d2cc045 100644 --- a/src/openvpn/dco_freebsd.h +++ b/src/openvpn/dco_freebsd.h @@ -33,6 +33,8 @@ typedef enum ovpn_key_cipher dco_cipher_t; enum ovpn_message_type_t { + /* message type #0 is treated as magic number by process_incoming_dco(= ) */ + OVPN_CMD_NO_MESSAGE =3D 0, OVPN_CMD_DEL_PEER, OVPN_CMD_PACKET, OVPN_CMD_SWAP_KEYS, @@ -57,9 +59,8 @@ int dco_message_peer_id; int dco_del_peer_reason; struct sockaddr_storage dco_float_peer_ss; + struct context *c; - uint64_t dco_read_bytes; - uint64_t dco_write_bytes; } dco_context_t; #endif /* defined(ENABLE_DCO) && defined(TARGET_FREEBSD) */ diff --git a/src/openvpn/dco_linux.c b/src/openvpn/dco_linux.c index 493fce6..8ce7026 100644 --- a/src/openvpn/dco_linux.c +++ b/src/openvpn/dco_linux.c @@ -50,6 +50,15 @@ #include #include +/* When parsing multiple DEL_PEER notifications, openvpn tries to request = stats + * for each DEL_PEER message (see setenv_stats). This triggers a GET_PEER + * request-reply while we are still parsing the rest of the initial + * notifications, which can lead to NLE_BUSY or even NLE_NOMEM. + * + * This basic lock ensures we don't bite our own tail by issuing a dco_get= _peer + * while still busy receiving and parsing other messages. + */ +static bool __is_locked =3D false; /* libnl < 3.5.0 does not set the NLA_F_NESTED on its own, therefore we * have to explicitly do it to prevent the kernel from failing upon @@ -62,8 +71,6 @@ void dco_check_key_ctx(const struct key_ctx_bi *key); -typedef int (*ovpn_nl_cb)(struct nl_msg *msg, void *arg); - /** * @brief resolves the netlink ID for ovpn-dco * @@ -131,7 +138,9 @@ static int ovpn_nl_recvmsgs(dco_context_t *dco, const char *prefix) { + __is_locked =3D true; int ret =3D nl_recvmsgs(dco->nl_sock, dco->nl_cb); + __is_locked =3D false; switch (ret) { @@ -167,23 +176,19 @@ } /** - * Send a prepared netlink message and registers cb as callback if non-nul= l. + * Send a prepared netlink message. * * The method will also free nl_msg * @param dco The dco context to use * @param nl_msg the message to use - * @param cb An optional callback if the caller expects an answer - * @param cb_arg An optional param to pass to the callback * @param prefix A prefix to report in the error message to give the us= er context * @return status of sending the message */ static int -ovpn_nl_msg_send(dco_context_t *dco, struct nl_msg *nl_msg, ovpn_nl_cb cb, - void *cb_arg, const char *prefix) +ovpn_nl_msg_send(dco_context_t *dco, struct nl_msg *nl_msg, const char *pr= efix) { dco->status =3D 1; - nl_cb_set(dco->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, cb, cb_arg); nl_send_auto(dco->nl_sock, nl_msg); while (dco->status =3D=3D 1) @@ -274,7 +279,7 @@ } nla_nest_end(nl_msg, attr); - ret =3D ovpn_nl_msg_send(dco, nl_msg, NULL, NULL, __func__); + ret =3D ovpn_nl_msg_send(dco, nl_msg, __func__); nla_put_failure: nlmsg_free(nl_msg); @@ -342,6 +347,8 @@ return NL_STOP; } +static int ovpn_handle_msg(struct nl_msg *msg, void *arg); + static void ovpn_dco_init_netlink(dco_context_t *dco) { @@ -373,11 +380,13 @@ nl_socket_set_cb(dco->nl_sock, dco->nl_cb); + dco->dco_message_peer_id =3D -1; nl_cb_err(dco->nl_cb, NL_CB_CUSTOM, ovpn_nl_cb_error, &dco->status); nl_cb_set(dco->nl_cb, NL_CB_FINISH, NL_CB_CUSTOM, ovpn_nl_cb_finish, &dco->status); nl_cb_set(dco->nl_cb, NL_CB_ACK, NL_CB_CUSTOM, ovpn_nl_cb_finish, &dco->status); + nl_cb_set(dco->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, ovpn_handle_msg, dco); /* The async PACKET messages confuse libnl and it will drop them with * wrong sequence numbers (NLE_SEQ_MISMATCH), so disable libnl's seque= nce @@ -501,7 +510,7 @@ NLA_PUT_U32(nl_msg, OVPN_SWAP_KEYS_ATTR_PEER_ID, peerid); nla_nest_end(nl_msg, attr); - ret =3D ovpn_nl_msg_send(dco, nl_msg, NULL, NULL, __func__); + ret =3D ovpn_nl_msg_send(dco, nl_msg, __func__); nla_put_failure: nlmsg_free(nl_msg); @@ -525,7 +534,7 @@ NLA_PUT_U32(nl_msg, OVPN_DEL_PEER_ATTR_PEER_ID, peerid); nla_nest_end(nl_msg, attr); - ret =3D ovpn_nl_msg_send(dco, nl_msg, NULL, NULL, __func__); + ret =3D ovpn_nl_msg_send(dco, nl_msg, __func__); nla_put_failure: nlmsg_free(nl_msg); @@ -551,7 +560,7 @@ NLA_PUT_U8(nl_msg, OVPN_DEL_KEY_ATTR_KEY_SLOT, slot); nla_nest_end(nl_msg, attr); - ret =3D ovpn_nl_msg_send(dco, nl_msg, NULL, NULL, __func__); + ret =3D ovpn_nl_msg_send(dco, nl_msg, __func__); nla_put_failure: nlmsg_free(nl_msg); @@ -608,7 +617,7 @@ nla_nest_end(nl_msg, attr); - ret =3D ovpn_nl_msg_send(dco, nl_msg, NULL, NULL, __func__); + ret =3D ovpn_nl_msg_send(dco, nl_msg, __func__); nla_put_failure: nlmsg_free(nl_msg); @@ -637,7 +646,7 @@ keepalive_timeout); nla_nest_end(nl_msg, attr); - ret =3D ovpn_nl_msg_send(dco, nl_msg, NULL, NULL, __func__); + ret =3D ovpn_nl_msg_send(dco, nl_msg, __func__); nla_put_failure: nlmsg_free(nl_msg); @@ -705,7 +714,7 @@ /* Even though 'nlctrl' is a constant, there seem to be no library * provided define for it */ - int ctrlid =3D genl_ctrl_resolve(dco->nl_sock, "nlctrl"); + dco->ctrlid =3D genl_ctrl_resolve(dco->nl_sock, "nlctrl"); struct nl_msg *nl_msg =3D nlmsg_alloc(); if (!nl_msg) @@ -713,12 +722,12 @@ return -ENOMEM; } - genlmsg_put(nl_msg, 0, 0, ctrlid, 0, 0, CTRL_CMD_GETFAMILY, 0); + genlmsg_put(nl_msg, 0, 0, dco->ctrlid, 0, 0, CTRL_CMD_GETFAMILY, 0); int ret =3D -EMSGSIZE; NLA_PUT_STRING(nl_msg, CTRL_ATTR_FAMILY_NAME, OVPN_NL_NAME); - ret =3D ovpn_nl_msg_send(dco, nl_msg, mcast_family_handler, dco, __fun= c__); + ret =3D ovpn_nl_msg_send(dco, nl_msg, __func__); nla_put_failure: nlmsg_free(nl_msg); @@ -726,108 +735,10 @@ } /* This function parses any netlink message sent by ovpn-dco to userspace = */ -static int -ovpn_handle_msg(struct nl_msg *msg, void *arg) -{ - dco_context_t *dco =3D arg; - - struct genlmsghdr *gnlh =3D nlmsg_data(nlmsg_hdr(msg)); - struct nlattr *attrs[OVPN_ATTR_MAX + 1]; - struct nlmsghdr *nlh =3D nlmsg_hdr(msg); - - if (!genlmsg_valid_hdr(nlh, 0)) - { - msg(D_DCO, "ovpn-dco: invalid header"); - return NL_SKIP; - } - - if (nla_parse(attrs, OVPN_ATTR_MAX, genlmsg_attrdata(gnlh, 0), - genlmsg_attrlen(gnlh, 0), NULL)) - { - msg(D_DCO, "received bogus data from ovpn-dco"); - return NL_SKIP; - } - - /* we must know which interface this message is referring to in order = to - * avoid mixing messages for other instances - */ - if (!attrs[OVPN_ATTR_IFINDEX]) - { - msg(D_DCO, "ovpn-dco: Received message without ifindex"); - return NL_SKIP; - } - - uint32_t ifindex =3D nla_get_u32(attrs[OVPN_ATTR_IFINDEX]); - if (ifindex !=3D dco->ifindex) - { - msg(D_DCO_DEBUG, - "ovpn-dco: ignoring message (type=3D%d) for foreign ifindex %d= ", - gnlh->cmd, ifindex); - return NL_SKIP; - } - - /* based on the message type, we parse the subobject contained in the - * message, that stores the type-specific attributes. - * - * the "dco" object is then filled accordingly with the information - * retrieved from the message, so that the rest of the OpenVPN code can - * react as need be. - */ - switch (gnlh->cmd) - { - case OVPN_CMD_DEL_PEER: - { - if (!attrs[OVPN_ATTR_DEL_PEER]) - { - msg(D_DCO, "ovpn-dco: no attributes in OVPN_DEL_PEER messa= ge"); - return NL_SKIP; - } - - struct nlattr *dp_attrs[OVPN_DEL_PEER_ATTR_MAX + 1]; - if (nla_parse_nested(dp_attrs, OVPN_DEL_PEER_ATTR_MAX, - attrs[OVPN_ATTR_DEL_PEER], NULL)) - { - msg(D_DCO, "received bogus del peer packet data from ovpn-= dco"); - return NL_SKIP; - } - - if (!dp_attrs[OVPN_DEL_PEER_ATTR_REASON]) - { - msg(D_DCO, "ovpn-dco: no reason in DEL_PEER message"); - return NL_SKIP; - } - if (!dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID]) - { - msg(D_DCO, "ovpn-dco: no peer-id in DEL_PEER message"); - return NL_SKIP; - } - int reason =3D nla_get_u8(dp_attrs[OVPN_DEL_PEER_ATTR_REASON]); - unsigned int peerid =3D nla_get_u32(dp_attrs[OVPN_DEL_PEER_ATT= R_PEER_ID]); - - msg(D_DCO_DEBUG, "ovpn-dco: received CMD_DEL_PEER, ifindex: %d= , peer-id %d, reason: %d", - ifindex, peerid, reason); - dco->dco_message_peer_id =3D peerid; - dco->dco_del_peer_reason =3D reason; - dco->dco_message_type =3D OVPN_CMD_DEL_PEER; - - break; - } - - default: - msg(D_DCO, "ovpn-dco: received unknown command: %d", gnlh->cmd= ); - dco->dco_message_type =3D 0; - return NL_SKIP; - } - - return NL_OK; -} - int -dco_do_read(dco_context_t *dco) +dco_read_and_process(dco_context_t *dco) { msg(D_DCO_DEBUG, __func__); - nl_cb_set(dco->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, ovpn_handle_msg, dco); - return ovpn_nl_recvmsgs(dco, __func__); } @@ -883,27 +794,21 @@ } } -int -dco_parse_peer_multi(struct nl_msg *msg, void *arg) +static int +ovpn_handle_peer(dco_context_t *dco, struct nlattr *attrs[]) { - struct nlattr *tb[OVPN_ATTR_MAX + 1]; - struct genlmsghdr *gnlh =3D nlmsg_data(nlmsg_hdr(msg)); + struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX + 1]; + struct context_2 *c2; - msg(D_DCO_DEBUG, "%s: parsing message...", __func__); - - nla_parse(tb, OVPN_ATTR_MAX, genlmsg_attrdata(gnlh, 0), - genlmsg_attrlen(gnlh, 0), NULL); - - if (!tb[OVPN_ATTR_GET_PEER]) + if (!attrs[OVPN_ATTR_GET_PEER]) { + msg(D_DCO_DEBUG, "%s: malformed reply", __func__); return NL_SKIP; } - struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX + 1]; - nla_parse(tb_peer, OVPN_GET_PEER_RESP_ATTR_MAX, - nla_data(tb[OVPN_ATTR_GET_PEER]), - nla_len(tb[OVPN_ATTR_GET_PEER]), NULL); + nla_data(attrs[OVPN_ATTR_GET_PEER]), + nla_len(attrs[OVPN_ATTR_GET_PEER]), NULL); if (!tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID]) { @@ -911,17 +816,180 @@ return NL_SKIP; } - struct multi_context *m =3D arg; uint32_t peer_id =3D nla_get_u32(tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_= ID]); + msg(D_DCO_DEBUG | M_NOIPREFIX, "%s: parsing message for peer %u...", + __func__, peer_id); - if (peer_id >=3D m->max_clients || !m->instances[peer_id]) + if (dco->ifmode =3D=3D OVPN_MODE_P2P) { - msg(M_WARN, "%s: cannot store DCO stats for peer %u", __func__, - peer_id); + c2 =3D &dco->c->c2; + if (c2->tls_multi->dco_peer_id !=3D (int)peer_id) + { + return NL_SKIP; + } + } + else + { + if (peer_id >=3D dco->c->multi->max_clients) + { + msg(M_WARN, "%s: received out of bound peer_id %u (max=3D%u)", + __func__, peer_id, dco->c->multi->max_clients); + return NL_SKIP; + } + + struct multi_instance *mi =3D dco->c->multi->instances[peer_id]; + if (!mi) + { + msg(M_WARN | M_NOIPREFIX, + "%s: received data for a non-existing peer %u", + __func__, peer_id); + return NL_SKIP; + } + + c2 =3D &mi->context.c2; + } + + dco_update_peer_stat(c2, tb_peer, peer_id); + + return NL_OK; +} + +static int +ovpn_handle_del_peer(dco_context_t *dco, struct nlattr *attrs[]) +{ + if (!attrs[OVPN_ATTR_DEL_PEER]) + { + msg(D_DCO, "ovpn-dco: no attributes in OVPN_DEL_PEER message"); + return NL_STOP; + } + + struct nlattr *dp_attrs[OVPN_DEL_PEER_ATTR_MAX + 1]; + if (nla_parse_nested(dp_attrs, OVPN_DEL_PEER_ATTR_MAX, + attrs[OVPN_ATTR_DEL_PEER], NULL)) + { + msg(D_DCO, "received bogus del peer packet data from ovpn-dco"); + return NL_STOP; + } + + if (!dp_attrs[OVPN_DEL_PEER_ATTR_REASON]) + { + msg(D_DCO, "ovpn-dco: no reason in DEL_PEER message"); + return NL_STOP; + } + if (!dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID]) + { + msg(D_DCO, "ovpn-dco: no peer-id in DEL_PEER message"); + return NL_STOP; + } + + int reason =3D nla_get_u8(dp_attrs[OVPN_DEL_PEER_ATTR_REASON]); + unsigned int peerid =3D nla_get_u32(dp_attrs[OVPN_DEL_PEER_ATTR_PEER_I= D]); + + msg(D_DCO_DEBUG, "ovpn-dco: received CMD_DEL_PEER, ifindex: %d, peer-i= d %d, reason: %d", + dco->ifindex, peerid, reason); + dco->dco_message_peer_id =3D peerid; + dco->dco_del_peer_reason =3D reason; + dco->dco_message_type =3D OVPN_CMD_DEL_PEER; + + return NL_OK; +} + +static int +ovpn_handle_msg(struct nl_msg *msg, void *arg) +{ + dco_context_t *dco =3D arg; + + struct nlmsghdr *nlh =3D nlmsg_hdr(msg); + struct genlmsghdr *gnlh =3D genlmsg_hdr(nlh); + struct nlattr *attrs[OVPN_ATTR_MAX + 1]; + + msg(D_DCO_DEBUG | M_NOIPREFIX, + "ovpn-dco: received netlink message type=3D%u cmd=3D%u flags=3D%#.= 4x", + nlh->nlmsg_type, gnlh->cmd, nlh->nlmsg_flags); + + /* if we get a message from the NLCTRL family, it means + * this is the reply to the mcast ID resolution request + * and we parse it accordingly. + */ + if (nlh->nlmsg_type =3D=3D dco->ctrlid) + { + msg(D_DCO_DEBUG, "ovpn-dco: received CTRLID message"); + return mcast_family_handler(msg, dco); + } + + if (!genlmsg_valid_hdr(nlh, 0)) + { + msg(D_DCO, "ovpn-dco: invalid header"); + return NL_STOP; + } + + if (nla_parse(attrs, OVPN_ATTR_MAX, genlmsg_attrdata(gnlh, 0), + genlmsg_attrlen(gnlh, 0), NULL)) + { + msg(D_DCO, "received bogus data from ovpn-dco"); + return NL_STOP; + } + + /* we must know which interface this message is referring to in order = to + * avoid mixing messages for other instances + */ + if (!attrs[OVPN_ATTR_IFINDEX]) + { + msg(D_DCO, "ovpn-dco: Received message without ifindex"); + return NL_STOP; + } + + uint32_t ifindex =3D nla_get_u32(attrs[OVPN_ATTR_IFINDEX]); + if (ifindex !=3D dco->ifindex) + { + msg(D_DCO_DEBUG, "ovpn-dco: ignoring message for foreign ifindex %= d", + ifindex); return NL_SKIP; } - dco_update_peer_stat(&m->instances[peer_id]->context.c2, tb_peer, peer= _id); + /* based on the message type, we parse the subobject contained in the + * message, that stores the type-specific attributes. + * + * the "dco" object is then filled accordingly with the information + * retrieved from the message, so that *process_incoming_dco can react + * as need be. + */ + int ret; + switch (gnlh->cmd) + { + case OVPN_CMD_GET_PEER: + { + /* return directly, there are no messages to pass to + * *process_incoming_dco() + */ + return ovpn_handle_peer(dco, attrs); + } + + case OVPN_CMD_DEL_PEER: + { + ret =3D ovpn_handle_del_peer(dco, attrs); + break; + } + + default: + msg(D_DCO, "ovpn-dco: received unknown command: %d", gnlh->cmd= ); + dco->dco_message_type =3D 0; + return NL_STOP; + } + + if (ret !=3D NL_OK) + { + return ret; + } + + if (dco->c->mode =3D=3D CM_TOP) + { + multi_process_incoming_dco(dco); + } + else + { + process_incoming_dco(dco); + } return NL_OK; } @@ -931,57 +999,29 @@ { msg(D_DCO_DEBUG, "%s", __func__); + if (__is_locked) + { + msg(D_DCO_DEBUG, "%s: cannot request peer stats while parsing othe= r messages", + __func__); + return 0; + } + + ASSERT(dco->c->multi =3D=3D m); + struct nl_msg *nl_msg =3D ovpn_dco_nlmsg_create(dco, OVPN_CMD_GET_PEER= ); + if (!nl_msg) + { + return -ENOMEM; + } nlmsg_hdr(nl_msg)->nlmsg_flags |=3D NLM_F_DUMP; - int ret =3D ovpn_nl_msg_send(dco, nl_msg, dco_parse_peer_multi, m, __f= unc__); + int ret =3D ovpn_nl_msg_send(dco, nl_msg, __func__); nlmsg_free(nl_msg); return ret; } -static int -dco_parse_peer(struct nl_msg *msg, void *arg) -{ - struct context *c =3D arg; - struct nlattr *tb[OVPN_ATTR_MAX + 1]; - struct genlmsghdr *gnlh =3D nlmsg_data(nlmsg_hdr(msg)); - - msg(D_DCO_DEBUG, "%s: parsing message...", __func__); - - nla_parse(tb, OVPN_ATTR_MAX, genlmsg_attrdata(gnlh, 0), - genlmsg_attrlen(gnlh, 0), NULL); - - if (!tb[OVPN_ATTR_GET_PEER]) - { - msg(D_DCO_DEBUG, "%s: malformed reply", __func__); - return NL_SKIP; - } - - struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX + 1]; - - nla_parse(tb_peer, OVPN_GET_PEER_RESP_ATTR_MAX, - nla_data(tb[OVPN_ATTR_GET_PEER]), - nla_len(tb[OVPN_ATTR_GET_PEER]), NULL); - - if (!tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID]) - { - msg(M_WARN, "%s: no peer-id provided in reply", __func__); - return NL_SKIP; - } - - uint32_t peer_id =3D nla_get_u32(tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_= ID]); - if (c->c2.tls_multi->dco_peer_id !=3D peer_id) - { - return NL_SKIP; - } - - dco_update_peer_stat(&c->c2, tb_peer, peer_id); - - return NL_OK; -} - int dco_get_peer_stats(struct context *c) { @@ -993,6 +1033,13 @@ return 0; } + if (__is_locked) + { + msg(D_DCO_DEBUG, "%s: cannot request peer stats while parsing othe= r messages", + __func__); + return 0; + } + dco_context_t *dco =3D &c->c1.tuntap->dco; struct nl_msg *nl_msg =3D ovpn_dco_nlmsg_create(dco, OVPN_CMD_GET_PEER= ); struct nlattr *attr =3D nla_nest_start(nl_msg, OVPN_ATTR_GET_PEER); @@ -1001,7 +1048,7 @@ NLA_PUT_U32(nl_msg, OVPN_GET_PEER_ATTR_PEER_ID, peer_id); nla_nest_end(nl_msg, attr); - ret =3D ovpn_nl_msg_send(dco, nl_msg, dco_parse_peer, c, __func__); + ret =3D ovpn_nl_msg_send(dco, nl_msg, __func__); nla_put_failure: nlmsg_free(nl_msg); diff --git a/src/openvpn/dco_linux.h b/src/openvpn/dco_linux.h index cf6bdd4..9209915 100644 --- a/src/openvpn/dco_linux.h +++ b/src/openvpn/dco_linux.h @@ -44,6 +44,7 @@ int status; struct context *c; + int ctrlid; enum ovpn_mode ifmode; @@ -55,8 +56,6 @@ int dco_message_type; int dco_message_peer_id; int dco_del_peer_reason; - uint64_t dco_read_bytes; - uint64_t dco_write_bytes; } dco_context_t; #endif /* defined(ENABLE_DCO) && defined(TARGET_LINUX) */ diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c index bc465db..b11d506 100644 --- a/src/openvpn/dco_win.c +++ b/src/openvpn/dco_win.c @@ -423,7 +423,7 @@ } int -dco_do_read(dco_context_t *dco) +dco_read_and_process(dco_context_t *dco) { /* no-op on windows */ ASSERT(0); diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index 4e9e739..e43ce28 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -1269,13 +1269,11 @@ } } -static void -process_incoming_dco(struct context *c) +void +process_incoming_dco(dco_context_t *dco) { #if defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARGET_FREEBS= D)) - dco_context_t *dco =3D &c->c1.tuntap->dco; - - dco_do_read(dco); + struct context *c =3D dco->c; /* FreeBSD currently sends us removal notifcation with the old peer-id= in * p2p mode with the ping timeout reason, so ignore that one to not sh= oot @@ -1291,6 +1289,8 @@ switch (dco->dco_message_type) { case OVPN_CMD_DEL_PEER: + /* peer is gone, unset ID to prevent more kernel calls */ + c->c2.tls_multi->dco_peer_id =3D -1; if (dco->dco_del_peer_reason =3D=3D OVPN_DEL_PEER_REASON_EXPIR= ED) { msg(D_DCO_DEBUG, "%s: received peer expired notification o= f for peer-id " @@ -2344,7 +2344,7 @@ { if (!IS_SIG(c)) { - process_incoming_dco(c); + dco_read_and_process(&c->c1.tuntap->dco); } } } diff --git a/src/openvpn/forward.h b/src/openvpn/forward.h index 3d0abd5..1de2aa2 100644 --- a/src/openvpn/forward.h +++ b/src/openvpn/forward.h @@ -50,6 +50,7 @@ #include "openvpn.h" #include "occ.h" #include "ping.h" +#include "dco.h" #define IOW_TO_TUN (1<<0) #define IOW_TO_LINK (1<<1) @@ -248,6 +249,12 @@ */ void process_incoming_tun(struct context *c); +/** + * Process an incoming DCO message (from kernel space). + * + * @param dco - Pointer to the structure representing the DCO context. + */ +void process_incoming_dco(dco_context_t *dco); /** * Write a packet to the virtual tun/tap network interface. diff --git a/src/openvpn/mtcp.c b/src/openvpn/mtcp.c index 38c938e..b1714c8 100644 --- a/src/openvpn/mtcp.c +++ b/src/openvpn/mtcp.c @@ -747,7 +747,7 @@ /* incoming data on DCO? */ else if (e->arg =3D=3D MTCP_DCO) { - multi_process_incoming_dco(m); + dco_read_and_process(&m->top.c1.tuntap->dco); } #endif /* signal received? */ diff --git a/src/openvpn/mudp.c b/src/openvpn/mudp.c index 8cc717b..9a71eeb 100644 --- a/src/openvpn/mudp.c +++ b/src/openvpn/mudp.c @@ -409,11 +409,7 @@ { if (!IS_SIG(&m->top)) { - bool ret =3D true; - while (ret) - { - ret =3D multi_process_incoming_dco(m); - } + dco_read_and_process(&m->top.c1.tuntap->dco); } } #endif diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 69497a6..7620065 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -3287,20 +3287,17 @@ * installed, and we do not need to clean up the state in the kernel */ mi->context.c2.tls_multi->dco_peer_id =3D -1; mi->context.sig->signal_text =3D reason; - mi->context.c2.dco_read_bytes =3D dco->dco_read_bytes; - mi->context.c2.dco_write_bytes =3D dco->dco_write_bytes; multi_signal_instance(m, mi, SIGTERM); } -bool -multi_process_incoming_dco(struct multi_context *m) +void +multi_process_incoming_dco(dco_context_t *dco) { - dco_context_t *dco =3D &m->top.c1.tuntap->dco; + ASSERT(dco->c->multi); + struct multi_context *m =3D dco->c->multi; struct multi_instance *mi =3D NULL; - int ret =3D dco_do_read(&m->top.c1.tuntap->dco); - int peer_id =3D dco->dco_message_peer_id; /* no peer-specific message delivered -> nothing to process. @@ -3308,7 +3305,7 @@ */ if (peer_id < 0) { - return ret > 0; + return; } if ((peer_id < m->max_clients) && (m->instances[peer_id])) @@ -3355,13 +3352,6 @@ "type %d, del_peer_reason %d", peer_id, dco->dco_message_type, dco->dco_del_peer_reason); } - - dco->dco_message_type =3D 0; - dco->dco_message_peer_id =3D -1; - dco->dco_del_peer_reason =3D -1; - dco->dco_read_bytes =3D 0; - dco->dco_write_bytes =3D 0; - return ret > 0; } #endif /* if defined(ENABLE_DCO) && defined(TARGET_LINUX) */ diff --git a/src/openvpn/multi.h b/src/openvpn/multi.h index 7167639..1b784e1 100644 --- a/src/openvpn/multi.h +++ b/src/openvpn/multi.h @@ -317,13 +317,9 @@ /** * Process an incoming DCO message (from kernel space). * - * @param m - The single \c multi_context structur.e - * - * @return - * - True, if the message was received correctly. - * - False, if there was an error while reading the message. + * @param dco - The DCO context containing the parsed message. */ -bool multi_process_incoming_dco(struct multi_context *m); +void multi_process_incoming_dco(dco_context_t *dco); /*************************************************************************= */ /** -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1632?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: merged Gerrit-Project: openvpn Gerrit-Branch: release/2.6 Gerrit-Change-Id: I92c5f74a27b40fede204f714b042a6cc80b3703e Gerrit-Change-Number: 1632 Gerrit-PatchSet: 3 Gerrit-Owner: ralf_lici Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel --Y9m7DFyQ0f4= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 sub= mitted this change.

View Change

dco: backport immediate notification processing =
on Linux and FreeBSD

Backport the immediate DCO message processing m= odel from commit 7791f53
("dco: process messages immediately after = read").

Change the core DCO API from dco_do_read() to dco_read_= and_process(),
and make the backend read paths own the parsing and immed= iate handling
of kernel notifications before handing the resulting state= to
process_incoming_dco() or multi_process_incoming_dco().

On Li= nux, install a permanent netlink callback and process GET_PEER and
DEL_P= EER messages as they are received, instead of switching callbacks
for ea= ch read and deferring handling through shared DCO message state.
Also ad= d a small guard to avoid requesting peer stats while libnl is
still pars= ing a batch of notifications.

On FreeBSD, move notification handling= into dco_read_and_process() and
update peer statistics directly from th= e backend instead of storing
temporary byte counters in dco_context_t.
This commit is part of a reworked backport of PR #945 originally
p= roposed by Nikolai Shelekhov <nickshv13@...2314...>.

Github: O= penVPN/openvpn#900
Github: OpenVPN/openvpn#918
Github: OpenVPN/openvp= n#931
Github: fixes OpenVPN/openvpn#919
Github: closes OpenVPN/openvp= n#945

Change-Id: I92c5f74a27b40fede204f714b042a6cc80b3703e
Signed= -off-by: Ralf Lici <ralf@...2726...>
Acked-by: Gert Doering <ge= rt@...1296...>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/163= 2
Message-Id: <20260421084906.5720-1-gert@...1296...>
URL: http= s://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg36707.html<= br>Signed-off-by: Gert Doering <gert@...1296...>
---
M src/open= vpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_freebsd.h
= M src/openvpn/dco_linux.c
M src/openvpn/dco_linux.h
M src/openvpn/dco= _win.c
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openv= pn/mtcp.c
M src/openvpn/mudp.c
M src/openvpn/multi.c
M src/openvpn= /multi.h
12 files changed, 299 insertions(+), 242 deletions(-)

diff --git a/src/openvpn/dco.h b/src/openvpn/dco.h
index= 334d468..3a36ddc 100644
--- a/src/openvpn/dco.h
= +++ b/src/openvpn/dco.h
@@ -128,12 +128,13 @@<= br> void close_tun_dco(struct tuntap *tt, openvpn_net_ctx_t *ctx);

/**
- * Read data from the DCO communication channel (i.e. a cont= rol packet)
+ * Read = and process data from the DCO communication channel
+ * (i.e. a control packet)
*

* @param dco the DCO context
= * @return 0 on success or a negative error code otherwise=
*/
-int dco= _do_read(dco_context_t *dco);
+int dco_read_and_process(dco_context_t *dco);

/**
* Install a DCO in the main event loo= p
@@ -300,7 +301,7 @@
}
<= /span>
static inline int
-dco_do_read(dco_context_t *dco)
+dco_read_and_process(dco_context_t *dco) {
ASSERT(false);
return 0= ;
diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_= freebsd.c
index b164bd3..9384bf1 100644
---= a/src/openvpn/dco_freebsd.c
+++ b/src/openvpn/dco_freebsd.= c
@@ -560,8 +560,23 @@
return ret;

}

+static void
+dco_update_peer_stat(struct multi_context *m, uint32_t peerid, const = nvlist_t *nvl)
+{
+ if (peerid >=3D = m->max_clients || !m->instances[peerid])
+ {
+ msg(M_WARN, "dco_update_peer_stat: invalid peer I= D %d returned by kernel", peerid);
+ return;
+ }
+
+ struct multi_= instance *mi =3D m->instances[peerid];
+
+ mi->= context.c2.dco_write_bytes =3D nvlist_get_number(nvl, "out");
+}
+
int
-dco_do_read(dco_context_t *dco)+dco_read_and_process(dco_cont= ext_t *dco)
{
struct ifdrv drv;
uint8_t buf[4096];
@@ -592,9 +607,13 @@
return -EINVAL;
}

- dco->dco_me= ssage_peer_id =3D nvlist_get_number(nvl, "peerid");
+ /* dco_message_peer_id is sig= ned int, because other parts of the

+ * code treat "-1" as "this is a message= not specific to one peer"
+ */
+= dco->dco_message_peer_id =3D (int)nvlist_get_number(nvl, "peeri= d");

- type =3D nvlist_get_number(nvl, "notification");=
+ type =3D (enum ovpn_no= tif_type)nvlist_get_number(nvl, "notification");
+
switch (type)<= /span>
{
case OVPN_NOTIF_DEL_PEER:
@@ -617,8 +636,15 @@
{ const nvlist_t *bytes =3D nvlist_get_nvlist(nvl, &= quot;bytes");

- dco->dco_read_bytes =3D nvlist_get_number= (bytes, "in");
+ = if (dco->c->mode =3D=3D CM_TOP)
+ {
+ dco_update_peer_stat(dco->= ;c->multi, dco->dco_message_peer_id, bytes);
+ }
+ else
+ {
+ dco->c->c2.dco_read_b= ytes =3D nvlist_get_number(bytes, "in");
+ dco->c->c2.dco_wri= te_bytes =3D nvlist_get_number(bytes, "out");
+ }
= }

dco->dco_messag= e_type =3D OVPN_CMD_DEL_PEER;
@@ -628,7 +654,8 @@ dco->dco_message_type =3D OVPN_CMD_SWAP_KEYS;=
break;

- case OVPN_NOTIF_FLOAT: {
+ case OVPN_NOTIF_FLOAT:
+ {
const nvlist_t *address;


= if (!nvlist_exists_nvlist(nvl, "address"))
<= span>@@ -649,11 +676,21 @@


defau= lt:
msg(M_WARN, "Unknown kernel notificat= ion %d", type);
= + dco->dco_message_type =3D OVPN_CMD_NO_MESSAGE;
break;

}

= nvlist_destroy(nvl);

+ if (dco->c->mode =3D=3D CM_TOP)
+ {
+ multi_process_incoming_dco(dc= o);
+ }
= + else
+ {
+ process_incoming_dco(dco);
+ }
+
return 0;
}

@@ -773,26 +810,9 @@
nv= list_destroy(nvl);
}

-static void
-dco_update_peer_stat(struct multi_context *m, uint3= 2_t peerid, const nvlist_t *nvl)
-{
-- if (peerid >=3D m->m= ax_clients || !m->instances[peerid])
- {
- msg(M_WARN, "dco_update_peer_stat: invalid peer ID %d return= ed by kernel", peerid);
- return;
= - }
-
- struct multi_instance *mi =3D m-= >instances[peerid];

= -
- mi->context.c= 2.dco_read_bytes =3D nvlist_get_number(nvl, "in");
- mi->context.c2.dco_write_byte= s =3D nvlist_get_number(nvl, "out");

-}
-
int
dco_get_peer_stats_multi(dco_co= ntext_t *dco, struct multi_context *m)
{
-
struct ifdrv drv;=
uint8_t *buf =3D NULL;
size_t bu= f_size =3D 4096;
diff --git a/src/openvpn/dco_freebsd.h b/s= rc/openvpn/dco_freebsd.h
index e8f723e..d2cc045 100644
--- a/src/openvpn/dco_freebsd.h
+++ b/src/openv= pn/dco_freebsd.h
@@ -33,6 +33,8 @@
typedef= enum ovpn_key_cipher dco_cipher_t;

enum= ovpn_message_type_t {
+ OVPN_CMD_= NO_MESSAGE =3D 0,
OVPN_CMD_DEL_PEER,
= OVPN_CMD_PACKET,
OVPN_CMD_SWAP_KEYS,
@@ -57,9 +59,8 @@

int dco_message_peer_id; int dco_del_peer_reason;
struct sockaddr_= storage dco_float_peer_ss;
+
struct context *c;
- uint64_t dco_read_bytes;
- uint64_t dco_write_bytes;
} dco_context_t;


#endif /* defined(= ENABLE_DCO) && defined(TARGET_FREEBSD) */
diff --gi= t a/src/openvpn/dco_linux.c b/src/openvpn/dco_linux.c
index= 493fce6..8ce7026 100644
--- a/src/openvpn/dco_linux.c
+++ b/src/openvpn/dco_linux.c
@@ -50,6 +50,15 @= @
#include <netlink/genl/family.h>
= #include <netlink/genl/ctrl.h>

+/* When parsing multiple DEL_PEER notifi= cations, openvpn tries to request stats
+ * for each DEL_PEER message (see setenv_stats). This t= riggers a GET_PEER
+ = * request-reply while we are still parsing the rest of the initial+ * notifications, which can = lead to NLE_BUSY or even NLE_NOMEM.
+ *
+ = * This basic lock ensures we don't bite our own tail by issuing a dco_g= et_peer
+ * while sti= ll busy receiving and parsing other messages.
+ */
+static bool __is_locked =3D false;

/* libnl < 3.5.0 does not set the NLA_F_NESTED on its own, therefor= e we

* have to explicitly do it to prevent the kernel fro= m failing upon
@@ -62,8 +71,6 @@
void dco_check_key_ctx(const struct key_ctx_bi *key);

-typedef int (*ov= pn_nl_cb)(struct nl_msg *msg, void *arg);
-
/**
* @brief resolv= es the netlink ID for ovpn-dco
*
@@ -131,= 7 +138,9 @@
static int
ovpn_nl_recvmsgs(d= co_context_t *dco, const char *prefix)
{
+ __is_locked =3D true;
<= span> int ret =3D nl_recvmsgs(dco->nl_sock, dco->nl_cb);+ __is_locked =3D false;

switch (ret)
{
@@ -167,23 +176,19 @@
}

/**
- *= Send a prepared netlink message and registers cb as callback if non-null.<= /span>
+ * Send a prepared n= etlink message.
*
* The method will als= o free nl_msg
* @param dco The dco context to use
* @param nl_msg the message to use
- * @param cb An optional callback i= f the caller expects an answer
- * @param cb_arg An optional param to pass to the callback
* @param prefix A prefix to report in the error message to= give the user context
* @return status of sendi= ng the message
*/
static int
<= span style=3D"color: hsl(0, 100%, 40%);">-ovpn_nl_msg_send(dco_context_t *d= co, struct nl_msg *nl_msg, ovpn_nl_cb cb,

- void *cb_arg, const char *prefix)
+ovpn_nl_msg_send(dco_con= text_t *dco, struct nl_msg *nl_msg, const char *prefix)
{<= /span>
dco->status =3D 1;

- nl_cb_set(dco->nl_cb, NL_CB_V= ALID, NL_CB_CUSTOM, cb, cb_arg);

nl_send_auto(dco->= nl_sock, nl_msg);

while (dco->sta= tus =3D=3D 1)
@@ -274,7 +279,7 @@
}
nla_nest_end(nl_msg, attr);

= - ret =3D ovpn_nl_msg_send(dco= , nl_msg, NULL, NULL, __func__);
+ ret =3D ovpn_nl_msg_send(dco, nl_msg, __func__);
nla_put_failure:
nlmsg_free(= nl_msg);
@@ -342,6 +347,8 @@
return NL= _STOP;
}

+static int ovpn_handle_msg(struct nl_msg *msg, void= *arg);
+
<= span> static void

ovpn_dco_init_netlink(dco_context_t *dco= )
{
@@ -373,11 +380,13 @@
=
nl_socket_set_cb(dco->nl_sock, dco->nl_cb);

+ = dco->dco_message_peer_id =3D -1;
nl_cb_err(dco->= nl_cb, NL_CB_CUSTOM, ovpn_nl_cb_error, &dco->status);
nl_cb_set(dco->nl_cb, NL_CB_FINISH, NL_CB_CUSTOM, ovpn_nl_cb_fini= sh,

&dco->status);
= nl_cb_set(dco->nl_cb, NL_CB_ACK, NL_CB_CUSTOM, ovpn_nl_cb_finish,
&dco->status);
+ nl_cb_set(dco->nl_cb, NL_CB_VALID, NL_= CB_CUSTOM, ovpn_handle_msg, dco);

/*= The async PACKET messages confuse libnl and it will drop them with<= br> * wrong sequence numbers (NLE_SEQ_MISMATCH), so disable libn= l's sequence
@@ -501,7 +510,7 @@
N= LA_PUT_U32(nl_msg, OVPN_SWAP_KEYS_ATTR_PEER_ID, peerid);
= nla_nest_end(nl_msg, attr);

- ret =3D ovpn_nl_msg_send(dco, nl_msg, NULL, = NULL, __func__);
+ = ret =3D ovpn_nl_msg_send(dco, nl_msg, __func__);
<= br> nla_put_failure:
nlmsg_free(nl_msg);<= br>@@ -525,7 +534,7 @@
NLA_PUT_U32(nl_msg, OVPN_= DEL_PEER_ATTR_PEER_ID, peerid);
nla_nest_end(nl_msg, a= ttr);

- ret =3D ovpn_nl_msg_send(dco, nl_msg, NULL, NULL, __func__);+ ret =3D ovpn_nl_msg_send= (dco, nl_msg, __func__);

nla_put_failure= :
nlmsg_free(nl_msg);
@@ -551,7 +560,7= @@
NLA_PUT_U8(nl_msg, OVPN_DEL_KEY_ATTR_KEY_SLOT, slo= t);
nla_nest_end(nl_msg, attr);

- ret =3D ovpn_nl_msg_se= nd(dco, nl_msg, NULL, NULL, __func__);
+ ret =3D ovpn_nl_msg_send(dco, nl_msg, __func__);

nla_put_failure:
nlmsg= _free(nl_msg);
@@ -608,7 +617,7 @@
=
nla_nest_end(nl_msg, attr);

- ret =3D ovpn_nl_msg_send(dco, nl= _msg, NULL, NULL, __func__);

+ ret =3D ovpn_nl_msg_send(dco, nl_msg, __func__);

nla_put_failure:
nlmsg_free(nl_m= sg);
@@ -637,7 +646,7 @@
k= eepalive_timeout);
nla_nest_end(nl_msg, attr);<= br>
- ret =3D= ovpn_nl_msg_send(dco, nl_msg, NULL, NULL, __func__);
+ ret =3D ovpn_nl_msg_send(dco, nl_msg,= __func__);

nla_put_failure:
<= span> nlmsg_free(nl_msg);

@@ -705,7 +714,7 @@
/* Even though 'nlctrl' is a constant= , there seem to be no library
* provided define for i= t */
- int ctrlid = =3D genl_ctrl_resolve(dco->nl_sock, "nlctrl");
+ dco->ctrlid =3D genl_ctrl_re= solve(dco->nl_sock, "nlctrl");


struct nl_msg *nl_msg =3D nlmsg_alloc();

if (!= nl_msg)
@@ -713,12 +722,12 @@
retu= rn -ENOMEM;
}

- genlmsg_put(nl_msg, 0, 0, ctrlid, 0, 0,= CTRL_CMD_GETFAMILY, 0);
+ genlmsg_put(nl_msg, 0, 0, dco->ctrlid, 0, 0, CTRL_CMD_GETFAMILY= , 0);

int ret =3D -EMSGSIZE;<= br> NLA_PUT_STRING(nl_msg, CTRL_ATTR_FAMILY_NAME, OVPN_NL_NAME);<= /span>

- = ret =3D ovpn_nl_msg_send(dco, nl_msg, mcast_family_handler, dco, __func__);=
+ ret =3D ovpn_nl= _msg_send(dco, nl_msg, __func__);

nla_pu= t_failure:
nlmsg_free(nl_msg);
@@ -726= ,108 +735,10 @@
}

/* Th= is function parses any netlink message sent by ovpn-dco to userspace */
-static int
-ovpn_handle_msg(struct nl_msg *msg, = void *arg)

-{- dco_context_t *dco =3D arg;=
-
- struct genlmsghdr *gnlh =3D nlmsg_data= (nlmsg_hdr(msg));
- = struct nlattr *attrs[OVPN_ATTR_MAX + 1];
- struct nlmsghdr *nlh =3D nlmsg_hdr(msg);
<= span style=3D"color: hsl(0, 100%, 40%);">-

- if (!genlmsg_valid_hdr(nlh, 0))
- {
- msg(D_DCO, "ovpn-dco: invalid header")= ;
- return NL_SK= IP;
- }
-

- if (nla_parse(attrs, OVPN_ATTR_MAX, genlmsg_attrdat= a(gnlh, 0),
- = genlmsg_attrlen(gnlh, 0), NULL))
- {
- return NL_SKIP;
- }
-
- /* we must know which interface this message is referring = to in order to
- * = avoid mixing messages for other instances
- */
- if (!attrs[OVPN_ATTR_IFINDEX])
- {
- return NL_= SKIP;
- }
= -
- uint32_t ifindex =3D nla_get_u32(attrs[OVPN_ATTR_= IFINDEX]);
- if (ifi= ndex !=3D dco->ifindex)
- {
- msg= (D_DCO_DEBUG,
- = "ovpn-dco: ignoring message (type=3D%d) for foreign ifindex %d&quo= t;,
- gnlh-&= gt;cmd, ifindex);
- = return NL_SKIP;
- = }
-
- /* based on the message type, we pa= rse the subobject contained in the
- * message, that stores the type-specific attributes.
- *
- * the "dco" object is then= filled accordingly with the information
- * retrieved from the message, so that the rest of t= he OpenVPN code can
- = * react as need be.
= - */
- switch (g= nlh->cmd)
- {
- case OVPN_CMD_DEL= _PEER:
- {
- if (!attrs[OVPN= _ATTR_DEL_PEER])
- = {
- = msg(D_DCO, "ovpn-dco: no attributes in OVPN_DEL_PEER message")= ;
- retu= rn NL_SKIP;
- = }
-
- struct nlattr *dp_attrs[OVP= N_DEL_PEER_ATTR_MAX + 1];
- if (nla_parse_nested(dp_attrs, OVPN_DEL_PEER_ATTR_MAX,
- = attrs[OVPN_ATTR_DEL_PEER], NULL))
- {
- msg(D_DCO, "received bogus del peer packet = data from ovpn-dco");
- return NL_SKIP;
- }
-
- if= (!dp_attrs[OVPN_DEL_PEER_ATTR_REASON])
- {
- msg(D_DCO, "ovpn-dco: no reason in DEL_PEER = message");
- = return NL_SKIP;
- }
- = if (!dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID])
- {
- msg(D_DCO, "ovpn-dco: no peer-id = in DEL_PEER message");
- return NL_SKIP;
- }
- int reason =3D nla_get_u8(dp_attrs[OVPN_DEL_PEER_ATTR_R= EASON]);
- u= nsigned int peerid =3D nla_get_u32(dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID]);
-
- msg(D_DCO_DEBUG, "ovpn-dco= : received CMD_DEL_PEER, ifindex: %d, peer-id %d, reason: %d",<= br>- ifindex, peer= id, reason);
- = dco->dco_message_peer_id =3D peerid;
- dco->dco_del_peer_reason =3D reason;
- dco->dco_= message_type =3D OVPN_CMD_DEL_PEER;
-
- = break;
- }<= /span>
-
- default:
- msg(D_DCO, "ovpn-dco: received = unknown command: %d", gnlh->cmd);
- dco->dco_message_type =3D 0;
<= span style=3D"color: hsl(0, 100%, 40%);">- return NL_SKIP;
- }
-
- return NL_OK;
-}
-
int

-dco_do_read(d= co_context_t *dco)
+d= co_read_and_process(dco_context_t *dco)
{
= msg(D_DCO_DEBUG, __func__);
- nl_cb_set(dco->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, ovpn_han= dle_msg, dco);
-=
return ovpn_nl_recvmsgs(dco, __func__);
}

@@ -883,27 +794,21 @@
= }
}

-int
-= dco_parse_peer_multi(struct nl_msg *msg, void *arg)
+static int
+ovpn_handle_peer(dco_context_t *dco, struct nlattr= *attrs[])
{
- struct nlattr *tb[OVPN_ATTR_MAX + 1];
- struct genlmsghdr *gnlh =3D nlmsg_data(nlms= g_hdr(msg));
+ str= uct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX + 1];
+ struct context_2 *c2;

- msg(D_DCO_DEBUG= , "%s: parsing message...", __func__);
-
- nla_parse(tb, OVPN_ATTR_MAX, genlmsg_attrdata(gnlh, 0),- genlmsg_attrlen(g= nlh, 0), NULL);
-
- if (!tb[OVPN_ATTR_GET_P= EER])
+ if (!attrs= [OVPN_ATTR_GET_PEER])
{
+ msg(D_DCO_DEBUG, "%s: malformed reply= ", __func__);
return NL_SKIP;
}


- struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX + 1];
= -
nla_parse(= tb_peer, OVPN_GET_PEER_RESP_ATTR_MAX,
- nla_data(tb[OVPN_ATTR_GET_PEER]),
<= span style=3D"color: hsl(0, 100%, 40%);">- nla_len(tb[OVPN_ATT= R_GET_PEER]), NULL);

= + nla_data(attrs[OVPN_ATTR_GET_PEER]),
+ nla_len(attrs[OVPN_ATTR_GET= _PEER]), NULL);

if (!tb_peer[OVPN_GE= T_PEER_RESP_ATTR_PEER_ID])
{
@@ -911,1= 7 +816,180 @@
return NL_SKIP;
= }

- = struct multi_context *m =3D arg;
uint32_t peer_id = =3D nla_get_u32(tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID]);
+ msg(D_DCO_DEBUG | M_NOIPREFIX, &= quot;%s: parsing message for peer %u...",
+ __func__, peer_id);

- if (peer_id >=3D = m->max_clients || !m->instances[peer_id])
+ if (dco->ifmode =3D=3D OVPN_MODE_P2P)
{
- = msg(M_WARN, "%s: cannot store DCO stats for peer %u", __fu= nc__,
- peer= _id);
+ c2 =3D= &dco->c->c2;
+ if (c2->tls_multi->dco_peer_id !=3D (int)peer_id)<= br>+ {
+ return NL_SKIP;+ }
+ }
+ else
+ {
+ = if (peer_id >=3D dco->c->multi->max_clients)
+ {

+ msg(M_WARN, "%s: receive= d out of bound peer_id %u (max=3D%u)",
+ __func__, peer_id, dco->c->mu= lti->max_clients);
+ return NL_SKIP;
+ }
+=
+ struct mult= i_instance *mi =3D dco->c->multi->instances[peer_id];
+ if (!mi)

+ {

+ msg(M_WARN | M_NOIPREFIX,<= br>+ "%s: r= eceived data for a non-existing peer %u",
+ __func__, peer_id);
+ return NL_SKIP;
+ }
+

+ c2 =3D &mi->context.c2;
+ }

+
+ dco_update_peer_stat(c2, tb_peer, peer_id);
+
+ return NL_OK;
+}
+
+static int
<= span style=3D"color: hsl(120, 100%, 40%);">+ovpn_handle_del_peer(dco_contex= t_t *dco, struct nlattr *attrs[])

+{
+ = if (!attrs[OVPN_ATTR_DEL_PEER])
+ {
+ = msg(D_DCO, "ovpn-dco: no attributes in OVPN_DEL_PEER message&quo= t;);
+ return = NL_STOP;
+ }
+
+ struct nlattr *dp_attrs[OVPN_DEL_PEER_AT= TR_MAX + 1];
+ if = (nla_parse_nested(dp_attrs, OVPN_DEL_PEER_ATTR_MAX,
+ attrs[OVPN_ATTR_= DEL_PEER], NULL))
+ = {
+ msg(D_DC= O, "received bogus del peer packet data from ovpn-dco");+ return NL_STOP;
+ }
+
+ if (!dp_attrs[OVPN_DEL_PEER_ATTR_REASON])
<= span style=3D"color: hsl(120, 100%, 40%);">+ {

+ msg(D_DCO, "ovpn-dco: no reason = in DEL_PEER message");
+ return NL_STOP;
+ }
+ = if (!dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID])
+ {
+ msg(D_DCO, "ovpn-dco: no peer-id in DEL_PEER messag= e");
+ re= turn NL_STOP;
+ }<= /span>
+
+ int reason =3D nla_get_u8(dp_attrs[= OVPN_DEL_PEER_ATTR_REASON]);
+ unsigned int peerid =3D nla_get_u32(dp_attrs[OVPN_DEL_PEER_ATT= R_PEER_ID]);
+=
+ msg(D_DCO_DEBUG, "= ;ovpn-dco: received CMD_DEL_PEER, ifindex: %d, peer-id %d, reason: %d"= ,
+ dco->if= index, peerid, reason);
+ dco->dco_message_peer_id =3D peerid;
+ dco->dco_del_peer_reason =3D reason;
+ dco->dco_message= _type =3D OVPN_CMD_DEL_PEER;
+
+ return= NL_OK;
+}
= +
+static int
+ovpn_handle_msg(struct nl_msg *msg, void *arg)
<= span style=3D"color: hsl(120, 100%, 40%);">+{

+ dco_context_t *dco =3D arg;
+
+ struct nlmsghdr *nlh =3D nlmsg_hdr(msg);
<= span style=3D"color: hsl(120, 100%, 40%);">+ struct genlmsghdr *gnlh =3D= genlmsg_hdr(nlh);

+ = struct nlattr *attrs[OVPN_ATTR_MAX + 1];
+
+ msg(D_DCO_DEBUG | M_NOIPREFIX,
+ "ovpn-dco: received netlink message type= =3D%u cmd=3D%u flags=3D%#.4x",
+ nlh->nlmsg_type, gnlh->cmd, nlh->nlmsg_fla= gs);
+
+ /* if we get a message from th= e NLCTRL family, it means

+ * this is the reply to the mcast ID resolution request+ * and we parse it accord= ingly.
+ */
+ if (nlh->nlmsg_typ= e =3D=3D dco->ctrlid)
+ {
+ m= sg(D_DCO_DEBUG, "ovpn-dco: received CTRLID message");
<= span style=3D"color: hsl(120, 100%, 40%);">+ return mcast_family_han= dler(msg, dco);

+ = }
+
+ if (!genlmsg_valid_hdr(nlh, 0))
+ {
+ msg(D_DCO, "ovpn-dco: = invalid header");

+ }
+=
+ if (nla_parse(attrs, O= VPN_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
+ genlmsg_attrlen(gnlh, 0), NULL))
+ {
+ msg(D_DCO, "received bog= us data from ovpn-dco");
+ return NL_STOP;
+ }
+=
+ /* we must know= which interface this message is referring to in order to
+ * avoid mixing messages for othe= r instances
+ */<= /span>
+ if (!attrs[OVPN_= ATTR_IFINDEX])
+ {=
+ msg(D_DCO, = "ovpn-dco: Received message without ifindex");
+ return NL_STOP;
+ }

+
+ uint32_t ifindex =3D nla_get_u32(attrs[OVPN_ATTR_IFINDEX]);
+ if (ifindex !=3D dc= o->ifindex)
+ {=
+ msg(D_DCO_D= EBUG, "ovpn-dco: ignoring message for foreign ifindex %d",=
+ ifindex);
return NL_SKIP;
}

- dco_update_peer= _stat(&m->instances[peer_id]->context.c2, tb_peer, peer_id);
+ /* based on the mess= age type, we parse the subobject contained in the
+ * message, that stores the type-specific= attributes.
+ *<= /span>
+ * the "dco= " object is then filled accordingly with the information
+ * retrieved from the message= , so that *process_incoming_dco can react

+ * as need be.
+ */
+ int ret;
+ switch (gnlh->cmd)
+ {
+ = case OVPN_CMD_GET_PEER:
+ {
+ = /* return directly, there are no messages to pass to
+ * *process_incoming_d= co()

+ */=
+ return = ovpn_handle_peer(dco, attrs);
+ }
+=
+ case OVPN_C= MD_DEL_PEER:
+ = {
+ ret = =3D ovpn_handle_del_peer(dco, attrs);
+ break;
+ }
+
+ defa= ult:
+ msg= (D_DCO, "ovpn-dco: received unknown command: %d", gnlh->cmd);<= /span>
+ dco->= dco_message_type =3D 0;
+ return NL_STOP;
+ }
+
+ if (ret !=3D NL_O= K)
+ {
<= span style=3D"color: hsl(120, 100%, 40%);">+ return ret;

<= span style=3D"color: hsl(120, 100%, 40%);">+ }

+
+ if (dco->c->mode =3D=3D CM_TOP)
+ {
+ multi_process_incoming_dco(dco);
+ }

+ else
+ {
+ process_incoming_dco(dco);
+ }

return NL_OK;=
}
@@ -931,57 +999,29 @@
= {
msg(D_DCO_DEBUG, "%s", __func__);
+ if (__= is_locked)
+ {
+ msg(D_DCO_DEBUG= , "%s: cannot request peer stats while parsing other messages",
+ __func__)= ;
+ return 0;<= /span>
+ }
+

+ ASSERT(dco->c->multi =3D=3D m);
<= span style=3D"color: hsl(120, 100%, 40%);">+

struct nl= _msg *nl_msg =3D ovpn_dco_nlmsg_create(dco, OVPN_CMD_GET_PEER);
<= span style=3D"color: hsl(120, 100%, 40%);">+ if (!nl_msg)

+ {

+ return -ENOMEM;
+ }

= nlmsg_hdr(nl_msg)->nlmsg_flags |=3D NLM_F_DUMP;

- int ret =3D ovpn_nl_msg= _send(dco, nl_msg, dco_parse_peer_multi, m, __func__);
+ int ret =3D ovpn_nl_msg_send(dco, nl= _msg, __func__);

nlmsg_free(nl_msg);=
return ret;
}

-static int
-dco_parse_peer(struct nl_msg *msg, vo= id *arg)

-{
<= span style=3D"color: hsl(0, 100%, 40%);">- struct context *c =3D arg;
- struct nlattr *tb[OV= PN_ATTR_MAX + 1];
- = struct genlmsghdr *gnlh =3D nlmsg_data(nlmsg_hdr(msg));
-
- msg(D_DCO_DEBUG, "%s: parsing message...", __fun= c__);
-
- nla_parse(tb, OVPN_ATTR_MAX, genl= msg_attrdata(gnlh, 0),

= - genlmsg_attrlen(gnlh, 0), NULL);
-
- if (!tb[OVPN_ATTR_GET_PEER])
- {
-= msg(D_DCO_DEBUG, "%s: malformed reply", __func__);=
- return NL_SKIP;
- }
-
- struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX + 1];
-
- nla_parse(tb_peer, OVPN_GET_PEER_RESP_A= TTR_MAX,
- = nla_data(tb[OVPN_ATTR_GET_PEER]),
- nla_len(tb[OVPN_ATTR_GET_PEER]), NULL);-
- if (!tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID])<= /span>
- {
- msg(M_WARN, "%s: no peer-= id provided in reply", __func__);
- return NL_SKIP;
- }
- uint32_t peer_= id =3D nla_get_u32(tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID]);
- if (c->c2.tls_multi->dco_= peer_id !=3D peer_id)

-= {
- return N= L_SKIP;
- }-
- dco_update_peer_stat(&c->c2, tb_peer, pe= er_id);
-
- return NL_OK;

-}
-
int
dco_get_peer_stats(s= truct context *c)
{
@@ -993,6 +1033,13 @@<= /span>
return 0;
}
=
+ if (__is_locked= )
+ {
+ msg(D_DCO_DEBUG, "%= s: cannot request peer stats while parsing other messages",

= + __func__);<= br>+ return 0;+ }
+
dco_context_t *dco = =3D &c->c1.tuntap->dco;
struct nl_msg *nl_ms= g =3D ovpn_dco_nlmsg_create(dco, OVPN_CMD_GET_PEER);
s= truct nlattr *attr =3D nla_nest_start(nl_msg, OVPN_ATTR_GET_PEER);@@ -1001,7 +1048,7 @@
NLA_PUT_U32(nl_msg, OVPN= _GET_PEER_ATTR_PEER_ID, peer_id);
nla_nest_end(nl_msg,= attr);

- ret =3D ovpn_nl_msg_send(dco, nl_msg, dco_parse_peer, c, __func__);=
+ ret =3D ovpn_nl= _msg_send(dco, nl_msg, __func__);

nla_pu= t_failure:
nlmsg_free(nl_msg);
diff --= git a/src/openvpn/dco_linux.h b/src/openvpn/dco_linux.h
ind= ex cf6bdd4..9209915 100644
--- a/src/openvpn/dco_linux.h
+++ b/src/openvpn/dco_linux.h
@@ -44,6 +44,7 = @@
int status;

= struct context *c;
+ = int ctrlid;

enum ovpn_mode ifmode= ;

@@ -55,8 +56,6 @@
= int dco_message_type;
int dco_message_peer_id;<= br> int dco_del_peer_reason;
- uint64_t dco_read_bytes;
- uint64_t dco_write_bytes;
} dc= o_context_t;

#endif /* defined(ENABLE_DC= O) && defined(TARGET_LINUX) */
diff --git a/src/ope= nvpn/dco_win.c b/src/openvpn/dco_win.c
index bc465db..b11d5= 06 100644
--- a/src/openvpn/dco_win.c
+++ b= /src/openvpn/dco_win.c
@@ -423,7 +423,7 @@
= }

int
-dco_do_read(dco_context_t *dco)
+dco_read_and_process(dco_context_t *dco)<= /span>
{
/* no-op on windows */
ASSERT(0);

diff --git a/src/openvpn/forward.c b/sr= c/openvpn/forward.c
index 4e9e739..e43ce28 100644--- a/src/openvpn/forward.c
+++ b/src/openvpn/forwar= d.c
@@ -1269,13 +1269,11 @@
} }

-static void
-pro= cess_incoming_dco(struct context *c)
+void
+process_incoming_dco(dco_context_t *dco)
{
#if defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TA= RGET_FREEBSD))

- dco= _context_t *dco =3D &c->c1.tuntap->dco;
-
- dco_do_read(dco);
+ struct context *c =3D dco->c;

<= span> /* FreeBSD currently sends us removal notifcation with the old pe= er-id in

* p2p mode with the ping timeout reason, so = ignore that one to not shoot
@@ -1291,6 +1289,8 @@ switch (dco->dco_message_type)
{
case OVPN_CMD_DEL_PEER:
+ /* peer is gone, unset ID to prevent mo= re kernel calls */
+ = c->c2.tls_multi->dco_peer_id =3D -1;
= if (dco->dco_del_peer_reason =3D=3D OVPN_DEL_PEER_REASON_EXPIRED= )
{
msg(D_DCO= _DEBUG, "%s: received peer expired notification of for peer-id "<= /span>
@@ -2344,7 +2344,7 @@
{
if (!IS_SIG(c))

{
- process_incoming_dco(c);=
+ dco_read_and_p= rocess(&c->c1.tuntap->dco);
}
= }
}
diff --git a/src/openvpn/fo= rward.h b/src/openvpn/forward.h
index 3d0abd5..1de2aa2 1006= 44
--- a/src/openvpn/forward.h
+++ b/src/op= envpn/forward.h
@@ -50,6 +50,7 @@
#include= "openvpn.h"
#include "occ.h" #include "ping.h"
+#include "dco.h"

#define IOW_TO_TUN (1<<0)

#define IOW_T= O_LINK (1<<1)
@@ -248,6 +249,12 @@
= */
void process_incoming_tun(struct context *c);

+/**=
+ * Process an incom= ing DCO message (from kernel space).
+ *
+= * @param dco - Pointer to the structure representing the DCO context.
+ */
+void process_incoming_dco(dco_context_t = *dco);

/**
* Write a p= acket to the virtual tun/tap network interface.
diff --git = a/src/openvpn/mtcp.c b/src/openvpn/mtcp.c
index 38c938e..b1= 714c8 100644
--- a/src/openvpn/mtcp.c
+++ b= /src/openvpn/mtcp.c
@@ -747,7 +747,7 @@
= /* incoming data on DCO? */
else if = (e->arg =3D=3D MTCP_DCO)
{
- multi_process_incoming= _dco(m);
+ = dco_read_and_process(&m->top.c1.tuntap->dco);
}

#endif
/* si= gnal received? */
diff --git a/src/openvpn/mudp.c b/src/ope= nvpn/mudp.c
index 8cc717b..9a71eeb 100644
-= -- a/src/openvpn/mudp.c
+++ b/src/openvpn/mudp.c
= @@ -409,11 +409,7 @@
{
= if (!IS_SIG(&m->top))
{
- bool ret =3D true;
= - while (ret)- {
- ret =3D multi_process_= incoming_dco(m);
- = }
+ = dco_read_and_process(&m->top.c1.tuntap->dco);
= }
}
#endif
dif= f --git a/src/openvpn/multi.c b/src/openvpn/multi.c
index 6= 9497a6..7620065 100644
--- a/src/openvpn/multi.c
= +++ b/src/openvpn/multi.c
@@ -3287,20 +3287,17 @@
* installed, and we do not need to clean up the state in= the kernel */
mi->context.c2.tls_multi->dco_pee= r_id =3D -1;
mi->context.sig->signal_text =3D re= ason;
- mi->conte= xt.c2.dco_read_bytes =3D dco->dco_read_bytes;
- mi->context.c2.dco_write_bytes =3D dco-&g= t;dco_write_bytes;
multi_signal_instance(m, mi, SIGTER= M);
}

-bool
-multi_process_incoming_dco(struct multi_context *m)
+void
+multi_process_incoming_dco(dco_context_t *dco) {
- dco_cont= ext_t *dco =3D &m->top.c1.tuntap->dco;
+ ASSERT(dco->c->multi);

+ struct mult= i_context *m =3D dco->c->multi;
struct multi_ins= tance *mi =3D NULL;

- int ret =3D dco_do_read(&m->top.c1.tuntap->dc= o);
-
= int peer_id =3D dco->dco_message_peer_id;
/* no peer-specific message delivered -> nothing to process= .
@@ -3308,7 +3305,7 @@
*/
= if (peer_id < 0)
{
- return ret > 0;
+ return;
= }

if ((peer_id < m->max_clien= ts) && (m->instances[peer_id]))
@@ -3355,13 +335= 2,6 @@
"type %d, del_peer_reason %d"= , peer_id, dco->dco_message_type,
dco->d= co_del_peer_reason);
}
-
= - dco->dco_message_type =3D 0;
- dco->dco_message_peer_id =3D -1;
- dco->dco_del_peer_reason =3D -1;
- dco->dco_read_byt= es =3D 0;
- dco->= dco_write_bytes =3D 0;
= - return ret > 0;
}
#endif /* if de= fined(ENABLE_DCO) && defined(TARGET_LINUX) */

diff --git a/src/openvpn/multi.h b/src/openvpn/multi.h<= br>index 7167639..1b784e1 100644
--- a/src/openvpn/mu= lti.h
+++ b/src/openvpn/multi.h
@@ -317,13 = +317,9 @@
/**
* Process an incoming DCO = message (from kernel space).
*
- * @param m - The single \c multi_con= text structur.e
- *
- * @return
- * - True, if the message was recei= ved correctly.

- * - F= alse, if there was an error while reading the message.
+ * @param dco - The DCO context containi= ng the parsed message.
*/
-bool multi_process_incoming_dco(struct multi_context = *m);
+void multi_proc= ess_incoming_dco(dco_context_t *dco);

/*= *************************************************************************/<= /span>
/**

To view, visit change 1632= . To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: release/2.6
Gerrit-Change-Id: I92c5f74a27b40fede204f714b04= 2a6cc80b3703e
Gerrit-Change-Number: 1632
Gerrit-PatchSet: 3
Gerrit-Owner: ralf_lici <ralf@...2726...>= ;
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --Y9m7DFyQ0f4=--