Made4it

How to configure FlowSpec on Juniper Routers

Overview:

BGP FlowSpec (Border Gateway Protocol Flow Specification) is an extension of the BGP protocol used to define traffic filtering rules on routers; in simpler terms, it can generate firewall rules on routers based on a BGP announcement. Unlike conventional BGP, which routes based on IPv4/IPv6 and prefix information, BGP FlowSpec allows network administrators to specify more granular criteria for packet forwarding, including Layer 4 information (TCP/UDP ports) and even packet patterns.

To learn more about BGP Flowspec, check out our article explaining what BGP Flowspec is by clicking this link.

Operation:

BGP FlowSpec works by adding new types of attributes to BGP, allowing network administrators to specify detailed filtering rules. These rules can include criteria such as:

  • IPv4/IPv6 source and destination addresses
  • TCP/UDP ports
  • Protocols
  • Bit masks
  • Package field values

The following actions can be taken with BGP FlowSpec:

  1. deny: Blocks the traffic corresponding to the rule.
  2. rate-limit: Limits the traffic rate corresponding to the rule.
  3. redirect: Redirects the traffic corresponding to the rule.
  4. sample: Collects a sample of the traffic corresponding to the rule.
  5. mark: Marks packages matching the rule with a specific mark.
  6. redirect-to-ip: Redirects the traffic corresponding to the rule to a specific IP address.
  7. traffic-rate: Limits the traffic rate corresponding to the rule to a specific value.
  8. traffic-action: Defines action for the corresponding traffic, such as accept, discard or forward.
  9. redirect-to-blackhole: Silently discards all traffic corresponding to the rule.

When these rules are propagated through the BGP network, routers can use this information to filter or manipulate traffic according to the defined policies.

Operation – More Details:

In the context of BGP FlowSpec, the actions are specified as part of the filter rules. Each filter rule contains three main parts:

  • Matching Fields: These specify the Matching Fields: criteria, such as source and destination IP addresses, TCP/UDP ports, protocols, bit masks and packet field values.
  • Action Fields: These specify the actions to be taken for the traffic that corresponds to the rule.
  • Protocol Fields: Specify the protocol that the filter rule should apply.

Actions in BGP FlowSpec are coded using BGP communities. Each action is mapped to a specific BGP community:

  • The‘deny‘ action can be represented by a specific BGP community, such as ‘65535:666’.
  • The‘rate-limit‘ action can be represented by another specific BGP community, such as ‘65535:777’.
  • The‘redirect‘ action can be represented by a different BGP community, such as ‘65535:888’.

When you create a BGP FlowSpec rule, you specify the matching fields, the desired action and, optionally, protocol fields. This rule is then encoded as a BGP community and included in a BGP update message that is sent to neighboring routers. The routers that receive this rule apply the specified actions to the packets that match the matching criteria.

Please note that the specific BGP communities for each action may vary depending on the BGP FlowSpec implementation on your network equipment. I recommend consulting your equipment’s documentation for detailed information on the BGP communities associated with each action in BGP FlowSpec.

Use Cases:

1. **DDoS attack mitigation:

BGP FlowSpec can be used to block or redirect malicious traffic during distributed denial of service (DDoS) attacks. Precise rules can be applied to filter out unwanted traffic and keep services online.

2. **QoS (Quality of Service) policies:

Network administrators can use BGP FlowSpec to guarantee quality of service by prioritizing certain types of traffic based on specific ports or protocols.

3. **Implementing Security Policies**:

BGP FlowSpec can be used to implement granular security policies, blocking traffic associated with malware or suspicious activity.

Configuration examples:

The BGP FlowSpec configuration may vary depending on the network equipment used.

This example explores how to design a DDoS mitigation solution in which a service provider allows its customers to advertise BGP FlowSpec routes to it.

It also discusses some of the best practices that should be considered before implementing this type of solution and, finally, some of the Junos commands available to help you check that your Flow-spec solution is working correctly.

Topology scenario for the example:

Let’s start by taking a look at how our solution will be configured:

As we can see in the topology above, there is “BORDA,” a Juniper device that serves as the network’s BGP router, and “Made4Flow,” the software that will analyze the flows, dynamically generate BGP FlowSpec rules, and advertise them via BGP to the BGP router called “BORDA.”

