From: Sabrina Dubroca <sd@queasysnail.net>
To: Antonio Quartulli <antonio@openvpn.net>
Cc: netdev@vger.kernel.org, Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Donald Hunter <donald.hunter@gmail.com>,
Shuah Khan <shuah@kernel.org>,
ryazanov.s.a@gmail.com, Andrew Lunn <andrew+netdev@lunn.ch>,
Simon Horman <horms@kernel.org>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
Xiao Liang <shaw.leon@gmail.com>
Subject: Re: [PATCH net-next v18 20/25] ovpn: implement peer add/get/dump/delete via netlink
Date: Mon, 3 Feb 2025 00:07:16 +0100 [thread overview]
Message-ID: <Z5_6pC-zsVzukJs3@hog> (raw)
In-Reply-To: <20250113-b4-ovpn-v18-20-1f00db9c2bd6@openvpn.net>
2025-01-13, 10:31:39 +0100, Antonio Quartulli wrote:
> +static int ovpn_nl_attr_sockaddr_remote(struct nlattr **attrs,
> + struct sockaddr_storage *ss)
> +{
> + struct sockaddr_in6 *sin6;
> + struct sockaddr_in *sin;
> + struct in6_addr *in6;
> + __be16 port = 0;
> + __be32 *in;
> + int af;
> +
> + ss->ss_family = AF_UNSPEC;
> +
> + if (attrs[OVPN_A_PEER_REMOTE_PORT])
> + port = nla_get_be16(attrs[OVPN_A_PEER_REMOTE_PORT]);
> +
> + if (attrs[OVPN_A_PEER_REMOTE_IPV4]) {
> + af = AF_INET;
> + ss->ss_family = AF_INET;
> + in = nla_data(attrs[OVPN_A_PEER_REMOTE_IPV4]);
> + } else if (attrs[OVPN_A_PEER_REMOTE_IPV6]) {
> + af = AF_INET6;
> + ss->ss_family = AF_INET6;
> + in6 = nla_data(attrs[OVPN_A_PEER_REMOTE_IPV6]);
> + } else {
> + return AF_UNSPEC;
> + }
> +
> + switch (ss->ss_family) {
> + case AF_INET6:
> + /* If this is a regular IPv6 just break and move on,
> + * otherwise switch to AF_INET and extract the IPv4 accordingly
> + */
> + if (!ipv6_addr_v4mapped(in6)) {
> + sin6 = (struct sockaddr_in6 *)ss;
> + sin6->sin6_port = port;
> + memcpy(&sin6->sin6_addr, in6, sizeof(*in6));
> + break;
> + }
> +
> + /* v4-mapped-v6 address */
> + ss->ss_family = AF_INET;
> + in = &in6->s6_addr32[3];
> + fallthrough;
> + case AF_INET:
> + sin = (struct sockaddr_in *)ss;
> + sin->sin_port = port;
> + sin->sin_addr.s_addr = *in;
> + break;
> + }
> +
> + /* don't return ss->ss_family as it may have changed in case of
> + * v4-mapped-v6 address
> + */
nit: I'm not sure that matters since the only thing the caller checks
is ret != AF_UNSPEC, and at this point, while ss_family could have
been changed, it would have changed from AF_INET6 to AF_INET, so it's
!= AF_UNSPEC.
> + return af;
> +}
[...]
> +static int ovpn_nl_peer_precheck(struct ovpn_priv *ovpn,
> + struct genl_info *info,
> + struct nlattr **attrs)
> +{
[...]
> +
> + /* VPN IPs are needed only in MP mode for selecting the right peer */
> + if (ovpn->mode == OVPN_MODE_P2P && (attrs[OVPN_A_PEER_VPN_IPV4] ||
> + attrs[OVPN_A_PEER_VPN_IPV6])) {
And in MP mode, at least one VPN_IP* is required?
[...]
> int ovpn_nl_peer_new_doit(struct sk_buff *skb, struct genl_info *info)
> {
[...]
> + /* Only when using UDP as transport protocol the remote endpoint
> + * can be configured so that ovpn knows where to send packets to.
> + *
> + * In case of TCP, the socket is connected to the peer and ovpn
> + * will just send bytes over it, without the need to specify a
> + * destination.
> + */
> + if (sock->sk->sk_protocol != IPPROTO_UDP &&
> + (attrs[OVPN_A_PEER_REMOTE_IPV4] ||
> + attrs[OVPN_A_PEER_REMOTE_IPV6])) {
Is a peer on a UDP socket without any remote (neither
OVPN_A_PEER_REMOTE_IPV4 nor OVPN_A_PEER_REMOTE_IPV6) valid? We just
wait until we get data from it to update the endpoint?
Or should there be a check to make sure that one was provided?
> + NL_SET_ERR_MSG_FMT_MOD(info->extack,
> + "unexpected remote IP address for non UDP socket");
> + sockfd_put(sock);
> + return -EINVAL;
> + }
> +
> + ovpn_sock = ovpn_socket_new(sock, peer);
> + if (IS_ERR(ovpn_sock)) {
> + NL_SET_ERR_MSG_FMT_MOD(info->extack,
> + "cannot encapsulate socket: %ld",
> + PTR_ERR(ovpn_sock));
> + sockfd_put(sock);
> + return -ENOTSOCK;
Maybe s/-ENOTSOCK/PTR_ERR(ovpn_sock)/ ?
Overwriting ovpn_socket_new's -EBUSY etc with -ENOTSOCK is a bit
misleading to the caller.
> + }
> +
> + peer->sock = ovpn_sock;
> +
> + ret = ovpn_nl_peer_modify(peer, info, attrs);
> + if (ret < 0)
> + goto peer_release;
> +
> + ret = ovpn_peer_add(ovpn, peer);
> + if (ret < 0) {
> + NL_SET_ERR_MSG_FMT_MOD(info->extack,
> + "cannot add new peer (id=%u) to hashtable: %d\n",
> + peer->id, ret);
> + goto peer_release;
> + }
> +
> + return 0;
> +
> +peer_release:
I think you need to add:
ovpn_socket_release(peer);
If ovpn_socket_new succeeded, ovpn_peer_release only takes care of the
peer but not its socket.
> + /* release right away because peer is not used in any context */
> + ovpn_peer_release(peer);
> +
> + return ret;
> }
>
> int ovpn_nl_peer_set_doit(struct sk_buff *skb, struct genl_info *info)
> {
[...]
> + if (attrs[OVPN_A_PEER_SOCKET]) {
> + NL_SET_ERR_MSG_FMT_MOD(info->extack,
> + "socket cannot be modified");
> + return -EINVAL;
> + }
> +
> + peer_id = nla_get_u32(attrs[OVPN_A_PEER_ID]);
> + peer = ovpn_peer_get_by_id(ovpn, peer_id);
> + if (!peer) {
> + NL_SET_ERR_MSG_FMT_MOD(info->extack,
> + "cannot find peer with id %u", peer_id);
> + return -ENOENT;
> + }
The check for non-UDP socket with a remote address configured should
be replicated here, no?
--
Sabrina
next prev parent reply other threads:[~2025-02-02 23:07 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-13 9:31 [PATCH net-next v18 00/25] Introducing OpenVPN Data Channel Offload Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 01/25] net: introduce OpenVPN Data Channel Offload (ovpn) Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 02/25] ovpn: add basic netlink support Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 03/25] ovpn: add basic interface creation/destruction/management routines Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 04/25] ovpn: keep carrier always on for MP interfaces Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 05/25] ovpn: introduce the ovpn_peer object Antonio Quartulli
2025-01-17 11:58 ` Sabrina Dubroca
2025-01-17 12:26 ` Antonio Quartulli
2025-02-02 22:56 ` Sabrina Dubroca
2025-02-03 8:41 ` Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 06/25] ovpn: introduce the ovpn_socket object Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 07/25] ovpn: implement basic TX path (UDP) Antonio Quartulli
2025-02-03 9:52 ` Sabrina Dubroca
2025-02-04 16:18 ` Sabrina Dubroca
2025-02-05 9:12 ` Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 08/25] ovpn: implement basic RX " Antonio Quartulli
2025-02-03 9:30 ` Sabrina Dubroca
2025-02-03 9:58 ` Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 09/25] ovpn: implement packet processing Antonio Quartulli
2025-01-17 12:16 ` Sabrina Dubroca
2025-01-17 12:28 ` Antonio Quartulli
2025-02-05 21:50 ` Sabrina Dubroca
2025-02-07 13:13 ` Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 10/25] ovpn: store tunnel and transport statistics Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 11/25] ipv6: export inet6_stream_ops via EXPORT_SYMBOL_GPL Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 12/25] ovpn: implement TCP transport Antonio Quartulli
2025-01-15 17:25 ` Sabrina Dubroca
2025-01-15 17:55 ` Jakub Kicinski
2025-01-17 17:14 ` Sabrina Dubroca
2025-01-19 20:06 ` Antonio Quartulli
2025-01-20 14:12 ` Antonio Quartulli
2025-01-21 9:28 ` Sabrina Dubroca
2025-02-03 10:05 ` Sabrina Dubroca
2025-02-03 13:12 ` Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 13/25] skb: implement skb_send_sock_locked_with_flags() Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 14/25] ovpn: add support for MSG_NOSIGNAL in tcp_sendmsg Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 15/25] ovpn: implement multi-peer support Antonio Quartulli
2025-02-02 23:00 ` Sabrina Dubroca
2025-02-03 9:01 ` Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 16/25] ovpn: implement peer lookup logic Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 17/25] ovpn: implement keepalive mechanism Antonio Quartulli
2025-02-03 9:20 ` Sabrina Dubroca
2025-02-03 9:55 ` Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 18/25] ovpn: add support for updating local UDP endpoint Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 19/25] ovpn: add support for peer floating Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 20/25] ovpn: implement peer add/get/dump/delete via netlink Antonio Quartulli
2025-01-17 11:48 ` Sabrina Dubroca
2025-01-17 12:59 ` Antonio Quartulli
2025-01-17 17:12 ` Sabrina Dubroca
2025-01-19 13:12 ` Antonio Quartulli
2025-01-20 10:09 ` Sabrina Dubroca
2025-01-20 10:45 ` Antonio Quartulli
2025-01-20 21:20 ` Antonio Quartulli
2025-01-21 9:59 ` Sabrina Dubroca
2025-01-21 10:10 ` Antonio Quartulli
2025-01-21 9:39 ` Sabrina Dubroca
2025-01-21 9:48 ` Antonio Quartulli
2025-01-20 14:52 ` Antonio Quartulli
2025-01-21 23:26 ` Antonio Quartulli
2025-01-22 8:45 ` Sabrina Dubroca
2025-01-22 0:40 ` Antonio Quartulli
2025-01-22 8:51 ` Sabrina Dubroca
2025-01-22 9:00 ` Antonio Quartulli
2025-02-02 23:07 ` Sabrina Dubroca [this message]
2025-02-03 9:46 ` Antonio Quartulli
2025-02-03 10:42 ` Sabrina Dubroca
2025-01-13 9:31 ` [PATCH net-next v18 21/25] ovpn: implement key add/get/del/swap " Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 22/25] ovpn: kill key and notify userspace in case of IV exhaustion Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 23/25] ovpn: notify userspace when a peer is deleted Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 24/25] ovpn: add basic ethtool support Antonio Quartulli
2025-01-13 9:31 ` [PATCH net-next v18 25/25] testing/selftests: add test tool and scripts for ovpn module Antonio Quartulli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z5_6pC-zsVzukJs3@hog \
--to=sd@queasysnail.net \
--cc=andrew+netdev@lunn.ch \
--cc=antonio@openvpn.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=ryazanov.s.a@gmail.com \
--cc=shaw.leon@gmail.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.