Rate Limiting

ALOS WALL enforces per-source-IP traffic ceilings entirely inside XDP: bits per second, packets per second, and independent limits per TCP flag and protocol. When a source exceeds any ceiling it is dropped immediately and held in a timed block, with every subsequent packet from that IP rejected at the very top of the pipeline before any further processing occurs.

Overview

Every source IP that sends traffic to the protected address gets its own isolated set of counters, stored as a value in an LRU hash map keyed by the 32-bit source address. The counters track bytes, total packets, and per-flag or per-protocol packet counts across one or more time windows.

On each arriving packet the XDP program looks up the source IP, increments the relevant counters, and compares them against the configured ceilings. If any ceiling is exceeded, the packet is dropped and the source IP is written into a separate block map with an expiry timestamp. While that entry is live, every packet from that IP is dropped at the very first map lookup, with no counter updates, no further checks, no passes to the kernel.

Because all of this runs in XDP before the kernel's network stack is touched, blocked traffic consumes almost no CPU and does not reach any socket or process on the host.

Rate limiting applies only to traffic destined for the protected IP. All other destination addresses are passed through without counter updates or limit checks.

Per-IP Counters

Each entry in the rate-limit map holds a struct of counters and a pair of window timestamps. Most counters reset on a rolling 1-second window: when the current second differs from the timestamp stored in the entry, the counters are zeroed and the timestamp is updated before the new packet is counted. This means every source IP effectively gets a fresh allowance each second without any background timer or periodic sweep.

The SYN burst counter uses a separate 10-second window (synper10). It accumulates SYN packets over ten seconds before resetting, letting you cap sustained SYN rates that might otherwise stay just under a per-second ceiling by bursting and pausing.

The underlying map is an LRU hash, sized to hold millions of distinct source IPs. When the map is full, the least-recently-used entry is evicted to make room for a new source. Under a spoofed-source flood this means attacker-controlled entries cycle out quickly as real sources keep theirs warm.

Window resets happen inline on the packet path. There is no background goroutine or timer. The first packet from a source in a new second pays a tiny extra cost to zero the struct; every subsequent packet in that second is a pure increment and compare.

The Limits

Each ceiling is an independent field in the configuration. Setting a field to 0 disables that particular check. The available limits are:

  • bps: bits per second from this source IP. Counts the full on-wire byte length of each packet multiplied by 8.
  • pps: total packets per second from this source IP, regardless of protocol or flags.
  • syn: TCP SYN packets per second (SYN flag set, ACK flag clear).
  • synper10: TCP SYN packets over a 10-second rolling window. Catches attackers who stay under the per-second SYN cap by spreading their flood.
  • ack: TCP ACK packets per second (ACK flag set, no PSH, no SYN).
  • synack: TCP SYN-ACK packets per second. Useful for blocking reflected or spoofed handshake responses.
  • pshack: TCP PSH+ACK packets per second. This is the flag combination used by most application-layer data segments.
  • rst: TCP RST packets per second.
  • fin: TCP FIN packets per second.
  • urg: TCP URG packets per second.
  • udp: UDP packets per second from this source IP.
  • icmp: ICMP packets per second from this source IP.
  • gre: GRE-encapsulated packets per second.
  • othertcp: TCP packets per second that do not match any of the specific flag buckets above.

Because every ceiling is evaluated independently, you can allow generous ACK rates (normal for a busy TCP server) while keeping the SYN rate very tight, without either limit interfering with the other.

json
{
  "bps":      500000000,
  "pps":      200000,
  "syn":      500,
  "synper10": 3000,
  "ack":      150000,
  "synack":   1000,
  "pshack":   100000,
  "rst":      2000,
  "fin":      2000,
  "urg":      100,
  "udp":      50000,
  "icmp":     500,
  "gre":      1000,
  "othertcp": 5000
}

Global vs Per-Port

Rate limits can be configured at two scopes: global and per-port.

Global ceilings apply to all traffic arriving at the protected IP, across every destination port. They are the outermost layer of defense and catch floods that are spread across many ports or that target ports with no specific rule.

Per-port overrides let you set tighter ceilings on a specific service port. When a packet arrives at a port that has its own rate-limit block configured, those values take precedence over the global values for the limits that are explicitly set. This lets you, for example, apply a very strict SYN rate on port 25 (SMTP, where SYN floods are common and legitimate connection rates are low) while leaving the global SYN limit higher for ports that handle more concurrent clients.

A per-port limit that is set to 0 disables that check for that port, even if the global value is non-zero. Set a field to a positive value to tighten it; leave it at 0 to fall back to the global ceiling. See Configuration for the full schema.

Block Windows

When a source IP trips any rate-limit ceiling, ALOS WALL writes that IP into a dedicated block map alongside an expiry timestamp computed as now + blocktime. On every subsequent packet from that IP, the XDP program checks the block map first. If a live entry exists, the packet is dropped immediately (before any rate-limit counters are even read) and the expiry is refreshed. This is the cheapest possible drop path.

The block clears automatically: once the current timestamp passes the stored expiry, the entry is considered stale and the next packet from that IP is allowed through to the normal rate-limit path, where it can either pass cleanly or start a new block if it still exceeds a ceiling.

Setting blocktime to 0 changes this behavior: the offending packet is dropped, but no entry is written to the block map. The source IP is not held blocked; each packet is evaluated independently against the rate-limit counters. Use this for very brief transient bursts where you want to shed the excess without penalizing the source for subsequent traffic.

A blocked IP that keeps sending traffic will have its expiry refreshed on each arriving packet. An attacker that never stops will remain blocked indefinitely. Set blocktime to a value short enough that legitimate IPs are not locked out after a brief legitimate burst (a few seconds is typical for most services).

Packet Weighting

Large packets carry more data per packet than small ones, so a simple per-packet count would let an attacker send a handful of jumbo frames just under the pps ceiling while delivering a large byte volume. To close this gap, the ACK and PSH-ACK accounting paths apply size-based weights before incrementing the counter:

  • Packets larger than 160 bytes count as 2.
  • Packets larger than 500 bytes count as 3.
  • Packets larger than 800 bytes count as 4.

A source sending 10,000 packets per second of 1,400-byte ACK segments will register 40,000 weighted units against the ack ceiling, not 10,000. Set your ACK limit accordingly when sizing limits for high-throughput legitimate traffic.

Tuning

Start with generous limits and watch the live dashboard. Each ceiling shows up as passed or blocked traffic in real time, so you can see which limits your real traffic is hitting and tighten them gradually rather than all at once.

Watch the live dashboard during normal load to find your traffic's natural peaks, then set each ceiling comfortably above them and switch to full protection. If a limit ever turns away legitimate users, just raise it. Changes apply instantly.

Per-IP rate limits do not stop spoofed-source floods. When every packet carries a different forged source address, each one appears as a unique IP with its own fresh counter, and the ceilings are never tripped. For that class of attack, use SYN cookies to validate TCP handshakes and byte-match filters to identify and drop the flood signatures before they reach the rate-limit path.

From here, explore the related subsystems: