diff --git a/sys/netinet/in.h b/sys/netinet/in.h index 175269ea07d8..48f5fab7018e 100644 --- a/sys/netinet/in.h +++ b/sys/netinet/in.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)in.h 8.3 (Berkeley) 1/3/94 - * $Id: in.h,v 1.12 1995/11/01 17:18:26 wollman Exp $ + * $Id: in.h,v 1.13 1995/11/14 20:33:57 phk Exp $ */ #ifndef _NETINET_IN_H_ @@ -74,6 +74,20 @@ #define IPPORT_RESERVED 1024 #define IPPORT_USERRESERVED 5000 +/* + * Range of ports for automatic assignment to local addresses that + * have not explicitly specified an address. + * + * These can be overridden at kernel config time, and are used to init + * sysctl variables. The sysctl variables can be changed at runtime. + */ +#ifndef IPPORT_FIRSTAUTO +#define IPPORT_FIRSTAUTO 20000 +#endif +#ifndef IPPORT_LASTAUTO +#define IPPORT_LASTAUTO 30000 +#endif + /* * Internet address (a structure for historical reasons) */ diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 73d564f35c46..6fa0d2fe49bb 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)in_pcb.c 8.4 (Berkeley) 5/24/95 - * $Id: in_pcb.c,v 1.14 1995/10/29 15:32:25 phk Exp $ + * $Id: in_pcb.c,v 1.15 1995/11/14 20:33:59 phk Exp $ */ #include @@ -46,6 +46,8 @@ #include #include #include +#include +#include #include #include @@ -59,6 +61,18 @@ struct in_addr zeroin_addr; +/* + * These configure the range of local port addresses assigned to + * "unspecified" outgoing connections/packets/whatever. + */ +static int ipport_firstauto = IPPORT_FIRSTAUTO; +static int ipport_lastauto = IPPORT_LASTAUTO; + +SYSCTL_INT(_net_inet_ip, OID_AUTO, port_first_auto, CTLFLAG_RW, + &ipport_firstauto, 0, ""); +SYSCTL_INT(_net_inet_ip, OID_AUTO, port_last_auto, CTLFLAG_RW, + &ipport_lastauto, 0, ""); + static void in_pcbinshash __P((struct inpcb *)); static void in_rtchange __P((struct inpcb *, int)); @@ -151,9 +165,9 @@ in_pcbbind(inp, nam) if (lport == 0) do { ++*lastport; - if (*lastport < IPPORT_RESERVED || - *lastport > IPPORT_USERRESERVED) - *lastport = IPPORT_RESERVED; + if (*lastport < ipport_firstauto || + *lastport > ipport_lastauto) + *lastport = ipport_firstauto; lport = htons(*lastport); } while (in_pcblookup(head, zeroin_addr, 0, inp->inp_laddr, lport, wild));