This change adds a MPTCP netlink interface command for issuing
ADD_ADDR advertisements over the chosen MPTCP connection from a
userspace path manager.
The command requires the following parameters:
{token, {loc_id, family, saddr4 | saddr6 [, sport]} }.
Signed-off-by: Kishen Maloor <kishen.maloor@intel.com>
---
include/uapi/linux/mptcp.h | 2 ++
net/mptcp/pm_netlink.c | 45 ++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+)
diff --git a/include/uapi/linux/mptcp.h b/include/uapi/linux/mptcp.h
index c8cc46f80a16..e22e891016e3 100644
--- a/include/uapi/linux/mptcp.h
+++ b/include/uapi/linux/mptcp.h
@@ -55,6 +55,7 @@ enum {
MPTCP_PM_ATTR_ADDR, /* nested address */
MPTCP_PM_ATTR_RCV_ADD_ADDRS, /* u32 */
MPTCP_PM_ATTR_SUBFLOWS, /* u32 */
+ MPTCP_PM_ATTR_TOKEN, /* u32 */
__MPTCP_PM_ATTR_MAX
};
@@ -92,6 +93,7 @@ enum {
MPTCP_PM_CMD_SET_LIMITS,
MPTCP_PM_CMD_GET_LIMITS,
MPTCP_PM_CMD_SET_FLAGS,
+ MPTCP_PM_CMD_ANNOUNCE,
__MPTCP_PM_CMD_AFTER_LAST
};
diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 2a3589b67768..1b41bbc70529 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -1028,6 +1028,7 @@ static const struct nla_policy mptcp_pm_policy[MPTCP_PM_ATTR_MAX + 1] = {
NLA_POLICY_NESTED(mptcp_pm_addr_policy),
[MPTCP_PM_ATTR_RCV_ADD_ADDRS] = { .type = NLA_U32, },
[MPTCP_PM_ATTR_SUBFLOWS] = { .type = NLA_U32, },
+ [MPTCP_PM_ATTR_TOKEN] = { .type = NLA_U32, },
};
void mptcp_pm_nl_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)
@@ -1735,6 +1736,45 @@ static int mptcp_nl_addr_backup(struct net *net,
return ret;
}
+static int mptcp_nl_cmd_announce(struct sk_buff *skb, struct genl_info *info)
+{
+ struct nlattr *addr = info->attrs[MPTCP_PM_ATTR_ADDR],
+ *token = info->attrs[MPTCP_PM_ATTR_TOKEN];
+ struct mptcp_sock *msk;
+ struct mptcp_pm_addr_entry _addr;
+ u32 _token;
+ int err;
+
+ if (!addr || !token) {
+ GENL_SET_ERR_MSG(info, "missing announce info");
+ return -EINVAL;
+ }
+
+ err = mptcp_pm_parse_addr(addr, info, true, &_addr);
+ if (err < 0)
+ return err;
+
+ _token = nla_get_u32(token);
+
+ msk = mptcp_token_get_sock(sock_net(skb->sk), _token);
+ if (!msk) {
+ NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token");
+ return -EINVAL;
+ }
+
+ lock_sock((struct sock *)msk);
+ spin_lock_bh(&msk->pm.lock);
+
+ msk->pm.userspace = true;
+ mptcp_pm_announce_addr(msk, &_addr.addr, false);
+ mptcp_pm_nl_addr_send_ack(msk);
+
+ spin_unlock_bh(&msk->pm.lock);
+ release_sock((struct sock *)msk);
+
+ return 0;
+}
+
static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info)
{
struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
@@ -2067,6 +2107,11 @@ static const struct genl_small_ops mptcp_pm_ops[] = {
.doit = mptcp_nl_cmd_set_flags,
.flags = GENL_ADMIN_PERM,
},
+ {
+ .cmd = MPTCP_PM_CMD_ANNOUNCE,
+ .doit = mptcp_nl_cmd_announce,
+ .flags = GENL_ADMIN_PERM,
+ },
};
static struct genl_family mptcp_genl_family __ro_after_init = {
--
2.31.1
On Thu, 2021-10-07 at 00:36 -0400, Kishen Maloor wrote:
> This change adds a MPTCP netlink interface command for issuing
> ADD_ADDR advertisements over the chosen MPTCP connection from a
> userspace path manager.
>
> The command requires the following parameters:
> {token, {loc_id, family, saddr4 | saddr6 [, sport]} }.
>
> Signed-off-by: Kishen Maloor <kishen.maloor@intel.com>
> ---
> include/uapi/linux/mptcp.h | 2 ++
> net/mptcp/pm_netlink.c | 45 ++++++++++++++++++++++++++++++++++++++
> 2 files changed, 47 insertions(+)
>
> diff --git a/include/uapi/linux/mptcp.h b/include/uapi/linux/mptcp.h
> index c8cc46f80a16..e22e891016e3 100644
> --- a/include/uapi/linux/mptcp.h
> +++ b/include/uapi/linux/mptcp.h
> @@ -55,6 +55,7 @@ enum {
> MPTCP_PM_ATTR_ADDR, /* nested address */
> MPTCP_PM_ATTR_RCV_ADD_ADDRS, /* u32 */
> MPTCP_PM_ATTR_SUBFLOWS, /* u32 */
> + MPTCP_PM_ATTR_TOKEN, /* u32 */
>
> __MPTCP_PM_ATTR_MAX
> };
> @@ -92,6 +93,7 @@ enum {
> MPTCP_PM_CMD_SET_LIMITS,
> MPTCP_PM_CMD_GET_LIMITS,
> MPTCP_PM_CMD_SET_FLAGS,
> + MPTCP_PM_CMD_ANNOUNCE,
>
> __MPTCP_PM_CMD_AFTER_LAST
> };
> diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
> index 2a3589b67768..1b41bbc70529 100644
> --- a/net/mptcp/pm_netlink.c
> +++ b/net/mptcp/pm_netlink.c
> @@ -1028,6 +1028,7 @@ static const struct nla_policy mptcp_pm_policy[MPTCP_PM_ATTR_MAX + 1] = {
> NLA_POLICY_NESTED(mptcp_pm_addr_policy),
> [MPTCP_PM_ATTR_RCV_ADD_ADDRS] = { .type = NLA_U32, },
> [MPTCP_PM_ATTR_SUBFLOWS] = { .type = NLA_U32, },
> + [MPTCP_PM_ATTR_TOKEN] = { .type = NLA_U32, },
> };
>
> void mptcp_pm_nl_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)
> @@ -1735,6 +1736,45 @@ static int mptcp_nl_addr_backup(struct net *net,
> return ret;
> }
>
> +static int mptcp_nl_cmd_announce(struct sk_buff *skb, struct genl_info *info)
> +{
> + struct nlattr *addr = info->attrs[MPTCP_PM_ATTR_ADDR],
> + *token = info->attrs[MPTCP_PM_ATTR_TOKEN];
> + struct mptcp_sock *msk;
> + struct mptcp_pm_addr_entry _addr;
The above should be change to respect the reverse xmas tree order, and
it's better to split the 2 assignement in separate definition:
struct nlattr *addr = info->attrs[MPTCP_PM_ATTR_ADDR];
struct nlattr *token = /...
> + u32 _token;
> + int err;
> +
> + if (!addr || !token) {
> + GENL_SET_ERR_MSG(info, "missing announce info");
> + return -EINVAL;
> + }
> +
> + err = mptcp_pm_parse_addr(addr, info, true, &_addr);
> + if (err < 0)
> + return err;
> +
> + _token = nla_get_u32(token);
I'm wondering if a new helper 'mptcp_pm_parse_addr_ex', additionally
parsing the code would help.
Cheers,
Paolo
Hi Kishen,
On 07/10/2021 06:36, Kishen Maloor wrote:
> This change adds a MPTCP netlink interface command for issuing
> ADD_ADDR advertisements over the chosen MPTCP connection from a
> userspace path manager.
>
> The command requires the following parameters:
> {token, {loc_id, family, saddr4 | saddr6 [, sport]} }.
Thank you for looking at that!
(...)
> diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
> index 2a3589b67768..1b41bbc70529 100644
> --- a/net/mptcp/pm_netlink.c
> +++ b/net/mptcp/pm_netlink.c
(...)
> +static int mptcp_nl_cmd_announce(struct sk_buff *skb, struct genl_info *info)
> +{
> + struct nlattr *addr = info->attrs[MPTCP_PM_ATTR_ADDR],
> + *token = info->attrs[MPTCP_PM_ATTR_TOKEN];
> + struct mptcp_sock *msk;
> + struct mptcp_pm_addr_entry _addr;
> + u32 _token;
Small detail but maybe clearer to avoid using variable with almost the
same name: 'addr' vs '_addr' and 'token', vs '_token'. What about
'addr_attr' and 'token_attr'?
Same in 'mptcp_nl_cmd_remove()'.
> + int err;
> +
> + if (!addr || !token) {
> + GENL_SET_ERR_MSG(info, "missing announce info");
> + return -EINVAL;
> + }
> +
> + err = mptcp_pm_parse_addr(addr, info, true, &_addr);
> + if (err < 0)
> + return err;
> +
> + _token = nla_get_u32(token);
> +
> + msk = mptcp_token_get_sock(sock_net(skb->sk), _token);
> + if (!msk) {
> + NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token");
> + return -EINVAL;
Should we try to return different err code per kind of error? Or the
error message is enough?
For example, we could return -ENOTCONN or -ENOKEY even if the string
linked to it is not 100% accurate? ("Transport endpoint is not
connected" and "Required key not available").
Cheers,
Matt
--
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
© 2016 - 2026 Red Hat, Inc.