From: "its_Giaan (Code Review)" Date: Thu, 6 Jun 2024 11:33:42 +0000 References: Reply-To: gianmarco@...2726..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="3K8KSMjus+E="; charset=UTF-8 Subject: [Openvpn-devel] [XL] Change in openvpn[master]: Lay the foundation to support both old and new versions of DCO List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --3K8KSMjus+E= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/662?usp=3Demail to review the following change. Change subject: Lay the foundation to support both old and new versions of = DCO ...................................................................... Lay the foundation to support both old and new versions of DCO Added a new abstraction layer based on the `struct dco_ops`, a structure of function pointers that ensures the appropriate APIs at runtime are used for DCO communication between kernel and user space, selection is based on the available module's family name. The old version, referred to as "ovpn_dco_v2", and its related commands and functions, will be distinguished with the "v2" suffix. Change-Id: I6662605b60d4859949970cfe256c55cbcbd4a672 Signed-off-by: Gianmarco De Gregori --- M CMakeLists.txt M src/openvpn/Makefile.am M src/openvpn/dco.c M src/openvpn/dco.h M src/openvpn/dco_freebsd.c M src/openvpn/dco_linux.c M src/openvpn/dco_linux.h A src/openvpn/dco_linux_v2.c M src/openvpn/dco_win.c M src/openvpn/forward.c 10 files changed, 923 insertions(+), 655 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/62/662/1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 096837d..732be9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -398,6 +398,7 @@ src/openvpn/dco_win.h src/openvpn/dco_linux.c src/openvpn/dco_linux.h + src/openvpn/dco_linux_v2.c src/openvpn/dco_freebsd.c src/openvpn/dco_freebsd.h src/openvpn/dhcp.c diff --git a/src/openvpn/Makefile.am b/src/openvpn/Makefile.am index 56cce9d..286d3c5 100644 --- a/src/openvpn/Makefile.am +++ b/src/openvpn/Makefile.am @@ -54,6 +54,7 @@ dco.c dco.h dco_internal.h \ dco_freebsd.c dco_freebsd.h \ dco_linux.c dco_linux.h \ + dco_linux_v2.c \ dco_win.c dco_win.h \ dhcp.c dhcp.h \ dns.c dns.h \ diff --git a/src/openvpn/dco.c b/src/openvpn/dco.c index 78243b1..80184f8 100644 --- a/src/openvpn/dco.c +++ b/src/openvpn/dco.c @@ -396,7 +396,7 @@ /* now that all options have been confirmed to be supported, check * if DCO is truly available on the system */ - return dco_available(msglevel); + return dco_available(msglevel, NULL); } bool diff --git a/src/openvpn/dco.h b/src/openvpn/dco.h index 50ebb35..fc34da8 100644 --- a/src/openvpn/dco.h +++ b/src/openvpn/dco.h @@ -56,7 +56,7 @@ * @param msglevel level to print messages to * @return true if ovpn-dco is available, false otherwise */ -bool dco_available(int msglevel); +bool dco_available(int msglevel, dco_context_t *dco); /** @@ -254,7 +254,7 @@ typedef void *dco_context_t; static inline bool -dco_available(int msglevel) +dco_available(int msglevel, dco_context_t *dco) { return false; } diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c index 7c8b29c..93c0813 100644 --- a/src/openvpn/dco_freebsd.c +++ b/src/openvpn/dco_freebsd.c @@ -569,7 +569,7 @@ } bool -dco_available(int msglevel) +dco_available(int msglevel, dco_context_t *dco) { struct if_clonereq ifcr; char *buf =3D NULL; diff --git a/src/openvpn/dco_linux.c b/src/openvpn/dco_linux.c index b2584b9..4feae6d 100644 --- a/src/openvpn/dco_linux.c +++ b/src/openvpn/dco_linux.c @@ -51,32 +51,28 @@ #include -/* 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 - * parsing of the message - */ -#define nla_nest_start(_msg, _type) \ - nla_nest_start(_msg, (_type) | NLA_F_NESTED) - -static int ovpn_get_mcast_id(dco_context_t *dco); - -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 - * - * This function queries the kernel via a netlink socket - * whether the ovpn-dco netlink namespace is available - * - * This function can be used to determine if the kernel - * supports DCO offloading. - * - * @return ID on success, negative error code on error - */ static int -resolve_ovpn_netlink_id(int msglevel) +do_family_name_resolve(struct nl_sock *nl_sock, int msglevel, const char *= family_name, + dco_context_t *dco, const struct dco_ops *ops) +{ + int ret =3D genl_ctrl_resolve(nl_sock, family_name); + + if (ret < 0) + { + msg(msglevel, "Cannot find %s netlink component: %s", family_name,= nl_geterror(ret)); + } + + if (dco) + { + /* Ensures that we will use the proper ops for the dco version ava= ilable */ + dco->ops =3D ops; + } + + return ret; +} + +int +resolve_ovpn_netlink_id(int msglevel, dco_context_t *dco) { int ret; struct nl_sock *nl_sock =3D nl_socket_alloc(); @@ -96,39 +92,14 @@ } set_cloexec(nl_socket_get_fd(nl_sock)); - ret =3D genl_ctrl_resolve(nl_sock, OVPN_NL_NAME); - if (ret < 0) - { - msg(msglevel, "Cannot find ovpn_dco netlink component: %s", - nl_geterror(ret)); - } + ret =3D do_family_name_resolve(nl_sock, msglevel, OVPN_NL_NAME, dco, &= dco_ops_v2); err_sock: nl_socket_free(nl_sock); return ret; } -static struct nl_msg * -ovpn_dco_nlmsg_create(dco_context_t *dco, enum ovpn_nl_commands cmd) -{ - struct nl_msg *nl_msg =3D nlmsg_alloc(); - if (!nl_msg) - { - msg(M_ERR, "cannot allocate netlink message"); - return NULL; - } - - genlmsg_put(nl_msg, 0, 0, dco->ovpn_dco_id, 0, 0, cmd, 0); - NLA_PUT_U32(nl_msg, OVPN_ATTR_IFINDEX, dco->ifindex); - - return nl_msg; -nla_put_failure: - nlmsg_free(nl_msg); - msg(M_INFO, "cannot put into netlink message"); - return NULL; -} - -static int +int ovpn_nl_recvmsgs(dco_context_t *dco, const char *prefix) { int ret =3D nl_recvmsgs(dco->nl_sock, dco->nl_cb); @@ -166,18 +137,7 @@ return ret; } -/** - * Send a prepared netlink message and registers cb as callback if non-nul= l. - * - * 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 +int ovpn_nl_msg_send(dco_context_t *dco, struct nl_msg *nl_msg, ovpn_nl_cb cb, void *cb_arg, const char *prefix) { @@ -218,71 +178,6 @@ } int -dco_new_peer(dco_context_t *dco, unsigned int peerid, int sd, - struct sockaddr *localaddr, struct sockaddr *remoteaddr, - struct in_addr *remote_in4, struct in6_addr *remote_in6) -{ - struct gc_arena gc =3D gc_new(); - const char *remotestr =3D "[undefined]"; - if (remoteaddr) - { - remotestr =3D print_sockaddr(remoteaddr, &gc); - } - msg(D_DCO_DEBUG, "%s: peer-id %d, fd %d, remote addr: %s", __func__, - peerid, sd, remotestr); - - struct nl_msg *nl_msg =3D ovpn_dco_nlmsg_create(dco, OVPN_CMD_NEW_PEER= ); - struct nlattr *attr =3D nla_nest_start(nl_msg, OVPN_ATTR_NEW_PEER); - int ret =3D -EMSGSIZE; - - NLA_PUT_U32(nl_msg, OVPN_NEW_PEER_ATTR_PEER_ID, peerid); - NLA_PUT_U32(nl_msg, OVPN_NEW_PEER_ATTR_SOCKET, sd); - - /* Set the remote endpoint if defined (for UDP) */ - if (remoteaddr) - { - remoteaddr =3D mapped_v4_to_v6(remoteaddr, &gc); - int alen =3D af_addr_size(remoteaddr->sa_family); - - NLA_PUT(nl_msg, OVPN_NEW_PEER_ATTR_SOCKADDR_REMOTE, alen, remotead= dr); - } - - if (localaddr) - { - localaddr =3D mapped_v4_to_v6(localaddr, &gc); - if (localaddr->sa_family =3D=3D AF_INET) - { - NLA_PUT(nl_msg, OVPN_NEW_PEER_ATTR_LOCAL_IP, sizeof(struct in_= addr), - &((struct sockaddr_in *)localaddr)->sin_addr); - } - else if (localaddr->sa_family =3D=3D AF_INET6) - { - NLA_PUT(nl_msg, OVPN_NEW_PEER_ATTR_LOCAL_IP, sizeof(struct in6= _addr), - &((struct sockaddr_in6 *)localaddr)->sin6_addr); - } - } - - /* Set the primary VPN IP addresses of the peer */ - if (remote_in4) - { - NLA_PUT_U32(nl_msg, OVPN_NEW_PEER_ATTR_IPV4, remote_in4->s_addr); - } - if (remote_in6) - { - NLA_PUT(nl_msg, OVPN_NEW_PEER_ATTR_IPV6, sizeof(struct in6_addr), - remote_in6); - } - nla_nest_end(nl_msg, attr); - - ret =3D ovpn_nl_msg_send(dco, nl_msg, NULL, NULL, __func__); - -nla_put_failure: - nlmsg_free(nl_msg); - gc_free(&gc); - return ret; -} - -static int ovpn_nl_cb_finish(struct nl_msg (*msg) __attribute__ ((unused)), void *arg) { int *status =3D arg; @@ -291,15 +186,7 @@ return NL_SKIP; } =20 -/* This function is used as error callback on the netlink socket. - * When something goes wrong and the kernel returns an error, this functio= n is - * invoked. - * - * We pass the error code to the user by means of a variable pointed by *a= rg - * (supplied by the user when setting this callback) and we parse the kern= el - * reply to see if it contains a human-readable error. If found, it is pri= nted. - */ -static int +int ovpn_nl_cb_error(struct sockaddr_nl (*nla) __attribute__ ((unused)), struct nlmsgerr *err, void *arg) { @@ -342,10 +229,16 @@ return NL_STOP; } -static void +void ovpn_dco_init_netlink(dco_context_t *dco) { - dco->ovpn_dco_id =3D resolve_ovpn_netlink_id(M_ERR); + struct gc_arena gc =3D gc_new(); + if (!dco->ops) + { + ALLOC_OBJ_CLEAR_GC(dco->ops, struct dco_ops, &gc); + } + + dco->ovpn_dco_id =3D resolve_ovpn_netlink_id(M_ERR, dco); dco->nl_sock =3D nl_socket_alloc(); @@ -388,6 +281,7 @@ * overrun with very fast connecting/disconnecting clients. * TODO: fix this in a better and more reliable way */ ASSERT(!nl_socket_set_buffer_size(dco->nl_sock, 1024*1024, 1024*1024)); + gc_free(&gc); } bool @@ -411,7 +305,7 @@ return true; } -static void +void ovpn_dco_uninit_netlink(dco_context_t *dco) { nl_socket_free(dco->nl_sock); @@ -423,7 +317,7 @@ CLEAR(dco); } -static void +void ovpn_dco_register(dco_context_t *dco) { msg(D_DCO_DEBUG, __func__); @@ -447,205 +341,11 @@ int open_tun_dco(struct tuntap *tt, openvpn_net_ctx_t *ctx, const char *dev) { - msg(D_DCO_DEBUG, "%s: %s", __func__, dev); - ASSERT(tt->type =3D=3D DEV_TYPE_TUN); - - int ret =3D net_iface_new(ctx, dev, "ovpn-dco", &tt->dco); - if (ret < 0) - { - msg(D_DCO_DEBUG, "Cannot create DCO interface %s: %d", dev, ret); - return ret; - } - - tt->dco.ifindex =3D if_nametoindex(dev); - if (!tt->dco.ifindex) - { - msg(M_FATAL, "DCO: cannot retrieve ifindex for interface %s", dev); - } - - tt->dco.dco_message_peer_id =3D -1; - - ovpn_dco_register(&tt->dco); - - return 0; -} - -void -close_tun_dco(struct tuntap *tt, openvpn_net_ctx_t *ctx) -{ - msg(D_DCO_DEBUG, __func__); - - net_iface_del(ctx, tt->actual_name); - ovpn_dco_uninit_netlink(&tt->dco); -} - -int -dco_swap_keys(dco_context_t *dco, unsigned int peerid) -{ - msg(D_DCO_DEBUG, "%s: peer-id %d", __func__, peerid); - - struct nl_msg *nl_msg =3D ovpn_dco_nlmsg_create(dco, OVPN_CMD_SWAP_KEY= S); - if (!nl_msg) - { - return -ENOMEM; - } - - struct nlattr *attr =3D nla_nest_start(nl_msg, OVPN_ATTR_SWAP_KEYS); - int ret =3D -EMSGSIZE; - 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__); - -nla_put_failure: - nlmsg_free(nl_msg); - return ret; -} - - -int -dco_del_peer(dco_context_t *dco, unsigned int peerid) -{ - msg(D_DCO_DEBUG, "%s: peer-id %d", __func__, peerid); - - struct nl_msg *nl_msg =3D ovpn_dco_nlmsg_create(dco, OVPN_CMD_DEL_PEER= ); - if (!nl_msg) - { - return -ENOMEM; - } - - struct nlattr *attr =3D nla_nest_start(nl_msg, OVPN_ATTR_DEL_PEER); - int ret =3D -EMSGSIZE; - 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__); - -nla_put_failure: - nlmsg_free(nl_msg); - return ret; -} - - -int -dco_del_key(dco_context_t *dco, unsigned int peerid, - dco_key_slot_t slot) -{ - msg(D_DCO_DEBUG, "%s: peer-id %d, slot %d", __func__, peerid, slot); - - struct nl_msg *nl_msg =3D ovpn_dco_nlmsg_create(dco, OVPN_CMD_DEL_KEY); - if (!nl_msg) - { - return -ENOMEM; - } - - struct nlattr *attr =3D nla_nest_start(nl_msg, OVPN_ATTR_DEL_KEY); - int ret =3D -EMSGSIZE; - NLA_PUT_U32(nl_msg, OVPN_DEL_KEY_ATTR_PEER_ID, peerid); - 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__); - -nla_put_failure: - nlmsg_free(nl_msg); + int ret =3D tt->dco.ops->open_tun_dco(tt, ctx, dev); return ret; } int -dco_new_key(dco_context_t *dco, unsigned int peerid, int keyid, - dco_key_slot_t slot, - const uint8_t *encrypt_key, const uint8_t *encrypt_iv, - const uint8_t *decrypt_key, const uint8_t *decrypt_iv, - const char *ciphername) -{ - msg(D_DCO_DEBUG, "%s: slot %d, key-id %d, peer-id %d, cipher %s", - __func__, slot, keyid, peerid, ciphername); - - const size_t key_len =3D cipher_kt_key_size(ciphername); - const int nonce_tail_len =3D 8; - - struct nl_msg *nl_msg =3D ovpn_dco_nlmsg_create(dco, OVPN_CMD_NEW_KEY); - if (!nl_msg) - { - return -ENOMEM; - } - - dco_cipher_t dco_cipher =3D dco_get_cipher(ciphername); - - int ret =3D -EMSGSIZE; - struct nlattr *attr =3D nla_nest_start(nl_msg, OVPN_ATTR_NEW_KEY); - NLA_PUT_U32(nl_msg, OVPN_NEW_KEY_ATTR_PEER_ID, peerid); - NLA_PUT_U8(nl_msg, OVPN_NEW_KEY_ATTR_KEY_SLOT, slot); - NLA_PUT_U8(nl_msg, OVPN_NEW_KEY_ATTR_KEY_ID, keyid); - NLA_PUT_U16(nl_msg, OVPN_NEW_KEY_ATTR_CIPHER_ALG, dco_cipher); - - struct nlattr *key_enc =3D nla_nest_start(nl_msg, - OVPN_NEW_KEY_ATTR_ENCRYPT_KEY); - if (dco_cipher !=3D OVPN_CIPHER_ALG_NONE) - { - NLA_PUT(nl_msg, OVPN_KEY_DIR_ATTR_CIPHER_KEY, key_len, encrypt_key= ); - NLA_PUT(nl_msg, OVPN_KEY_DIR_ATTR_NONCE_TAIL, nonce_tail_len, - encrypt_iv); - } - nla_nest_end(nl_msg, key_enc); - - struct nlattr *key_dec =3D nla_nest_start(nl_msg, - OVPN_NEW_KEY_ATTR_DECRYPT_KEY); - if (dco_cipher !=3D OVPN_CIPHER_ALG_NONE) - { - NLA_PUT(nl_msg, OVPN_KEY_DIR_ATTR_CIPHER_KEY, key_len, decrypt_key= ); - NLA_PUT(nl_msg, OVPN_KEY_DIR_ATTR_NONCE_TAIL, nonce_tail_len, - decrypt_iv); - } - nla_nest_end(nl_msg, key_dec); - - nla_nest_end(nl_msg, attr); - - ret =3D ovpn_nl_msg_send(dco, nl_msg, NULL, NULL, __func__); - -nla_put_failure: - nlmsg_free(nl_msg); - return ret; -} - -int -dco_set_peer(dco_context_t *dco, unsigned int peerid, - int keepalive_interval, int keepalive_timeout, int mss) -{ - msg(D_DCO_DEBUG, "%s: peer-id %d, keepalive %d/%d, mss %d", __func__, - peerid, keepalive_interval, keepalive_timeout, mss); - - struct nl_msg *nl_msg =3D ovpn_dco_nlmsg_create(dco, OVPN_CMD_SET_PEER= ); - if (!nl_msg) - { - return -ENOMEM; - } - - struct nlattr *attr =3D nla_nest_start(nl_msg, OVPN_ATTR_SET_PEER); - int ret =3D -EMSGSIZE; - NLA_PUT_U32(nl_msg, OVPN_SET_PEER_ATTR_PEER_ID, peerid); - NLA_PUT_U32(nl_msg, OVPN_SET_PEER_ATTR_KEEPALIVE_INTERVAL, - keepalive_interval); - NLA_PUT_U32(nl_msg, OVPN_SET_PEER_ATTR_KEEPALIVE_TIMEOUT, - keepalive_timeout); - nla_nest_end(nl_msg, attr); - - ret =3D ovpn_nl_msg_send(dco, nl_msg, NULL, NULL, __func__); - -nla_put_failure: - nlmsg_free(nl_msg); - return ret; -} - -/* This function parses the reply provided by the kernel to the CTRL_CMD_G= ETFAMILY - * message. We parse the reply and we retrieve the multicast group ID asso= ciated - * with the "ovpn-dco" netlink family. - * - * The ID is later used to subscribe to the multicast group and be notified - * about any multicast message sent by the ovpn-dco kernel module. - */ -static int mcast_family_handler(struct nl_msg *msg, void *arg) { dco_context_t *dco =3D arg; @@ -687,12 +387,8 @@ return NL_SKIP; } -/** - * Lookup the multicast id for OpenVPN. This method and its help method cu= rrently - * hardcode the lookup to OVPN_NL_NAME and OVPN_NL_MULTICAST_GROUP_PEERS b= ut - * extended in the future if we need to lookup more than one mcast id. - */ -static int + +int ovpn_get_mcast_id(dco_context_t *dco) { dco->ovpn_dco_mcast_id =3D -ENOENT; @@ -719,299 +415,15 @@ return ret; } -/* 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) -{ - 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__); -} - -static void -dco_update_peer_stat(struct context_2 *c2, struct nlattr *tb[], uint32_t i= d) -{ - if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES]) - { - c2->dco_read_bytes =3D nla_get_u64(tb[OVPN_GET_PEER_RESP_ATTR_LINK= _RX_BYTES]); - msg(D_DCO_DEBUG, "%s / dco_read_bytes: " counter_format, __func__, - c2->dco_read_bytes); - } - else - { - msg(M_WARN, "%s: no link RX bytes provided in reply for peer %u", - __func__, id); - } - - if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES]) - { - c2->dco_write_bytes =3D nla_get_u64(tb[OVPN_GET_PEER_RESP_ATTR_LIN= K_TX_BYTES]); - msg(D_DCO_DEBUG, "%s / dco_write_bytes: " counter_format, __func__, - c2->dco_write_bytes); - } - else - { - msg(M_WARN, "%s: no link TX bytes provided in reply for peer %u", - __func__, id); - } - - if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES]) - { - c2->tun_read_bytes =3D nla_get_u64(tb[OVPN_GET_PEER_RESP_ATTR_VPN_= RX_BYTES]); - msg(D_DCO_DEBUG, "%s / tun_read_bytes: " counter_format, __func__, - c2->tun_read_bytes); - } - else - { - msg(M_WARN, "%s: no VPN RX bytes provided in reply for peer %u", - __func__, id); - } - - if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_TX_BYTES]) - { - c2->tun_write_bytes =3D nla_get_u64(tb[OVPN_GET_PEER_RESP_ATTR_VPN= _TX_BYTES]); - msg(D_DCO_DEBUG, "%s / tun_write_bytes: " counter_format, __func__, - c2->tun_write_bytes); - } - else - { - msg(M_WARN, "%s: no VPN TX bytes provided in reply for peer %u", - __func__, id); - } -} - -int -dco_parse_peer_multi(struct nl_msg *msg, void *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]) - { - 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; - } - - struct multi_context *m =3D arg; - uint32_t peer_id =3D nla_get_u32(tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_= ID]); - - if (peer_id >=3D m->max_clients || !m->instances[peer_id]) - { - msg(M_WARN, "%s: cannot store DCO stats for peer %u", __func__, - peer_id); - return NL_SKIP; - } - - dco_update_peer_stat(&m->instances[peer_id]->context.c2, tb_peer, peer= _id); - - return NL_OK; -} - -int -dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m) -{ - msg(D_DCO_DEBUG, "%s", __func__); - - struct nl_msg *nl_msg =3D ovpn_dco_nlmsg_create(dco, OVPN_CMD_GET_PEER= ); - - 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__); - - 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) -{ - uint32_t peer_id =3D c->c2.tls_multi->dco_peer_id; - msg(D_DCO_DEBUG, "%s: peer-id %d", __func__, peer_id); - - if (!c->c1.tuntap) - { - 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); - int ret =3D -EMSGSIZE; - - 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__); - -nla_put_failure: - nlmsg_free(nl_msg); - return ret; -} - bool -dco_available(int msglevel) +dco_available(int msglevel, dco_context_t *dco) { - if (resolve_ovpn_netlink_id(D_DCO_DEBUG) < 0) + if (resolve_ovpn_netlink_id(D_DCO_DEBUG, dco) < 0) { msg(msglevel, "Note: Kernel support for ovpn-dco missing, disabling data cha= nnel offload."); return false; } - return true; } @@ -1043,6 +455,94 @@ return BSTR(&out); } +int +dco_new_peer(dco_context_t *dco, unsigned int peerid, int sd, + struct sockaddr *localaddr, struct sockaddr *remoteaddr, + struct in_addr *remote_in4, struct in6_addr *remote_in6) +{ + int ret =3D dco->ops->dco_new_peer(dco, peerid, sd, localaddr, remotea= ddr, remote_in4, remote_in6); + return ret; +} + +void +close_tun_dco(struct tuntap *tt, openvpn_net_ctx_t *ctx) +{ + tt->dco.ops->close_tun_dco(tt, ctx); +} + +int +dco_swap_keys(dco_context_t *dco, unsigned int peerid) +{ + int ret =3D dco->ops->dco_swap_keys(dco, peerid); + return ret; +} + + +int +dco_del_peer(dco_context_t *dco, unsigned int peerid) +{ + int ret =3D dco->ops->dco_del_peer(dco, peerid); + return ret; +} + + +int +dco_del_key(dco_context_t *dco, unsigned int peerid, + dco_key_slot_t slot) +{ + int ret =3D dco->ops->dco_del_key(dco, peerid, slot); + return ret; +} + +int +dco_new_key(dco_context_t *dco, unsigned int peerid, int keyid, + dco_key_slot_t slot, + const uint8_t *encrypt_key, const uint8_t *encrypt_iv, + const uint8_t *decrypt_key, const uint8_t *decrypt_iv, + const char *ciphername) +{ + int ret =3D dco->ops->dco_new_key(dco, peerid, keyid, slot, encrypt_ke= y, encrypt_iv, decrypt_key, decrypt_iv, ciphername); + return ret; +} + +int +dco_set_peer(dco_context_t *dco, unsigned int peerid, + int keepalive_interval, int keepalive_timeout, int mss) +{ + int ret =3D dco->ops->dco_set_peer(dco, peerid, keepalive_interval, ke= epalive_timeout, mss); + return ret; +} + +int +dco_do_read(dco_context_t *dco) +{ + int ret =3D dco->ops->dco_do_read(dco); + return ret; +} + +int +dco_parse_peer_multi(struct nl_msg *msg, void *arg) +{ + struct multi_context *m =3D arg; + int ret =3D m->top.c1.tuntap->dco.ops->dco_parse_peer_multi(msg, arg); + + return ret; +} + +int +dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m) +{ + int ret =3D dco->ops->dco_get_peer_stats_multi(dco, m); + return ret; +} + +int +dco_get_peer_stats(struct context *c) +{ + int ret =3D c->c1.tuntap->dco.ops->dco_get_peer_stats(c); + return ret; +} + void dco_event_set(dco_context_t *dco, struct event_set *es, void *arg) { diff --git a/src/openvpn/dco_linux.h b/src/openvpn/dco_linux.h index 511519a..a3cf528 100644 --- a/src/openvpn/dco_linux.h +++ b/src/openvpn/dco_linux.h @@ -31,9 +31,30 @@ #include #include +#include +#include +#include + +#include "networking.h" +#include "fdmisc.h" + +/* forward declarations (including other headers leads to nasty include + * order problems) + */ +struct multi_context; +struct context_2; +struct key_ctx_bi; + typedef enum ovpn_key_slot dco_key_slot_t; typedef enum ovpn_cipher_alg dco_cipher_t; +/* 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 + * parsing of the message + */ +#define nla_nest_start(_msg, _type) \ + nla_nest_start(_msg, (_type) | NLA_F_NESTED) + typedef struct { @@ -53,7 +74,114 @@ int dco_del_peer_reason; uint64_t dco_read_bytes; uint64_t dco_write_bytes; + + const struct dco_ops *ops; } dco_context_t; +struct dco_ops +{ + struct nl_msg *(*ovpn_dco_nlmsg_create)(dco_context_t *dco, int cmd); + int (*dco_new_peer)(dco_context_t *dco, unsigned int peerid, int sd, s= truct sockaddr *localaddr, struct sockaddr *remoteaddr, struct in_addr *rem= ote_in4, struct in6_addr *remote_in6); + int (*open_tun_dco)(struct tuntap *tt, openvpn_net_ctx_t *ctx, const c= har *dev); + void (*close_tun_dco)(struct tuntap *tt, openvpn_net_ctx_t *ctx); + int (*dco_swap_keys)(dco_context_t *dco, unsigned int peerid); + int (*dco_del_peer)(dco_context_t *dco, unsigned int peerid); + int (*dco_del_key)(dco_context_t *dco, unsigned int peerid, dco_key_sl= ot_t slot); + int (*dco_new_key)(dco_context_t *dco, unsigned int peerid, int keyid,= dco_key_slot_t slot, const uint8_t *encrypt_key, const uint8_t *encrypt_iv= , const uint8_t *decrypt_key, const uint8_t *decrypt_iv, const char *cipher= name); + int (*dco_set_peer)(dco_context_t *dco, unsigned int peerid, int keepa= live_interval, int keepalive_timeout, int mss); + int (*ovpn_handle_msg)(struct nl_msg *msg, void *arg); + int (*dco_do_read)(dco_context_t *dco); + void (*dco_update_peer_stat)(struct context_2 *c2, struct nlattr *tb[]= , uint32_t id); + int (*dco_parse_peer_multi)(struct nl_msg *msg, void *arg); + int (*dco_get_peer_stats_multi)(dco_context_t *dco, struct multi_conte= xt *m); + int (*dco_parse_peer)(struct nl_msg *msg, void *arg); + int (*dco_get_peer_stats)(struct context *c); +}; + +extern const struct dco_ops dco_ops_v2; + +int ovpn_get_mcast_id(dco_context_t *dco); + +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 + * + * This function queries the kernel via a netlink socket + * whether the ovpn-dco netlink namespace is available + * + * This function can be used to determine if the kernel + * supports DCO offloading. + * + * @return ID on success, negative error code on error + */ +int resolve_ovpn_netlink_id(int msglevel, dco_context_t *dco); + +int ovpn_nl_recvmsgs(dco_context_t *dco, const char *prefix); + +/** + * Send a prepared netlink message and registers cb as callback if non-nul= l. + * + * 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 + */ +int ovpn_nl_msg_send(dco_context_t *dco, struct nl_msg *nl_msg, ovpn_nl_cb= cb, + void *cb_arg, const char *prefix); + +struct sockaddr * +mapped_v4_to_v6(struct sockaddr *sock, struct gc_arena *gc); + +int ovpn_nl_cb_finish(struct nl_msg (*msg) __attribute__ ((unused)), void = *arg); + +/* This function is used as error callback on the netlink socket. + * When something goes wrong and the kernel returns an error, this functio= n is + * invoked. + * + * We pass the error code to the user by means of a variable pointed by *a= rg + * (supplied by the user when setting this callback) and we parse the kern= el + * reply to see if it contains a human-readable error. If found, it is pri= nted. + */ +int ovpn_nl_cb_error(struct sockaddr_nl (*nla) __attribute__ ((unused)), + struct nlmsgerr *err, void *arg); + +void ovpn_dco_init_netlink(dco_context_t *dco); + +bool ovpn_dco_init(int mode, dco_context_t *dco); + +void ovpn_dco_uninit_netlink(dco_context_t *dco); + +void ovpn_dco_register(dco_context_t *dco); + +/* This function parses the reply provided by the kernel to the CTRL_CMD_G= ETFAMILY + * message. We parse the reply and we retrieve the multicast group ID asso= ciated + * with the "ovpn-dco" netlink family. + * + * The ID is later used to subscribe to the multicast group and be notified + * about any multicast message sent by the ovpn-dco kernel module. + */ +int mcast_family_handler(struct nl_msg *msg, void *arg); + +/** + * Lookup the multicast id for OpenVPN. This method and its help method cu= rrently + * hardcode the lookup to OVPN_NL_NAME and OVPN_NL_MULTICAST_GROUP_PEERS b= ut + * extended in the future if we need to lookup more than one mcast id. + */ +int ovpn_get_mcast_id(dco_context_t *dco); + +bool dco_available(int msglevel, dco_context_t *dco); + +const char *dco_version_string(struct gc_arena *gc); + +void dco_event_set(dco_context_t *dco, struct event_set *es, void *arg); + +const char *dco_get_supported_ciphers(); + #endif /* defined(ENABLE_DCO) && defined(TARGET_LINUX) */ #endif /* ifndef DCO_LINUX_H */ diff --git a/src/openvpn/dco_linux_v2.c b/src/openvpn/dco_linux_v2.c new file mode 100644 index 0000000..6fc47fa --- /dev/null +++ b/src/openvpn/dco_linux_v2.c @@ -0,0 +1,636 @@ +/* + * Interface to linux dco networking code + * + * Copyright (C) 2020-2024 Antonio Quartulli + * Copyright (C) 2020-2024 Arne Schwabe + * Copyright (C) 2020-2024 Gianmarco De Gregori + * Copyright (C) 2020-2024 OpenVPN Inc + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (see the file COPYING included with this + * distribution); if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#if defined(ENABLE_DCO) && defined(TARGET_LINUX) + +#include "syshead.h" + +#include "dco_linux.h" +#include "errlevel.h" +#include "buffer.h" +#include "networking.h" +#include "openvpn.h" + +#include "socket.h" +#include "tun.h" +#include "ssl.h" +#include "fdmisc.h" +#include "multi.h" +#include "ssl_verify.h" + +#include "ovpn_dco_linux.h" + +#include +#include +#include +#include +#include + +int +open_tun_dco_v2(struct tuntap *tt, openvpn_net_ctx_t *ctx, const char *dev) +{ + msg(D_DCO_DEBUG, "%s: %s", __func__, dev); + ASSERT(tt->type =3D=3D DEV_TYPE_TUN); + + int ret =3D net_iface_new(ctx, dev, "ovpn-dco", &tt->dco); + if (ret < 0) + { + msg(D_DCO_DEBUG, "Cannot create DCO interface %s: %d", dev, ret); + return ret; + } + + tt->dco.ifindex =3D if_nametoindex(dev); + if (!tt->dco.ifindex) + { + msg(M_FATAL, "DCO: cannot retrieve ifindex for interface %s", dev); + } + + tt->dco.dco_message_peer_id =3D -1; + + ovpn_dco_register(&tt->dco); + + return 0; +} + +static struct nl_msg * +ovpn_dco_v2_nlmsg_create(dco_context_t *dco, int cmd) +{ + enum ovpn_nl_commands enum_cmd =3D (enum ovpn_nl_commands)cmd; + struct nl_msg *nl_msg =3D nlmsg_alloc(); + if (!nl_msg) + { + msg(M_ERR, "cannot allocate netlink message"); + return NULL; + } + + genlmsg_put(nl_msg, 0, 0, dco->ovpn_dco_id, 0, 0, enum_cmd, 0); + NLA_PUT_U32(nl_msg, OVPN_ATTR_IFINDEX, dco->ifindex); + + return nl_msg; +nla_put_failure: + nlmsg_free(nl_msg); + msg(M_INFO, "cannot put into netlink message"); + return NULL; +} + +int +dco_v2_new_peer(dco_context_t *dco, unsigned int peerid, int sd, + struct sockaddr *localaddr, struct sockaddr *remoteaddr, + struct in_addr *remote_in4, struct in6_addr *remote_in6) +{ + struct gc_arena gc =3D gc_new(); + const char *remotestr =3D "[undefined]"; + if (remoteaddr) + { + remotestr =3D print_sockaddr(remoteaddr, &gc); + } + msg(D_DCO_DEBUG, "%s: peer-id %d, fd %d, remote addr: %s", __func__, + peerid, sd, remotestr); + + struct nl_msg *nl_msg =3D ovpn_dco_v2_nlmsg_create(dco, OVPN_CMD_NEW_P= EER); + struct nlattr *attr =3D nla_nest_start(nl_msg, OVPN_ATTR_NEW_PEER); + int ret =3D -EMSGSIZE; + + NLA_PUT_U32(nl_msg, OVPN_NEW_PEER_ATTR_PEER_ID, peerid); + NLA_PUT_U32(nl_msg, OVPN_NEW_PEER_ATTR_SOCKET, sd); + + /* Set the remote endpoint if defined (for UDP) */ + if (remoteaddr) + { + remoteaddr =3D mapped_v4_to_v6(remoteaddr, &gc); + int alen =3D af_addr_size(remoteaddr->sa_family); + + NLA_PUT(nl_msg, OVPN_NEW_PEER_ATTR_SOCKADDR_REMOTE, alen, remotead= dr); + } + + if (localaddr) + { + localaddr =3D mapped_v4_to_v6(localaddr, &gc); + if (localaddr->sa_family =3D=3D AF_INET) + { + NLA_PUT(nl_msg, OVPN_NEW_PEER_ATTR_LOCAL_IP, sizeof(struct in_= addr), + &((struct sockaddr_in *)localaddr)->sin_addr); + } + else if (localaddr->sa_family =3D=3D AF_INET6) + { + NLA_PUT(nl_msg, OVPN_NEW_PEER_ATTR_LOCAL_IP, sizeof(struct in6= _addr), + &((struct sockaddr_in6 *)localaddr)->sin6_addr); + } + } + + /* Set the primary VPN IP addresses of the peer */ + if (remote_in4) + { + NLA_PUT_U32(nl_msg, OVPN_NEW_PEER_ATTR_IPV4, remote_in4->s_addr); + } + if (remote_in6) + { + NLA_PUT(nl_msg, OVPN_NEW_PEER_ATTR_IPV6, sizeof(struct in6_addr), + remote_in6); + } + nla_nest_end(nl_msg, attr); + + ret =3D ovpn_nl_msg_send(dco, nl_msg, NULL, NULL, __func__); + +nla_put_failure: + nlmsg_free(nl_msg); + gc_free(&gc); + return ret; +} + +void +close_tun_dco_v2(struct tuntap *tt, openvpn_net_ctx_t *ctx) +{ + msg(D_DCO_DEBUG, __func__); + + net_iface_del(ctx, tt->actual_name); + ovpn_dco_uninit_netlink(&tt->dco); +} + +int +dco_v2_swap_keys(dco_context_t *dco, unsigned int peerid) +{ + msg(D_DCO_DEBUG, "%s: peer-id %d", __func__, peerid); + + struct nl_msg *nl_msg =3D ovpn_dco_v2_nlmsg_create(dco, OVPN_CMD_SWAP_= KEYS); + if (!nl_msg) + { + return -ENOMEM; + } + + struct nlattr *attr =3D nla_nest_start(nl_msg, OVPN_ATTR_SWAP_KEYS); + int ret =3D -EMSGSIZE; + 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__); + +nla_put_failure: + nlmsg_free(nl_msg); + return ret; +} + + +int +dco_v2_del_peer(dco_context_t *dco, unsigned int peerid) +{ + msg(D_DCO_DEBUG, "%s: peer-id %d", __func__, peerid); + + struct nl_msg *nl_msg =3D ovpn_dco_v2_nlmsg_create(dco, OVPN_CMD_DEL_P= EER); + if (!nl_msg) + { + return -ENOMEM; + } + + struct nlattr *attr =3D nla_nest_start(nl_msg, OVPN_ATTR_DEL_PEER); + int ret =3D -EMSGSIZE; + 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__); + +nla_put_failure: + nlmsg_free(nl_msg); + return ret; +} + + +int +dco_v2_del_key(dco_context_t *dco, unsigned int peerid, + dco_key_slot_t slot) +{ + msg(D_DCO_DEBUG, "%s: peer-id %d, slot %d", __func__, peerid, slot); + + struct nl_msg *nl_msg =3D ovpn_dco_v2_nlmsg_create(dco, OVPN_CMD_DEL_K= EY); + if (!nl_msg) + { + return -ENOMEM; + } + + struct nlattr *attr =3D nla_nest_start(nl_msg, OVPN_ATTR_DEL_KEY); + int ret =3D -EMSGSIZE; + NLA_PUT_U32(nl_msg, OVPN_DEL_KEY_ATTR_PEER_ID, peerid); + 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__); + +nla_put_failure: + nlmsg_free(nl_msg); + return ret; +} + +int +dco_v2_new_key(dco_context_t *dco, unsigned int peerid, int keyid, + dco_key_slot_t slot, + const uint8_t *encrypt_key, const uint8_t *encrypt_iv, + const uint8_t *decrypt_key, const uint8_t *decrypt_iv, + const char *ciphername) +{ + msg(D_DCO_DEBUG, "%s: slot %d, key-id %d, peer-id %d, cipher %s", + __func__, slot, keyid, peerid, ciphername); + + const size_t key_len =3D cipher_kt_key_size(ciphername); + const int nonce_tail_len =3D 8; + + struct nl_msg *nl_msg =3D ovpn_dco_v2_nlmsg_create(dco, OVPN_CMD_NEW_K= EY); + if (!nl_msg) + { + return -ENOMEM; + } + + dco_cipher_t dco_cipher =3D dco_get_cipher(ciphername); + + int ret =3D -EMSGSIZE; + struct nlattr *attr =3D nla_nest_start(nl_msg, OVPN_ATTR_NEW_KEY); + NLA_PUT_U32(nl_msg, OVPN_NEW_KEY_ATTR_PEER_ID, peerid); + NLA_PUT_U8(nl_msg, OVPN_NEW_KEY_ATTR_KEY_SLOT, slot); + NLA_PUT_U8(nl_msg, OVPN_NEW_KEY_ATTR_KEY_ID, keyid); + NLA_PUT_U16(nl_msg, OVPN_NEW_KEY_ATTR_CIPHER_ALG, dco_cipher); + + struct nlattr *key_enc =3D nla_nest_start(nl_msg, + OVPN_NEW_KEY_ATTR_ENCRYPT_KEY); + if (dco_cipher !=3D OVPN_CIPHER_ALG_NONE) + { + NLA_PUT(nl_msg, OVPN_KEY_DIR_ATTR_CIPHER_KEY, key_len, encrypt_key= ); + NLA_PUT(nl_msg, OVPN_KEY_DIR_ATTR_NONCE_TAIL, nonce_tail_len, + encrypt_iv); + } + nla_nest_end(nl_msg, key_enc); + + struct nlattr *key_dec =3D nla_nest_start(nl_msg, + OVPN_NEW_KEY_ATTR_DECRYPT_KEY); + if (dco_cipher !=3D OVPN_CIPHER_ALG_NONE) + { + NLA_PUT(nl_msg, OVPN_KEY_DIR_ATTR_CIPHER_KEY, key_len, decrypt_key= ); + NLA_PUT(nl_msg, OVPN_KEY_DIR_ATTR_NONCE_TAIL, nonce_tail_len, + decrypt_iv); + } + nla_nest_end(nl_msg, key_dec); + + nla_nest_end(nl_msg, attr); + + ret =3D ovpn_nl_msg_send(dco, nl_msg, NULL, NULL, __func__); + +nla_put_failure: + nlmsg_free(nl_msg); + return ret; +} + +int +dco_v2_set_peer(dco_context_t *dco, unsigned int peerid, + int keepalive_interval, int keepalive_timeout, int mss) +{ + msg(D_DCO_DEBUG, "%s: peer-id %d, keepalive %d/%d, mss %d", __func__, + peerid, keepalive_interval, keepalive_timeout, mss); + + struct nl_msg *nl_msg =3D ovpn_dco_v2_nlmsg_create(dco, OVPN_CMD_SET_P= EER); + if (!nl_msg) + { + return -ENOMEM; + } + + struct nlattr *attr =3D nla_nest_start(nl_msg, OVPN_ATTR_SET_PEER); + int ret =3D -EMSGSIZE; + NLA_PUT_U32(nl_msg, OVPN_SET_PEER_ATTR_PEER_ID, peerid); + NLA_PUT_U32(nl_msg, OVPN_SET_PEER_ATTR_KEEPALIVE_INTERVAL, + keepalive_interval); + NLA_PUT_U32(nl_msg, OVPN_SET_PEER_ATTR_KEEPALIVE_TIMEOUT, + keepalive_timeout); + nla_nest_end(nl_msg, attr); + + ret =3D ovpn_nl_msg_send(dco, nl_msg, NULL, NULL, __func__); + +nla_put_failure: + nlmsg_free(nl_msg); + return ret; +} + +/* This function parses any netlink message sent by ovpn-dco to userspace = */ +static int +ovpn_v2_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; +} + +static int +dco_v2_do_read(dco_context_t *dco) +{ + msg(D_DCO_DEBUG, __func__); + nl_cb_set(dco->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, ovpn_v2_handle_msg, d= co); + + return ovpn_nl_recvmsgs(dco, __func__); +} + +static void +dco_v2_update_peer_stat(struct context_2 *c2, struct nlattr *tb[], uint32_= t id) +{ + if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES]) + { + c2->dco_read_bytes =3D nla_get_u64(tb[OVPN_GET_PEER_RESP_ATTR_LINK= _RX_BYTES]); + msg(D_DCO_DEBUG, "%s / dco_read_bytes: " counter_format, __func__, + c2->dco_read_bytes); + } + else + { + msg(M_WARN, "%s: no link RX bytes provided in reply for peer %u", + __func__, id); + } + + if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES]) + { + c2->dco_write_bytes =3D nla_get_u64(tb[OVPN_GET_PEER_RESP_ATTR_LIN= K_TX_BYTES]); + msg(D_DCO_DEBUG, "%s / dco_write_bytes: " counter_format, __func__, + c2->dco_write_bytes); + } + else + { + msg(M_WARN, "%s: no link TX bytes provided in reply for peer %u", + __func__, id); + } + + if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES]) + { + c2->tun_read_bytes =3D nla_get_u64(tb[OVPN_GET_PEER_RESP_ATTR_VPN_= RX_BYTES]); + msg(D_DCO_DEBUG, "%s / tun_read_bytes: " counter_format, __func__, + c2->tun_read_bytes); + } + else + { + msg(M_WARN, "%s: no VPN RX bytes provided in reply for peer %u", + __func__, id); + } + + if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_TX_BYTES]) + { + c2->tun_write_bytes =3D nla_get_u64(tb[OVPN_GET_PEER_RESP_ATTR_VPN= _TX_BYTES]); + msg(D_DCO_DEBUG, "%s / tun_write_bytes: " counter_format, __func__, + c2->tun_write_bytes); + } + else + { + msg(M_WARN, "%s: no VPN TX bytes provided in reply for peer %u", + __func__, id); + } +} + +int +dco_v2_parse_peer_multi(struct nl_msg *msg, void *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]) + { + 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; + } + + struct multi_context *m =3D arg; + uint32_t peer_id =3D nla_get_u32(tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_= ID]); + + if (peer_id >=3D m->max_clients || !m->instances[peer_id]) + { + msg(M_WARN, "%s: cannot store DCO stats for peer %u", __func__, + peer_id); + return NL_SKIP; + } + + dco_v2_update_peer_stat(&m->instances[peer_id]->context.c2, tb_peer, p= eer_id); + + return NL_OK; +} + +int +dco_v2_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m) +{ + msg(D_DCO_DEBUG, "%s", __func__); + + struct nl_msg *nl_msg =3D ovpn_dco_v2_nlmsg_create(dco, OVPN_CMD_GET_P= EER); + + nlmsg_hdr(nl_msg)->nlmsg_flags |=3D NLM_F_DUMP; + + int ret =3D ovpn_nl_msg_send(dco, nl_msg, dco_v2_parse_peer_multi, m, = __func__); + + nlmsg_free(nl_msg); + return ret; +} + +static int +dco_v2_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_v2_update_peer_stat(&c->c2, tb_peer, peer_id); + + return NL_OK; +} + +int +dco_v2_get_peer_stats(struct context *c) +{ + uint32_t peer_id =3D c->c2.tls_multi->dco_peer_id; + msg(D_DCO_DEBUG, "%s: peer-id %d", __func__, peer_id); + + if (!c->c1.tuntap) + { + return 0; + } + + dco_context_t *dco =3D &c->c1.tuntap->dco; + struct nl_msg *nl_msg =3D ovpn_dco_v2_nlmsg_create(dco, OVPN_CMD_GET_P= EER); + struct nlattr *attr =3D nla_nest_start(nl_msg, OVPN_ATTR_GET_PEER); + int ret =3D -EMSGSIZE; + + 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_v2_parse_peer, c, __func__); + +nla_put_failure: + nlmsg_free(nl_msg); + return ret; +} + +const struct dco_ops dco_ops_v2 =3D { + .ovpn_dco_nlmsg_create =3D ovpn_dco_v2_nlmsg_create, + .dco_new_peer =3D &dco_v2_new_peer, + .open_tun_dco =3D open_tun_dco_v2, + .close_tun_dco =3D close_tun_dco_v2, + .dco_swap_keys =3D &dco_v2_swap_keys, + .dco_del_peer =3D &dco_v2_del_peer, + .dco_del_key =3D &dco_v2_del_key, + .dco_new_key =3D &dco_v2_new_key, + .dco_set_peer =3D &dco_v2_set_peer, + .ovpn_handle_msg =3D &ovpn_v2_handle_msg, + .dco_do_read =3D &dco_v2_do_read, + .dco_update_peer_stat =3D &dco_v2_update_peer_stat, + .dco_parse_peer_multi =3D &dco_v2_parse_peer_multi, + .dco_get_peer_stats_multi =3D &dco_v2_get_peer_stats_multi, + .dco_parse_peer =3D &dco_v2_parse_peer, + .dco_get_peer_stats =3D &dco_v2_get_peer_stats +}; + +#endif /* defined(ENABLE_DCO) && defined(TARGET_LINUX) */ diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c index e3ada76..65be766 100644 --- a/src/openvpn/dco_win.c +++ b/src/openvpn/dco_win.c @@ -357,7 +357,7 @@ } bool -dco_available(int msglevel) +dco_available(int msglevel, dco_context_t *dco) { /* try to open device by symbolic name */ HANDLE h =3D CreateFile("\\\\.\\ovpn-dco", GENERIC_READ | GENERIC_WRIT= E, diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index 01165b2..118c32a 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -1230,6 +1230,9 @@ process_incoming_dco(struct context *c) { #if defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARGET_FREEBS= D)) + int cmd_del_peer =3D OVPN_CMD_DEL_PEER; + int cmd_swap_keys =3D OVPN_CMD_SWAP_KEYS; + dco_context_t *dco =3D &c->c1.tuntap->dco; dco_do_read(dco); @@ -1245,31 +1248,30 @@ return; } - switch (dco->dco_message_type) + if (dco->dco_message_type =3D=3D cmd_del_peer) { - case OVPN_CMD_DEL_PEER: - 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 " - "%d", __func__, dco->dco_message_peer_id); - trigger_ping_timeout_signal(c); - return; - } - break; - - case OVPN_CMD_SWAP_KEYS: - msg(D_DCO_DEBUG, "%s: received key rotation notification for p= eer-id %d", - __func__, dco->dco_message_peer_id); - tls_session_soft_reset(c->c2.tls_multi); - break; - - default: - msg(D_DCO_DEBUG, "%s: received message of type %u - ignoring",= __func__, - dco->dco_message_type); + if (dco->dco_del_peer_reason =3D=3D OVPN_DEL_PEER_REASON_EXPIRED) + { + msg(D_DCO_DEBUG, "%s: received peer expired notification of fo= r peer-id " + "%d", __func__, dco->dco_message_peer_id); + trigger_ping_timeout_signal(c); return; + } + } + else if (dco->dco_message_type =3D=3D cmd_swap_keys) + { + msg(D_DCO_DEBUG, "%s: received key rotation notification for peer-= id %d", + __func__, dco->dco_message_peer_id); + tls_session_soft_reset(c->c2.tls_multi); + } + else + { + msg(D_DCO_DEBUG, "%s: received message of type %u - ignoring", __f= unc__, + dco->dco_message_type); + return; } -#endif /* if defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARG= ET_FREEBSD)) */ +#endif /* #if defined(ENABLE_DCO) && defined(TARGET_FREEBSD) */ } /* -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/662?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I6662605b60d4859949970cfe256c55cbcbd4a672 Gerrit-Change-Number: 662 Gerrit-PatchSet: 1 Gerrit-Owner: its_Giaan Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --3K8KSMjus+E= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

