Commit d9a4594e authored by Kishen Maloor's avatar Kishen Maloor Committed by David S. Miller

mptcp: netlink: Add MPTCP_PM_CMD_REMOVE

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: default avatarPaolo Abeni <pabeni@redhat.com>
Signed-off-by: default avatarKishen Maloor <kishen.maloor@intel.com>
Signed-off-by: default avatarMat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 9a0b3650
......@@ -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
};
......@@ -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
};
......
......@@ -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)
......@@ -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;
......@@ -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 = {
......
......@@ -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;
}
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment