From 6f9b0a82492172dd51ec454d0cfecc4869f0fda5 Mon Sep 17 00:00:00 2001 From: Vladimir Stoilov <vladimir@safing.io> Date: Wed, 15 May 2024 18:04:49 +0300 Subject: [PATCH] [service] Minor windows kext improvments --- .../interception/interception_windows.go | 39 +++++++------------ .../interception/windowskext2/handler.go | 17 ++++---- 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/service/firewall/interception/interception_windows.go b/service/firewall/interception/interception_windows.go index 11eadbf3..ab753518 100644 --- a/service/firewall/interception/interception_windows.go +++ b/service/firewall/interception/interception_windows.go @@ -66,19 +66,16 @@ func startInterception(packets chan packet.Packet) error { // Start bandwidth stats monitor. module.StartServiceWorker("kext bandwidth request worker", 0, func(ctx context.Context) error { timer := time.NewTicker(1 * time.Second) + defer timer.Stop() for { select { case <-timer.C: - { - err := kext2.SendBandwidthStatsRequest() - if err != nil { - return err - } + err := kext2.SendBandwidthStatsRequest() + if err != nil { + return err } case <-ctx.Done(): - { - return nil - } + return nil } } @@ -87,19 +84,16 @@ func startInterception(packets chan packet.Packet) error { // Start kext logging. The worker will periodically send request to the kext to send logs. module.StartServiceWorker("kext log request worker", 0, func(ctx context.Context) error { timer := time.NewTicker(1 * time.Second) + defer timer.Stop() for { select { case <-timer.C: - { - err := kext2.SendLogRequest() - if err != nil { - return err - } + err := kext2.SendLogRequest() + if err != nil { + return err } case <-ctx.Done(): - { - return nil - } + return nil } } @@ -107,19 +101,16 @@ func startInterception(packets chan packet.Packet) error { module.StartServiceWorker("kext clean ended connection worker", 0, func(ctx context.Context) error { timer := time.NewTicker(30 * time.Second) + defer timer.Stop() for { select { case <-timer.C: - { - err := kext2.SendCleanEndedConnection() - if err != nil { - return err - } + err := kext2.SendCleanEndedConnection() + if err != nil { + return err } case <-ctx.Done(): - { - return nil - } + return nil } } diff --git a/service/firewall/interception/windowskext2/handler.go b/service/firewall/interception/windowskext2/handler.go index 55d4a6de..b6339b50 100644 --- a/service/firewall/interception/windowskext2/handler.go +++ b/service/firewall/interception/windowskext2/handler.go @@ -40,16 +40,15 @@ func Handler(ctx context.Context, packets chan packet.Packet, bandwidthUpdate ch switch { case packetInfo.ConnectionV4 != nil: { - log.Tracef("packet: %+v", packetInfo.ConnectionV4) + // log.Tracef("packet: %+v", packetInfo.ConnectionV4) conn := packetInfo.ConnectionV4 // New Packet - new := &Packet{ + newPacket := &Packet{ verdictRequest: conn.Id, payload: conn.Payload, verdictSet: abool.NewBool(false), } - new.Base.Payload() - info := new.Info() + info := newPacket.Info() info.Inbound = conn.Direction > 0 info.InTunnel = false info.Protocol = packet.IPProtocol(conn.Protocol) @@ -88,19 +87,19 @@ func Handler(ctx context.Context, packets chan packet.Packet, bandwidthUpdate ch info.DstPort = conn.RemotePort } - packets <- new + packets <- newPacket } case packetInfo.ConnectionV6 != nil: { - log.Tracef("packet: %+v", packetInfo.ConnectionV6) + // log.Tracef("packet: %+v", packetInfo.ConnectionV6) conn := packetInfo.ConnectionV6 // New Packet - new := &Packet{ + newPacket := &Packet{ verdictRequest: conn.Id, payload: conn.Payload, verdictSet: abool.NewBool(false), } - info := new.Info() + info := newPacket.Info() info.Inbound = conn.Direction > 0 info.InTunnel = false info.Protocol = packet.IPProtocol(conn.Protocol) @@ -139,7 +138,7 @@ func Handler(ctx context.Context, packets chan packet.Packet, bandwidthUpdate ch info.DstPort = conn.RemotePort } - packets <- new + packets <- newPacket } case packetInfo.LogLine != nil: {