1 // SPDX-License-Identifier: GPL-2.0 2 /* Multipath TCP 3 * 4 * Copyright (c) 2022, Intel Corporation. 5 */ 6 7 #include "protocol.h" 8 #include "mib.h" 9 #include "mptcp_pm_gen.h" 10 11 #define mptcp_for_each_userspace_pm_addr(__msk, __entry) \ 12 list_for_each_entry(__entry, \ 13 &((__msk)->pm.userspace_pm_local_addr_list), list) 14 15 void mptcp_free_local_addr_list(struct mptcp_sock *msk) 16 { 17 struct mptcp_pm_addr_entry *entry, *tmp; 18 struct sock *sk = (struct sock *)msk; 19 LIST_HEAD(free_list); 20 21 if (!mptcp_pm_is_userspace(msk)) 22 return; 23 24 spin_lock_bh(&msk->pm.lock); 25 list_splice_init(&msk->pm.userspace_pm_local_addr_list, &free_list); 26 spin_unlock_bh(&msk->pm.lock); 27 28 list_for_each_entry_safe(entry, tmp, &free_list, list) { 29 sock_kfree_s(sk, entry, sizeof(*entry)); 30 } 31 } 32 33 static struct mptcp_pm_addr_entry * 34 mptcp_userspace_pm_lookup_addr(struct mptcp_sock *msk, 35 const struct mptcp_addr_info *addr) 36 { 37 struct mptcp_pm_addr_entry *entry; 38 39 mptcp_for_each_userspace_pm_addr(msk, entry) { 40 if (mptcp_addresses_equal(&entry->addr, addr, false)) 41 return entry; 42 } 43 return NULL; 44 } 45 46 static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, 47 struct mptcp_pm_addr_entry *entry, 48 bool needs_id) 49 { 50 DECLARE_BITMAP(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); 51 struct mptcp_pm_addr_entry *match = NULL; 52 struct sock *sk = (struct sock *)msk; 53 struct mptcp_pm_addr_entry *e; 54 bool addr_match = false; 55 bool id_match = false; 56 int ret = -EINVAL; 57 58 bitmap_zero(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); 59 60 spin_lock_bh(&msk->pm.lock); 61 mptcp_for_each_userspace_pm_addr(msk, e) { 62 addr_match = mptcp_addresses_equal(&e->addr, &entry->addr, true); 63 if (addr_match && entry->addr.id == 0 && needs_id) 64 entry->addr.id = e->addr.id; 65 id_match = (e->addr.id == entry->addr.id); 66 if (addr_match && id_match) { 67 match = e; 68 break; 69 } else if (addr_match || id_match) { 70 break; 71 } 72 __set_bit(e->addr.id, id_bitmap); 73 } 74 75 if (!match && !addr_match && !id_match) { 76 /* Memory for the entry is allocated from the 77 * sock option buffer. 78 */ 79 e = sock_kmalloc(sk, sizeof(*e), GFP_ATOMIC); 80 if (!e) { 81 ret = -ENOMEM; 82 goto append_err; 83 } 84 85 *e = *entry; 86 if (!e->addr.id && needs_id) 87 e->addr.id = find_next_zero_bit(id_bitmap, 88 MPTCP_PM_MAX_ADDR_ID + 1, 89 1); 90 list_add_tail_rcu(&e->list, &msk->pm.userspace_pm_local_addr_list); 91 msk->pm.local_addr_used++; 92 ret = e->addr.id; 93 } else if (match) { 94 ret = entry->addr.id; 95 } 96 97 append_err: 98 spin_unlock_bh(&msk->pm.lock); 99 return ret; 100 } 101 102 /* If the subflow is closed from the other peer (not via a 103 * subflow destroy command then), we want to keep the entry 104 * not to assign the same ID to another address and to be 105 * able to send RM_ADDR after the removal of the subflow. 106 */ 107 static int mptcp_userspace_pm_delete_local_addr(struct mptcp_sock *msk, 108 struct mptcp_pm_addr_entry *addr) 109 { 110 struct sock *sk = (struct sock *)msk; 111 struct mptcp_pm_addr_entry *entry; 112 113 entry = mptcp_userspace_pm_lookup_addr(msk, &addr->addr); 114 if (!entry) 115 return -EINVAL; 116 117 /* TODO: a refcount is needed because the entry can 118 * be used multiple times (e.g. fullmesh mode). 119 */ 120 list_del_rcu(&entry->list); 121 sock_kfree_s(sk, entry, sizeof(*entry)); 122 msk->pm.local_addr_used--; 123 return 0; 124 } 125 126 static struct mptcp_pm_addr_entry * 127 mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_sock *msk, unsigned int id) 128 { 129 struct mptcp_pm_addr_entry *entry; 130 131 mptcp_for_each_userspace_pm_addr(msk, entry) { 132 if (entry->addr.id == id) 133 return entry; 134 } 135 return NULL; 136 } 137 138 int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, 139 struct mptcp_addr_info *skc) 140 { 141 struct mptcp_pm_addr_entry *entry = NULL, new_entry; 142 __be16 msk_sport = ((struct inet_sock *) 143 inet_sk((struct sock *)msk))->inet_sport; 144 145 spin_lock_bh(&msk->pm.lock); 146 entry = mptcp_userspace_pm_lookup_addr(msk, skc); 147 spin_unlock_bh(&msk->pm.lock); 148 if (entry) 149 return entry->addr.id; 150 151 memset(&new_entry, 0, sizeof(struct mptcp_pm_addr_entry)); 152 new_entry.addr = *skc; 153 new_entry.addr.id = 0; 154 new_entry.flags = MPTCP_PM_ADDR_FLAG_IMPLICIT; 155 156 if (new_entry.addr.port == msk_sport) 157 new_entry.addr.port = 0; 158 159 return mptcp_userspace_pm_append_new_local_addr(msk, &new_entry, true); 160 } 161 162 bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, 163 struct mptcp_addr_info *skc) 164 { 165 struct mptcp_pm_addr_entry *entry; 166 bool backup; 167 168 spin_lock_bh(&msk->pm.lock); 169 entry = mptcp_userspace_pm_lookup_addr(msk, skc); 170 backup = entry && !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); 171 spin_unlock_bh(&msk->pm.lock); 172 173 return backup; 174 } 175 176 static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *info) 177 { 178 struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN]; 179 struct mptcp_sock *msk; 180 181 if (!token) { 182 GENL_SET_ERR_MSG(info, "missing required token"); 183 return NULL; 184 } 185 186 msk = mptcp_token_get_sock(genl_info_net(info), nla_get_u32(token)); 187 if (!msk) { 188 NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); 189 return NULL; 190 } 191 192 if (!mptcp_pm_is_userspace(msk)) { 193 GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); 194 sock_put((struct sock *)msk); 195 return NULL; 196 } 197 198 return msk; 199 } 200 201 int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) 202 { 203 struct nlattr *addr = info->attrs[MPTCP_PM_ATTR_ADDR]; 204 struct mptcp_pm_addr_entry addr_val; 205 struct mptcp_sock *msk; 206 int err = -EINVAL; 207 struct sock *sk; 208 209 if (!addr) { 210 GENL_SET_ERR_MSG(info, "missing required address"); 211 return err; 212 } 213 214 msk = mptcp_userspace_pm_get_sock(info); 215 if (!msk) 216 return err; 217 218 sk = (struct sock *)msk; 219 220 err = mptcp_pm_parse_entry(addr, info, true, &addr_val); 221 if (err < 0) { 222 GENL_SET_ERR_MSG(info, "error parsing local address"); 223 goto announce_err; 224 } 225 226 if (addr_val.addr.id == 0 || !(addr_val.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) { 227 GENL_SET_ERR_MSG(info, "invalid addr id or flags"); 228 err = -EINVAL; 229 goto announce_err; 230 } 231 232 err = mptcp_userspace_pm_append_new_local_addr(msk, &addr_val, false); 233 if (err < 0) { 234 GENL_SET_ERR_MSG(info, "did not match address and id"); 235 goto announce_err; 236 } 237 238 lock_sock(sk); 239 spin_lock_bh(&msk->pm.lock); 240 241 if (mptcp_pm_alloc_anno_list(msk, &addr_val.addr)) { 242 msk->pm.add_addr_signaled++; 243 mptcp_pm_announce_addr(msk, &addr_val.addr, false); 244 mptcp_pm_nl_addr_send_ack(msk); 245 } 246 247 spin_unlock_bh(&msk->pm.lock); 248 release_sock(sk); 249 250 err = 0; 251 announce_err: 252 sock_put(sk); 253 return err; 254 } 255 256 static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk, 257 struct genl_info *info) 258 { 259 struct mptcp_rm_list list = { .nr = 0 }; 260 struct mptcp_subflow_context *subflow; 261 struct sock *sk = (struct sock *)msk; 262 bool has_id_0 = false; 263 int err = -EINVAL; 264 265 lock_sock(sk); 266 mptcp_for_each_subflow(msk, subflow) { 267 if (READ_ONCE(subflow->local_id) == 0) { 268 has_id_0 = true; 269 break; 270 } 271 } 272 if (!has_id_0) { 273 GENL_SET_ERR_MSG(info, "address with id 0 not found"); 274 goto remove_err; 275 } 276 277 list.ids[list.nr++] = 0; 278 279 spin_lock_bh(&msk->pm.lock); 280 mptcp_pm_remove_addr(msk, &list); 281 spin_unlock_bh(&msk->pm.lock); 282 283 err = 0; 284 285 remove_err: 286 release_sock(sk); 287 return err; 288 } 289 290 void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk, 291 struct mptcp_pm_addr_entry *entry) 292 { 293 struct mptcp_rm_list alist = { .nr = 0 }; 294 int anno_nr = 0; 295 296 /* only delete if either announced or matching a subflow */ 297 if (mptcp_remove_anno_list_by_saddr(msk, &entry->addr)) 298 anno_nr++; 299 else if (!mptcp_lookup_subflow_by_saddr(&msk->conn_list, &entry->addr)) 300 return; 301 302 alist.ids[alist.nr++] = entry->addr.id; 303 304 spin_lock_bh(&msk->pm.lock); 305 msk->pm.add_addr_signaled -= anno_nr; 306 mptcp_pm_remove_addr(msk, &alist); 307 spin_unlock_bh(&msk->pm.lock); 308 } 309 310 int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) 311 { 312 struct nlattr *id = info->attrs[MPTCP_PM_ATTR_LOC_ID]; 313 struct mptcp_pm_addr_entry *match; 314 struct mptcp_sock *msk; 315 int err = -EINVAL; 316 struct sock *sk; 317 u8 id_val; 318 319 if (!id) { 320 GENL_SET_ERR_MSG(info, "missing required ID"); 321 return err; 322 } 323 324 id_val = nla_get_u8(id); 325 326 msk = mptcp_userspace_pm_get_sock(info); 327 if (!msk) 328 return err; 329 330 sk = (struct sock *)msk; 331 332 if (id_val == 0) { 333 err = mptcp_userspace_pm_remove_id_zero_address(msk, info); 334 goto out; 335 } 336 337 lock_sock(sk); 338 339 spin_lock_bh(&msk->pm.lock); 340 match = mptcp_userspace_pm_lookup_addr_by_id(msk, id_val); 341 if (!match) { 342 GENL_SET_ERR_MSG(info, "address with specified id not found"); 343 spin_unlock_bh(&msk->pm.lock); 344 release_sock(sk); 345 goto out; 346 } 347 348 list_del_rcu(&match->list); 349 spin_unlock_bh(&msk->pm.lock); 350 351 mptcp_pm_remove_addr_entry(msk, match); 352 353 release_sock(sk); 354 355 sock_kfree_s(sk, match, sizeof(*match)); 356 357 err = 0; 358 out: 359 sock_put(sk); 360 return err; 361 } 362 363 int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) 364 { 365 struct nlattr *raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; 366 struct nlattr *laddr = info->attrs[MPTCP_PM_ATTR_ADDR]; 367 struct mptcp_pm_addr_entry entry = { 0 }; 368 struct mptcp_addr_info addr_r; 369 struct mptcp_pm_local local; 370 struct mptcp_sock *msk; 371 int err = -EINVAL; 372 struct sock *sk; 373 374 if (!laddr || !raddr) { 375 GENL_SET_ERR_MSG(info, "missing required address(es)"); 376 return err; 377 } 378 379 msk = mptcp_userspace_pm_get_sock(info); 380 if (!msk) 381 return err; 382 383 sk = (struct sock *)msk; 384 385 err = mptcp_pm_parse_entry(laddr, info, true, &entry); 386 if (err < 0) { 387 NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr"); 388 goto create_err; 389 } 390 391 if (entry.flags & MPTCP_PM_ADDR_FLAG_SIGNAL) { 392 GENL_SET_ERR_MSG(info, "invalid addr flags"); 393 err = -EINVAL; 394 goto create_err; 395 } 396 entry.flags |= MPTCP_PM_ADDR_FLAG_SUBFLOW; 397 398 err = mptcp_pm_parse_addr(raddr, info, &addr_r); 399 if (err < 0) { 400 NL_SET_ERR_MSG_ATTR(info->extack, raddr, "error parsing remote addr"); 401 goto create_err; 402 } 403 404 if (!mptcp_pm_addr_families_match(sk, &entry.addr, &addr_r)) { 405 GENL_SET_ERR_MSG(info, "families mismatch"); 406 err = -EINVAL; 407 goto create_err; 408 } 409 410 err = mptcp_userspace_pm_append_new_local_addr(msk, &entry, false); 411 if (err < 0) { 412 GENL_SET_ERR_MSG(info, "did not match address and id"); 413 goto create_err; 414 } 415 416 local.addr = entry.addr; 417 local.flags = entry.flags; 418 local.ifindex = entry.ifindex; 419 420 lock_sock(sk); 421 err = __mptcp_subflow_connect(sk, &local, &addr_r); 422 release_sock(sk); 423 424 spin_lock_bh(&msk->pm.lock); 425 if (err) 426 mptcp_userspace_pm_delete_local_addr(msk, &entry); 427 else 428 msk->pm.subflows++; 429 spin_unlock_bh(&msk->pm.lock); 430 431 create_err: 432 sock_put(sk); 433 return err; 434 } 435 436 static struct sock *mptcp_nl_find_ssk(struct mptcp_sock *msk, 437 const struct mptcp_addr_info *local, 438 const struct mptcp_addr_info *remote) 439 { 440 struct mptcp_subflow_context *subflow; 441 442 if (local->family != remote->family) 443 return NULL; 444 445 mptcp_for_each_subflow(msk, subflow) { 446 const struct inet_sock *issk; 447 struct sock *ssk; 448 449 ssk = mptcp_subflow_tcp_sock(subflow); 450 451 if (local->family != ssk->sk_family) 452 continue; 453 454 issk = inet_sk(ssk); 455 456 switch (ssk->sk_family) { 457 case AF_INET: 458 if (issk->inet_saddr != local->addr.s_addr || 459 issk->inet_daddr != remote->addr.s_addr) 460 continue; 461 break; 462 #if IS_ENABLED(CONFIG_MPTCP_IPV6) 463 case AF_INET6: { 464 const struct ipv6_pinfo *pinfo = inet6_sk(ssk); 465 466 if (!ipv6_addr_equal(&local->addr6, &pinfo->saddr) || 467 !ipv6_addr_equal(&remote->addr6, &ssk->sk_v6_daddr)) 468 continue; 469 break; 470 } 471 #endif 472 default: 473 continue; 474 } 475 476 if (issk->inet_sport == local->port && 477 issk->inet_dport == remote->port) 478 return ssk; 479 } 480 481 return NULL; 482 } 483 484 int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info) 485 { 486 struct nlattr *raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; 487 struct nlattr *laddr = info->attrs[MPTCP_PM_ATTR_ADDR]; 488 struct mptcp_pm_addr_entry addr_l; 489 struct mptcp_addr_info addr_r; 490 struct mptcp_sock *msk; 491 struct sock *sk, *ssk; 492 int err = -EINVAL; 493 494 if (!laddr || !raddr) { 495 GENL_SET_ERR_MSG(info, "missing required address(es)"); 496 return err; 497 } 498 499 msk = mptcp_userspace_pm_get_sock(info); 500 if (!msk) 501 return err; 502 503 sk = (struct sock *)msk; 504 505 err = mptcp_pm_parse_entry(laddr, info, true, &addr_l); 506 if (err < 0) { 507 NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr"); 508 goto destroy_err; 509 } 510 511 err = mptcp_pm_parse_addr(raddr, info, &addr_r); 512 if (err < 0) { 513 NL_SET_ERR_MSG_ATTR(info->extack, raddr, "error parsing remote addr"); 514 goto destroy_err; 515 } 516 517 #if IS_ENABLED(CONFIG_MPTCP_IPV6) 518 if (addr_l.addr.family == AF_INET && ipv6_addr_v4mapped(&addr_r.addr6)) { 519 ipv6_addr_set_v4mapped(addr_l.addr.addr.s_addr, &addr_l.addr.addr6); 520 addr_l.addr.family = AF_INET6; 521 } 522 if (addr_r.family == AF_INET && ipv6_addr_v4mapped(&addr_l.addr.addr6)) { 523 ipv6_addr_set_v4mapped(addr_r.addr.s_addr, &addr_l.addr.addr6); 524 addr_r.family = AF_INET6; 525 } 526 #endif 527 if (addr_l.addr.family != addr_r.family) { 528 GENL_SET_ERR_MSG(info, "address families do not match"); 529 err = -EINVAL; 530 goto destroy_err; 531 } 532 533 if (!addr_l.addr.port || !addr_r.port) { 534 GENL_SET_ERR_MSG(info, "missing local or remote port"); 535 err = -EINVAL; 536 goto destroy_err; 537 } 538 539 lock_sock(sk); 540 ssk = mptcp_nl_find_ssk(msk, &addr_l.addr, &addr_r); 541 if (!ssk) { 542 err = -ESRCH; 543 goto release_sock; 544 } 545 546 spin_lock_bh(&msk->pm.lock); 547 mptcp_userspace_pm_delete_local_addr(msk, &addr_l); 548 spin_unlock_bh(&msk->pm.lock); 549 mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN); 550 mptcp_close_ssk(sk, ssk, mptcp_subflow_ctx(ssk)); 551 MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMSUBFLOW); 552 release_sock: 553 release_sock(sk); 554 555 destroy_err: 556 sock_put(sk); 557 return err; 558 } 559 560 int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) 561 { 562 struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, }; 563 struct mptcp_pm_addr_entry rem = { .addr = { .family = AF_UNSPEC }, }; 564 struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; 565 struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; 566 struct mptcp_pm_addr_entry *entry; 567 struct mptcp_sock *msk; 568 int ret = -EINVAL; 569 struct sock *sk; 570 u8 bkup = 0; 571 572 msk = mptcp_userspace_pm_get_sock(info); 573 if (!msk) 574 return ret; 575 576 sk = (struct sock *)msk; 577 578 ret = mptcp_pm_parse_entry(attr, info, false, &loc); 579 if (ret < 0) 580 goto set_flags_err; 581 582 if (attr_rem) { 583 ret = mptcp_pm_parse_entry(attr_rem, info, false, &rem); 584 if (ret < 0) 585 goto set_flags_err; 586 } 587 588 if (loc.addr.family == AF_UNSPEC || 589 rem.addr.family == AF_UNSPEC) { 590 GENL_SET_ERR_MSG(info, "invalid address families"); 591 ret = -EINVAL; 592 goto set_flags_err; 593 } 594 595 if (loc.flags & MPTCP_PM_ADDR_FLAG_BACKUP) 596 bkup = 1; 597 598 spin_lock_bh(&msk->pm.lock); 599 entry = mptcp_userspace_pm_lookup_addr(msk, &loc.addr); 600 if (entry) { 601 if (bkup) 602 entry->flags |= MPTCP_PM_ADDR_FLAG_BACKUP; 603 else 604 entry->flags &= ~MPTCP_PM_ADDR_FLAG_BACKUP; 605 } 606 spin_unlock_bh(&msk->pm.lock); 607 608 lock_sock(sk); 609 ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc.addr, &rem.addr, bkup); 610 release_sock(sk); 611 612 set_flags_err: 613 sock_put(sk); 614 return ret; 615 } 616 617 int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, 618 struct netlink_callback *cb) 619 { 620 struct id_bitmap { 621 DECLARE_BITMAP(map, MPTCP_PM_MAX_ADDR_ID + 1); 622 } *bitmap; 623 const struct genl_info *info = genl_info_dump(cb); 624 struct mptcp_pm_addr_entry *entry; 625 struct mptcp_sock *msk; 626 int ret = -EINVAL; 627 struct sock *sk; 628 void *hdr; 629 630 bitmap = (struct id_bitmap *)cb->ctx; 631 632 msk = mptcp_userspace_pm_get_sock(info); 633 if (!msk) 634 return ret; 635 636 sk = (struct sock *)msk; 637 638 lock_sock(sk); 639 spin_lock_bh(&msk->pm.lock); 640 mptcp_for_each_userspace_pm_addr(msk, entry) { 641 if (test_bit(entry->addr.id, bitmap->map)) 642 continue; 643 644 hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, 645 cb->nlh->nlmsg_seq, &mptcp_genl_family, 646 NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR); 647 if (!hdr) 648 break; 649 650 if (mptcp_nl_fill_addr(msg, entry) < 0) { 651 genlmsg_cancel(msg, hdr); 652 break; 653 } 654 655 __set_bit(entry->addr.id, bitmap->map); 656 genlmsg_end(msg, hdr); 657 } 658 spin_unlock_bh(&msk->pm.lock); 659 release_sock(sk); 660 ret = msg->len; 661 662 sock_put(sk); 663 return ret; 664 } 665 666 int mptcp_userspace_pm_get_addr(struct sk_buff *skb, 667 struct genl_info *info) 668 { 669 struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; 670 struct mptcp_pm_addr_entry addr, *entry; 671 struct mptcp_sock *msk; 672 struct sk_buff *msg; 673 int ret = -EINVAL; 674 struct sock *sk; 675 void *reply; 676 677 msk = mptcp_userspace_pm_get_sock(info); 678 if (!msk) 679 return ret; 680 681 sk = (struct sock *)msk; 682 683 ret = mptcp_pm_parse_entry(attr, info, false, &addr); 684 if (ret < 0) 685 goto out; 686 687 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 688 if (!msg) { 689 ret = -ENOMEM; 690 goto out; 691 } 692 693 reply = genlmsg_put_reply(msg, info, &mptcp_genl_family, 0, 694 info->genlhdr->cmd); 695 if (!reply) { 696 GENL_SET_ERR_MSG(info, "not enough space in Netlink message"); 697 ret = -EMSGSIZE; 698 goto fail; 699 } 700 701 lock_sock(sk); 702 spin_lock_bh(&msk->pm.lock); 703 entry = mptcp_userspace_pm_lookup_addr_by_id(msk, addr.addr.id); 704 if (!entry) { 705 GENL_SET_ERR_MSG(info, "address not found"); 706 ret = -EINVAL; 707 goto unlock_fail; 708 } 709 710 ret = mptcp_nl_fill_addr(msg, entry); 711 if (ret) 712 goto unlock_fail; 713 714 genlmsg_end(msg, reply); 715 ret = genlmsg_reply(msg, info); 716 spin_unlock_bh(&msk->pm.lock); 717 release_sock(sk); 718 sock_put(sk); 719 return ret; 720 721 unlock_fail: 722 spin_unlock_bh(&msk->pm.lock); 723 release_sock(sk); 724 fail: 725 nlmsg_free(msg); 726 out: 727 sock_put(sk); 728 return ret; 729 } 730