Skip to content

Commit f070dbc

Browse files
committed
tgupdate: merge t/DO-NOT-MERGE-mptcp-use-kmalloc-on-kasan-build into t/DO-NOT-MERGE-mptcp-enabled-by-default base
2 parents 358a6a6 + 64bf1dc commit f070dbc

File tree

4 files changed

+124
-159
lines changed

4 files changed

+124
-159
lines changed

net/mptcp/pm.c

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "protocol.h"
1111

1212
#include "mib.h"
13+
#include "mptcp_pm_gen.h"
1314

1415
/* path manager command handlers */
1516

@@ -433,14 +434,62 @@ bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc)
433434
return mptcp_pm_nl_is_backup(msk, &skc_local);
434435
}
435436

436-
int mptcp_pm_get_addr(struct sk_buff *skb, struct genl_info *info)
437+
static int mptcp_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
438+
struct genl_info *info)
437439
{
438440
if (info->attrs[MPTCP_PM_ATTR_TOKEN])
439-
return mptcp_userspace_pm_get_addr(skb, info);
440-
return mptcp_pm_nl_get_addr(skb, info);
441+
return mptcp_userspace_pm_get_addr(id, addr, info);
442+
return mptcp_pm_nl_get_addr(id, addr, info);
441443
}
442444

443-
int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb)
445+
int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info)
446+
{
447+
struct mptcp_pm_addr_entry addr;
448+
struct nlattr *attr;
449+
struct sk_buff *msg;
450+
void *reply;
451+
int ret;
452+
453+
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR))
454+
return -EINVAL;
455+
456+
attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
457+
ret = mptcp_pm_parse_entry(attr, info, false, &addr);
458+
if (ret < 0)
459+
return ret;
460+
461+
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
462+
if (!msg)
463+
return -ENOMEM;
464+
465+
reply = genlmsg_put_reply(msg, info, &mptcp_genl_family, 0,
466+
info->genlhdr->cmd);
467+
if (!reply) {
468+
GENL_SET_ERR_MSG(info, "not enough space in Netlink message");
469+
ret = -EMSGSIZE;
470+
goto fail;
471+
}
472+
473+
ret = mptcp_pm_get_addr(addr.addr.id, &addr, info);
474+
if (ret) {
475+
NL_SET_ERR_MSG_ATTR(info->extack, attr, "address not found");
476+
goto fail;
477+
}
478+
479+
ret = mptcp_nl_fill_addr(msg, &addr);
480+
if (ret)
481+
goto fail;
482+
483+
genlmsg_end(msg, reply);
484+
ret = genlmsg_reply(msg, info);
485+
return ret;
486+
487+
fail:
488+
nlmsg_free(msg);
489+
return ret;
490+
}
491+
492+
static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb)
444493
{
445494
const struct genl_info *info = genl_info_dump(cb);
446495

@@ -449,11 +498,34 @@ int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb)
449498
return mptcp_pm_nl_dump_addr(msg, cb);
450499
}
451500

452-
int mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
501+
int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg,
502+
struct netlink_callback *cb)
503+
{
504+
return mptcp_pm_dump_addr(msg, cb);
505+
}
506+
507+
static int mptcp_pm_set_flags(struct genl_info *info)
453508
{
509+
struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, };
510+
struct nlattr *attr_loc;
511+
int ret = -EINVAL;
512+
513+
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR))
514+
return ret;
515+
516+
attr_loc = info->attrs[MPTCP_PM_ATTR_ADDR];
517+
ret = mptcp_pm_parse_entry(attr_loc, info, false, &loc);
518+
if (ret < 0)
519+
return ret;
520+
454521
if (info->attrs[MPTCP_PM_ATTR_TOKEN])
455-
return mptcp_userspace_pm_set_flags(skb, info);
456-
return mptcp_pm_nl_set_flags(skb, info);
522+
return mptcp_userspace_pm_set_flags(&loc, info);
523+
return mptcp_pm_nl_set_flags(&loc, info);
524+
}
525+
526+
int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info)
527+
{
528+
return mptcp_pm_set_flags(info);
457529
}
458530

459531
void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)

net/mptcp/pm_netlink.c

Lines changed: 22 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,65 +1773,24 @@ int mptcp_nl_fill_addr(struct sk_buff *skb,
17731773
return -EMSGSIZE;
17741774
}
17751775

1776-
int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info)
1776+
int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
1777+
struct genl_info *info)
17771778
{
17781779
struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
1779-
struct mptcp_pm_addr_entry addr, *entry;
1780-
struct sk_buff *msg;
1781-
struct nlattr *attr;
1782-
void *reply;
1783-
int ret;
1784-
1785-
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR))
1786-
return -EINVAL;
1787-
1788-
attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
1789-
ret = mptcp_pm_parse_entry(attr, info, false, &addr);
1790-
if (ret < 0)
1791-
return ret;
1792-
1793-
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1794-
if (!msg)
1795-
return -ENOMEM;
1796-
1797-
reply = genlmsg_put_reply(msg, info, &mptcp_genl_family, 0,
1798-
info->genlhdr->cmd);
1799-
if (!reply) {
1800-
GENL_SET_ERR_MSG(info, "not enough space in Netlink message");
1801-
ret = -EMSGSIZE;
1802-
goto fail;
1803-
}
1780+
struct mptcp_pm_addr_entry *entry;
1781+
int ret = -EINVAL;
18041782

