Upgrading -> Wireguard bug?

Sorry if this is redundant, but I wanted to post a possible bug regarding wireguard tunnels:

Upgrading Routeros 7.13.4. to 7.14.1: working Wireguard tunnels (eg to NordVPN) fail to TX (no change in config). 0 bytes send/received, error # increasing.

Downgraded → same problem

Upgraded again → problem still there.

Then changed the private/public keys in the interface as well as in the peers to WRONG keys and applied. Then entered the correct keys again, applied and voila: everything is working again!

Seems like a bug to me….

Read the 7.14 thread… http://forum.mikrotik.com/t/v7-14-3-stable-is-released/174007/1 or do forum search for like issue…
http://forum.mikrotik.com/t/too-many-wireguard-logs-from-version-7-14beta3/172509/1

Lots of problems with wg and logging etc…


/system/logging/set 0 topics=info,!wireguard action=memory

I have encountered this bug many times. It has driven me nuts over and over. The linked thread looks like a different issue to me. I don’t have an issue with too many logs, but as described in licht77’s post. TX goes up but RX stays at zero and no connection. I remove the client endpoint, apply, add it back, apply and things start to work. I’ve encountered this at least 5 times and now 100% sure of the mechanism. It applies when both ends have a client endpoint specified. Before someone says that maybe it’s not meant to work with my config, then it has to be a bug when it starts working. In one way or the other it’s a bug. I am on 7.20.1

mike kulls, its a nice story, but without evidence aka the config, its fiction :slight_smile:

/export file=anynameyouwish ( minus router serial number, any public WANIP information, keys, dhcp lease lists).

Here it is. It’s quite basic. I am sure I have seen this many times. WG won’t connect. Delete an endpoint, add it back and suddenly it starts working.

/interface ethernet
set [ find default-name=ether1 ] disable-running-check=no
/interface wireguard
add listen-port=13233 mtu=1420 name=WG0
/ipv6 settings
set disable-ipv6=yes
/interface wireguard peers
add allowed-address=192.168.102.1/32,192.168.9.0/24 endpoint-address=x.x.x.x endpoint-port=13233 interface=WG0 name=Home public-key="xxxxxx"
/ip address
add address=192.168.102.2/24 interface=WG0 network=192.168.102.0
/ip dhcp-client
add default-route-tables=main interface=ether1
/ip firewall filter
add action=accept chain=input comment="Allow established" connection-state=established,related
add action=drop chain=input comment="Drop invalid" connection-state=invalid
add action=accept chain=input comment="Allow wireguard UDP connections" dst-port=13233 protocol=udp
add action=accept chain=input comment="Allow anything from home" src-address=x.x.x.x
add action=accept chain=input comment="Allow anything from wireguard connections" src-address=192.168.102.0/24
add action=accept chain=input comment="Allow ping" protocol=icmp
add action=drop chain=input comment="Drop everything else"
add action=accept chain=forward comment="Allow established" connection-state=established,related
add action=drop chain=forward comment="Drop invalid" connection-state=invalid
add action=accept chain=forward comment="Allow anything from home" src-address=192.168.9.0/24
add action=accept chain=forward comment="Allow anything from wireguard connections" src-address=192.168.102.0/24
add action=drop chain=forward comment="Drop everything else"
/ip firewall nat
add action=src-nat chain=srcnat out-interface=ether1 to-addresses=x.x.x.x
/ip route
add disabled=no distance=1 dst-address=192.168.9.0/24 gateway=WG0 routing-table=main scope=30 suppress-hw-offload=no target-scope=10
/system identity
set name=Australia
/system ntp client
set enabled=yes
/system ntp client servers
add address=au.pool.ntp.org

Do both ends have public IP addresses or is any of the two peers behind NAT/CGNAT? When the tunnel is running and also when it's not running, can you compare the values of Endpoint and Endpoint Port, with the values in the read-only fields Current Endpoint Address and Current Endpoint Port below them? Are there any mismatch?

If one side is behind NAT or CGNAT, that side should turn on Persistent Keepalive (set to 25s for example).

1.Why do you have this rule?
add action=accept chain=input comment="Allow wireguard UDP connections" dst-port=13233 protocol=udp

Clearly the router is client peer for handshake and therefore not expecting an incoming connection to be originated at the other end hitting this router.

  1. Allowed Addresses needs slight modification.. TO
    /interface wireguard peers
    add allowed-address=192.168.102.0/24,192.168.9.0/24 endpoint-address=x.x.x.x endpoint-port=13233 interface=WG0 name=Home public-key="xxxxxx" persistent-keep-alive=30

They are both on fixed public IPs with no NAT. For testing I did have keep alive turned on but turned it off once running.

Just left over from trying different stuff. With both ends being fixed public IPs either end could initiate the connection. My understanding of wireguard is there is no persistent connection, so if I turn off keep alive then either end could send packets. I quite often make rules like that when setting stuff up “just in case” and then delete them if the byte count is zero.

I recently had a similar bug, in 7.19.4 :

→ Created a peer

→ Realised that the associated interface was not the correct one

→ Changed the “Interface” attribute of the peer

→ Everything is displayed correctly… but does not connect

→ Recreate the peer, with the exact same configuration, it works !

Similar things could happen if the “endpoint-address” goes from IPv4 to IPv6, you have to recreate the peer, or reboot but it doesn’t always work.

I didn’t try in 7.20 / 7.21, maybe this behavior is resolved,

Obviously RouterOS is not bug free, but in my experience, these things could always be traced to two non-trivial (but not bug) causes:

  • Wireguard equips handshakes with timestamps. In order to prevent replays, these have to be monotonic. Timestamps going back in time lead to failed handshakes. Disabling and enabling (or removing/readding) the peer resets the stored value.
  • Wireguard is often NAT-ed. With the relatively fast handshake retries, a nat entry that should be updated isn't allowed to expire. Changing the interface port or disabling the peer for long enough to let the conntrack entry expire fixes this.

Of course if you have a reproducible bug, preferably without nat and with monotonic clocks, let MT know.

macbookpro yesterday, not used, fired it up, nothing worked, till I manually changed the date time from feb 2023 LOL

I've seen cases like that were I couldn't even get a DHCP lease from some Cisco router until I changed the clock to something close enough.

I think I may have tracked down the issue. I have 3 MT routers like this

Source router 192.168.10.1 (Main LAN) → 10.8.8.2 (VLAN98 for WAN to SXT)
Default route to 10.8.8.1 (no NAT)

SXT 10.8.8.1 (VLAN98) NATted to LTE1

Destination router with fixed public IP

I had a firewall rule in the SXT to forward 192.168.0.0/16 to internet to cover myself for any LANs I might create (this is all testing at the moment). However the interesting thing was the packets for the wireguard connection didn’t have a source IP of 192.168.10.x as I expected. MT set the source as 10.8.8.2, skipping 1 hop. One of those things that makes sense once you know. But here is the interesting thing, I have 2 WG connections setup and one of them was working. That was really baffling me. So this is what I think happened. I setup 1 WG connection, got it working. I added the firewall rule because the SXT initially had no rules at all. Then I setup the second WG connection. Maybe connection tracking was holding a connection open? I rebooted both routers but never the SXT. @lurker888 is that what you’re talking about above with NAT?