()
| 55 | } |
| 56 | |
| 57 | func (r *Rule) Validate() error { |
| 58 | if r.ipNet == nil { |
| 59 | return fmt.Errorf("no ipnet set on the rule") |
| 60 | } |
| 61 | |
| 62 | if len(r.ports) > 0 { |
| 63 | sort.Ints(r.ports) |
| 64 | for _, port := range r.ports { |
| 65 | if port < 1 || port > 65535 { |
| 66 | return fmt.Errorf("invalid port %d, needs to be between 1 and 65535", port) |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | return nil |
| 72 | } |
| 73 | |
| 74 | func (h *Policy) Allowed(ip net.IP, port int) (bool, *Rule) { |
| 75 | if len(h.rules) == 0 { |