Commit 64ecc883 authored by Evan Hunt's avatar Evan Hunt

Several BSD-related fixes for port range:

 - add param.h for NetBSD [rt18228]
 - use correct sysctl strings on NetBSD [rt18230]
 - use net.inet.ip.portrange.hiport/hilast instead of
   first/last on FreeBSD [rt18234]
 - define sysctl strings for DragonFly [rt18235]
 - use sysctl() on OpenBSD because it doesn't support
   sysctlbyname() [rt18231]
parent 34350037
......@@ -15,12 +15,16 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: net.c,v 1.39 2008/06/24 01:40:25 jinmei Exp $ */
/* $Id: net.c,v 1.40 2008/07/04 05:52:31 each Exp $ */
#include <config.h>
#include <sys/types.h>
#ifdef HAVE_SYS_SYSCTL_H
#if defined(HAVE_SYS_SYSCTL_H)
#if defined(HAVE_SYS_PARAM_H)
#include <sys/param.h>
#endif
#include <sys/sysctl.h>
#endif
......@@ -52,33 +56,42 @@
#define ISC_NET_PORTRANGEHIGH 65535
#endif /* ISC_NET_PORTRANGEHIGH */
#ifdef HAVE_SYSCTLBYNAME
/*%
* sysctl variants
*/
#if defined(__FreeBSD__) || defined(__APPLE__)
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
#define USE_SYSCTL_PORTRANGE
#define SYSCTL_V4PORTRANGE_LOW "net.inet.ip.portrange.first"
#define SYSCTL_V4PORTRANGE_HIGH "net.inet.ip.portrange.last"
#define SYSCTL_V6PORTRANGE_LOW "net.inet.ip.portrange.first"
#define SYSCTL_V6PORTRANGE_HIGH "net.inet.ip.portrange.last"
#define SYSCTL_V4PORTRANGE_LOW "net.inet.ip.portrange.hifirst"
#define SYSCTL_V4PORTRANGE_HIGH "net.inet.ip.portrange.hilast"
#define SYSCTL_V6PORTRANGE_LOW "net.inet.ip.portrange.hifirst"
#define SYSCTL_V6PORTRANGE_HIGH "net.inet.ip.portrange.hilast"
#endif
#ifdef __NetBSD__
#define USE_SYSCTL_PORTRANGE
#define SYSCTL_V4PORTRANGE_LOW "net.inet.ip.anonportmin"
#define SYSCTL_V4PORTRANGE_HIGH "net.inet.ip.anonportmax"
#define SYSCTL_V6PORTRANGE_LOW "net.inet6.ip6.portrange.first"
#define SYSCTL_V6PORTRANGE_HIGH "net.inet6.ip6.portrange.last"
#define SYSCTL_V6PORTRANGE_LOW "net.inet6.ip6.anonportmin"
#define SYSCTL_V6PORTRANGE_HIGH "net.inet6.ip6.anonportmax"
#endif
#else /* !HAVE_SYSCTLBYNAME */
#ifdef __OpenBSD__
#define USE_SYSCTL_PORTRANGE
#define SYSCTL_V4PORTRANGE_LOW "net.inet.ip.portfirst"
#define SYSCTL_V4PORTRANGE_HIGH "net.inet.ip.portlast"
#define SYSCTL_V6PORTRANGE_LOW "net.inet6.ip6.portrange.first"
#define SYSCTL_V6PORTRANGE_HIGH "net.inet6.ip6.portrange.last"
#define SYSCTL_V4PORTRANGE_LOW { CTL_NET, PF_INET, IPPROTO_IP, \
IPCTL_IPPORT_HIFIRSTAUTO }
#define SYSCTL_V4PORTRANGE_HIGH { CTL_NET, PF_INET, IPPROTO_IP, \
IPCTL_IPPORT_HILASTAUTO }
/* Same for IPv6 */
#define SYSCTL_V6PORTRANGE_LOW SYSCTL_V4PORTRANGE_LOW
#define SYSCTL_V6PORTRANGE_HIGH SYSCTL_V4PORTRANGE_HIGH
#endif
#endif /* HAVE_SYSCTLBYNAME */
#if defined(ISC_PLATFORM_HAVEIPV6)
# if defined(ISC_PLATFORM_NEEDIN6ADDRANY)
const struct in6_addr isc_net_in6addrany = IN6ADDR_ANY_INIT;
......@@ -387,7 +400,8 @@ isc_net_probe_ipv6pktinfo(void) {
return (ipv6pktinfo_result);
}
#ifdef USE_SYSCTL_PORTRANGE
#if defined(USE_SYSCTL_PORTRANGE)
#if defined(HAVE_SYSCTLBYNAME)
static isc_result_t
getudpportrange_sysctl(int af, in_port_t *low, in_port_t *high) {
int port_low, port_high;
......@@ -419,7 +433,47 @@ getudpportrange_sysctl(int af, in_port_t *low, in_port_t *high) {
return (ISC_R_SUCCESS);
}
#endif
#else /* !HAVE_SYSCTLBYNAME */
static isc_result_t
getudpportrange_sysctl(int af, in_port_t *low, in_port_t *high) {
int mib_lo4[4] = SYSCTL_V4PORTRANGE_LOW;
int mib_hi4[4] = SYSCTL_V4PORTRANGE_HIGH;
int mib_lo6[4] = SYSCTL_V6PORTRANGE_LOW;
int mib_hi6[4] = SYSCTL_V6PORTRANGE_HIGH;
int *mib_lo, *mib_hi, miblen;
int port_low, port_high;
size_t portlen;
if (af == AF_INET) {
mib_lo = mib_lo4;
mib_hi = mib_hi4;
miblen = sizeof(mib_lo4) / sizeof(mib_lo4[0]);
} else {
mib_lo = mib_lo6;
mib_hi = mib_hi6;
miblen = sizeof(mib_lo6) / sizeof(mib_lo6[0]);
}
portlen = sizeof(portlen);
if (sysctl(mib_lo, miblen, &port_low, &portlen, NULL, 0) < 0) {
return (ISC_R_FAILURE);
}
portlen = sizeof(portlen);
if (sysctl(mib_hi, miblen, &port_high, &portlen, NULL, 0) < 0) {
return (ISC_R_FAILURE);
}
if ((port_low & ~0xffff) != 0 || (port_high & ~0xffff) != 0)
return (ISC_R_RANGE);
*low = (in_port_t) port_low;
*high = (in_port_t) port_high;
return (ISC_R_SUCCESS);
}
#endif /* HAVE_SYSCTLBYNAME */
#endif /* USE_SYSCTL_PORTRANGE */
isc_result_t
isc_net_getudpportrange(int af, in_port_t *low, in_port_t *high) {
......@@ -427,7 +481,7 @@ isc_net_getudpportrange(int af, in_port_t *low, in_port_t *high) {
REQUIRE(low != NULL && high != NULL);
#ifdef USE_SYSCTL_PORTRANGE
#if defined(USE_SYSCTL_PORTRANGE)
result = getudpportrange_sysctl(af, low, high);
#else
UNUSED(af);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment