]> Cypherpunks repositories - gostls13.git/commitdiff
net: tweak the ephemeral port range on dragonfly
authorMikio Hara <mikioh.mikioh@gmail.com>
Sat, 29 Mar 2014 04:04:25 +0000 (13:04 +0900)
committerMikio Hara <mikioh.mikioh@gmail.com>
Sat, 29 Mar 2014 04:04:25 +0000 (13:04 +0900)
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

src/pkg/net/sockopt_bsd.go
src/pkg/syscall/net_nacl.go

index c0255f1644798eb068a0f4509ae3dbb5ce1daae9..77d51d7376d45aacfcb65929d62c0b101d1caba1 100644 (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
index a2588d04191301ea970c30e49c3df82ab7e4e64c..aaa8b71119c00fe2fc3af0bfc7b5738b5f0fc226 100644 (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