Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F152893251
D22971.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
7 KB
Referenced Files
None
Subscribers
None
D22971.diff
View Options
Index: head/sys/netinet/in_pcb.h
===================================================================
--- head/sys/netinet/in_pcb.h
+++ head/sys/netinet/in_pcb.h
@@ -832,7 +832,7 @@
u_short *, struct ucred *);
int in_pcbconnect(struct inpcb *, struct sockaddr *, struct ucred *);
int in_pcbconnect_mbuf(struct inpcb *, struct sockaddr *, struct ucred *,
- struct mbuf *);
+ struct mbuf *, bool);
int in_pcbconnect_setup(struct inpcb *, struct sockaddr *, in_addr_t *,
u_short *, in_addr_t *, u_short *, struct inpcb **,
struct ucred *);
@@ -841,7 +841,7 @@
void in_pcbdrop(struct inpcb *);
void in_pcbfree(struct inpcb *);
int in_pcbinshash(struct inpcb *);
-int in_pcbinshash_nopcbgroup(struct inpcb *);
+int in_pcbinshash_mbuf(struct inpcb *, struct mbuf *);
int in_pcbladdr(struct inpcb *, struct in_addr *, struct in_addr *,
struct ucred *);
struct inpcb *
Index: head/sys/netinet/in_pcb.c
===================================================================
--- head/sys/netinet/in_pcb.c
+++ head/sys/netinet/in_pcb.c
@@ -972,7 +972,7 @@
*/
int
in_pcbconnect_mbuf(struct inpcb *inp, struct sockaddr *nam,
- struct ucred *cred, struct mbuf *m)
+ struct ucred *cred, struct mbuf *m, bool rehash)
{
u_short lport, fport;
in_addr_t laddr, faddr;
@@ -991,6 +991,8 @@
/* Do the initial binding of the local address if required. */
if (inp->inp_laddr.s_addr == INADDR_ANY && inp->inp_lport == 0) {
+ KASSERT(rehash == true,
+ ("Rehashing required for unbound inps"));
inp->inp_lport = lport;
inp->inp_laddr.s_addr = laddr;
if (in_pcbinshash(inp) != 0) {
@@ -1005,7 +1007,11 @@
inp->inp_laddr.s_addr = laddr;
inp->inp_faddr.s_addr = faddr;
inp->inp_fport = fport;
- in_pcbrehash_mbuf(inp, m);
+ if (rehash) {
+ in_pcbrehash_mbuf(inp, m);
+ } else {
+ in_pcbinshash_mbuf(inp, m);
+ }
if (anonport)
inp->inp_flags |= INP_ANONPORT;
@@ -1016,7 +1022,7 @@
in_pcbconnect(struct inpcb *inp, struct sockaddr *nam, struct ucred *cred)
{
- return (in_pcbconnect_mbuf(inp, nam, cred, NULL));
+ return (in_pcbconnect_mbuf(inp, nam, cred, NULL, true));
}
/*
@@ -2500,7 +2506,7 @@
* Insert PCB onto various hash lists.
*/
static int
-in_pcbinshash_internal(struct inpcb *inp, int do_pcbgroup_update)
+in_pcbinshash_internal(struct inpcb *inp, struct mbuf *m)
{
struct inpcbhead *pcbhash;
struct inpcbporthead *pcbporthash;
@@ -2566,35 +2572,27 @@
CK_LIST_INSERT_HEAD(pcbhash, inp, inp_hash);
inp->inp_flags |= INP_INHASHLIST;
#ifdef PCBGROUP
- if (do_pcbgroup_update)
+ if (m != NULL) {
+ in_pcbgroup_update_mbuf(inp, m);
+ } else {
in_pcbgroup_update(inp);
+ }
#endif
return (0);
}
-/*
- * For now, there are two public interfaces to insert an inpcb into the hash
- * lists -- one that does update pcbgroups, and one that doesn't. The latter
- * is used only in the TCP syncache, where in_pcbinshash is called before the
- * full 4-tuple is set for the inpcb, and we don't want to install in the
- * pcbgroup until later.
- *
- * XXXRW: This seems like a misfeature. in_pcbinshash should always update
- * connection groups, and partially initialised inpcbs should not be exposed
- * to either reservation hash tables or pcbgroups.
- */
int
in_pcbinshash(struct inpcb *inp)
{
- return (in_pcbinshash_internal(inp, 1));
+ return (in_pcbinshash_internal(inp, NULL));
}
int
-in_pcbinshash_nopcbgroup(struct inpcb *inp)
+in_pcbinshash_mbuf(struct inpcb *inp, struct mbuf *m)
{
- return (in_pcbinshash_internal(inp, 0));
+ return (in_pcbinshash_internal(inp, m));
}
/*
Index: head/sys/netinet/tcp_syncache.c
===================================================================
--- head/sys/netinet/tcp_syncache.c
+++ head/sys/netinet/tcp_syncache.c
@@ -841,34 +841,8 @@
#endif
}
- /*
- * Install in the reservation hash table for now, but don't yet
- * install a connection group since the full 4-tuple isn't yet
- * configured.
- */
inp->inp_lport = sc->sc_inc.inc_lport;
- if ((error = in_pcbinshash_nopcbgroup(inp)) != 0) {
- /*
- * Undo the assignments above if we failed to
- * put the PCB on the hash lists.
- */
#ifdef INET6
- if (sc->sc_inc.inc_flags & INC_ISIPV6)
- inp->in6p_laddr = in6addr_any;
- else
-#endif
- inp->inp_laddr.s_addr = INADDR_ANY;
- inp->inp_lport = 0;
- if ((s = tcp_log_addrs(&sc->sc_inc, NULL, NULL, NULL))) {
- log(LOG_DEBUG, "%s; %s: in_pcbinshash failed "
- "with error %i\n",
- s, __func__, error);
- free(s, M_TCPLOG);
- }
- INP_HASH_WUNLOCK(&V_tcbinfo);
- goto abort;
- }
-#ifdef INET6
if (inp->inp_vflag & INP_IPV6PROTO) {
struct inpcb *oinp = sotoinpcb(lso);
@@ -900,7 +874,7 @@
if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr))
inp->in6p_laddr = sc->sc_inc.inc6_laddr;
if ((error = in6_pcbconnect_mbuf(inp, (struct sockaddr *)&sin6,
- thread0.td_ucred, m)) != 0) {
+ thread0.td_ucred, m, false)) != 0) {
inp->in6p_laddr = laddr6;
if ((s = tcp_log_addrs(&sc->sc_inc, NULL, NULL, NULL))) {
log(LOG_DEBUG, "%s; %s: in6_pcbconnect failed "
@@ -940,7 +914,7 @@
if (inp->inp_laddr.s_addr == INADDR_ANY)
inp->inp_laddr = sc->sc_inc.inc_laddr;
if ((error = in_pcbconnect_mbuf(inp, (struct sockaddr *)&sin,
- thread0.td_ucred, m)) != 0) {
+ thread0.td_ucred, m, false)) != 0) {
inp->inp_laddr = laddr;
if ((s = tcp_log_addrs(&sc->sc_inc, NULL, NULL, NULL))) {
log(LOG_DEBUG, "%s; %s: in_pcbconnect failed "
Index: head/sys/netinet6/in6_pcb.h
===================================================================
--- head/sys/netinet6/in6_pcb.h
+++ head/sys/netinet6/in6_pcb.h
@@ -86,7 +86,7 @@
int in6_pcbbind(struct inpcb *, struct sockaddr *, struct ucred *);
int in6_pcbconnect(struct inpcb *, struct sockaddr *, struct ucred *);
int in6_pcbconnect_mbuf(struct inpcb *, struct sockaddr *,
- struct ucred *, struct mbuf *);
+ struct ucred *, struct mbuf *, bool);
void in6_pcbdisconnect(struct inpcb *);
struct inpcb *
in6_pcblookup_local(struct inpcbinfo *,
Index: head/sys/netinet6/in6_pcb.c
===================================================================
--- head/sys/netinet6/in6_pcb.c
+++ head/sys/netinet6/in6_pcb.c
@@ -411,7 +411,7 @@
*/
int
in6_pcbconnect_mbuf(struct inpcb *inp, struct sockaddr *nam,
- struct ucred *cred, struct mbuf *m)
+ struct ucred *cred, struct mbuf *m, bool rehash)
{
struct inpcbinfo *pcbinfo = inp->inp_pcbinfo;
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nam;
@@ -437,6 +437,8 @@
}
if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)) {
if (inp->inp_lport == 0) {
+ KASSERT(rehash == true,
+ ("Rehashing required for unbound inps"));
error = in6_pcbbind(inp, (struct sockaddr *)0, cred);
if (error)
return (error);
@@ -451,7 +453,11 @@
inp->inp_flow |=
(htonl(ip6_randomflowlabel()) & IPV6_FLOWLABEL_MASK);
- in_pcbrehash_mbuf(inp, m);
+ if (rehash) {
+ in_pcbrehash_mbuf(inp, m);
+ } else {
+ in_pcbinshash_mbuf(inp, m);
+ }
return (0);
}
@@ -460,7 +466,7 @@
in6_pcbconnect(struct inpcb *inp, struct sockaddr *nam, struct ucred *cred)
{
- return (in6_pcbconnect_mbuf(inp, nam, cred, NULL));
+ return (in6_pcbconnect_mbuf(inp, nam, cred, NULL, true));
}
void
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Apr 18, 8:26 PM (3 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31732331
Default Alt Text
D22971.diff (7 KB)
Attached To
Mode
D22971: Fix race when accepting TCP connections
Attached
Detach File
Event Timeline
Log In to Comment