its_Giaan would like plaisthos and flichtenheld to review this change.

Vi= ew Change

Lay the foundation to support both old and new versions of DC=
O

Added a new abstraction layer based on the `struct dco_ops`,
a = structure of function pointers that ensures the appropriate
APIs at runt= ime are used for DCO communication between kernel
and user space, select= ion is based on the available module's
family name.

The old v= ersion, referred to as "ovpn_dco_v2", and its related
commands= and functions, will be distinguished with the "v2" suffix.
Change-Id: I6662605b60d4859949970cfe256c55cbcbd4a672
Signed-off-by: Gi= anmarco De Gregori <gianmarco@...2726...>
---
M CMakeLists.txt<= br>M src/openvpn/Makefile.am
M src/openvpn/dco.c
M src/openvpn/dco.h<= br>M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvp= n/dco_linux.h
A src/openvpn/dco_linux_v2.c
M src/openvpn/dco_win.cM src/openvpn/forward.c
10 files changed, 923 insertions(+), 655 deleti= ons(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/chang=
es/62/662/1
diff --git a/CMakeLists.txt b/CMakeLists.txt
= index 096837d..732be9e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -398,6 +398,7 @@
src/openvpn/dco_win.h
src/openvpn/dco= _linux.c
src/openvpn/dco_linux.h
+ src/openvpn/dco_linux_v2.c
= src/openvpn/dco_freebsd.c
src/openvpn/dco_f= reebsd.h
src/openvpn/dhcp.c
diff --git= a/src/openvpn/Makefile.am b/src/openvpn/Makefile.am
index = 56cce9d..286d3c5 100644
--- a/src/openvpn/Makefile.am
+++ b/src/openvpn/Makefile.am
@@ -54,6 +54,7 @@<= /span>
dco.c dco.h dco_internal.h \
dco_freebs= d.c dco_freebsd.h \
dco_linux.c dco_linux.h \
<= span style=3D"color: hsl(120, 100%, 40%);">+ dco_linux_v2.c \

dco_win.c dco_win.h \

dhcp.c dhcp.h \
dns.c dns.h \

diff --git a/src/openvpn/dco.c b/src/open= vpn/dco.c
index 78243b1..80184f8 100644
---= a/src/openvpn/dco.c
+++ b/src/openvpn/dco.c
@@ -396,7 +396,7 @@

/* now that all options have bee= n confirmed to be supported, check
* if DCO is truly = available on the system
*/
- return dco_available(msglevel);
+ return dco_available(msgleve= l, NULL);
}

