cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
65584
Views
28
Helpful
66
Comments
xthuijs
Cisco Employee
Cisco Employee

 

Introduction

BGP flow spec is a new tool that can be used to assist in DDOS mitigation in a dynamic fashion, levering BGP.

When I first started working and looking at BGP-FS I was a bit confused and in this article I would like to try and unravvle some of the specifics of BGP-FS, what you can do with it and how it works.

 

DDOS mitigation via RTBH (remote triggered blackhole)

Conceptually in this picture:

 

DDOS mitigation with the help of BGP is generally done via RTBH (remote triggered blackhole). And this comes basically in 2 key flavors: Source and Destination based.

The concept is that a BGP edge speaker has a static route defined to a "special next hop" to null0.

From a central point we inject a new route for a particular destination (eg our affected webserver) with a next hop pointing to that special next hop. This means that now at our border routers, our webserver address is set to a next hop, and this next hop is drop, and we prevent this traffic from hitting our server. This protects it nicely. But it removes the ability to reach this server completely!

The source based model is a similar concept whereby we KNOW where an attack comes from and now we send in a bgp path for that source with the special next hop, which then points to null.

Now when we use uRPF (reverse path forwarding), when a packet from that suspect source comes in, we apply RPF, we find the nexthop set to null0/discard. This would make RPF fail and we drop the packet from that host (or subnet for that matter).

Both options work great, but are big hammers.

BGP flowspec allows for a more granular appraoch and effectively construct instructions to match a particular flow with source AND destination, and L4 parameters and packet specifics such as length, fragment etc, and allow for a dynamic installation of an action at the border rotuers to either:

  • drop the traffic
  • inject it in a different vrf (for analysis)
  • or allow it, but police it at a specific defined rate.

Cool. Now that we got that theory out of the way, how about Flowspec then, what does it do and how is it different?!

 

BGP flowspec definitions

This conceptually describes how flowspec works:

So instead of sending/injecting a route for our server or server subnet with a special community that the border routers will associated with a nexthop to drop in their route policy language, in this case we are sending the new flowspec attribute format down to the border routers instructing them to create a sort of ACL with class-map and policy-map to implement this rule that we are advertising!

Very nifty, am lovin it. So in order to do that, we need to extend the BGP protocol a bit, and this is how the RFC is defining that approach:

BGP FS adds a new NLRI (network layer reachability info) to the BGP protocol:

NLRI defined (AFI=1, SAFI=133)

It adds the following packet/attribute format:

It allows for the following parameters to be defined:

1.Destination IP Address (1 component)
2.Source IP Address (1 component)
3.IP Protocol (+1 component)
4.Port (+1 component)
5.Destination port (+1 component)

6.Source Port (+1 component)

7.ICMP Type (asr9k has support for this yet, CRS does also)

8.ICMP Code (asr9k has support for this yet, CRS does also)

9.TCP Flags (asr9k supports lower byte, crs can not look at all bits)

10.Packet length

11.DSCP

12.Fragment

 

The actions that can be associated to a flow that we matched on by the parameters specified above are encoded as follows:

 

And the available actions that we can define are:

So with these new rules we can define a prefix or prefix set and not just that, we can base it on L3 source, L3 dest, its L4 specifics and even on packet length and L3 header options such as fragments! Then we can specify what actions we want to associate with that flow, redirect it, remark it, drop it or police it. And that is the full flow info.

All actions are supported by both CRS and ASR9000.

Ok this is all awesome, now that we got the theory out of the way, you want to go set it up I am sure!

Client/Server Model

In BGP-FS there is a client and a server. What that effectively means is that there is a device that injects the new flowspec entry (for the lack of a better word I guess) and there is a device (BGP speaker) that receives that NRLI and has to implement something in the hardware forwarding to act on that instruction.

So the device sending or injecting the NRLI is what I call the server, and the device that receive the NRLI and programs the hardware forwarding is called the client.

Visually:

CLIENT

In this concept the server in the grey box injects the flowspec NRLI and the client in the right box receives the information, sends it to the flow spec manager, configures the ePBR (enhance Policy based routing) infrastructure who then in turn programs the hardware from the underlaying platform in use.

