wrong gateway for snmp responses

mikrotik.png
Hi!
I faced a problem I can not understand, so I need some help :slight_smile:
New router, mikrotik RB3011, BGP+OSPF, some vlans:
vlan_manage - 100.69.0.181/16
vlan_routing - 100.70.67.181/24 - OSPF backbone
vlan_bgp* - links to BGP PEERS (internal and confederation external)
Tried to add to mrtg system, invoke “cfgmaker 100.69.0.181” - no answer. Standard situation - UDP response is coming with different source IP than expected. Quick “tcpdump” approves assumption, but the source IP is not expected at all - it belongs to a router, which should be apart from the route. Some more investigation revealed the strange problem (take a look at the picture):
SNMP request path is X.Y.5.44 (mrtg host) → twp → tw4 (as expected)
SNMP answer is tw4 (source 100.69.0.181) → ras → mrtg host
Since ras (rb750) does NAT I was able to spot the strange reverse path - the answer came with source IP X.Y.5.49
All routing info seems OK:

[admin@tw4] > ip route print detail where X.Y.5.44 in dst-address
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
 0 ADb  dst-address=0.0.0.0/0 gateway=100.70.61.178 gateway-status=100.70.61.178 reachable via  vlan_bgp1 distance=200 scope=40 target-scope=30 bgp-local-pref=999 bgp-origin=igp         received-from=twp

 1  Db  dst-address=0.0.0.0/0 gateway=100.70.63.108 gateway-status=100.70.63.108 reachable via  vlan_bgp3_d2 distance=20 scope=40 target-scope=10 bgp-as-path="(65001)"         bgp-local-pref=100 bgp-origin=igp received-from=gate1

 2 ADo  dst-address=X.Y.0.0/19 gateway=100.70.67.178,100.70.67.180 gateway-status=100.70.67.178 reachable via  vlan_routing,100.70.67.180 reachable via  vlan_routing  distance=110 scope=20 target-scope=10 ospf-metric=10 ospf-type=external-type-2

 3 ADb  dst-address=X.Y.0.0/20 gateway=100.70.62.178 gateway-status=100.70.62.178 reachable via  vlan_bgp2 distance=200 scope=40 target-scope=30 bgp-as-path="(65001)" bgp-local-pref=400 bgp-med=0 bgp-origin=igp bgp-communities=0:10,ASN:40,ASN:ASN received-from=twp

 4 ADbU dst-address=X.Y.5.0/24 type=unreachable distance=20 bgp-origin=incomplete

 5  Db  dst-address=X.Y.5.0/24 gateway=100.70.62.178 gateway-status=100.70.62.178 reachable via  vlan_bgp2 distance=200 scope=40 target-scope=30 bgp-local-pref=100 bgp-med=0 bgp-origin=igp bgp-communities=ASN:100,ASN:ASN received-from=twp

 6 ADo  dst-address=X.Y.5.40/29 gateway=100.70.67.180 gateway-status=100.70.67.180 reachable via  vlan_routing distance=110 scope=20 target-scope=10 ospf-metric=10 ospf-type=external-type-2

 7 ADo  dst-address=X.Y.5.44/32 gateway=100.70.67.178 gateway-status=100.70.67.178 reachable via  vlan_routing distance=110 scope=20 target-scope=10 ospf-metric=10 ospf-type=external-type-2

A “quick sniffer” approves packets come via twp but go out via ras:
3C:4A:92:7C:3E:D5 - twp
E4:8D:8C:79:DC:0E - tw4
00:0C:42:EF:DB:43 - ras

[admin@tw4] > tool sniffer quick interface=ether2 port=161
INTERFACE                TIME    NUM DIR SRC-MAC           DST-MAC           VLAN   SRC-ADDRESS                         DST-ADDRESS                         PROTOCOL   SIZE CPU FP
ether2                  6.411      1 <-  3C:4A:92:7C:3E:D5 E4:8D:8C:79:DC:0E 3566   X.Y.5.44:46024                  100.69.0.181:161 (snmp)             ip:udp       87   1 no
ether2                  6.411      2 ->  E4:8D:8C:79:DC:0E 00:0C:42:EF:DB:43 3566   100.69.0.181:161 (snmp)             X.Y.5.44:46024                  ip:udp      109   0 no

