How BGP FlowSpec Works: Distributed DDoS Mitigation via BGP

BGP FlowSpec (Flow Specification) is a BGP extension that allows network operators to distribute traffic filtering and rate-limiting rules across their network using the BGP routing protocol. Instead of manually configuring access control lists (ACLs) on every router during a DDoS attack, an operator can inject a single FlowSpec rule into BGP, and it propagates automatically to all BGP-speaking routers in the network. FlowSpec transforms BGP from a pure reachability protocol into a distributed firewall policy distribution system. Originally defined in RFC 5575 and updated by RFC 8955 (which obsoletes RFC 5575), FlowSpec is one of the most powerful tools available for real-time DDoS mitigation in ISP and enterprise networks.

FlowSpec is particularly valuable because it operates at the network layer, close to the attack source. Rather than absorbing attack traffic at a scrubbing center or at the target, FlowSpec rules can be pushed to upstream routers and even to peering partners, filtering malicious traffic before it consumes expensive transit capacity. When combined with BGP communities and automation, FlowSpec enables sub-minute DDoS response times without human intervention.

The Problem FlowSpec Solves

Consider a typical DDoS mitigation scenario without FlowSpec: a volumetric UDP flood targets a customer's IP address. The operator detects the attack (via NetFlow, sFlow, or inline monitoring), identifies the attack characteristics (source port 53, destination port random, protocol UDP), and then must:

  1. Log into each border router individually
  2. Write an ACL that matches the attack traffic
  3. Apply the ACL to the appropriate interface
  4. Repeat for every router that receives attack traffic
  5. Reverse the process when the attack ends

In a network with 20 border routers across multiple PoPs, this manual process can take 30-60 minutes — during which the target is unreachable and collateral damage affects other customers sharing the same links. FlowSpec replaces this entire process with a single BGP announcement that propagates to all routers in seconds.

FlowSpec DDoS Mitigation Distribution Attack Traffic UDP flood, 50 Gbps Border-1 FlowSpec: DROP Border-2 FlowSpec: DROP Border-3 FlowSpec: DROP Core Network iBGP mesh / RR FlowSpec Controller DDoS detection + BGP Injects FlowSpec NLRI BGP Protected Target 203.0.113.50/32 Result: attack traffic dropped at network edge in seconds Single BGP announcement → all border routers install filter → attack mitigated before reaching target

FlowSpec NLRI Encoding

FlowSpec uses a new BGP NLRI (Network Layer Reachability Information) encoding to describe traffic flows. Each FlowSpec rule is encoded as a sequence of match components in the NLRI, and actions encoded as extended communities attached to the BGP UPDATE. The NLRI is carried in the BGP Multiprotocol Extensions (RFC 4760) using AFI 1 (IPv4) or AFI 2 (IPv6) and SAFI 133 (FlowSpec) or SAFI 134 (FlowSpec VPN).

Match Components (NLRI)

Each match component specifies a condition that traffic must meet. Multiple components are combined with an implicit AND — all conditions must match for the rule to apply. The following component types are defined in RFC 8955:

RFC 8956 extends FlowSpec to IPv6, adding match components for IPv6 flow labels and using the IPv6 next-header field instead of IP protocol.

Numeric Operators

For numeric match components (port, packet length, protocol, etc.), FlowSpec uses a compact operator encoding. Each value is preceded by an operator byte that specifies the comparison:

Multiple values can be chained together with OR or AND logic. For example, to match "destination port 80 OR 443": =80 | =443. To match "port >= 1024 AND <= 65535": >=1024 & <=65535.

FlowSpec Actions

Actions are encoded as BGP extended communities attached to the FlowSpec NLRI. When a packet matches the flow specification, one or more actions are applied:

FlowSpec Validation

To prevent a rogue BGP speaker from injecting FlowSpec rules that disrupt legitimate traffic, RFC 8955 defines strict validation rules that a receiving router must apply before installing a FlowSpec rule:

  1. Origin AS validation: The originator of the FlowSpec NLRI must be the same AS that originates the best-match unicast route for the destination prefix in the FlowSpec rule. If the FlowSpec rule specifies destination 203.0.113.0/24, and the best unicast route for 203.0.113.0/24 is originated by AS64500, then the FlowSpec rule must also originate from AS64500. This prevents arbitrary ASes from injecting filters for prefixes they do not own.
  2. Neighbor AS validation: For eBGP-learned FlowSpec, the FlowSpec NLRI must be received from the same neighbor that advertised the best-match unicast route. This ensures FlowSpec rules propagate along the same paths as the unicast routes they protect.
  3. Feasibility check: The destination prefix in the FlowSpec rule must have a matching entry in the unicast routing table. A FlowSpec rule for a prefix with no unicast route is rejected.

These validation rules are critical for security but can also be operationally inconvenient. For internal iBGP FlowSpec (where the FlowSpec controller is within the same AS), validation can be relaxed because the iBGP session is trusted. Many operators disable origin AS validation for iBGP-learned FlowSpec rules while keeping it strict for eBGP-learned rules.

FlowSpec Rule Examples

Here are practical FlowSpec rules expressed in a common CLI-like notation (actual syntax varies by vendor):

Drop all UDP traffic to a target

flow {
  match destination 203.0.113.50/32;
  match protocol udp;
  then discard;
}

This drops all UDP traffic destined for 203.0.113.50. Simple and effective for a UDP-only flood, but also drops legitimate UDP traffic (DNS, QUIC) to the target.

Drop DNS amplification attack

