github.com/osrg/gobgp@v2.0.0+incompatible/pkg/server/sockopt_bsd.go (about) 1 // Copyright (C) 2016 Nippon Telegraph and Telephone Corporation. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 // implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // +build dragonfly freebsd netbsd 16 17 package server 18 19 import ( 20 "net" 21 "syscall" 22 ) 23 24 const ( 25 tcpMD5SIG = 0x10 // TCP MD5 Signature (RFC2385) 26 ipv6MinHopCount = 73 // Generalized TTL Security Mechanism (RFC5082) 27 ) 28 29 func setTcpMD5SigSockopt(l *net.TCPListener, address string, key string) error { 30 sc, err := l.SyscallConn() 31 if err != nil { 32 return err 33 } 34 // always enable and assumes that the configuration is done by setkey() 35 return setsockOptInt(sc, syscall.IPPROTO_TCP, tcpMD5SIG, 1) 36 } 37 38 func setListenTcpTTLSockopt(l *net.TCPListener, ttl int) error { 39 family := extractFamilyFromTCPListener(l) 40 sc, err := l.SyscallConn() 41 if err != nil { 42 return err 43 } 44 return setsockoptIpTtl(sc, family, ttl) 45 } 46 47 func setTcpTTLSockopt(conn *net.TCPConn, ttl int) error { 48 family := extractFamilyFromTCPConn(conn) 49 sc, err := conn.SyscallConn() 50 if err != nil { 51 return err 52 } 53 return setsockoptIpTtl(sc, family, ttl) 54 } 55 56 func setTcpMinTTLSockopt(conn *net.TCPConn, ttl int) error { 57 family := extractFamilyFromTCPConn(conn) 58 sc, err := conn.SyscallConn() 59 if err != nil { 60 return err 61 } 62 level := syscall.IPPROTO_IP 63 name := syscall.IP_MINTTL 64 if family == syscall.AF_INET6 { 65 level = syscall.IPPROTO_IPV6 66 name = ipv6MinHopCount 67 } 68 return setsockOptInt(sc, level, name, ttl) 69 }