Skip to content

Commit

Permalink
go.mod: gvisor.dev/gvisor v0.0.0-20221216231429-a78e892a26d2
Browse files Browse the repository at this point in the history
Signed-off-by: Akihiro Suda <[email protected]>
  • Loading branch information
AkihiroSuda authored and cfergeau committed Dec 20, 2022
1 parent 7f0e6e6 commit d098437
Show file tree
Hide file tree
Showing 132 changed files with 5,289 additions and 1,810 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa
golang.org/x/sync v0.1.0
golang.org/x/sys v0.3.0
gvisor.dev/gvisor v0.0.0-20220908032458-edc830a43ba6
gvisor.dev/gvisor v0.0.0-20221216231429-a78e892a26d2
inet.af/tcpproxy v0.0.0-20220326234310-be3ee21c9fa0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gvisor.dev/gvisor v0.0.0-20220908032458-edc830a43ba6 h1:Aq4piePGzmo0ij3yfseJ0rj9W8jxSJgRfiA9QMWngdA=
gvisor.dev/gvisor v0.0.0-20220908032458-edc830a43ba6/go.mod h1:TIvkJD0sxe8pIob3p6T8IzxXunlp6yfgktvTNp+DGNM=
gvisor.dev/gvisor v0.0.0-20221216231429-a78e892a26d2 h1:QN+Xh63jThYFN4CrcD4KXj+rUhevlb0LXEAlZ4m+qXQ=
gvisor.dev/gvisor v0.0.0-20221216231429-a78e892a26d2/go.mod h1:Dn5idtptoW1dIos9U6A2rpebLs/MtTwFacjKb8jLdQA=
inet.af/tcpproxy v0.0.0-20220326234310-be3ee21c9fa0 h1:PqdHrvQRVK1zapJkd0qf6+tevvSIcWdfenVqJd3PHWU=
inet.af/tcpproxy v0.0.0-20220326234310-be3ee21c9fa0/go.mod h1:Tojt5kmHpDIR2jMojxzZK2w2ZR7OILODmUo2gaSwjrk=
8 changes: 4 additions & 4 deletions pkg/tap/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ func (e *LinkEndpoint) IsAttached() bool {
return e.dispatcher != nil
}

func (e *LinkEndpoint) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
func (e *LinkEndpoint) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr) {
e.dispatcher.DeliverNetworkPacket(protocol, pkt)
}

