Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F142048641
D47451.id146062.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D47451.id146062.diff
View Options
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c
--- a/sys/netinet/in_pcb.c
+++ b/sys/netinet/in_pcb.c
@@ -916,8 +916,10 @@
return (EINVAL);
lport = sin->sin_port;
}
+ laddr = sin->sin_addr;
+
/* NB: lport is left as 0 if the port isn't being changed. */
- if (IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) {
+ if (IN_MULTICAST(ntohl(laddr.s_addr))) {
/*
* Treat SO_REUSEADDR as SO_REUSEPORT for multicast;
* allow complete duplication of binding if
@@ -934,7 +936,7 @@
if ((so->so_options &
(SO_REUSEADDR|SO_REUSEPORT_LB)) != 0)
reuseport_lb = SO_REUSEADDR|SO_REUSEPORT_LB;
- } else if (sin->sin_addr.s_addr != INADDR_ANY) {
+ } else if (!in_nullhost(laddr)) {
sin->sin_port = 0; /* yech... */
bzero(&sin->sin_zero, sizeof(sin->sin_zero));
/*
@@ -943,50 +945,44 @@
* to any endpoint address, local or not.
*/
if ((inp->inp_flags & INP_BINDANY) == 0 &&
- ifa_ifwithaddr_check((struct sockaddr *)sin) == 0)
+ ifa_ifwithaddr_check(
+ (const struct sockaddr *)sin) == 0)
return (EADDRNOTAVAIL);
}
- laddr = sin->sin_addr;
if (lport) {
struct inpcb *t;
- /* GROSS */
if (ntohs(lport) <= V_ipport_reservedhigh &&
ntohs(lport) >= V_ipport_reservedlow &&
priv_check_cred(cred, PRIV_NETINET_RESERVEDPORT))
return (EACCES);
- if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr)) &&
+
+ if (!IN_MULTICAST(ntohl(laddr.s_addr)) &&
priv_check_cred(inp->inp_cred, PRIV_NETINET_REUSEPORT) != 0) {
- t = in_pcblookup_local(pcbinfo, sin->sin_addr,
- lport, INPLOOKUP_WILDCARD, cred);
- /*
- * XXX
- * This entire block sorely needs a rewrite.
- */
+ t = in_pcblookup_local(pcbinfo, laddr, lport,
+ INPLOOKUP_WILDCARD, cred);
if (t != NULL &&
(so->so_type != SOCK_STREAM ||
- ntohl(t->inp_faddr.s_addr) == INADDR_ANY) &&
- (ntohl(sin->sin_addr.s_addr) != INADDR_ANY ||
- ntohl(t->inp_laddr.s_addr) != INADDR_ANY ||
+ in_nullhost(t->inp_faddr)) &&
+ (!in_nullhost(laddr) ||
+ !in_nullhost(t->inp_laddr) ||
(t->inp_socket->so_options & SO_REUSEPORT) ||
(t->inp_socket->so_options & SO_REUSEPORT_LB) == 0) &&
(inp->inp_cred->cr_uid !=
t->inp_cred->cr_uid))
return (EADDRINUSE);
}
- t = in_pcblookup_local(pcbinfo, sin->sin_addr,
- lport, lookupflags, cred);
- if (t != NULL && (reuseport & t->inp_socket->so_options) == 0 &&
- (reuseport_lb & t->inp_socket->so_options) == 0) {
+ t = in_pcblookup_local(pcbinfo, laddr, lport,
+ lookupflags, cred);
+ if (t != NULL && ((reuseport | reuseport_lb) &
+ t->inp_socket->so_options) == 0) {
#ifdef INET6
- if (ntohl(sin->sin_addr.s_addr) !=
- INADDR_ANY ||
- ntohl(t->inp_laddr.s_addr) !=
- INADDR_ANY ||
+ if (!in_nullhost(laddr) ||
+ !in_nullhost(t->inp_laddr) ||
(inp->inp_vflag & INP_IPV6PROTO) == 0 ||
(t->inp_vflag & INP_IPV6PROTO) == 0)
#endif
- return (EADDRINUSE);
+ return (EADDRINUSE);
}
}
}
diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c
--- a/sys/netinet6/in6_pcb.c
+++ b/sys/netinet6/in6_pcb.c
@@ -247,11 +247,11 @@
if (lport) {
struct inpcb *t;
- /* GROSS */
if (ntohs(lport) <= V_ipport_reservedhigh &&
ntohs(lport) >= V_ipport_reservedlow &&
priv_check_cred(cred, PRIV_NETINET_RESERVEDPORT))
return (EACCES);
+
if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr) &&
priv_check_cred(inp->inp_cred, PRIV_NETINET_REUSEPORT) != 0) {
t = in6_pcblookup_local(pcbinfo,
@@ -279,8 +279,7 @@
INPLOOKUP_WILDCARD, cred);
if (t != NULL &&
(so->so_type != SOCK_STREAM ||
- ntohl(t->inp_faddr.s_addr) ==
- INADDR_ANY) &&
+ in_nullhost(t->inp_faddr)) &&
(inp->inp_cred->cr_uid !=
t->inp_cred->cr_uid))
return (EADDRINUSE);
@@ -289,10 +288,9 @@
}
t = in6_pcblookup_local(pcbinfo, &sin6->sin6_addr,
lport, lookupflags, cred);
- if (t && (reuseport & t->inp_socket->so_options) == 0 &&
- (reuseport_lb & t->inp_socket->so_options) == 0) {
+ if (t != NULL && ((reuseport | reuseport_lb) &
+ t->inp_socket->so_options) == 0)
return (EADDRINUSE);
- }
#ifdef INET
if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0 &&
IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
@@ -301,11 +299,10 @@
in6_sin6_2_sin(&sin, sin6);
t = in_pcblookup_local(pcbinfo, sin.sin_addr,
lport, lookupflags, cred);
- if (t &&
- (reuseport & t->inp_socket->so_options) == 0 &&
- (reuseport_lb & t->inp_socket->so_options) == 0 &&
- (ntohl(t->inp_laddr.s_addr) != INADDR_ANY ||
- (t->inp_vflag & INP_IPV6PROTO) != 0)) {
+ if (t != NULL && ((reuseport | reuseport_lb) &
+ t->inp_socket->so_options) == 0 &&
+ (!in_nullhost(t->inp_laddr) ||
+ (t->inp_vflag & INP_IPV6PROTO) != 0)) {
return (EADDRINUSE);
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jan 16, 11:00 AM (7 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27660166
Default Alt Text
D47451.id146062.diff (4 KB)
Attached To
Mode
D47451: inpcb: Make some cosmetic improvements to in_pcbbind()
Attached
Detach File
Event Timeline
Log In to Comment