in6_src.c (185348) | in6_src.c (185435) |
---|---|
1/*- 2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 47 unchanged lines hidden (view full) --- 56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 58 * SUCH DAMAGE. 59 * 60 * @(#)in_pcb.c 8.2 (Berkeley) 1/4/94 61 */ 62 63#include <sys/cdefs.h> | 1/*- 2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 47 unchanged lines hidden (view full) --- 56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 58 * SUCH DAMAGE. 59 * 60 * @(#)in_pcb.c 8.2 (Berkeley) 1/4/94 61 */ 62 63#include <sys/cdefs.h> |
64__FBSDID("$FreeBSD: head/sys/netinet6/in6_src.c 185348 2008-11-26 22:32:07Z zec $"); | 64__FBSDID("$FreeBSD: head/sys/netinet6/in6_src.c 185435 2008-11-29 14:32:14Z bz $"); |
65 66#include "opt_inet.h" 67#include "opt_inet6.h" 68#include "opt_mpath.h" 69 70#include <sys/param.h> 71#include <sys/systm.h> 72#include <sys/lock.h> 73#include <sys/malloc.h> 74#include <sys/mbuf.h> 75#include <sys/priv.h> 76#include <sys/protosw.h> 77#include <sys/socket.h> 78#include <sys/socketvar.h> 79#include <sys/sockio.h> 80#include <sys/sysctl.h> 81#include <sys/errno.h> 82#include <sys/time.h> | 65 66#include "opt_inet.h" 67#include "opt_inet6.h" 68#include "opt_mpath.h" 69 70#include <sys/param.h> 71#include <sys/systm.h> 72#include <sys/lock.h> 73#include <sys/malloc.h> 74#include <sys/mbuf.h> 75#include <sys/priv.h> 76#include <sys/protosw.h> 77#include <sys/socket.h> 78#include <sys/socketvar.h> 79#include <sys/sockio.h> 80#include <sys/sysctl.h> 81#include <sys/errno.h> 82#include <sys/time.h> |
83#include <sys/jail.h> |
|
83#include <sys/kernel.h> 84#include <sys/sx.h> 85#include <sys/vimage.h> 86 87#include <net/if.h> 88#include <net/route.h> 89#ifdef RADIX_MPATH 90#include <net/radix_mpath.h> --- 139 unchanged lines hidden (view full) --- 230 srcsock.sin6_family = AF_INET6; 231 srcsock.sin6_len = sizeof(srcsock); 232 srcsock.sin6_addr = pi->ipi6_addr; 233 if (ifp) { 234 *errorp = in6_setscope(&srcsock.sin6_addr, ifp, NULL); 235 if (*errorp != 0) 236 return (NULL); 237 } | 84#include <sys/kernel.h> 85#include <sys/sx.h> 86#include <sys/vimage.h> 87 88#include <net/if.h> 89#include <net/route.h> 90#ifdef RADIX_MPATH 91#include <net/radix_mpath.h> --- 139 unchanged lines hidden (view full) --- 231 srcsock.sin6_family = AF_INET6; 232 srcsock.sin6_len = sizeof(srcsock); 233 srcsock.sin6_addr = pi->ipi6_addr; 234 if (ifp) { 235 *errorp = in6_setscope(&srcsock.sin6_addr, ifp, NULL); 236 if (*errorp != 0) 237 return (NULL); 238 } |
239 if (cred != NULL && prison_local_ip6(cred, &srcsock.sin6_addr, 240 (inp != NULL && (inp->inp_flags & IN6P_IPV6_V6ONLY) != 0)) != 0) { 241 *errorp = EADDRNOTAVAIL; 242 return (NULL); 243 } |
|
238 239 ia6 = (struct in6_ifaddr *)ifa_ifwithaddr((struct sockaddr *)(&srcsock)); 240 if (ia6 == NULL || 241 (ia6->ia6_flags & (IN6_IFF_ANYCAST | IN6_IFF_NOTREADY))) { 242 *errorp = EADDRNOTAVAIL; 243 return (NULL); 244 } 245 pi->ipi6_addr = srcsock.sin6_addr; /* XXX: this overrides pi */ 246 if (ifpp) 247 *ifpp = ifp; 248 return (&ia6->ia_addr.sin6_addr); 249 } 250 251 /* 252 * Otherwise, if the socket has already bound the source, just use it. 253 */ 254 if (inp != NULL && !IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)) { | 244 245 ia6 = (struct in6_ifaddr *)ifa_ifwithaddr((struct sockaddr *)(&srcsock)); 246 if (ia6 == NULL || 247 (ia6->ia6_flags & (IN6_IFF_ANYCAST | IN6_IFF_NOTREADY))) { 248 *errorp = EADDRNOTAVAIL; 249 return (NULL); 250 } 251 pi->ipi6_addr = srcsock.sin6_addr; /* XXX: this overrides pi */ 252 if (ifpp) 253 *ifpp = ifp; 254 return (&ia6->ia_addr.sin6_addr); 255 } 256 257 /* 258 * Otherwise, if the socket has already bound the source, just use it. 259 */ 260 if (inp != NULL && !IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)) { |
261 if (cred != NULL && prison_local_ip6(cred, &inp->in6p_laddr, 262 ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0)) != 0) { 263 *errorp = EADDRNOTAVAIL; 264 return (NULL); 265 } |
|
255 return (&inp->in6p_laddr); 256 } 257 258 /* 259 * If the address is not specified, choose the best one based on 260 * the outgoing interface and the destination address. 261 */ 262 /* get the outgoing interface */ --- 35 unchanged lines hidden (view full) --- 298 /* avoid unusable addresses */ 299 if ((ia->ia6_flags & 300 (IN6_IFF_NOTREADY | IN6_IFF_ANYCAST | IN6_IFF_DETACHED))) { 301 continue; 302 } 303 if (!V_ip6_use_deprecated && IFA6_IS_DEPRECATED(ia)) 304 continue; 305 | 266 return (&inp->in6p_laddr); 267 } 268 269 /* 270 * If the address is not specified, choose the best one based on 271 * the outgoing interface and the destination address. 272 */ 273 /* get the outgoing interface */ --- 35 unchanged lines hidden (view full) --- 309 /* avoid unusable addresses */ 310 if ((ia->ia6_flags & 311 (IN6_IFF_NOTREADY | IN6_IFF_ANYCAST | IN6_IFF_DETACHED))) { 312 continue; 313 } 314 if (!V_ip6_use_deprecated && IFA6_IS_DEPRECATED(ia)) 315 continue; 316 |
317 if (cred != NULL && 318 prison_local_ip6(cred, &ia->ia_addr.sin6_addr, 319 (inp != NULL && 320 (inp->inp_flags & IN6P_IPV6_V6ONLY) != 0)) != 0) 321 continue; 322 |
|
306 /* Rule 1: Prefer same address */ 307 if (IN6_ARE_ADDR_EQUAL(&dst, &ia->ia_addr.sin6_addr)) { 308 ia_best = ia; 309 BREAK(1); /* there should be no better candidate */ 310 } 311 312 if (ia_best == NULL) 313 REPLACE(0); --- 465 unchanged lines hidden (view full) --- 779 struct socket *so = inp->inp_socket; 780 u_int16_t lport = 0, first, last, *lastport; 781 int count, error = 0, wild = 0, dorandom; 782 struct inpcbinfo *pcbinfo = inp->inp_pcbinfo; 783 784 INP_INFO_WLOCK_ASSERT(pcbinfo); 785 INP_WLOCK_ASSERT(inp); 786 | 323 /* Rule 1: Prefer same address */ 324 if (IN6_ARE_ADDR_EQUAL(&dst, &ia->ia_addr.sin6_addr)) { 325 ia_best = ia; 326 BREAK(1); /* there should be no better candidate */ 327 } 328 329 if (ia_best == NULL) 330 REPLACE(0); --- 465 unchanged lines hidden (view full) --- 796 struct socket *so = inp->inp_socket; 797 u_int16_t lport = 0, first, last, *lastport; 798 int count, error = 0, wild = 0, dorandom; 799 struct inpcbinfo *pcbinfo = inp->inp_pcbinfo; 800 801 INP_INFO_WLOCK_ASSERT(pcbinfo); 802 INP_WLOCK_ASSERT(inp); 803 |
804 if (prison_local_ip6(cred, laddr, 805 ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0)) != 0) 806 return(EINVAL); 807 |
|
787 /* XXX: this is redundant when called from in6_pcbbind */ 788 if ((so->so_options & (SO_REUSEADDR|SO_REUSEPORT)) == 0) 789 wild = INPLOOKUP_WILDCARD; 790 791 inp->inp_flags |= INP_ANONPORT; 792 793 if (inp->inp_flags & INP_HIGHPORT) { 794 first = V_ipport_hifirstauto; /* sysctl */ --- 336 unchanged lines hidden --- | 808 /* XXX: this is redundant when called from in6_pcbbind */ 809 if ((so->so_options & (SO_REUSEADDR|SO_REUSEPORT)) == 0) 810 wild = INPLOOKUP_WILDCARD; 811 812 inp->inp_flags |= INP_ANONPORT; 813 814 if (inp->inp_flags & INP_HIGHPORT) { 815 first = V_ipport_hifirstauto; /* sysctl */ --- 336 unchanged lines hidden --- |