Juniper Junos BGP Flowspec Guide: Signaling Upstream DDoS Filtering Rules

BGP Flowspec (RFC 8955) enables network operators to distribute granular traffic-filtering rules directly through BGP. By encoding packet-matching tuples—such as source/destination prefixes, IP protocols, TCP/UDP ports, and ICMP types—into BGP NLRI (SAFI 133), any peer configured with family inet flow automatically compiles and installs line-rate firewall filters. This makes BGP Flowspec a cornerstone mechanism for automated, surgical upstream DDoS mitigation.

In this hands-on Juniper Junos (vMX) walkthrough, we configure a customer edge router (Controller) to signal Flowspec rules to an upstream ISP router (Controlled PE), selectively dropping attack traffic upstream while keeping legitimate services unaffected.

Lab Topology & Node Roles

Juniper Junos BGP Flowspec topology showing external source vMX-VFP3 (R1, 10.0.0.1 / 100.64.0.1), upstream ISP PE vMX-VFP4 (R2, 10.0.0.2), customer edge vMX-VFP9 (CE-B, 10.0.0.3), Switch10, and protected server Client-B (100.64.1.2/24)
Figure 1: Juniper vMX BGP Flowspec lab topology (including VCP/VFP control-forwarding split and subnet addressing).

The lab topology maps EVE-NG vMX forwarding nodes to their Junos CLI hostnames as follows:

  • vMX-VFP3 (R1, 10.0.0.1): Simulates an external Internet client/attacker using secondary loopback IP 100.64.0.1.
  • vMX-VFP4 (R2, 10.0.0.2): Upstream ISP PE router (Controlled End) that receives Flowspec NLRI into inetflow.0 and generates the dynamic __flowspec_default_inet__ firewall filter.
  • vMX-VFP9 (CE-B, 10.0.0.3): Customer Edge router (Controller) that injects Flowspec mitigation routes when an attack occurs.
  • Client-B (100.64.1.2/24): Protected target server attached behind Switch10.

Mitigation Objective

  • When a DDoS attack hits Client-B, CE-B signals a BGP Flowspec NLRI update to upstream ISP PE R2.
  • R2 dynamically installs the corresponding firewall term and drops matching attack packets upstream before they saturate the customer access link.

Base BGP & Flowspec Address-Family Configuration

Interface IP addressing and underlay OSPF reachability are pre-configured in the lab (note: production eBGP ISP interconnects do not run OSPF; OSPF is present here solely to support follow-up multi-lab testing).

Because BGP Flowspec operates in a Controller–Controlled model, the upstream ISP router only needs to enable the Flowspec address family (alongside strict inbound prefix-ownership validation in production), while all filtering rules are authored and advertised from the customer edge router (CE-B).

1. Customer Edge Router (vMX-VFP9 / CE-B)

root@CE-B# show

routing-options {
    flow {
        term-order standard; // Enable BGP Flowspec using RFC standard term ordering
    }
    router-id 10.0.0.3;
}
protocols {
    bgp {
        group inet-4 {
            type internal;
            local-address 10.0.0.3;
            family inet {
                unicast; // Enable IPv4 unicast NLRI (SAFI 1)
                flow; // Enable IPv4 Flowspec NLRI (SAFI 133)
            }
            local-as 65000;
            neighbor 10.0.0.2 {
                import import;
                export export;
                peer-as 65000;
            }
        }
    }
}
policy-options {
    policy-statement export {
        term inet-flow-export {
            from rib inetflow.0; // Export Flowspec rules from inetflow.0
            then accept;
        }
        term inet-unicast-export {
            from {
                rib inet.0;
                route-filter 100.64.1.0/24 exact; // Advertise our server prefix
            }
            then accept;
        }
        term last {
            then reject;
        }
    }
    policy-statement import {
        then accept;
    }
}

[edit]

2. Upstream ISP PE Router (vMX-VFP4 / R2)

root@R2# show

