Changeset View
Changeset View
Standalone View
Standalone View
sys/netinet/tcp_usrreq.c
Show First 20 Lines • Show All 315 Lines • ▼ Show 20 Lines | |||||
tcp_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td) | tcp_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td) | ||||
{ | { | ||||
int error = 0; | int error = 0; | ||||
struct inpcb *inp; | struct inpcb *inp; | ||||
struct tcpcb *tp = NULL; | struct tcpcb *tp = NULL; | ||||
struct sockaddr_in *sinp; | struct sockaddr_in *sinp; | ||||
sinp = (struct sockaddr_in *)nam; | sinp = (struct sockaddr_in *)nam; | ||||
if (nam->sa_family != AF_INET) | |||||
return (EAFNOSUPPORT); | |||||
if (nam->sa_len != sizeof (*sinp)) | if (nam->sa_len != sizeof(*sinp)) | ||||
return (EINVAL); | return (EINVAL); | ||||
/* | /* | ||||
* Must check for multicast addresses and disallow binding | * Must check for multicast addresses and disallow binding | ||||
* to them. | * to them. | ||||
*/ | */ | ||||
if (sinp->sin_family == AF_INET && | if (IN_MULTICAST(ntohl(sinp->sin_addr.s_addr))) | ||||
IN_MULTICAST(ntohl(sinp->sin_addr.s_addr))) | |||||
return (EAFNOSUPPORT); | return (EAFNOSUPPORT); | ||||
TCPDEBUG0; | TCPDEBUG0; | ||||
inp = sotoinpcb(so); | inp = sotoinpcb(so); | ||||
KASSERT(inp != NULL, ("tcp_usr_bind: inp == NULL")); | KASSERT(inp != NULL, ("tcp_usr_bind: inp == NULL")); | ||||
INP_WLOCK(inp); | INP_WLOCK(inp); | ||||
if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { | if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { | ||||
error = EINVAL; | error = EINVAL; | ||||
Show All 19 Lines | |||||
{ | { | ||||
int error = 0; | int error = 0; | ||||
struct inpcb *inp; | struct inpcb *inp; | ||||
struct tcpcb *tp = NULL; | struct tcpcb *tp = NULL; | ||||
struct sockaddr_in6 *sin6; | struct sockaddr_in6 *sin6; | ||||
u_char vflagsav; | u_char vflagsav; | ||||
sin6 = (struct sockaddr_in6 *)nam; | sin6 = (struct sockaddr_in6 *)nam; | ||||
if (nam->sa_family != AF_INET6) | |||||
return (EAFNOSUPPORT); | |||||
if (nam->sa_len != sizeof (*sin6)) | if (nam->sa_len != sizeof(*sin6)) | ||||
return (EINVAL); | return (EINVAL); | ||||
/* | /* | ||||
* Must check for multicast addresses and disallow binding | * Must check for multicast addresses and disallow binding | ||||
* to them. | * to them. | ||||
*/ | */ | ||||
if (sin6->sin6_family == AF_INET6 && | if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) | ||||
IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) | |||||
return (EAFNOSUPPORT); | return (EAFNOSUPPORT); | ||||
TCPDEBUG0; | TCPDEBUG0; | ||||
inp = sotoinpcb(so); | inp = sotoinpcb(so); | ||||
KASSERT(inp != NULL, ("tcp6_usr_bind: inp == NULL")); | KASSERT(inp != NULL, ("tcp6_usr_bind: inp == NULL")); | ||||
INP_WLOCK(inp); | INP_WLOCK(inp); | ||||
vflagsav = inp->inp_vflag; | vflagsav = inp->inp_vflag; | ||||
if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { | if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { | ||||
▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
struct epoch_tracker et; | struct epoch_tracker et; | ||||
int error = 0; | int error = 0; | ||||
struct inpcb *inp; | struct inpcb *inp; | ||||
struct tcpcb *tp = NULL; | struct tcpcb *tp = NULL; | ||||
struct sockaddr_in *sinp; | struct sockaddr_in *sinp; | ||||
sinp = (struct sockaddr_in *)nam; | sinp = (struct sockaddr_in *)nam; | ||||
if (nam->sa_family != AF_INET) | |||||
return (EAFNOSUPPORT); | |||||
if (nam->sa_len != sizeof (*sinp)) | if (nam->sa_len != sizeof (*sinp)) | ||||
return (EINVAL); | return (EINVAL); | ||||
/* | /* | ||||
* Must disallow TCP ``connections'' to multicast addresses. | * Must disallow TCP ``connections'' to multicast addresses. | ||||
*/ | */ | ||||
if (sinp->sin_family == AF_INET | if (IN_MULTICAST(ntohl(sinp->sin_addr.s_addr))) | ||||
&& IN_MULTICAST(ntohl(sinp->sin_addr.s_addr))) | |||||
return (EAFNOSUPPORT); | return (EAFNOSUPPORT); | ||||
if ((sinp->sin_family == AF_INET) && | if (ntohl(sinp->sin_addr.s_addr) == INADDR_BROADCAST) | ||||
(ntohl(sinp->sin_addr.s_addr) == INADDR_BROADCAST)) | |||||
return (EACCES); | return (EACCES); | ||||
if ((error = prison_remote_ip4(td->td_ucred, &sinp->sin_addr)) != 0) | if ((error = prison_remote_ip4(td->td_ucred, &sinp->sin_addr)) != 0) | ||||
return (error); | return (error); | ||||
TCPDEBUG0; | TCPDEBUG0; | ||||
inp = sotoinpcb(so); | inp = sotoinpcb(so); | ||||
KASSERT(inp != NULL, ("tcp_usr_connect: inp == NULL")); | KASSERT(inp != NULL, ("tcp_usr_connect: inp == NULL")); | ||||
INP_WLOCK(inp); | INP_WLOCK(inp); | ||||
Show All 38 Lines | tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td) | ||||
struct tcpcb *tp = NULL; | struct tcpcb *tp = NULL; | ||||
struct sockaddr_in6 *sin6; | struct sockaddr_in6 *sin6; | ||||
u_int8_t incflagsav; | u_int8_t incflagsav; | ||||
u_char vflagsav; | u_char vflagsav; | ||||
TCPDEBUG0; | TCPDEBUG0; | ||||
sin6 = (struct sockaddr_in6 *)nam; | sin6 = (struct sockaddr_in6 *)nam; | ||||
if (nam->sa_family != AF_INET6) | |||||
return (EAFNOSUPPORT); | |||||
if (nam->sa_len != sizeof (*sin6)) | if (nam->sa_len != sizeof (*sin6)) | ||||
return (EINVAL); | return (EINVAL); | ||||
/* | /* | ||||
* Must disallow TCP ``connections'' to multicast addresses. | * Must disallow TCP ``connections'' to multicast addresses. | ||||
*/ | */ | ||||
if (sin6->sin6_family == AF_INET6 | if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) | ||||
&& IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) | |||||
return (EAFNOSUPPORT); | return (EAFNOSUPPORT); | ||||
inp = sotoinpcb(so); | inp = sotoinpcb(so); | ||||
KASSERT(inp != NULL, ("tcp6_usr_connect: inp == NULL")); | KASSERT(inp != NULL, ("tcp6_usr_connect: inp == NULL")); | ||||
INP_WLOCK(inp); | INP_WLOCK(inp); | ||||
vflagsav = inp->inp_vflag; | vflagsav = inp->inp_vflag; | ||||
incflagsav = inp->inp_inc.inc_flags; | incflagsav = inp->inp_inc.inc_flags; | ||||
if (inp->inp_flags & INP_TIMEWAIT) { | if (inp->inp_flags & INP_TIMEWAIT) { | ||||
▲ Show 20 Lines • Show All 2,373 Lines • Show Last 20 Lines |