From d93c3f60ce3f6e122661e0f95d7d95e16dabcfd9 Mon Sep 17 00:00:00 2001 From: Patrick Pacher Date: Tue, 12 Jul 2022 11:27:46 +0200 Subject: [PATCH] Add additional field to internal SQL model --- netquery/database.go | 7 +++++++ netquery/manager.go | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/netquery/database.go b/netquery/database.go index 5197868d..57aa6f6c 100644 --- a/netquery/database.go +++ b/netquery/database.go @@ -92,6 +92,13 @@ type ( Allowed *bool `sqlite:"allowed"` ProfileRevision int `sqlite:"profile_revision"` ExitNode *string `sqlite:"exit_node"` + + // FIXME(ppacher): support "NOT" in search query to get rid of the following helper fields + SPNUsed bool `sqlite:"spn_used"` // could use "exit_node IS NOT NULL" or "exit IS NULL" + Active bool `sqlite:"active"` // could use "ended IS NOT NULL" or "ended IS NULL" + + // FIXME(ppacher): we need to profile here for "suggestion" support. It would be better to keep a table of profiles in sqlite and use joins here + ProfileName string `sqlite:"profile_name"` } ) diff --git a/netquery/manager.go b/netquery/manager.go index 2620e510..d5d4992f 100644 --- a/netquery/manager.go +++ b/netquery/manager.go @@ -177,6 +177,7 @@ func convertConnection(conn *network.Connection) (*Conn, error) { ProfileID: conn.ProcessContext.Source + "/" + conn.ProcessContext.Profile, Path: conn.ProcessContext.BinaryPath, ProfileRevision: int(conn.ProfileRevisionCounter), + ProfileName: conn.ProcessContext.ProfileName, } switch conn.Type { @@ -200,6 +201,9 @@ func convertConnection(conn *network.Connection) (*Conn, error) { if conn.Ended > 0 { ended := time.Unix(conn.Ended, 0) c.Ended = &ended + c.Active = false + } else { + c.Active = true } extraData := map[string]interface{}{ @@ -210,6 +214,7 @@ func convertConnection(conn *network.Connection) (*Conn, error) { extraData["tunnel"] = conn.TunnelContext exitNode := conn.TunnelContext.GetExitNodeID() c.ExitNode = &exitNode + c.SPNUsed = true } if conn.DNSContext != nil {