Merge branch 'mptcp-pm-misc-cleanups-part-2'
Matthieu Baerts says: ==================== mptcp: pm: misc cleanups, part 2 These cleanups lead the way to the unification of the path-manager interfaces, and allow future extensions. The following patches are not all linked to each others, but are all related to the path-managers. - Patch 1: drop unneeded parameter in a function helper. - Patch 2: clearer NL error message when an NL attribute is missing. - Patch 3: more precise NL messages by avoiding 'this or that is NOK'. - Patch 4: improve too vague or missing NL err messages. - Patch 5: use GENL_REQ_ATTR_CHECK to look for mandatory NL attributes. - Patch 6: avoid overriding the error message. - Patch 7: check all mandatory NL attributes with GENL_REQ_ATTR_CHECK. - Patch 8: use NL_SET_ERR_MSG_ATTR instead of GENL_SET_ERR_MSG - Patch 9: move doit callbacks used for both PM to pm.c. - Patch 10: drop another unneeded parameter in a function helper. - Patch 11: share the ID parsing code for the 'get_addr' callback. - Patch 12: share sending NL code for the 'get_addr' callback. - Patch 13: drop yet another unneeded parameter in a function helper. - Patch 14: pick the usual structure type for the remote address. - Patch 15: share the local addr parsing code for the 'set_flags' cb. The behaviour when there are no errors should then not be modified. Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> ==================== v2: https://lore.kernel.org/r/20250117-net-next-mptcp-pm-misc-cleanup-2-v2-0-61d4fe0586e8@kernel.org v1: https://lore.kernel.org/r/20250116-net-next-mptcp-pm-misc-cleanup-2-v1-0-c0b43f18fe06@kernel.org Link: https://patch.msgid.link/20250207-net-next-mptcp-pm-misc-cleanup-2-v3-0-71753ed957de@kernel.org Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
+79
-7
@@ -10,6 +10,7 @@
|
||||
#include "protocol.h"
|
||||
|
||||
#include "mib.h"
|
||||
#include "mptcp_pm_gen.h"
|
||||
|
||||
/* path manager command handlers */
|
||||
|
||||
@@ -433,14 +434,62 @@ bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc)
|
||||
return mptcp_pm_nl_is_backup(msk, &skc_local);
|
||||
}
|
||||
|
||||
int mptcp_pm_get_addr(struct sk_buff *skb, 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(skb, info);
|
||||
return mptcp_pm_nl_get_addr(skb, info);
|
||||
return mptcp_userspace_pm_get_addr(id, addr, info);
|
||||
return mptcp_pm_nl_get_addr(id, addr, info);
|
||||
}
|
||||
|
||||
int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb)
|
||||
int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info)
|
||||
{
|
||||
struct mptcp_pm_addr_entry addr;
|
||||
struct nlattr *attr;
|
||||
struct sk_buff *msg;
|
||||
void *reply;
|
||||
int ret;
|
||||
|
||||
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR))
|
||||
return -EINVAL;
|
||||
|
||||
attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
|
||||
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) {
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, attr, "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;
|
||||
}
|
||||
|
||||
static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb)
|
||||
{
|
||||
const struct genl_info *info = genl_info_dump(cb);
|
||||
|
||||
@@ -449,11 +498,34 @@ int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb)
|
||||
return mptcp_pm_nl_dump_addr(msg, cb);
|
||||
}
|
||||
|
||||
int mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
|
||||
int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg,
|
||||
struct netlink_callback *cb)
|
||||
{
|
||||
return mptcp_pm_dump_addr(msg, cb);
|
||||
}
|
||||
|
||||
static int mptcp_pm_set_flags(struct genl_info *info)
|
||||
{
|
||||
struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, };
|
||||
struct nlattr *attr_loc;
|
||||
int ret = -EINVAL;
|
||||
|
||||
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR))
|
||||
return ret;
|
||||
|
||||
attr_loc = info->attrs[MPTCP_PM_ATTR_ADDR];
|
||||
ret = mptcp_pm_parse_entry(attr_loc, info, false, &loc);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
if (info->attrs[MPTCP_PM_ATTR_TOKEN])
|
||||
return mptcp_userspace_pm_set_flags(skb, info);
|
||||
return mptcp_pm_nl_set_flags(skb, info);
|
||||
return mptcp_userspace_pm_set_flags(&loc, info);
|
||||
return mptcp_pm_nl_set_flags(&loc, info);
|
||||
}
|
||||
|
||||
int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info)
|
||||
{
|
||||
return mptcp_pm_set_flags(info);
|
||||
}
|
||||
|
||||
void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)
|
||||
|
||||
+45
-84
@@ -1393,28 +1393,35 @@ static bool mptcp_pm_has_addr_attr_id(const struct nlattr *attr,
|
||||
|
||||
int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, 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 nlattr *attr;
|
||||
int ret;
|
||||
|
||||
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR))
|
||||
return -EINVAL;
|
||||
|
||||
attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
|
||||
ret = mptcp_pm_parse_entry(attr, info, true, &addr);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
if (addr.addr.port && !address_use_port(&addr)) {
|
||||
GENL_SET_ERR_MSG(info, "flags must have signal and not subflow when using port");
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, attr,
|
||||
"flags must have signal and not subflow when using port");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (addr.flags & MPTCP_PM_ADDR_FLAG_SIGNAL &&
|
||||
addr.flags & MPTCP_PM_ADDR_FLAG_FULLMESH) {
|
||||
GENL_SET_ERR_MSG(info, "flags mustn't have both signal and fullmesh");
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, attr,
|
||||
"flags mustn't have both signal and fullmesh");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (addr.flags & MPTCP_PM_ADDR_FLAG_IMPLICIT) {
|
||||
GENL_SET_ERR_MSG(info, "can't create IMPLICIT endpoint");
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, attr,
|
||||
"can't create IMPLICIT endpoint");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -1587,12 +1594,16 @@ next:
|
||||
|
||||
int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, 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;
|
||||
unsigned int addr_max;
|
||||
struct nlattr *attr;
|
||||
int ret;
|
||||
|
||||
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR))
|
||||
return -EINVAL;
|
||||
|
||||
attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
|
||||
ret = mptcp_pm_parse_entry(attr, info, false, &addr);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
@@ -1608,7 +1619,7 @@ int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, struct genl_info *info)
|
||||
spin_lock_bh(&pernet->lock);
|
||||
entry = __lookup_addr_by_id(pernet, addr.addr.id);
|
||||
if (!entry) {
|
||||
GENL_SET_ERR_MSG(info, "address not found");
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, attr, "address not found");
|
||||
spin_unlock_bh(&pernet->lock);
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -1762,61 +1773,24 @@ nla_put_failure:
|
||||
return -EMSGSIZE;
|
||||
}
|
||||
|
||||
int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info)
|
||||
int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
|
||||
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 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;
|
||||
}
|
||||
struct mptcp_pm_addr_entry *entry;
|
||||
int ret = -EINVAL;
|
||||
|
||||
rcu_read_lock();
|
||||
entry = __lookup_addr_by_id(pernet, addr.addr.id);
|
||||
if (!entry) {
|
||||
GENL_SET_ERR_MSG(info, "address not found");
|
||||
ret = -EINVAL;
|
||||
goto unlock_fail;
|
||||
entry = __lookup_addr_by_id(pernet, id);
|
||||
if (entry) {
|
||||
*addr = *entry;
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
ret = mptcp_nl_fill_addr(msg, entry);
|
||||
if (ret)
|
||||
goto unlock_fail;
|
||||
|
||||
genlmsg_end(msg, reply);
|
||||
ret = genlmsg_reply(msg, info);
|
||||
rcu_read_unlock();
|
||||
return ret;
|
||||
|
||||
unlock_fail:
|
||||
rcu_read_unlock();
|
||||
|
||||
fail:
|
||||
nlmsg_free(msg);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info)
|
||||
{
|
||||
return mptcp_pm_get_addr(skb, info);
|
||||
}
|
||||
|
||||
int mptcp_pm_nl_dump_addr(struct sk_buff *msg,
|
||||
struct netlink_callback *cb)
|
||||
{
|
||||
@@ -1860,12 +1834,6 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg,
|
||||
return msg->len;
|
||||
}
|
||||
|
||||
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];
|
||||
@@ -1875,7 +1843,9 @@ static int parse_limit(struct genl_info *info, int id, unsigned int *limit)
|
||||
|
||||
*limit = nla_get_u32(attr);
|
||||
if (*limit > MPTCP_PM_ADDR_MAX) {
|
||||
GENL_SET_ERR_MSG(info, "limit greater than maximum");
|
||||
NL_SET_ERR_MSG_ATTR_FMT(info->extack, attr,
|
||||
"limit greater than maximum (%u)",
|
||||
MPTCP_PM_ADDR_MAX);
|
||||
return -EINVAL;
|
||||
}
|
||||
return 0;
|
||||
@@ -1981,66 +1951,57 @@ next:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info)
|
||||
int mptcp_pm_nl_set_flags(struct mptcp_pm_addr_entry *local,
|
||||
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 net *net = sock_net(skb->sk);
|
||||
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) {
|
||||
if (local->addr.family == AF_UNSPEC) {
|
||||
lookup_by_id = 1;
|
||||
if (!addr.addr.id) {
|
||||
GENL_SET_ERR_MSG(info, "missing required inputs");
|
||||
if (!local->addr.id) {
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, attr,
|
||||
"missing address ID");
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
}
|
||||
|
||||
if (addr.flags & MPTCP_PM_ADDR_FLAG_BACKUP)
|
||||
if (local->flags & MPTCP_PM_ADDR_FLAG_BACKUP)
|
||||
bkup = 1;
|
||||
|
||||
spin_lock_bh(&pernet->lock);
|
||||
entry = lookup_by_id ? __lookup_addr_by_id(pernet, addr.addr.id) :
|
||||
__lookup_addr(pernet, &addr.addr);
|
||||
entry = lookup_by_id ? __lookup_addr_by_id(pernet, local->addr.id) :
|
||||
__lookup_addr(pernet, &local->addr);
|
||||
if (!entry) {
|
||||
spin_unlock_bh(&pernet->lock);
|
||||
GENL_SET_ERR_MSG(info, "address not found");
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, attr, "address not found");
|
||||
return -EINVAL;
|
||||
}
|
||||
if ((addr.flags & MPTCP_PM_ADDR_FLAG_FULLMESH) &&
|
||||
if ((local->flags & MPTCP_PM_ADDR_FLAG_FULLMESH) &&
|
||||
(entry->flags & (MPTCP_PM_ADDR_FLAG_SIGNAL |
|
||||
MPTCP_PM_ADDR_FLAG_IMPLICIT))) {
|
||||
spin_unlock_bh(&pernet->lock);
|
||||
GENL_SET_ERR_MSG(info, "invalid addr flags");
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, attr, "invalid addr flags");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
changed = (addr.flags ^ entry->flags) & mask;
|
||||
entry->flags = (entry->flags & ~mask) | (addr.flags & mask);
|
||||
addr = *entry;
|
||||
changed = (local->flags ^ entry->flags) & mask;
|
||||
entry->flags = (entry->flags & ~mask) | (local->flags & mask);
|
||||
*local = *entry;
|
||||
spin_unlock_bh(&pernet->lock);
|
||||
|
||||
mptcp_nl_set_flags(net, &addr.addr, bkup, changed);
|
||||
mptcp_nl_set_flags(net, &local->addr, bkup, changed);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info)
|
||||
{
|
||||
return mptcp_pm_set_flags(skb, info);
|
||||
}
|
||||
|
||||
static void mptcp_nl_mcast_send(struct net *net, struct sk_buff *nlskb, gfp_t gfp)
|
||||
{
|
||||
genlmsg_multicast_netns(&mptcp_genl_family, net,
|
||||
|
||||
+94
-115
@@ -175,14 +175,13 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk,
|
||||
|
||||
static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *info)
|
||||
{
|
||||
struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN];
|
||||
struct mptcp_sock *msk;
|
||||
struct nlattr *token;
|
||||
|
||||
if (!token) {
|
||||
GENL_SET_ERR_MSG(info, "missing required token");
|
||||
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_TOKEN))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
token = info->attrs[MPTCP_PM_ATTR_TOKEN];
|
||||
msk = mptcp_token_get_sock(genl_info_net(info), nla_get_u32(token));
|
||||
if (!msk) {
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token");
|
||||
@@ -190,7 +189,8 @@ static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *in
|
||||
}
|
||||
|
||||
if (!mptcp_pm_is_userspace(msk)) {
|
||||
GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected");
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, token,
|
||||
"userspace PM not selected");
|
||||
sock_put((struct sock *)msk);
|
||||
return NULL;
|
||||
}
|
||||
@@ -200,16 +200,14 @@ static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *in
|
||||
|
||||
int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info)
|
||||
{
|
||||
struct nlattr *addr = info->attrs[MPTCP_PM_ATTR_ADDR];
|
||||
struct mptcp_pm_addr_entry addr_val;
|
||||
struct mptcp_sock *msk;
|
||||
struct nlattr *addr;
|
||||
int err = -EINVAL;
|
||||
struct sock *sk;
|
||||
|
||||
if (!addr) {
|
||||
GENL_SET_ERR_MSG(info, "missing required address");
|
||||
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR))
|
||||
return err;
|
||||
}
|
||||
|
||||
msk = mptcp_userspace_pm_get_sock(info);
|
||||
if (!msk)
|
||||
@@ -217,21 +215,27 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info)
|
||||
|
||||
sk = (struct sock *)msk;
|
||||
|
||||
addr = info->attrs[MPTCP_PM_ATTR_ADDR];
|
||||
err = mptcp_pm_parse_entry(addr, info, true, &addr_val);
|
||||
if (err < 0) {
|
||||
GENL_SET_ERR_MSG(info, "error parsing local address");
|
||||
if (err < 0)
|
||||
goto announce_err;
|
||||
|
||||
if (addr_val.addr.id == 0) {
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, addr, "invalid addr id");
|
||||
err = -EINVAL;
|
||||
goto announce_err;
|
||||
}
|
||||
|
||||
if (addr_val.addr.id == 0 || !(addr_val.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
|
||||
GENL_SET_ERR_MSG(info, "invalid addr id or flags");
|
||||
if (!(addr_val.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, addr, "invalid addr flags");
|
||||
err = -EINVAL;
|
||||
goto announce_err;
|
||||
}
|
||||
|
||||
err = mptcp_userspace_pm_append_new_local_addr(msk, &addr_val, false);
|
||||
if (err < 0) {
|
||||
GENL_SET_ERR_MSG(info, "did not match address and id");
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, addr,
|
||||
"did not match address and id");
|
||||
goto announce_err;
|
||||
}
|
||||
|
||||
@@ -253,8 +257,7 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info)
|
||||
return err;
|
||||
}
|
||||
|
||||
static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk,
|
||||
struct genl_info *info)
|
||||
static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk)
|
||||
{
|
||||
struct mptcp_rm_list list = { .nr = 0 };
|
||||
struct mptcp_subflow_context *subflow;
|
||||
@@ -269,10 +272,8 @@ static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk,
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!has_id_0) {
|
||||
GENL_SET_ERR_MSG(info, "address with id 0 not found");
|
||||
if (!has_id_0)
|
||||
goto remove_err;
|
||||
}
|
||||
|
||||
list.ids[list.nr++] = 0;
|
||||
|
||||
@@ -309,18 +310,17 @@ void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk,
|
||||
|
||||
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_sock *msk;
|
||||
struct nlattr *id;
|
||||
int err = -EINVAL;
|
||||
struct sock *sk;
|
||||
u8 id_val;
|
||||
|
||||
if (!id) {
|
||||
GENL_SET_ERR_MSG(info, "missing required ID");
|
||||
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_LOC_ID))
|
||||
return err;
|
||||
}
|
||||
|
||||
id = info->attrs[MPTCP_PM_ATTR_LOC_ID];
|
||||
id_val = nla_get_u8(id);
|
||||
|
||||
msk = mptcp_userspace_pm_get_sock(info);
|
||||
@@ -330,7 +330,7 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)
|
||||
sk = (struct sock *)msk;
|
||||
|
||||
if (id_val == 0) {
|
||||
err = mptcp_userspace_pm_remove_id_zero_address(msk, info);
|
||||
err = mptcp_userspace_pm_remove_id_zero_address(msk);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -339,7 +339,6 @@ 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);
|
||||
if (!match) {
|
||||
GENL_SET_ERR_MSG(info, "address with specified id not found");
|
||||
spin_unlock_bh(&msk->pm.lock);
|
||||
release_sock(sk);
|
||||
goto out;
|
||||
@@ -356,25 +355,28 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)
|
||||
|
||||
err = 0;
|
||||
out:
|
||||
if (err)
|
||||
NL_SET_ERR_MSG_ATTR_FMT(info->extack, id,
|
||||
"address with id %u not found",
|
||||
id_val);
|
||||
|
||||
sock_put(sk);
|
||||
return err;
|
||||
}
|
||||
|
||||
int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
|
||||
{
|
||||
struct nlattr *raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
|
||||
struct nlattr *laddr = info->attrs[MPTCP_PM_ATTR_ADDR];
|
||||
struct mptcp_pm_addr_entry entry = { 0 };
|
||||
struct mptcp_addr_info addr_r;
|
||||
struct nlattr *raddr, *laddr;
|
||||
struct mptcp_pm_local local;
|
||||
struct mptcp_sock *msk;
|
||||
int err = -EINVAL;
|
||||
struct sock *sk;
|
||||
|
||||
if (!laddr || !raddr) {
|
||||
GENL_SET_ERR_MSG(info, "missing required address(es)");
|
||||
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR) ||
|
||||
GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR_REMOTE))
|
||||
return err;
|
||||
}
|
||||
|
||||
msk = mptcp_userspace_pm_get_sock(info);
|
||||
if (!msk)
|
||||
@@ -382,24 +384,22 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
|
||||
|
||||
sk = (struct sock *)msk;
|
||||
|
||||
laddr = info->attrs[MPTCP_PM_ATTR_ADDR];
|
||||
err = mptcp_pm_parse_entry(laddr, info, true, &entry);
|
||||
if (err < 0) {
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr");
|
||||
if (err < 0)
|
||||
goto create_err;
|
||||
}
|
||||
|
||||
if (entry.flags & MPTCP_PM_ADDR_FLAG_SIGNAL) {
|
||||
GENL_SET_ERR_MSG(info, "invalid addr flags");
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, laddr, "invalid addr flags");
|
||||
err = -EINVAL;
|
||||
goto create_err;
|
||||
}
|
||||
entry.flags |= MPTCP_PM_ADDR_FLAG_SUBFLOW;
|
||||
|
||||
raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
|
||||
err = mptcp_pm_parse_addr(raddr, info, &addr_r);
|
||||
if (err < 0) {
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, raddr, "error parsing remote addr");
|
||||
if (err < 0)
|
||||
goto create_err;
|
||||
}
|
||||
|
||||
if (!mptcp_pm_addr_families_match(sk, &entry.addr, &addr_r)) {
|
||||
GENL_SET_ERR_MSG(info, "families mismatch");
|
||||
@@ -409,7 +409,8 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
|
||||
|
||||
err = mptcp_userspace_pm_append_new_local_addr(msk, &entry, false);
|
||||
if (err < 0) {
|
||||
GENL_SET_ERR_MSG(info, "did not match address and id");
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, laddr,
|
||||
"did not match address and id");
|
||||
goto create_err;
|
||||
}
|
||||
|
||||
@@ -421,6 +422,9 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
|
||||
err = __mptcp_subflow_connect(sk, &local, &addr_r);
|
||||
release_sock(sk);
|
||||
|
||||
if (err)
|
||||
GENL_SET_ERR_MSG_FMT(info, "connect error: %d", err);
|
||||
|
||||
spin_lock_bh(&msk->pm.lock);
|
||||
if (err)
|
||||
mptcp_userspace_pm_delete_local_addr(msk, &entry);
|
||||
@@ -483,18 +487,16 @@ static struct sock *mptcp_nl_find_ssk(struct mptcp_sock *msk,
|
||||
|
||||
int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info)
|
||||
{
|
||||
struct nlattr *raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
|
||||
struct nlattr *laddr = info->attrs[MPTCP_PM_ATTR_ADDR];
|
||||
struct mptcp_pm_addr_entry addr_l;
|
||||
struct mptcp_addr_info addr_r;
|
||||
struct nlattr *raddr, *laddr;
|
||||
struct mptcp_sock *msk;
|
||||
struct sock *sk, *ssk;
|
||||
int err = -EINVAL;
|
||||
|
||||
if (!laddr || !raddr) {
|
||||
GENL_SET_ERR_MSG(info, "missing required address(es)");
|
||||
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR) ||
|
||||
GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR_REMOTE))
|
||||
return err;
|
||||
}
|
||||
|
||||
msk = mptcp_userspace_pm_get_sock(info);
|
||||
if (!msk)
|
||||
@@ -502,17 +504,15 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info
|
||||
|
||||
sk = (struct sock *)msk;
|
||||
|
||||
laddr = info->attrs[MPTCP_PM_ATTR_ADDR];
|
||||
err = mptcp_pm_parse_entry(laddr, info, true, &addr_l);
|
||||
if (err < 0) {
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr");
|
||||
if (err < 0)
|
||||
goto destroy_err;
|
||||
}
|
||||
|
||||
raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
|
||||
err = mptcp_pm_parse_addr(raddr, info, &addr_r);
|
||||
if (err < 0) {
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, raddr, "error parsing remote addr");
|
||||
if (err < 0)
|
||||
goto destroy_err;
|
||||
}
|
||||
|
||||
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
|
||||
if (addr_l.addr.family == AF_INET && ipv6_addr_v4mapped(&addr_r.addr6)) {
|
||||
@@ -530,8 +530,14 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info
|
||||
goto destroy_err;
|
||||
}
|
||||
|
||||
if (!addr_l.addr.port || !addr_r.port) {
|
||||
GENL_SET_ERR_MSG(info, "missing local or remote port");
|
||||
if (!addr_l.addr.port) {
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, laddr, "missing local port");
|
||||
err = -EINVAL;
|
||||
goto destroy_err;
|
||||
}
|
||||
|
||||
if (!addr_r.port) {
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, raddr, "missing remote port");
|
||||
err = -EINVAL;
|
||||
goto destroy_err;
|
||||
}
|
||||
@@ -539,6 +545,7 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info
|
||||
lock_sock(sk);
|
||||
ssk = mptcp_nl_find_ssk(msk, &addr_l.addr, &addr_r);
|
||||
if (!ssk) {
|
||||
GENL_SET_ERR_MSG(info, "subflow not found");
|
||||
err = -ESRCH;
|
||||
goto release_sock;
|
||||
}
|
||||
@@ -557,46 +564,51 @@ destroy_err:
|
||||
return err;
|
||||
}
|
||||
|
||||
int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
|
||||
int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *local,
|
||||
struct genl_info *info)
|
||||
{
|
||||
struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, };
|
||||
struct mptcp_pm_addr_entry rem = { .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_pm_addr_entry *entry;
|
||||
struct nlattr *attr, *attr_rem;
|
||||
struct mptcp_sock *msk;
|
||||
int ret = -EINVAL;
|
||||
struct sock *sk;
|
||||
u8 bkup = 0;
|
||||
|
||||
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR_REMOTE))
|
||||
return ret;
|
||||
|
||||
msk = mptcp_userspace_pm_get_sock(info);
|
||||
if (!msk)
|
||||
return ret;
|
||||
|
||||
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_entry(attr_rem, info, false, &rem);
|
||||
if (ret < 0)
|
||||
goto set_flags_err;
|
||||
}
|
||||
|
||||
if (loc.addr.family == AF_UNSPEC ||
|
||||
rem.addr.family == AF_UNSPEC) {
|
||||
GENL_SET_ERR_MSG(info, "invalid address families");
|
||||
attr = info->attrs[MPTCP_PM_ATTR_ADDR];
|
||||
if (local->addr.family == AF_UNSPEC) {
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, attr,
|
||||
"invalid local address family");
|
||||
ret = -EINVAL;
|
||||
goto set_flags_err;
|
||||
}
|
||||
|
||||
if (loc.flags & MPTCP_PM_ADDR_FLAG_BACKUP)
|
||||
attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
|
||||
ret = mptcp_pm_parse_addr(attr_rem, info, &rem);
|
||||
if (ret < 0)
|
||||
goto set_flags_err;
|
||||
|
||||
if (rem.family == AF_UNSPEC) {
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, attr_rem,
|
||||
"invalid remote address family");
|
||||
ret = -EINVAL;
|
||||
goto set_flags_err;
|
||||
}
|
||||
|
||||
if (local->flags & MPTCP_PM_ADDR_FLAG_BACKUP)
|
||||
bkup = 1;
|
||||
|
||||
spin_lock_bh(&msk->pm.lock);
|
||||
entry = mptcp_userspace_pm_lookup_addr(msk, &loc.addr);
|
||||
entry = mptcp_userspace_pm_lookup_addr(msk, &local->addr);
|
||||
if (entry) {
|
||||
if (bkup)
|
||||
entry->flags |= MPTCP_PM_ADDR_FLAG_BACKUP;
|
||||
@@ -606,9 +618,13 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
|
||||
spin_unlock_bh(&msk->pm.lock);
|
||||
|
||||
lock_sock(sk);
|
||||
ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc.addr, &rem.addr, bkup);
|
||||
ret = mptcp_pm_nl_mp_prio_send_ack(msk, &local->addr, &rem, bkup);
|
||||
release_sock(sk);
|
||||
|
||||
/* mptcp_pm_nl_mp_prio_send_ack() only fails in one case */
|
||||
if (ret < 0)
|
||||
GENL_SET_ERR_MSG(info, "subflow not found");
|
||||
|
||||
set_flags_err:
|
||||
sock_put(sk);
|
||||
return ret;
|
||||
@@ -663,16 +679,13 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int mptcp_userspace_pm_get_addr(struct sk_buff *skb,
|
||||
int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
|
||||
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;
|
||||
struct sock *sk;
|
||||
void *reply;
|
||||
|
||||
msk = mptcp_userspace_pm_get_sock(info);
|
||||
if (!msk)
|
||||
@@ -680,50 +693,16 @@ int mptcp_userspace_pm_get_addr(struct sk_buff *skb,
|
||||
|
||||
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;
|
||||
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, addr.addr.id);
|
||||
if (!entry) {
|
||||
GENL_SET_ERR_MSG(info, "address not found");
|
||||
ret = -EINVAL;
|
||||
goto unlock_fail;
|
||||
entry = mptcp_userspace_pm_lookup_addr_by_id(msk, id);
|
||||
if (entry) {
|
||||
*addr = *entry;
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
ret = mptcp_nl_fill_addr(msg, entry);
|
||||
if (ret)
|
||||
goto unlock_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:
|
||||
sock_put(sk);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1038,9 +1038,10 @@ bool mptcp_lookup_subflow_by_saddr(const struct list_head *list,
|
||||
const struct mptcp_addr_info *saddr);
|
||||
bool mptcp_remove_anno_list_by_saddr(struct mptcp_sock *msk,
|
||||
const struct mptcp_addr_info *addr);
|
||||
int mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info);
|
||||
int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info);
|
||||
int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info);
|
||||
int mptcp_pm_nl_set_flags(struct mptcp_pm_addr_entry *local,
|
||||
struct genl_info *info);
|
||||
int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *local,
|
||||
struct genl_info *info);
|
||||
int mptcp_pm_announce_addr(struct mptcp_sock *msk,
|
||||
const struct mptcp_addr_info *addr,
|
||||
bool echo);
|
||||
@@ -1131,14 +1132,13 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_in
|
||||
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);
|
||||
int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb);
|
||||
int mptcp_pm_nl_dump_addr(struct sk_buff *msg,
|
||||
struct netlink_callback *cb);
|
||||
int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,
|
||||
struct netlink_callback *cb);
|
||||
int mptcp_pm_get_addr(struct sk_buff *skb, struct genl_info *info);
|
||||
int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info);
|
||||
int mptcp_userspace_pm_get_addr(struct sk_buff *skb,
|
||||
int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user