Skip to content

Commit af51a65

Browse files
Geliang Tangintel-lab-lkp
authored andcommitted
mptcp: add mptcp_pm_genl_fill_addr helper
To save some redundant code in dump_addr() interfaces of both the netlink PM and userspace PM, the code that calls netlink message helpers (genlmsg_put/cancel/end) and mptcp_nl_fill_addr() is wrapped into a new helper mptcp_pm_genl_fill_addr(). This helper will also be used in BPF path managers. Signed-off-by: Geliang Tang <[email protected]>
1 parent 6667e65 commit af51a65

File tree

4 files changed

+26
-22
lines changed

4 files changed

+26
-22
lines changed

net/mptcp/pm.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,27 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info)
489489
return ret;
490490
}
491491

492+
int mptcp_pm_genl_fill_addr(struct sk_buff *msg,
493+
struct netlink_callback *cb,
494+
struct mptcp_pm_addr_entry *entry)
495+
{
496+
void *hdr;
497+
498+
hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid,
499+
cb->nlh->nlmsg_seq, &mptcp_genl_family,
500+
NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR);
501+
if (!hdr)
502+
return -EINVAL;
503+
504+
if (mptcp_nl_fill_addr(msg, entry) < 0) {
505+
genlmsg_cancel(msg, hdr);
506+
return -EINVAL;
507+
}
508+
509+
genlmsg_end(msg, hdr);
510+
return 0;
511+
}
512+
492513
static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb)
493514
{
494515
const struct genl_info *info = genl_info_dump(cb);

net/mptcp/pm_netlink.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,7 +1798,6 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg,
17981798
struct mptcp_pm_addr_entry *entry;
17991799
struct pm_nl_pernet *pernet;
18001800
int id = cb->args[0];
1801-
void *hdr;
18021801
int i;
18031802

18041803
pernet = pm_nl_get_pernet(net);
@@ -1813,19 +1812,10 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg,
18131812
if (entry->addr.id <= id)
18141813
continue;
18151814

1816-
hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid,
1817-
cb->nlh->nlmsg_seq, &mptcp_genl_family,
1818-
NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR);
1819-
if (!hdr)
1815+
if (mptcp_pm_genl_fill_addr(msg, cb, entry))
18201816
break;
18211817

1822-
if (mptcp_nl_fill_addr(msg, entry) < 0) {
1823-
genlmsg_cancel(msg, hdr);
1824-
break;
1825-
}
1826-
18271818
id = entry->addr.id;
1828-
genlmsg_end(msg, hdr);
18291819
}
18301820
}
18311821
rcu_read_unlock();

net/mptcp/pm_userspace.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,6 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,
641641
struct mptcp_sock *msk;
642642
int ret = -EINVAL;
643643
struct sock *sk;
644-
void *hdr;
645644

646645
bitmap = (struct id_bitmap *)cb->ctx;
647646

@@ -657,19 +656,10 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,
657656
if (test_bit(entry->addr.id, bitmap->map))
658657
continue;
659658

660-
hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid,
661-
cb->nlh->nlmsg_seq, &mptcp_genl_family,
662-
NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR);
663-
if (!hdr)
659+
if (mptcp_pm_genl_fill_addr(msg, cb, entry))
664660
break;
665661

666-
if (mptcp_nl_fill_addr(msg, entry) < 0) {
667-
genlmsg_cancel(msg, hdr);
668-
break;
669-
}
670-
671662
__set_bit(entry->addr.id, bitmap->map);
672-
genlmsg_end(msg, hdr);
673663
}
674664
spin_unlock_bh(&msk->pm.lock);
675665
release_sock(sk);

net/mptcp/protocol.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,9 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg,
11311131
struct netlink_callback *cb);
11321132
int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,
11331133
struct netlink_callback *cb);
1134+
int mptcp_pm_genl_fill_addr(struct sk_buff *msg,
1135+
struct netlink_callback *cb,
1136+
struct mptcp_pm_addr_entry *entry);
11341137
int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
11351138
struct genl_info *info);
11361139
int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,

0 commit comments

Comments
 (0)