Skip to content

Commit 91ea153

Browse files
Geliang Tangintel-lab-lkp
authored andcommitted
mptcp: reuse sending nlmsg code in dump_addr
With the help of get_addr(), we can modify dump_addr() interfaces to reuse send_nlmsg code between the netlink PM and userspace PM. The current dump_addr() flow looks like this: lock(); for_each_entry(entry) send_nlmsg(entry); unlock(); After holding the lock, get every entry by walking the address list, send each one looply, and finally release the lock. This set changes the process by copying the address list to an id bitmap while holding the lock, then release the lock immediately. After that, without locking, walking the copied id bitmap to get every copy of entry by using get_addr(), and send each one looply: lock(); for_each_entry(entry) set_bit(bitmap); unlock(); for_each_bit(bitmap) { copy = get_addr(); send_nlmsg(copy); } With this, we can reuse the send_nlmsg() code in dump_addr() interfaces between the netlink PM and userspace PM. They only need to implement their own dump_addr() interfaces to hold the different locks, copy the different address lists to an id bitmap, then release the locks. Signed-off-by: Geliang Tang <[email protected]>
1 parent 4009531 commit 91ea153

File tree

4 files changed

+59
-66
lines changed

4 files changed

+59
-66
lines changed

net/mptcp/pm.c

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,20 +485,55 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info)
485485
return ret;
486486
}
487487

488-
static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb,
488+
static int mptcp_pm_dump_addr(mptcp_pm_addr_id_bitmap_t *bitmap,
489489
const struct genl_info *info)
490490
{
491491
if (info->attrs[MPTCP_PM_ATTR_TOKEN])
492-
return mptcp_userspace_pm_dump_addr(msg, cb, info);
493-
return mptcp_pm_nl_dump_addr(msg, cb, info);
492+
return mptcp_userspace_pm_dump_addr(bitmap, info);
493+
return mptcp_pm_nl_dump_addr(bitmap, info);
494494
}
495495

496496
int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg,
497497
struct netlink_callback *cb)
498498
{
499499
const struct genl_info *info = genl_info_dump(cb);
500+
mptcp_pm_addr_id_bitmap_t *bitmap;
501+
struct mptcp_pm_addr_entry entry;
502+
int id = cb->args[0];
503+
void *hdr;
504+
int i;
505+
506+
bitmap = (mptcp_pm_addr_id_bitmap_t *)cb->ctx;
507+
508+
mptcp_pm_dump_addr(bitmap, info);
509+
510+
for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) {
511+
if (test_bit(i, bitmap->map)) {
512+
if (mptcp_pm_get_addr(i, &entry, info))
513+
break;
514+
515+
if (id && entry.addr.id <= id)
516+
continue;
517+
518+
hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid,
519+
cb->nlh->nlmsg_seq,
520+
&mptcp_genl_family, NLM_F_MULTI,
521+
MPTCP_PM_CMD_GET_ADDR);
522+
if (!hdr)
523+
break;
524+
525+
if (mptcp_nl_fill_addr(msg, &entry) < 0) {
526+
genlmsg_cancel(msg, hdr);
527+
break;
528+
}
529+
530+
id = entry.addr.id;
531+
genlmsg_end(msg, hdr);
532+
}
533+
}
500534

501-
return mptcp_pm_dump_addr(msg, cb, info);
535+
cb->args[0] = id;
536+
return msg->len;
502537
}
503538

504539
static int mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info)

net/mptcp/pm_netlink.c

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,48 +1783,19 @@ int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
17831783
return ret;
17841784
}
17851785