bool=
diff --git a/src/openvpn/dco.h b/src/openvpn/dco.h
index 50ebb35..fc34da8 100644
--- a/src/openvpn/dco.h
+++ b/src/openvpn/dco.h
@@ -56,7 +56,7 @@

* @param msglevel level to print messages to
<= span> * @return true if ovpn-dco is available, false otherwis= e
*/
= -bool dco_available(int msglevel);
+bool dco_available(int msglevel, dco_context_t *dco);=


/**
@@ -254,= 7 +254,7 @@
typedef void *dco_context_t;
=
static inline bool
-dco_available(int msglevel)
+dco_available(int msglevel, dco_context_t *dco)
{
return false;
}=
diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.= c
index 7c8b29c..93c0813 100644
--- a/src/o= penvpn/dco_freebsd.c
+++ b/src/openvpn/dco_freebsd.c=
@@ -569,7 +569,7 @@
}
bool
-dco_avai= lable(int msglevel)
+= dco_available(int msglevel, dco_context_t *dco)
{ struct if_clonereq ifcr;
char *buf =3D NU= LL;
diff --git a/src/openvpn/dco_linux.c b/src/openvpn/dco_= linux.c
index b2584b9..4feae6d 100644
--- a= /src/openvpn/dco_linux.c
+++ b/src/openvpn/dco_linux.c
@@ -51,32 +51,28 @@
#include <netlink/genl/= ctrl.h>


-/* libnl < 3.5.0 does not set the NLA_F_NESTED = on its own, therefore we
- * parsing of the message<= /span>
- */
-#define nla_nest_start(_msg, _type) \

- nla_nest_start(_msg,= (_type) | NLA_F_NESTED)
-static int ovpn_ge= t_mcast_id(dco_context_t *dco);
-
-void dco_ch= eck_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
- *
- * whether the ovpn-dco netlink names= pace is available
- *
- * This function can be= used to determine if the kernel
- * supports DCO offloading.
- *
- *= @return ID on success, negative error code on error
- */
static int
<= span style=3D"color: hsl(0, 100%, 40%);">-resolve_ovpn_netlink_id(int msgle= vel)

+do_family_name_= resolve(struct nl_sock *nl_sock, int msglevel, const char *family_name,
+ = dco_context_t *dco, const struct dco_ops *ops)
+{
+ int ret =3D genl_ctrl_resolve(nl_sock, family_name);+
+ if (ret < 0)
+ {
+ msg(msglevel, "Cannot find %s netlink component: = %s", family_name, nl_geterror(ret));
+ }
+
+ if (dco= )
+ {
+ /* Ensures that we will = use the proper ops for the dco version available */

+ dco->ops =3D ops;
+ }
+
+ return ret;
+}
+
<= span style=3D"color: hsl(120, 100%, 40%);">+int
+resolve_ovpn_netlink_id(int msglevel, dco_conte= xt_t *dco)
{
int ret;
struct nl_sock *nl_sock =3D nl_socket_alloc();
@@ -96= ,39 +92,14 @@
}
set_cloexec(nl_so= cket_get_fd(nl_sock));

- ret =3D genl_ctrl_resolve(nl_sock, OVPN_NL_NAME);

- if (ret < 0)
- {
- msg(msglevel, "Cannot find ov= pn_dco netlink component: %s",
- nl_geterror(ret));
- }
+ ret =3D do_family_name_resolve(nl_sock, msglevel, OVPN_NL_NAME= , dco, &dco_ops_v2);

err_sock:
nl_socket_free(nl_sock);
return ret;
}

-static struct nl_msg *
-ovpn_dco_nlmsg_create(dco_context_t *dco, enum ovpn_nl_comma= nds cmd)
-{
<= span style=3D"color: hsl(0, 100%, 40%);">- struct nl_msg *nl_msg =3D nlm= sg_alloc();

- if (!n= l_msg)
- {- msg(M_ERR, "cannot= allocate netlink message");
- return NULL;
- }
-
- genlmsg_put(nl_msg, 0,= 0, dco->ovpn_dco_id, 0, 0, cmd, 0);
- NLA_PUT_U32(nl_msg, OVPN_ATTR_IFINDEX, dco->ifinde= x);
-
- return nl_msg;
-nla_put_failure:
- nlmsg_free(nl_msg);
- msg(M_INFO, "cannot put into netli= nk message");
- = return NULL;
-}=
-
-static int
+int
ovpn_nl_recvmsgs(dco_context_t *dco, = const char *prefix)
{
int ret =3D nl_= recvmsgs(dco->nl_sock, dco->nl_cb);
@@ -166,18 +137,7= @@
return ret;
}

-/**
- * Send a prepared netlink message and re= gisters cb as callback if non-null.
- *
- * Th= e method will also free nl_msg
- * @param dco The dco context to use
- * @param nl_msg the message to use
- * @param cb An opt= ional callback if the caller expects an answer
- * @param cb_arg An optional param to pass to t= he callback
- * @param = prefix A prefix to report in the error message to give the user context<= /span>
- * @return st= atus of sending the message
- */
-static int
+int
= ovpn_nl_msg_send(dco_context_t *dco, struct nl_msg *nl_msg, ovpn_nl_cb cb,<= /span>
void *cb_arg, const char *prefix)<= br> {
@@ -218,71 +178,6 @@
}<= br>
int
-dco_new_peer(dco_context_t *dco, unsigned int peerid, int sd,
- struct socka= ddr *localaddr, struct sockaddr *remoteaddr,
- struct in_addr *remote_in4, struct in6_= addr *remote_in6)
-{
- struct gc_arena gc = =3D gc_new();
- cons= t char *remotestr =3D "[undefined]";
- if (remoteaddr)
- {
- remotestr =3D print_sockaddr(remoteaddr, &gc);- }
- msg(D_DCO_DEBUG, "%s: peer-id %d, fd %= d, remote addr: %s", __func__,
- peerid, sd, remotestr);
-
- struct nlattr= *attr =3D nla_nest_start(nl_msg, OVPN_ATTR_NEW_PEER);
- int ret =3D -EMSGSIZE;
-

- NLA_PUT_U32(nl_msg, OVPN_NEW_PEER_ATTR_PEER_ID, peerid= );
- NLA_PUT_U32(nl_= msg, OVPN_NEW_PEER_ATTR_SOCKET, sd);
-
- /*= Set the remote endpoint if defined (for UDP) */
- if (remoteaddr)
- {
- remoteaddr =3D mapped_v4_to_v6(remoteaddr, &gc);
- int alen =3D af_add= r_size(remoteaddr->sa_family);
-
- N= LA_PUT(nl_msg, OVPN_NEW_PEER_ATTR_SOCKADDR_REMOTE, alen, remoteaddr);
- }
-
- if (localaddr)
- {
- = localaddr =3D mapped_v4_to_v6(localaddr, &gc);
- if (localaddr->sa_family =3D=3D AF_= INET)
- {=
- NLA_PUT(nl_msg, = OVPN_NEW_PEER_ATTR_LOCAL_IP, sizeof(struct in_addr),
- &((struct sockaddr_= in *)localaddr)->sin_addr);
- }
- = else if (localaddr->sa_family =3D=3D AF_INET6)
- {
- NLA_PUT(nl_msg, OVPN_NEW_PEER_ATTR_LOCAL_I= P, sizeof(struct in6_addr),
- &((struct sockaddr_in6 *)localaddr)->sin6_= addr);
- }
- }
-
- /* Set the primary VPN IP addresses of the peer */- if (remote_in4)
<= span style=3D"color: hsl(0, 100%, 40%);">- {

- NLA_PUT_U32(nl_msg, OVPN_NEW_PEER_ATTR_IP= V4, remote_in4->s_addr);
- }
- if (re= mote_in6)
- {=
- NLA_PUT(nl_msg, OVPN= _NEW_PEER_ATTR_IPV6, sizeof(struct in6_addr),
- remote_in6);
- }
- nla_nest_end(nl_msg, attr);
-
- ret =3D ovpn_nl_msg_send(dco, nl_msg, NULL, NULL, __func__);
-
-nla_put_failure:
- nlmsg_free(nl_msg);
- gc_free(&gc);
- return ret;
-}
-
-static int
ovpn_nl_cb_finish(struct nl_msg (*msg) __attribute__ ((unused)), void = *arg)

