Changeset View
Changeset View
Standalone View
Standalone View
sys/netinet6/in6_src.c
Show First 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* Return an IPv6 address, which is the most appropriate for a given | * Return an IPv6 address, which is the most appropriate for a given | ||||
* destination and user specified options. | * destination and user specified options. | ||||
* If necessary, this function lookups the routing table and returns | * If necessary, this function lookups the routing table and returns | ||||
* an entry to the caller for later use. | * an entry to the caller for later use. | ||||
*/ | */ | ||||
#define REPLACE(r) do {\ | #define REPLACE(r) do {\ | ||||
IP6STAT_INC(ip6s_sources_rule[(r)]); \ | IP6STAT_INC2(ip6s_sources_rule, (r)); \ | ||||
/* { \ | /* { \ | ||||
char ip6buf[INET6_ADDRSTRLEN], ip6b[INET6_ADDRSTRLEN]; \ | char ip6buf[INET6_ADDRSTRLEN], ip6b[INET6_ADDRSTRLEN]; \ | ||||
printf("in6_selectsrc: replace %s with %s by %d\n", ia_best ? ip6_sprintf(ip6buf, &ia_best->ia_addr.sin6_addr) : "none", ip6_sprintf(ip6b, &ia->ia_addr.sin6_addr), (r)); \ | printf("in6_selectsrc: replace %s with %s by %d\n", ia_best ? ip6_sprintf(ip6buf, &ia_best->ia_addr.sin6_addr) : "none", ip6_sprintf(ip6b, &ia->ia_addr.sin6_addr), (r)); \ | ||||
} */ \ | } */ \ | ||||
goto replace; \ | goto replace; \ | ||||
} while(0) | } while(0) | ||||
#define NEXT(r) do {\ | #define NEXT(r) do {\ | ||||
/* { \ | /* { \ | ||||
char ip6buf[INET6_ADDRSTRLEN], ip6b[INET6_ADDRSTRLEN]; \ | char ip6buf[INET6_ADDRSTRLEN], ip6b[INET6_ADDRSTRLEN]; \ | ||||
printf("in6_selectsrc: keep %s against %s by %d\n", ia_best ? ip6_sprintf(ip6buf, &ia_best->ia_addr.sin6_addr) : "none", ip6_sprintf(ip6b, &ia->ia_addr.sin6_addr), (r)); \ | printf("in6_selectsrc: keep %s against %s by %d\n", ia_best ? ip6_sprintf(ip6buf, &ia_best->ia_addr.sin6_addr) : "none", ip6_sprintf(ip6b, &ia->ia_addr.sin6_addr), (r)); \ | ||||
} */ \ | } */ \ | ||||
goto next; /* XXX: we can't use 'continue' here */ \ | goto next; /* XXX: we can't use 'continue' here */ \ | ||||
} while(0) | } while(0) | ||||
#define BREAK(r) do { \ | #define BREAK(r) do { \ | ||||
IP6STAT_INC(ip6s_sources_rule[(r)]); \ | IP6STAT_INC2(ip6s_sources_rule, (r)); \ | ||||
goto out; /* XXX: we can't use 'break' here */ \ | goto out; /* XXX: we can't use 'break' here */ \ | ||||
} while(0) | } while(0) | ||||
static int | static int | ||||
in6_selectsrc(uint32_t fibnum, struct sockaddr_in6 *dstsock, | in6_selectsrc(uint32_t fibnum, struct sockaddr_in6 *dstsock, | ||||
struct ip6_pktopts *opts, struct inpcb *inp, struct ucred *cred, | struct ip6_pktopts *opts, struct inpcb *inp, struct ucred *cred, | ||||
struct ifnet **ifpp, struct in6_addr *srcp) | struct ifnet **ifpp, struct in6_addr *srcp) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 339 Lines • ▼ Show 20 Lines | if (cred != NULL && prison_local_ip6(cred, &tmp, (inp != NULL && | ||||
return (EADDRNOTAVAIL); | return (EADDRNOTAVAIL); | ||||
} | } | ||||
if (ifpp) | if (ifpp) | ||||
*ifpp = ifp; | *ifpp = ifp; | ||||
bcopy(&tmp, srcp, sizeof(*srcp)); | bcopy(&tmp, srcp, sizeof(*srcp)); | ||||
if (ia->ia_ifp == ifp) | if (ia->ia_ifp == ifp) | ||||
IP6STAT_INC(ip6s_sources_sameif[best_scope]); | IP6STAT_INC2(ip6s_sources_sameif, best_scope); | ||||
else | else | ||||
IP6STAT_INC(ip6s_sources_otherif[best_scope]); | IP6STAT_INC2(ip6s_sources_otherif, best_scope); | ||||
if (dst_scope == best_scope) | if (dst_scope == best_scope) | ||||
IP6STAT_INC(ip6s_sources_samescope[best_scope]); | IP6STAT_INC2(ip6s_sources_samescope, best_scope); | ||||
else | else | ||||
IP6STAT_INC(ip6s_sources_otherscope[best_scope]); | IP6STAT_INC2(ip6s_sources_otherscope, best_scope); | ||||
if (IFA6_IS_DEPRECATED(ia)) | if (IFA6_IS_DEPRECATED(ia)) | ||||
IP6STAT_INC(ip6s_sources_deprecated[best_scope]); | IP6STAT_INC2(ip6s_sources_deprecated, best_scope); | ||||
IN6_IFADDR_RUNLOCK(&in6_ifa_tracker); | IN6_IFADDR_RUNLOCK(&in6_ifa_tracker); | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Select source address based on @inp, @dstsock and @opts. | * Select source address based on @inp, @dstsock and @opts. | ||||
* Stores selected address to @srcp. If @scope_ambiguous is set, | * Stores selected address to @srcp. If @scope_ambiguous is set, | ||||
* embed scope from selected outgoing interface. If @hlim pointer | * embed scope from selected outgoing interface. If @hlim pointer | ||||
▲ Show 20 Lines • Show All 573 Lines • Show Last 20 Lines |