The very strange is the fact EVERYTHING else follows the normal path:
ping to:

[admin@tw4] > tool sniffer quick interface=ether2 ip-protocol=icmp
INTERFACE                TIME    NUM DIR SRC-MAC           DST-MAC           VLAN   SRC-ADDRESS                         DST-ADDRESS                         PROTOCOL   SIZE CPU FP
ether2                 18.478      1 <-  3C:4A:92:7C:3E:D5 E4:8D:8C:79:DC:0E 3566   X.Y.5.44                        100.69.0.181                        ip:icmp     102   1 no
ether2                 18.478      2 ->  E4:8D:8C:79:DC:0E 3C:4A:92:7C:3E:D5 3567   100.69.0.181                        X.Y.5.44                        ip:icmp     102   0 no

ping from:

[admin@tw4] > tool sniffer quick interface=ether2 ip-protocol=icmp
INTERFACE                TIME    NUM DIR SRC-MAC           DST-MAC           VLAN   SRC-ADDRESS                         DST-ADDRESS                         PROTOCOL   SIZE CPU FP
ether2                 13.011      1 ->  E4:8D:8C:79:DC:0E 3C:4A:92:7C:3E:D5 3567   100.70.67.181                       X.Y.5.44                        ip:icmp      74   0 no
ether2                 13.011      2 <-  3C:4A:92:7C:3E:D5 E4:8D:8C:79:DC:0E 3567   X.Y.5.44                        100.70.67.181                       ip:icmp      74   0 no

traceroute:

[admin@tw4] > tool traceroute X.Y.5.44
 # ADDRESS                          LOSS SENT    LAST     AVG    BEST   WORST STD-DEV STATUS
 1 100.70.67.178                      0%   10   0.2ms     0.1     0.1     0.2       0
 2 X.Y.5.44                       0%   10   0.4ms     0.4     0.3     0.5     0.1

The only packets going via ras are the snmp responses, nothing else.
There is no policy routing (/ip route rule)
I can not imagine - WHY these packets are being sent to the “wrong” gateway?

P.S. I was wrong, snmp responses are not the only packets, I enabled the remote DNS requests and they go the same path, seems all UDP responses use this path. But only responses. When connection is initiated by tw4 it goes via twp.

mikrotik-simple.png
Hi again :slight_smile:
Some more info. I simplified configuration, and it became much clearer.
Router ras ignored - it has proxy-arp, and it was the reason to take part in the path traverse. Why - later.
I removed everything not needed - bgp, ospf, some vlans, some addresses. Here is the config:

[admin@MikroTik] > export 
# jan/02/1970 18:49:12 by RouterOS 6.36
# software id = hidden
#
/interface vlan
add interface=ether2 name=vlan_manage vlan-id=3566
add interface=ether2 name=vlan_routing vlan-id=3567
/snmp community
add addresses=0.0.0.0/0
/ip address
add address=100.70.67.181/24 interface=vlan_routing network=100.70.67.0
add address=100.69.0.181/16 interface=vlan_manage network=100.69.0.0
/ip route
add distance=1 dst-address=X.Y.5.44/32 gateway=100.70.67.178
/ip ssh
set always-allow-password-login=yes
/snmp
set contact=hidden enabled=yes location=hidden
/system routerboard settings
set protected-routerboot=disabled

SNMP response is being sent via vlan_manage, and the router is looking for X.Y.5.44 directly on interface, i.e. packets do not go through the gateway (tcpdump on twp):

# tcpdump -eni eth1 ether src or dst e4:8d:8c:79:dc:0e
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth1, link-type EN10MB (Ethernet), capture size 65535 bytes
19:03:12.587607 3c:4a:92:7c:3e:d5 > e4:8d:8c:79:dc:0e, ethertype 802.1Q (0x8100), length 87: vlan 3566, p 0, ethertype IPv4, X.Y.5.44.34578 > 100.69.0.181.161:  GetNextRequest(26)  .1.3.6.1.2.1.1
19:03:12.587852 e4:8d:8c:79:dc:0e > ff:ff:ff:ff:ff:ff, ethertype 802.1Q (0x8100), length 60: vlan 3566, p 0, ethertype ARP, Request who-has X.Y.5.44 tell 100.69.0.181, length 42
19:03:13.586478 e4:8d:8c:79:dc:0e > ff:ff:ff:ff:ff:ff, ethertype 802.1Q (0x8100), length 60: vlan 3566, p 0, ethertype ARP, Request who-has X.Y.5.44 tell 100.69.0.181, length 42
19:03:14.573540 3c:4a:92:7c:3e:d5 > e4:8d:8c:79:dc:0e, ethertype 802.1Q (0x8100), length 87: vlan 3566, p 0, ethertype IPv4, X.Y.5.44.34578 > 100.69.0.181.161:  GetNextRequest(26)  .1.3.6.1.2.1.1
19:03:14.586484 e4:8d:8c:79:dc:0e > ff:ff:ff:ff:ff:ff, ethertype 802.1Q (0x8100), length 60: vlan 3566, p 0, ethertype ARP, Request who-has X.Y.5.44 tell 100.69.0.181, length 42
19:03:16.550414 3c:4a:92:7c:3e:d5 > e4:8d:8c:79:dc:0e, ethertype 802.1Q (0x8100), length 87: vlan 3566, p 0, ethertype IPv4, X.Y.5.44.34578 > 100.69.0.181.161:  GetNextRequest(26)  .1.3.6.1.2.1.1
19:03:16.550613 e4:8d:8c:79:dc:0e > ff:ff:ff:ff:ff:ff, ethertype 802.1Q (0x8100), length 60: vlan 3566, p 0, ethertype ARP, Request who-has X.Y.5.44 tell 100.69.0.181, length 42
19:03:17.546474 e4:8d:8c:79:dc:0e > ff:ff:ff:ff:ff:ff, ethertype 802.1Q (0x8100), length 60: vlan 3566, p 0, ethertype ARP, Request who-has X.Y.5.44 tell 100.69.0.181, length 42
19:03:18.546479 e4:8d:8c:79:dc:0e > ff:ff:ff:ff:ff:ff, ethertype 802.1Q (0x8100), length 60: vlan 3566, p 0, ethertype ARP, Request who-has X.Y.5.44 tell 100.69.0.181, length 42
19:03:18.552625 3c:4a:92:7c:3e:d5 > e4:8d:8c:79:dc:0e, ethertype 802.1Q (0x8100), length 87: vlan 3566, p 0, ethertype IPv4, X.Y.5.44.34578 > 100.69.0.181.161:  GetNextRequest(26)  .1.3.6.1.2.1.1
19:03:20.554652 3c:4a:92:7c:3e:d5 > e4:8d:8c:79:dc:0e, ethertype 802.1Q (0x8100), length 87: vlan 3566, p 0, ethertype IPv4, X.Y.5.44.34578 > 100.69.0.181.161:  GetNextRequest(26)  .1.3.6.1.2.1.1
19:03:20.554857 e4:8d:8c:79:dc:0e > ff:ff:ff:ff:ff:ff, ethertype 802.1Q (0x8100), length 60: vlan 3566, p 0, ethertype ARP, Request who-has X.Y.5.44 tell 100.69.0.181, length 42
19:03:21.546488 e4:8d:8c:79:dc:0e > ff:ff:ff:ff:ff:ff, ethertype 802.1Q (0x8100), length 60: vlan 3566, p 0, ethertype ARP, Request who-has X.Y.5.44 tell 100.69.0.181, length 42
19:03:22.546507 e4:8d:8c:79:dc:0e > ff:ff:ff:ff:ff:ff, ethertype 802.1Q (0x8100), length 60: vlan 3566, p 0, ethertype ARP, Request who-has X.Y.5.44 tell 100.69.0.181, length 42

This was the reason packets to go via ras - it was responding to the above arp requests due to the proxy-arp setting.
If I change the gateway from 100.70.67.178 to 100.69.0.178, everything is OK:

19:13:00.882324 3c:4a:92:7c:3e:d5 > e4:8d:8c:79:dc:0e, ethertype 802.1Q (0x8100), length 89: vlan 3566, p 0, ethertype IPv4, X.Y.5.44.49418 > 100.69.0.181.161:  GetRequest(28)  .1.3.6.1.2.1.1.1.0
19:13:00.882574 e4:8d:8c:79:dc:0e > 3c:4a:92:7c:3e:d5, ethertype 802.1Q (0x8100), length 108: vlan 3566, p 0, ethertype IPv4, 100.69.0.181.161 > X.Y.5.44.49418:  GetResponse(47)  .1.3.6.1.2.1.1.1.0="RouterOS RB3011UiAS"

Ping is not affected (in both directions, from and to tw4):

# ping -c1 100.69.0.181
PING 100.69.0.181 (100.69.0.181) 56(84) bytes of data.
64 bytes from 100.69.0.181: icmp_req=1 ttl=63 time=0.442 ms

--- 100.69.0.181 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.442/0.442/0.442/0.000 ms

As you can see, the echo reply follows the routing table (vlan_routing):

19:37:17.838040 3c:4a:92:7c:3e:d5 > e4:8d:8c:79:dc:0e, ethertype 802.1Q (0x8100), length 102: vlan 3566, p 0, ethertype IPv4, X.Y.5.44 > 100.69.0.181: ICMP echo request, id 3805, seq 1, length 64
19:37:17.838146 e4:8d:8c:79:dc:0e > 3c:4a:92:7c:3e:d5, ethertype 802.1Q (0x8100), length 102: vlan 3567, p 0, ethertype IPv4, 100.69.0.181 > X.Y.5.44: ICMP echo reply, id 3805, seq 1, length 64

From tw4:

[admin@MikroTik] > ping X.Y.5.44 src-address=100.69.0.181 count=1
  SEQ HOST                                     SIZE TTL TIME  STATUS                                                                                                               
    0 X.Y.5.44                               56  63 0ms  
    sent=1 received=1 packet-loss=0% min-rtt=0ms avg-rtt=0ms max-rtt=0ms

The same with echo request:

19:41:20.834459 e4:8d:8c:79:dc:0e > 3c:4a:92:7c:3e:d5, ethertype 802.1Q (0x8100), length 74: vlan 3567, p 0, ethertype IPv4, 100.69.0.181 > X.Y.5.44: ICMP echo request, id 23044, seq 256, length 36
19:41:20.834797 3c:4a:92:7c:3e:d5 > e4:8d:8c:79:dc:0e, ethertype 802.1Q (0x8100), length 74: vlan 3566, p 0, ethertype IPv4, X.Y.5.44 > 100.69.0.181: ICMP echo reply, id 23044, seq 256, length 36

As seen, I upgraded to latest ROS, from today - no change.
There are tens or hundreds ways to solve this, but I do not need to solve the problem, I need to know why it appears.

P.S. I saw now I haven’t mentioned something - if request is sent to 100.70.67.181 the response is returned as expected. As if there is some policy routing. It was the reason to make the ping above with source 100.69.0.181.
P.P.S. Disabling route cache doesn’t help too.

I faced almost the same problem in another network, linux mail server. Since it is pure linux, I could inspect more deeply the problem - very simple configuration as it acts as a server, not as a router, the entire routing table was one connected route and the default gateway in main table, nothing unusual in all routing tables (in fact, only main+local), accept_redirects disabled, no vrf, and the IP, considered to be directly connected on the ethernet, was from another ISP. So, I draw conclusion it is not ROS related, but related to linux kernel.
P.S. On the linux mail server the problem disappeared after reboot :slight_smile: Shame on me for the solution, I was taken 20 years back in my professional experience, but… :slight_smile: