Merge pull request #205 from safing/fix/packet-context

Fix tracing context assigned to packets
This commit is contained in:
Daniel 2020-11-30 15:13:23 +01:00 committed by GitHub
commit b29775b6a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -64,11 +64,13 @@ func handlePacket(ctx context.Context, pkt packet.Packet) {
return return
} }
// Add context tracer and set context on packet.
traceCtx, tracer := log.AddTracer(ctx) traceCtx, tracer := log.AddTracer(ctx)
if tracer != nil { if tracer != nil {
pkt.SetCtx(traceCtx) defer tracer.Submit()
tracer.Tracef("filter: handling packet: %s", pkt) tracer.Tracef("filter: handling packet: %s", pkt)
} }
pkt.SetCtx(traceCtx)
// associate packet to link and handle // associate packet to link and handle
conn, ok := network.GetConnection(pkt.GetConnectionID()) conn, ok := network.GetConnection(pkt.GetConnectionID())
@ -327,8 +329,8 @@ func packetHandler(ctx context.Context) error {
case <-ctx.Done(): case <-ctx.Done():
return nil return nil
case pkt := <-interception.Packets: case pkt := <-interception.Packets:
interceptionModule.StartWorker("initial packet handler", func(ctx context.Context) error { interceptionModule.StartWorker("initial packet handler", func(workerCtx context.Context) error {
handlePacket(ctx, pkt) handlePacket(workerCtx, pkt)
return nil return nil
}) })
} }