SERVER

The server is configured either via CLI or XML to provide that entry for NRLI injection.

Note that XRv, virtual XR, can be a Server, it can inject those NRLI's for an asr9000 or CRS to act on those. Obviously XRv, not having a hardware forwarding layer is not a client

 

Configuration

conceptually

BGP

applicable to both client and server, we need to enable the new address family for advertisement:

router bgp 100

 address-family ipv4 flowspec

 ! Initializes the global address family

 address-family ipv6 flowspec

 !

 neighbor 1.1.1.1

  remote-as 100

  address-family ipv4 flowspec

  ! Ties it to a neighbor configuration

  address-family ipv6 flowspec

  !

 

Interface

You can disable flowspec on the interface as follows:

Interface gigabit0/0/0/0

 ipv4 flowspec disable

 !

Client

requires no special config other then a flowspec enabled peer.

Server

The server side configuration includes the policy-map definition and the association to the ePBR config consists of 2 portions, the class definition, and using that class in ePBR to define the action.

Classification

class-map type traffic match-all <class-name>

 <match statement> #Any combination of tuples 1-13 match statements goes here.

 end-class-map

 !

!

Tuple definition possibilities:

#Type 1: match  destination-address {ipv4| ipv6} <IPv4/v6 address>/<mask-length>

#Type 2: match  source-address {ipv4| ipv6}  <IPv4/v6 address>/<mask-length>

#Type 3: match protocol  { <value> | <min_value> -  <max_value> }

<!In case of IPv6, it will map to last next-header >

#Type 4: create two class-maps one with source-port and another with destionation-port

match source-port { <value> | <min_value> -  <max_value> }

match destination-port { <value> | <min_value> -  <max_value> }

<! Applicable only for TCP and UDP protocol !>

#Type 5: match destination-port { <value> | <min_value> -  <max_value> }

#Type 6: match source-port   { <value> | <min_value> -  <max_value> }

#Type 7: match {ipv4 | ipv6} icmp-type  { <value> | <min_value> - <max_value>}

#Type 8: match {ipv4 | Ipv6} icmp-code { <value> | <min_value> - <max_value>}

#Type 9: match tcp-flag   <value>  bit-mask <mask-value>

#Type 10: match packet length { <value> | <min_value> -  <max_value> }

#Type 11: match dscp { <value> | <min_value> -  <max_value> }

match ipv6 traffic-class  { <value> | <min_value> -  <max_value> }  

   [for providing 8 bit traffic class value]

#Type 12:  match fragment-type  {dont-fragment, is-fragment, first-fragment, last-fragment}

#Type 13:   match ipv6 flow-label { <value> | <min_value> -  <max_value> }

 

policy-map type pbr <policy-name>

 class type traffic  <class-name>

   <action>  #Any one of the extend community action listed below

 class class-default

 end-policy-map

ACTIONS:

##Traffic rate:

     police  rate < >  | drop

#Traffic action:

   sample-log

#Traffic marking:

     set dscp  <6 bit value> |

     set ipv6 traffic-class <8 bit value>

#VRF  redirect based on route-target:

  redirect {ipv6} extcommunity rt <route_target_string>

# Redirect IP nexthop support

 redirect {ipv6} next-hop <ipv4/v6 address> {ipv4/v6 address}

 

The following ties the flowspec to the PBR policies defined earlier.

flowspec

 [local-install interface-all]

 address-family ipv4

  [local-install interface-all]

  service-policy type pbr <policy-name>

  service-policy type pbr <policy-name>

 address-family ipv6

  [local-install interface-all]

  service-policy type pbr <policy-name>

  service-policy type pbr <policy-name>

  !

 ! 

 vrf  <vrf-name> 

  address-family ipv4

   [local-install interface-all]

   service-policy type pbr <policy-name>

   service-policy type pbr <policy-name>

  address-family ipv6

   [local-install interface-all]

   service-policy type pbr <policy-name>

   service-policy type pbr <policy-name>

   !

  !

 !

