2016-03-01 15:57:46 -07:00
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
2011-05-02 08:50:12 -06:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2014-09-18 04:17:55 -06:00
|
|
|
// +build darwin dragonfly freebsd netbsd openbsd
|
build: add build comments to core packages
The go/build package already recognizes
system-specific file names like
mycode_darwin.go
mycode_darwin_386.go
mycode_386.s
However, it is also common to write files that
apply to multiple architectures, so a recent CL added
to go/build the ability to process comments
listing a set of conditions for building. For example:
// +build darwin freebsd openbsd/386
says that this file should be compiled only on
OS X, FreeBSD, or 32-bit x86 OpenBSD systems.
These conventions are not yet documented
(hence this long CL description).
This CL adds build comments to the multi-system
files in the core library, a step toward making it
possible to use go/build to build them.
With this change go/build can handle crypto/rand,
exec, net, path/filepath, os/user, and time.
os and syscall need additional adjustments.
R=golang-dev, r, gri, r, gustavo
CC=golang-dev
https://golang.org/cl/5011046
2011-09-15 14:48:57 -06:00
|
|
|
|
2011-05-02 08:50:12 -06:00
|
|
|
package net
|
|
|
|
|
|
|
|
import (
|
2012-01-31 09:53:26 -07:00
|
|
|
"os"
|
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
2014-03-28 22:04:25 -06:00
|
|
|
"runtime"
|
2011-05-02 08:50:12 -06:00
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
2013-07-27 20:18:06 -06:00
|
|
|
func setDefaultSockopts(s, family, sotype int, ipv6only bool) error {
|
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
2014-03-28 22:04:25 -06:00
|
|
|
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
|
2014-08-21 02:53:45 -06:00
|
|
|
// as described in RFC 6056 and is pretty narrow.
|
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
2014-03-28 22:04:25 -06:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2015-05-13 19:18:10 -06:00
|
|
|
if supportsIPv4map && family == syscall.AF_INET6 && sotype != syscall.SOCK_RAW {
|
2013-07-27 20:18:06 -06:00
|
|
|
// Allow both IP versions even if the OS default
|
2016-03-01 16:21:55 -07:00
|
|
|
// is otherwise. Note that some operating systems
|
2013-07-27 20:18:06 -06:00
|
|
|
// never admit this option.
|
|
|
|
syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, boolint(ipv6only))
|
2012-01-14 22:19:44 -07:00
|
|
|
}
|
2011-05-02 08:50:12 -06:00
|
|
|
// Allow broadcast.
|
2013-07-27 20:18:06 -06:00
|
|
|
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1))
|
2012-02-10 19:50:51 -07:00
|
|
|
}
|
2012-01-31 09:53:26 -07:00
|
|
|
|
2012-02-10 19:50:51 -07:00
|
|
|
func setDefaultListenerSockopts(s int) error {
|
|
|
|
// Allow reuse of recently-used addresses.
|
2013-07-27 20:18:06 -06:00
|
|
|
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1))
|
2012-01-14 22:19:44 -07:00
|
|
|
}
|
2011-05-02 08:50:12 -06:00
|
|
|
|
2012-01-31 09:53:26 -07:00
|
|
|
func setDefaultMulticastSockopts(s int) error {
|
2012-01-14 22:19:44 -07:00
|
|
|
// Allow multicast UDP and raw IP datagram sockets to listen
|
|
|
|
// concurrently across multiple listeners.
|
2013-07-27 20:18:06 -06:00
|
|
|
if err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil {
|
2012-01-31 09:53:26 -07:00
|
|
|
return os.NewSyscallError("setsockopt", err)
|
|
|
|
}
|
2012-02-12 20:45:59 -07:00
|
|
|
// Allow reuse of recently-used ports.
|
|
|
|
// This option is supported only in descendants of 4.4BSD,
|
|
|
|
// to make an effective multicast application that requires
|
|
|
|
// quick draw possible.
|
2013-07-27 20:18:06 -06:00
|
|
|
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEPORT, 1))
|
2011-05-02 08:50:12 -06:00
|
|
|
}
|