mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-28 13:49:58 +00:00
TUN-4961: Update quic-go to latest
- Updates fips-go to be the latest on cfsetup.yaml - Updates sumtype's x/tools to be latest to avoid Internal: nil pkg errors with fips.
This commit is contained in:
90
vendor/github.com/lucas-clemente/quic-go/conn_oob.go
generated
vendored
90
vendor/github.com/lucas-clemente/quic-go/conn_oob.go
generated
vendored
@@ -12,13 +12,27 @@ import (
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/net/ipv4"
|
||||
"golang.org/x/net/ipv6"
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
||||
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||
)
|
||||
|
||||
const ecnMask uint8 = 0x3
|
||||
const (
|
||||
ecnMask = 0x3
|
||||
oobBufferSize = 128
|
||||
)
|
||||
|
||||
// Contrary to what the naming suggests, the ipv{4,6}.Message is not dependent on the IP version.
|
||||
// They're both just aliases for x/net/internal/socket.Message.
|
||||
// This means we can use this struct to read from a socket that receives both IPv4 and IPv6 messages.
|
||||
var _ ipv4.Message = ipv6.Message{}
|
||||
|
||||
type batchConn interface {
|
||||
ReadBatch(ms []ipv4.Message, flags int) (int, error)
|
||||
}
|
||||
|
||||
func inspectReadBuffer(c interface{}) (int, error) {
|
||||
conn, ok := c.(interface {
|
||||
@@ -43,7 +57,12 @@ func inspectReadBuffer(c interface{}) (int, error) {
|
||||
|
||||
type oobConn struct {
|
||||
OOBCapablePacketConn
|
||||
oobBuffer []byte
|
||||
batchConn batchConn
|
||||
|
||||
readPos uint8
|
||||
// Packets received from the kernel, but not yet returned by ReadPacket().
|
||||
messages []ipv4.Message
|
||||
buffers [batchSize]*packetBuffer
|
||||
}
|
||||
|
||||
var _ connection = &oobConn{}
|
||||
@@ -94,23 +113,52 @@ func newConn(c OOBCapablePacketConn) (*oobConn, error) {
|
||||
return nil, errors.New("activating packet info failed for both IPv4 and IPv6")
|
||||
}
|
||||
}
|
||||
return &oobConn{
|
||||
|
||||
// Allows callers to pass in a connection that already satisfies batchConn interface
|
||||
// to make use of the optimisation. Otherwise, ipv4.NewPacketConn would unwrap the file descriptor
|
||||
// via SyscallConn(), and read it that way, which might not be what the caller wants.
|
||||
var bc batchConn
|
||||
if ibc, ok := c.(batchConn); ok {
|
||||
bc = ibc
|
||||
} else {
|
||||
bc = ipv4.NewPacketConn(c)
|
||||
}
|
||||
|
||||
oobConn := &oobConn{
|
||||
OOBCapablePacketConn: c,
|
||||
oobBuffer: make([]byte, 128),
|
||||
}, nil
|
||||
batchConn: bc,
|
||||
messages: make([]ipv4.Message, batchSize),
|
||||
readPos: batchSize,
|
||||
}
|
||||
for i := 0; i < batchSize; i++ {
|
||||
oobConn.messages[i].OOB = make([]byte, oobBufferSize)
|
||||
}
|
||||
return oobConn, nil
|
||||
}
|
||||
|
||||
func (c *oobConn) ReadPacket() (*receivedPacket, error) {
|
||||
buffer := getPacketBuffer()
|
||||
// The packet size should not exceed protocol.MaxPacketBufferSize bytes
|
||||
// If it does, we only read a truncated packet, which will then end up undecryptable
|
||||
buffer.Data = buffer.Data[:protocol.MaxPacketBufferSize]
|
||||
c.oobBuffer = c.oobBuffer[:cap(c.oobBuffer)]
|
||||
n, oobn, _, addr, err := c.OOBCapablePacketConn.ReadMsgUDP(buffer.Data, c.oobBuffer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if len(c.messages) == int(c.readPos) { // all messages read. Read the next batch of messages.
|
||||
c.messages = c.messages[:batchSize]
|
||||
// replace buffers data buffers up to the packet that has been consumed during the last ReadBatch call
|
||||
for i := uint8(0); i < c.readPos; i++ {
|
||||
buffer := getPacketBuffer()
|
||||
buffer.Data = buffer.Data[:protocol.MaxPacketBufferSize]
|
||||
c.buffers[i] = buffer
|
||||
c.messages[i].Buffers = [][]byte{c.buffers[i].Data}
|
||||
}
|
||||
c.readPos = 0
|
||||
|
||||
n, err := c.batchConn.ReadBatch(c.messages, 0)
|
||||
if n == 0 || err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.messages = c.messages[:n]
|
||||
}
|
||||
ctrlMsgs, err := unix.ParseSocketControlMessage(c.oobBuffer[:oobn])
|
||||
|
||||
msg := c.messages[c.readPos]
|
||||
buffer := c.buffers[c.readPos]
|
||||
c.readPos++
|
||||
ctrlMsgs, err := unix.ParseSocketControlMessage(msg.OOB[:msg.NN])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -129,13 +177,15 @@ func (c *oobConn) ReadPacket() (*receivedPacket, error) {
|
||||
// struct in_addr ipi_addr; /* Header Destination
|
||||
// address */
|
||||
// };
|
||||
ip := make([]byte, 4)
|
||||
if len(ctrlMsg.Data) == 12 {
|
||||
ifIndex = binary.LittleEndian.Uint32(ctrlMsg.Data)
|
||||
destIP = net.IP(ctrlMsg.Data[8:12])
|
||||
copy(ip, ctrlMsg.Data[8:12])
|
||||
} else if len(ctrlMsg.Data) == 4 {
|
||||
// FreeBSD
|
||||
destIP = net.IP(ctrlMsg.Data)
|
||||
copy(ip, ctrlMsg.Data)
|
||||
}
|
||||
destIP = net.IP(ip)
|
||||
}
|
||||
}
|
||||
if ctrlMsg.Header.Level == unix.IPPROTO_IPV6 {
|
||||
@@ -148,7 +198,9 @@ func (c *oobConn) ReadPacket() (*receivedPacket, error) {
|
||||
// unsigned int ipi6_ifindex; /* send/recv interface index */
|
||||
// };
|
||||
if len(ctrlMsg.Data) == 20 {
|
||||
destIP = net.IP(ctrlMsg.Data[:16])
|
||||
ip := make([]byte, 16)
|
||||
copy(ip, ctrlMsg.Data[:16])
|
||||
destIP = net.IP(ip)
|
||||
ifIndex = binary.LittleEndian.Uint32(ctrlMsg.Data[16:])
|
||||
}
|
||||
}
|
||||
@@ -162,9 +214,9 @@ func (c *oobConn) ReadPacket() (*receivedPacket, error) {
|
||||
}
|
||||
}
|
||||
return &receivedPacket{
|
||||
remoteAddr: addr,
|
||||
remoteAddr: msg.Addr,
|
||||
rcvTime: time.Now(),
|
||||
data: buffer.Data[:n],
|
||||
data: msg.Buffers[0][:msg.N],
|
||||
ecn: ecn,
|
||||
info: info,
|
||||
buffer: buffer,
|
||||
|
Reference in New Issue
Block a user