Skip to content

Commit a3400e8

Browse files
Paolo Abenidavem330
authored andcommitted
mptcp: more detailed error reporting on endpoint creation
Endpoint creation can fail for a number of reasons; in case of failure append the error number to the extended ack message, using a newly introduced generic helper. Additionally let mptcp_pm_nl_append_new_local_addr() report different error reasons. Reviewed-by: Mat Martineau <[email protected]> Signed-off-by: Paolo Abeni <[email protected]> Signed-off-by: Mat Martineau <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 976d302 commit a3400e8

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

include/net/genetlink.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ static inline void genl_info_net_set(struct genl_info *info, struct net *net)
125125

126126
#define GENL_SET_ERR_MSG(info, msg) NL_SET_ERR_MSG((info)->extack, msg)
127127

128+
#define GENL_SET_ERR_MSG_FMT(info, msg, args...) \
129+
NL_SET_ERR_MSG_FMT((info)->extack, msg, ##args)
130+
128131
/* Report that a root attribute is missing */
129132
#define GENL_REQ_ATTR_CHECK(info, attr) ({ \
130133
struct genl_info *__info = (info); \

net/mptcp/pm_netlink.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -912,10 +912,14 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,
912912
*/
913913
if (pernet->next_id == MPTCP_PM_MAX_ADDR_ID)
914914
pernet->next_id = 1;
915-
if (pernet->addrs >= MPTCP_PM_ADDR_MAX)
915+
if (pernet->addrs >= MPTCP_PM_ADDR_MAX) {
916+
ret = -ERANGE;
916917
goto out;
917-
if (test_bit(entry->addr.id, pernet->id_bitmap))
918+
}
919+
if (test_bit(entry->addr.id, pernet->id_bitmap)) {
920+
ret = -EBUSY;
918921
goto out;
922+
}
919923

920924
/* do not insert duplicate address, differentiate on port only
921925
* singled addresses
@@ -929,8 +933,10 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,
929933
* endpoint is an implicit one and the user-space
930934
* did not provide an endpoint id
931935
*/
932-
if (!(cur->flags & MPTCP_PM_ADDR_FLAG_IMPLICIT))
936+
if (!(cur->flags & MPTCP_PM_ADDR_FLAG_IMPLICIT)) {
937+
ret = -EEXIST;
933938
goto out;
939+
}
934940
if (entry->addr.id)
935941
goto out;
936942

@@ -1016,16 +1022,12 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk,
10161022
addrlen = sizeof(struct sockaddr_in6);
10171023
#endif
10181024
err = kernel_bind(ssock, (struct sockaddr *)&addr, addrlen);
1019-
if (err) {
1020-
pr_warn("kernel_bind error, err=%d", err);
1025+
if (err)
10211026
return err;
1022-
}
10231027

10241028
err = kernel_listen(ssock, backlog);
1025-
if (err) {
1026-
pr_warn("kernel_listen error, err=%d", err);
1029+
if (err)
10271030
return err;
1028-
}
10291031

10301032
return 0;
10311033
}
@@ -1329,13 +1331,13 @@ static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info)
13291331
if (entry->addr.port) {
13301332
ret = mptcp_pm_nl_create_listen_socket(skb->sk, entry);
13311333
if (ret) {
1332-
GENL_SET_ERR_MSG(info, "create listen socket error");
1334+
GENL_SET_ERR_MSG_FMT(info, "create listen socket error: %d", ret);
13331335
goto out_free;
13341336
}
13351337
}
13361338
ret = mptcp_pm_nl_append_new_local_addr(pernet, entry);
13371339
if (ret < 0) {
1338-
GENL_SET_ERR_MSG(info, "too many addresses or duplicate one");
1340+
GENL_SET_ERR_MSG_FMT(info, "too many addresses or duplicate one: %d", ret);
13391341
goto out_free;
13401342
}
13411343

0 commit comments

Comments
 (0)