ovpn: honor NLM_F_ECHO for peer deletion notifications
Subsystems (2)
PATCH 1/1 ovpn: honor NLM_F_ECHO for peer deletion notifications
Peer deletion notifications are sent only to the multicast group, ignoring NLM_F_ECHO on the triggering request. A requester without a multicast subscription therefore receives no deletion notification.
Pass the request context through the peer deletion paths, including P2P peer replacement, and send a unicast copy when NLM_F_ECHO is set. Send the echo to the requester's network namespace with the request's port ID and sequence number, while multicasting in the device's namespace.
Exclude the requesting socket from multicast delivery when sending an echo to avoid duplicate notifications. Compare socket pointers rather than port IDs, since distinct sockets in different network namespaces can have the same port ID.
---
This patch depends on the ovpn foreign-netns support series:
https://lore.kernel.org/all/[email protected]/
It builds on that series' notification routing: multicast notifications go to the device's network namespace, while an NLM_F_ECHO response goes to the requesting socket.
drivers/net/ovpn/netlink.c | 34 +++++++++++++++++++++++++----- drivers/net/ovpn/netlink.h | 13 +++++++++++- drivers/net/ovpn/peer.c | 43 ++++++++++++++++++++++++-------------- drivers/net/ovpn/peer.h | 8 +++++-- drivers/net/ovpn/tcp.c | 4 ++-- 5 files changed, 76 insertions(+), 26 deletions(-)
drivers/net/ovpn/netlink.c +29 -5
@@ -370,6 +370,7 @@ static int ovpn_nl_peer_modify(struct ovpn_peer *peer, struct genl_info *info,int ovpn_nl_peer_new_doit (struct sk_buff *skb,struct genl_info *info) { +struct ovpn_nl_request req = { .info = info, .sk =NETLINK_CB (skb).sk };struct nlattr *attrs[OVPN_A_PEER_MAX +1 ];struct ovpn_priv *ovpn = info->user_ptr[0 ];struct ovpn_socket *ovpn_sock;
@@ -473,7 +474,7 @@ int ovpn_nl_peer_new_doit(struct sk_buff *skb, struct genl_info *info)if (ret <0 ) goto sock_release; - ret =ovpn_peer_add (ovpn, peer); + ret =ovpn_peer_add (ovpn, peer, &req);if (ret <0 ) { NL_SET_ERR_MSG_FMT_MOD(info->extack, "cannot add new peer (id=%u) to hashtable: %d",
@@ -817,6 +818,7 @@ int ovpn_nl_peer_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb)int ovpn_nl_peer_del_doit (struct sk_buff *skb,struct genl_info *info) { +struct ovpn_nl_request req = { .info = info, .sk =NETLINK_CB (skb).sk };struct nlattr *attrs[OVPN_A_PEER_MAX +1 ];struct ovpn_priv *ovpn = info->user_ptr[0 ];struct ovpn_peer *peer;
@@ -844,7 +846,7 @@ int ovpn_nl_peer_del_doit(struct sk_buff *skb, struct genl_info *info) }netdev_dbg (ovpn->dev,"del peer %u\n" , peer->id); - ret =ovpn_peer_del (peer,OVPN_DEL_PEER_REASON_USERSPACE ); + ret =ovpn_peer_del (peer,OVPN_DEL_PEER_REASON_USERSPACE , &req);ovpn_peer_put (peer);return ret;
@@ -1180,17 +1182,27 @@ int ovpn_nl_key_del_doit(struct sk_buff *skb, struct genl_info *info)return 0 ; } +static int ovpn_nl_echo_filter (struct sock *sk,struct sk_buff *skb,void *data) +{ +return sk == data; +} +/** * ovpn_nl_peer_del_notify - notify userspace about peer being deleted * @peer: the peer being deleted +* @req: request context, or NULL for unsolicited notifications * * Return: 0 on success or a negative error code otherwise */ -int ovpn_nl_peer_del_notify (struct ovpn_peer *peer) +int ovpn_nl_peer_del_notify (struct ovpn_peer *peer, +struct ovpn_nl_request *req) { +struct genl_info *info = req ? req->info :NULL ; +struct net *net =dev_net (peer->ovpn->dev);struct sk_buff *msg;struct nlattr *attr;int ret = -EMSGSIZE ; +bool report;void *hdr; netdev_info(peer->ovpn->dev, "deleting peer with id %u, reason %d\n",
@@ -1221,8 +1233,20 @@ int ovpn_nl_peer_del_notify(struct ovpn_peer *peer)nla_nest_end (msg, attr);genlmsg_end (msg, hdr); -genlmsg_multicast_netns (&ovpn_nl_family,dev_net (peer->ovpn->dev), msg, -0 ,OVPN_NLGRP_PEERS ,GFP_ATOMIC ); + report = info &&nlmsg_report (info->nlhdr); + +if (report) { +nlmsg_hdr (msg)->nlmsg_pid = info->snd_portid; +nlmsg_hdr (msg)->nlmsg_seq = info->snd_seq; +/* the echo goes to the requester, the multicast to the device */ +skb_get (msg); + } +genlmsg_multicast_netns_filtered (&ovpn_nl_family, net, msg,0 , +OVPN_NLGRP_PEERS ,GFP_ATOMIC , + ovpn_nl_echo_filter, + report ? req->sk :NULL ); +if (report) +genlmsg_reply (msg, info);return 0 ;
drivers/net/ovpn/netlink.h +12 -1
@@ -9,10 +9,21 @@#ifndef _NET_OVPN_NETLINK_H_#define _NET_OVPN_NETLINK_H_ +/** +* struct ovpn_nl_request - context for request-triggered notifications +* @info: generic netlink request information +* @sk: requesting netlink socket +*/ +struct ovpn_nl_request { +struct genl_info *info; +struct sock *sk; +}; +int ovpn_nl_register (void );void ovpn_nl_unregister (void ); -int ovpn_nl_peer_del_notify (struct ovpn_peer *peer); +int ovpn_nl_peer_del_notify (struct ovpn_peer *peer, +struct ovpn_nl_request *req);int ovpn_nl_peer_float_notify (struct ovpn_peer *peer,const struct sockaddr_storage *ss);int ovpn_nl_key_swap_notify (struct ovpn_peer *peer,u8 key_id);
drivers/net/ovpn/peer.c +27 -16
156 lines not on this page · raw message
drivers/net/ovpn/peer.h +6 -2
@@ -17,6 +17,8 @@#include "socket.h" #include "stats.h" +struct ovpn_nl_request ; +/** * struct ovpn_peer - the main remote peer object * @ovpn: main openvpn instance this peer belongs to
@@ -139,8 +141,10 @@ static inline void ovpn_peer_put(struct ovpn_peer *peer) }struct ovpn_peer *ovpn_peer_new (struct ovpn_priv *ovpn,u32 id); -int ovpn_peer_add (struct ovpn_priv *ovpn,struct ovpn_peer *peer); -int ovpn_peer_del (struct ovpn_peer *peer,enum ovpn_del_peer_reason reason); +int ovpn_peer_add (struct ovpn_priv *ovpn,struct ovpn_peer *peer, +struct ovpn_nl_request *req); +int ovpn_peer_del (struct ovpn_peer *peer,enum ovpn_del_peer_reason reason, +struct ovpn_nl_request *req);void ovpn_peers_free (struct ovpn_priv *ovpn,struct sock *sock,enum ovpn_del_peer_reason reason);
drivers/net/ovpn/tcp.c +2 -2
@@ -502,7 +502,7 @@ static void ovpn_tcp_peer_del_work(struct work_struct *work) struct ovpn_peer *peer = container_of(work, struct ovpn_peer, tcp.defer_del_work); -ovpn_peer_del (peer,OVPN_DEL_PEER_REASON_TRANSPORT_ERROR ); +ovpn_peer_del (peer,OVPN_DEL_PEER_REASON_TRANSPORT_ERROR ,NULL );ovpn_peer_put (peer); }
@@ -594,7 +594,7 @@ static void ovpn_tcp_close(struct sock *sk, long timeout) }rcu_read_unlock (); -ovpn_peer_del (peer,OVPN_DEL_PEER_REASON_TRANSPORT_DISCONNECT ); +ovpn_peer_del (peer,OVPN_DEL_PEER_REASON_TRANSPORT_DISCONNECT ,NULL ); peer->tcp.sk_cb.prot->close (sk, timeout);ovpn_peer_put (peer); }
Signature · 8 lines
2.43.0 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel