В данной статье мы разберем особенности конфигурации и работы с BGP Flow Specification.
BGP Flowspec (BGP Flow Specification) - это расширение протокола BGP, который позволяет фильтровать и совершать действия в отношении определенных портов и протоколов, как стандартных ACL, при этом для обмена правилами маршрутизации между узлами BGP используется детализированная информация NLRI.
На оборудовании серии ME реализован функционал BGP flowspec только в режиме клиента. Соответственно, на сети должен присутствовать элемент, способный генерировать Flowspec правила для дальнейшей отправки их по сети.
На данный момент, оборудование ME поддерживает следующие типы фильтров (NLRI):
1) Destination Prefix;
2) Source Prefix;
3) IP Protocol;
4) Port;
5) Destination Port;
6) Source Port;
7) DSCP;
8) Fragment;
Касательно типов действий над траффиком (Traffic Filtering Actions):
1) Пропуск траффика (Accept);
2) Блокировка траффика (Discard);
3) Перемаркировка dscp(traffic-marking);
4) Перенаправление - redirect ipv4 nexthop;
На схеме в качестве устройства, которое будет генерировать flowspec правила выступает Cisco XRv. Устройство R1 является Route-Reflector и его задача принимать данные Flowspec правила от Cisco и отправлять Route-Reflector client. ACL Flowspec будет сконфигурирован в сторону порта генератора траффика R3(te0/0/10), так как ACL работает только в ingress направлении.
Для конфигурирования данного функционала, впервую очередь, необходимо высвободить аппаратные ресурсы. Для этого на маршрутизаторе R3 добавим следующее: hw-module maximum acl-entries 100 <<<<< Высвобождение ресурсов под ACL записи hw-module enable acl-counters <<<<< Включение счетчиков ACL Важно помнить, что подсчет счетчиков возможен только, если у вас установлена плата статистики SM-STAT: 0/ME5100:R2_v2# show system inventory Mon Sep 25 04:28:37 2023 SM-STAT board: 10AX048H3F34E2SG ME5000-SM-STAT Hardware version: 1v3
Перейдем к конфигурированию устройств:
interface loopback 1 ipv4 address 1.1.1.1/32 exit interface tengigabitethernet 0/0/3 description to_R3 ipv4 address 172.16.0.1/30 load-interval 30 exit interface tengigabitethernet 0/0/5 description to_R5 ipv4 address 172.16.0.9/30 load-interval 30 exit interface tengigabitethernet 0/0/20.2101 description "to Cisco Flowspec" encapsulation outer-vid 2101 ipv4 address 10.0.0.5/30 load-interval 30 exit router bgp 64500 bgp router-id 1.1.1.1 neighbor 2.2.2.2 address-family ipv4 flowspec exit address-family ipv4 unicast exit remote-as 64500 route-reflector-client send-community send-community-ext update-source 1.1.1.1 exit neighbor 3.3.3.3 address-family ipv4 flowspec exit address-family ipv4 unicast exit remote-as 64500 route-reflector-client send-community send-community-ext update-source 1.1.1.1 exit neighbor 5.5.5.5 address-family ipv4 flowspec exit address-family ipv4 unicast exit remote-as 64500 route-reflector-client send-community send-community-ext update-source 1.1.1.1 exit exit router isis IGP interface loopback 1 address-family ipv4 unicast exit passive exit interface tengigabitethernet 0/0/3 address-family ipv4 unicast bfd fast-detect exit point-to-point exit interface tengigabitethernet 0/0/5 address-family ipv4 unicast bfd fast-detect exit point-to-point exit interface tengigabitethernet 0/0/20.2101 address-family ipv4 unicast bfd fast-detect exit point-to-point exit host-name R1 is-level level-2 net 49.0001.0000.0000.0001.00 exit
interface Loopback1 ipv4 address 2.2.2.2 255.255.255.255 ! interface GigabitEthernet0/0/0/0.2101 ipv4 address 10.0.0.6 255.255.255.252 encapsulation dot1q 2101 ! router isis 1 is-type level-2-only net 49.0001.0000.0000.0002.00 address-family ipv4 unicast ! interface Loopback1 passive address-family ipv4 unicast ! ! interface GigabitEthernet0/0/0/0.2101 bfd fast-detect ipv4 point-to-point address-family ipv4 unicast ! router bgp 64500 address-family ipv4 unicast ! address-family ipv4 flowspec ! neighbor 1.1.1.1 remote-as 64500 update-source Loopback1 address-family ipv4 unicast ! address-family ipv4 flowspec !
interface tengigabitethernet 0/0/1 description to_R1 ipv4 address 172.16.0.2/30 load-interval 30 exit interface tengigabitethernet 0/0/10 access-group ingress flow <<<<< Включение ACL на интерфейсе description Server ipv4 address 10.1.0.2/30 load-interval 30 exit router bgp 64500 address-family ipv4 unicast exit bgp router-id 3.3.3.3 neighbor 1.1.1.1 address-family ipv4 flowspec exit address-family ipv4 unicast exit remote-as 64500 send-community send-community-ext update-source 3.3.3.3 exit router isis IGP interface loopback 1 address-family ipv4 unicast exit passive exit interface tengigabitethernet 0/0/1 address-family ipv4 unicast bfd fast-detect exit point-to-point exit interface tengigabitethernet 0/0/10 address-family ipv4 unicast exit passive exit host-name R2 is-level level-2 net 49.0001.0000.0000.0003.00 exit access-list flow seq-num 1 flowspec <<<<< Включение для заданной ACL Flowspec правил exit exit
interface tengigabitethernet 0/0/1 description to_R1 ipv4 address 172.16.0.10/30 load-interval 30 exit interface tengigabitethernet 0/0/10 description Server ipv4 address 10.168.20.2/24 load-interval 20 exit router bgp 64500 address-family ipv4 unicast exit bgp router-id 5.5.5.5 neighbor 1.1.1.1 address-family ipv4 flowspec exit address-family ipv4 unicast exit remote-as 64500 send-community send-community-ext update-source 5.5.5.5 exit exit router isis IGP interface loopback 1 address-family ipv4 unicast exit passive exit interface tengigabitethernet 0/0/4 address-family ipv4 unicast bfd fast-detect exit point-to-point exit interface tengigabitethernet 0/0/10 address-family ipv4 unicast exit passive exit host-name R5 ipv4-te-level level-2 is-level level-2 microloop-avoidance rib-update-delay 100 net 49.0001.0000.0000.0005.00 spf interval maximum-wait 100 te-router-id 5.5.5.5 exit
Для примера создадим на Cisco Flowspec правила:
class-map type traffic match-all tcp_drop match destination-address ipv4 10.168.20.1 255.255.255.255 match source-address ipv4 10.1.0.0 255.255.255.0 match protocol tcp end-class-map ! policy-map type pbr tcp_drop class type traffic tcp_drop drop ! class type traffic class-default ! end-policy-map ! flowspec address-family ipv4 service-policy type pbr tcp_drop !
Фиксируем flowspec правило на R1(RR) и на R3:
0/ME5100:R1# show bgp ipv4 flowspec Thu Sep 21 05:48:19 2023 BGP router identifier 1.1.1.1, local AS number 64500 Graceful Restart is disabled BGP table state: active BGP scan interval: 120 secs Status codes: d damped, h history, > best, b backup, S stale, * active, u untracked, i internal Origin codes: i igp, e egp, ? incomplete Network Action Peer Address Metric LocPrf Weight Path ------------- ------------- ---------------------------------------- ------- ------- ------- ----- u>i Dst:10.168.20.1/32, Src:10.1.0.0/24, Proto:=tcp deny 2.2.2.2 0 100 0 i 0/ME5100:R3# show bg ipv4 flowspec Thu Sep 21 12:53:32 2023 BGP router identifier 3.3.3.3, local AS number 64500 Graceful Restart is disabled BGP table state: active BGP scan interval: 120 secs Status codes: d damped, h history, > best, b backup, S stale, * active, u untracked, i internal Origin codes: i igp, e egp, ? incomplete Network Action Peer Address Metric LocPrf Weight Path ------------- ------------- ---------------------------------------- ------- ------- ------- ----- u>i Dst:10.168.20.1/32, Src:10.1.0.0/24, Proto:=tcp deny 1.1.1.1 0 100 0 i
С помощью утилиты hping3 пробуем отправить TCP пакеты с маршрутизатора из подсети 10.1.0.0/24 до узла 10.168.20.1:
еester@qwesta:~$ sudo hping3 10.168.20.1 HPING 10.168.20.1 (eth1 10.168.20.1): NO FLAGS are set, 40 headers + 0 data bytes ^C --- 10.168.20.1 hping statistic --- 8 packets transmitted, 0 packets received, 100% packet loss round-trip min/avg/max = 0.0/0.0/0.0 ms
Проверим срабатывание счетчиков ACL на R3:
0/ME5100:R3# show access-lists detailed Thu Sep 21 08:44:18 2023 HW resources: 1/100 acl entries Access-list: flow Configured on interfaces: te0/0/10, IPv4: 8 hits seq-num 1 action: deny match: proto tcp, tos any, no fragments, tcp-flags any source: ipv4 10.1.0.0/24, ipv6 any, port any, mac any destination: ipv4 10.168.20.1, ipv6 any, port any, mac any set: none total: IPv4: 8 hits
Изменим Flowspec правило, добавив поле DSCP и сделаем его разрешающим:
class-map type traffic match-all tcp_drop match destination-address ipv4 10.168.20.1 255.255.255.255 match source-address ipv4 10.1.0.0 255.255.255.0 match dscp 12 match protocol tcp end-class-map policy-map type pbr tcp_drop class type traffic tcp_drop transmit
Проверим срабатывания счетчиков и прохождение траффика:
tester@qwesta:~/exabgp$ sudo hping3 10.168.20.1 --tos 32 HPING 10.168.20.1 (eth1 10.168.20.1): NO FLAGS are set, 40 headers + 0 data bytes len=46 ip=10.168.20.1 ttl=60 DF id=0 sport=0 flags=RA seq=0 win=0 rtt=0.4 ms len=46 ip=10.168.20.1 ttl=60 DF id=0 sport=0 flags=RA seq=1 win=0 rtt=0.2 ms len=46 ip=10.168.20.1 ttl=60 DF id=0 sport=0 flags=RA seq=2 win=0 rtt=4.1 ms len=46 ip=10.168.20.1 ttl=60 DF id=0 sport=0 flags=RA seq=3 win=0 rtt=4.1 ms ^C --- 10.168.20.1 hping statistic --- 4 packets transmitted, 4 packets received, 0% packet loss round-trip min/avg/max = 0.2/2.2/4.1 ms 0/ME5100:R3# show access-lists detailed Thu Sep 21 09:14:18 2023 HW resources: 1/100 acl entries Access-list: flow Configured on interfaces: te0/0/10, IPv4: 4 hits seq-num 1 action: permit match: proto tcp, tos any, dscp 12, no fragments, tcp-flags any source: ipv4 10.1.0.0/24, ipv6 any, port any, mac any destination: ipv4 10.168.20.1, ipv6 any, port any, mac any set: none total: IPv4: 4 hits
Следует сказать, что мы не поддерживаем спецификации заданные, как диапазон. Например, в отношении L4 портов мы не можем работать с диапазоном портов, следует передавать их простыми числами вида: 22, 443.
Так же рассмотрим следующий случай:
class-map type traffic match-all 2 match destination-address ipv4 10.168.20.1 255.255.255.255 match source-address ipv4 10.1.0.0 255.255.255.0 match protocol tcp match source-port 1111 1112 match dscp 12 end-class-map
В данном случае, мы имеем 3 условия соответствия пакета фильтрам (TCP, DSCP, Source-port). Каждое из них объединяется операцией логического И, в результате чего, на ME увидим следующий ACL:
0/ME5100:R2_v2# show access-lists detailed Mon Sep 25 10:39:47 2023 HW resources: 4/100 acl entries Access-list: flow Configured on interfaces: te0/0/10, IPv4: 0 hits seq-num 1 action: permit match: proto tcp, tos any, dscp 12, no fragments, tcp-flags any source: ipv4 10.1.0.0/24, ipv6 any, port eq 1111, mac any destination: ipv4 10.168.20.1, ipv6 any, port any, mac any set: none total: IPv4: 0 hits seq-num 1 action: permit match: proto tcp, tos any, dscp 12, no fragments, tcp-flags any source: ipv4 10.1.0.0/24, ipv6 any, port eq 1112, mac any destination: ipv4 10.168.20.1, ipv6 any, port any, mac any set: none total: IPv4: 0 hits
Проверим срабатывания счетчиков и прохождение траффика:
tester@qwesta:~/exabgp$ sudo hping3 10.168.20.1 --tos 32 -s 1111 HPING 10.168.20.1 (eth1 10.168.20.1): NO FLAGS are set, 40 headers + 0 data bytes len=46 ip=10.168.20.1 ttl=60 DF id=0 sport=0 flags=RA seq=0 win=0 rtt=3.3 ms len=46 ip=10.168.20.1 ttl=60 DF id=0 sport=0 flags=RA seq=1 win=0 rtt=3.1 ms len=46 ip=10.168.20.1 ttl=60 DF id=0 sport=0 flags=RA seq=2 win=0 rtt=3.0 ms ^C --- 10.168.20.1 hping statistic --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max = 3.0/3.1/3.3 ms tester@qwesta:~/exabgp$ sudo hping3 10.168.20.1 --tos 32 -s 1112 HPING 10.168.20.1 (eth1 10.168.20.1): NO FLAGS are set, 40 headers + 0 data bytes len=46 ip=10.168.20.1 ttl=60 DF id=0 sport=0 flags=RA seq=0 win=0 rtt=3.3 ms len=46 ip=10.168.20.1 ttl=60 DF id=0 sport=0 flags=RA seq=1 win=0 rtt=3.1 ms len=46 ip=10.168.20.1 ttl=60 DF id=0 sport=0 flags=RA seq=2 win=0 rtt=3.0 ms len=46 ip=10.168.20.1 ttl=60 DF id=0 sport=0 flags=RA seq=3 win=0 rtt=3.0 ms len=46 ip=10.168.20.1 ttl=60 DF id=0 sport=0 flags=RA seq=4 win=0 rtt=2.9 ms ^C --- 10.168.20.1 hping statistic --- 5 packets transmitted, 5 packets received, 0% packet loss round-trip min/avg/max = 2.9/3.1/3.3 ms 0/ME5100:R3# show access-lists detailed Mon Sep 25 11:02:41 2023 HW resources: 2/100 acl entries Access-list: flow Configured on interfaces: te0/0/10, IPv4: 8 hits seq-num 1 action: permit match: proto tcp, tos any, dscp 12, no fragments, tcp-flags any source: ipv4 10.1.0.0/24, ipv6 any, port eq 1111, mac any destination: ipv4 10.168.20.1, ipv6 any, port any, mac any set: none total: IPv4: 3 hits seq-num 1 action: permit match: proto tcp, tos any, dscp 12, no fragments, tcp-flags any source: ipv4 10.1.0.0/24, ipv6 any, port eq 1112, mac any destination: ipv4 10.168.20.1, ipv6 any, port any, mac any set: none total: IPv4: 5 hits