Skip to content

Commit 2bc927f

Browse files
committed
2 parents 2576201 + 85fd2e4 commit 2bc927f

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

freebsd/netinet/in_pcb.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,10 @@ if (lport == 0)
11261126
ifp_sin.sin_len = sizeof(ifp_sin);
11271127
ifa = ifa_ifwithnet((struct sockaddr *)&ifp_sin, 0, RT_ALL_FIBS);
11281128
if (ifa == NULL) {
1129-
return (EADDRNOTAVAIL);
1129+
ifp_sin.sin_addr.s_addr = faddr.s_addr;
1130+
ifa = ifa_ifwithnet((struct sockaddr *)&ifp_sin, 0, RT_ALL_FIBS);
1131+
if ( ifa == NULL )
1132+
return (EADDRNOTAVAIL);
11301133
}
11311134
ifp = ifa->ifa_ifp;
11321135
while (lport == 0) {

freebsd/netinet/tcp_usrreq.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,14 +1321,22 @@ tcp_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
13211321
error = EADDRINUSE;
13221322
goto out;
13231323
}
1324+
1325+
// inp->inp_lport != lport means in_pcbconnect_setup selected new port to inp->inp_lport.
1326+
// inp will inhash.
1327+
if (in_pcbinshash(inp) != 0) {
1328+
inp->inp_laddr.s_addr = INADDR_ANY;
1329+
inp->inp_lport = 0;
1330+
return (EAGAIN);
1331+
}
13241332
}
1325-
1326-
if (in_pcbinshash(inp) != 0) {
1327-
inp->inp_laddr.s_addr = INADDR_ANY;
1328-
inp->inp_lport = 0;
1329-
return (EAGAIN);
1333+
else
1334+
{
1335+
// app call bind() and connect(), lport is set when bind, and the inp is inhashed in bind() function.
1336+
// in_pcbconnect_setup() update inp->inp_faddr/inp->inp_fport, so inp should be rehashed.
1337+
in_pcbrehash(inp);
13301338
}
1331-
1339+
13321340
if (anonport) {
13331341
inp->inp_flags |= INP_ANONPORT;
13341342
}

0 commit comments

Comments
 (0)