golang.org/x/net@v0.25.1-0.20240516223405-c87a5b62e243/quic/udp_linux.go (about)

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build go1.21 && linux
     6  
     7  package quic
     8  
     9  import (
    10  	"golang.org/x/sys/unix"
    11  )
    12  
    13  // See udp.go.
    14  const (
    15  	udpECNSupport              = true
    16  	udpInvalidLocalAddrIsError = false
    17  )
    18  
    19  // The IP_TOS socket option is a single byte containing the IP TOS field.
    20  // The low two bits are the ECN field.
    21  
    22  func parseIPTOS(b []byte) (ecnBits, bool) {
    23  	if len(b) != 1 {
    24  		return 0, false
    25  	}
    26  	return ecnBits(b[0] & ecnMask), true
    27  }
    28  
    29  func appendCmsgECNv4(b []byte, ecn ecnBits) []byte {
    30  	b, data := appendCmsg(b, unix.IPPROTO_IP, unix.IP_TOS, 1)
    31  	data[0] = byte(ecn)
    32  	return b
    33  }