flow {
  match destination 203.0.113.50/32;
  match protocol udp;
  match source-port 53;
  match packet-length >= 512;
  then discard;
}

Targets DNS amplification specifically: large UDP packets from source port 53. Legitimate DNS responses to the target are typically small; amplified responses are artificially large. The packet-length filter reduces collateral damage to legitimate DNS traffic.

Rate-limit NTP amplification

flow {
  match destination 203.0.113.0/24;
  match protocol udp;
  match source-port 123;
  then rate-limit 1000000;
}

Instead of dropping all NTP traffic, this rate-limits it to 1 Mbps. Some NTP traffic may be legitimate; rate limiting allows a small amount through while preventing the volumetric attack from consuming all bandwidth.

Redirect SYN flood to scrubbing VRF

flow {
  match destination 203.0.113.50/32;
  match protocol tcp;
  match tcp-flags syn !ack;
  then redirect vrf SCRUBBER;
}

Redirects TCP SYN packets (without ACK, indicating connection initiation) to a scrubbing VRF where a mitigation appliance performs SYN validation (SYN cookies or SYN proxy) and forwards legitimate connections back.

FlowSpec at Internet Exchange Points

Some Internet Exchange Points (IXPs) and transit providers support FlowSpec from their customers via eBGP. This allows a customer under attack to inject FlowSpec rules that the upstream provider applies on its border routers, filtering attack traffic before it enters the customer's last-mile link. This is sometimes called upstream FlowSpec or remote triggered FlowSpec.

Upstream FlowSpec requires trust between the customer and the provider. Providers typically apply strict validation rules and limit the scope of FlowSpec rules a customer can inject:

FlowSpec vs. RTBH (Remotely Triggered Black Hole)

Before FlowSpec, the primary BGP-based DDoS mitigation technique was RTBH (Remotely Triggered Black Hole), also known as blackhole routing. RTBH works by advertising a /32 host route for the target IP with a specific BGP community (often the well-known blackhole community 65535:666, defined in RFC 7999). Upstream routers receiving this announcement set the next-hop to a null interface, dropping all traffic to that IP.

RTBH is simpler than FlowSpec but far cruder:

Many operators use both: FlowSpec for targeted, selective mitigation of attacks with identifiable signatures, and RTBH as a fallback when FlowSpec is insufficient or the attack volume exceeds the network's capacity to filter.

FlowSpec and BGP Hijack Mitigation

While FlowSpec is primarily used for DDoS mitigation, it can also play a role in responding to BGP hijacks. If an operator detects that their prefix is being hijacked (traffic is being misdirected to an unauthorized AS), they can use FlowSpec to filter spoofed traffic or redirect traffic matching specific patterns while the hijack is being resolved through RPKI-based route origin validation or manual coordination.

FlowSpec Implementation Considerations

Deploying FlowSpec in production requires careful attention to several operational details:

FlowSpec Rule Lifecycle 1. Detect NetFlow/sFlow analysis identifies attack signature 2. Inject Controller creates FlowSpec NLRI + action communities 3. Propagate BGP distributes to all routers via iBGP / RR 4. Filter Each router installs ACL/policer in forwarding hardware 5. Withdraw Attack ends; BGP withdraw removes rule Typical timeline: detect (5-30s) + inject (instant) + propagate (1-5s iBGP) + filter install (1-2s) = 10-40s total Compare: manual ACL deployment across 20 routers = 30-60 minutes FlowSpec provides 50-100x faster response time for DDoS mitigation

FlowSpec Automation

The full power of FlowSpec is realized when it is integrated with automated DDoS detection systems. The typical architecture uses:

  1. Flow telemetry collection: NetFlow v9/IPFIX or sFlow data is collected from all border and core routers and sent to a central collector.
  2. DDoS detection engine: Software that analyzes flow data in real time, detecting traffic anomalies that match known DDoS attack patterns (volumetric floods, protocol attacks, application-layer attacks).
  3. FlowSpec controller: When an attack is detected, the controller automatically generates the appropriate FlowSpec rule based on the attack characteristics and injects it into BGP. The controller maintains a BGP session with a route reflector or directly with border routers.
  4. Automatic withdrawal: The controller monitors ongoing traffic to determine when the attack has subsided and automatically withdraws the FlowSpec rule. Rules may also have a configurable timeout (not part of the BGP protocol but implemented in the controller logic).

Open-source tools like ExaBGP and GoBGP can act as FlowSpec controllers, injecting rules programmatically via BGP. Commercial platforms from vendors like Arbor/NETSCOUT, Flowmon, and A10 provide integrated detection-and-mitigation workflows with FlowSpec as the distribution mechanism.

Limitations of FlowSpec

FlowSpec is powerful but not a complete DDoS solution:

RFCs and Standards

The FlowSpec standard has evolved over time:

Monitor BGP Routes and DDoS Indicators

FlowSpec is one layer of the DDoS defense stack built on top of BGP. Understanding how traffic flows between networks — the AS paths, upstream providers, and peering relationships — is essential context for designing effective FlowSpec rules. Use the god.ad BGP Looking Glass to explore live BGP routing data, trace AS paths to potential attack sources, and understand the routing topology that FlowSpec protects.

See BGP routing data in real time

Open Looking Glass
More Articles
What is BGP? The Internet's Routing Protocol Explained
What is an Autonomous System (AS)?
What is a BGP Looking Glass?
How to Look Up an IP Address's BGP Route
Understanding BGP AS Paths
What is RPKI? Securing BGP Routing