* Select source address based on @inp, @dstsock and @opts. * Stores selected address to @srcp. If @scope_ambiguous is set, * embed scope from selected outgoing interface. If @hlim pointer * is provided, stores calculated hop limit there. * Returns 0 on success. */
| 550 | * Returns 0 on success. |
| 551 | */ |
| 552 | int |
| 553 | in6_selectsrc_socket(struct sockaddr_in6 *dstsock, struct ip6_pktopts *opts, |
| 554 | struct inpcb *inp, struct ucred *cred, int scope_ambiguous, |
| 555 | struct in6_addr *srcp, int *hlim) |
| 556 | { |
| 557 | struct ifnet *retifp; |
| 558 | uint32_t fibnum; |
| 559 | int error; |
| 560 | |
| 561 | fibnum = inp->inp_inc.inc_fibnum; |
| 562 | retifp = NULL; |
| 563 | |
| 564 | error = in6_selectsrc(fibnum, dstsock, opts, inp, cred, &retifp, srcp); |
| 565 | if (error != 0) |
| 566 | return (error); |
| 567 | |
| 568 | if (hlim != NULL) |
| 569 | *hlim = in6_selecthlim(inp, retifp); |
| 570 | |
| 571 | if (retifp == NULL || scope_ambiguous == 0) |
| 572 | return (0); |
| 573 | |
| 574 | /* |
| 575 | * Application should provide a proper zone ID or the use of |
| 576 | * default zone IDs should be enabled. Unfortunately, some |
| 577 | * applications do not behave as it should, so we need a |
| 578 | * workaround. Even if an appropriate ID is not determined |
| 579 | * (when it's required), if we can determine the outgoing |
| 580 | * interface. determine the zone ID based on the interface. |
| 581 | */ |
| 582 | error = in6_setscope(&dstsock->sin6_addr, retifp, NULL); |
| 583 | |
| 584 | return (error); |
| 585 | } |
| 586 | |
| 587 | /* |
| 588 | * Select source address based on @fibnum, @dst and @scopeid. |
no test coverage detected