routing-options {
    flow {
        term-order standard; // Enable BGP Flowspec using RFC standard term ordering
    }
    router-id 10.0.0.2;
}
protocols {
    bgp {
        group inet-4 {
            type internal;
            local-address 10.0.0.2;
            cluster 10.0.0.2;
            local-as 65000;
            neighbor 10.0.0.1 {
                import all;
                export all;
                peer-as 65000;
            }
            neighbor 10.0.0.3 {
                import all;
                family inet {
                    unicast; // Enable IPv4 unicast SAFI to exchange IPv4 routes
                    flow; // Enable IPv4 Flowspec SAFI to accept/propagate Flowspec rules
                }
                export all;
                peer-as 65000;
            }
        }
    }
policy-options {
    policy-statement all {
        then accept;
    }
}

Baseline Session & Connectivity Verification

Verify that the BGP peering between CE-B and R2 is Established for both inet.0 and inetflow.0:

root@CE-B# run show bgp summary
Groups: 1 Peers: 1 Down peers: 0
Table          Tot Paths  Act Paths Suppressed    History Damp State    Pending
inet.0
                       6          1          0          0          0          0
inetflow.0
                       0          0          0          0          0          0
Peer                     AS      InPkt     OutPkt    OutQ   Flaps Last Up/Dwn State|#Active/Received/Accepted/Damped...
10.0.0.2              65000         81         77       0       0       33:09 Establ
  inet.0: 1/6/5/0
  inetflow.0: 0/0/0/0

From external node R1 (100.64.0.1), confirm normal baseline reachability to Client-B (100.64.1.2) over both ICMP and SSH:

root@R1> ping 100.64.1.2 count 3 source 100.64.0.1
PING 100.64.1.2 (100.64.1.2): 56 data bytes
64 bytes from 100.64.1.2: icmp_seq=0 ttl=62 time=563.488 ms
64 bytes from 100.64.1.2: icmp_seq=1 ttl=62 time=173.453 ms
64 bytes from 100.64.1.2: icmp_seq=2 ttl=62 time=370.806 ms

--- 100.64.1.2 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max/stddev = 173.453/369.249/563.488/159.235 ms

root@R1> ssh 100.64.1.2 source 100.64.0.1
The authenticity of host '100.64.1.2 (100.64.1.2)' can't be established.
ECDSA key fingerprint is SHA256:UGgeGwcaz0+JMrvB1Sh/DEtay3sc3mTrjJYztLLTtHs.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '100.64.1.2' (ECDSA) to the list of known hosts.
root@100.64.1.2's password:

Both Ping and SSH succeed as expected before any Flowspec filter is injected.

How Flowspec Signaling & Upstream Filtering Work

BGP Flowspec control-plane signaling and data-plane filtering workflow: CE-B advertises SAFI 133 rules from inetflow.0 to R2, which compiles __flowspec_default_inet__ to drop SSH TCP/22 or ICMP flood packets upstream
Figure 2: Control-plane Flowspec NLRI propagation (inetflow.0) and verified upstream mitigation on ISP PE R2.

Scenario 1: Mitigating an SSH (TCP/22) Flood Attack

Now simulate a volumetric brute-force or SYN flood targeting SSH port 22 on 100.64.1.2. To neutralize the attack upstream while preserving normal routing paths for all other traffic, define the deny-ssh Flowspec route on CE-B:

root@CE-B# show routing-options
flow {
    route deny-ssh {  // Define a Flowspec rule named deny-ssh
        match {  // Match traffic tuples
            protocol tcp; // TCP protocol
            destination-port 22; // Destination port 22 (SSH)
            destination 100.64.1.2/32; // Target victim server IP
        }
        then discard; // Drop matching packets upstream
    }
    term-order standard;
}

Inspect inetflow.0 and the auto-compiled firewall filter __flowspec_default_inet__ on upstream router R2:

root@R2> show route table inetflow.0 extensive

inetflow.0: 1 destinations, 1 routes (1 active, 0 holddown, 0 hidden)
100.64.1.2,*,proto=6,dstport=22/term:1 (1 entry, 1 announced)
TSI:
KRT in dfwd;
Action(s): discard,count
        *BGP    Preference: 170/-101
                Next hop type: Fictitious, Next hop index: 0
                Address: 0xa1d9dbc
                Next-hop reference count: 1
                Next hop:
                State: <Active Int Ext>
                Peer AS:   65000
                Age: 2:28
                Validation State: unverified
                Task: BGP_65000_65000.10.0.0.3+179
                Announcement bits (1): 0-Flow
                AS path: I
                Communities: traffic-rate:0:0
                Accepted
                Localpref: 100
                Router ID: 10.0.0.3

root@R2> show firewall filter __flowspec_default_inet__

Filter: __flowspec_default_inet__
Counters:
Name                                                Bytes              Packets
100.64.1.2,*,proto=6,dstport=22                         0                    0

Notice that R2 accepted 100.64.1.2,*,proto=6,dstport=22 with extended community traffic-rate:0:0 (discard) and programmed it directly into dfwd under __flowspec_default_inet__.

Re-test both ICMP and SSH from R1 toward 100.64.1.2:

root@R1> ping 100.64.1.2 count 3 source 100.64.0.1
PING 100.64.1.2 (100.64.1.2): 56 data bytes
64 bytes from 100.64.1.2: icmp_seq=0 ttl=62 time=11.102 ms
64 bytes from 100.64.1.2: icmp_seq=1 ttl=62 time=7.364 ms
64 bytes from 100.64.1.2: icmp_seq=2 ttl=62 time=332.472 ms

--- 100.64.1.2 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max/stddev = 7.364/116.979/332.472/152.384 ms

root@R1> ssh 100.64.1.2 source 100.64.0.1
ssh: connect to host 100.64.1.2 port 22: Operation timed out

Check the dynamic firewall counters on R2:

root@R2> show firewall filter __flowspec_default_inet__

Filter: __flowspec_default_inet__
Counters:
Name                                                Bytes              Packets
100.64.1.2,*,proto=6,dstport=22                       432                    8

Upstream PE R2 dropped 8 TCP port 22 packets (432 bytes) destined for 100.64.1.2 while ICMP traffic continued flowing with 0% packet loss.

Scenario 2: Mitigating an ICMP Flood (Permit TCP, Drop ICMP)

Next, deactivate deny-ssh and inject deny-icmp matching ICMP Echo Reply and Request (icmp-type [ 0 8 ]) to simulate mitigating an ICMP flood:

root@CE-B# show
inactive: route deny-ssh {
    match {
        protocol tcp;
        destination-port 22;
        destination 100.64.1.2/32;
    }
    then discard;
}
route deny-icmp {
    match {
        protocol icmp;
        icmp-type [ 0 8 ];
    }
    then discard;
}
term-order standard;

Test ICMP and SSH again from R1:

root@R1> ping 100.64.1.2 count 3 source 100.64.0.1
PING 100.64.1.2 (100.64.1.2): 56 data bytes

--- 100.64.1.2 ping statistics ---
3 packets transmitted, 0 packets received, 100% packet loss

root@R1> ssh 100.64.1.2 source 100.64.0.1
root@100.64.1.2's password:
Permission denied, please try again.
root@100.64.1.2's password:

Inspect the updated firewall counters on R2:

root@R2> show firewall filter __flowspec_default_inet__

Filter: __flowspec_default_inet__
Counters:
Name                                                Bytes              Packets
*,*,proto=1,icmp-type=0,=8                            252                    3

All 3 ICMP test packets (252 bytes) were intercepted at R2 by __flowspec_default_inet__, while SSH connectivity to Client-B resumed immediately.

Production Deployment Considerations

  • Controller–Controlled Architecture: Every enforcement point in the transit path must enable family inet flow. If Flowspec routes traverse Route Reflectors, the RRs should reflect inetflow.0 NLRI without installing filters on their own forwarding plane.
  • Inbound Prefix-Ownership Validation: When offering BGP Flowspec to downstream customers in production, service providers must apply strict inbound validation (matching the customer’s authorized prefixes per RFC 8955 / IRR / RPKI) so one tenant cannot blackhole traffic belonging to another customer.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.