In TCP, connect() can return incorrect error code EINVAL

instead of EADDRINUSE or ECONNREFUSED

PR:			https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=196035
Differential Revision:	https://reviews.freebsd.org/D1982
Reported by:		Mark Nunberg <mnunberg@haskalah.org>
Submitted by:		Harrison Grundy <harrison.grundy@astrodoggroup.com>
Reviewed by:		adrian, jch, glebius, gnn
Approved by:		jhb
MFC after:		2 weeks
This commit is contained in:
Julien Charbon 2015-03-09 20:29:16 +00:00
parent be070eb896
commit eb96dc3336
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=279821

View File

@ -476,8 +476,12 @@ tcp_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
inp = sotoinpcb(so);
KASSERT(inp != NULL, ("tcp_usr_connect: inp == NULL"));
INP_WLOCK(inp);
if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
error = EINVAL;
if (inp->inp_flags & INP_TIMEWAIT) {
error = EADDRINUSE;
goto out;
}
if (inp->inp_flags & INP_DROPPED) {
error = ECONNREFUSED;
goto out;
}
tp = intotcpcb(inp);
@ -523,8 +527,12 @@ tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
inp = sotoinpcb(so);
KASSERT(inp != NULL, ("tcp6_usr_connect: inp == NULL"));
INP_WLOCK(inp);
if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
error = EINVAL;
if (inp->inp_flags & INP_TIMEWAIT) {
error = EADDRINUSE;
goto out;
}
if (inp->inp_flags & INP_DROPPED) {
error = ECONNREFUSED;
goto out;
}
tp = intotcpcb(inp);