Análisis de redistribución OSPF que podría generar bucle

Fecha: 21 de agosto del 2021

 

Escenario

 

Este laboratorio nació a partir de una migración en un escenario mas complejo y en el que terminé teniendo dudas

de un posible daño colateral en un extremo (una ruta redistribuida en OSPF y hacia un gateway que justamente era

a donde apuntaba la ruta misma) y que confirmé que no.

Pero cuando ya me había ido a dormir me quedó dando vueltas la pregunta “por qué no ? ”

 

             

 

Al otro día tuve que poner manos a la obra para probar por qué no hubo daño colateral (llámese bucle), aún sabiendo

que la magia del OSPF lo resuelve, tenía que verlo por mis propios ojos.

Para eso armé una adyacencia OSPF entre dos routers conectados por un HUB y así poder capturar los paquetes

OSPF y ver como se anunciaba la ruta redistribuida (red, máscara, next-hop).

 

1.- Escenario original:

 

 

Inicialmente apunté a algún mecanismo del ASA ya que estaba involucrada una VPN con unos NATs para enmascarar

el tráfico interesante en el túnel, y también interviniendo la ruta por defecto, en la web de Cisco encontré lo siguiente:

 

How Routing Behaves Within the ASA Security Appliance

 

The ASA security appliance uses both routing table and XLATE tables for routing decisions. To handle destination IP translated

traffic, that is, untranslated traffic, ASA searches for existing XLATE, or static translation to select the egress interface.

The selection process is as follows:

 

Egress Interface Selection Process

 

1.    If destination IP translating XLATE already exists, the egress interface for the packet is determined from the XLATE table,

but not from the routing table. (era mi teoría más sólida, pero luego entendí que usaba el NAT a pesar de estar la

ruta en la tabla, en este caso la ruta ni estaba instalada en la tabla)

2.    If destination IP translating XLATE does not exist, but a matching static translation exists, then the egress interface is determined

 

3.    from the static route and an XLATE is created, and the routing table is not used.

 

3. If destination IP translating XLATE does not exist and no matching static translation exists, the packet is not destination IP translated.

The appliance processes this packet by looking up the route to select egress interface, then source IP translation is performed (if necessary).

 

For regular dynamic outbound NAT, initial outgoing packets are routed using the route table and then creating the XLATE.

Incoming return packets are forwarded using existing XLATE only. For static NAT, destination translated incoming packets are always

forwarded using existing XLATE or static translation rules.

 

Fuente: https://www.cisco.com/c/en/us/td/docs/security/asa/asa72/configuration/guide/conf_gd/ip.html

 

Luego de buscar por el lado complejo, salieron las dudas por el lado fácil: si la ruta estática tiene como next-hop él mismo,

debería descartarse, pero como acá teníamos la redistribución, había que “ver para creer” como era la inyección de la ruta

en el OSPF, para ello recurrí a un escenario más simple, bien de sábado a la mañana.

 

2.- Pruebas en un escenario más simple:

 

Tal como se mencionó antes, se creó una adyacencia OSPF entre dos routers conectados por un HUB y así poder capturar

los paquetes OSPF y ver como se anunciaba la ruta redistribuida.

Para las capturas usé un HUB por motivos de simplicidad (era sábado a la mañana y tenía cosas que hacer).

 

 

Cisco1841(config)#int fa0/0

Cisco1841(config-if)#ip add 192.168.0.2 255.255.255.0

Cisco1841(config-if)#exit

Cisco1841(config)#router ospf 1

Cisco1841(config-router)#network 192.168.0.0 0.0.0.255 area 0

Cisco1841(config-router)#redistribute static

% Only classful networks will be redistributed

Cisco1841(config-router)#end

Cisco1841#

 

2.1.- Verificamos adyacencia OSPF:

 

Cisco1841#sh ip ospf nei

 

Neighbor ID     Pri   State           Dead Time      Address         Interface

192.168.0.3     1   FULL/BDR        00:00:32    192.168.0.3     FastEthernet0/0

Cisco1841#

 

[admin@MikroTik] > routing ospf nei print

 0 instance=default router-id=192.168.0.2 address=192.168.0.2 interface=ether5

   priority=1 dr-address=192.168.0.2 backup-dr-address=192.168.0.3 state="Full"

   state-changes=5 ls-retransmits=0 ls-requests=0 db-summaries=0

   adjacency=2m26s

[admin@MikroTik] >

 

2.2.- Implementamos una ruta estática:

 

Esto lo dejamos como otro paso para disparar un update con la redistribución y poder capturar el tráfico.

 

Cisco1841#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

Cisco1841(config)#ip route 192.168.1.0 255.255.255.0 192.168.0.3

Cisco1841(config)#

 

2.3.- Verificamos:

 

Cisco1841#sh ip route

Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP

       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area

       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

       E1 - OSPF external type 1, E2 - OSPF external type 2

       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2

       ia - IS-IS inter area, * - candidate default, U - per-user static route

       o - ODR, P - periodic downloaded static route

 

Gateway of last resort is not set

 

