snapshot: sagernet/gvisor v0.0.0-20260727.0-sing-box-mod.1 + SPEC 048 guard
Обновление снапшота с v0.0.0-20250811.0 на пин, которого требует sing-box после мержа 235 коммитов (upstream d620bbbf2 "Update gvisor to 20260727.0"). Прежний снапшот был взят 2026-08-04 ровно с той версии, на которой тогда стоял апстрим; разрыв возник 2026-08-05 вместе с его бампом. За год апстрим-gvisor изменил ~14 000 строк в 292 файлах. Значимое для нас — сетевой стек: tcp/connect.go (PMTU-discovery + исправление начального RTT/RTO: раньше задержка ACK внутри стека завышала стартовый таймаут на несколько RTT), tcp/snd.go, tcp/rcv.go, stack/conntrack.go, stack/packet_buffer.go. Всего 30 файлов в TCP и 37 в stack. Баг SPEC 048 апстрим НЕ исправил — проверено по коду новой версии: handleConnecting по-прежнему проверяет состояние endpoint'а, но не ep.h, а performHandshake так же зануляет h и отпускает мьютекс до Close(). Поэтому guard перенесён (12 строк) вместе со своим тестом (45 строк). Red/green проверен на новой базе: без guard'а тест падает с той же nil-паникой, что в полевом крашдампе; с ним зелёный.
This commit is contained in:
parent
ffebe42860
commit
117243aa02
293 changed files with 16413 additions and 2842 deletions
|
|
@ -205,10 +205,80 @@ func (b IPv6) NextHeader() uint8 {
|
|||
}
|
||||
|
||||
// TransportProtocol implements Network.TransportProtocol.
|
||||
//
|
||||
// Deprecated: Use TryParseTransportProtocol instead.
|
||||
// This function does not parse extension headers and returns the next header
|
||||
// field of the IPv6 header as the transport
|
||||
// protocol which may not be the actual transport protocol.
|
||||
// Use TryParseTransportProtocol to get the transport protocol correctly.
|
||||
func (b IPv6) TransportProtocol() tcpip.TransportProtocolNumber {
|
||||
return tcpip.TransportProtocolNumber(b.NextHeader())
|
||||
}
|
||||
|
||||
// IsExtensionHeader returns true if the next header is a known extension header.
|
||||
func IsExtensionHeader(nextHdr uint8) bool {
|
||||
extType := IPv6ExtensionHeaderIdentifier(nextHdr)
|
||||
switch extType {
|
||||
case IPv6HopByHopOptionsExtHdrIdentifier, IPv6RoutingExtHdrIdentifier, IPv6FragmentExtHdrIdentifier, IPv6DestinationOptionsExtHdrIdentifier, IPv6AuthenticationExtHdrIdentifier, IPv6NoNextHeaderIdentifier:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// TryParseTransportProtocol parses the IPv6 header and extension headers to get the
|
||||
// transport protocol.
|
||||
// Reference: net/ipv6/exthdrs_core.c:ipv6_skip_exthdr.
|
||||
// Returns the transport protocol and a boolean indicating if the transport
|
||||
// protocol parsing was successful.
|
||||
func (b IPv6) TryParseTransportProtocol() (tcpip.TransportProtocolNumber, bool) {
|
||||
if len(b) < IPv6MinimumSize {
|
||||
return 0, false
|
||||
}
|
||||
data := []byte(b[IPv6MinimumSize:])
|
||||
nxtHdr := b.NextHeader()
|
||||
maybeProto := tcpip.TransportProtocolNumber(nxtHdr)
|
||||
for IsExtensionHeader(nxtHdr) {
|
||||
dataLen := len(data)
|
||||
if dataLen < 2 {
|
||||
return maybeProto, false
|
||||
}
|
||||
currHdrLen := 0
|
||||
switch IPv6ExtensionHeaderIdentifier(nxtHdr) {
|
||||
case IPv6FragmentExtHdrIdentifier:
|
||||
// Fragment extension header is always 8 bytes long.
|
||||
if dataLen < 8 {
|
||||
return maybeProto, false
|
||||
}
|
||||
// Get the fragment offset from the fragment extension header.
|
||||
fragOffset := binary.BigEndian.Uint16(data[2:4]) & ^uint16(0x7)
|
||||
if fragOffset != 0 {
|
||||
return tcpip.TransportProtocolNumber(data[0]), false
|
||||
}
|
||||
currHdrLen = 8
|
||||
case IPv6HopByHopOptionsExtHdrIdentifier, IPv6RoutingExtHdrIdentifier, IPv6DestinationOptionsExtHdrIdentifier:
|
||||
currHdrLen = int(data[1]+1) * 8
|
||||
case IPv6AuthenticationExtHdrIdentifier:
|
||||
// Authentication extension header length calculation is different from
|
||||
// other extension headers.
|
||||
currHdrLen = int(data[1]+2) * 4
|
||||
default:
|
||||
// IPv6NoNextHeaderIdentifier or any unknown extension header.
|
||||
return maybeProto, false
|
||||
}
|
||||
if currHdrLen > len(data) {
|
||||
return maybeProto, false
|
||||
}
|
||||
nxtHdr = data[0]
|
||||
maybeProto = tcpip.TransportProtocolNumber(nxtHdr)
|
||||
data = data[currHdrLen:]
|
||||
}
|
||||
if len(data) == 0 {
|
||||
return maybeProto, false
|
||||
}
|
||||
return maybeProto, true
|
||||
}
|
||||
|
||||
// Payload implements Network.Payload.
|
||||
func (b IPv6) Payload() []byte {
|
||||
return b[IPv6MinimumSize:][:b.PayloadLength()]
|
||||
|
|
|
|||
|
|
@ -45,6 +45,11 @@ const (
|
|||
// Destination Options extension header, as per RFC 8200 section 4.6.
|
||||
IPv6DestinationOptionsExtHdrIdentifier IPv6ExtensionHeaderIdentifier = 60
|
||||
|
||||
// IPv6AuthenticationExtHdrIdentifier is the header identifier of an
|
||||
// Authentication extension header, as per RFC 8200 section 4.1.
|
||||
// TODO: b/512233021 - Parse Authentication extension header correctly.
|
||||
IPv6AuthenticationExtHdrIdentifier IPv6ExtensionHeaderIdentifier = 51
|
||||
|
||||
// IPv6NoNextHeaderIdentifier is the header identifier used to signify the end
|
||||
// of an IPv6 payload, as per RFC 8200 section 4.7.
|
||||
IPv6NoNextHeaderIdentifier IPv6ExtensionHeaderIdentifier = 59
|
||||
|
|
|
|||
|
|
@ -158,9 +158,19 @@ traverseExtensions:
|
|||
//
|
||||
// Returns true if the header was successfully parsed.
|
||||
func UDP(pkt *stack.PacketBuffer) bool {
|
||||
_, ok := pkt.TransportHeader().Consume(header.UDPMinimumSize)
|
||||
hdr, ok := pkt.TransportHeader().Consume(header.UDPMinimumSize)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
pkt.TransportProtocolNumber = header.UDPProtocolNumber
|
||||
return ok
|
||||
// Validate the UDP payload length.
|
||||
length := int(header.UDP(hdr).Length()) - header.UDPMinimumSize
|
||||
if length < 0 || length > pkt.Data().Size() {
|
||||
return false
|
||||
}
|
||||
// Trim the payload to the length specified in the UDP header.
|
||||
pkt.Data().CapLength(length)
|
||||
return true
|
||||
}
|
||||
|
||||
// TCP parses a TCP packet found in pkt.Data and populates pkt's transport
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ package header
|
|||
import (
|
||||
"encoding/binary"
|
||||
|
||||
"github.com/google/btree"
|
||||
"github.com/sagernet/gvisor/pkg/tcpip"
|
||||
"github.com/sagernet/gvisor/pkg/tcpip/checksum"
|
||||
"github.com/sagernet/gvisor/pkg/tcpip/seqnum"
|
||||
|
|
@ -175,11 +174,6 @@ type SACKBlock struct {
|
|||
End seqnum.Value
|
||||
}
|
||||
|
||||
// Less returns true if r.Start < b.Start.
|
||||
func (r SACKBlock) Less(b btree.Item) bool {
|
||||
return r.Start.LessThan(b.(SACKBlock).Start)
|
||||
}
|
||||
|
||||
// Contains returns true if b is completely contained in r.
|
||||
func (r SACKBlock) Contains(b SACKBlock) bool {
|
||||
return r.Start.LessThanEq(b.Start) && b.End.LessThanEq(r.End)
|
||||
|
|
@ -219,9 +213,8 @@ const (
|
|||
// TCPTotalHeaderMaximumSize is the maximum size of headers from all layers in
|
||||
// a TCP packet. It analogous to MAX_TCP_HEADER in Linux.
|
||||
//
|
||||
// TODO(b/319936470): Investigate why this needs to be at least 140 bytes. In
|
||||
// Linux this value is at least 160, but in theory we should be able to use
|
||||
// 138. In practice anything less than 140 starts to break GSO on gVNIC
|
||||
// Note: In Linux this value is at least 160, but in theory we should be able
|
||||
// to use 138. In practice anything less than 140 starts to break GSO on gVNIC
|
||||
// hardware.
|
||||
TCPTotalHeaderMaximumSize = 160
|
||||
|
||||
|
|
|
|||
|
|
@ -138,20 +138,33 @@ func (b UDP) Encode(u *UDPFields) {
|
|||
|
||||
// SetSourcePortWithChecksumUpdate implements ChecksummableTransport.
|
||||
func (b UDP) SetSourcePortWithChecksumUpdate(new uint16) {
|
||||
if b.Checksum() == 0 {
|
||||
b.SetSourcePort(new)
|
||||
return
|
||||
}
|
||||
old := b.SourcePort()
|
||||
b.SetSourcePort(new)
|
||||
b.SetChecksum(^checksumUpdate2ByteAlignedUint16(^b.Checksum(), old, new))
|
||||
xsum := ^checksumUpdate2ByteAlignedUint16(^b.Checksum(), old, new)
|
||||
b.SetChecksum(normalizeChecksum(xsum))
|
||||
}
|
||||
|
||||
// SetDestinationPortWithChecksumUpdate implements ChecksummableTransport.
|
||||
func (b UDP) SetDestinationPortWithChecksumUpdate(new uint16) {
|
||||
if b.Checksum() == 0 {
|
||||
b.SetDestinationPort(new)
|
||||
return
|
||||
}
|
||||
old := b.DestinationPort()
|
||||
b.SetDestinationPort(new)
|
||||
b.SetChecksum(^checksumUpdate2ByteAlignedUint16(^b.Checksum(), old, new))
|
||||
xsum := ^checksumUpdate2ByteAlignedUint16(^b.Checksum(), old, new)
|
||||
b.SetChecksum(normalizeChecksum(xsum))
|
||||
}
|
||||
|
||||
// UpdateChecksumPseudoHeaderAddress implements ChecksummableTransport.
|
||||
func (b UDP) UpdateChecksumPseudoHeaderAddress(old, new tcpip.Address, fullChecksum bool) {
|
||||
if fullChecksum && b.Checksum() == 0 {
|
||||
return
|
||||
}
|
||||
xsum := b.Checksum()
|
||||
if fullChecksum {
|
||||
xsum = ^xsum
|
||||
|
|
@ -159,7 +172,7 @@ func (b UDP) UpdateChecksumPseudoHeaderAddress(old, new tcpip.Address, fullCheck
|
|||
|
||||
xsum = checksumUpdate2ByteAlignedAddress(xsum, old, new)
|
||||
if fullChecksum {
|
||||
xsum = ^xsum
|
||||
xsum = normalizeChecksum(^xsum)
|
||||
}
|
||||
|
||||
b.SetChecksum(xsum)
|
||||
|
|
@ -197,3 +210,14 @@ func UDPValid(hdr UDP, payloadChecksum func() uint16, payloadSize uint16, netPro
|
|||
|
||||
return true, hdr.IsChecksumValid(srcAddr, dstAddr, payloadChecksum())
|
||||
}
|
||||
|
||||
func normalizeChecksum(xsum uint16) uint16 {
|
||||
// RFC 768:
|
||||
// If the computed UDP checksum is zero, it is transmitted as all ones.
|
||||
// An all zero transmitted checksum value means that
|
||||
// the transmitter generated no checksum.
|
||||
if xsum == 0 {
|
||||
return 0xFFFF
|
||||
}
|
||||
return xsum
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue