FindFirstMatch will try match the connection against the existing rule set.
(con *conman.Connection)
| 495 | |
| 496 | // FindFirstMatch will try match the connection against the existing rule set. |
| 497 | func (l *Loader) FindFirstMatch(con *conman.Connection) (match *Rule) { |
| 498 | l.RLock() |
| 499 | defer l.RUnlock() |
| 500 | |
| 501 | for _, idx := range l.activeRules { |
| 502 | rule, _ := l.rules[idx] |
| 503 | if rule.Match(con, l.checkSums) { |
| 504 | // We have a match. |
| 505 | // Save the rule in order to don't ask the user to take action, |
| 506 | // and keep iterating until a Deny or a Priority rule appears. |
| 507 | match = rule |
| 508 | if rule.Action == Reject || rule.Action == Deny || rule.Precedence == true { |
| 509 | return rule |
| 510 | } |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | return match |
| 515 | } |