Skip to content

Commit a16f957

Browse files
committed
netstack: m debug logs
1 parent a59656a commit a16f957

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
@@ -395,7 +395,7 @@ func (e *endpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error)
395395
if len(batch)+numIovecs > rawfile.MaxIovs {
396396
// writes in to fd, up to len(batch) not cap(batch)
397397
if err := rawfile.NonBlockingWriteIovec(fd, batch); err != nil {
398-
log.W("ns: WritePackets (to tun): err(%v), sent(%d)/total(%d)", err, written, total)
398+
log.W("ns: tun(%d): WritePackets (to tun): err(%v), sent(%d)/total(%d)", fd, err, written, total)
399399
return written, err
400400
}
401401
// mark processed packets as written
@@ -412,13 +412,13 @@ func (e *endpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error)
412412
}
413413
if len(batch) > 0 {
414414
if err := rawfile.NonBlockingWriteIovec(fd, batch); err != nil {
415-
log.W("ns: WritePackets (to tun): err(%v), sent(%d)/total(%d)", err, packets, total)
415+
log.W("ns: tun(%d): WritePackets (to tun): err(%v), sent(%d)/total(%d)", fd, err, packets, total)
416416
return written, err
417417
}
418418
written += packets
419419
}
420420

421-
log.V("ns: WritePackets (to tun): written(%d)/total(%d)", written, total)
421+
log.V("ns: tun(%d): WritePackets (to tun): written(%d)/total(%d)", fd, written, total)
422422
return written, nil
423423
}
424424

@@ -464,7 +464,8 @@ func (e *endpoint) InjectInbound(protocol tcpip.NetworkProtocolNumber, pkt *stac
464464
// Unused: InjectOutobund implements stack.InjectableEndpoint.InjectOutbound.
465465
// InjectOutbound egresses a tun-inbound packet.
466466
func (e *endpoint) InjectOutbound(dest tcpip.Address, packet *buffer.View) tcpip.Error {
467-
log.V("ns: inject-outbound (to tun) to dst(%v)", dest)
467+
fd := e.fd()
468+
log.V("ns: tun(%d): inject-outbound (to tun) to dst(%v)", fd, dest)
468469
// TODO: e.logPacketIfNeeded(sniffer.DirectionSend, packet)
469-
return rawfile.NonBlockingWrite(e.fd(), packet.AsSlice())
470+
return rawfile.NonBlockingWrite(fd, packet.AsSlice())
470471
}

0 commit comments

Comments
 (0)