lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZIMqp+uJ9SUIHvR5@lincoln>
Date:   Fri, 9 Jun 2023 15:35:35 +0200
From:   Larysa Zaremba <larysa.zaremba@...el.com>
To:     Matthieu Baerts <matthieu.baerts@...sares.net>
CC:     <mptcp@...ts.linux.dev>, Mat Martineau <martineau@...nel.org>,
        "David S. Miller" <davem@...emloft.net>,
        Eric Dumazet <edumazet@...gle.com>,
        "Jakub Kicinski" <kuba@...nel.org>,
        Paolo Abeni <pabeni@...hat.com>, <netdev@...r.kernel.org>,
        <linux-kernel@...r.kernel.org>,
        Geliang Tang <geliang.tang@...e.com>
Subject: Re: [PATCH net-next 4/4] mptcp: unify pm set_flags interfaces

On Thu, Jun 08, 2023 at 03:20:52PM +0200, Matthieu Baerts wrote:
> From: Geliang Tang <geliang.tang@...e.com>
> 
> This patch unifies the three PM set_flags() interfaces:
> 
> mptcp_pm_nl_set_flags() in mptcp/pm_netlink.c for the in-kernel PM and
> mptcp_userspace_pm_set_flags() in mptcp/pm_userspace.c for the
> userspace PM.
> 
> They'll be switched in the common PM infterface mptcp_pm_set_flags() in
> mptcp/pm.c based on whether token is NULL or not.
> 
> Signed-off-by: Geliang Tang <geliang.tang@...e.com>
> Reviewed-by: Matthieu Baerts <matthieu.baerts@...sares.net>
> Signed-off-by: Matthieu Baerts <matthieu.baerts@...sares.net>

Reviewed-by: Larysa Zaremba <larysa.zaremba@...el.com>

