diff --git a/daemon/main.go b/daemon/main.go index 25d146deef..c8b08d0afa 100644 --- a/daemon/main.go +++ b/daemon/main.go @@ -199,8 +199,8 @@ func acceptOrDeny(packet *netfilter.Packet, con *conman.Connection) *rule.Rule { // UI client if connected and running r, connected = uiClient.Ask(con) if r == nil { - log.Error("Invalid rule received, skipping") - packet.SetVerdict(netfilter.NF_DROP) + log.Error("Invalid rule received, applying default action") + applyDefaultAction(packet) return nil } if connected { diff --git a/daemon/rule/rule.go b/daemon/rule/rule.go index 5dc1d32a61..ccb6c68acc 100644 --- a/daemon/rule/rule.go +++ b/daemon/rule/rule.go @@ -83,6 +83,9 @@ func Deserialize(reply *protocol.Rule) *Rule { } func (r *Rule) Serialize() *protocol.Rule { + if r == nil { + return nil + } return &protocol.Rule{ Name: string(r.Name), Enabled: bool(r.Enabled), diff --git a/daemon/statistics/stats.go b/daemon/statistics/stats.go index 71fec2d03b..335f106443 100644 --- a/daemon/statistics/stats.go +++ b/daemon/statistics/stats.go @@ -134,7 +134,7 @@ func (s *Statistics) onConnection(con *conman.Connection, match *rule.Rule, wasM s.RuleHits++ } - if match.Action == rule.Allow { + if wasMissed == false && match.Action == rule.Allow { s.Accepted++ } else { s.Dropped++ @@ -155,6 +155,9 @@ func (s *Statistics) onConnection(con *conman.Connection, match *rule.Rule, wasM if nEvents == maxEvents { s.Events = s.Events[1:] } + if wasMissed { + return + } s.Events = append(s.Events, NewEvent(con, match)) } diff --git a/daemon/ui/client.go b/daemon/ui/client.go index 7391c60889..dd15ba541d 100644 --- a/daemon/ui/client.go +++ b/daemon/ui/client.go @@ -225,12 +225,13 @@ func (c *Client) Ask(con *conman.Connection) (*rule.Rule, bool) { c.Lock() defer c.Unlock() - ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) + // FIXME: if timeout is fired, the rule is not added to the list in the GUI + ctx, cancel := context.WithTimeout(context.Background(), time.Second*120) defer cancel() reply, err := c.client.AskRule(ctx, con.Serialize()) if err != nil { - log.Warning("Error while asking for rule: %s", err, con) - return clientErrorRule, false + log.Warning("Error while asking for rule: %s - %v", err, con) + return nil, false } return rule.Deserialize(reply), true