Example use case/configuration:

Target:

all packets to 10.0.1/24 from 192/8 and destination-port {range [137, 139] or 8080, rate limit to 500 bps in blue vrf and drop it in vrf-default. Also disable flowspec getting enabled on gig 0/0/0/0.

Associated copy paste config:

class-map type traffic match-all fs_tuple

 match destination-address ipv4 10.0.1.0/24

 match source-address ipv4 192.0.0.0/8

 match destination-port 137-139 8080

 end-class-map

 !

!

policy-map type pbr fs_table_blue

 class type traffic fs_tuple

  police rate 500 bps

  !

 !

 class class-default

 !

 end-policy-map

policy-map type pbr fs_table_default

 class type traffic fs_tuple

  drop

  !

 !

 class class-default

 !

 end-policy-map

flowspec

 local-install interface-all

 address-family ipv4

  service-policy type pbr fs_table_default

  !

 !

 vrf blue

  address-family ipv4

   service-policy type pbr fs_table_blue local

   !

  !

 !

!

Interface GigabitEthernet 0/0/0/0

 vrf blue

 ipv4 flowspec disable

 

 

BGP Flowspec and local QoS configuration

When flowspec is implemented on an interface that is also having local QoS configuration, local config will come before flowspec processing.
Local config will police and dscp-mark the packets and pass them to flowspec.
Flowspec will then do its processing (police, redirect) except dscp marking.

Flowspec will retain dscp marking as dictated by local qos config.

Say, we have the following:

inbound qos config : police 100Mbps, mark dscp af11
 
=============================================================
 
ipv4 access-list acl_ipv4_qos_stream
6 permit ipv4 any host 200.255.5.2
!
!
class-map match-any cm_ipv4_qos_stream
match access-group ipv4 acl_ipv4_qos_stream
 end-class-map
!
 
policy-map pm_ipv4_qos_stream
class cm_ipv4_qos_stream
  police rate 100 mbps
  !
  set dscp af11
!
 class class-default
!
 end-policy-map
!
 
interface hundredGigE 0/4/0/35
service-policy input pm_ipv4_qos_stream
 
=============================================================

Then we receive the following in flowspec advertisement.
flowspec config : police 50Mbps, mark dscp af43, redir vrf.
 
=============================================================
 
RP/0/RP0/CPU0:fretta-50#sh flowspec ipv4 detail | b 200.255.5.2
  Flow           :Dest:200.255.5.2/32
    Actions      :Traffic-rate: 50000000 bps DSCP: af43 Redirect: VRF honeypot Route-target: ASN2-4787:13  (bgp.1)
    Statistics                        (packets/bytes)
      Matched             :           116570713/12822778430        
      Transmitted         :            57360817/6309689870         
      Dropped             :            59209896/6513088560   
 
=============================================================
 
Then the outcome will be:

 

  1. traffic will be policed by flowspec at 50Mbps.
  2. traffic will be redirected by flowspec to VRF honeypot.
  3. flowspec will not overwrite dscp marking, traffic will be forwarded using dscp af11 instead of af43.

NCS5500 platform will also display this same behavior.

 

Special thanks to Nic Fevrier whose pictures I used for some of the visuals above.

 

Xander Thuijs CCIE#6775

Principal Engineer, ASR9000

 

Comments
vikas.hazrati1
Level 1
Level 1

Thanks this new version of BRKSPG-2904 provided many answers

Bradley Gould
Level 1
Level 1

Hi Xander,

 

There is some performance penalty with QPPB and re-circulation of packets to assign the qos-group.

 

No mention of that here - so is flow-spec superior in this regard?  Is there any other limitations apart from what you have discussed?

 

Thanks!

 

Brad

xthuijs
Cisco Employee
Cisco Employee

hi bradley, BGP-FS is merely "PBR" (and the pbr constructed by a bgp message), so the performance impact here is like using an ACL with an ABF next hop, which is about 25%-ish.

xander

nimmi.phasil
Level 1
Level 1

Hi Xander,

When I try to commit the flowspec configuration , Im getting the the error " !!% 'FlowSpec' detected the 'warning' condition 'FS MGR': Not supported ".

RP/0/RSP0/CPU0:LAB-ASR-2-R4(config-flowspec-af)#commit
Mon Jul 27 00:01:35.474 UTC

% Failed to commit one or more configuration items during a pseudo-atomic operation. All changes made have been reverted. Please issue 'show configuration failed [inheritance]' from this session to view the errors
RP/0/RSP0/CPU0:LAB-ASR-2-R4(config-flowspec-af)#show configuration failed
Mon Jul 27 00:01:53.037 UTC
!! SEMANTIC ERRORS: This configuration was rejected by
!! the system due to semantic errors. The individual
!! errors with each failed configuration command can be
!! found below.


flowspec
 address-family ipv4
  service-policy type pbr nv1
!!% 'FlowSpec' detected the 'warning' condition 'FS MGR': Not supported
 !
!
end

RP/0/RSP0/CPU0:LAB-ASR-2-R4(config-flowspec-af)#

 

Thanks 

Nimmi MP

Nicolas Fevrier
Cisco Employee
Cisco Employee

HI NIimmi,

are you using an ASR9000 with a minimum version of 5.2.0 ?

Please provide a "show install act sum".

Thanks,

N.

nimmi.phasil
Level 1
Level 1

Hi Nicolas,

Yes,.

RP/0/RSP0/CPU0:LAB-ASR-2-R4#sh install act sum
Mon Jul 27 00:27:03.616 UTC
Default Profile:
  SDRs:
    Owner
  Active Packages:
    disk0:asr9k-mini-px-5.2.0
    disk0:asr9k-fpd-px-5.2.0
    disk0:asr9k-mcast-px-5.2.0
    disk0:asr9k-mpls-px-5.2.0
    disk0:asr9k-mgbl-px-5.2.0

RP/0/RSP0/CPU0:LAB-ASR-2-R4#

 

Thanks

Nimmi 

Nicolas Fevrier
Cisco Employee
Cisco Employee

Ok, you should be good on this front then,

please share the part of your configuration related to the BGPFS so we can try to understand what goes wrong.

Also, you can create a new forum post for the sake of clarity, up to you.

Cheers,

N.

nimmi.phasil
Level 1
Level 1

Configuration.

class-map type traffic match-all nv
 match destination-address ipv4 119.227.2.252 255.255.255.255
 match source-address ipv4 0.0.0.0 0.0.0.0
 end-class-map

policy-map type pbr nv1
 class type traffic nv
  drop

router bgp 9583
 
 !
 address-family ipv4 flowspec
 !
 neighbor 202.144.74.184
  
  !
  address-family ipv4 flowspec
  !

Trying to add ,

flowspec
 local-install interface-all
 address-family ipv4
  service-policy type pbr nv1
 !

  getting error.

 

I have applied the above configuration to another ASR 9000(acting as server) and committed successfully. For testing purpose , added the same configuration to the client ; but got error.

Nicolas Fevrier
Cisco Employee
Cisco Employee

Hi Nimmi,

I thought it could be your source statement (which is not really useful, matching everything or not specifying anything providing the same results) but I tried in my setup and it works just fine.

I've seen trouble in the past when a router was used with other PBR path features like openFlow and then configured for FlowSpec. But it was never a config commit failed.

I suppose your two lab boxes have the exact same hardware and IOS XR installed on it ?

Cheers,

N.

nimmi.phasil
Level 1
Level 1

Hi Nicolas,

The idea is to drop packets from any source to destination 119.227.2.252 . It was not working . So I tried to configure in the client as well. Both have same hardware and IOS XR . 

Documentation for the Flowspec configuration:

Flowspec router CLI example:
class-map type traffic match-all cm1
match source-address ipv4 100.0.0.0/24
policy-map type pbr pm1
class type traffic cm1
drop
flowspec
address-family ipv4
service-policy type pbr pm0
Transient router CLI:
flowspec
address-family ipv4
service-policy type pbr pm1

In transient router (client) , I could not configure service-policy type pbr pm1 under flowspec since pm1 should be defined under policy . This lead to configuring the class-map and policy in the client.

Nicolas Fevrier
Cisco Employee
Cisco Employee

Hi Nimmi,

Let's separate the discussion in two parts.

- the fact that the config is not committed: it's unexpected and at the moment, I can not explain the root cause

- The way you approach the design BGP FS Client / Controller: it's not the way BGP flowspec is supposed to work.

You don't have to configure your class-map/policy-map on the client (it defeats comply the purpose of dissemination of the rules) but only on the controller.

On the controller you will have:

class-map type traffic match-all CLASS-MAP-1
 match destination-address ipv4 119.227.2.252 255.255.255.255
 end-class-map
!
policy-map type pbr POLICY-MAP-1
 class type traffic CLASS-MAP-1
  drop
!
router bgp XXX
 !
 address-family ipv4 flowspec
 !
 neighbor @client
  remote-as XXX
  !
  address-family ipv4 flowspec
  !
flowspec
 address-family ipv4
  service-policy type pbr POLICY-MAP-1
 !

and on the client:

router bgp XXX
 !
 address-family ipv4 flowspec
 !
 neighbor @cserver
  remote-as XXX
  !
  address-family ipv4 flowspec
  !
flowspec
 local-install interface-all
!

And that should be it. No need to configure a match any for the source, it's implicit.

Best regards,

N.

nimmi.phasil
Level 1
Level 1

Hi Nicolas,

 

Yes, I did the same  configuration . Since it didnt work (there was no match and no drop) , I tried to do the conf in client as well. Lets discuss that part later. 

With the same configuration , my ICMP packets are not getting dropped.

Output from client.

RP/0/RSP0/CPU0:LAB-ASR-2-R4#sh flowspec ipv4 detail
Mon Jul 27 02:57:42.931 UTC

AFI: IPv4
 Flow           :Dest:119.227.2.252/32
  Actions       :Traffic-rate: 0 bps  (bgp.1)
  Statistics                        (packets/bytes)
   Matched             :                   0/0
   Dropped             :                   0/0
RP/0/RSP0/CPU0:LAB-ASR-2-R4#

xthuijs
Cisco Employee
Cisco Employee

could it be you have a trident linecard in your system or that you are using XRv?

that will throw an unsupported error.

cheers!

xander
 

Nicolas Fevrier
Cisco Employee
Cisco Employee

Hi Nimmi,

let's start from here then. It seems that you received the rule on the client which means the config is probably OK.

First, remember that Flowspec is only applied on the ingress interface only. It can be physical or logical (bundle or dot1q) but not a tunnel (GRE or other).

It doesn't apply in egress or from the locally generated traffic.

In your case, if you trying to drop ICMP traffic, it will need to come from an external source into your client router interface.

Source --> ClientIngressInterface - ClientRouter - ClientEgressInterface --- 119.227.2.252

So make sure you are indeed receiving the traffic on the proper place (you can try ACL with logging option to verify that the traffic is indeed flowing on your interface, or more simple you can use "show interface 0/X/X/X accounting rate" to check the IPv4 traffic).

As mentioned briefly in the discussion, we got some bugs affecting the PBR path in case of multiple configuration. So, if it's possible in your lab environment, you should probably start reloading the router (admin reload location all) or at the minimum the ingress linecard.

If the problem persists, we will need to understand some other details of your topology (do you have the controller and client in the same ASN, for example). Also, it will be good to get detailed on:

show policy-map transient targets type pbr
show policy-map transient type pbr pmap-name __bgpfs_default_IPv4
show flowspec ipv4 internal
show flowspec trace manager event error
show flowspec trace client event error
show flowspec client internal

debug flowspec error 
(before establishing the BGP FS session and pushing the rule).

Thanks,

N.

 

 

 

 

Nicolas Fevrier
Cisco Employee
Cisco Employee

Good point Xander, I overlooked the basics.

Nimmi, please send us a "show plat" to confirm.

Thanks,

N.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Quick Links