Interface status script (Scripting noob)

Hi guys

I have policy based routing that routes all my DNS and HTTP(S) traffic via a pppoe interface. Some times this (ADSL) pppoe connection goes down and when it does I need to disable the default route with the routing mark for those packets.

My problem is I do not know how to read the interface status. I can write the script here, the way I think it should work, if someone can just help me by pointing me in the right direction regarding the interface status.

Here is my idea: (my syntax will be completely off)

:global ppp_int [/find interface name "pppoe-to-my-isp]

if( $ppp_int status != “connected” )
{
/ip route disable [/ip route find comment name=“route-via-some-gateway”]
}
else if( ( /ip route disable [/ip route find comment name=“route-via-some-gateway”] == disabled) and ($ppp_int status == “connected”) )
{
/ip route find comment name=“route-via-some-gateway” enable
}

I hope from the example above you guys can help me a bit.

Thanks in advance

use “gateway=pppoe-out1”, not “gateway=ip-address” - the route will be disabled automatically

Hi Chupaka

That is how it is setup at the moment.

Can I show you what I got?

Here are my mangle rules:

8 X chain=prerouting action=mark-routing new-routing-mark=route-via-adsl passthrough=no protocol=udp in-interface=Ethernet2 dst-port=53

9 X chain=prerouting action=mark-routing new-routing-mark=route-via-adsl passthrough=no protocol=tcp dst-address-list=!bypass-http-routes in-interface=Ethernet2 dst-port=80

And here is my default route for it (the pppoe does not get the default route added when it connects)
For some reason in console the /ip route print command does not show the packet mark, but it is there.

DST-ADDRESS PREF-SRC GATEWAY DISTANCE

2 S 0.0.0.0/0 pppoe-to-mweb 1

And then I have a lookup rule for that route

/ip route rule print

3 routing-mark=route-via-adsl action=lookup table=route-via-adsl

But still, if the ADSL fails, http and dns strill try to route via that link.

well… what version do you use? do you actually need that routing rule?.. it’s behaviour by default…

p.s. /ip route print detail

Well, if I change my mangle rules to:

Where in interface !pppoe-to-my-isp then it works. If the interface is down then the mangle rules become red.