{
int *status =3D arg;@@ -291,15 +186,7 @@
return NL_SKIP; }

-/* This function is used as error callback on the netlink socket.
- * When something goes wr= ong and the kernel returns an error, this function is
- * invoked.
- *
- * (supplied by t= he user when setting this callback) and we parse the kernel
- * reply to see if it contains a huma= n-readable error. If found, it is printed.

- */
+int
ovpn_nl_cb_error(struct sockaddr_nl (*nla) __attribute__ ((u= nused)),
struct nlmsgerr *err, void *arg)=
{
@@ -342,10 +229,16 @@
= return NL_STOP;
}

-static void
+void
ovpn_dco_init_netlink(dco_= context_t *dco)
{
- dco->ovpn_dco_id =3D resolve_ovpn_netlink_id(M_ERR);
+ struct gc_arena gc= =3D gc_new();
+ i= f (!dco->ops)
+ = {
+ ALLOC_OBJ= _CLEAR_GC(dco->ops, struct dco_ops, &gc);
+ }
+
+ = dco->ovpn_dco_id =3D resolve_ovpn_netlink_id(M_ERR, dco);

dco->nl_sock =3D nl_socket_alloc();
<= span>

@@ -388,6 +281,7 @@
* overrun = with very fast connecting/disconnecting clients.
* TO= DO: fix this in a better and more reliable way */
ASSE= RT(!nl_socket_set_buffer_size(dco->nl_sock, 1024*1024, 1024*1024));
+ gc_free(&gc);
}

bool
@@= -411,7 +305,7 @@
return true;
}

-static v= oid
+void
<= span> ovpn_dco_uninit_netlink(dco_context_t *dco)

{=
nl_socket_free(dco->nl_sock);
@@ -423,7 += 317,7 @@
CLEAR(dco);
}

-static void=
+void
ovpn= _dco_register(dco_context_t *dco)
{
m= sg(D_DCO_DEBUG, __func__);
@@ -447,205 +341,11 @@ int
open_tun_dco(struct tuntap *tt, openvpn_net_ct= x_t *ctx, const char *dev)
{
- msg(D_DCO_DEBUG, "%s: %s", __func__, = dev);
- ASSERT(tt-&g= t;type =3D=3D DEV_TYPE_TUN);
-
- int ret = =3D net_iface_new(ctx, dev, "ovpn-dco", &tt->dco);<= br>- if (ret < 0)- {
- msg(D_DCO_DEBUG, "Cannot create DC= O interface %s: %d", dev, ret);
- return ret;
- }
-
- tt->dco.ifindex = =3D if_nametoindex(dev);
- {
- = msg(M_FATAL, "DCO: cannot retrieve ifindex for interface %s", d= ev);
- }
<= span style=3D"color: hsl(0, 100%, 40%);">-

- tt->dco.dco_message_peer_id =3D -1;
<= span style=3D"color: hsl(0, 100%, 40%);">-

- ovpn_dco_register(&tt->dco);
-

- return 0;
-}
--void
-close_tun_dco(struct tuntap *tt, openvpn_net_ctx= _t *ctx)
-{
<= span style=3D"color: hsl(0, 100%, 40%);">- msg(D_DCO_DEBUG, __func__);
-
- net_iface_del(ctx, tt->actual_name);=
- ovpn_dco_uninit_n= etlink(&tt->dco);
-
-int
-dco_swap_keys(dco_context_t *dco, unsigned int peerid)
-{
- msg(D_DCO_DEBUG, "%s: peer-id %d&q= uot;, __func__, peerid);
- struct nl_msg = *nl_msg =3D ovpn_dco_nlmsg_create(dco, OVPN_CMD_SWAP_KEYS);
- if (!nl_msg)

- {
- return -ENOMEM;
- }
- struct nlattr = *attr =3D nla_nest_start(nl_msg, OVPN_ATTR_SWAP_KEYS);
- int ret =3D -EMSGSIZE;
- NLA_PUT_U32(nl_msg, OVPN_SWAP_KEY= S_ATTR_PEER_ID, peerid);

-
- ret = =3D ovpn_nl_msg_send(dco, nl_msg, NULL, NULL, __func__);
-
-nla_put_failure:
- nlmsg_free(nl_msg);
- return ret;
-}
-
-

-int
-= dco_del_peer(dco_context_t *dco, unsigned int peerid)
-{
- msg(D_DCO_DEBUG, "%s: peer-id %d", __func__, peer= id);
-
- struct nl_msg *nl_msg =3D ovpn_dco= _nlmsg_create(dco, OVPN_CMD_DEL_PEER);
- if (!nl_msg)
- {
- = return -ENOMEM;
- = }
-
- struct nlattr *attr =3D nla_nest_st= art(nl_msg, OVPN_ATTR_DEL_PEER);
- int ret =3D -EMSGSIZE;
- NLA_PUT_U32(nl_msg, OVPN_DEL_PEER_ATTR_PEER_ID, peerid)= ;
- nla_nest_end(nl_= msg, attr);
-- ret =3D ovpn_nl_msg_send(dc= o, nl_msg, NULL, NULL, __func__);
-
-nla_put_f= ailure:
- nlmsg_free= (nl_msg);
- return r= et;
-}
-
-
-int
-dco_del_key(dco_context= _t *dco, unsigned int peerid,
- dco_key_slot_t slot)
-{
- = msg(D_DCO_DEBUG, "%s: peer-id %d, slot %d", __func__, peerid, = slot);
-
- struct nl_msg *nl_msg =3D ovpn_d= co_nlmsg_create(dco, OVPN_CMD_DEL_KEY);

- if (!nl_msg)
- {
- = return -ENOMEM;
- = }
-
- struct nlattr *attr =3D nla_nest_s= tart(nl_msg, OVPN_ATTR_DEL_KEY);
- int ret =3D -EMSGSIZE;
- NLA_PUT_U32(nl_msg, OVPN_DEL_KEY_ATTR_PEER_ID, peerid);=
- 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__);=
-
-nla_put_failure:
- nlmsg_free(nl_msg);
+ int ret =3D tt->dco.ops->open_tun_dco(tt= , ctx, dev);
return ret;
}
=
int
-dco_new_key(dco_context_t *dco, unsigned int peerid, int keyid,
- dco_key_slot_t= slot,
- con= st uint8_t *encrypt_key, const uint8_t *encrypt_iv,
- const uint8_t *decrypt_key, con= st uint8_t *decrypt_iv,
- const char *ciphername)
-{
- = msg(D_DCO_DEBUG, "%s: slot %d, key-id %d, peer-id %d, cipher %s",=
- __func__, slo= t, keyid, peerid, ciphername);
-
- const si= ze_t key_len =3D cipher_kt_key_size(ciphername);
- const int nonce_tail_len =3D 8;
-

- struct nl_msg *nl_msg =3D ovpn_dco_nlmsg_create(dco= , OVPN_CMD_NEW_KEY);
- = if (!nl_msg)
- {<= /span>
- return -ENOMEM= ;
- }
-

- dco_cipher_t dco_cipher =3D dco_get_cipher(ciphername= );
-
- int ret =3D -EMSGSIZE;
- struct nlattr *attr =3D nla_nes= t_start(nl_msg, OVPN_ATTR_NEW_KEY);

- NLA_PUT_U32(nl_msg, OVPN_NEW_KEY_ATTR_PEER_ID, peerid);
- NLA_PUT_U8(nl_msg, = OVPN_NEW_KEY_ATTR_KEY_SLOT, slot);
- NLA_PUT_U8(nl_msg, OVPN_NEW_KEY_ATTR_KEY_ID, keyid);
- NLA_PUT_U16(nl_msg, OVP= N_NEW_KEY_ATTR_CIPHER_ALG, dco_cipher);
-
- = struct nlattr *key_enc =3D nla_nest_start(nl_msg,
- OV= PN_NEW_KEY_ATTR_ENCRYPT_KEY);
- if (dco_cipher !=3D OVPN_CIPHER_ALG_NONE)
- {
- NLA_PUT(nl_msg, OVPN_KEY_DIR_ATTR_CIPHER_KEY, key_l= en, encrypt_key);
- = NLA_PUT(nl_msg, OVPN_KEY_DIR_ATTR_NONCE_TAIL, nonce_tail_len,- encrypt_iv);
- }
- nla_nest_end(nl_msg, key_enc);
-
- struct nlattr *key_dec =3D nla_nest_start(nl= _msg,
- = OVPN_NEW_KEY_ATTR_DECRYPT_KEY);
- if (dco_cipher !=3D OVPN_CIPHER_A= LG_NONE)

- {<= br>- NLA_PUT(nl_msg, OVPN_= KEY_DIR_ATTR_CIPHER_KEY, key_len, decrypt_key);
- NLA_PUT(nl_msg, OVPN_KEY_DIR_ATTR_NONCE_T= AIL, nonce_tail_len,
- = decrypt_iv);
- }
- nla_ne= st_end(nl_msg, key_dec);
- nla_nest_end(n= l_msg, attr);
-<= br>- ret =3D ovpn_nl_msg_send(= dco, nl_msg, NULL, NULL, __func__);
-
-nla_put= _failure:
- nlmsg_fr= ee(nl_msg);
- return= ret;
-}
-

-int
-= dco_set_peer(dco_context_t *dco, unsigned int peerid,
- int keepalive_interval, int ke= epalive_timeout, int mss)
-{
- msg(D_DCO_DE= BUG, "%s: peer-id %d, keepalive %d/%d, mss %d", __func__,<= br>- peerid, keepalive_int= erval, keepalive_timeout, mss);
-
- struct = nl_msg *nl_msg =3D ovpn_dco_nlmsg_create(dco, OVPN_CMD_SET_PEER);- if (!nl_msg)
- {

- return -ENOMEM;
- }
-
- struct n= lattr *attr =3D nla_nest_start(nl_msg, OVPN_ATTR_SET_PEER);
- int ret =3D -EMSGSIZE;

= - NLA_PUT_U32(nl_msg, OVPN_SET= _PEER_ATTR_PEER_ID, peerid);
- NLA_PUT_U32(nl_msg, OVPN_SET_PEER_ATTR_KEEPALIVE_INTERVAL,
- keepalive_i= nterval);
- NLA_PUT_= U32(nl_msg, OVPN_SET_PEER_ATTR_KEEPALIVE_TIMEOUT,
- keepalive_timeout);
<= span style=3D"color: hsl(0, 100%, 40%);">- nla_nest_end(nl_msg, attr);
-
- ret =3D ovpn_nl_msg_send(dco, nl_msg, N= ULL, NULL, __func__);
-=
-nla_put_failure:
- nlmsg_free(nl_msg);
- return ret;-}
-
-/* This function parses the reply provided by the kernel to the CTRL_CM= D_GETFAMILY
- * message= . We parse the reply and we retrieve the multicast group ID associated
- * with the "ovpn-dco= " netlink family.
= - *
- * The ID is later= used to subscribe to the multicast group and be notified
- * about any multicast message sent by = the ovpn-dco kernel module.
- */
-static int
mcast_family_handler(struct nl_msg *msg, void *arg)<= br> {
dco_context_t *dco =3D arg;
@@ -687,12 +387,8 @@


return NL_SKI= P;
}
-= /**
- * Lookup the mult= icast id for OpenVPN. This method and its help method currently
<= span style=3D"color: hsl(0, 100%, 40%);">- * hardcode the lookup to OVPN_NL= _NAME and OVPN_NL_MULTICAST_GROUP_PEERS but

- * extended in the future if we need to lookup more t= han one mcast id.
- */<= /span>
-static int
<= span style=3D"color: hsl(120, 100%, 40%);">+

+int
ovpn_get_mcast_id(dco_context= _t *dco)
{
dco->ovpn_dco_mcast_id = =3D -ENOENT;
@@ -719,299 +415,15 @@
re= turn ret;
}

-/* This function parses any netlink message sent b= y ovpn-dco to userspace */
-static int
-ovpn_h= andle_msg(struct nl_msg *msg, void *arg)
-{
- = dco_context_t *dco =3D arg;
-
- struct g= enlmsghdr *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 d= ata from ovpn-dco");
- return NL_SKIP;
- }
-- /* we must know which inter= face this message is referring to in order to
- * avoid mixing messages for other instances
- */
- if (!attrs[OVPN_ATTR_IFINDEX])
- {
- msg(D_DCO, "ovpn-dco: Receiv= ed message without ifindex");
- return NL_SKIP;
- }
-<= /span>
- 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<= /span>
- * 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 attribut= es in OVPN_DEL_PEER message");
- return NL_SKIP;
- }
-
- = struct nlattr *dp_attrs[OVPN_DEL_PEER_ATTR_MAX + 1];
- if (nla_parse_nested(dp_a= ttrs, OVPN_DEL_PEER_ATTR_MAX,

- attrs[OVPN_ATTR_DEL_PEER], NULL))<= /span>
- {- msg(D_DCO, &qu= ot;received bogus del peer packet data from ovpn-dco");
- return NL_SKIP;
- }
-

- if (!dp_attrs[OVPN_DEL_PEER_ATTR_REASON])
- {- msg(D_DCO, &quo= t;ovpn-dco: no reason in DEL_PEER message");
- return NL_SKIP;
- }

- if (!dp_attrs[OVPN_DEL_PEER_ATT= R_PEER_ID])
- = {
- ms= g(D_DCO, "ovpn-dco: no peer-id in DEL_PEER message");
<= span style=3D"color: hsl(0, 100%, 40%);">- return NL_SKIP;
- }- int reason =3D nla_= get_u8(dp_attrs[OVPN_DEL_PEER_ATTR_REASON]);
- unsigned int peerid =3D nla_get_u32(dp_a= ttrs[OVPN_DEL_PEER_ATTR_PEER_ID]);
-
- = msg(D_DCO_DEBUG, "ovpn-dco: received CMD_DEL_PEER, ifindex: %d, pe= er-id %d, reason: %d",
- ifindex, peerid, reason);
- dco->dco_message_peer_id =3D peeri= d;
- dco->= ;dco_del_peer_reason =3D reason;
- dco->dco_message_type =3D OVPN_CMD_DEL_PEER;
-
- break;
- }
-
- = default:
- m= sg(D_DCO, "ovpn-dco: received unknown command: %d", gnlh->cmd)= ;
- dco->= dco_message_type =3D 0;
- return NL_SKIP;
- }
-<= br>- return NL_OK;
<= span style=3D"color: hsl(0, 100%, 40%);">-}