func (e *LinkEndpoint) AddHeader(pkt *stack.PacketBuffer) {
func (e *LinkEndpoint) AddHeader(pkt stack.PacketBufferPtr) {
}

func (e *LinkEndpoint) Capabilities() stack.LinkEndpointCapabilities {
Expand Down Expand Up @@ -93,7 +93,7 @@ func (e *LinkEndpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Err
return n, nil
}

func (e *LinkEndpoint) writePacket(r stack.RouteInfo, protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) tcpip.Error {
func (e *LinkEndpoint) writePacket(r stack.RouteInfo, protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr) tcpip.Error {
// Preserve the src address if it's set in the route.
srcAddr := e.LinkAddress()
if r.LocalLinkAddress != "" {
Expand Down Expand Up @@ -126,7 +126,7 @@ func (e *LinkEndpoint) writePacket(r stack.RouteInfo, protocol tcpip.NetworkProt
return nil
}

func (e *LinkEndpoint) WriteRawPacket(pkt *stack.PacketBuffer) tcpip.Error {
func (e *LinkEndpoint) WriteRawPacket(pkt stack.PacketBufferPtr) tcpip.Error {
return &tcpip.ErrNotSupported{}
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/tap/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import (
)

type VirtualDevice interface {
DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer)
DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr)
LinkAddress() tcpip.LinkAddress
IP() string
}

type NetworkSwitch interface {
DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer)
DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr)
}

type Switch struct {
Expand Down Expand Up @@ -73,7 +73,7 @@ func (e *Switch) Connect(ep VirtualDevice) {
e.gateway = ep
}

func (e *Switch) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
func (e *Switch) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr) {
if err := e.tx(pkt); err != nil {
log.Error(err)
}
Expand Down Expand Up @@ -111,24 +111,24 @@ func (e *Switch) connect(conn net.Conn) (int, bool) {
return id, false
}

func (e *Switch) tx(pkt *stack.PacketBuffer) error {
func (e *Switch) tx(pkt stack.PacketBufferPtr) error {
if e.protocol.Stream() {
return e.txStream(pkt, e.protocol.(streamProtocol))
}
return e.txNonStream(pkt)
}

func (e *Switch) txNonStream(pkt *stack.PacketBuffer) error {
func (e *Switch) txNonStream(pkt stack.PacketBufferPtr) error {
return e.txBuf(pkt, nil)
}

func (e *Switch) txStream(pkt *stack.PacketBuffer, sProtocol streamProtocol) error {
func (e *Switch) txStream(pkt stack.PacketBufferPtr, sProtocol streamProtocol) error {
size := sProtocol.Buf()
sProtocol.Write(size, pkt.Size())
return e.txBuf(pkt, size)
}

func (e *Switch) txBuf(pkt *stack.PacketBuffer, size []byte) error {
func (e *Switch) txBuf(pkt stack.PacketBufferPtr, size []byte) error {
e.writeLock.Lock()
defer e.writeLock.Unlock()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,36 @@
// +build !arm64

package atomicbitops

import (
"gvisor.dev/gvisor/pkg/state"
)

func (b *Bool) StateTypeName() string {
return "pkg/atomicbitops.Bool"
}

func (b *Bool) StateFields() []string {
return []string{
"Uint32",
}
}

func (b *Bool) beforeSave() {}

// +checklocksignore
func (b *Bool) StateSave(stateSinkObject state.Sink) {
b.beforeSave()
stateSinkObject.Save(0, &b.Uint32)
}

func (b *Bool) afterLoad() {}

// +checklocksignore
func (b *Bool) StateLoad(stateSourceObject state.Source) {
stateSourceObject.Load(0, &b.Uint32)
}

func init() {
state.Register((*Bool)(nil))
}
71 changes: 71 additions & 0 deletions vendor/gvisor.dev/gvisor/pkg/atomicbitops/bool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2022 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 atomicbitops

import "sync/atomic"

// Bool is an atomic Boolean.
//
// It is implemented by a Uint32, with value 0 indicating false, and 1
// indicating true.
//
// +stateify savable
type Bool struct {
Uint32
}

// FromBool returns an Bool initialized to value val.
//
//go:nosplit
func FromBool(val bool) Bool {
var u uint32
if val {
u = 1
}
return Bool{
Uint32{
value: u,
},
}
}

// Load is analogous to atomic.LoadBool, if such a thing existed.
//
//go:nosplit
func (b *Bool) Load() bool {
return atomic.LoadUint32(&b.value) == 1
}

// Store is analogous to atomic.StoreBool, if such a thing existed.
//
//go:nosplit
func (b *Bool) Store(val bool) {
var u uint32
if val {
u = 1
}
atomic.StoreUint32(&b.value, u)
}

// Swap is analogous to atomic.SwapBool, if such a thing existed.
//
//go:nosplit
func (b *Bool) Swap(val bool) bool {
var u uint32
if val {
u = 1
}
return atomic.SwapUint32(&b.value, u) == 1
}
20 changes: 20 additions & 0 deletions vendor/gvisor.dev/gvisor/pkg/bufferv2/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package bufferv2
import (
"fmt"
"io"

"gvisor.dev/gvisor/pkg/tcpip/checksum"
)

// Buffer is a non-linear buffer.
Expand Down Expand Up @@ -443,6 +445,24 @@ func (b *Buffer) SubApply(offset, length int, fn func(*View)) {
}
}

// Checksum calculates a checksum over the buffer's payload starting at offset.
func (b *Buffer) Checksum(offset int) uint16 {
if offset >= int(b.size) {
return 0
}
var v *View
for v = b.data.Front(); v != nil && offset >= v.Size(); v = v.Next() {
offset -= v.Size()
}

var cs checksum.Checksumer
cs.Add(v.AsSlice()[offset:])
for v = v.Next(); v != nil; v = v.Next() {
cs.Add(v.AsSlice())
}
return cs.Checksum()
}

// Merge merges the provided Buffer with this one.
//
// The other Buffer will be appended to v, and other will be empty after this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (b *Buffer) afterLoad() {}
// +checklocksignore
func (b *Buffer) StateLoad(stateSourceObject state.Source) {
stateSourceObject.Load(1, &b.size)
stateSourceObject.LoadValue(0, new([]byte), func(y interface{}) { b.loadData(y.([]byte)) })
stateSourceObject.LoadValue(0, new([]byte), func(y any) { b.loadData(y.([]byte)) })
}

func (c *chunk) StateTypeName() string {
Expand Down
12 changes: 3 additions & 9 deletions vendor/gvisor.dev/gvisor/pkg/bufferv2/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ import (
"gvisor.dev/gvisor/pkg/sync"
)

// PoolingEnabled is set to true when pooling is enabled. Added as a
// global to allow easy access.
//
// TODO(b/236996271): Remove once buffer pooling experiment complete.
var PoolingEnabled = true

const (
// This is log2(baseChunkSize). This number is used to calculate which pool
// to use for a payload size by right shifting the payload size by this
Expand All @@ -53,7 +47,7 @@ var chunkPools [numPools]sync.Pool
func init() {
for i := 0; i < numPools; i++ {
chunkSize := baseChunkSize * (1 << i)
chunkPools[i].New = func() interface{} {
chunkPools[i].New = func() any {
return &chunk{
data: make([]byte, chunkSize),
}
Expand Down Expand Up @@ -86,7 +80,7 @@ type chunk struct {

func newChunk(size int) *chunk {
var c *chunk
if !PoolingEnabled || size > MaxChunkSize {
if size > MaxChunkSize {
c = &chunk{
data: make([]byte, size),
}
Expand All @@ -102,7 +96,7 @@ func newChunk(size int) *chunk {
}

func (c *chunk) destroy() {
if !PoolingEnabled || len(c.data) > MaxChunkSize {
if len(c.data) > MaxChunkSize {
c.data = nil
return
}
Expand Down
20 changes: 10 additions & 10 deletions vendor/gvisor.dev/gvisor/pkg/bufferv2/chunk_refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

"gvisor.dev/gvisor/pkg/atomicbitops"
"gvisor.dev/gvisor/pkg/refsvfs2"
"gvisor.dev/gvisor/pkg/refs"
)

// enableLogging indicates whether reference-related events should be logged (with
Expand Down Expand Up @@ -44,20 +44,20 @@ type chunkRefs struct {
// checking.
func (r *chunkRefs) InitRefs() {
r.refCount.Store(1)
refsvfs2.Register(r)
refs.Register(r)
}

// RefType implements refsvfs2.CheckedObject.RefType.
// RefType implements refs.CheckedObject.RefType.
func (r *chunkRefs) RefType() string {
return fmt.Sprintf("%T", chunkobj)[1:]
}

// LeakMessage implements refsvfs2.CheckedObject.LeakMessage.
// LeakMessage implements refs.CheckedObject.LeakMessage.
func (r *chunkRefs) LeakMessage() string {
return fmt.Sprintf("[%s %p] reference count of %d instead of 0", r.RefType(), r, r.ReadRefs())
}

// LogRefs implements refsvfs2.CheckedObject.LogRefs.
// LogRefs implements refs.CheckedObject.LogRefs.
func (r *chunkRefs) LogRefs() bool {
return chunkenableLogging
}
Expand All @@ -74,7 +74,7 @@ func (r *chunkRefs) ReadRefs() int64 {
func (r *chunkRefs) IncRef() {
v := r.refCount.Add(1)
if chunkenableLogging {
refsvfs2.LogIncRef(r, v)
refs.LogIncRef(r, v)
}
if v <= 1 {
panic(fmt.Sprintf("Incrementing non-positive count %p on %s", r, r.RefType()))
Expand All @@ -98,7 +98,7 @@ func (r *chunkRefs) TryIncRef() bool {

v := r.refCount.Add(-speculativeRef + 1)
if chunkenableLogging {
refsvfs2.LogTryIncRef(r, v)
refs.LogTryIncRef(r, v)
}
return true
}
Expand All @@ -118,14 +118,14 @@ func (r *chunkRefs) TryIncRef() bool {
func (r *chunkRefs) DecRef(destroy func()) {
v := r.refCount.Add(-1)
if chunkenableLogging {
refsvfs2.LogDecRef(r, v)
refs.LogDecRef(r, v)
}
switch {
case v < 0:
panic(fmt.Sprintf("Decrementing non-positive ref count %p, owned by %s", r, r.RefType()))

case v == 0:
refsvfs2.Unregister(r)
refs.Unregister(r)

if destroy != nil {
destroy()
Expand All @@ -135,6 +135,6 @@ func (r *chunkRefs) DecRef(destroy func()) {

func (r *chunkRefs) afterLoad() {
if r.ReadRefs() > 0 {
refsvfs2.Register(r)
refs.Register(r)
}
}
2 changes: 1 addition & 1 deletion vendor/gvisor.dev/gvisor/pkg/bufferv2/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
const ReadSize = 512

var viewPool = sync.Pool{
New: func() interface{} {
New: func() any {
return &View{}
},
}
Expand Down
Loading

0 comments on commit d098437

Please sign in to comment.