1786-
int mptcp_pm_nl_dump_addr(struct sk_buff *msg,
1787-
struct netlink_callback *cb,
1786+
int mptcp_pm_nl_dump_addr(mptcp_pm_addr_id_bitmap_t *bitmap,
17881787
const struct genl_info *info)
17891788
{
17901789
struct net *net = genl_info_net(info);
1791-
struct mptcp_pm_addr_entry *entry;
17921790
struct pm_nl_pernet *pernet;
1793-
int id = cb->args[0];
1794-
void *hdr;
1795-
int i;
17961791

17971792
pernet = pm_nl_get_pernet(net);
17981793

17991794
rcu_read_lock();
1800-
for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) {
1801-
if (test_bit(i, pernet->id_bitmap)) {
1802-
entry = __lookup_addr_by_id(pernet, i);
1803-
if (!entry)
1804-
break;
1805-
1806-
if (entry->addr.id <= id)
1807-
continue;
1808-
1809-
hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid,
1810-
cb->nlh->nlmsg_seq, &mptcp_genl_family,
1811-
NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR);
1812-
if (!hdr)
1813-
break;
1814-
1815-
if (mptcp_nl_fill_addr(msg, entry) < 0) {
1816-
genlmsg_cancel(msg, hdr);
1817-
break;
1818-
}
1819-
1820-
id = entry->addr.id;
1821-
genlmsg_end(msg, hdr);
1822-
}
1823-
}
1795+
bitmap_copy(bitmap->map, pernet->id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
18241796
rcu_read_unlock();
18251797

1826-
cb->args[0] = id;
1827-
return msg->len;
1798+
return 0;
18281799
}
18291800

18301801
static int parse_limit(struct genl_info *info, int id, unsigned int *limit)

net/mptcp/pm_userspace.c

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -614,18 +614,25 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
614614
return ret;
615615
}
616616

617-
int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,
618-
struct netlink_callback *cb,
619-
const struct genl_info *info)
617+
static int mptcp_userspace_pm_reset_bitmap(struct mptcp_sock *msk,
618+
mptcp_pm_addr_id_bitmap_t *bitmap)
620619
{
621-
mptcp_pm_addr_id_bitmap_t *bitmap;
622620
struct mptcp_pm_addr_entry *entry;
621+
622+
bitmap_zero(bitmap->map, MPTCP_PM_MAX_ADDR_ID + 1);
623+
624+
mptcp_for_each_userspace_pm_addr(msk, entry)
625+
__set_bit(entry->addr.id, bitmap->map);
626+
627+
return 0;
628+
}
629+
630+
int mptcp_userspace_pm_dump_addr(mptcp_pm_addr_id_bitmap_t *bitmap,
631+
const struct genl_info *info)
632+
{
623633
struct mptcp_sock *msk;
624634
int ret = -EINVAL;
625635
struct sock *sk;
626-
void *hdr;
627-
628-
bitmap = (mptcp_pm_addr_id_bitmap_t *)cb->ctx;
629636

630637
msk = mptcp_userspace_pm_get_sock(info);
631638
if (!msk)
@@ -635,27 +642,9 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,
635642

636643
lock_sock(sk);
637644
spin_lock_bh(&msk->pm.lock);
638-
mptcp_for_each_userspace_pm_addr(msk, entry) {
639-
if (test_bit(entry->addr.id, bitmap->map))
640-
continue;
641-
642-
hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid,
643-
cb->nlh->nlmsg_seq, &mptcp_genl_family,
644-
NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR);
645-
if (!hdr)
646-
break;
647-
648-
if (mptcp_nl_fill_addr(msg, entry) < 0) {
649-
genlmsg_cancel(msg, hdr);
650-
break;
651-
}
652-
653-
__set_bit(entry->addr.id, bitmap->map);
654-
genlmsg_end(msg, hdr);
655-
}
645+
ret = mptcp_userspace_pm_reset_bitmap(msk, bitmap);
656646
spin_unlock_bh(&msk->pm.lock);
657647
release_sock(sk);
658-
ret = msg->len;
659648

660649
sock_put(sk);
661650
return ret;

net/mptcp/protocol.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,11 +1124,9 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_in
11241124
bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc);
11251125
bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc);
11261126
bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc);
1127-
int mptcp_pm_nl_dump_addr(struct sk_buff *msg,
1128-
struct netlink_callback *cb,
1127+
int mptcp_pm_nl_dump_addr(mptcp_pm_addr_id_bitmap_t *bitmap,
11291128
const struct genl_info *info);
1130-
int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,
1131-
struct netlink_callback *cb,
1129+
int mptcp_userspace_pm_dump_addr(mptcp_pm_addr_id_bitmap_t *bitmap,
11321130
const struct genl_info *info);
11331131
int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
11341132
const struct genl_info *info);

0 commit comments

Comments
 (0)