-
= -int
-dco_do_read(dco_c= ontext_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__);
-}

-
-= static void
-dco_update= _peer_stat(struct context_2 *c2, struct nlattr *tb[], uint32_t id)-{
- if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES])=
- {
- c2->dco_read_bytes =3D nla= _get_u64(tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES]);

- msg(D_DCO_DEBUG, "%s / dco_rea= d_bytes: " counter_format, __func__,
- c2->dco_read_bytes);
- }
- else
- {
- msg= (M_WARN, "%s: no link RX bytes provided in reply for peer %u",
- __func__, id= );
- }
-

- if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES])
- {
- c2->dco_write_bytes =3D nla_get_= u64(tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES]);
- msg(D_DCO_DEBUG, "%s / dco_write_byt= es: " counter_format, __func__,
- c2->dco_write_bytes);
- }
- else
- msg(M= _WARN, "%s: no link TX bytes provided in reply for peer %u",
- __func__, id);=
- }
-

- if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES])- {
- c2->tun_read_bytes =3D nla_get_u64(= tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES]);
- msg(D_DCO_DEBUG, "%s / tun_read_bytes: &q= uot; counter_format, __func__,
- c2->tun_read_bytes);
- }
- else
- {<= /span>
- msg(M_WARN, &q= uot;%s: no VPN RX bytes provided in reply for peer %u",
- __func__, id);
- }
-
- if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_TX_BYTES])
- {
- c2->tun_write_bytes =3D nla_get_u64(tb[OVPN_G= ET_PEER_RESP_ATTR_VPN_TX_BYTES]);
- msg(D_DCO_DEBUG, "%s / tun_write_bytes: " cou= nter_format, __func__,
= - c2->tun_write_bytes);
- }
-= else
- {<= br>- msg(M_WARN, "%s:= no VPN TX bytes provided in reply for peer %u",
- __func__, id);
- }
-}
= -
-int
-dco_parse_peer_multi(struct nl_msg *ms= g, void *arg)
-{=
- struct nlattr *tb[OVPN_A= TTR_MAX + 1];
- stru= ct genlmsghdr *gnlh =3D nlmsg_data(nlmsg_hdr(msg));
-
- msg(D_DCO_DEBUG, "%s: parsing message...", __func_= _);
-
- nla_parse(tb, OVPN_ATTR_MAX, genlms= g_attrdata(gnlh, 0),
- = genlmsg_attrlen(gnlh, 0), NULL);
-
- {
- = return NL_SKIP;
-= }
-
- struct nlattr *tb_peer[OVPN_GET_P= EER_RESP_ATTR_MAX + 1];

-
- nla_parse(tb_pe= er, 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_P= EER_RESP_ATTR_PEER_ID])
- {
- msg(M_= WARN, "%s: no peer-id provided in reply", __func__);
- 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]);
-
- if (peer_id &= gt;=3D m->max_clients || !m->instances[peer_id])
- {
- msg(M_WARN, "%s: cannot store DCO stats for p= eer %u", __func__,
- peer_id);
- return NL_SKIP;
- }
-
<= span style=3D"color: hsl(0, 100%, 40%);">- dco_update_peer_stat(&m-&= gt;instances[peer_id]->context.c2, tb_peer, peer_id);

-
- return NL_OK;
-}
--int
-dco_get_peer_stats_multi(dco_context_t *dco, stru= ct multi_context *m)
-{=
- msg(D_DCO_DEBUG, = "%s", __func__);
-
- struct nl_ms= g *nl_msg =3D ovpn_dco_nlmsg_create(dco, OVPN_CMD_GET_PEER);
-

- nlmsg_hdr(nl_msg)->nlmsg_flags |=3D NLM_F_DUMP;
-
- int ret =3D ovpn_nl_msg_send(dco, nl_ms= g, dco_parse_peer_multi, m, __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),<= /span>
- genlmsg_= attrlen(gnlh, 0), NULL);
- if (!tb[OVPN_A= TTR_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_GE= T_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;
- }<= /span>
-
- uint32_t peer_id =3D nla_get_u32(tb_pee= r[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)
= -{
- uint32_t peer_id =3D c->c2.tls_multi->dco_= peer_id;
- msg(D_DCO= _DEBUG, "%s: peer-id %d", __func__, peer_id);
-
- if (!c->c1.tuntap)
- {
= - return 0;
- = }
-
- dco_context_t *dco =3D &c->c1= .tuntap->dco;
- s= truct 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);
- int ret =3D -EMSGSIZE;
-
- 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, n= l_msg, dco_parse_peer, c, __func__);

-
-nla_pu= t_failure:
- nlmsg_f= ree(nl_msg);
- retur= n ret;
-}
-

bool
-dco_available(int msglevel)
=
+dco_available(int msglevel= , dco_context_t *dco)
{
- if (resolve_ovpn_netlink_id(D_DCO_DEBUG) < 0)
+ if (resolve_ovpn_ne= tlink_id(D_DCO_DEBUG, dco) < 0)
{
= msg(msglevel,
"Note: Kernel suppo= rt for ovpn-dco missing, disabling data channel offload.");
= return false;
}
-
return true; }

@@ -1043,6 +455,94 @@ return BSTR(&out);
}

