Skip to content

Commit

Permalink
increase default timeout to ask for a rule
Browse files Browse the repository at this point in the history
Explained here: #28 (comment)
  • Loading branch information
gustavo-iniguez-goya committed Jun 3, 2020
1 parent 36a11b4 commit 78c0da8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions daemon/rule/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
5 changes: 4 additions & 1 deletion daemon/statistics/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand All @@ -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))
}

Expand Down
7 changes: 4 additions & 3 deletions daemon/ui/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 78c0da8

Please sign in to comment.