refactor PM interfaces
Subsystems (2)
Geliang Tang
reviewerv3 cover refactor PM interfaces
From: Geliang Tang <[email protected]>
v3:
- two more patches, 14-15, drop struct mptcp_pm_local and structmptcp_pm_add_entry.
v2:
- split patch 5 into two.
- new patches 9-13.
In order to implement BPF path manager, this set refactors get_addr and dump_addr interfaces of PM.
Depends on:
- cleanups for PM interfaces, v3
Based-on: <[email protected]>
Geliang Tang (15):
mptcp: add id parameter for get_addr
mptcp: add addr parameter for get_addr
mptcp: reuse sending nlmsg code in get_addr
mptcp: change info of get_addr as const
mptcp: refactor dump_addr with id bitmap
mptcp: refactor dump_addr with get_addr
mptcp: reuse sending nlmsg code in dump_addr
mptcp: add loc and rem for set_flags
mptcp: update address type of get_local_id
mptcp: change is_backup interfaces as get_flags
mptcp: hold pm lock when deleting entry
mptcp: rename mptcp_pm_remove_addrs
mptcp: drop free_list for deleting entries
mptcp: drop struct mptcp_pm_local
mptcp: drop struct mptcp_pm_add_entry
net/mptcp/pm.c | 17 ++- net/mptcp/pm_netlink.c | 245 ++++++++++++++++++++------------------- net/mptcp/pm_userspace.c | 168 ++++++++------------------- net/mptcp/protocol.h | 50 ++++---- net/mptcp/subflow.c | 2 +- 5 files changed, 220 insertions(+), 262 deletions(-)
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v3 1/15 mptcp: add id parameter for get_addr
From: Geliang Tang <[email protected]>
The address id is parsed both in mptcp_pm_nl_get_addr() and mptcp_userspace_pm_get_addr(), this makes the code somewhat repetitive. So this patch adds a new parameter "id" for all get_addr() interfaces. The address id is only parsed in mptcp_pm_nl_get_addr_doit(), then pass it to both mptcp_pm_nl_get_addr() and mptcp_userspace_pm_get_addr().
--- net/mptcp/pm_netlink.c | 28 ++++++++++++++++------------ net/mptcp/pm_userspace.c | 11 +++-------- net/mptcp/protocol.h | 2 +- 3 files changed, 20 insertions(+), 21 deletions(-)
net/mptcp/pm_netlink.c +16 -12
@@ -1792,19 +1792,14 @@ int mptcp_nl_fill_addr(struct sk_buff *skb,return -EMSGSIZE ; } -static int mptcp_pm_nl_get_addr (struct genl_info *info) +static int mptcp_pm_nl_get_addr (u8 id,struct genl_info *info) { -struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR ];struct pm_nl_pernet *pernet =genl_info_pm_nl (info); -struct mptcp_pm_addr_entry addr, *entry; +struct mptcp_pm_addr_entry *entry;struct sk_buff *msg;void *reply;int ret; - ret =mptcp_pm_parse_entry (attr, info, false, &addr); -if (ret <0 ) -return ret; - msg =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL );if (!msg)return -ENOMEM ;
@@ -1818,7 +1813,7 @@ static int mptcp_pm_nl_get_addr(struct genl_info *info) }spin_lock_bh (&pernet->lock); - entry =__lookup_addr_by_id (pernet, addr.addr.id); + entry =__lookup_addr_by_id (pernet, id);if (!entry) {GENL_SET_ERR_MSG (info,"address not found" ); ret = -EINVAL ;
@@ -1842,16 +1837,25 @@ static int mptcp_pm_nl_get_addr(struct genl_info *info)return ret; } -static int mptcp_pm_get_addr (struct genl_info *info) +static int mptcp_pm_get_addr (u8 id,struct genl_info *info) {if (info->attrs[MPTCP_PM_ATTR_TOKEN ]) -return mptcp_userspace_pm_get_addr (info); -return mptcp_pm_nl_get_addr (info); +return mptcp_userspace_pm_get_addr (id, info); +return mptcp_pm_nl_get_addr (id, info); }int mptcp_pm_nl_get_addr_doit (struct sk_buff *skb,struct genl_info *info) { -return mptcp_pm_get_addr (info); +struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR ]; +struct mptcp_pm_addr_entry addr; +int ret; + + ret =mptcp_pm_parse_entry (attr, info, false, &addr); +if (ret <0 ) +return ret; + + ret =mptcp_pm_get_addr (addr.addr.id, info); +return ret; } static int mptcp_pm_nl_dump_addr(struct sk_buff *msg,
net/mptcp/pm_userspace.c +3 -8
@@ -629,10 +629,9 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,return ret; } -int mptcp_userspace_pm_get_addr (struct genl_info *info) +int mptcp_userspace_pm_get_addr (u8 id,struct genl_info *info) { -struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR ]; -struct mptcp_pm_addr_entry addr, *entry; +struct mptcp_pm_addr_entry *entry;struct mptcp_sock *msk;struct sk_buff *msg;int ret = -EINVAL ;
@@ -645,10 +644,6 @@ int mptcp_userspace_pm_get_addr(struct genl_info *info) sk = (struct sock *)msk; - ret =mptcp_pm_parse_entry (attr, info, false, &addr); -if (ret <0 ) - goto out; - msg =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL );if (!msg) { ret = -ENOMEM ;
@@ -665,7 +660,7 @@ int mptcp_userspace_pm_get_addr(struct genl_info *info)lock_sock (sk);spin_lock_bh (&msk->pm.lock); - entry =mptcp_userspace_pm_lookup_addr_by_id (msk, addr.addr.id); + entry =mptcp_userspace_pm_lookup_addr_by_id (msk, id);if (!entry) {GENL_SET_ERR_MSG (info,"address not found" ); ret = -EINVAL ;
net/mptcp/protocol.h +1 -1
@@ -1125,7 +1125,7 @@ bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc);bool mptcp_userspace_pm_is_backup (struct mptcp_sock *msk,struct mptcp_addr_info *skc);int mptcp_userspace_pm_dump_addr (struct sk_buff *msg,struct netlink_callback *cb); -int mptcp_userspace_pm_get_addr (struct genl_info *info); +int mptcp_userspace_pm_get_addr (u8 id,struct genl_info *info);static inline u8 subflow_get_local_id (const struct mptcp_subflow_context *subflow) {
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v3 2/15 mptcp: add addr parameter for get_addr
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
The netlink messages are sent both in mptcp_pm_nl_get_addr() and mptcp_userspace_pm_get_addr(), this makes the code somewhat repetitive. This is because the netlink PM and userspace PM use different locks to protect the address entry that needs to be sent via the netlink message. The former uses pernet->lock, and the latter uses msk->pm.lock.
The current get_addr() flow looks like this:
lock(); entry = get_entry(); send_nlmsg(entry); unlock();
After holding the lock, get the entry from the list, send the entry, and finally release the lock.
This patch changes the process by getting the entry while holding the lock, then making a copy of the entry so that the lock can be released. Finally, the copy of the entry is sent without locking:
lock(); entry = get_entry(); *copy = *entry; unlock(); send_nlmsg(copy);
This way we can reuse this send_nlmsg() code between the netlink PM and userspace PM.
--- net/mptcp/pm_netlink.c | 33 ++++++++++++++++++--------------- net/mptcp/pm_userspace.c | 24 +++++++++++++----------- net/mptcp/protocol.h | 3 ++- 3 files changed, 33 insertions(+), 27 deletions(-)
net/mptcp/pm_netlink.c +18 -15
@@ -1792,13 +1792,14 @@ int mptcp_nl_fill_addr(struct sk_buff *skb,return -EMSGSIZE ; } -static int mptcp_pm_nl_get_addr (u8 id,struct genl_info *info) +static int mptcp_pm_nl_get_addr (u8 id,struct mptcp_pm_addr_entry *addr, +struct genl_info *info) {struct pm_nl_pernet *pernet =genl_info_pm_nl (info);struct mptcp_pm_addr_entry *entry;struct sk_buff *msg; +int ret = -EINVAL ;void *reply; -int ret; msg =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL );if (!msg)
@@ -1814,34 +1815,36 @@ static int mptcp_pm_nl_get_addr(u8 id, struct genl_info *info)spin_lock_bh (&pernet->lock); entry =__lookup_addr_by_id (pernet, id); -if (!entry) { +if (entry) { + *addr = *entry; + ret =0 ; + } +spin_unlock_bh (&pernet->lock); + +if (ret) {GENL_SET_ERR_MSG (info,"address not found" ); - ret = -EINVAL ; - goto unlock_fail; + goto fail; } - ret =mptcp_nl_fill_addr (msg, entry); + ret =mptcp_nl_fill_addr (msg, addr);if (ret) - goto unlock_fail; + goto fail;genlmsg_end (msg, reply); ret =genlmsg_reply (msg, info); -spin_unlock_bh (&pernet->lock);return ret; -unlock_fail: -spin_unlock_bh (&pernet->lock); - fail:nlmsg_free (msg);return ret; } -static int mptcp_pm_get_addr (u8 id,struct genl_info *info) +static int mptcp_pm_get_addr (u8 id,struct mptcp_pm_addr_entry *addr, +struct genl_info *info) {if (info->attrs[MPTCP_PM_ATTR_TOKEN ]) -return mptcp_userspace_pm_get_addr (id, info); -return mptcp_pm_nl_get_addr (id, info); +return mptcp_userspace_pm_get_addr (id, addr, info); +return mptcp_pm_nl_get_addr (id, addr, info); }int mptcp_pm_nl_get_addr_doit (struct sk_buff *skb,struct genl_info *info)
@@ -1854,7 +1857,7 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info)if (ret <0 )return ret; - ret =mptcp_pm_get_addr (addr.addr.id, info); + ret =mptcp_pm_get_addr (addr.addr.id, &addr, info);return ret; }
net/mptcp/pm_userspace.c +13 -11
@@ -629,7 +629,8 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,return ret; } -int mptcp_userspace_pm_get_addr (u8 id,struct genl_info *info) +int mptcp_userspace_pm_get_addr (u8 id,struct mptcp_pm_addr_entry *addr, +struct genl_info *info) {struct mptcp_pm_addr_entry *entry;struct mptcp_sock *msk;
@@ -661,26 +662,27 @@ int mptcp_userspace_pm_get_addr(u8 id, struct genl_info *info)lock_sock (sk);spin_lock_bh (&msk->pm.lock); entry =mptcp_userspace_pm_lookup_addr_by_id (msk, id); -if (!entry) { +if (entry) { + *addr = *entry; + ret =0 ; + } +spin_unlock_bh (&msk->pm.lock); +release_sock (sk); + +if (ret) {GENL_SET_ERR_MSG (info,"address not found" ); - ret = -EINVAL ; - goto unlock_fail; + goto fail; } - ret =mptcp_nl_fill_addr (msg, entry); + ret =mptcp_nl_fill_addr (msg, addr);if (ret) - goto unlock_fail; + goto fail;genlmsg_end (msg, reply); ret =genlmsg_reply (msg, info); -spin_unlock_bh (&msk->pm.lock); -release_sock (sk);sock_put (sk);return ret; -unlock_fail: -spin_unlock_bh (&msk->pm.lock); -release_sock (sk); fail:nlmsg_free (msg); out:
net/mptcp/protocol.h +2 -1
@@ -1125,7 +1125,8 @@ bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc);bool mptcp_userspace_pm_is_backup (struct mptcp_sock *msk,struct mptcp_addr_info *skc);int mptcp_userspace_pm_dump_addr (struct sk_buff *msg,struct netlink_callback *cb); -int mptcp_userspace_pm_get_addr (u8 id,struct genl_info *info); +int mptcp_userspace_pm_get_addr (u8 id,struct mptcp_pm_addr_entry *addr, +struct genl_info *info);static inline u8 subflow_get_local_id (const struct mptcp_subflow_context *subflow) {
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v3 3/15 mptcp: reuse sending nlmsg code in get_addr
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
With the previous commit, we can reuse the send_nlmsg() code in get_addr() interfaces between the netlink PM and userspace PM. They only need to implement their own get_addr() interfaces to hold the different locks, get the entry from the different lists, then release the locks.
--- net/mptcp/pm_netlink.c | 58 ++++++++++++++++++++-------------------- net/mptcp/pm_userspace.c | 33 ----------------------- 2 files changed, 29 insertions(+), 62 deletions(-)
net/mptcp/pm_netlink.c +29 -29
@@ -1797,21 +1797,7 @@ static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, {struct pm_nl_pernet *pernet =genl_info_pm_nl (info);struct mptcp_pm_addr_entry *entry; -struct sk_buff *msg;int ret = -EINVAL ; -void *reply; - - msg =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL ); -if (!msg) -return -ENOMEM ; - - reply =genlmsg_put_reply (msg, info, &mptcp_genl_family,0 , - info->genlhdr->cmd); -if (!reply) { -GENL_SET_ERR_MSG (info,"not enough space in Netlink message" ); - ret = -EMSGSIZE ; - goto fail; - }spin_lock_bh (&pernet->lock); entry =__lookup_addr_by_id (pernet, id);
@@ -1821,21 +1807,6 @@ static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, }spin_unlock_bh (&pernet->lock); -if (ret) { -GENL_SET_ERR_MSG (info,"address not found" ); - goto fail; - } - - ret =mptcp_nl_fill_addr (msg, addr); -if (ret) - goto fail; - -genlmsg_end (msg, reply); - ret =genlmsg_reply (msg, info); -return ret; - -fail: -nlmsg_free (msg);return ret; }
@@ -1851,13 +1822,42 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) {struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR ];struct mptcp_pm_addr_entry addr; +struct sk_buff *msg; +void *reply;int ret; ret =mptcp_pm_parse_entry (attr, info, false, &addr);if (ret <0 )return ret; + msg =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL ); +if (!msg) +return -ENOMEM ; + + reply =genlmsg_put_reply (msg, info, &mptcp_genl_family,0 , + info->genlhdr->cmd); +if (!reply) { +GENL_SET_ERR_MSG (info,"not enough space in Netlink message" ); + ret = -EMSGSIZE ; + goto fail; + } + ret =mptcp_pm_get_addr (addr.addr.id, &addr, info); +if (ret) { +GENL_SET_ERR_MSG (info,"address not found" ); + goto fail; + } + + ret =mptcp_nl_fill_addr (msg, &addr); +if (ret) + goto fail; + +genlmsg_end (msg, reply); + ret =genlmsg_reply (msg, info); +return ret; + +fail: +nlmsg_free (msg);return ret; }
net/mptcp/pm_userspace.c +0 -33
@@ -634,10 +634,8 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, {struct mptcp_pm_addr_entry *entry;struct mptcp_sock *msk; -struct sk_buff *msg;int ret = -EINVAL ;struct sock *sk; -void *reply; msk =mptcp_userspace_pm_get_sock (info);if (!msk)
@@ -645,20 +643,6 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, sk = (struct sock *)msk; - msg =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL ); -if (!msg) { - ret = -ENOMEM ; - goto out; - } - - reply =genlmsg_put_reply (msg, info, &mptcp_genl_family,0 , - info->genlhdr->cmd); -if (!reply) { -GENL_SET_ERR_MSG (info,"not enough space in Netlink message" ); - ret = -EMSGSIZE ; - goto fail; - } -lock_sock (sk);spin_lock_bh (&msk->pm.lock); entry =mptcp_userspace_pm_lookup_addr_by_id (msk, id);
@@ -669,23 +653,6 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,spin_unlock_bh (&msk->pm.lock);release_sock (sk); -if (ret) { -GENL_SET_ERR_MSG (info,"address not found" ); - goto fail; - } - - ret =mptcp_nl_fill_addr (msg, addr); -if (ret) - goto fail; - -genlmsg_end (msg, reply); - ret =genlmsg_reply (msg, info); -sock_put (sk); -return ret; - -fail: -nlmsg_free (msg); -out:sock_put (sk);return ret; }
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v3 4/15 mptcp: change info of get_addr as const
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
get_addr() interfeces will be invoked by dump_addr(), which using const parameters "info", so this patch changes "info" parameters of get_addr() as const too.
--- net/mptcp/pm_netlink.c | 9 ++++++--- net/mptcp/pm_userspace.c | 2 +- net/mptcp/protocol.h | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-)
net/mptcp/pm_netlink.c +6 -3
@@ -1793,12 +1793,15 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, }static int mptcp_pm_nl_get_addr (u8 id,struct mptcp_pm_addr_entry *addr, -struct genl_info *info) +const struct genl_info *info) { -struct pm_nl_pernet *pernet =genl_info_pm_nl (info); +struct net *net =genl_info_net (info);struct mptcp_pm_addr_entry *entry; +struct pm_nl_pernet *pernet;int ret = -EINVAL ; + pernet =pm_nl_get_pernet (net); +spin_lock_bh (&pernet->lock); entry =__lookup_addr_by_id (pernet, id);if (entry) {
@@ -1811,7 +1814,7 @@ static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, }static int mptcp_pm_get_addr (u8 id,struct mptcp_pm_addr_entry *addr, -struct genl_info *info) +const struct genl_info *info) {if (info->attrs[MPTCP_PM_ATTR_TOKEN ])return mptcp_userspace_pm_get_addr (id, addr, info);
net/mptcp/pm_userspace.c +1 -1
@@ -630,7 +630,7 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, }int mptcp_userspace_pm_get_addr (u8 id,struct mptcp_pm_addr_entry *addr, -struct genl_info *info) +const struct genl_info *info) {struct mptcp_pm_addr_entry *entry;struct mptcp_sock *msk;
net/mptcp/protocol.h +1 -1
@@ -1126,7 +1126,7 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_infoint mptcp_userspace_pm_dump_addr (struct sk_buff *msg,struct netlink_callback *cb);int mptcp_userspace_pm_get_addr (u8 id,struct mptcp_pm_addr_entry *addr, -struct genl_info *info); +const struct genl_info *info);static inline u8 subflow_get_local_id (const struct mptcp_subflow_context *subflow) {
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v3 5/15 mptcp: refactor dump_addr with id bitmap
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
With the help of get_addr(), we can refactor 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.
This patch is the first part of refactoring dump_addr().
Without changing the position of the locks, the dump process is split into two parts: copying the ID bitmap first, and then traversing the ID bitmap, use lookup_addr_by_id() to get the entry, then send each one through nlmsg:
lock();
for_each_entry(entry)
set_bit(bitmap);
for_each_bit(bitmap) {
entry = lookup_addr_by_id();
send_nlmsg(entry);
}
unlock();--- net/mptcp/pm_netlink.c | 6 ++++- net/mptcp/pm_userspace.c | 54 +++++++++++++++++++++++++++++----------- 2 files changed, 45 insertions(+), 15 deletions(-)
net/mptcp/pm_netlink.c +5 -1
@@ -1869,16 +1869,20 @@ static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, {struct net *net =sock_net (msg->sk);struct mptcp_pm_addr_entry *entry; +struct mptcp_id_bitmap *bitmap;struct pm_nl_pernet *pernet;int id = cb->args[0 ];void *hdr;int i; + bitmap = (struct mptcp_id_bitmap *)cb->ctx; pernet =pm_nl_get_pernet (net);spin_lock_bh (&pernet->lock); +if (!id) +bitmap_copy (bitmap->map, pernet->id_bitmap.map,MPTCP_PM_MAX_ADDR_ID +1 );for (i = id; i <MPTCP_PM_MAX_ADDR_ID +1 ; i++) { -if (test_bit (i, pernet->id_bitmap.map)) { +if (test_bit (i, bitmap->map)) { entry =__lookup_addr_by_id (pernet, i);if (!entry)break ;
net/mptcp/pm_userspace.c +40 -14
79 lines not on this page · raw message
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v3 6/15 mptcp: refactor dump_addr with get_addr
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
This patch is the second part of refactoring dump_addr().
With the help of get_addr(), only copy 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);
}--- net/mptcp/pm_netlink.c | 20 +++++++++++--------- net/mptcp/pm_userspace.c | 23 ++++++++++++----------- 2 files changed, 23 insertions(+), 20 deletions(-)
net/mptcp/pm_netlink.c +11 -9
@@ -1867,8 +1867,9 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info)static int mptcp_pm_nl_dump_addr (struct sk_buff *msg,struct netlink_callback *cb) { +const struct genl_info *info =genl_info_dump (cb);struct net *net =sock_net (msg->sk); -struct mptcp_pm_addr_entry *entry; +struct mptcp_pm_addr_entry entry;struct mptcp_id_bitmap *bitmap;struct pm_nl_pernet *pernet;int id = cb->args[0 ];
@@ -1878,16 +1879,18 @@ static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, bitmap = (struct mptcp_id_bitmap *)cb->ctx; pernet =pm_nl_get_pernet (net); -spin_lock_bh (&pernet->lock); -if (!id) +if (!id) { +spin_lock_bh (&pernet->lock);bitmap_copy (bitmap->map, pernet->id_bitmap.map,MPTCP_PM_MAX_ADDR_ID +1 ); +spin_unlock_bh (&pernet->lock); + } +for (i = id; i <MPTCP_PM_MAX_ADDR_ID +1 ; i++) {if (test_bit (i, bitmap->map)) { - entry =__lookup_addr_by_id (pernet, i); -if (!entry) +if (mptcp_pm_nl_get_addr (i, &entry, info))break ; -if (entry->addr.id <= id) +if (entry.addr.id <= id)continue ; hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid,
@@ -1896,16 +1899,15 @@ static int mptcp_pm_nl_dump_addr(struct sk_buff *msg,if (!hdr)break ; -if (mptcp_nl_fill_addr (msg, entry) <0 ) { +if (mptcp_nl_fill_addr (msg, &entry) <0 ) {genlmsg_cancel (msg, hdr);break ; } - id = entry->addr.id; + id = entry.addr.id;genlmsg_end (msg, hdr); } } -spin_unlock_bh (&pernet->lock); cb->args[0 ] = id;return msg->len;
net/mptcp/pm_userspace.c +12 -11
@@ -601,7 +601,7 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) {const struct genl_info *info =genl_info_dump (cb); -struct mptcp_pm_addr_entry *entry; +struct mptcp_pm_addr_entry entry;struct mptcp_id_bitmap *bitmap;struct mptcp_sock *msk;int id = cb->args[0 ];
@@ -618,17 +618,20 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, sk = (struct sock *)msk; -lock_sock (sk); -spin_lock_bh (&msk->pm.lock); -if (!id) +if (!id) { +lock_sock (sk); +spin_lock_bh (&msk->pm.lock); ret =mptcp_userspace_pm_set_bitmap (msk, bitmap); +spin_unlock_bh (&msk->pm.lock); +release_sock (sk); + } +for (i = id; i <MPTCP_PM_MAX_ADDR_ID +1 ; i++) {if (test_bit (i, bitmap->map)) { - entry =mptcp_userspace_pm_lookup_addr_by_id (msk, i); -if (!entry) +if (mptcp_userspace_pm_get_addr (i, &entry, info))break ; -if (id && entry->addr.id <= id) +if (id && entry.addr.id <= id)continue ; hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid,
@@ -637,18 +640,16 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,if (!hdr)break ; -if (mptcp_nl_fill_addr (msg, entry) <0 ) { +if (mptcp_nl_fill_addr (msg, &entry) <0 ) {genlmsg_cancel (msg, hdr);break ; } - id = entry->addr.id; + id = entry.addr.id;genlmsg_end (msg, hdr); } } cb->args[0 ] = id; -spin_unlock_bh (&msk->pm.lock); -release_sock (sk); ret = msg->len;sock_put (sk);
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v3 7/15 mptcp: reuse sending nlmsg code in dump_addr
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
With the previous commit, 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.
--- net/mptcp/pm_netlink.c | 56 +++++++++++++++++++++------------------- net/mptcp/pm_userspace.c | 50 +++++------------------------------ net/mptcp/protocol.h | 4 +-- 3 files changed, 38 insertions(+), 72 deletions(-)
net/mptcp/pm_netlink.c +29 -27
@@ -1864,33 +1864,50 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info)return ret; } -static int mptcp_pm_nl_dump_addr (struct sk_buff *msg, -struct netlink_callback *cb) +static int mptcp_pm_nl_dump_addr (struct mptcp_id_bitmap *bitmap, +const struct genl_info *info) +{ +struct net *net =genl_info_net (info); +struct pm_nl_pernet *pernet; + + pernet =pm_nl_get_pernet (net); + +spin_lock_bh (&pernet->lock); +bitmap_copy (bitmap->map, pernet->id_bitmap.map,MPTCP_PM_MAX_ADDR_ID +1 ); +spin_unlock_bh (&pernet->lock); + +return 0 ; +} + +static int mptcp_pm_dump_addr (struct mptcp_id_bitmap *bitmap, +const struct genl_info *info) +{ +if (info->attrs[MPTCP_PM_ATTR_TOKEN ]) +return mptcp_userspace_pm_dump_addr (bitmap, info); +return mptcp_pm_nl_dump_addr (bitmap, info); +} + +int mptcp_pm_nl_get_addr_dumpit (struct sk_buff *msg, +struct netlink_callback *cb) {const struct genl_info *info =genl_info_dump (cb); -struct net *net =sock_net (msg->sk);struct mptcp_pm_addr_entry entry;struct mptcp_id_bitmap *bitmap; -struct pm_nl_pernet *pernet;int id = cb->args[0 ];void *hdr;int i; bitmap = (struct mptcp_id_bitmap *)cb->ctx; - pernet =pm_nl_get_pernet (net); -if (!id) { -spin_lock_bh (&pernet->lock); -bitmap_copy (bitmap->map, pernet->id_bitmap.map,MPTCP_PM_MAX_ADDR_ID +1 ); -spin_unlock_bh (&pernet->lock); - } +if (!id) +mptcp_pm_dump_addr (bitmap, info);for (i = id; i <MPTCP_PM_MAX_ADDR_ID +1 ; i++) {if (test_bit (i, bitmap->map)) { -if (mptcp_pm_nl_get_addr (i, &entry, info)) +if (mptcp_pm_get_addr (i, &entry, info))break ; -if (entry.addr.id <= id) +if (id && entry.addr.id <= id)continue ; hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid,
@@ -1913,21 +1930,6 @@ static int mptcp_pm_nl_dump_addr(struct sk_buff *msg,return msg->len; } -static int mptcp_pm_dump_addr (struct sk_buff *msg,struct netlink_callback *cb) -{ -const struct genl_info *info =genl_info_dump (cb); - -if (info->attrs[MPTCP_PM_ATTR_TOKEN ]) -return mptcp_userspace_pm_dump_addr (msg, cb); -return mptcp_pm_nl_dump_addr (msg, cb); -} - -int mptcp_pm_nl_get_addr_dumpit (struct sk_buff *msg, -struct netlink_callback *cb) -{ -return mptcp_pm_dump_addr (msg, cb); -} -static int parse_limit (struct genl_info *info,int id,unsigned int *limit) {struct nlattr *attr = info->attrs[id];
net/mptcp/pm_userspace.c +7 -43
66 lines not on this page · raw message
net/mptcp/protocol.h +2 -2
@@ -1123,8 +1123,8 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_inbool mptcp_pm_is_backup (struct mptcp_sock *msk,struct sock_common *skc);bool mptcp_pm_nl_is_backup (struct mptcp_sock *msk,struct mptcp_addr_info *skc);bool mptcp_userspace_pm_is_backup (struct mptcp_sock *msk,struct mptcp_addr_info *skc); -int mptcp_userspace_pm_dump_addr (struct sk_buff *msg, -struct netlink_callback *cb); +int mptcp_userspace_pm_dump_addr (struct mptcp_id_bitmap *bitmap, +const struct genl_info *info);int mptcp_userspace_pm_get_addr (u8 id,struct mptcp_pm_addr_entry *addr,const struct genl_info *info);
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v3 8/15 mptcp: add loc and rem for set_flags
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
This patch updates the interfaces set_flags to reduce repetitive code, adds two more parameters "loc" and "rem" for them. These addresses are parsed in public helper mptcp_pm_nl_set_flags_doit(), then pass them to mptcp_pm_nl_set_flags() and mptcp_userspace_pm_set_flags().
--- net/mptcp/pm_netlink.c | 38 ++++++++++++++++++++++++++------------ net/mptcp/pm_userspace.c | 26 +++++++------------------- net/mptcp/protocol.h | 4 +++- 3 files changed, 36 insertions(+), 32 deletions(-)
net/mptcp/pm_netlink.c +26 -12
@@ -2045,25 +2045,21 @@ static int mptcp_nl_set_flags(struct net *net,return ret; } -static int mptcp_pm_nl_set_flags (struct genl_info *info) +static int mptcp_pm_nl_set_flags (struct mptcp_pm_addr_entry *loc, +struct mptcp_addr_info *rem, +struct genl_info *info) { -struct mptcp_pm_addr_entry addr = { .addr = { .family =AF_UNSPEC }, }; -struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR ];u8 changed, mask =MPTCP_PM_ADDR_FLAG_BACKUP |MPTCP_PM_ADDR_FLAG_FULLMESH ; +struct mptcp_pm_addr_entry addr = *loc;struct net *net =genl_info_net (info);struct mptcp_pm_addr_entry *entry;struct pm_nl_pernet *pernet;u8 lookup_by_id =0 ;u8 bkup =0 ; -int ret; pernet =pm_nl_get_pernet (net); - ret =mptcp_pm_parse_entry (attr, info, false, &addr); -if (ret <0 ) -return ret; -if (addr.addr.family ==AF_UNSPEC ) { lookup_by_id =1 ;if (!addr.addr.id) {
@@ -2099,16 +2095,34 @@ static int mptcp_pm_nl_set_flags(struct genl_info *info)return 0 ; } -static int mptcp_pm_set_flags (struct genl_info *info) +static int mptcp_pm_set_flags (struct mptcp_pm_addr_entry *loc, +struct mptcp_addr_info *rem, +struct genl_info *info) {if (info->attrs[MPTCP_PM_ATTR_TOKEN ]) -return mptcp_userspace_pm_set_flags (info); -return mptcp_pm_nl_set_flags (info); +return mptcp_userspace_pm_set_flags (loc, rem, info); +return mptcp_pm_nl_set_flags (loc, rem, info); }int mptcp_pm_nl_set_flags_doit (struct sk_buff *skb,struct genl_info *info) { -return mptcp_pm_set_flags (info); +struct mptcp_pm_addr_entry loc = { .addr = { .family =AF_UNSPEC }, }; +struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE ]; +struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR ]; +struct mptcp_addr_info rem = { .family =AF_UNSPEC , }; +int ret; + + ret =mptcp_pm_parse_entry (attr, info, false, &loc); +if (ret <0 ) +return ret; + +if (attr_rem) { + ret =mptcp_pm_parse_addr (attr_rem, info, &rem); +if (ret <0 ) +return ret; + } + +return mptcp_pm_set_flags (&loc, &rem, info); }static void mptcp_nl_mcast_send (struct net *net,struct sk_buff *nlskb,gfp_t gfp)
net/mptcp/pm_userspace.c +7 -19
@@ -536,12 +536,10 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *inforeturn err; } -int mptcp_userspace_pm_set_flags (struct genl_info *info) +int mptcp_userspace_pm_set_flags (struct mptcp_pm_addr_entry *loc, +struct mptcp_addr_info *rem, +struct genl_info *info) { -struct mptcp_pm_addr_entry loc = { .addr = { .family =AF_UNSPEC }, }; -struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE ]; -struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR ]; -struct mptcp_addr_info rem = { .family =AF_UNSPEC , };struct mptcp_sock *msk;int ret = -EINVAL ;struct sock *sk;
@@ -553,28 +551,18 @@ int mptcp_userspace_pm_set_flags(struct genl_info *info) sk = (struct sock *)msk; - ret =mptcp_pm_parse_entry (attr, info, false, &loc); -if (ret <0 ) - goto set_flags_err; - -if (attr_rem) { - ret =mptcp_pm_parse_addr (attr_rem, info, &rem); -if (ret <0 ) - goto set_flags_err; - } - -if (loc.addr.family ==AF_UNSPEC || - rem.family ==AF_UNSPEC ) { +if (loc->addr.family ==AF_UNSPEC || + rem->family ==AF_UNSPEC ) {GENL_SET_ERR_MSG (info,"invalid address families" ); ret = -EINVAL ; goto set_flags_err; } -if (loc.flags &MPTCP_PM_ADDR_FLAG_BACKUP ) +if (loc->flags &MPTCP_PM_ADDR_FLAG_BACKUP ) bkup =1 ;lock_sock (sk); - ret =mptcp_pm_nl_mp_prio_send_ack (msk, &loc.addr, &rem, bkup); + ret =mptcp_pm_nl_mp_prio_send_ack (msk, &loc->addr, rem, bkup);release_sock (sk); set_flags_err:
net/mptcp/protocol.h +3 -1
@@ -1033,7 +1033,9 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk,struct mptcp_pm_add_entry *mptcp_lookup_anno_list_by_saddr (const struct mptcp_sock *msk,const struct mptcp_addr_info *addr); -int mptcp_userspace_pm_set_flags (struct genl_info *info); +int mptcp_userspace_pm_set_flags (struct mptcp_pm_addr_entry *loc, +struct mptcp_addr_info *rem, +struct genl_info *info);int mptcp_pm_announce_addr (struct mptcp_sock *msk,const struct mptcp_addr_info *addr,bool echo);
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v3 9/15 mptcp: update address type of get_local_id
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
The following code in mptcp_userspace_pm_get_local_id() that assigns "skc" to "new_entry" is not allowed in BPF if we use the same code to implement the get_local_id() interface of a BFP path manager:
memset(&new_entry, 0, sizeof(struct mptcp_pm_addr_entry)); new_entry.addr = *skc; new_entry.addr.id = 0; new_entry.flags = MPTCP_PM_ADDR_FLAG_IMPLICIT;
To solve the issue, this patch moves this assignment to "new_entry" forward to mptcp_pm_get_local_id(), and then passing "new_entry" as a parameter to both mptcp_pm_nl_get_local_id() and mptcp_userspace_pm_get_local_id().
--- net/mptcp/pm.c | 10 ++++++++-- net/mptcp/pm_netlink.c | 11 +++-------- net/mptcp/pm_userspace.c | 17 ++++++----------- net/mptcp/protocol.h | 4 ++-- 4 files changed, 19 insertions(+), 23 deletions(-)
net/mptcp/pm.c +8 -2
@@ -404,6 +404,7 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc) {struct mptcp_addr_info skc_local;struct mptcp_addr_info msk_local; +struct mptcp_pm_addr_entry local;if (WARN_ON_ONCE (!msk))return -1 ;
@@ -416,9 +417,14 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)if (mptcp_addresses_equal (&msk_local, &skc_local, false))return 0 ; +memset (&local,0 ,sizeof (struct mptcp_pm_addr_entry )); + local.addr = skc_local; + local.addr.id =0 ; + local.flags =MPTCP_PM_ADDR_FLAG_IMPLICIT ; +if (mptcp_pm_is_userspace (msk)) -return mptcp_userspace_pm_get_local_id (msk, &skc_local); -return mptcp_pm_nl_get_local_id (msk, &skc_local); +return mptcp_userspace_pm_get_local_id (msk, &local); +return mptcp_pm_nl_get_local_id (msk, &local); }bool mptcp_pm_is_backup (struct mptcp_sock *msk,struct sock_common *skc)
net/mptcp/pm_netlink.c +3 -8
@@ -1137,7 +1137,7 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk,return err; } -int mptcp_pm_nl_get_local_id (struct mptcp_sock *msk,struct mptcp_addr_info *skc) +int mptcp_pm_nl_get_local_id (struct mptcp_sock *msk,struct mptcp_pm_addr_entry *local) {struct mptcp_pm_addr_entry *entry;struct pm_nl_pernet *pernet;
@@ -1146,7 +1146,7 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc pernet =pm_nl_get_pernet_from_msk (msk);rcu_read_lock (); - entry =__lookup_addr (pernet, skc); + entry =__lookup_addr (pernet, &local->addr);if (entry) ret = entry->addr.id;rcu_read_unlock ();
@@ -1158,12 +1158,7 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skcif (!entry)return -ENOMEM ; - entry->addr = *skc; - entry->addr.id =0 ; - entry->addr.port =0 ; - entry->ifindex =0 ; - entry->flags =MPTCP_PM_ADDR_FLAG_IMPLICIT ; - entry->lsk =NULL ; + *entry = *local; ret =mptcp_pm_nl_append_new_local_addr (pernet, entry, true);if (ret <0 )kfree (entry);
net/mptcp/pm_userspace.c +6 -11
@@ -131,27 +131,22 @@ mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_sock *msk, unsigned int id) }int mptcp_userspace_pm_get_local_id (struct mptcp_sock *msk, -struct mptcp_addr_info *skc) +struct mptcp_pm_addr_entry *local) { -struct mptcp_pm_addr_entry *entry =NULL , new_entry; +struct mptcp_pm_addr_entry *entry =NULL ;__be16 msk_sport = ((struct inet_sock *)inet_sk ((struct sock *)msk))->inet_sport;spin_lock_bh (&msk->pm.lock); - entry =mptcp_userspace_pm_lookup_addr (msk, skc); + entry =mptcp_userspace_pm_lookup_addr (msk, &local->addr);spin_unlock_bh (&msk->pm.lock);if (entry)return entry->addr.id; -memset (&new_entry,0 ,sizeof (struct mptcp_pm_addr_entry )); - new_entry.addr = *skc; - new_entry.addr.id =0 ; - new_entry.flags =MPTCP_PM_ADDR_FLAG_IMPLICIT ; - -if (new_entry.addr.port == msk_sport) - new_entry.addr.port =0 ; +if (local->addr.port == msk_sport) + local->addr.port =0 ; -return mptcp_userspace_pm_append_new_local_addr (msk, &new_entry, true); +return mptcp_userspace_pm_append_new_local_addr (msk, local, true); } bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk,
net/mptcp/protocol.h +2 -2
@@ -1120,8 +1120,8 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, const struct sk_buff *skb,bool mptcp_pm_rm_addr_signal (struct mptcp_sock *msk,unsigned int remaining,struct mptcp_rm_list *rm_list);int mptcp_pm_get_local_id (struct mptcp_sock *msk,struct sock_common *skc); -int mptcp_pm_nl_get_local_id (struct mptcp_sock *msk,struct mptcp_addr_info *skc); -int mptcp_userspace_pm_get_local_id (struct mptcp_sock *msk,struct mptcp_addr_info *skc); +int mptcp_pm_nl_get_local_id (struct mptcp_sock *msk,struct mptcp_pm_addr_entry *local); +int mptcp_userspace_pm_get_local_id (struct mptcp_sock *msk,struct mptcp_pm_addr_entry *local);bool mptcp_pm_is_backup (struct mptcp_sock *msk,struct sock_common *skc);bool mptcp_pm_nl_is_backup (struct mptcp_sock *msk,struct mptcp_addr_info *skc);bool mptcp_userspace_pm_is_backup (struct mptcp_sock *msk,struct mptcp_addr_info *skc);
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v3 10/15 mptcp: change is_backup interfaces as get_flags
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
The is_backup() interface of path manager is not very common. A more common approach is to add a get_flags() interface to obtain the flags value of a given address. Then is_backup() can be implemented through get_flags() by test whether backup flag is set in the flags value.
--- net/mptcp/pm.c | 7 +++++-- net/mptcp/pm_netlink.c | 8 ++++---- net/mptcp/pm_userspace.c | 10 +++++----- net/mptcp/protocol.h | 4 ++-- 4 files changed, 16 insertions(+), 13 deletions(-)
net/mptcp/pm.c +5 -2
@@ -430,13 +430,16 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)bool mptcp_pm_is_backup (struct mptcp_sock *msk,struct sock_common *skc) {struct mptcp_addr_info skc_local; +u8 flags;mptcp_local_address ((struct sock_common *)skc, &skc_local);if (mptcp_pm_is_userspace (msk)) -return mptcp_userspace_pm_is_backup (msk, &skc_local); + flags =mptcp_userspace_pm_get_flags (msk, &skc_local); +else + flags =mptcp_pm_nl_get_flags (msk, &skc_local); -return mptcp_pm_nl_is_backup (msk, &skc_local); +return !!(flags &MPTCP_PM_ADDR_FLAG_BACKUP ); }void mptcp_pm_subflow_chk_stale (const struct mptcp_sock *msk,struct sock *ssk)
net/mptcp/pm_netlink.c +4 -4
@@ -1166,19 +1166,19 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_pm_addr_entryreturn ret; } -bool mptcp_pm_nl_is_backup (struct mptcp_sock *msk,struct mptcp_addr_info *skc) +u8 mptcp_pm_nl_get_flags (struct mptcp_sock *msk,struct mptcp_addr_info *skc) {struct pm_nl_pernet *pernet =pm_nl_get_pernet_from_msk (msk);struct mptcp_pm_addr_entry *entry; -bool backup = false; +u8 flags =0 ;rcu_read_lock (); entry =__lookup_addr (pernet, skc);if (entry) - backup = !!(entry->flags &MPTCP_PM_ADDR_FLAG_BACKUP ); + flags = entry->flags;rcu_read_unlock (); -return backup; +return flags; }#define MPTCP_PM_CMD_GRP_OFFSET 0
net/mptcp/pm_userspace.c +5 -5
@@ -149,19 +149,19 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk,return mptcp_userspace_pm_append_new_local_addr (msk, local, true); } -bool mptcp_userspace_pm_is_backup (struct mptcp_sock *msk, -struct mptcp_addr_info *skc) +u8 mptcp_userspace_pm_get_flags (struct mptcp_sock *msk, +struct mptcp_addr_info *skc) {struct mptcp_pm_addr_entry *entry; -bool backup = false; +u8 flags =0 ;spin_lock_bh (&msk->pm.lock); entry =mptcp_userspace_pm_lookup_addr (msk, skc);if (entry) - backup = !!(entry->flags &MPTCP_PM_ADDR_FLAG_BACKUP ); + flags = entry->flags;spin_unlock_bh (&msk->pm.lock); -return backup; +return flags; }static struct mptcp_sock *mptcp_userspace_pm_get_sock (const struct genl_info *info)
net/mptcp/protocol.h +2 -2
@@ -1123,8 +1123,8 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);int mptcp_pm_nl_get_local_id (struct mptcp_sock *msk,struct mptcp_pm_addr_entry *local);int mptcp_userspace_pm_get_local_id (struct mptcp_sock *msk,struct mptcp_pm_addr_entry *local);bool mptcp_pm_is_backup (struct mptcp_sock *msk,struct sock_common *skc); -bool mptcp_pm_nl_is_backup (struct mptcp_sock *msk,struct mptcp_addr_info *skc); -bool mptcp_userspace_pm_is_backup (struct mptcp_sock *msk,struct mptcp_addr_info *skc); +u8 mptcp_pm_nl_get_flags (struct mptcp_sock *msk,struct mptcp_addr_info *skc); +u8 mptcp_userspace_pm_get_flags (struct mptcp_sock *msk,struct mptcp_addr_info *skc);int mptcp_userspace_pm_dump_addr (struct mptcp_id_bitmap *bitmap,const struct genl_info *info); int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v3 11/15 mptcp: hold pm lock when deleting entry
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
When traversing userspace_pm_local_addr_list and deleting an entry from it in mptcp_pm_nl_remove_doit(), msk->pm.lock should be held.
--- net/mptcp/pm_userspace.c | 3 +++ 1 file changed, 3 insertions(+)
net/mptcp/pm_userspace.c +3 -0
@@ -310,14 +310,17 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)lock_sock (sk); +spin_lock_bh (&msk->pm.lock); match =mptcp_userspace_pm_lookup_addr_by_id (msk, id_val);if (!match) {GENL_SET_ERR_MSG (info,"address with specified id not found" ); +spin_unlock_bh (&msk->pm.lock);release_sock (sk); goto out; }list_move (&match->list, &free_list); +spin_unlock_bh (&msk->pm.lock);mptcp_pm_remove_addrs (msk, &free_list);
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v3 12/15 mptcp: rename mptcp_pm_remove_addrs
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
mptcp_pm_remove_addrs() actually only deletes one address, which does not match its name. This patch renames it to mptcp_pm_remove_addr_entry() and changes the parameter "rm_list" to "entry".
--- net/mptcp/pm_netlink.c | 24 ++++++++++-------------- net/mptcp/pm_userspace.c | 2 +- net/mptcp/protocol.h | 3 ++- 3 files changed, 13 insertions(+), 16 deletions(-)
net/mptcp/pm_netlink.c +10 -14
@@ -1629,26 +1629,22 @@ int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, struct genl_info *info) }/* Called from the userspace PM only */ -void mptcp_pm_remove_addrs (struct mptcp_sock *msk,struct list_head *rm_list) +void mptcp_pm_remove_addr_entry (struct mptcp_sock *msk, +struct mptcp_pm_addr_entry *entry) {struct mptcp_rm_list alist = { .nr =0 }; -struct mptcp_pm_addr_entry *entry;int anno_nr =0 ; -list_for_each_entry (entry, rm_list, list) { -if (alist.nr >=MPTCP_RM_IDS_MAX ) -break ; - -/* only delete if either announced or matching a subflow */ -if (remove_anno_list_by_saddr (msk, &entry->addr)) - anno_nr++; -else if (!lookup_subflow_by_saddr (&msk->conn_list, - &entry->addr)) -continue ; +/* only delete if either announced or matching a subflow */ +if (remove_anno_list_by_saddr (msk, &entry->addr)) + anno_nr++; +else if (!lookup_subflow_by_saddr (&msk->conn_list, + &entry->addr)) + goto out; - alist.ids[alist.nr++] = entry->addr.id; - } + alist.ids[alist.nr++] = entry->addr.id; +out:if (alist.nr) {spin_lock_bh (&msk->pm.lock); msk->pm.add_addr_signaled -= anno_nr;
net/mptcp/pm_userspace.c +1 -1
@@ -322,7 +322,7 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)list_move (&match->list, &free_list);spin_unlock_bh (&msk->pm.lock); -mptcp_pm_remove_addrs (msk, &free_list); +mptcp_pm_remove_addr_entry (msk, match);release_sock (sk);
net/mptcp/protocol.h +2 -1
@@ -1040,7 +1040,8 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,const struct mptcp_addr_info *addr, bool echo);int mptcp_pm_remove_addr (struct mptcp_sock *msk,const struct mptcp_rm_list *rm_list); -void mptcp_pm_remove_addrs (struct mptcp_sock *msk,struct list_head *rm_list); +void mptcp_pm_remove_addr_entry (struct mptcp_sock *msk, +struct mptcp_pm_addr_entry *entry);void mptcp_free_local_addr_list (struct mptcp_sock *msk);
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v3 13/15 mptcp: drop free_list for deleting entries
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
With the help of mptcp_pm_remove_addr_entry(), it's no longer necessary to move the entry to be deleted to free_list and then traverse the list to delete the entry, which is not allowed in BPF. The entry can be directly deleted through list_del_rcu() and sock_kfree_s() now.
--- net/mptcp/pm_userspace.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
net/mptcp/pm_userspace.c +5 -9
@@ -283,9 +283,7 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) {struct nlattr *id = info->attrs[MPTCP_PM_ATTR_LOC_ID ];struct mptcp_pm_addr_entry *match; -struct mptcp_pm_addr_entry *entry;struct mptcp_sock *msk; -LIST_HEAD (free_list);int err = -EINVAL ;struct sock *sk;u8 id_val;
@@ -312,23 +310,21 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)spin_lock_bh (&msk->pm.lock); match =mptcp_userspace_pm_lookup_addr_by_id (msk, id_val); +spin_unlock_bh (&msk->pm.lock);if (!match) {GENL_SET_ERR_MSG (info,"address with specified id not found" ); -spin_unlock_bh (&msk->pm.lock);release_sock (sk); goto out; } -list_move (&match->list, &free_list); -spin_unlock_bh (&msk->pm.lock); -mptcp_pm_remove_addr_entry (msk, match);release_sock (sk); -list_for_each_entry_safe (match, entry, &free_list, list) { -sock_kfree_s (sk, match,sizeof (*match)); - } +spin_lock_bh (&msk->pm.lock); +list_del_rcu (&match->list); +sock_kfree_s (sk, match,sizeof (*match)); +spin_unlock_bh (&msk->pm.lock); err =0 ; out:
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v3 14/15 mptcp: drop struct mptcp_pm_local
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
The following code in mptcp_pm_nl_subflow_create_doit() that assigns struct mptcp_pm_addr_entry "entry" to the local struct mptcp_pm_local variable "local" is not allowed in BPF if we use the same code to implement the subflow_create() interface of a BFP path manager:
struct mptcp_pm_local local; local.addr = entry.addr; local.flags = entry.flags; local.ifindex = entry.ifindex;
We should avoid this type of assignment from struct mptcp_pm_addr_entry to struct mptcp_pm_local.
In fact, there is no need to add a dedicated address entry type for local address entry. All its fields are the same as struct mptcp_pm_addr_entry, except that it lacks a "lsk" for the listening socket. So we can use struct mptcp_pm_addr_entry directly. This makes the path manager code simpler.
--- net/mptcp/pm_netlink.c | 22 ++++++++-------------- net/mptcp/pm_userspace.c | 7 +------ net/mptcp/protocol.h | 8 +------- net/mptcp/subflow.c | 2 +- 4 files changed, 11 insertions(+), 28 deletions(-)
net/mptcp/pm_netlink.c +8 -14
@@ -149,7 +149,7 @@ static bool lookup_subflow_by_daddr(const struct list_head *list,static bool select_local_address (const struct pm_nl_pernet *pernet,const struct mptcp_sock *msk, -struct mptcp_pm_local *new_local) +struct mptcp_pm_addr_entry *new_local) {struct mptcp_pm_addr_entry *entry;bool found = false;
@@ -164,9 +164,7 @@ select_local_address(const struct pm_nl_pernet *pernet,if (!test_bit (entry->addr.id, msk->pm.id_avail_bitmap.map))continue ; - new_local->addr = entry->addr; - new_local->flags = entry->flags; - new_local->ifindex = entry->ifindex; + *new_local = *entry; found = true;break ; }
@@ -177,7 +175,7 @@ select_local_address(const struct pm_nl_pernet *pernet,static bool select_signal_address (struct pm_nl_pernet *pernet,const struct mptcp_sock *msk, -struct mptcp_pm_local *new_local) +struct mptcp_pm_addr_entry *new_local) {struct mptcp_pm_addr_entry *entry;bool found = false;
@@ -195,9 +193,7 @@ select_signal_address(struct pm_nl_pernet *pernet, const struct mptcp_sock *msk,if (!(entry->flags &MPTCP_PM_ADDR_FLAG_SIGNAL ))continue ; - new_local->addr = entry->addr; - new_local->flags = entry->flags; - new_local->ifindex = entry->ifindex; + *new_local = *entry; found = true;break ; }
@@ -534,11 +530,11 @@ __lookup_addr(struct pm_nl_pernet *pernet, const struct mptcp_addr_info *info)static void mptcp_pm_create_subflow_or_signal_addr (struct mptcp_sock *msk) {struct sock *sk = (struct sock *)msk; +struct mptcp_pm_addr_entry local;unsigned int add_addr_signal_max;bool signal_and_subflow = false;unsigned int local_addr_max;struct pm_nl_pernet *pernet; -struct mptcp_pm_local local;unsigned int subflows_max; pernet =pm_nl_get_pernet (sock_net (sk));
@@ -660,7 +656,7 @@ static void mptcp_pm_nl_subflow_established(struct mptcp_sock *msk)*/ static unsigned int fill_local_addresses_vec (struct mptcp_sock *msk,struct mptcp_addr_info *remote, -struct mptcp_pm_local *locals) +struct mptcp_pm_addr_entry *locals) {struct sock *sk = (struct sock *)msk;struct mptcp_pm_addr_entry *entry;
@@ -683,9 +679,7 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk,continue ;if (msk->pm.subflows < subflows_max) { - locals[i].addr = entry->addr; - locals[i].flags = entry->flags; - locals[i].ifindex = entry->ifindex; + locals[i] = *entry;/* Special case for ID0: set the correct ID */ if (mptcp_addresses_equal (&locals[i].addr, &mpc_addr, locals[i].addr.port))
@@ -721,7 +715,7 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk,static void mptcp_pm_nl_add_addr_received (struct mptcp_sock *msk) { -struct mptcp_pm_local locals[MPTCP_PM_ADDR_MAX ]; +struct mptcp_pm_addr_entry locals[MPTCP_PM_ADDR_MAX ];struct sock *sk = (struct sock *)msk;unsigned int add_addr_accept_max;struct mptcp_addr_info remote;
net/mptcp/pm_userspace.c +1 -6
@@ -338,7 +338,6 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)struct nlattr *laddr = info->attrs[MPTCP_PM_ATTR_ADDR ];struct mptcp_pm_addr_entry entry = {0 };struct mptcp_addr_info addr_r; -struct mptcp_pm_local local;struct mptcp_sock *msk;int err = -EINVAL ;struct sock *sk;
@@ -385,12 +384,8 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) goto create_err; } - local.addr = entry.addr; - local.flags = entry.flags; - local.ifindex = entry.ifindex; -lock_sock (sk); - err =__mptcp_subflow_connect (sk, &local, &addr_r); + err =__mptcp_subflow_connect (sk, &entry, &addr_r);release_sock (sk);spin_lock_bh (&msk->pm.lock);
net/mptcp/protocol.h +1 -7
@@ -240,12 +240,6 @@ struct mptcp_pm_data {struct mptcp_rm_list rm_list_rx; }; -struct mptcp_pm_local { -struct mptcp_addr_info addr; -u8 flags; -int ifindex; -}; -struct mptcp_pm_addr_entry {struct list_head list;struct mptcp_addr_info addr;
@@ -738,7 +732,7 @@ bool mptcp_addresses_equal(const struct mptcp_addr_info *a,void mptcp_local_address (const struct sock_common *skc,struct mptcp_addr_info *addr);/* called with sk socket lock held */ -int __mptcp_subflow_connect (struct sock *sk,const struct mptcp_pm_local *local, +int __mptcp_subflow_connect (struct sock *sk,const struct mptcp_pm_addr_entry *local,const struct mptcp_addr_info *remote);int mptcp_subflow_create_socket (struct sock *sk,unsigned short family,struct socket **new_sock);
net/mptcp/subflow.c +1 -1
@@ -1582,7 +1582,7 @@ void mptcp_info2sockaddr(const struct mptcp_addr_info *info,#endif } -int __mptcp_subflow_connect (struct sock *sk,const struct mptcp_pm_local *local, +int __mptcp_subflow_connect (struct sock *sk,const struct mptcp_pm_addr_entry *local,const struct mptcp_addr_info *remote) {struct mptcp_sock *msk =mptcp_sk (sk);
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v3 15/15 mptcp: drop struct mptcp_pm_add_entry
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
There is no need to add a dedicated address entry type "mptcp_pm_add_entry" to represent ADD_ADDR addresses. Additional fileds for ADD_ADDR addresses can be added into struct mptcp_pm_addr_entry directly. This makes the path manager code simpler.
Here "union" can be used to merge struct mptcp_pm_addr_entry and struct mptcp_pm_add_entry into one. Then all mptcp_pm_add_entry can be replaced by mptcp_pm_addr_entry.
--- net/mptcp/pm_netlink.c | 26 +++++++++----------------- net/mptcp/protocol.h | 20 +++++++++++++++----- 2 files changed, 24 insertions(+), 22 deletions(-)
net/mptcp/pm_netlink.c +9 -17
@@ -18,14 +18,6 @@static int pm_nl_pernet_id; -struct mptcp_pm_add_entry { -struct list_head list; -struct mptcp_addr_info addr; -u8 retrans_times; -struct timer_list add_timer; -struct mptcp_sock *sock; -}; -struct pm_nl_pernet {/* protects pernet updates */ spinlock_t lock;
@@ -247,11 +239,11 @@ bool mptcp_pm_nl_check_work_pending(struct mptcp_sock *msk)return true; } -struct mptcp_pm_add_entry * +struct mptcp_pm_addr_entry *mptcp_lookup_anno_list_by_saddr (const struct mptcp_sock *msk,const struct mptcp_addr_info *addr) { -struct mptcp_pm_add_entry *entry; +struct mptcp_pm_addr_entry *entry;lockdep_assert_held (&msk->pm.lock);
@@ -265,7 +257,7 @@ mptcp_lookup_anno_list_by_saddr(const struct mptcp_sock *msk,bool mptcp_pm_sport_in_anno_list (struct mptcp_sock *msk,const struct sock *sk) { -struct mptcp_pm_add_entry *entry; +struct mptcp_pm_addr_entry *entry;struct mptcp_addr_info saddr;bool ret = false;
@@ -286,7 +278,7 @@ bool mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk, const struct sock *sk)static void mptcp_pm_add_timer (struct timer_list *timer) { -struct mptcp_pm_add_entry *entry =from_timer (entry, timer, add_timer); +struct mptcp_pm_addr_entry *entry =from_timer (entry, timer, add_timer);struct mptcp_sock *msk = entry->sock;struct sock *sk = (struct sock *)msk;
@@ -328,11 +320,11 @@ static void mptcp_pm_add_timer(struct timer_list *timer)__sock_put (sk); } -struct mptcp_pm_add_entry * +struct mptcp_pm_addr_entry *mptcp_pm_del_add_timer (struct mptcp_sock *msk,const struct mptcp_addr_info *addr,bool check_id) { -struct mptcp_pm_add_entry *entry; +struct mptcp_pm_addr_entry *entry;struct sock *sk = (struct sock *)msk;struct timer_list *add_timer =NULL ;
@@ -356,7 +348,7 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk,bool mptcp_pm_alloc_anno_list (struct mptcp_sock *msk,const struct mptcp_addr_info *addr) { -struct mptcp_pm_add_entry *add_entry =NULL ; +struct mptcp_pm_addr_entry *add_entry =NULL ;struct sock *sk = (struct sock *)msk;struct net *net =sock_net (sk);
@@ -392,7 +384,7 @@ bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk,void mptcp_pm_free_anno_list (struct mptcp_sock *msk) { -struct mptcp_pm_add_entry *entry, *tmp; +struct mptcp_pm_addr_entry *entry, *tmp;struct sock *sk = (struct sock *)msk;LIST_HEAD (free_list);
@@ -1439,7 +1431,7 @@ int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, struct genl_info *info)static bool remove_anno_list_by_saddr (struct mptcp_sock *msk,const struct mptcp_addr_info *addr) { -struct mptcp_pm_add_entry *entry; +struct mptcp_pm_addr_entry *entry; entry =mptcp_pm_del_add_timer (msk, addr, false);if (entry) {
net/mptcp/protocol.h +15 -5
@@ -243,9 +243,19 @@ struct mptcp_pm_data {struct mptcp_pm_addr_entry {struct list_head list;struct mptcp_addr_info addr; -u8 flags; -int ifindex; -struct socket *lsk; +union { +struct { +u8 flags; +int ifindex; +struct socket *lsk; + }; +/* mptcp_pm_add_entry */ +struct { +u8 retrans_times; +struct timer_list add_timer; +struct mptcp_sock *sock; + }; + }; };struct mptcp_data_frag {
@@ -1021,10 +1031,10 @@ bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk, const struct mptcp_addr_info *addr);void mptcp_pm_free_anno_list (struct mptcp_sock *msk);bool mptcp_pm_sport_in_anno_list (struct mptcp_sock *msk,const struct sock *sk); -struct mptcp_pm_add_entry * +struct mptcp_pm_addr_entry *mptcp_pm_del_add_timer (struct mptcp_sock *msk,const struct mptcp_addr_info *addr,bool check_id); -struct mptcp_pm_add_entry * +struct mptcp_pm_addr_entry *mptcp_lookup_anno_list_by_saddr (const struct mptcp_sock *msk,const struct mptcp_addr_info *addr); int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *loc,
Signature · 1 line
2.43.0
Hi Geliang,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal: Unstable: 1 failed test(s): packetdrill_dss 🔴
- KVM Validation: debug: Unstable: 1 failed test(s): packetdrill_dss 🔴
- KVM Validation: btf (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/11268311983
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/8a88c16c3a19
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=897455
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-normalFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
Matthieu Baerts
maintainerHi Geliang,
Quoted 8 lines · MPTCP CI
Hi Geliang,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal: Unstable: 1 failed test(s):
packetdrill_dss🔴
- KVM Validation: debug: Unstable: 1 failed test(s):packetdrill_dss🔴
That's interesting: the CI had this error, because the code doesn't have "mptcp: fallback when MPTCP opts are dropped after 1st data" commit.
https://github.com/multipath-tcp/mptcp_net-next/commits/8a88c16c3a19
That's appently because when using the "Based-on", Patchew will use the tag it created, then apply the new patches. It will then not use the last version of the "export" branch, then apply the dependences, then the new ones.
In other words, we can ignore the failed tests here.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.