Auto Repair Passthrough In Mangle - MikroTik Script RouterOS

Script to solve passthrough errors in mikrotik mangle with many rules.

note: remember we understand the conditions of each mangle, because each setting will be different conditions, here I generally assume that all "mark-connection", "mark-routing" uses passthrough = yes and "mark-packet" uses passthrough = no

foreach mrk in=("packet","connection", "routing") do={
foreach i in=([/ip firewall mangle find where action=("mark-" . $mrk)]) do={
:if ($mrk = "packet") do={ 
local cmd ("ip firewall mangle set " . $i . " passthrough=no")
:execute $cmd
}
:if ($mrk = "connection") do={ 
local cmd ("ip firewall mangle set " . $i . " passthrough=yes")
:execute $cmd
}
:if ($mrk = "routing") do={ 
local cmd ("ip firewall mangle set " . $i . " passthrough=yes")
:execute $cmd
}
}
}
Credit: www.o-om.com