mptcp: add set_flags command in PM netlink
This patch added a new command MPTCP_PM_CMD_SET_FLAGS in PM netlink: In mptcp_nl_cmd_set_flags, parse the input address, get the backup value according to whether the address's FLAG_BACKUP flag is set from the user-space. Then check whether this address had been added in the local address list. If it had been, then call mptcp_nl_addr_backup to deal with this address. In mptcp_nl_addr_backup, traverse all the existing msk sockets to find the relevant sockets, and call mptcp_pm_nl_mp_prio_send_ack to send out a MP_PRIO ACK packet. Finally in mptcp_nl_cmd_set_flags, set or clear the address's FLAG_BACKUP flag. Signed-off-by: Geliang Tang <geliangtang@gmail.com> Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
40453a5c61
commit
0f9f696a50
|
@ -82,6 +82,7 @@ enum {
|
|||
MPTCP_PM_CMD_FLUSH_ADDRS,
|
||||
MPTCP_PM_CMD_SET_LIMITS,
|
||||
MPTCP_PM_CMD_GET_LIMITS,
|
||||
MPTCP_PM_CMD_SET_FLAGS,
|
||||
|
||||
__MPTCP_PM_CMD_AFTER_LAST
|
||||
};
|
||||
|
|
|
@ -1164,6 +1164,66 @@ fail:
|
|||
return -EMSGSIZE;
|
||||
}
|
||||
|
||||
static int mptcp_nl_addr_backup(struct net *net,
|
||||
struct mptcp_addr_info *addr,
|
||||
u8 bkup)
|
||||
{
|
||||
long s_slot = 0, s_num = 0;
|
||||
struct mptcp_sock *msk;
|
||||
int ret = -EINVAL;
|
||||
|
||||
while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num)) != NULL) {
|
||||
struct sock *sk = (struct sock *)msk;
|
||||
|
||||
if (list_empty(&msk->conn_list))
|
||||
goto next;
|
||||
|
||||
lock_sock(sk);
|
||||
spin_lock_bh(&msk->pm.lock);
|
||||
ret = mptcp_pm_nl_mp_prio_send_ack(msk, addr, bkup);
|
||||
spin_unlock_bh(&msk->pm.lock);
|
||||
release_sock(sk);
|
||||
|
||||
next:
|
||||
sock_put(sk);
|
||||
cond_resched();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info)
|
||||
{
|
||||
struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
|
||||
struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
|
||||
struct mptcp_pm_addr_entry addr, *entry;
|
||||
struct net *net = sock_net(skb->sk);
|
||||
u8 bkup = 0;
|
||||
int ret;
|
||||
|
||||
ret = mptcp_pm_parse_addr(attr, info, true, &addr);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
if (addr.addr.flags & MPTCP_PM_ADDR_FLAG_BACKUP)
|
||||
bkup = 1;
|
||||
|
||||
list_for_each_entry(entry, &pernet->local_addr_list, list) {
|
||||
if (addresses_equal(&entry->addr, &addr.addr, true)) {
|
||||
ret = mptcp_nl_addr_backup(net, &entry->addr, bkup);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (bkup)
|
||||
entry->addr.flags |= MPTCP_PM_ADDR_FLAG_BACKUP;
|
||||
else
|
||||
entry->addr.flags &= ~MPTCP_PM_ADDR_FLAG_BACKUP;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct genl_small_ops mptcp_pm_ops[] = {
|
||||
{
|
||||
.cmd = MPTCP_PM_CMD_ADD_ADDR,
|
||||
|
@ -1194,6 +1254,11 @@ static const struct genl_small_ops mptcp_pm_ops[] = {
|
|||
.cmd = MPTCP_PM_CMD_GET_LIMITS,
|
||||
.doit = mptcp_nl_cmd_get_limits,
|
||||
},
|
||||
{
|
||||
.cmd = MPTCP_PM_CMD_SET_FLAGS,
|
||||
.doit = mptcp_nl_cmd_set_flags,
|
||||
.flags = GENL_ADMIN_PERM,
|
||||
},
|
||||
};
|
||||
|
||||
static struct genl_family mptcp_genl_family __ro_after_init = {
|
||||
|
|
Loading…
Reference in New Issue