C    192.168.0.0/24 is directly connected, FastEthernet0/0

S    192.168.1.0/24 [1/0] via 192.168.0.3

Cisco1841#

 

2.4.- Verificamos en el vecino:

 

Podemos notar que no está la ruta redistribuida, queda confirmar analizando el tráfico OSPF capturado.

Con esto descartamos que en el escenario original la ruta sea omitida por mecanismos de VPN o NATs.

 

[admin@MikroTik] > ip route print       

Flags: X - disabled, A - active, D - dynamic,

C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,

B - blackhole, U - unreachable, P - prohibit

 #            DST-ADDRESS        PREF-SRC        GATEWAY            DISTANCE

 0 ADC  192.168.0.0/24           192.168.0.3          ether5                    0

[admin@MikroTik] >

 

2.5.- Verificamos en las capturas Wireshark:

 

 

Frame 3: 98 bytes on wire (784 bits), 98 bytes captured (784 bits) on interface id 0

Ethernet II, Src: 00:17:95:c0:ac:a2, Dst: 01:00:5e:00:00:05

Internet Protocol Version 4, Src: 192.168.0.2, Dst: 224.0.0.5

Open Shortest Path First

    OSPF Header

    LS Update Packet

        Number of LSAs: 1

        LSA-type 5 (AS-External-LSA (ASBR)), len 36

            .000 0000 0000 0001 = LS Age (seconds): 1

            0... .... .... .... = Do Not Age Flag: 0

            Options: 0x20, (DC) Demand Circuits

            LS Type: AS-External-LSA (ASBR) (5)

            Link State ID: 192.168.1.0

            Advertising Router: 192.168.0.2

            Sequence Number: 0x80000001

            Checksum: 0x6df0

            Length: 36

            Netmask: 255.255.255.0

            1... .... = External Type: Type 2 (metric is larger than any other link state path)

            .000 0000 = TOS: 0

            Metric: 20

            Forwarding Address: 192.168.0.3 (el mismo router que recibe la redistribución)

            External Route Tag: 0

 

2.6.- Pruebas utilizando un gateway diferente:

 

 

Con esto realizamos una contraprueba utilizando un hipotético gateway diferente, lo cual no dispararía

un loop de enrutamiento y la ruta debería instalarse en la tabla.

 

2.6.1.- Cambiamos la ruta:

 

Cisco1841#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

Cisco1841(config)#no ip route 192.168.1.0 255.255.255.0 192.168.0.3

Cisco1841(config)#ip route 192.168.1.0 255.255.255.0 192.168.0.1

Cisco1841(config)#

 

2.6.2.- Verificamos en las capturas Wireshark:

 

 

Frame 3: 98 bytes on wire (784 bits), 98 bytes captured (784 bits) on interface id 0

Ethernet II, Src: 00:17:95:c0:ac:a2, Dst: 01:00:5e:00:00:05

Internet Protocol Version 4, Src: 192.168.0.2, Dst: 224.0.0.5

Open Shortest Path First

    OSPF Header

    LS Update Packet

        Number of LSAs: 1

        LSA-type 5 (AS-External-LSA (ASBR)), len 36

            .000 0000 0000 0001 = LS Age (seconds): 1

            0... .... .... .... = Do Not Age Flag: 0

            Options: 0x20, (DC) Demand Circuits

            LS Type: AS-External-LSA (ASBR) (5)

            Link State ID: 192.168.1.0

            Advertising Router: 192.168.0.2

            Sequence Number: 0x80000001

            Checksum: 0x510f

            Length: 36

            Netmask: 255.255.255.0

            1... .... = External Type: Type 2 (metric is larger than any other link state path)

            .000 0000 = TOS: 0

            Metric: 20

            Forwarding Address: 192.168.0.1

            External Route Tag: 0

 

2.6.3.- Verificamos:

 

[admin@MikroTik] > ip route print

Flags: X - disabled, A - active, D - dynamic,

C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,

B - blackhole, U - unreachable, P - prohibit

 #      DST-ADDRESS        PREF-SRC        GATEWAY            DISTANCE

 0 ADC  192.168.0.0/24     192.168.0.3        ether5                    0

 1 ADo  192.168.1.0/24                                192.168.0.1           110 (notar que Mikrotik en esta tabla no detalla que es OE2)

[admin@MikroTik] >

 

3.- Resumen:

 

Aunque sabemos que OSPF es un protocolo de enrutamiento que intenta evitar bucles, en este escenario también intervienen

rutas estáticas (que bien configuradas o mal configuradas) pueden disparar un posible bucle.

La finalidad de este lab era disipar la duda de cual era el factor que lo había evitado: en la redistribución de la ruta por OSPF se

detalla el next-hop de la misma, el vecino OSPF al recibir dicho update evalúa que el mismo es el next-hop y descarta la misma.

 

En el escenario original más complejo, el destino se alcanza descartando esta ruta y utilizando la ruta por defecto, lo cual dispara

mecanismos de IPSec utilizando crypto-maps y la ACL asociada a él.

 

 

 

(2021) Redistribution may cause white nights

Rosario, Argentina