# IP rule keys

| Key | Type | Default | Takes effect |
|---|---|---|---|
| [`action`](#action) | enum | **required** | live |
| [`match`](#match) | ipmatch | **required** | live |
| [`note`](#note) | string | empty | live |

### `action`

What a match does.

- **Where:** `…/ip_rules/ip_rules_subitem/action`, in each rule of the global, listener and endpoint `ip_rules` lists
- **Type:** `enum`: `allow` or `deny`
- **Default:** none: the key is required
- **Applies:** always
- **Takes effect:** live, when saved or loaded (no restart)
- **Flags:** required: a missing value is ERROR REQUIRED on its object
- **UI:** Security › Action: Whether a matching client is allowed or denied.

### `match`

Addresses the rule covers.

- **Where:** `…/ip_rules/ip_rules_subitem/match`, in each rule of the global, listener and endpoint `ip_rules` lists
- **Type:** `ipmatch`
- **Default:** none: the key is required
- **Applies:** always
- **Takes effect:** live, when saved or loaded (no restart)
- **Flags:** required: a missing value is ERROR REQUIRED on its object
- **UI:** Security › Match: Addresses the rule covers: *, an IP address, a CIDR block, a range a-b, or a pattern such as 192.168.*.

### `note`

Free text, shown in the UI and in deny log lines.

- **Where:** `…/ip_rules/ip_rules_subitem/note`, in each rule of the global, listener and endpoint `ip_rules` lists
- **Type:** `string`, at most 200 characters
- **Default:** empty
- **Applies:** always
- **Takes effect:** live, when saved or loaded (no restart)
- **Flags:** none
- **UI:** Security › Note: Free text on a single line, shown in the UI and in deny log lines.

### Notes on the IP rule keys

The list semantics are under [IP rule lists](#ip-rule-lists).

### IP rule lists

- **Model:** a list is evaluated exactly like CrushFTP 11's `check_ip`. It agrees with CrushFTP 11 except for a few deliberate deviations (notation, IPv4-mapped clients, host names, bad entries, temporary bans).
- **Order:** first match wins.
- **No match: deny, unless the list is empty.**
  - An empty list allows everyone.
  - A list of only `deny` rules therefore denies everyone, as in CrushMFT. It gets WARN RULES_DENY_ONLY, at every level; the warning never blocks a save.
  - A block list is written as its `deny` rules followed by `allow *`.
  - The UI shows the resulting "everything else" row: allow for an empty list, otherwise deny.
- **Address families:**
  - An `allow` rule whose range is the whole IPv4 space also matches every IPv6 client, as CrushMFT's allow row `0.0.0.0-255.255.255.255` does. This holds for every notation that parses to exactly that range (`0.0.0.0-255.255.255.255`, `0.0.0.0/0`, `*.*.*.*` and others): CrushMFT compares the row text, CrushBalance compares the parsed range.
  - No other IPv4 rule matches an IPv6 client, and a `deny` rule never widens.
  - The widening is a property of IP rule lists only. Trust lists (`admin_allowed_ips`, `trusted_proxies`) never widen.
  - An IPv6 rule never matches an IPv4 client.
  - `*` matches both families.
  - IPv4-mapped clients (`::ffff:a.b.c.d`) are matched as IPv4.
- **Levels:**
  - the global list, then the listener list (both must allow), checked once per new client connection;
  - endpoint lists remove endpoints from the candidates before balancing.
- **Rule changes:**
  - global and listener rules apply to new connections;
  - endpoint rules are evaluated on every route call, so they apply from the next route call, and so from the next request of an open `http`/`https` session.
- **One invalid entry:** the whole list is ERROR RULE_BAD and fails closed. At startup it denies everyone; on reload the previous list stays in force. A save with an invalid entry is rejected.

### Address grammars and client identity

**`addrlist`** (`admin_allowed_ips`, `trusted_proxies`):
- IP literals and CIDR blocks only. No wildcards and no host names, because a trust list must never depend on DNS or patterns.
- The UI converts a trailing wildcard such as `192.168.*` into CIDR.
- An invalid item is rejected on save. On a disk load an invalid item is dropped with WARN ADDR_ITEM_DROPPED and the rest is used, so the list trusts **less**.
- If `admin_allowed_ips` was non-empty and no valid item remains, that is ERROR BAD_VALUE on the key and only loopback is allowed (fails closed); it never falls back to `""` = any source.
- A `trusted_proxies` list emptied this way on a `proxy_protocol_in=true` listener gives ERROR PROXY_IN_NO_TRUST.
- **Trust lists are not IP rule lists.** The IPv4-to-IPv6 widening of IP rule lists never applies to them: an IPv4 item, `0.0.0.0/0` included, never matches an IPv6 source.

**`ipmatch`** (IP rule `match`):

```
match   := "*" | ip | cidr | range | pattern
ip      := IPv4 dotted quad | IPv6 literal (any compression, no zone id)
cidr    := ip "/" prefix                      host bits set -> WARN, normalised on save
range   := (ip | pattern) "-" (ip | pattern)  same family, low <= high
pattern := IPv4 with "*" octets, optionally shortened: 192.168.*  10.*.*.5   (CrushMFT notation)
```

- **CrushMFT notation**, as in CrushMFT's `is_ip_allowed`:
  - A `*`, or a missing trailing octet, counts as 0 at the low end and 255 at the high end. The result is a numeric range, not a mask.
  - `192.168.*` is 192.168.0.0–192.168.255.255.
  - `10.*.*.5` is the range 10.0.0.5–10.255.255.5.
  - In an explicit range, `*` is 0 on the low side and 255 on the high side.
  - A shortened pattern must end in `*`: `10.1` and `192.*.1` are invalid.
  - Where CrushFTP 11 reads a pattern differently, CrushBalance keeps these rules: a two-field pattern such as `192.*` (CrushMFT: 192.0.192.0–192.255.192.255) and `*.*.*.*` (CrushMFT: a host name).
- **IPv4-mapped clients** (`::ffff:a.b.c.d`) are matched as IPv4.
- **Not supported:** host names, globs and regular expressions.
- **Saved form:** the editor stores its canonical form (IPv6 in RFC 5952, CIDR normalised).

**Client identity** for caps, stickiness and GeoIP: the IPv4 address (/32) or the IPv6 /64. IP rules always see the full address. The client is the address from inbound PROXY when `proxy_protocol_in=true`.