In this scenario, the example attack is a DNS amplification attack. This means that the network is receiving a large volume of UDP port 53 packets that it doesn’t actually need for the ISP to function normally.

The attack fills the circuit between the ISP and the operators and effectively renders the network inoperable.

When the attacker decides to launch the attack, the ISP can use Made4Flow to generate a BGP FlowSpec route specifically for UDP port 53 packets and announce it to the BGP EDGE router, which can then convert that route into a firewall filter on its interfaces that communicate with the carriers.

And then this blocks the DNS amplification packets at the edge of the ISP’s network and also at the carrier (if the carrier supports FlowSpec sessions), but allows legitimate traffic to continue arriving.


First, let’s look at the BGP FlowSpec session settings on the BORDA BGP router with Made4Flow, assuming that the router is already configured for normal BGP unicast routing (Normal BGP session for announcing Blackhole or Mitigation/Scrubbing Center routes).

To configure a BGP FlowSpec session on Juniper devices, we use the following commands:

Good practices:

There are best practices for protecting this solution. Both the BGP FlowSpec routes and the resulting firewall filters they create are finite resources in the router.

Therefore, the BGP EDGE router can filter incoming routes to ensure that it does not receive more routes than expected or incorrect routes.

Prefix Limit:

So the first thing to do is to set a prefix limit for BGP FlowSpec routes.

You could simply set a single prefix limit for the inet unicast and inet flowroutes; however, this example will set a separate limit for the inet flowroutes. To ensure that Made4Flow can send only ten BGP Flowspec routes at a time, let’s set the prefix limit to 10 (this configuration should be adjusted according to each scenario):

Route Policy :

The next thing to do is to apply an inbound route policy. This policy will limit the router to receiving prefixes that are from the ISP itself with prefixes /24 to /32, which are those announced by Made4Flow.

Let’s also add a Community 64496:86 so that it can identify the routes as BGP FlowSpec routes.

For all other routes, you can simply filter them based on the client’s route assignment:

1. Create the policy definition:

2. Apply the policy as an import policy in the BGP session with Made4Flow:

Maximum prefixes:

The last thing to do is to set a maximum number of BGP FlowSpec prefixes that can be installed in the routing table.

This example sets a maximum of 10,000 routes, but let’s also configure the router to notify the administrator via a syslog message when a 90% threshold is reached. This configuration must be applied to all routers in the ISP’s network in the example:

It may not be very intuitive to understand in the syntax above, but the conf. threshold 90 is what tells the router that you want a syslog message when the 90% threshold is reached.

Verification:

The first thing to check is that BGP FlowSpec is configured correctly. Let’s look at the NLRIs that are activated in the BGP peer.

Checking the NLRI: From operational mode on the BORDA router, enter the Junos OS command show bgp neighbor 10.70.0.68 and look for the inet-flow capability in the output:

Checking Routes:

The next thing to look at is the flow route that was sent by Made4Flow and received at the BORDA:

And here the route is being received from Made4Flow. Note that the only community attached to the route is the one that specifies that you should set a rate of 0 for the traffic.

Now let’s take a look at the route in the BGP BORDA router’s routing table:

The route has been installed in the route table in BORDA and Community 64496:86 that was assigned was added to the route.

Note that the flow was mapped to the unicast route and validated for consistency.

With that, we continue…

Checking the firewall filters:

Now that the flow routes have been validated, they are turned into firewall filters.

Let’s take a look at the firewall filter:

All OK.

Check the system log:

EXAMPLE: If you have followed the best practices above and set a prefix limit in the BGP session, you will see a log message when the maximum is reached:

Final summary of the example:

As we can see, configuring a BGP FlowSpec solution is simple.

Between ISPs it can become a little more complicated, as it requires coordination between the client and the service provider. Unfortunately, not all operators provide FlowSpec sessions.

Check with your service provider to see if this is possible, as it is essential to have this set up in advance of a DDoS attack.

Find out more about how to optimize traffic forwarding with BGP FlowSpec and simplify network security management! Explore Made4Flow, our netflow analysis tool, and take your network infrastructure to the next level.

Made4it arises to meet the needs of the market, which has been demanding more and more personalized solutions.