Skip to content

Commit 94898d5

Browse files
Merge pull request #410 from AkihiroSuda/gvisor
Update to gvisor release-20240916.0
2 parents 78d4944 + a312ff4 commit 94898d5

File tree

12 files changed

+124
-81
lines changed

12 files changed

+124
-81
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ require (
2828
golang.org/x/crypto v0.28.0
2929
golang.org/x/sync v0.8.0
3030
golang.org/x/sys v0.26.0
31-
gvisor.dev/gvisor v0.0.0-20240826182512-9f3309e5b121
31+
gvisor.dev/gvisor v0.0.0-20240916094835-a174eb65023f
3232
)
3333

3434
require (

go.sum

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ github.com/apparentlymart/go-cidr v1.1.0 h1:2mAhrMoF+nhXqxTzSZMUzDHkLjmIHC+Zzn4t
44
github.com/apparentlymart/go-cidr v1.1.0/go.mod h1:EBcsNrHc3zQeuaeCeCtQruQm+n9/YjEn/vI25Lg7Gwc=
55
github.com/areYouLazy/libhosty v1.1.0 h1:kO6UTk9z72cHW28A/V1kKi7C8iKQGqINiVGXp+05Eao=
66
github.com/areYouLazy/libhosty v1.1.0/go.mod h1:dV4ir3feRrTbWdcJ21mt3MeZlASg0sc8db6nimL9GOA=
7-
github.com/armon/go-proxyproto v0.0.0-20210323213023-7e956b284f0a/go.mod h1:QmP9hvJ91BbJmGVGSbutW19IC0Q9phDCLGaomwTJbgU=
87
github.com/containers/winquit v1.1.0 h1:jArun04BNDQvt2W0Y78kh9TazN2EIEMG5Im6/JY7+pE=
98
github.com/containers/winquit v1.1.0/go.mod h1:PsPeZlnbkmGGIToMPHF1zhWjBUkd8aHjMOr/vFcPxw8=
109
github.com/coreos/stream-metadata-go v0.4.4 h1:PM/6iNhofKGydsatiY1zdnMMHBT34skb5P7nfEFR4GU=
@@ -43,8 +42,6 @@ github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo
4342
github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5 h1:5iH8iuqE5apketRbSFBy+X1V0o+l+8NF1avt4HWl7cA=
4443
github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
4544
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
46-
github.com/inetaf/tcpproxy v0.0.0-20221017015627-91f861402626 h1:oeu2cpk2bBlSgMQiSQIBJ8+FZsTqMG9fwdPez/weEbk=
47-
github.com/inetaf/tcpproxy v0.0.0-20221017015627-91f861402626/go.mod h1:Tojt5kmHpDIR2jMojxzZK2w2ZR7OILODmUo2gaSwjrk=
4845
github.com/insomniacslk/dhcp v0.0.0-20240710054256-ddd8a41251c9 h1:LZJWucZz7ztCqY6Jsu7N9g124iJ2kt/O62j3+UchZFg=
4946
github.com/insomniacslk/dhcp v0.0.0-20240710054256-ddd8a41251c9/go.mod h1:KclMyHxX06VrVr0DJmeFSUb1ankt7xTfoOA35pCkoic=
5047
github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA=
@@ -177,5 +174,5 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
177174
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
178175
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
179176
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
180-
gvisor.dev/gvisor v0.0.0-20240826182512-9f3309e5b121 h1:2Vd3QUoPYevmDp3S7jUQgxEzdeMlDh8pYFELopFXn3w=
181-
gvisor.dev/gvisor v0.0.0-20240826182512-9f3309e5b121/go.mod h1:sxc3Uvk/vHcd3tj7/DHVBoR5wvWT/MmRq2pj7HRJnwU=
177+
gvisor.dev/gvisor v0.0.0-20240916094835-a174eb65023f h1:O2w2DymsOlM/nv2pLNWCMCYOldgBBMkD7H0/prN5W2k=
178+
gvisor.dev/gvisor v0.0.0-20240916094835-a174eb65023f/go.mod h1:sxc3Uvk/vHcd3tj7/DHVBoR5wvWT/MmRq2pj7HRJnwU=

vendor/gvisor.dev/gvisor/pkg/sleep/sleep_unsafe.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ type Waker struct {
394394
allWakersNext *Waker
395395
}
396396

397+
// +stateify savable
397398
type wakerState struct {
398399
asserted bool
399400
other *Sleeper

vendor/gvisor.dev/gvisor/pkg/sleep/sleep_unsafe_state_autogen.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,36 @@ func (w *Waker) StateLoad(ctx context.Context, stateSourceObject state.Source) {
7474
stateSourceObject.LoadValue(0, new(wakerState), func(y any) { w.loadS(ctx, y.(wakerState)) })
7575
}
7676

77+
func (w *wakerState) StateTypeName() string {
78+
return "pkg/sleep.wakerState"
79+
}
80+
81+
func (w *wakerState) StateFields() []string {
82+
return []string{
83+
"asserted",
84+
"other",
85+
}
86+
}
87+
88+
func (w *wakerState) beforeSave() {}
89+
90+
// +checklocksignore
91+
func (w *wakerState) StateSave(stateSinkObject state.Sink) {
92+
w.beforeSave()
93+
stateSinkObject.Save(0, &w.asserted)
94+
stateSinkObject.Save(1, &w.other)
95+
}
96+
97+
func (w *wakerState) afterLoad(context.Context) {}
98+
99+
// +checklocksignore
100+
func (w *wakerState) StateLoad(ctx context.Context, stateSourceObject state.Source) {
101+
stateSourceObject.Load(0, &w.asserted)
102+
stateSourceObject.Load(1, &w.other)
103+
}
104+
77105
func init() {
78106
state.Register((*Sleeper)(nil))
79107
state.Register((*Waker)(nil))
108+
state.Register((*wakerState)(nil))
80109
}

vendor/gvisor.dev/gvisor/pkg/state/wire/wire.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,8 @@ func (r *Reader) readByte() byte {
5858
type Writer struct {
5959
io.Writer
6060

61-
buf [1]byte
62-
}
63-
64-
// writeByte writes a single byte to w.Writer without allocation. It panics on
65-
// error.
66-
func (w *Writer) writeByte(b byte) {
67-
w.buf[0] = b
68-
n, err := w.Write(w.buf[:])
69-
if n != 1 {
70-
panic(err)
71-
}
61+
// buf is used by Uint as a scratch buffer.
62+
buf [10]byte
7263
}
7364

7465
// readFull is a utility. The equivalent is not needed for Write, but the API
@@ -173,11 +164,16 @@ func loadUint(r *Reader) Uint {
173164

174165
// save implements Object.save.
175166
func (u Uint) save(w *Writer) {
167+
i := 0
176168
for u >= 0x80 {
177-
w.writeByte(byte(u) | 0x80)
169+
w.buf[i] = byte(u) | 0x80
170+
i++
178171
u >>= 7
179172
}
180-
w.writeByte(byte(u))
173+
w.buf[i] = byte(u)
174+
if _, err := w.Write(w.buf[:i+1]); err != nil {
175+
panic(err)
176+
}
181177
}
182178

183179
// load implements Object.load.

vendor/gvisor.dev/gvisor/pkg/tcpip/link/sniffer/sniffer.go

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,19 @@ var LogPackets atomicbitops.Uint32 = atomicbitops.FromUint32(1)
4444
// sniffer was created for this flag to have effect.
4545
var LogPacketsToPCAP atomicbitops.Uint32 = atomicbitops.FromUint32(1)
4646

47+
// Endpoint is used to sniff and log network traffic.
48+
//
4749
// +stateify savable
48-
type endpoint struct {
50+
type Endpoint struct {
4951
nested.Endpoint
5052
writer io.Writer
5153
maxPCAPLen uint32
5254
logPrefix string
5355
}
5456

55-
var _ stack.GSOEndpoint = (*endpoint)(nil)
56-
var _ stack.LinkEndpoint = (*endpoint)(nil)
57-
var _ stack.NetworkDispatcher = (*endpoint)(nil)
57+
var _ stack.GSOEndpoint = (*Endpoint)(nil)
58+
var _ stack.LinkEndpoint = (*Endpoint)(nil)
59+
var _ stack.NetworkDispatcher = (*Endpoint)(nil)
5860

5961
// A Direction indicates whether the packing is being sent or received.
6062
type Direction int
@@ -66,9 +68,20 @@ const (
6668
DirectionRecv
6769
)
6870

71+
func (dr Direction) String() string {
72+
switch dr {
73+
case DirectionSend:
74+
return "send"
75+
case DirectionRecv:
76+
return "recv"
77+
default:
78+
panic(fmt.Sprintf("invalid Direction %d", dr))
79+
}
80+
}
81+
6982
// New creates a new sniffer link-layer endpoint. It wraps around another
7083
// endpoint and logs packets and they traverse the endpoint.
71-
func New(lower stack.LinkEndpoint) stack.LinkEndpoint {
84+
func New(lower stack.LinkEndpoint) *Endpoint {
7285
return NewWithPrefix(lower, "")
7386
}
7487

@@ -79,8 +92,8 @@ func New(lower stack.LinkEndpoint) stack.LinkEndpoint {
7992
// logPrefix is prepended to the log line without any separators.
8093
// E.g. logPrefix = "NIC:en0/" will produce log lines like
8194
// "NIC:en0/send udp [...]".
82-
func NewWithPrefix(lower stack.LinkEndpoint, logPrefix string) stack.LinkEndpoint {
83-
sniffer := &endpoint{logPrefix: logPrefix}
95+
func NewWithPrefix(lower stack.LinkEndpoint, logPrefix string) *Endpoint {
96+
sniffer := &Endpoint{logPrefix: logPrefix}
8497
sniffer.Endpoint.Init(lower, sniffer)
8598
return sniffer
8699
}
@@ -119,11 +132,11 @@ func writePCAPHeader(w io.Writer, maxLen uint32) error {
119132
// snapLen is the maximum amount of a packet to be saved. Packets with a length
120133
// less than or equal to snapLen will be saved in their entirety. Longer
121134
// packets will be truncated to snapLen.
122-
func NewWithWriter(lower stack.LinkEndpoint, writer io.Writer, snapLen uint32) (stack.LinkEndpoint, error) {
135+
func NewWithWriter(lower stack.LinkEndpoint, writer io.Writer, snapLen uint32) (*Endpoint, error) {
123136
if err := writePCAPHeader(writer, snapLen); err != nil {
124137
return nil, err
125138
}
126-
sniffer := &endpoint{
139+
sniffer := &Endpoint{
127140
writer: writer,
128141
maxPCAPLen: snapLen,
129142
}
@@ -134,22 +147,28 @@ func NewWithWriter(lower stack.LinkEndpoint, writer io.Writer, snapLen uint32) (
134147
// DeliverNetworkPacket implements the stack.NetworkDispatcher interface. It is
135148
// called by the link-layer endpoint being wrapped when a packet arrives, and
136149
// logs the packet before forwarding to the actual dispatcher.
137-
func (e *endpoint) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
138-
e.dumpPacket(DirectionRecv, protocol, pkt)
150+
func (e *Endpoint) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
151+
e.DumpPacket(DirectionRecv, protocol, pkt, nil)
139152
e.Endpoint.DeliverNetworkPacket(protocol, pkt)
140153
}
141154

142-
func (e *endpoint) dumpPacket(dir Direction, protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
155+
// DumpPacket logs a packet, depending on configuration, to stderr and/or a
156+
// pcap file. ts is an optional timestamp for the packet.
157+
func (e *Endpoint) DumpPacket(dir Direction, protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer, ts *time.Time) {
143158
writer := e.writer
144159
if LogPackets.Load() == 1 {
145160
LogPacket(e.logPrefix, dir, protocol, pkt)
146161
}
147162
if writer != nil && LogPacketsToPCAP.Load() == 1 {
148163
packet := pcapPacket{
149-
timestamp: time.Now(),
150164
packet: pkt,
151165
maxCaptureLen: int(e.maxPCAPLen),
152166
}
167+
if ts == nil {
168+
packet.timestamp = time.Now()
169+
} else {
170+
packet.timestamp = *ts
171+
}
153172
b, err := packet.MarshalBinary()
154173
if err != nil {
155174
panic(err)
@@ -163,9 +182,9 @@ func (e *endpoint) dumpPacket(dir Direction, protocol tcpip.NetworkProtocolNumbe
163182
// WritePackets implements the stack.LinkEndpoint interface. It is called by
164183
// higher-level protocols to write packets; it just logs the packet and
165184
// forwards the request to the lower endpoint.
166-
func (e *endpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error) {
185+
func (e *Endpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error) {
167186
for _, pkt := range pkts.AsSlice() {
168-
e.dumpPacket(DirectionSend, pkt.NetworkProtocolNumber, pkt)
187+
e.DumpPacket(DirectionSend, pkt.NetworkProtocolNumber, pkt, nil)
169188
}
170189
return e.Endpoint.WritePackets(pkts)
171190
}
@@ -181,16 +200,6 @@ func LogPacket(prefix string, dir Direction, protocol tcpip.NetworkProtocolNumbe
181200
var fragmentOffset uint16
182201
var moreFragments bool
183202

184-
var directionPrefix string
185-
switch dir {
186-
case DirectionSend:
187-
directionPrefix = "send"
188-
case DirectionRecv:
189-
directionPrefix = "recv"
190-
default:
191-
panic(fmt.Sprintf("unrecognized direction: %d", dir))
192-
}
193-
194203
clone := trimmedClone(pkt)
195204
defer clone.DecRef()
196205
switch protocol {
@@ -232,14 +241,14 @@ func LogPacket(prefix string, dir Direction, protocol tcpip.NetworkProtocolNumbe
232241
log.Infof(
233242
"%s%s arp %s (%s) -> %s (%s) valid:%t",
234243
prefix,
235-
directionPrefix,
244+
dir,
236245
tcpip.AddrFromSlice(arp.ProtocolAddressSender()), tcpip.LinkAddress(arp.HardwareAddressSender()),
237246
tcpip.AddrFromSlice(arp.ProtocolAddressTarget()), tcpip.LinkAddress(arp.HardwareAddressTarget()),
238247
arp.IsValid(),
239248
)
240249
return
241250
default:
242-
log.Infof("%s%s unknown network protocol: %d", prefix, directionPrefix, protocol)
251+
log.Infof("%s%s unknown network protocol: %d", prefix, dir, protocol)
243252
return
244253
}
245254

@@ -283,7 +292,7 @@ func LogPacket(prefix string, dir Direction, protocol tcpip.NetworkProtocolNumbe
283292
icmpType = "info reply"
284293
}
285294
}
286-
log.Infof("%s%s %s %s -> %s %s len:%d id:%04x code:%d", prefix, directionPrefix, transName, src, dst, icmpType, size, id, icmp.Code())
295+
log.Infof("%s%s %s %s -> %s %s len:%d id:%04x code:%d", prefix, dir, transName, src, dst, icmpType, size, id, icmp.Code())
287296
return
288297

289298
case header.ICMPv6ProtocolNumber:
@@ -318,7 +327,7 @@ func LogPacket(prefix string, dir Direction, protocol tcpip.NetworkProtocolNumbe
318327
case header.ICMPv6RedirectMsg:
319328
icmpType = "redirect message"
320329
}
321-
log.Infof("%s%s %s %s -> %s %s len:%d id:%04x code:%d", prefix, directionPrefix, transName, src, dst, icmpType, size, id, icmp.Code())
330+
log.Infof("%s%s %s %s -> %s %s len:%d id:%04x code:%d", prefix, dir, transName, src, dst, icmpType, size, id, icmp.Code())
322331
return
323332

324333
case header.UDPProtocolNumber:
@@ -359,24 +368,24 @@ func LogPacket(prefix string, dir Direction, protocol tcpip.NetworkProtocolNumbe
359368

360369
// Initialize the TCP flags.
361370
flags := tcp.Flags()
362-
details = fmt.Sprintf("flags: %s seqnum: %d ack: %d win: %d xsum:0x%x", flags, tcp.SequenceNumber(), tcp.AckNumber(), tcp.WindowSize(), tcp.Checksum())
371+
details = fmt.Sprintf("flags:%s seqnum:%d ack:%d win:%d xsum:0x%x", flags, tcp.SequenceNumber(), tcp.AckNumber(), tcp.WindowSize(), tcp.Checksum())
363372
if flags&header.TCPFlagSyn != 0 {
364-
details += fmt.Sprintf(" options: %+v", header.ParseSynOptions(tcp.Options(), flags&header.TCPFlagAck != 0))
373+
details += fmt.Sprintf(" options:%+v", header.ParseSynOptions(tcp.Options(), flags&header.TCPFlagAck != 0))
365374
} else {
366-
details += fmt.Sprintf(" options: %+v", tcp.ParsedOptions())
375+
details += fmt.Sprintf(" options:%+v", tcp.ParsedOptions())
367376
}
368377
}
369378

370379
default:
371-
log.Infof("%s%s %s -> %s unknown transport protocol: %d", prefix, directionPrefix, src, dst, transProto)
380+
log.Infof("%s%s %s -> %s unknown transport protocol: %d", prefix, dir, src, dst, transProto)
372381
return
373382
}
374383

375384
if pkt.GSOOptions.Type != stack.GSONone {
376-
details += fmt.Sprintf(" gso: %#v", pkt.GSOOptions)
385+
details += fmt.Sprintf(" gso:%#v", pkt.GSOOptions)
377386
}
378387

379-
log.Infof("%s%s %s %s:%d -> %s:%d len:%d id:%04x %s", prefix, directionPrefix, transName, src, srcPort, dst, dstPort, size, id, details)
388+
log.Infof("%s%s %s %s:%d -> %s:%d len:%d id:0x%04x %s", prefix, dir, transName, src, srcPort, dst, dstPort, size, id, details)
380389
}
381390

382391
// trimmedClone clones the packet buffer to not modify the original. It trims

vendor/gvisor.dev/gvisor/pkg/tcpip/link/sniffer/sniffer_state_autogen.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88
"gvisor.dev/gvisor/pkg/state"
99
)
1010

11-
func (e *endpoint) StateTypeName() string {
12-
return "pkg/tcpip/link/sniffer.endpoint"
11+
func (e *Endpoint) StateTypeName() string {
12+
return "pkg/tcpip/link/sniffer.Endpoint"
1313
}
1414

15-
func (e *endpoint) StateFields() []string {
15+
func (e *Endpoint) StateFields() []string {
1616
return []string{
1717
"Endpoint",
1818
"writer",
@@ -21,27 +21,27 @@ func (e *endpoint) StateFields() []string {
2121
}
2222
}
2323

24-
func (e *endpoint) beforeSave() {}
24+
func (e *Endpoint) beforeSave() {}
2525

2626
// +checklocksignore
27-
func (e *endpoint) StateSave(stateSinkObject state.Sink) {
27+
func (e *Endpoint) StateSave(stateSinkObject state.Sink) {
2828
e.beforeSave()
2929
stateSinkObject.Save(0, &e.Endpoint)
3030
stateSinkObject.Save(1, &e.writer)
3131
stateSinkObject.Save(2, &e.maxPCAPLen)
3232
stateSinkObject.Save(3, &e.logPrefix)
3333
}
3434

35-
func (e *endpoint) afterLoad(context.Context) {}
35+
func (e *Endpoint) afterLoad(context.Context) {}
3636

3737
// +checklocksignore
38-
func (e *endpoint) StateLoad(ctx context.Context, stateSourceObject state.Source) {
38+
func (e *Endpoint) StateLoad(ctx context.Context, stateSourceObject state.Source) {
3939
stateSourceObject.Load(0, &e.Endpoint)
4040
stateSourceObject.Load(1, &e.writer)
4141
stateSourceObject.Load(2, &e.maxPCAPLen)
4242
stateSourceObject.Load(3, &e.logPrefix)
4343
}
4444

4545
func init() {
46-
state.Register((*endpoint)(nil))
46+
state.Register((*Endpoint)(nil))
4747
}

vendor/gvisor.dev/gvisor/pkg/tcpip/stack/addressable_endpoint_state.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ type AddressableEndpointState struct {
4141
// AddressableEndpointState.mu
4242
// addressState.mu
4343
mu addressableEndpointStateRWMutex `state:"nosave"`
44+
// TODO(b/361075310): Enable s/r for the below fields.
45+
//
4446
// +checklocks:mu
45-
endpoints map[tcpip.Address]*addressState
47+
endpoints map[tcpip.Address]*addressState `state:"nosave"`
4648
// +checklocks:mu
47-
primary []*addressState
49+
primary []*addressState `state:"nosave"`
4850
}
4951

5052
// AddressableEndpointStateOptions contains options used to configure an

0 commit comments

Comments
 (0)