18051783
rcu_read_lock();
1806-
entry = __lookup_addr_by_id(pernet, addr.addr.id);
1807-
if (!entry) {
1808-
NL_SET_ERR_MSG_ATTR(info->extack, attr, "address not found");
1809-
ret = -EINVAL;
1810-
goto unlock_fail;
1784+
entry = __lookup_addr_by_id(pernet, id);
1785+
if (entry) {
1786+
*addr = *entry;
1787+
ret = 0;
18111788
}
1812-
1813-
ret = mptcp_nl_fill_addr(msg, entry);
1814-
if (ret)
1815-
goto unlock_fail;
1816-
1817-
genlmsg_end(msg, reply);
1818-
ret = genlmsg_reply(msg, info);
1819-
rcu_read_unlock();
1820-
return ret;
1821-
1822-
unlock_fail:
18231789
rcu_read_unlock();
18241790

1825-
fail:
1826-
nlmsg_free(msg);
18271791
return ret;
18281792
}
18291793

1830-
int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info)
1831-
{
1832-
return mptcp_pm_get_addr(skb, info);
1833-
}
1834-
18351794
int mptcp_pm_nl_dump_addr(struct sk_buff *msg,
18361795
struct netlink_callback *cb)
18371796
{
@@ -1875,12 +1834,6 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg,
18751834
return msg->len;
18761835
}
18771836

1878-
int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg,
1879-
struct netlink_callback *cb)
1880-
{
1881-
return mptcp_pm_dump_addr(msg, cb);
1882-
}
1883-
18841837
static int parse_limit(struct genl_info *info, int id, unsigned int *limit)
18851838
{
18861839
struct nlattr *attr = info->attrs[id];
@@ -1998,70 +1951,56 @@ static int mptcp_nl_set_flags(struct net *net,
19981951
return ret;
19991952
}
20001953

2001-
int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info)
1954+
int mptcp_pm_nl_set_flags(struct mptcp_pm_addr_entry *local,
1955+
struct genl_info *info)
20021956
{
2003-
struct mptcp_pm_addr_entry addr = { .addr = { .family = AF_UNSPEC }, };
1957+
struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
20041958
u8 changed, mask = MPTCP_PM_ADDR_FLAG_BACKUP |
20051959
MPTCP_PM_ADDR_FLAG_FULLMESH;
2006-
struct net *net = sock_net(skb->sk);
1960+
struct net *net = genl_info_net(info);
20071961
struct mptcp_pm_addr_entry *entry;
20081962
struct pm_nl_pernet *pernet;
2009-
struct nlattr *attr;
20101963
u8 lookup_by_id = 0;
20111964
u8 bkup = 0;
2012-
int ret;
2013-
2014-
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR))
2015-
return -EINVAL;
20161965

20171966
pernet = pm_nl_get_pernet(net);
20181967

2019-
attr = info->attrs[MPTCP_PM_ATTR_ADDR];
2020-
ret = mptcp_pm_parse_entry(attr, info, false, &addr);
2021-
if (ret < 0)
2022-
return ret;
2023-
2024-
if (addr.addr.family == AF_UNSPEC) {
1968+
if (local->addr.family == AF_UNSPEC) {
20251969
lookup_by_id = 1;
2026-
if (!addr.addr.id) {
1970+
if (!local->addr.id) {
20271971
NL_SET_ERR_MSG_ATTR(info->extack, attr,
20281972
"missing address ID");
20291973
return -EOPNOTSUPP;
20301974
}
20311975
}
20321976

2033-
if (addr.flags & MPTCP_PM_ADDR_FLAG_BACKUP)
1977+
if (local->flags & MPTCP_PM_ADDR_FLAG_BACKUP)
20341978
bkup = 1;
20351979

20361980
spin_lock_bh(&pernet->lock);
2037-
entry = lookup_by_id ? __lookup_addr_by_id(pernet, addr.addr.id) :
2038-
__lookup_addr(pernet, &addr.addr);
1981+
entry = lookup_by_id ? __lookup_addr_by_id(pernet, local->addr.id) :
1982+
__lookup_addr(pernet, &local->addr);
20391983
if (!entry) {
20401984
spin_unlock_bh(&pernet->lock);
20411985
NL_SET_ERR_MSG_ATTR(info->extack, attr, "address not found");
20421986
return -EINVAL;
20431987
}
2044-
if ((addr.flags & MPTCP_PM_ADDR_FLAG_FULLMESH) &&
1988+
if ((local->flags & MPTCP_PM_ADDR_FLAG_FULLMESH) &&
20451989
(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
20461990
spin_unlock_bh(&pernet->lock);
20471991
NL_SET_ERR_MSG_ATTR(info->extack, attr, "invalid addr flags");
20481992
return -EINVAL;
20491993
}
20501994

2051-
changed = (addr.flags ^ entry->flags) & mask;
2052-
entry->flags = (entry->flags & ~mask) | (addr.flags & mask);
2053-
addr = *entry;
1995+
changed = (local->flags ^ entry->flags) & mask;
1996+
entry->flags = (entry->flags & ~mask) | (local->flags & mask);
1997+
*local = *entry;
20541998
spin_unlock_bh(&pernet->lock);
20551999

2056-
mptcp_nl_set_flags(net, &addr.addr, bkup, changed);
2000+
mptcp_nl_set_flags(net, &local->addr, bkup, changed);
20572001
return 0;
20582002
}
20592003

2060-
int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info)
2061-
{
2062-
return mptcp_pm_set_flags(skb, info);
2063-
}
2064-
20652004
static void mptcp_nl_mcast_send(struct net *net, struct sk_buff *nlskb, gfp_t gfp)
20662005
{
20672006
genlmsg_multicast_netns(&mptcp_genl_family, net,

0 commit comments

Comments
 (0)