Skip to content

Commit 2e7e6e9

Browse files
matttbekuba-moo
authored andcommitted
mptcp: pm: move Netlink PM helpers to pm_netlink.c
Before this patch, the PM code was dispersed in different places: - pm.c had common code for all PMs, but also Netlink specific code that will not be needed with the future BPF path-managers. - pm_netlink.c had common Netlink code. To clarify the code, a reorganisation is suggested here, only by moving code around, and small helper renaming to avoid confusions: - pm_netlink.c now only contains common PM Netlink code: - PM events: this code was already there - shared helpers around Netlink code that were already there as well - shared Netlink commands code from pm.c - pm.c now no longer contain Netlink specific code. - protocol.h has been updated accordingly: - mptcp_nl_fill_addr() no longer need to be exported. The code around the PM is now less confusing, which should help for the maintenance in the long term. This will certainly impact future backports, but because other cleanups have already done recently, and more are coming to ease the addition of a new path-manager controlled with BPF (struct_ops), doing that now seems to be a good time. Also, many issues around the PM have been fixed a few months ago while increasing the code coverage in the selftests, so such big reorganisation can be done with more confidence now. No behavioural changes intended. Reviewed-by: Geliang Tang <geliang@kernel.org> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> Link: https://patch.msgid.link/20250307-net-next-mptcp-pm-reorg-v1-15-abef20ada03b@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 8617e85 commit 2e7e6e9

File tree

3 files changed

+117
-123
lines changed

3 files changed

+117
-123
lines changed

net/mptcp/pm.c

Lines changed: 0 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@
55
*/
66
#define pr_fmt(fmt) "MPTCP: " fmt
77

8-
#include <linux/kernel.h>
9-
#include <net/mptcp.h>
108
#include "protocol.h"
11-
129
#include "mib.h"
13-
#include "mptcp_pm_gen.h"
1410

1511
#define ADD_ADDR_RETRANS_MAX 3
1612

@@ -888,121 +884,6 @@ bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc)
888884
return mptcp_pm_nl_is_backup(msk, &skc_local);
889885
}
890886

891-
static int mptcp_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
892-
struct genl_info *info)
893-
{
894-
if (info->attrs[MPTCP_PM_ATTR_TOKEN])
895-
return mptcp_userspace_pm_get_addr(id, addr, info);
896-
return mptcp_pm_nl_get_addr(id, addr, info);
897-
}
898-
899-
int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info)
900-
{
901-
struct mptcp_pm_addr_entry addr;
902-
struct nlattr *attr;
903-
struct sk_buff *msg;
904-
void *reply;
905-
int ret;
906-
907-
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR))
908-
return -EINVAL;
909-
910-
attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
911-
ret = mptcp_pm_parse_entry(attr, info, false, &addr);
912-
if (ret < 0)
913-
return ret;
914-
915-
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
916-
if (!msg)
917-
return -ENOMEM;
918-
919-
reply = genlmsg_put_reply(msg, info, &mptcp_genl_family, 0,
920-
info->genlhdr->cmd);
921-
if (!reply) {
922-
GENL_SET_ERR_MSG(info, "not enough space in Netlink message");
923-
ret = -EMSGSIZE;
924-
goto fail;
925-
}
926-
927-
ret = mptcp_pm_get_addr(addr.addr.id, &addr, info);
928-
if (ret) {
929-
NL_SET_ERR_MSG_ATTR(info->extack, attr, "address not found");
930-
goto fail;
931-
}
932-
933-
ret = mptcp_nl_fill_addr(msg, &addr);
934-
if (ret)
935-
goto fail;
936-
937-
genlmsg_end(msg, reply);
938-
ret = genlmsg_reply(msg, info);
939-
return ret;
940-
941-
fail:
942-
nlmsg_free(msg);
943-
return ret;
944-
}
945-
946-
int mptcp_pm_genl_fill_addr(struct sk_buff *msg,
947-
struct netlink_callback *cb,
948-
struct mptcp_pm_addr_entry *entry)
949-
{
950-
void *hdr;
951-
952-
hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid,
953-
cb->nlh->nlmsg_seq, &mptcp_genl_family,
954-
NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR);
955-
if (!hdr)
956-
return -EINVAL;
957-
958-
if (mptcp_nl_fill_addr(msg, entry) < 0) {
959-
genlmsg_cancel(msg, hdr);
960-
return -EINVAL;
961-
}
962-
963-
genlmsg_end(msg, hdr);
964-
return 0;
965-
}
966-
967-
static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb)
968-
{
969-
const struct genl_info *info = genl_info_dump(cb);
970-
971-
if (info->attrs[MPTCP_PM_ATTR_TOKEN])
972-
return mptcp_userspace_pm_dump_addr(msg, cb);
973-
return mptcp_pm_nl_dump_addr(msg, cb);
974-
}
975-
976-
int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg,
977-
struct netlink_callback *cb)
978-
{
979-
return mptcp_pm_dump_addr(msg, cb);
980-
}
981-
982-
static int mptcp_pm_set_flags(struct genl_info *info)
983-
{
984-
struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, };
985-
struct nlattr *attr_loc;
986-
int ret = -EINVAL;
987-
988-
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR))
989-
return ret;
990-
991-
attr_loc = info->attrs[MPTCP_PM_ATTR_ADDR];
992-
ret = mptcp_pm_parse_entry(attr_loc, info, false, &loc);
993-
if (ret < 0)
994-
return ret;
995-
996-
if (info->attrs[MPTCP_PM_ATTR_TOKEN])
997-
return mptcp_userspace_pm_set_flags(&loc, info);
998-
return mptcp_pm_nl_set_flags(&loc, info);
999-
}
1000-
1001-
int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info)
1002-
{
1003-
return mptcp_pm_set_flags(info);
1004-
}
1005-
1006887
static void mptcp_pm_subflows_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)
1007888
{
1008889
struct mptcp_subflow_context *iter, *subflow = mptcp_subflow_ctx(ssk);

net/mptcp/pm_netlink.c

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ int mptcp_pm_parse_entry(struct nlattr *attr, struct genl_info *info,
127127
return 0;
128128
}
129129

130-
int mptcp_nl_fill_addr(struct sk_buff *skb,
131-
struct mptcp_pm_addr_entry *entry)
130+
static int mptcp_nl_fill_addr(struct sk_buff *skb,
131+
struct mptcp_pm_addr_entry *entry)
132132
{
133133
struct mptcp_addr_info *addr = &entry->addr;
134134
struct nlattr *attr;
@@ -166,6 +166,121 @@ int mptcp_nl_fill_addr(struct sk_buff *skb,
166166
return -EMSGSIZE;
167167
}
168168

169+
static int mptcp_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
170+
struct genl_info *info)
171+
{
172+
if (info->attrs[MPTCP_PM_ATTR_TOKEN])
173+
return mptcp_userspace_pm_get_addr(id, addr, info);
174+
return mptcp_pm_nl_get_addr(id, addr, info);
175+
}
176+
177+
int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info)
178+
{
179+
struct mptcp_pm_addr_entry addr;
180+
struct nlattr *attr;
181+
struct sk_buff *msg;
182+
void *reply;
183+
int ret;
184+
185+
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR))
186+
return -EINVAL;
187+
188+
attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
189+
ret = mptcp_pm_parse_entry(attr, info, false, &addr);
190+
if (ret < 0)
191+
return ret;
192+
193+
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
194+
if (!msg)
195+
return -ENOMEM;
196+
197+
reply = genlmsg_put_reply(msg, info, &mptcp_genl_family, 0,
198+
info->genlhdr->cmd);
199+
if (!reply) {
200+
GENL_SET_ERR_MSG(info, "not enough space in Netlink message");
201+
ret = -EMSGSIZE;
202+
goto fail;
203+
}
204+
205+
ret = mptcp_pm_get_addr(addr.addr.id, &addr, info);
206+
if (ret) {
207+
NL_SET_ERR_MSG_ATTR(info->extack, attr, "address not found");
208+
goto fail;
209+
}
210+
211+
ret = mptcp_nl_fill_addr(msg, &addr);
212+
if (ret)
213+
goto fail;
214+
215+
genlmsg_end(msg, reply);
216+
ret = genlmsg_reply(msg, info);
217+
return ret;
218+
219+
fail:
220+
nlmsg_free(msg);
221+
return ret;
222+
}
223+
224+
int mptcp_pm_genl_fill_addr(struct sk_buff *msg,
225+
struct netlink_callback *cb,
226+
struct mptcp_pm_addr_entry *entry)
227+
{
228+
void *hdr;
229+
230+
hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid,
231+
cb->nlh->nlmsg_seq, &mptcp_genl_family,
232+
NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR);
233+
if (!hdr)
234+
return -EINVAL;
235+
236+
if (mptcp_nl_fill_addr(msg, entry) < 0) {
237+
genlmsg_cancel(msg, hdr);
238+
return -EINVAL;
239+
}
240+
241+
genlmsg_end(msg, hdr);
242+
return 0;
243+
}
244+
245+
static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb)
246+
{
247+
const struct genl_info *info = genl_info_dump(cb);
248+
249+
if (info->attrs[MPTCP_PM_ATTR_TOKEN])
250+
return mptcp_userspace_pm_dump_addr(msg, cb);
251+
return mptcp_pm_nl_dump_addr(msg, cb);
252+
}
253+
254+
int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg,
255+
struct netlink_callback *cb)
256+
{
257+
return mptcp_pm_dump_addr(msg, cb);
258+
}
259+
260+
static int mptcp_pm_set_flags(struct genl_info *info)
261+
{
262+
struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, };
263+
struct nlattr *attr_loc;
264+
int ret = -EINVAL;
265+
266+
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR))
267+
return ret;
268+
269+
attr_loc = info->attrs[MPTCP_PM_ATTR_ADDR];
270+
ret = mptcp_pm_parse_entry(attr_loc, info, false, &loc);
271+
if (ret < 0)
272+
return ret;
273+
274+
if (info->attrs[MPTCP_PM_ATTR_TOKEN])
275+
return mptcp_userspace_pm_set_flags(&loc, info);
276+
return mptcp_pm_nl_set_flags(&loc, info);
277+
}
278+
279+
int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info)
280+
{
281+
return mptcp_pm_set_flags(info);
282+
}
283+
169284
static void mptcp_nl_mcast_send(struct net *net, struct sk_buff *nlskb, gfp_t gfp)
170285
{
171286
genlmsg_multicast_netns(&mptcp_genl_family, net,

net/mptcp/protocol.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,8 +1057,6 @@ bool mptcp_userspace_pm_active(const struct mptcp_sock *msk);
10571057

10581058
void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subflow,
10591059
struct request_sock *req);
1060-
int mptcp_nl_fill_addr(struct sk_buff *skb,
1061-
struct mptcp_pm_addr_entry *entry);
10621060
int mptcp_pm_genl_fill_addr(struct sk_buff *msg,
10631061
struct netlink_callback *cb,
10641062
struct mptcp_pm_addr_entry *entry);

0 commit comments

Comments
 (0)