+int
+dco_new_peer(dco_context_t *dco, unsig= ned int peerid, int sd,
+ struct sockaddr *localaddr, struct sockaddr *remoteaddr,
+ struct i= n_addr *remote_in4, struct in6_addr *remote_in6)
+{
+ int ret =3D dco->ops->dco_new_peer(dco, peerid, sd, lo= caladdr, remoteaddr, remote_in4, remote_in6);
+ return ret;
+}
+
+void
= +close_tun_dco(struct tuntap *t= t, openvpn_net_ctx_t *ctx)
+{
+ tt->= dco.ops->close_tun_dco(tt, ctx);
+}
+
+int
+dco_swap_keys(dco_context_t *dco, uns= igned int peerid)
+{<= /span>
+ int ret =3D dco-= >ops->dco_swap_keys(dco, peerid);
+ return ret;
+}
+
+
+int
+dco_del_peer(dco_context_t *dco, unsigned int peerid)
+{
+ int ret =3D dco->ops->dco_del_= peer(dco, peerid);
+ = return ret;
+}
+
+
+int
+d= co_del_key(dco_context_t *dco, unsigned int peerid,
+ dco_key_slot_t slot)+{
+ int ret =3D dco->ops->dco_del_key(dc= o, peerid, slot);
+ = return ret;
+}
+
+int
+dco_new_key(dco_context_t *dco, unsigned int peerid, int = keyid,
+ d= co_key_slot_t slot,
+= const uint8_t *encrypt_key, const uint8_t *encrypt_iv,+ const uint8_t *d= ecrypt_key, const uint8_t *decrypt_iv,
+ const char *ciphername)
+{
+ int ret =3D dco->ops->dco_new_key(dco, peerid, k= eyid, slot, encrypt_key, encrypt_iv, decrypt_key, decrypt_iv, ciphername);<= /span>
+ return ret;
+}
+
+int
+d= co_set_peer(dco_context_t *dco, unsigned int peerid,
+ int keepalive_interval, int = keepalive_timeout, int mss)
+{
+ int re= t =3D dco->ops->dco_set_peer(dco, peerid, keepalive_interval, keepali= ve_timeout, mss);
+ = return ret;
+}
+
+int
+dco_do_read(dco_context_t *dco)
+{
+ int ret =3D dco->ops->dco_do_read(dco);
+ return ret;

+}
+
= +int
+dco_parse_peer_= multi(struct nl_msg *msg, void *arg)
+{
+ = struct multi_context *m =3D arg;
+ int ret =3D m->top.c1.tuntap->dco.ops->dco_par= se_peer_multi(msg, arg);
+
+ return ret= ;
+}
+
+int
+dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m)
+{
+ int ret =3D dco->ops->dco_get= _peer_stats_multi(dco, m);
+ return ret;
+
+int

+dco_get_peer_stats(struct context *c)
+{

+ int ret =3D c->c1.tuntap->dco.ops->dc= o_get_peer_stats(c);
= + return ret;
+}
+
voi= d
dco_event_set(dco_context_t *dco, struct event_set *es, = void *arg)
{
diff --git a/src/openvpn/dco_= linux.h b/src/openvpn/dco_linux.h
index 511519a..a3cf528 10= 0644
--- a/src/openvpn/dco_linux.h
+++ b/sr= c/openvpn/dco_linux.h
@@ -31,9 +31,30 @@
#= include <netlink/socket.h>
#include <netlink/netl= ink.h>

+#include <netlink/genl/genl.h>
+#include <netlink/genl/family.h>
<= span style=3D"color: hsl(120, 100%, 40%);">+#include <netlink/genl/ctrl.= h>

+
+#include "networking.h"=

+#include "fdmi= sc.h"
++/* forward declarations (inc= luding other headers leads to nasty include
+ * order problems)
+ */
+struct multi_context;
+struct context_2;
+struct key_ctx_bi;
+
typedef enum ovpn_key_slot dco_key_slot_t; typedef enum ovpn_cipher_alg dco_cipher_t;

+/* libnl < 3.5.0 does = not set the NLA_F_NESTED on its own, therefore we
+ * have to explicitly do it to prevent the ke= rnel from failing upon
+ */
+#define= nla_nest_start(_msg, _type) \
+ nla_nest_start(_msg, (_type) | NLA_F_NESTED)
+


= typedef struct
{
@@ -53,7 +74,114 @@
int dco_del_peer_reason;
uint64_t dco= _read_bytes;
uint64_t dco_write_bytes;
+

+ const struct dco_ops *ops;
} dco_= context_t;

+struct dco_ops
+{
+ struct nl_= msg *(*ovpn_dco_nlmsg_create)(dco_context_t *dco, int cmd);
+ int (*dco_new_peer)(dco_context= _t *dco, unsigned int peerid, int sd, struct sockaddr *localaddr, struct so= ckaddr *remoteaddr, struct in_addr *remote_in4, struct in6_addr *remote_in6= );

+ int (*open_tu= n_dco)(struct tuntap *tt, openvpn_net_ctx_t *ctx, const char *dev);<= br>+ void (*close_tun_dco)(s= truct tuntap *tt, openvpn_net_ctx_t *ctx);
+ int (*dco_swap_keys)(dco_context_t *dco, unsigne= d int peerid);
+ i= nt (*dco_del_peer)(dco_context_t *dco, unsigned int peerid);
+ int (*dco_del_key)(dco_context= _t *dco, unsigned int peerid, dco_key_slot_t slot);

+ int (*dco_new_key)(dco_context_t *dco= , unsigned int peerid, int keyid, dco_key_slot_t slot, const uint8_t *encry= pt_key, const uint8_t *encrypt_iv, const uint8_t *decrypt_key, const uint8_= t *decrypt_iv, const char *ciphername);
+ int (*dco_set_peer)(dco_context_t *dco, unsigned in= t peerid, int keepalive_interval, int keepalive_timeout, int mss);+ int (*ovpn_handle_msg)(s= truct nl_msg *msg, void *arg);
+ int (*dco_do_read)(dco_context_t *dco);
+ void (*dco_update_peer_stat)(struct = context_2 *c2, struct nlattr *tb[], uint32_t id);
+ int (*dco_parse_peer_multi)(struct nl_msg= *msg, void *arg);
+ = int (*dco_get_peer_stats_multi)(dco_context_t *dco, struct multi_context= *m);
+ int (*dco_= parse_peer)(struct nl_msg *msg, void *arg);
+ int (*dco_get_peer_stats)(struct context *c);
+};
+
+extern const struct dco_ops dco_ops_v2;
+
+int ovpn_get_mcast_id(dco_context_t *dco);
+

+void dco_check_key_ctx(const struct key_ctx_bi *key)= ;
+
+typedef int (*ovpn_nl_cb)(struct nl_m= sg *msg, void *arg);
= +
+/**
+ * @brief resolves the netlink ID = for ovpn-dco

+ *
+ * This function queries= the kernel via a netlink socket
+ * whether the ovpn-dco netlink namespace is available<= br>+ *
+ * This function can be used to determine if= the kernel
+ * suppo= rts DCO offloading.
+= *
+ * @return ID on = success, negative error code on error
+ */
+int resolve_ovpn_netlink_id(int msglevel, dco_context_t *dco);
= +
+int ovpn_nl_recvmsgs(dco_context_t *dco, const ch= ar *prefix);
+=
+/**
+ * Send a prepared netlink message and re= gisters cb as callback if non-null.
+ *
+ = * The method will also free nl_msg
+ * @param dco The dco context to use
+ * @param nl_msg the message to us= e
+ * @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 u= ser context
+ * @retu= rn status of sending the message
+ */
+int ovpn_nl_msg_send(dco_context_t *dco, struct nl_msg *nl_msg, ovpn_= nl_cb cb,
+ = void *cb_arg, const char *prefix);
+
+struct sockaddr *
+mapped_v4_to_v6(struct sockaddr *sock, struct gc_arena *gc);+
+int ovpn_nl_cb_finish(struct nl_msg (*msg) __att= ribute__ ((unused)), void *arg);
+
+/* Thi= s function is used as error callback on the netlink socket.
+ * When something goes wrong and th= e kernel returns an error, this function is

+ * invoked.
+ *
+ = * We pass the error code to the user by means of a variable pointed by *arg=
+ * (supplied by the= user when setting this callback) and we parse the kernel
+ * reply to see if it contains a huma= n-readable error. If found, it is printed.
+ */
+int ovpn_nl_cb_error(struct sockaddr_nl (*nla) __attribute__ ((unuse= d)),
+ = struct nlmsgerr *err, void *arg);
+
= +void ovpn_dco_init_netlink(dco_context_t *dco);
+
+bool ovpn_dco_init(int mode, dco_context_t *dco);
+

+void ovpn_dco_uninit_netlink(dco_context_t *dco);
+
+void ovpn_dco_register(dco_context_t *dco= );
+
+/* This function parses the reply pr= ovided by the kernel to the CTRL_CMD_GETFAMILY
+ * message. We parse the reply and we retrieve t= he multicast group ID associated
+ * with the "ovpn-dco" netlink family.
+ *

+ * The ID is later used to subscribe to the multic= ast group and be notified
+ * about any multicast message sent by the ovpn-dco kernel module.
+ */
+int mcast_family_handler(struct nl_msg= *msg, void *arg);
+<= /span>
+/**
+ * Lookup the multicast id for OpenV= PN. This method and its help method currently
+ * hardcode the lookup to OVPN_NL_NAME and OVPN_N= L_MULTICAST_GROUP_PEERS but
+ * extended in the future if we need to lookup more than one mcast = id.
+ */
+int ovpn_get_mcast_id(dco_contex= t_t *dco);

++bool dco_available(int msgle= vel, dco_context_t *dco);
+
+const char *d= co_version_string(struct gc_arena *gc);
+
= +void dco_event_set(dco_context_t *dco, struct event_set *es, void *arg);
+
+const char *dco_get_supported_ciphers();=
+
#= endif /* defined(ENABLE_DCO) && defined(TARGET_LINUX) */
= #endif /* ifndef DCO_LINUX_H */
diff --git a/src/ope= nvpn/dco_linux_v2.c b/src/openvpn/dco_linux_v2.c
new file m= ode 100644
index 0000000..6fc47fa
--- /dev/= null
+++ b/src/openvpn/dco_linux_v2.c
@@ -0= ,0 +1,636 @@
+/*
+ * Interface to linux d= co networking code
+ = *
+ * Copyright (C) = 2020-2024 Antonio Quartulli <a@...2181...>
+ * Copyright (C) 2020-2024 Arne Schwabe <a= rne@...1227...>
+ = * Copyright (C) 2020-2024 Gianmarco De Gregori <gianmarco@...2726...>= ;
+ * Copyright (C) = 2020-2024 OpenVPN Inc <sales@...515...>
+ *
+ * This program is free software; you can redistribute it and/or = modify
+ * it under = the terms of the GNU General Public License version 2
+ * as published by the Free Software Fou= ndation.
+ *+ * This program is distribu= ted in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied = warranty of
+ * MERC= HANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for mo= re details.
+ *
+ * You should have recei= ved a copy of the GNU General Public License
+ * along with this program (see the file COPYING = included with this
+ = * distribution); if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Sui= te 330, Boston, MA 02111-1307 USA
+ */
+=
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"<= br>+#endif
+
+#if defined(ENABLE_DCO) && defined(TARGET_LINUX)
+
+#include "syshead.h"
= +
+#include "dco_linux.h"
+#include "errlevel.h"
+#include "buffer.h&= quot;
+#include "= ;networking.h"
+= #include "openvpn.h"
+
+#include= "socket.h"
+#include "tun.h"
+#include "ssl.h"
+#include "fdmisc.h"
+#include "multi.h"
+#include "ssl_verify.h"=
+
+#include "ovpn_dco_linux.h"<= br>+
+#include <netlink/socket.h>
+#include <netlink/netlink.h&g= t;

+#include <netl= ink/genl/genl.h>
+= #include <netlink/genl/family.h>
+#include <netlink/genl/ctrl.h>
+
+int
= +open_tun_dco_v2(struct tuntap *tt, openvpn_net_ctx_t *ctx, const char *dev= )
+{
+ msg(D_DCO_DEBUG, "%s: %s&qu= ot;, __func__, dev);
= + ASSERT(tt->type =3D=3D DEV_TYPE_TUN);
+
+ int ret =3D net_iface_new(ctx, dev, "ovpn-dco", &t= t->dco);
+ if (= ret < 0)
+ {
+ msg(D_DCO_DEBU= G, "Cannot create DCO interface %s: %d", dev, ret);
+ return ret;

+ }

+
+ tt->dco.ifindex =3D if_nametoindex(dev);
+ if (!tt->dco.ifindex)+ {
+ msg(M_FATAL, "DCO: cannot re= trieve ifindex for interface %s", dev);
+ }
+
+ tt-&= gt;dco.dco_message_peer_id =3D -1;
+
+ = ovpn_dco_register(&tt->dco);
+
+ = return 0;
+}<= br>+
+static struct nl_msg *
+ovpn_dco_v2_nlmsg_create(dco_context_t *d= co, int cmd)
+{
+ enum ovpn_nl_commands= enum_cmd =3D (enum ovpn_nl_commands)cmd;
+ struct nl_msg *nl_msg =3D nlmsg_alloc();+ if (!nl_msg)
<= span style=3D"color: hsl(120, 100%, 40%);">+ {

+ msg(M_ERR, "cannot allocate netl= ink message");
+= return NULL;
= + }
+
+ genlmsg_put(nl_msg, 0, 0, dc= o->ovpn_dco_id, 0, 0, enum_cmd, 0);

+ NLA_PUT_U32(nl_msg, OVPN_ATTR_IFINDEX, dco->ifind= ex);
+
+ return nl_msg;

+nla_put_failure:

+ nlmsg_free(nl_msg);
+ msg(M_INFO, "cannot put i= nto netlink message");

+ return NULL;
+}
+
+int

+dco_v2_new_peer(dco_context_t *dco, unsigned int= peerid, int sd,
+ = struct sockaddr *localaddr, struct sockaddr *remoteaddr,
+ struct in= _addr *remote_in4, struct in6_addr *remote_in6)
+{
+ struct gc_arena gc =3D gc_new();
+ const char *remotestr =3D "[undefined]&= quot;;
+ if (remot= eaddr)
+ {<= br>+ remotestr =3D print= _sockaddr(remoteaddr, &gc);
+ }
+ = msg(D_DCO_DEBUG, "%s: peer-id %d, fd %d, remote addr: %s", __fu= nc__,
+ peerid= , sd, remotestr);
+
+ struct nl_msg *nl= _msg =3D ovpn_dco_v2_nlmsg_create(dco, OVPN_CMD_NEW_PEER);
+ struct nlattr *attr =3D nla_nest= _start(nl_msg, OVPN_ATTR_NEW_PEER);
+ int ret =3D -EMSGSIZE;
+
+ NLA_PUT_U32(nl_msg, OVPN_NEW_PEER_ATTR_PEER_ID, peerid);
= + NLA_PUT_U32(nl_msg, OVPN_N= EW_PEER_ATTR_SOCKET, sd);
+
+ /* Set th= e remote endpoint if defined (for UDP) */
+ if (remoteaddr)
+ {
+ remoteaddr =3D mapped_v4_to_v6(remoteaddr, &gc);=
+ int alen =3D af_ad= dr_size(remoteaddr->sa_family);
+
+ = NLA_PUT(nl_msg, OVPN_NEW_PEER_ATTR_SOCKADDR_REMOTE, alen, remoteaddr);<= /span>
+ }
+

+ if (localaddr)
+ {
+ localaddr =3D mapped_v4_to_v6(localaddr, &gc);+ if (localaddr->sa_= family =3D=3D AF_INET)
+ = NLA_PUT(nl_msg, OVPN_NEW_PEER_ATTR_LOCAL_IP, sizeof(struct in_addr),
+ &= amp;((struct sockaddr_in *)localaddr)->sin_addr);
+ }
+ else if (localaddr->sa_family =3D=3D AF_= INET6)
+ {
+ NLA_PUT(nl_= msg, OVPN_NEW_PEER_ATTR_LOCAL_IP, sizeof(struct in6_addr),
+ &((struct so= ckaddr_in6 *)localaddr)->sin6_addr);
+ }
+ }
+
+ /* Set the primary = VPN IP addresses of the peer */
+ if (remote_in4)
+ {
+ = NLA_PUT_U32(nl_msg, OVPN_NEW_PEER_ATTR_IPV4, remote_in4->s_addr);<= /span>
+ }
+ if (remote_in6)

+ {

+ NLA_PUT(nl_msg, OVPN_NEW_PEER_ATTR_IPV6,= sizeof(struct in6_addr),
+ remote_in6);
+ }
= + nla_nest_end(nl_msg, attr);
+
+ re= t =3D ovpn_nl_msg_send(dco, nl_msg, NULL, NULL, __func__);
+
+nla_put_failure:
+ nlmsg_free(nl_msg);
+ gc_free(&gc);
+ return ret;
+}
= +
+void
+close_tun_dco_v2(struct tuntap *t= t, openvpn_net_ctx_t *ctx)

+{
+ msg(D_D= CO_DEBUG, __func__);
= +
+ net_iface_del(= ctx, tt->actual_name);
+ ovpn_dco_uninit_netlink(&tt->dco);
+}
+
+int=
+dco_v2_swap_keys(dc= o_context_t *dco, unsigned int peerid)
+{
= + msg(D_DCO_DEBUG, "%s: peer-id %d", __func__, peerid);=
+
+ struct nl_msg *nl_msg =3D ovpn_dco_v2_nlm= sg_create(dco, OVPN_CMD_SWAP_KEYS);
+ if (!nl_msg)
+ {
+ = return -ENOMEM;
+
= + struct nlattr *attr =3D nl= a_nest_start(nl_msg, OVPN_ATTR_SWAP_KEYS);
+ int ret =3D -EMSGSIZE;
+ NLA_PUT_U32(nl_msg, OVPN_SWAP_KEYS_ATTR_P= EER_ID, peerid);
+ = nla_nest_end(nl_msg, attr);
+
+ ret = =3D ovpn_nl_msg_send(dco, nl_msg, NULL, NULL, __func__);
+
+nla_put_failure:
+ nlmsg_free(nl_msg);
+ return ret;
+}
+
+
+int
+dco_v2_del_peer(dco_context_t *dco, unsigned int peerid)<= /span>
+{
+ msg(D_DCO_DEBUG, "%s: peer-id= %d", __func__, peerid);
+
+ struc= t nl_msg *nl_msg =3D ovpn_dco_v2_nlmsg_create(dco, OVPN_CMD_DEL_PEER);
+ if (!nl_msg)<= br>+ {
+ return -ENOMEM;
+ }
+
+ struct nlattr *attr =3D nla_nest_start(nl_msg, OVPN_ATTR_DEL_PEER)= ;
+ int ret =3D -E= MSGSIZE;
+ 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__);
+=
+nla_put_failure:+ nlmsg_free(nl_msg);
+ return ret;+}
+
+
+int=
+dco_v2_del_key(dco_context= _t *dco, unsigned int peerid,
+ dco_key_slot_t slot)
+{
+ msg(D_DCO_DEBUG, "%s: peer-id %d, slot %d", __func__,= peerid, slot);
+
+ struct nl_msg *nl_m= sg =3D ovpn_dco_v2_nlmsg_create(dco, OVPN_CMD_DEL_KEY);
+ if (!nl_msg)
+ {
+ return -ENOMEM;
+ }
+
+ struc= t nlattr *attr =3D nla_nest_start(nl_msg, OVPN_ATTR_DEL_KEY);
+ int ret =3D -EMSGSIZE;
=
+ NLA_PUT_U32(nl_msg, OV= PN_DEL_KEY_ATTR_PEER_ID, peerid);
+ NLA_PUT_U8(nl_msg, OVPN_DEL_KEY_ATTR_KEY_SLOT, slot);
+ nla_nest_end(nl_msg= , attr);
+
= + ret =3D ovpn_nl_msg_send(d= co, nl_msg, NULL, NULL, __func__);
+
+nla_= put_failure:
+ nlm= sg_free(nl_msg);
+ = return ret;
+}
+
+int
+dco_v2_new_key(dco_context_t *dco, unsigned int peerid, int = keyid,
+ = dco_key_slot_t slot,
+ const u= int8_t *decrypt_key, const uint8_t *decrypt_iv,
+ const char *ciphername)+{
+ msg(D_DCO_DEBUG, "%s: slot %d, key-id= %d, peer-id %d, cipher %s",
+ __func__, slot, keyid, peerid, ciphername);+
+ const size_t key_len =3D cipher_kt_key_size(= ciphername);
+ con= st int nonce_tail_len =3D 8;
+
+ struct= nl_msg *nl_msg =3D ovpn_dco_v2_nlmsg_create(dco, OVPN_CMD_NEW_KEY);=
+ if (!nl_msg)+ {
+ return -ENOMEM;
+ }
+
+ dco_cipher_t dco_cipher =3D dco_get_cipher(ciphername);
= +
+ int ret =3D -EMSGSIZE;
+ struct nlattr *attr =3D nla_nest_star= t(nl_msg, OVPN_ATTR_NEW_KEY);
+ NLA_PUT_U32(nl_msg, OVPN_NEW_KEY_ATTR_PEER_ID, peerid);
+ NLA_PUT_U8(nl_msg, OV= PN_NEW_KEY_ATTR_KEY_SLOT, slot);
+ NLA_PUT_U8(nl_msg, OVPN_NEW_KEY_ATTR_KEY_ID, keyid);
+ NLA_PUT_U16(nl_msg, O= VPN_NEW_KEY_ATTR_CIPHER_ALG, dco_cipher);
+
+ = OVPN_NEW_KEY_ATTR_ENCRYPT_KEY);
+ if (dco_cipher !=3D OVPN_CIPHER_ALG_NONE)
<= span style=3D"color: hsl(120, 100%, 40%);">+ {

+ NLA_PUT(nl_msg, OVPN_KEY_DIR_ATTR_CIP= HER_KEY, key_len, encrypt_key);
+ NLA_PUT(nl_msg, OVPN_KEY_DIR_ATTR_NONCE_TAIL, nonce_tai= l_len,
+ = encrypt_iv);
+ = }
+ nla_nest_end(n= l_msg, key_enc);
+
+ struct nlattr *key= _dec =3D nla_nest_start(nl_msg,
+ OVPN_NEW_KEY_ATTR_D= ECRYPT_KEY);
+ if = (dco_cipher !=3D OVPN_CIPHER_ALG_NONE)
+ {
+ NLA_PUT(nl_msg, OVPN_KEY_DIR_ATTR_CIPHER_KEY, key_len, decrypt= _key);
+ NLA_P= UT(nl_msg, OVPN_KEY_DIR_ATTR_NONCE_TAIL, nonce_tail_len,
+ decrypt_iv);+ }
+ nla_nest_end(nl_msg, key_dec);=
+
+ nla_nest_end(nl_msg, attr);
+

+ ret =3D ovpn_nl_msg_send(dco, nl_msg, NULL, NULL= , __func__);
+=
+nla_put_failure:+ nlmsg_free(nl_msg);
+ return ret;+}
+
+int
+dco_v2_= set_peer(dco_context_t *dco, unsigned int peerid,
+ int keepalive_interval, int k= eepalive_timeout, int mss)
+{
+ msg(D_D= CO_DEBUG, "%s: peer-id %d, keepalive %d/%d, mss %d", __func__,
+ peerid, keepal= ive_interval, keepalive_timeout, mss);
+
+= struct nl_msg *nl_msg =3D ovpn_dco_v2_nlmsg_create(dco, OVPN_CMD_SET_PE= ER);
+ if (!nl_msg= )
+ {
+ return -ENOMEM;
+ }
+
+ struct nlattr *attr =3D nla_nest_start(nl_msg, OVPN_ATTR= _SET_PEER);
+ int = ret =3D -EMSGSIZE;
+ = NLA_PUT_U32(nl_msg, OVPN_SET_PEER_ATTR_PEER_ID, peerid);
+ NLA_PUT_U32(nl_msg, OVPN_SET_PE= ER_ATTR_KEEPALIVE_INTERVAL,

+ keepalive_interval);
+ NLA_PUT_U32(nl_msg, OVPN_SET_PEER_ATTR_KEEPALI= VE_TIMEOUT,
+ = keepalive_timeout);
+ nla_nest_end(nl_msg, attr);
+
= + ret =3D ovpn_nl_msg_send(dco, nl_msg, NULL, NULL, __func__);+
+nla_put_failure:
+ nlmsg_free(nl_msg);
+ return ret;
+}
+
+/* This funct= ion parses any netlink message sent by ovpn-dco to userspace */
<= span style=3D"color: hsl(120, 100%, 40%);">+static int

+ovpn_v2_handle_msg(struct nl_msg *msg, v= oid *arg)
+{+ dco_context_t *dco =3D a= rg;
+
+ struct genlmsghdr *gnlh =3D nlm= sg_data(nlmsg_hdr(msg));

+ struct nlattr *attrs[OVPN_ATTR_MAX + 1];
+ struct nlmsghdr *nlh =3D nlmsg_hdr(msg);<= /span>
+
+ if (!genlmsg_valid_hdr(nlh, 0))
+ {
+ msg(D_DCO, "ovpn-dco: in= valid header");
= + return NL_SKIP;
+ }
++ if (nla_parse(attrs, OVP= N_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 w= hich interface this message is referring to in order to
+ * avoid mixing messages for other = instances
+ */
+ if (!attrs[OVPN_AT= TR_IFINDEX])
+ {
+ msg(D_DCO, &q= uot;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_DEB= UG,
+ &quo= t;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.<= /span>
+ *
+ * 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.
+ */
+ {
+ = case OVPN_CMD_DEL_PEER:
+ {
+ = if (!attrs[OVPN_ATTR_DEL_PEER])
+ {
+ msg(D_DCO, "ovpn-dco: no attributes in = OVPN_DEL_PEER message");
+ 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], N= ULL))
+ {<= /span>
+ msg(= D_DCO, "received bogus del peer packet data from ovpn-dco");
+ return N= L_SKIP;
+ = }
+
+ if (!dp_attrs[OVPN_DEL_PE= ER_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_PE= ER message");
+ = return NL_SKIP;
+ }
+ int reason =3D nla_get_u8(dp_attrs[OVPN_DEL_PEER_ATTR_REAS= ON]);
+ un= signed int peerid =3D nla_get_u32(dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID]);
+
+ msg(D_DCO_DEBUG, "ovpn-d= co: 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 re= ason;
+ dc= o->dco_message_type =3D OVPN_CMD_DEL_PEER;
+
+ break;
+ }
+
+ default:=
+ msg(D_DCO, &qu= ot;ovpn-dco: received unknown command: %d", gnlh->cmd);
<= span style=3D"color: hsl(120, 100%, 40%);">+ dco->dco_message= _type =3D 0;

+ = return NL_SKIP;
= + }
+
+ return NL_OK;

+}

+
+static int
+dco_v= 2_do_read(dco_context_t *dco)
+{
+ msg(= D_DCO_DEBUG, __func__);
+ nl_cb_set(dco->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, ovpn_v2_handle_= msg, dco);
++ return ovpn_nl_recvmsgs(= dco, __func__);
+}
+
+static void
+dco_v2_update_peer_stat(struct context_2 *c2, str= uct nlattr *tb[], uint32_t id)
+{
+ if = (tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES])
+ {
+ c2->dco_read_bytes =3D nla_get_u64(tb[OVPN_GET_PEER_RE= SP_ATTR_LINK_RX_BYTES]);
+ msg(D_DCO_DEBUG, "%s / dco_read_bytes: " counter_for= mat, __func__,
+ = c2->dco_read_bytes);
+ }
+ = else
+ {+ msg(M_WARN, "%s= : no link RX bytes provided in reply for peer %u",
+ __func__, id);
+ }

+
+ if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES])
+ {

+ c2->dco_write_bytes =3D nla_get_u64(t= b[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES]);
+ msg(D_DCO_DEBUG, "%s / dco_write_bytes:= " counter_format, __func__,
+ c2->dco_write_bytes);
+ }
+ else
+ {
+ = msg(M_WARN, "%s: no link TX bytes provided in reply for peer %u",=
+ __func_= _, id);
+ }=
+
+ if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYT= ES])
+ {+ c2->tun_read_bytes= =3D nla_get_u64(tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES]);
+ msg(D_DCO_DEBUG, "%s /= tun_read_bytes: " counter_format, __func__,

+ c2->tun_read_bytes);+ }
+ else
+ {
+ msg(M_WARN, "%s: no VPN RX bytes provided in reply fo= r peer %u",
+ = __func__, id);
+ }
++ if (tb[OVPN_GET_PEER_RESP= _ATTR_VPN_TX_BYTES])
= + {
+ c2-&g= t;tun_write_bytes =3D nla_get_u64(tb[OVPN_GET_PEER_RESP_ATTR_VPN_TX_BYTES])= ;
+ msg(D_DCO_= DEBUG, "%s / tun_write_bytes: " counter_format, __func__,<= br>+ c2->tun_writ= e_bytes);
+ }
+ else
+ {

+ msg(M_WARN, "%s: no VPN TX bytes pro= vided in reply for peer %u",
+ __func__, id);
+ }
+}
+
= +int
+dco_v2_parse_peer_multi(struct nl_msg *msg, vo= id *arg)
+{+ struct nlattr *tb[OVPN_AT= TR_MAX + 1];
+ str= uct genlmsghdr *gnlh =3D nlmsg_data(nlmsg_hdr(msg));
+
+ msg(D_DCO_DEBUG, "%s: parsing message...", __f= unc__);
+
<= span style=3D"color: hsl(120, 100%, 40%);">+ nla_parse(tb, OVPN_ATTR_MAX= , genlmsg_attrdata(gnlh, 0),

+ genlmsg_attrlen(gnlh, 0), NULL);
+
+ if (!tb[OVPN_ATTR_GET_PEER])
+ {
+ return NL_SKIP;
+ }
+
+ struct nl= attr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX + 1];
+
+ nla_parse(tb_peer, OVPN_GET_PEER_RESP_ATTR_MAX,
+ nla_data(tb[OVPN_ATT= R_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;
+ }
+
+ struct multi_cont= ext *m =3D arg;
+ = uint32_t peer_id =3D nla_get_u32(tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID]);=
+
+ if (peer_id >=3D m->max_clie= nts || !m->instances[peer_id])
+ {
+= msg(M_WARN, "%s: cannot store DCO stats for peer %u", __f= unc__,
+ p= eer_id);
+ ret= urn NL_SKIP;
+ }
+
+ dco_v2_update_peer_stat(&m->i= nstances[peer_id]->context.c2, tb_peer, peer_id);
+
+ return NL_OK;
+}
+
+int
+dco_v2_get_peer_stats_multi(dco_context_= t *dco, struct multi_context *m)
+{
+ m= sg(D_DCO_DEBUG, "%s", __func__);
+
+ struct nl_msg *nl_msg =3D ovpn_dco_v2_nlmsg_create(dco, OVPN_CMD_GE= T_PEER);
+
= + nlmsg_hdr(nl_msg)->nlms= g_flags |=3D NLM_F_DUMP;
+
+ int ret = =3D ovpn_nl_msg_send(dco, nl_msg, dco_v2_parse_peer_multi, m, __func__);
+
+ nlmsg_free(nl_msg);
+ return ret;
+}
+
+sta= tic int
+dco_v2_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_dat= a(nlmsg_hdr(msg));
+<= /span>
+ msg(D_DCO_DEBUG,= "%s: parsing message...", __func__);
+
+ nla_parse(tb, OVPN_ATTR_MAX, genlmsg_attrdata(gnlh, 0),=
+ genlmsg_attr= len(gnlh, 0), NULL);
= +
+ if (!tb[OVPN_A= TTR_GET_PEER])
+ {=
+ msg(D_DCO_D= EBUG, "%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,<= /span>
+ nla_da= ta(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 pe= er-id provided in reply", __func__);

+ return NL_SKIP;
+ }
+
+ uin= t32_t peer_id =3D nla_get_u32(tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID]);
+ if (c->c2.tls_m= ulti->dco_peer_id !=3D peer_id)
+ {
= + return NL_SKIP;
+ }
++ dco_v2_update_peer_stat(= &c->c2, tb_peer, peer_id);
+
+ r= eturn NL_OK;
+}
+
+int
+dco_v2_get_peer_stats(struct context *c)
+{
+ uint32_t peer_id =3D c->c2.tls_multi->dco_peer_= id;
+ msg(D_DCO_DE= BUG, "%s: peer-id %d", __func__, peer_id);
+
+ if (!c->c1.tuntap)
+ {
+ return 0;
+ }
++ dco_context_t *dco =3D &= amp;c->c1.tuntap->dco;
+ struct nl_msg *nl_msg =3D ovpn_dco_v2_nlmsg_create(dco, OVPN_C= MD_GET_PEER);
+ st= ruct nlattr *attr =3D nla_nest_start(nl_msg, OVPN_ATTR_GET_PEER);+ int ret =3D -EMSGSIZE;
+
+ NLA_PUT_U32(nl_msg, OVPN_GET_PEER_ATT= R_PEER_ID, peer_id);
= + nla_nest_end(nl_msg, attr);
+
+ re= t =3D ovpn_nl_msg_send(dco, nl_msg, dco_v2_parse_peer, c, __func__);=
+
+nla_put_failure:
+ nlmsg_free(nl_msg);
+ return ret;
+}
+
+const stru= ct dco_ops dco_ops_v2 =3D {
+ .ovpn_dco_nlmsg_create =3D ovpn_dco_v2_nlmsg_create,
= + .dco_new_peer =3D &dco= _v2_new_peer,
+ .o= pen_tun_dco =3D open_tun_dco_v2,
+ .close_tun_dco =3D close_tun_dco_v2,
+ .dco_swap_keys =3D &dco_v2_swap_k= eys,
+ .dco_del_pe= er =3D &dco_v2_del_peer,
+ .dco_del_key =3D &dco_v2_del_key,
+ .dco_new_key =3D &dco_v2_new_key,
+ .dco_set_peer =3D = &dco_v2_set_peer,
+ .ovpn_handle_msg =3D &ovpn_v2_handle_msg,
+ .dco_do_read =3D &dco_v2_do_read,=
+ .dco_update_pee= r_stat =3D &dco_v2_update_peer_stat,
+ .dco_parse_peer_multi =3D &dco_v2_parse_peer_m= ulti,
+ .dco_get_p= eer_stats_multi =3D &dco_v2_get_peer_stats_multi,
+ .dco_parse_peer =3D &dco_v2_parse= _peer,
+ .dco_get_= peer_stats =3D &dco_v2_get_peer_stats
+};
+
+#endif /* defi= ned(ENABLE_DCO) && defined(TARGET_LINUX) */
diff --= git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c
index e= 3ada76..65be766 100644
--- a/src/openvpn/dco_win.c+++ b/src/openvpn/dco_win.c
@@ -357,7 +357,7 @@
}

