github.com/osrg/gobgp/v3@v3.30.0/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 //go:build dragonfly || freebsd || netbsd 16 // +build dragonfly freebsd netbsd 17 18 package server 19 20 import ( 21 "net" 22 "syscall" 23 ) 24 25 const ( 26 tcpMD5SIG = 0x10 // TCP MD5 Signature (RFC2385) 27 ipv6MinHopCount = 73 // Generalized TTL Security Mechanism (RFC5082) 28 ) 29 30 func setTcpMD5SigSockopt(l *net.TCPListener, address string, key string) error { 31 sc, err := l.SyscallConn() 32 if err != nil { 33 return err 34 } 35 // always enable and assumes that the configuration is done by setkey() 36 return setsockOptInt(sc, syscall.IPPROTO_TCP, tcpMD5SIG, 1) 37 } 38 39 func setTcpTTLSockopt(conn *net.TCPConn, ttl int) error { 40 family := extractFamilyFromTCPConn(conn) 41 sc, err := conn.SyscallConn() 42 if err != nil { 43 return err 44 } 45 return setsockoptIpTtl(sc, family, ttl) 46 } 47 48 func setTcpMinTTLSockopt(conn *net.TCPConn, ttl int) error { 49 family := extractFamilyFromTCPConn(conn) 50 sc, err := conn.SyscallConn() 51 if err != nil { 52 return err 53 } 54 level := syscall.IPPROTO_IP 55 name := syscall.IP_MINTTL 56 if family == syscall.AF_INET6 { 57 level = syscall.IPPROTO_IPV6 58 name = ipv6MinHopCount 59 } 60 return setsockOptInt(sc, level, name, ttl) 61 } 62 63 func setTcpMSSSockopt(conn *net.TCPConn, mss uint16) error { 64 family := extractFamilyFromTCPConn(conn) 65 sc, err := conn.SyscallConn() 66 if err != nil { 67 return err 68 } 69 return setsockoptTcpMss(sc, family, mss) 70 }