Skip to content

Commit 2c45455

Browse files
committed
Merge branch 'mptcp-netlink'
Mat Martineau says: ==================== mptcp: More specific netlink command errors This series makes the error reporting for the MPTCP_PM_CMD_ADD_ADDR netlink command more specific, since there are multiple reasons the command could fail. Note that patch 2 adds a GENL_SET_ERR_MSG_FMT() macro to genetlink.h, which is outside the MPTCP subsystem. Patch 1 refactors in-kernel listening socket and endpoint creation to simplify the second patch. Patch 2 updates the error values returned by the in-kernel path manager when it fails to create a local endpoint. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 7a7160e + a3400e8 commit 2c45455

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
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: 26 additions & 33 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

@@ -1003,39 +1009,27 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk,
10031009
return err;
10041010

10051011
msk = mptcp_sk(entry->lsk->sk);
1006-
if (!msk) {
1007-
err = -EINVAL;
1008-
goto out;
1009-
}
1012+
if (!msk)
1013+
return -EINVAL;
10101014

10111015
ssock = __mptcp_nmpc_socket(msk);
1012-
if (!ssock) {
1013-
err = -EINVAL;
1014-
goto out;
1015-
}
1016+
if (!ssock)
1017+
return -EINVAL;
10161018

10171019
mptcp_info2sockaddr(&entry->addr, &addr, entry->addr.family);
10181020
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
10191021
if (entry->addr.family == AF_INET6)
10201022
addrlen = sizeof(struct sockaddr_in6);
10211023
#endif
10221024
err = kernel_bind(ssock, (struct sockaddr *)&addr, addrlen);
1023-
if (err) {
1024-
pr_warn("kernel_bind error, err=%d", err);
1025-
goto out;
1026-
}
1025+
if (err)
1026+
return err;
10271027

10281028
err = kernel_listen(ssock, backlog);
1029-
if (err) {
1030-
pr_warn("kernel_listen error, err=%d", err);
1031-
goto out;
1032-
}
1029+
if (err)
1030+
return err;
10331031

10341032
return 0;
1035-
1036-
out:
1037-
sock_release(entry->lsk);
1038-
return err;
10391033
}
10401034

10411035
int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
@@ -1327,7 +1321,7 @@ static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info)
13271321
return -EINVAL;
13281322
}
13291323

1330-
entry = kmalloc(sizeof(*entry), GFP_KERNEL_ACCOUNT);
1324+
entry = kzalloc(sizeof(*entry), GFP_KERNEL_ACCOUNT);
13311325
if (!entry) {
13321326
GENL_SET_ERR_MSG(info, "can't allocate addr");
13331327
return -ENOMEM;
@@ -1337,23 +1331,22 @@ static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info)
13371331
if (entry->addr.port) {
13381332
ret = mptcp_pm_nl_create_listen_socket(skb->sk, entry);
13391333
if (ret) {
1340-
GENL_SET_ERR_MSG(info, "create listen socket error");
1341-
kfree(entry);
1342-
return ret;
1334+
GENL_SET_ERR_MSG_FMT(info, "create listen socket error: %d", ret);
1335+
goto out_free;
13431336
}
13441337
}
13451338
ret = mptcp_pm_nl_append_new_local_addr(pernet, entry);
13461339
if (ret < 0) {
1347-
GENL_SET_ERR_MSG(info, "too many addresses or duplicate one");
1348-
if (entry->lsk)
1349-
sock_release(entry->lsk);
1350-
kfree(entry);
1351-
return ret;
1340+
GENL_SET_ERR_MSG_FMT(info, "too many addresses or duplicate one: %d", ret);
1341+
goto out_free;
13521342
}
13531343

13541344
mptcp_nl_add_subflow_or_signal_addr(sock_net(skb->sk));
1355-
13561345
return 0;
1346+
1347+
out_free:
1348+
__mptcp_pm_release_addr_entry(entry);
1349+
return ret;
13571350
}
13581351

13591352
int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id,

0 commit comments

Comments
 (0)