bool
-dco_available(int msglevel)
+dco_available(int msglevel, dco_c= ontext_t *dco)

{
/* try to open devic= e by symbolic name */
HANDLE h =3D CreateFile("\\= \\.\\ovpn-dco", GENERIC_READ | GENERIC_WRITE,
diff --g= it a/src/openvpn/forward.c b/src/openvpn/forward.c
index 01= 165b2..118c32a 100644
--- a/src/openvpn/forward.c+++ b/src/openvpn/forward.c
@@ -1230,6 +1230,9 @@
process_incoming_dco(struct context *c)
{
#if defined(ENABLE_DCO) && (defined(TARGET_LINUX) |= | defined(TARGET_FREEBSD))
+ int cmd_del_peer =3D OVPN_CMD_DEL_PEER;
+ int cmd_swap_keys =3D OVPN_CMD_SWAP_KEYS= ;
+
= dco_context_t *dco =3D &c->c1.tuntap->dco;
<= /span>
dco_do_read(dco);
@@ -1245,31 +1248,30= @@
return;
}

- switch (dco->= ;dco_message_type)
+ = if (dco->dco_message_type =3D=3D cmd_del_peer)
{=
- case OVPN_CMD= _DEL_PEER:
- = if (dco->dco_del_peer_reason =3D=3D OVPN_DEL_PEER_REASON_EXPIRED)
- {
- msg(D_DCO_DEBUG, &q= uot;%s: received peer expired notification of for peer-id "

= - "%d&quo= t;, __func__, dco->dco_message_peer_id);
- trigger_ping_timeout_signal(c);
- return;
- }
<= span style=3D"color: hsl(0, 100%, 40%);">- break;

-

- case OVPN_CMD_SWAP_KEYS:
- msg(D_DCO_DEBUG, "%s: receive= d key rotation notification for peer-id %d",
- __func__, dco->dco_message_p= eer_id);
- t= ls_session_soft_reset(c->c2.tls_multi);
- break;
-
- = default:
- = msg(D_DCO_DEBUG, "%s: received message of type %u - ignoring"= , __func__,
- = dco->dco_message_type);
+ if (dco->dco_del_peer_reason =3D=3D OVPN_DEL_PEER_R= EASON_EXPIRED)
+ = {
+ msg= (D_DCO_DEBUG, "%s: received peer expired notification of for peer-id &= quot;
+ = "%d", __func__, dco->dco_message_peer_id);
+ trigger_ping_timeout_sign= al(c);
return;
+ }
+ }
+= else if (dco->dco_message_type =3D=3D cmd_swap_keys)
+ {

+ msg(D_DCO_DEBUG, "%s: received key r= otation notification for peer-id %d",
+ __func__, dco->dco_message_peer_id);<= /span>
+ tls_session_= soft_reset(c->c2.tls_multi);
+ }
+ = else
+ {<= br>+ msg(D_DCO_DEBUG, &q= uot;%s: received message of type %u - ignoring", __func__,
<= span style=3D"color: hsl(120, 100%, 40%);">+ dco->dco_message= _type);

+ retu= rn;
}

-#endif /* if defined(ENABLE_DCO) && (defined= (TARGET_LINUX) || defined(TARGET_FREEBSD)) */
+#endif /* #if defined(ENABLE_DCO) && defi= ned(TARGET_FREEBSD) */
}

/*


To view, visit change 662. To unsubscri= be, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6662605b60d4859949970cfe256= c55cbcbd4a672
Gerrit-Change-Number: 662
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <gianmarco@...2786...= ..>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newchange
--3K8KSMjus+E=--