@@ -1796,21 +1796,7 @@ static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
{
struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
struct mptcp_pm_addr_entry *entry;
- struct sk_buff *msg;
int ret = -EINVAL;
- void *reply;
-
- 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;
- }
spin_lock_bh(&pernet->lock);
entry = __lookup_addr_by_id(pernet, id);
@@ -1820,21 +1806,6 @@ static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
}
spin_unlock_bh(&pernet->lock);
- if (ret) {
- GENL_SET_ERR_MSG(info, "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;
}
@@ -1850,13 +1821,42 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info)
{
struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
struct mptcp_pm_addr_entry addr;
+ 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;
+ }
+
ret = mptcp_pm_get_addr(addr.addr.id, &addr, info);
+ if (ret) {
+ GENL_SET_ERR_MSG(info, "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;
}
@@ -634,10 +634,8 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
{
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)
@@ -645,20 +643,6 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
sk = (struct sock *)msk;
- 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, id);
@@ -669,23 +653,6 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
spin_unlock_bh(&msk->pm.lock);
release_sock(sk);
- if (ret) {
- GENL_SET_ERR_MSG(info, "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);
- sock_put(sk);
- return ret;
-
-fail:
- nlmsg_free(msg);
-out:
sock_put(sk);
return ret;
}