Skip to content

Commit

Permalink
mptcp: netlink: Add MPTCP_PM_CMD_REMOVE
Browse files Browse the repository at this point in the history
This change adds a MPTCP netlink command for issuing a
REMOVE_ADDR signal for an address over the chosen MPTCP
connection from a userspace path manager.

The command requires the following parameters: {token, loc_id}.

Acked-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Kishen Maloor <kishen.maloor@intel.com>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
kmaloor authored and davem330 committed May 4, 2022
1 parent 9a0b365 commit d9a4594
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/uapi/linux/mptcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ enum {
MPTCP_PM_ATTR_RCV_ADD_ADDRS, /* u32 */
MPTCP_PM_ATTR_SUBFLOWS, /* u32 */
MPTCP_PM_ATTR_TOKEN, /* u32 */
MPTCP_PM_ATTR_LOC_ID, /* u8 */

__MPTCP_PM_ATTR_MAX
};
Expand Down Expand Up @@ -95,6 +96,7 @@ enum {
MPTCP_PM_CMD_GET_LIMITS,
MPTCP_PM_CMD_SET_FLAGS,
MPTCP_PM_CMD_ANNOUNCE,
MPTCP_PM_CMD_REMOVE,

__MPTCP_PM_CMD_AFTER_LAST
};
Expand Down
10 changes: 8 additions & 2 deletions net/mptcp/pm_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,7 @@ static const struct nla_policy mptcp_pm_policy[MPTCP_PM_ATTR_MAX + 1] = {
[MPTCP_PM_ATTR_RCV_ADD_ADDRS] = { .type = NLA_U32, },
[MPTCP_PM_ATTR_SUBFLOWS] = { .type = NLA_U32, },
[MPTCP_PM_ATTR_TOKEN] = { .type = NLA_U32, },
[MPTCP_PM_ATTR_LOC_ID] = { .type = NLA_U8, },
};

void mptcp_pm_nl_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)
Expand Down Expand Up @@ -1504,8 +1505,8 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info)
return ret;
}

static void mptcp_pm_remove_addrs_and_subflows(struct mptcp_sock *msk,
struct list_head *rm_list)
void mptcp_pm_remove_addrs_and_subflows(struct mptcp_sock *msk,
struct list_head *rm_list)
{
struct mptcp_rm_list alist = { .nr = 0 }, slist = { .nr = 0 };
struct mptcp_pm_addr_entry *entry;
Expand Down Expand Up @@ -2204,6 +2205,11 @@ static const struct genl_small_ops mptcp_pm_ops[] = {
.doit = mptcp_nl_cmd_announce,
.flags = GENL_ADMIN_PERM,
},
{
.cmd = MPTCP_PM_CMD_REMOVE,
.doit = mptcp_nl_cmd_remove,
.flags = GENL_ADMIN_PERM,
},
};

static struct genl_family mptcp_genl_family __ro_after_init = {
Expand Down
62 changes: 62 additions & 0 deletions net/mptcp/pm_userspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,65 @@ int mptcp_nl_cmd_announce(struct sk_buff *skb, struct genl_info *info)
sock_put((struct sock *)msk);
return err;
}

int mptcp_nl_cmd_remove(struct sk_buff *skb, struct genl_info *info)
{
struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN];
struct nlattr *id = info->attrs[MPTCP_PM_ATTR_LOC_ID];
struct mptcp_pm_addr_entry *match = NULL;
struct mptcp_pm_addr_entry *entry;
struct mptcp_sock *msk;
LIST_HEAD(free_list);
int err = -EINVAL;
u32 token_val;
u8 id_val;

if (!id || !token) {
GENL_SET_ERR_MSG(info, "missing required inputs");
return err;
}

id_val = nla_get_u8(id);
token_val = nla_get_u32(token);

msk = mptcp_token_get_sock(sock_net(skb->sk), token_val);
if (!msk) {
NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token");
return err;
}

if (!mptcp_pm_is_userspace(msk)) {
GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected");
goto remove_err;
}

lock_sock((struct sock *)msk);

list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) {
if (entry->addr.id == id_val) {
match = entry;
break;
}
}

if (!match) {
GENL_SET_ERR_MSG(info, "address with specified id not found");
release_sock((struct sock *)msk);
goto remove_err;
}

list_move(&match->list, &free_list);

mptcp_pm_remove_addrs_and_subflows(msk, &free_list);

release_sock((struct sock *)msk);

list_for_each_entry_safe(match, entry, &free_list, list) {
sock_kfree_s((struct sock *)msk, match, sizeof(*match));
}

err = 0;
remove_err:
sock_put((struct sock *)msk);
return err;
}
4 changes: 4 additions & 0 deletions net/mptcp/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -801,10 +801,14 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,
bool echo);
int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_list);
int mptcp_pm_remove_subflow(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_list);
void mptcp_pm_remove_addrs_and_subflows(struct mptcp_sock *msk,
struct list_head *rm_list);

int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk,
struct mptcp_pm_addr_entry *entry);
void mptcp_free_local_addr_list(struct mptcp_sock *msk);
int mptcp_nl_cmd_announce(struct sk_buff *skb, struct genl_info *info);
int mptcp_nl_cmd_remove(struct sk_buff *skb, struct genl_info *info);

void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk,
const struct sock *ssk, gfp_t gfp);
Expand Down

0 comments on commit d9a4594

Please sign in to comment.