snapshot: sagernet/gvisor v0.0.0-20250811.0-sing-box-mod.1
Содержимое пина, зафиксированного в go.mod sing-box-lx, одним коммитом без истории. Полная история SagerNet/gvisor — 1.45 ГБ и клонируется в каждой CI-джобе; наша дельта — одна вставка в одну функцию, история для неё не нужна. Module path github.com/sagernet/gvisor сохранён намеренно: на него опирается replace-директива суперпроекта. Патч поверх — отдельным коммитом, чтобы дельта читалась одним git show и переносилась на новый пин копированием. SPECS/TASKS/048-GVISOR_HANDSHAKE_NIL_CRASH
This commit is contained in:
commit
2c4ae3b0a4
712 changed files with 185689 additions and 0 deletions
96
pkg/tcpip/link/waitable/endpoint_mutex.go
Normal file
96
pkg/tcpip/link/waitable/endpoint_mutex.go
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
package waitable
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/sagernet/gvisor/pkg/sync"
|
||||
"github.com/sagernet/gvisor/pkg/sync/locking"
|
||||
)
|
||||
|
||||
// RWMutex is sync.RWMutex with the correctness validator.
|
||||
type endpointRWMutex struct {
|
||||
mu sync.RWMutex
|
||||
}
|
||||
|
||||
// lockNames is a list of user-friendly lock names.
|
||||
// Populated in init.
|
||||
var endpointlockNames []string
|
||||
|
||||
// lockNameIndex is used as an index passed to NestedLock and NestedUnlock,
|
||||
// referring to an index within lockNames.
|
||||
// Values are specified using the "consts" field of go_template_instance.
|
||||
type endpointlockNameIndex int
|
||||
|
||||
// DO NOT REMOVE: The following function automatically replaced with lock index constants.
|
||||
// LOCK_NAME_INDEX_CONSTANTS
|
||||
const ()
|
||||
|
||||
// Lock locks m.
|
||||
// +checklocksignore
|
||||
func (m *endpointRWMutex) Lock() {
|
||||
locking.AddGLock(endpointprefixIndex, -1)
|
||||
m.mu.Lock()
|
||||
}
|
||||
|
||||
// NestedLock locks m knowing that another lock of the same type is held.
|
||||
// +checklocksignore
|
||||
func (m *endpointRWMutex) NestedLock(i endpointlockNameIndex) {
|
||||
locking.AddGLock(endpointprefixIndex, int(i))
|
||||
m.mu.Lock()
|
||||
}
|
||||
|
||||
// Unlock unlocks m.
|
||||
// +checklocksignore
|
||||
func (m *endpointRWMutex) Unlock() {
|
||||
m.mu.Unlock()
|
||||
locking.DelGLock(endpointprefixIndex, -1)
|
||||
}
|
||||
|
||||
// NestedUnlock unlocks m knowing that another lock of the same type is held.
|
||||
// +checklocksignore
|
||||
func (m *endpointRWMutex) NestedUnlock(i endpointlockNameIndex) {
|
||||
m.mu.Unlock()
|
||||
locking.DelGLock(endpointprefixIndex, int(i))
|
||||
}
|
||||
|
||||
// RLock locks m for reading.
|
||||
// +checklocksignore
|
||||
func (m *endpointRWMutex) RLock() {
|
||||
locking.AddGLock(endpointprefixIndex, -1)
|
||||
m.mu.RLock()
|
||||
}
|
||||
|
||||
// RUnlock undoes a single RLock call.
|
||||
// +checklocksignore
|
||||
func (m *endpointRWMutex) RUnlock() {
|
||||
m.mu.RUnlock()
|
||||
locking.DelGLock(endpointprefixIndex, -1)
|
||||
}
|
||||
|
||||
// RLockBypass locks m for reading without executing the validator.
|
||||
// +checklocksignore
|
||||
func (m *endpointRWMutex) RLockBypass() {
|
||||
m.mu.RLock()
|
||||
}
|
||||
|
||||
// RUnlockBypass undoes a single RLockBypass call.
|
||||
// +checklocksignore
|
||||
func (m *endpointRWMutex) RUnlockBypass() {
|
||||
m.mu.RUnlock()
|
||||
}
|
||||
|
||||
// DowngradeLock atomically unlocks rw for writing and locks it for reading.
|
||||
// +checklocksignore
|
||||
func (m *endpointRWMutex) DowngradeLock() {
|
||||
m.mu.DowngradeLock()
|
||||
}
|
||||
|
||||
var endpointprefixIndex *locking.MutexClass
|
||||
|
||||
// DO NOT REMOVE: The following function is automatically replaced.
|
||||
func endpointinitLockNames() {}
|
||||
|
||||
func init() {
|
||||
endpointinitLockNames()
|
||||
endpointprefixIndex = locking.NewMutexClass(reflect.TypeOf(endpointRWMutex{}), endpointlockNames)
|
||||
}
|
||||
196
pkg/tcpip/link/waitable/waitable.go
Normal file
196
pkg/tcpip/link/waitable/waitable.go
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
// Copyright 2018 The gVisor Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Package waitable provides the implementation of data-link layer endpoints
|
||||
// that wrap other endpoints, and can wait for inflight calls to WritePacket or
|
||||
// DeliverNetworkPacket to finish (and new ones to be prevented).
|
||||
//
|
||||
// Waitable endpoints can be used in the networking stack by calling New(eID) to
|
||||
// create a new endpoint, where eID is the ID of the endpoint being wrapped,
|
||||
// and then passing it as an argument to Stack.CreateNIC().
|
||||
package waitable
|
||||
|
||||
import (
|
||||
"github.com/sagernet/gvisor/pkg/sync"
|
||||
"github.com/sagernet/gvisor/pkg/tcpip"
|
||||
"github.com/sagernet/gvisor/pkg/tcpip/header"
|
||||
"github.com/sagernet/gvisor/pkg/tcpip/stack"
|
||||
)
|
||||
|
||||
var (
|
||||
_ stack.NetworkDispatcher = (*Endpoint)(nil)
|
||||
_ stack.LinkEndpoint = (*Endpoint)(nil)
|
||||
)
|
||||
|
||||
// Endpoint is a waitable link-layer endpoint.
|
||||
//
|
||||
// +stateify savable
|
||||
type Endpoint struct {
|
||||
dispatchGate sync.Gate
|
||||
|
||||
mu endpointRWMutex `state:"nosave"`
|
||||
// +checklocks:mu
|
||||
dispatcher stack.NetworkDispatcher
|
||||
|
||||
writeGate sync.Gate
|
||||
lower stack.LinkEndpoint
|
||||
}
|
||||
|
||||
// New creates a new waitable link-layer endpoint. It wraps around another
|
||||
// endpoint and allows the caller to block new write/dispatch calls and wait for
|
||||
// the inflight ones to finish before returning.
|
||||
func New(lower stack.LinkEndpoint) *Endpoint {
|
||||
return &Endpoint{
|
||||
lower: lower,
|
||||
}
|
||||
}
|
||||
|
||||
// DeliverNetworkPacket implements stack.NetworkDispatcher.DeliverNetworkPacket.
|
||||
// It is called by the link-layer endpoint being wrapped when a packet arrives,
|
||||
// and only forwards to the actual dispatcher if Wait or WaitDispatch haven't
|
||||
// been called.
|
||||
func (e *Endpoint) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
|
||||
if !e.dispatchGate.Enter() {
|
||||
return
|
||||
}
|
||||
e.mu.RLock()
|
||||
d := e.dispatcher
|
||||
e.mu.RUnlock()
|
||||
if d != nil {
|
||||
d.DeliverNetworkPacket(protocol, pkt)
|
||||
}
|
||||
e.dispatchGate.Leave()
|
||||
}
|
||||
|
||||
// DeliverLinkPacket implements stack.NetworkDispatcher.
|
||||
func (e *Endpoint) DeliverLinkPacket(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
|
||||
if !e.dispatchGate.Enter() {
|
||||
return
|
||||
}
|
||||
e.mu.RLock()
|
||||
d := e.dispatcher
|
||||
e.mu.RUnlock()
|
||||
if d != nil {
|
||||
d.DeliverLinkPacket(protocol, pkt)
|
||||
}
|
||||
e.dispatchGate.Leave()
|
||||
}
|
||||
|
||||
// Attach implements stack.LinkEndpoint.Attach. It saves the dispatcher and
|
||||
// registers with the lower endpoint as its dispatcher so that "e" is called
|
||||
// for inbound packets.
|
||||
func (e *Endpoint) Attach(dispatcher stack.NetworkDispatcher) {
|
||||
e.mu.Lock()
|
||||
e.dispatcher = dispatcher
|
||||
e.mu.Unlock()
|
||||
e.lower.Attach(e)
|
||||
}
|
||||
|
||||
// IsAttached implements stack.LinkEndpoint.IsAttached.
|
||||
func (e *Endpoint) IsAttached() bool {
|
||||
e.mu.RLock()
|
||||
defer e.mu.RUnlock()
|
||||
return e.dispatcher != nil
|
||||
}
|
||||
|
||||
// MTU implements stack.LinkEndpoint.MTU. It just forwards the request to the
|
||||
// lower endpoint.
|
||||
func (e *Endpoint) MTU() uint32 {
|
||||
return e.lower.MTU()
|
||||
}
|
||||
|
||||
// SetMTU implements stack.LinkEndpoint.SetMTU. It just forwards the request to
|
||||
// the lower endpoint.
|
||||
func (e *Endpoint) SetMTU(mtu uint32) {
|
||||
e.lower.SetMTU(mtu)
|
||||
}
|
||||
|
||||
// Capabilities implements stack.LinkEndpoint.Capabilities. It just forwards the
|
||||
// request to the lower endpoint.
|
||||
func (e *Endpoint) Capabilities() stack.LinkEndpointCapabilities {
|
||||
return e.lower.Capabilities()
|
||||
}
|
||||
|
||||
// MaxHeaderLength implements stack.LinkEndpoint.MaxHeaderLength. It just
|
||||
// forwards the request to the lower endpoint.
|
||||
func (e *Endpoint) MaxHeaderLength() uint16 {
|
||||
return e.lower.MaxHeaderLength()
|
||||
}
|
||||
|
||||
// LinkAddress implements stack.LinkEndpoint.LinkAddress. It just forwards the
|
||||
// request to the lower endpoint.
|
||||
func (e *Endpoint) LinkAddress() tcpip.LinkAddress {
|
||||
return e.lower.LinkAddress()
|
||||
}
|
||||
|
||||
// SetLinkAddress implements stack.LinkEndpoint.SetLinkAddress. It forwards the
|
||||
// request to the lower endpoint.
|
||||
func (e *Endpoint) SetLinkAddress(addr tcpip.LinkAddress) {
|
||||
e.mu.Lock()
|
||||
defer e.mu.Unlock()
|
||||
e.lower.SetLinkAddress(addr)
|
||||
}
|
||||
|
||||
// WritePackets implements stack.LinkEndpoint.WritePackets. It is called by
|
||||
// higher-level protocols to write packets. It only forwards packets to the
|
||||
// lower endpoint if Wait or WaitWrite haven't been called.
|
||||
func (e *Endpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error) {
|
||||
if !e.writeGate.Enter() {
|
||||
return pkts.Len(), nil
|
||||
}
|
||||
|
||||
n, err := e.lower.WritePackets(pkts)
|
||||
e.writeGate.Leave()
|
||||
return n, err
|
||||
}
|
||||
|
||||
// WaitWrite prevents new calls to WritePacket from reaching the lower endpoint,
|
||||
// and waits for inflight ones to finish before returning.
|
||||
func (e *Endpoint) WaitWrite() {
|
||||
e.writeGate.Close()
|
||||
}
|
||||
|
||||
// WaitDispatch prevents new calls to DeliverNetworkPacket from reaching the
|
||||
// actual dispatcher, and waits for inflight ones to finish before returning.
|
||||
func (e *Endpoint) WaitDispatch() {
|
||||
e.dispatchGate.Close()
|
||||
}
|
||||
|
||||
// Wait implements stack.LinkEndpoint.Wait.
|
||||
func (e *Endpoint) Wait() {}
|
||||
|
||||
// ARPHardwareType implements stack.LinkEndpoint.ARPHardwareType.
|
||||
func (e *Endpoint) ARPHardwareType() header.ARPHardwareType {
|
||||
return e.lower.ARPHardwareType()
|
||||
}
|
||||
|
||||
// AddHeader implements stack.LinkEndpoint.AddHeader.
|
||||
func (e *Endpoint) AddHeader(pkt *stack.PacketBuffer) {
|
||||
e.lower.AddHeader(pkt)
|
||||
}
|
||||
|
||||
// ParseHeader implements stack.LinkEndpoint.ParseHeader.
|
||||
func (e *Endpoint) ParseHeader(pkt *stack.PacketBuffer) bool {
|
||||
return e.lower.ParseHeader(pkt)
|
||||
}
|
||||
|
||||
// SetOnCloseAction implements stack.LinkEndpoint.SetOnCloseAction.
|
||||
func (e *Endpoint) SetOnCloseAction(action func()) {
|
||||
e.lower.SetOnCloseAction(action)
|
||||
}
|
||||
|
||||
// Close implements stack.LinkEndpoint.
|
||||
func (e *Endpoint) Close() {
|
||||
e.lower.Close()
|
||||
}
|
||||
47
pkg/tcpip/link/waitable/waitable_state_autogen.go
Normal file
47
pkg/tcpip/link/waitable/waitable_state_autogen.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
// automatically generated by stateify.
|
||||
|
||||
package waitable
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/sagernet/gvisor/pkg/state"
|
||||
)
|
||||
|
||||
func (e *Endpoint) StateTypeName() string {
|
||||
return "pkg/tcpip/link/waitable.Endpoint"
|
||||
}
|
||||
|
||||
func (e *Endpoint) StateFields() []string {
|
||||
return []string{
|
||||
"dispatchGate",
|
||||
"dispatcher",
|
||||
"writeGate",
|
||||
"lower",
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Endpoint) beforeSave() {}
|
||||
|
||||
// +checklocksignore
|
||||
func (e *Endpoint) StateSave(stateSinkObject state.Sink) {
|
||||
e.beforeSave()
|
||||
stateSinkObject.Save(0, &e.dispatchGate)
|
||||
stateSinkObject.Save(1, &e.dispatcher)
|
||||
stateSinkObject.Save(2, &e.writeGate)
|
||||
stateSinkObject.Save(3, &e.lower)
|
||||
}
|
||||
|
||||
func (e *Endpoint) afterLoad(context.Context) {}
|
||||
|
||||
// +checklocksignore
|
||||
func (e *Endpoint) StateLoad(ctx context.Context, stateSourceObject state.Source) {
|
||||
stateSourceObject.Load(0, &e.dispatchGate)
|
||||
stateSourceObject.Load(1, &e.dispatcher)
|
||||
stateSourceObject.Load(2, &e.writeGate)
|
||||
stateSourceObject.Load(3, &e.lower)
|
||||
}
|
||||
|
||||
func init() {
|
||||
state.Register((*Endpoint)(nil))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue