net: tweak the ephemeral port range on dragonfly

On DragonFly BSD, we adjust the ephemeral port range because
unlike other BSD systems its default ephemeral port range
doesn't conform to IANA recommendation as described in RFC 6355
and is pretty narrow.

On DragonFly BSD 3.6: default range [1024, 5000], high range [49152, 65535]
On FreeBSD 10: default range [10000, 65535], high range [49152, 65535]
On Linux 3.11: default range [32768, 61000]

Fixes #7541.

LGTM=iant
R=jsing, gobot, iant
CC=golang-codereviews
https://golang.org/cl/80610044
This commit is contained in:
Mikio Hara 2014-03-29 13:04:25 +09:00
parent a7858a40a5
commit 83ac901fb9
2 changed files with 21 additions and 0 deletions

View file

@ -8,10 +8,23 @@ package net
import (
"os"
"runtime"
"syscall"
)
func setDefaultSockopts(s, family, sotype int, ipv6only bool) error {
if runtime.GOOS == "dragonfly" && sotype != syscall.SOCK_RAW {
// On DragonFly BSD, we adjust the ephemeral port
// range because unlike other BSD systems its default
// port range doesn't conform to IANA recommendation
// as described in RFC 6355 and is pretty narrow.
switch family {
case syscall.AF_INET:
syscall.SetsockoptInt(s, syscall.IPPROTO_IP, syscall.IP_PORTRANGE, syscall.IP_PORTRANGE_HIGH)
case syscall.AF_INET6:
syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_PORTRANGE, syscall.IPV6_PORTRANGE_HIGH)
}
}
if family == syscall.AF_INET6 && sotype != syscall.SOCK_RAW {
// Allow both IP versions even if the OS default
// is otherwise. Note that some operating systems

View file

@ -113,9 +113,17 @@ const (
SO_KEEPALIVE
SO_LINGER
SO_ERROR
IP_PORTRANGE
IP_PORTRANGE_DEFAULT
IP_PORTRANGE_LOW
IP_PORTRANGE_HIGH
IP_MULTICAST_IF
IP_MULTICAST_LOOP
IP_ADD_MEMBERSHIP
IPV6_PORTRANGE
IPV6_PORTRANGE_DEFAULT
IPV6_PORTRANGE_LOW
IPV6_PORTRANGE_HIGH
IPV6_MULTICAST_IF
IPV6_MULTICAST_LOOP
IPV6_JOIN_GROUP