mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
net: platform-dependent default socket options
This CL revises existing platform-dependent default socket options to make it possible to accomodate multiple multicast datagram listeners on a single service port. Also removes unnecessary SO_REUSEADDR, SO_REUSEPORT socket options from unicast datagram sockets by default. Fixes #1692. R=devon.odell, alex.brainman, rsc CC=golang-dev https://golang.org/cl/5538052
This commit is contained in:
parent
2374edc640
commit
7419921bf3
6 changed files with 104 additions and 29 deletions
|
|
@ -10,16 +10,27 @@ import (
|
|||
"syscall"
|
||||
)
|
||||
|
||||
func setKernelSpecificSockopt(s, f int) {
|
||||
// Allow reuse of recently-used addresses.
|
||||
syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
|
||||
func setDefaultSockopts(s, f, p int) {
|
||||
switch f {
|
||||
case syscall.AF_INET6:
|
||||
// Allow both IP versions even if the OS default is otherwise.
|
||||
syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, 0)
|
||||
}
|
||||
|
||||
if f == syscall.AF_UNIX || p == syscall.IPPROTO_TCP {
|
||||
// Allow reuse of recently-used addresses.
|
||||
syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
|
||||
}
|
||||
|
||||
// Allow broadcast.
|
||||
syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1)
|
||||
|
||||
if f == syscall.AF_INET6 {
|
||||
// using ip, tcp, udp, etc.
|
||||
// allow both protocols even if the OS default is otherwise.
|
||||
syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, 0)
|
||||
}
|
||||
}
|
||||
|
||||
func setDefaultMulticastSockopts(fd *netFD) {
|
||||
fd.incref()
|
||||
defer fd.decref()
|
||||
// Allow multicast UDP and raw IP datagram sockets to listen
|
||||
// concurrently across multiple listeners.
|
||||
syscall.SetsockoptInt(fd.sysfd, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue