@@ -194,15 +194,15 @@ type supervisor struct {
194194 processors []processor
195195 seed uint32
196196 wg sync.WaitGroup
197- fd * core.Volatile [int ] // tun fd for diagnostics
197+ sid * core.Volatile [int ] // tun fd for diagnostics
198198 ready []bool
199199}
200200
201201// newSupervisor creates a new supervisor for the processors of endpoint e.
202202func newSupervisor (e stack.InjectableLinkEndpoint , fd int ) * supervisor {
203203 m := & supervisor {
204204 seed : rand .Uint32 (),
205- fd : core .NewVolatile (fd ),
205+ sid : core .NewVolatile (fd ),
206206 ready : make ([]bool , maxForwarders ),
207207 processors : make ([]processor , maxForwarders ),
208208 wg : sync.WaitGroup {},
@@ -220,21 +220,21 @@ func newSupervisor(e stack.InjectableLinkEndpoint, fd int) *supervisor {
220220 return m
221221}
222222
223- // tun returns the tun fd (use for diagnostics only) .
224- func (m * supervisor ) tun () int {
225- return m .fd .Load ()
223+ // tunid returns a unique identifier (usually current tun fd); used for diagnostics only.
224+ func (m * supervisor ) tunid () int {
225+ return m .sid .Load ()
226226}
227227
228228// note notes the new tun fd (used for diagnostics only).
229229func (m * supervisor ) note (sid int ) {
230- m .fd .Store (sid )
230+ m .sid .Store (sid )
231231}
232232
233233// start starts the processor goroutines if the processor manager is configured
234234// with more than one processor.
235235func (m * supervisor ) start () {
236236 if settings .Debug {
237- log .D ("ns: tun(%d): forwarder: starting %d procs %d" , m .tun (), len (m .processors ), m .seed )
237+ log .D ("ns: tun(%d): forwarder: starting %d procs %d" , m .tunid (), len (m .processors ), m .seed )
238238 }
239239 if m .canDeliverInline () {
240240 return
@@ -275,12 +275,12 @@ func (m *supervisor) id(t *fiveTuple) uint32 {
275275// queuePacket queues a packet to be delivered to the appropriate processor.
276276func (m * supervisor ) queuePacket (pkt * stack.PacketBuffer , hasEthHeader bool ) {
277277 sz := uint32 (len (m .processors ))
278- fd := m .tun ()
278+ sid := m .tunid ()
279279 var pIdx uint32
280280 tup , nonConnectionPkt := tcpipConnectionID (pkt )
281281 if ! hasEthHeader {
282282 if nonConnectionPkt {
283- log .D ("ns: tun(%d): forwarder: drop non-connection pkt (sz: %d)" , fd , pkt .Size ())
283+ log .D ("ns: tun(%d): forwarder: drop non-connection pkt (sz: %d)" , sid , pkt .Size ())
284284 // If there's no eth header this should be a standard tcpip packet. If
285285 // it isn't the packet is invalid so drop it.
286286 return
@@ -297,13 +297,13 @@ func (m *supervisor) queuePacket(pkt *stack.PacketBuffer, hasEthHeader bool) {
297297 // despite uint32, pIdx goes negative? github.com/celzero/firestack/issues/59
298298 // go.dev/ref/spec#Integer_overflow?
299299 if pIdx > sz {
300- log .W ("ns: tun(%d): forwarder: invalid processor index %d, %s" , fd , pIdx , tup )
300+ log .W ("ns: tun(%d): forwarder: invalid processor index %d, %s" , sid , pIdx , tup )
301301 pIdx = 0
302302 }
303303 p := & m .processors [pIdx ]
304304
305305 if settings .Debug {
306- log .VV ("ns: tun(%d): forwarder: q on proc %d, %s" , fd , pIdx , tup )
306+ log .VV ("ns: tun(%d): forwarder: q on proc %d, %s" , sid , pIdx , tup )
307307 }
308308
309309 p .mu .Lock ()
@@ -315,22 +315,17 @@ func (m *supervisor) queuePacket(pkt *stack.PacketBuffer, hasEthHeader bool) {
315315
316316// stop stops all processor goroutines.
317317func (m * supervisor ) stop () {
318- fd := m .tun ()
318+ sid := m .tunid ()
319319 start := time .Now ()
320- if settings .Debug {
321- log .D ("ns: tun(%d): forwarder: stopping %d procs" , fd , len (m .processors ))
322- }
320+ log .D ("ns: tun(%d): forwarder: stopping %d procs" , sid , len (m .processors ))
323321 if ! m .canDeliverInline () {
324322 for i := range m .processors {
325323 p := & m .processors [i ]
326324 p .closeWaker .Assert ()
327325 }
328326 m .wg .Wait ()
329327 } // else: no goroutines to stop or wait for.
330- if settings .Debug {
331- elapsed := time .Since (start ).Milliseconds () / 1000
332- log .D ("ns: tun(%d): forwarder: stopped %d procs in %ds" , fd , len (m .processors ), elapsed )
333- }
328+ log .D ("ns: tun(%d): forwarder: stopped %d procs in %s" , sid , len (m .processors ), core .FmtTimeAsPeriod (start ))
334329}
335330
336331// wakeReady wakes up all processors that have a packet queued. If there is only
0 commit comments