MCPcopy Create free account
hub / github.com/F-Stack/f-stack / in6_pcbladdr

Function in6_pcbladdr

freebsd/netinet6/in6_pcb.c:347–403  ·  view source on GitHub ↗

* Transform old in6_pcbconnect() into an inner subroutine for new * in6_pcbconnect(): Do some validity-checking on the remote * address (in mbuf 'nam') and then determine local host address * (i.e., which interface) to use to access that remote host. * * This preserves definition of in6_pcbconnect(), while supporting a * slightly different version for T/TCP. (This is more than

Source from the content-addressed store, hash-verified

345 * have forced minor changes in every protocol).
346 */
347static int
348in6_pcbladdr(struct inpcb *inp, struct sockaddr *nam,
349 struct in6_addr *plocal_addr6)
350{
351 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nam;
352 int error = 0;
353 int scope_ambiguous = 0;
354 struct in6_addr in6a;
355
356 INP_WLOCK_ASSERT(inp);
357 INP_HASH_WLOCK_ASSERT(inp->inp_pcbinfo); /* XXXRW: why? */
358
359 if (nam->sa_len != sizeof (*sin6))
360 return (EINVAL);
361 if (sin6->sin6_family != AF_INET6)
362 return (EAFNOSUPPORT);
363 if (sin6->sin6_port == 0)
364 return (EADDRNOTAVAIL);
365
366 if (sin6->sin6_scope_id == 0 && !V_ip6_use_defzone)
367 scope_ambiguous = 1;
368 if ((error = sa6_embedscope(sin6, V_ip6_use_defzone)) != 0)
369 return(error);
370
371 if (!CK_STAILQ_EMPTY(&V_in6_ifaddrhead)) {
372 /*
373 * If the destination address is UNSPECIFIED addr,
374 * use the loopback addr, e.g ::1.
375 */
376 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
377 sin6->sin6_addr = in6addr_loopback;
378 }
379 if ((error = prison_remote_ip6(inp->inp_cred, &sin6->sin6_addr)) != 0)
380 return (error);
381
382 error = in6_selectsrc_socket(sin6, inp->in6p_outputopts,
383 inp, inp->inp_cred, scope_ambiguous, &in6a, NULL);
384 if (error)
385 return (error);
386
387 /*
388 * Do not update this earlier, in case we return with an error.
389 *
390 * XXX: this in6_selectsrc_socket result might replace the bound local
391 * address with the address specified by setsockopt(IPV6_PKTINFO).
392 * Is it the intended behavior?
393 */
394 *plocal_addr6 = in6a;
395
396 /*
397 * Don't do pcblookup call here; return interface in
398 * plocal_addr6
399 * and exit to caller, that will do the lookup.
400 */
401
402 return (0);
403}
404

Callers 1

in6_pcbconnect_mbufFunction · 0.85

Calls 3

sa6_embedscopeFunction · 0.85
in6_selectsrc_socketFunction · 0.85
prison_remote_ip6Function · 0.70

Tested by

no test coverage detected