1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-24 11:29:10 +00:00

Re-use passive data ports with the SO_REUSEADDR

socket option to avoid exausting the passive port
space by TIME_WAIT'ing connections.

PR:		bin/36955
Submitted by:	Maxim Konovalov <maxim@FreeBSD.org>
MFC after:	2 weeks
This commit is contained in:
Yaroslav Tykhiy 2002-07-24 16:11:34 +00:00
parent adf721d1cb
commit 8af7c9a3c0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=100615

View File

@ -2473,7 +2473,7 @@ myoob(void)
void
passive(void)
{
int len;
int len, on;
char *p, *a;
if (pdata >= 0) /* close old port if one set */
@ -2484,13 +2484,16 @@ passive(void)
perror_reply(425, "Can't open passive connection");
return;
}
on = 1;
if (setsockopt(pdata, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0)
syslog(LOG_WARNING, "pdata setsockopt (SO_REUSEADDR): %m");
(void) seteuid((uid_t)0);
#ifdef IP_PORTRANGE
if (ctrl_addr.su_family == AF_INET) {
int on = restricted_data_ports ? IP_PORTRANGE_HIGH
: IP_PORTRANGE_DEFAULT;
on = restricted_data_ports ? IP_PORTRANGE_HIGH
: IP_PORTRANGE_DEFAULT;
if (setsockopt(pdata, IPPROTO_IP, IP_PORTRANGE,
&on, sizeof(on)) < 0)
@ -2499,8 +2502,8 @@ passive(void)
#endif
#ifdef IPV6_PORTRANGE
if (ctrl_addr.su_family == AF_INET6) {
int on = restricted_data_ports ? IPV6_PORTRANGE_HIGH
: IPV6_PORTRANGE_DEFAULT;
on = restricted_data_ports ? IPV6_PORTRANGE_HIGH
: IPV6_PORTRANGE_DEFAULT;
if (setsockopt(pdata, IPPROTO_IPV6, IPV6_PORTRANGE,
&on, sizeof(on)) < 0)
@ -2553,7 +2556,7 @@ passive(void)
void
long_passive(char *cmd, int pf)
{
int len;
int len, on;
char *p, *a;
if (pdata >= 0) /* close old port if one set */
@ -2591,6 +2594,9 @@ long_passive(char *cmd, int pf)
perror_reply(425, "Can't open passive connection");
return;
}
on = 1;
if (setsockopt(pdata, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0)
syslog(LOG_WARNING, "pdata setsockopt (SO_REUSEADDR): %m");
(void) seteuid((uid_t)0);
@ -2600,8 +2606,8 @@ long_passive(char *cmd, int pf)
#ifdef IP_PORTRANGE
if (ctrl_addr.su_family == AF_INET) {
int on = restricted_data_ports ? IP_PORTRANGE_HIGH
: IP_PORTRANGE_DEFAULT;
on = restricted_data_ports ? IP_PORTRANGE_HIGH
: IP_PORTRANGE_DEFAULT;
if (setsockopt(pdata, IPPROTO_IP, IP_PORTRANGE,
&on, sizeof(on)) < 0)
@ -2610,8 +2616,8 @@ long_passive(char *cmd, int pf)
#endif
#ifdef IPV6_PORTRANGE
if (ctrl_addr.su_family == AF_INET6) {
int on = restricted_data_ports ? IPV6_PORTRANGE_HIGH
: IPV6_PORTRANGE_DEFAULT;
on = restricted_data_ports ? IPV6_PORTRANGE_HIGH
: IPV6_PORTRANGE_DEFAULT;
if (setsockopt(pdata, IPPROTO_IPV6, IPV6_PORTRANGE,
&on, sizeof(on)) < 0)