mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-23 16:53:58 -05:00
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 <davem@davemloft.net>
This commit is contained in:
commit
2c45455ea1
2 changed files with 29 additions and 33 deletions
|
@ -125,6 +125,9 @@ static inline void genl_info_net_set(struct genl_info *info, struct net *net)
|
||||||
|
|
||||||
#define GENL_SET_ERR_MSG(info, msg) NL_SET_ERR_MSG((info)->extack, msg)
|
#define GENL_SET_ERR_MSG(info, msg) NL_SET_ERR_MSG((info)->extack, msg)
|
||||||
|
|
||||||
|
#define GENL_SET_ERR_MSG_FMT(info, msg, args...) \
|
||||||
|
NL_SET_ERR_MSG_FMT((info)->extack, msg, ##args)
|
||||||
|
|
||||||
/* Report that a root attribute is missing */
|
/* Report that a root attribute is missing */
|
||||||
#define GENL_REQ_ATTR_CHECK(info, attr) ({ \
|
#define GENL_REQ_ATTR_CHECK(info, attr) ({ \
|
||||||
struct genl_info *__info = (info); \
|
struct genl_info *__info = (info); \
|
||||||
|
|
|
@ -912,10 +912,14 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,
|
||||||
*/
|
*/
|
||||||
if (pernet->next_id == MPTCP_PM_MAX_ADDR_ID)
|
if (pernet->next_id == MPTCP_PM_MAX_ADDR_ID)
|
||||||
pernet->next_id = 1;
|
pernet->next_id = 1;
|
||||||
if (pernet->addrs >= MPTCP_PM_ADDR_MAX)
|
if (pernet->addrs >= MPTCP_PM_ADDR_MAX) {
|
||||||
|
ret = -ERANGE;
|
||||||
goto out;
|
goto out;
|
||||||
if (test_bit(entry->addr.id, pernet->id_bitmap))
|
}
|
||||||
|
if (test_bit(entry->addr.id, pernet->id_bitmap)) {
|
||||||
|
ret = -EBUSY;
|
||||||
goto out;
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
/* do not insert duplicate address, differentiate on port only
|
/* do not insert duplicate address, differentiate on port only
|
||||||
* singled addresses
|
* singled addresses
|
||||||
|
@ -929,8 +933,10 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,
|
||||||
* endpoint is an implicit one and the user-space
|
* endpoint is an implicit one and the user-space
|
||||||
* did not provide an endpoint id
|
* did not provide an endpoint id
|
||||||
*/
|
*/
|
||||||
if (!(cur->flags & MPTCP_PM_ADDR_FLAG_IMPLICIT))
|
if (!(cur->flags & MPTCP_PM_ADDR_FLAG_IMPLICIT)) {
|
||||||
|
ret = -EEXIST;
|
||||||
goto out;
|
goto out;
|
||||||
|
}
|
||||||
if (entry->addr.id)
|
if (entry->addr.id)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -1003,16 +1009,12 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk,
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
msk = mptcp_sk(entry->lsk->sk);
|
msk = mptcp_sk(entry->lsk->sk);
|
||||||
if (!msk) {
|
if (!msk)
|
||||||
err = -EINVAL;
|
return -EINVAL;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
ssock = __mptcp_nmpc_socket(msk);
|
ssock = __mptcp_nmpc_socket(msk);
|
||||||
if (!ssock) {
|
if (!ssock)
|
||||||
err = -EINVAL;
|
return -EINVAL;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
mptcp_info2sockaddr(&entry->addr, &addr, entry->addr.family);
|
mptcp_info2sockaddr(&entry->addr, &addr, entry->addr.family);
|
||||||
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
|
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
|
||||||
|
@ -1020,22 +1022,14 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk,
|
||||||
addrlen = sizeof(struct sockaddr_in6);
|
addrlen = sizeof(struct sockaddr_in6);
|
||||||
#endif
|
#endif
|
||||||
err = kernel_bind(ssock, (struct sockaddr *)&addr, addrlen);
|
err = kernel_bind(ssock, (struct sockaddr *)&addr, addrlen);
|
||||||
if (err) {
|
if (err)
|
||||||
pr_warn("kernel_bind error, err=%d", err);
|
return err;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = kernel_listen(ssock, backlog);
|
err = kernel_listen(ssock, backlog);
|
||||||
if (err) {
|
if (err)
|
||||||
pr_warn("kernel_listen error, err=%d", err);
|
return err;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out:
|
|
||||||
sock_release(entry->lsk);
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
|
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)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
entry = kmalloc(sizeof(*entry), GFP_KERNEL_ACCOUNT);
|
entry = kzalloc(sizeof(*entry), GFP_KERNEL_ACCOUNT);
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
GENL_SET_ERR_MSG(info, "can't allocate addr");
|
GENL_SET_ERR_MSG(info, "can't allocate addr");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
@ -1337,23 +1331,22 @@ static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info)
|
||||||
if (entry->addr.port) {
|
if (entry->addr.port) {
|
||||||
ret = mptcp_pm_nl_create_listen_socket(skb->sk, entry);
|
ret = mptcp_pm_nl_create_listen_socket(skb->sk, entry);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
GENL_SET_ERR_MSG(info, "create listen socket error");
|
GENL_SET_ERR_MSG_FMT(info, "create listen socket error: %d", ret);
|
||||||
kfree(entry);
|
goto out_free;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret = mptcp_pm_nl_append_new_local_addr(pernet, entry);
|
ret = mptcp_pm_nl_append_new_local_addr(pernet, entry);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
GENL_SET_ERR_MSG(info, "too many addresses or duplicate one");
|
GENL_SET_ERR_MSG_FMT(info, "too many addresses or duplicate one: %d", ret);
|
||||||
if (entry->lsk)
|
goto out_free;
|
||||||
sock_release(entry->lsk);
|
|
||||||
kfree(entry);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mptcp_nl_add_subflow_or_signal_addr(sock_net(skb->sk));
|
mptcp_nl_add_subflow_or_signal_addr(sock_net(skb->sk));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
out_free:
|
||||||
|
__mptcp_pm_release_addr_entry(entry);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id,
|
int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id,
|
||||||
|
|
Loading…
Add table
Reference in a new issue