> ---
>  net/mptcp/pm.c         |  9 +++++++
>  net/mptcp/pm_netlink.c | 70 +++++++++++++++++++++++++++-----------------------
>  net/mptcp/protocol.h   |  4 +++
>  3 files changed, 51 insertions(+), 32 deletions(-)
> 
> diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
> index 2d04598dde05..36bf9196168b 100644
> --- a/net/mptcp/pm.c
> +++ b/net/mptcp/pm.c
> @@ -433,6 +433,15 @@ int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id
>  	return mptcp_pm_nl_get_flags_and_ifindex_by_id(msk, id, flags, ifindex);
>  }
>  
> +int mptcp_pm_set_flags(struct net *net, struct nlattr *token,
> +		       struct mptcp_pm_addr_entry *loc,
> +		       struct mptcp_pm_addr_entry *rem, u8 bkup)
> +{
> +	if (token)
> +		return mptcp_userspace_pm_set_flags(net, token, loc, rem, bkup);
> +	return mptcp_pm_nl_set_flags(net, loc, bkup);
> +}
> +
>  void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)
>  {
>  	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
> diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
> index e8b32d369f11..13be9205d36d 100644
> --- a/net/mptcp/pm_netlink.c
> +++ b/net/mptcp/pm_netlink.c
> @@ -1864,18 +1864,50 @@ static int mptcp_nl_set_flags(struct net *net,
>  	return ret;
>  }
>  
> +int mptcp_pm_nl_set_flags(struct net *net, struct mptcp_pm_addr_entry *addr, u8 bkup)
> +{
> +	struct pm_nl_pernet *pernet = pm_nl_get_pernet(net);
> +	u8 changed, mask = MPTCP_PM_ADDR_FLAG_BACKUP |
> +			   MPTCP_PM_ADDR_FLAG_FULLMESH;
> +	struct mptcp_pm_addr_entry *entry;
> +	u8 lookup_by_id = 0;
> +
> +	if (addr->addr.family == AF_UNSPEC) {
> +		lookup_by_id = 1;
> +		if (!addr->addr.id)
> +			return -EOPNOTSUPP;
> +	}
> +
> +	spin_lock_bh(&pernet->lock);
> +	entry = __lookup_addr(pernet, &addr->addr, lookup_by_id);
> +	if (!entry) {
> +		spin_unlock_bh(&pernet->lock);
> +		return -EINVAL;
> +	}
> +	if ((addr->flags & MPTCP_PM_ADDR_FLAG_FULLMESH) &&
> +	    (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
> +		spin_unlock_bh(&pernet->lock);
> +		return -EINVAL;
> +	}
> +
> +	changed = (addr->flags ^ entry->flags) & mask;
> +	entry->flags = (entry->flags & ~mask) | (addr->flags & mask);
> +	*addr = *entry;
> +	spin_unlock_bh(&pernet->lock);
> +
> +	mptcp_nl_set_flags(net, &addr->addr, bkup, changed);
> +	return 0;
> +}
> +
>  static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info)
>  {
> -	struct mptcp_pm_addr_entry addr = { .addr = { .family = AF_UNSPEC }, }, *entry;
>  	struct mptcp_pm_addr_entry remote = { .addr = { .family = AF_UNSPEC }, };
> +	struct mptcp_pm_addr_entry addr = { .addr = { .family = AF_UNSPEC }, };
>  	struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
>  	struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN];
>  	struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
> -	struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
> -	u8 changed, mask = MPTCP_PM_ADDR_FLAG_BACKUP |
> -			   MPTCP_PM_ADDR_FLAG_FULLMESH;
>  	struct net *net = sock_net(skb->sk);
> -	u8 bkup = 0, lookup_by_id = 0;
> +	u8 bkup = 0;
>  	int ret;
>  
>  	ret = mptcp_pm_parse_entry(attr, info, false, &addr);
> @@ -1890,34 +1922,8 @@ static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info)
>  
>  	if (addr.flags & MPTCP_PM_ADDR_FLAG_BACKUP)
>  		bkup = 1;
> -	if (addr.addr.family == AF_UNSPEC) {
> -		lookup_by_id = 1;
> -		if (!addr.addr.id)
> -			return -EOPNOTSUPP;
> -	}
>  
> -	if (token)
> -		return mptcp_userspace_pm_set_flags(net, token, &addr, &remote, bkup);
> -
> -	spin_lock_bh(&pernet->lock);
> -	entry = __lookup_addr(pernet, &addr.addr, lookup_by_id);
> -	if (!entry) {
> -		spin_unlock_bh(&pernet->lock);
> -		return -EINVAL;
> -	}
> -	if ((addr.flags & MPTCP_PM_ADDR_FLAG_FULLMESH) &&
> -	    (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
> -		spin_unlock_bh(&pernet->lock);
> -		return -EINVAL;
> -	}
> -
> -	changed = (addr.flags ^ entry->flags) & mask;
> -	entry->flags = (entry->flags & ~mask) | (addr.flags & mask);
> -	addr = *entry;
> -	spin_unlock_bh(&pernet->lock);
> -
> -	mptcp_nl_set_flags(net, &addr.addr, bkup, changed);
> -	return 0;
> +	return mptcp_pm_set_flags(net, token, &addr, &remote, bkup);
>  }
>  
>  static void mptcp_nl_mcast_send(struct net *net, struct sk_buff *nlskb, gfp_t gfp)
> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> index 607cbd2ccb98..1e7465bb66d5 100644
> --- a/net/mptcp/protocol.h
> +++ b/net/mptcp/protocol.h
> @@ -827,6 +827,10 @@ int mptcp_pm_nl_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int
>  int mptcp_userspace_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk,
>  						   unsigned int id,
>  						   u8 *flags, int *ifindex);
> +int mptcp_pm_set_flags(struct net *net, struct nlattr *token,
> +		       struct mptcp_pm_addr_entry *loc,
> +		       struct mptcp_pm_addr_entry *rem, u8 bkup);
> +int mptcp_pm_nl_set_flags(struct net *net, struct mptcp_pm_addr_entry *addr, u8 bkup);
>  int mptcp_userspace_pm_set_flags(struct net *net, struct nlattr *token,
>  				 struct mptcp_pm_addr_entry *loc,
>  				 struct mptcp_pm_addr_entry *rem, u8 bkup);
> 
> -- 
> 2.40.1
> 
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