Skip to content

Commit 704cf34

Browse files
Geliang Tangintel-lab-lkp
authored andcommitted
mptcp: reuse sending nlmsg code in dump_addr
A new type mptcp_pm_addr_id_bitmap_t is defined to easily modify dump_addr() interface of the path managers to accept an id_bitmap type parameter. It also allows this parameter of dump_addr() can be modified by BPF program when implementing this interface of a BFP path manager. 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 38d7bb6 commit 704cf34

File tree

5 files changed

+65
-71
lines changed

5 files changed

+65
-71
lines changed

include/net/mptcp.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ struct mptcp_sched_ops {
120120
void (*release)(struct mptcp_sock *msk);
121121
} ____cacheline_aligned_in_smp;
122122

123+
/* max value of mptcp_addr_info.id */
124+
#define MPTCP_PM_MAX_ADDR_ID U8_MAX
125+
126+
typedef struct {
127+
DECLARE_BITMAP(map, MPTCP_PM_MAX_ADDR_ID + 1);
128+
} mptcp_pm_addr_id_bitmap_t;
129+
123130
#ifdef CONFIG_MPTCP
124131
void mptcp_init(void);
125132

net/mptcp/pm.c

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,20 +485,54 @@ 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;
500505

501-
return mptcp_pm_dump_addr(msg, cb, info);
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, &mptcp_genl_family,
520+
NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR);
521+
if (!hdr)
522+
break;
523+
524+
if (mptcp_nl_fill_addr(msg, &entry) < 0) {
525+
genlmsg_cancel(msg, hdr);
526+
break;
527+
}
528+
529+
id = entry.addr.id;
530+
genlmsg_end(msg, hdr);
531+
}
532+
}
533+
534+
cb->args[0] = id;
535+
return msg->len;
502536
}
503537

504538
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 & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -614,20 +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-
struct id_bitmap {
622-
DECLARE_BITMAP(map, MPTCP_PM_MAX_ADDR_ID + 1);
623-
} *bitmap;
624620
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+
{
625633
struct mptcp_sock *msk;
626634
int ret = -EINVAL;
627635
struct sock *sk;
628-
void *hdr;
629-
630-
bitmap = (struct id_bitmap *)cb->ctx;
631636

632637
msk = mptcp_userspace_pm_get_sock(info);
633638
if (!msk)
@@ -637,27 +642,9 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,
637642

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

662649
sock_put(sk);
663650
return ret;

net/mptcp/protocol.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,6 @@ enum mptcp_addr_signal_status {
208208
MPTCP_RM_ADDR_SIGNAL,
209209
};
210210

211-
/* max value of mptcp_addr_info.id */
212-
#define MPTCP_PM_MAX_ADDR_ID U8_MAX
213-
214211
struct mptcp_pm_data {
215212
struct mptcp_addr_info local;
216213
struct mptcp_addr_info remote;
@@ -1127,11 +1124,9 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_in
11271124
bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc);
11281125
bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc);
11291126
bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc);
1130-
int mptcp_pm_nl_dump_addr(struct sk_buff *msg,
1131-
struct netlink_callback *cb,
1127+
int mptcp_pm_nl_dump_addr(mptcp_pm_addr_id_bitmap_t *bitmap,
11321128
const struct genl_info *info);
1133-
int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,
1134-
struct netlink_callback *cb,
1129+
int mptcp_userspace_pm_dump_addr(mptcp_pm_addr_id_bitmap_t *bitmap,
11351130
const struct genl_info *info);
11361131
int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
11371132
const struct genl_info *info);

0 commit comments

Comments
 (0)