github.com/osrg/gobgp/v3@v3.30.0/pkg/server/sockopt_windows.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 windows
    16  // +build windows
    17  
    18  package server
    19  
    20  import (
    21  	"fmt"
    22  	"net"
    23  	"syscall"
    24  
    25  	"github.com/osrg/gobgp/v3/pkg/log"
    26  )
    27  
    28  const (
    29  	tcpMD5SIG       = 14   // TCP MD5 Signature (RFC2385)
    30  	ipv6MinHopCount = 73   // Generalized TTL Security Mechanism (RFC5082)
    31  	IP_MINTTL       = 0x15 // pulled from https://golang.org/pkg/syscall/?GOOS=linux#IP_MINTTL
    32  	TCP_MAXSEG      = 0x2  // pulled from https://pkg.go.dev/syscall?GOOS=linux#TCP_MAXSEG
    33  )
    34  
    35  func setTCPMD5SigSockopt(l *net.TCPListener, address string, key string) error {
    36  	return fmt.Errorf("setting md5 is not supported")
    37  }
    38  
    39  func setBindToDevSockopt(sc syscall.RawConn, device string) error {
    40  	return fmt.Errorf("binding connection to a device is not supported")
    41  }
    42  
    43  func setTCPTTLSockopt(conn *net.TCPConn, ttl int) error {
    44  	family := extractFamilyFromTCPConn(conn)
    45  	sc, err := conn.SyscallConn()
    46  	if err != nil {
    47  		return err
    48  	}
    49  	return setsockoptIpTtl(sc, family, ttl)
    50  }
    51  
    52  func setTCPMinTTLSockopt(conn *net.TCPConn, ttl int) error {
    53  	family := extractFamilyFromTCPConn(conn)
    54  	sc, err := conn.SyscallConn()
    55  	if err != nil {
    56  		return err
    57  	}
    58  	level := syscall.IPPROTO_IP
    59  	name := IP_MINTTL
    60  	if family == syscall.AF_INET6 {
    61  		level = syscall.IPPROTO_IPV6
    62  		name = ipv6MinHopCount
    63  	}
    64  	return setsockOptInt(sc, level, name, ttl)
    65  }
    66  
    67  func setTCPMSSSockopt(conn *net.TCPConn, mss uint16) error {
    68  	// TCP_MAXSEG syscall option exists only from Windows 10
    69  	// https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getsockopt
    70  	sc, err := conn.SyscallConn()
    71  	if err != nil {
    72  		return err
    73  	}
    74  	level := syscall.IPPROTO_TCP
    75  	name := TCP_MAXSEG
    76  	return setsockOptInt(sc, level, name, int(mss))
    77  }
    78  
    79  func dialerControl(logger log.Logger, network, address string, c syscall.RawConn, ttl, ttlMin uint8, mss uint16, password string, bindInterface string) error {
    80  	if password != "" {
    81  		logger.Warn("setting md5 for active connection is not supported",
    82  			log.Fields{
    83  				"Topic": "Peer",
    84  				"Key":   address})
    85  	}
    86  	if ttl != 0 {
    87  		logger.Warn("setting ttl for active connection is not supported",
    88  			log.Fields{
    89  				"Topic": "Peer",
    90  				"Key":   address})
    91  	}
    92  	if ttlMin != 0 {
    93  		logger.Warn("setting min ttl for active connection is not supported",
    94  			log.Fields{
    95  				"Topic": "Peer",
    96  				"Key":   address})
    97  	}
    98  	if mss != 0 {
    99  		logger.Warn("setting MSS for active connection is not supported",
   100  			log.Fields{
   101  				"Topic": "Peer",
   102  				"Key":   address})
   103  	}
   104  	return nil
   105  }