Skip to content

Instantly share code, notes, and snippets.

@elico
Last active June 1, 2024 21:03
Show Gist options
  • Save elico/1e0e7d4c0de4f15eca05b1d0a5fb8261 to your computer and use it in GitHub Desktop.
Save elico/1e0e7d4c0de4f15eca05b1d0a5fb8261 to your computer and use it in GitHub Desktop.
Example of ppp profile on-up script for a pppoe-client interface
{
:do {
:log info ("ppp on-up script for interface id: " . $interface . " Started" );
:local interfaceName [/interface/get $interface name];
:log info ("ppp on-up script for interface name: " . $interfaceName . " Started" );
:local routingTable "WAN1";
:local routingTable "WAN2";
:local routingTable "LTE1";
:local routingTable "LTE2";
:set routingTable "WAN2";
:local routingTableCount [/routing/table/print count-only where name="$routingTable"];
:if ($routingTableCount = 0) do={
/routing/table/add name="$routingTable" fib;
}
:local count [/ip/route/print count-only where comment="$routingTable" and routing-table=$routingTable];
:log info ("ppp on-up script for interface: " . $interfaceName . " step 1" );
:if ($count = 0) do={
:log info ("ppp on-up script for interface: " . $interfaceName . " step 2" );
/ip/route/add dst-address=0.0.0.0/0 gateway=$interfaceName comment="$routingTable" routing-table=$routingTable;
} else={
:log info ("ppp on-up script for interface: " . $interfaceName . " step 3" );
:if ($count = 1) do={
:local test [/ip/route/find where comment="$routingTable" and routing-table="$routingTable" and dst-address=0.0.0.0/0 ];
:if ([/ip/route/get $test gateway] != "$interfaceName") do={
/ip/route/set $test gateway=$interfaceName;
} else={
:log info "Multiple routes found for $routingTable";
}
}
}
:log info ("ppp on-up script for interface: " . $interfaceName . " finished Succesfuly" );
} on-error={
:log info ("ppp on-up script for interface: " . $interfaceName . " had an error" );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment