BGP FlowSpec DDoS Filtering: Rules, Deployment, Limits
BGP FlowSpec DDoS filtering uses BGP itself to distribute packet-filter rules (match on destination, protocol, port, packet length, TCP flags) to routers, which then drop or rate-limit only the matching attack traffic. Unlike a blackhole, which discards everything sent to the victim IP, FlowSpec can keep legitimate traffic flowing to the same address while the attack is filtered.
This guide covers how FlowSpec rules are built and distributed, how it compares to RTBH, a working ExaBGP and FRR example, and the mistakes that most often cause FlowSpec to fail or to hurt production traffic.
How BGP FlowSpec works
FlowSpec is defined in RFC 8955 (IPv4) and RFC 8956 (IPv6). It adds a new address family (AFI 1 / SAFI 133 for IPv4 unicast flow rules) to a normal BGP session. Instead of announcing a prefix, you announce a flow specification: a set of match conditions plus an action carried in extended communities.
Typical match components:
| Component | Example |
|---|---|
| Destination prefix | 203.0.113.10/32 |
| Source prefix | 198.51.100.0/24 |
| IP protocol | UDP (17) |
| Source / destination port | source port 123 |
| Packet length | 400–500 bytes |
| TCP flags | SYN only |
| ICMP type/code | echo request |
| Fragment bits | is-fragment |
Typical actions:
- traffic-rate: rate-limit matching traffic. The rate is in bytes per second, and a rate of 0 means discard.
- redirect: send matching traffic to a VRF or next hop, for example toward a scrubbing path.
- traffic-marking: rewrite DSCP so downstream QoS can deprioritize it.
- traffic-action sample: sample matching packets for analysis.
Every router that accepts the rule and supports it in hardware installs it as a filter. Because BGP propagates the rule, one announcement can protect many edge routers at once.
FlowSpec vs. blackhole (RTBH)
Remote-triggered blackholing is simple and widely supported, but it is blunt. When you blackhole 203.0.113.10/32, the attack stops reaching your network, and so does every legitimate customer of that IP. The attacker has effectively achieved the goal.
| RTBH | FlowSpec | |
|---|---|---|
| Granularity | Destination IP only | L3/L4 fields, packet size, flags |
| Legitimate traffic | Dropped too | Preserved if the attack has a signature |
| Upstream support | Very common | Less common, often by arrangement |
| Hardware needs | Minimal | Filter/TCAM resources |
| Risk of misconfiguration | Self-inflicted outage of one IP | Can drop wide traffic classes |
FlowSpec shines against attacks with a clear signature: NTP, DNS, memcached, or CLDAP reflection, SYN floods to a single port, or fragmented UDP. It helps less against well-formed HTTP floods or attacks that mimic real traffic. In those cases you need L7 filtering or scrubbing. FlowSpec and RTBH are complementary: keep RTBH as the last-resort fallback when an attack saturates your uplink and no filter is possible.
For background on the blackhole side, see our earlier article on when a /32 blackhole makes sense.
Where the rule must be enforced
This is the most important design point. A filter on your own edge router only protects what is behind that router. If the attack fills your transit link, packets are already dropped upstream before your rule is evaluated. To be effective against volumetric attacks, FlowSpec rules need to be installed at your upstream or at a scrubbing network, not just locally.
That means FlowSpec is usually a relationship, not just a feature:
- Your upstream (or DDoS protection provider) agrees to accept FlowSpec from your ASN.
- They restrict you to rules whose destination is inside your own prefixes.
- You, or your detection system, announce rules during an attack and withdraw them afterward.
Many providers do not accept customer FlowSpec at all. Confirm in advance what your upstream supports, including limits on the number of rules. Where it is not available, a protected path such as a DDoS protection and firewall service in front of your prefixes does the filtering before traffic reaches your link.
Example: announcing rules with ExaBGP
ExaBGP is a common way to generate FlowSpec routes from scripts. A minimal session using documentation addresses and ASNs:
neighbor 192.0.2.1 {
router-id 192.0.2.2;
local-address 192.0.2.2;
local-as 64496;
peer-as 64500;
family {
ipv4 flow;
}
api {
processes [ announce ];
}
}
process announce {
run /usr/bin/python3 /etc/exabgp/flow.py;
encoder text;
}
Your script writes commands to stdout. To drop NTP reflection traffic aimed at one host:
announce flow route {
match {
destination 203.0.113.10/32;
protocol udp;
source-port =123;
packet-length >=400&<=500;
}
then {
discard;
}
}
To rate-limit instead of dropping (rate in bytes per second):
announce flow route {
match {
destination 203.0.113.10/32;
protocol udp;
source-port =53;
}
then {
rate-limit 125000;
}
}
Withdraw with the same match using withdraw flow route { ... }. Always automate the withdrawal or set an expiry in your tooling; stale rules are a frequent source of "why is that port dead" tickets.
Example: receiving FlowSpec on Linux with FRR
FRRouting has FlowSpec support in bgpd and can install received rules on a Linux host (via ipset and iptables). Support is more limited than on carrier-grade routers, so test your specific rule types.
router bgp 64496
neighbor 192.0.2.1 remote-as 64500
!
address-family ipv4 flowspec
neighbor 192.0.2.1 activate
local-install eth0
exit-address-family
Check the result with:
vtysh -c "show bgp ipv4 flowspec"
iptables -S | grep -i match-set
This is useful for protecting a single server or a VDS, but remember that a host-level filter does nothing for link saturation. If you want to run your own BGP speaker, a BGP-enabled VDS lets you announce your own ASN and prefixes and test routing policy before moving it to production routers.
Validation and safety guardrails
RFC 8955 defines a validation procedure: a FlowSpec rule with a destination prefix is only accepted if it comes from the same peer that originated the best unicast route for that destination, and no more-specific unicast route exists from a different AS. This prevents a random peer from filtering someone else's traffic.
Practical guardrails to apply on any session that carries FlowSpec:
- Limit scope by destination. Accept only rules whose destination falls inside your registered prefixes (for example 203.0.113.0/24). Reject rules with no destination prefix.
- Cap the rule count. Configure a maximum-prefix limit for the flowspec family so a bug or runaway script cannot exhaust router filter memory.
- Restrict actions. Many operators permit only discard and rate-limit and disallow redirect from customers.
- Keep the session separate from your production unicast session if your platform allows it, so a flowspec issue does not reset routing.
- Log every announce and withdraw with a timestamp and the attack ID that triggered it.
Common mistakes and fixes
Rate-limit values are bytes, not bits. A value you think is 1 Mbps may be 8 times too low or high. Convert carefully: 1 Mbps is 125000 bytes per second.
Rule accepted but nothing happens. Check that the platform actually installed it in hardware. Some routers accept the NLRI but cannot match certain fields (for example packet length or fragments) and silently skip them. Verify with counters per rule.
Rule is rejected as invalid. Usually a validation failure: the rule came from a peer that did not originate the best route to the destination, or a more-specific unicast route exists. Fix route origin consistency, or on iBGP sessions disable validation deliberately and document it.
Blocking legitimate traffic. A rule such as "drop UDP source port 53" will also drop real DNS responses to your resolvers. Narrow the match with destination, packet length, and fragment fields, and prefer rate-limit first when you are unsure.
Source-port-only rules against spoofed floods. Reflection attacks use real reflector IPs, so a source-port match is effective, but pure random-source floods give you nothing to match on besides destination and protocol.
Forgetting IPv6. RFC 8956 rules use a separate family (ipv6 flow). If you protect a dual-stack service, create rules for both.
Never withdrawing. Attach a timer to every rule and review active rules after each incident.
Detection feeds FlowSpec
FlowSpec is only as good as the signature behind it. Flow telemetry (NetFlow, sFlow, IPFIX) shows top source ports, protocols, and packet sizes toward a target, which is exactly the data you need to write a rule. A practical pipeline looks like this:
- Flow collector detects a traffic spike toward 203.0.113.10.
- Analysis extracts the dominant signature (UDP, source port 123, 468-byte packets).
- A script announces the matching FlowSpec rule to the upstream.
- Counters confirm the drop; the rule is withdrawn after the attack ends.
NixMon provides flow-based network monitoring and DDoS detection that can supply this kind of visibility, so you can build rules from real data instead of guesses.
Checklist before you rely on FlowSpec
- Confirm your upstream accepts FlowSpec from your ASN, and with which actions and limits.
- Test rules on a single non-critical /32 first.
- Keep an RTBH community available as a last-resort fallback.
- Automate withdrawal and alert on long-lived rules.
- Verify per-rule counters during every real or simulated event.
FlowSpec does not replace capacity or scrubbing, but for signature-based attacks it gives you a precise tool that keeps your service reachable.
Frequently asked questions
What is BGP FlowSpec?
BGP FlowSpec (RFC 8955 and RFC 8956) is a BGP extension that distributes traffic-filtering rules. A rule matches fields such as destination, protocol, port, and packet length and applies an action like discard or rate-limit on routers that receive it.
Is FlowSpec better than RTBH blackholing?
For attacks with a clear signature, yes, because it drops only matching traffic and keeps the target reachable. RTBH is still useful as a last resort when an attack is saturating your link and no precise filter is possible.
Can I use FlowSpec if my upstream does not support it?
A local FlowSpec rule only protects what sits behind that router and cannot relieve a saturated uplink. Without upstream support, you need filtering upstream of your link, such as a DDoS-protected path or scrubbing service.
Why is my FlowSpec rule accepted but not filtering traffic?
The router may not support the matched fields in hardware, or filter resources may be exhausted. Check per-rule counters and the platform's FlowSpec documentation, and test the rule with simple matches first.