Skip to content

Commit 2768c5b

Browse files
committed
netstack: m debug logs
1 parent 94dc310 commit 2768c5b

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

intra/netstack/dispatchers.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func (d *readVDispatcher) stop() {
187187
d.stopFd.stop()
188188
// TODO: should close tun-fd before stopFd?
189189
err := syscall.Close(d.fd)
190-
log.I("ns: stop: fds closed event(%d) tun(%d); err? %v", d.efd, d.fd, err)
190+
log.I("ns: dispatch: stop: fds closed event(%d) tun(%d); err? %v", d.efd, d.fd, err)
191191
}
192192

193193
const abort = false // abort indicates that the dispatcher should stop.
@@ -196,7 +196,7 @@ const cont = true // cont indicates that the dispatcher should continue delive
196196
// dispatch reads one packet from the file descriptor and dispatches it.
197197
func (d *readVDispatcher) dispatch() (bool, tcpip.Error) {
198198
done := d.closed.Load()
199-
log.V("ns: dispatch: done? %t", done)
199+
log.V("ns: tun(%d): dispatch: done? %t", d.fd, done)
200200
if done {
201201
return abort, new(tcpip.ErrAborted)
202202
}
@@ -208,7 +208,7 @@ func (d *readVDispatcher) dispatch() (bool, tcpip.Error) {
208208

209209
n, err := rawfile.BlockingReadvUntilStopped(d.efd, d.fd, iov)
210210

211-
log.V("ns: dispatch: got(%d bytes), err(%v)", n, err)
211+
log.V("ns: tun(%d): dispatch: got(%d bytes), err(%v)", d.fd, n, err)
212212
if n <= 0 || err != nil {
213213
if err == nil {
214214
err = new(tcpip.ErrNoSuchFile)
@@ -235,7 +235,7 @@ func (d *readVDispatcher) dispatch() (bool, tcpip.Error) {
235235
// IP version information is at the first octet, so pulling up 1 byte.
236236
h, ok := pkt.Data().PullUp(1)
237237
if !ok {
238-
log.W("ns: dispatch: no data!")
238+
log.W("ns: tun(%d): dispatch: no data!", d.fd)
239239
pkt.DecRef()
240240
return cont, nil
241241
}
@@ -245,13 +245,13 @@ func (d *readVDispatcher) dispatch() (bool, tcpip.Error) {
245245
case header.IPv6Version:
246246
p = header.IPv6ProtocolNumber
247247
default:
248-
log.W("ns: dispatch: unknown proto!")
248+
log.W("ns: tun(%d): dispatch: unknown proto!", d.fd)
249249
pkt.DecRef()
250250
return cont, nil
251251
}
252252
}
253253

254-
log.V("ns: dispatch (from-tun) proto(%d) for pkt-id(%d)", p, pkt.Hash)
254+
log.V("ns: tun(%d): dispatch: (from-tun) proto(%d) for pkt-id(%d)", d.fd, p, pkt.Hash)
255255

256256
go func() {
257257
d.e.InjectInbound(p, pkt)

intra/netstack/fdbased.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ func (e *endpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error)
392392
if len(batch)+numIovecs > rawfile.MaxIovs {
393393
// writes in to fd, up to len(batch) not cap(batch)
394394
if err := rawfile.NonBlockingWriteIovec(fd, batch); err != nil {
395-
log.W("ns: WritePackets (to tun): err(%v), sent(%d)/total(%d)", err, written, total)
395+
log.W("ns: tun(%d): WritePackets (to tun): err(%v), sent(%d)/total(%d)", fd, err, written, total)
396396
return written, err
397397
}
398398
// mark processed packets as written
@@ -409,13 +409,13 @@ func (e *endpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error)
409409
}
410410
if len(batch) > 0 {
411411
if err := rawfile.NonBlockingWriteIovec(fd, batch); err != nil {
412-
log.W("ns: WritePackets (to tun): err(%v), sent(%d)/total(%d)", err, packets, total)
412+
log.W("ns: tun(%d): WritePackets (to tun): err(%v), sent(%d)/total(%d)", fd, err, packets, total)
413413
return written, err
414414
}
415415
written += packets
416416
}
417417

418-
log.V("ns: WritePackets (to tun): written(%d)/total(%d)", written, total)
418+
log.V("ns: tun(%d): WritePackets (to tun): written(%d)/total(%d)", fd, written, total)
419419
return written, nil
420420
}
421421

@@ -461,7 +461,8 @@ func (e *endpoint) InjectInbound(protocol tcpip.NetworkProtocolNumber, pkt *stac
461461
// Unused: InjectOutobund implements stack.InjectableEndpoint.InjectOutbound.
462462
// InjectOutbound egresses a tun-inbound packet.
463463
func (e *endpoint) InjectOutbound(dest tcpip.Address, packet *buffer.View) tcpip.Error {
464-
log.V("ns: inject-outbound (to tun) to dst(%v)", dest)
464+
fd := e.fd()
465+
log.V("ns: tun(%d): inject-outbound (to tun) to dst(%v)", fd, dest)
465466
// TODO: e.logPacketIfNeeded(sniffer.DirectionSend, packet)
466-
return rawfile.NonBlockingWrite(e.fd(), packet.AsSlice())
467+
return rawfile.NonBlockingWrite(fd, packet.AsSlice())
467468
}

0 commit comments

Comments
 (0)