This shows you the differences between two versions of the page.
| — | sdk:set-default-route-based-on-current-ssid [2014/11/26 16:26] (current) – created - external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Set fake default route dynamically based on SSID ====== | ||
| + | This script checks every 5 seconds which interface should be used as default gateway. As the default gateway is managed by the link-manager, | ||
| + | Conditions could be any, here it depend on which WLAN SSID the router is connected. | ||
| + | <code c set-route.are> | ||
| + | /* DESC: set route to server depending on active WWAN / WLAN network | ||
| + | * Copyright (C) 2014 NetModule AG | ||
| + | * | ||
| + | */ | ||
| + | |||
| + | nb_syslog(" | ||
| + | |||
| + | void restartIPsec(){ | ||
| + | nb_config_set(" | ||
| + | sleep(6); // lower valus result in disabled ipsec admin status | ||
| + | nb_config_set(" | ||
| + | } | ||
| + | void addRoute(int id, string interface, string destination, | ||
| + | route = strcat(" | ||
| + | route = strcat(route, | ||
| + | route = strcat(route, | ||
| + | route = strcat(route, | ||
| + | route = strcat(route, | ||
| + | nb_config_set(route); | ||
| + | } | ||
| + | |||
| + | lastWanInterface = ""; | ||
| + | while (1) { | ||
| + | wanInterface = ""; | ||
| + | status = nb_status(" | ||
| + | wwan_status = status.WANLINK1_STATE; | ||
| + | wlan_status = status.WANLINK2_STATE; | ||
| + | wlan_network = status.WANLINK2_NETWORK; | ||
| + | SERVER = nb_config_get(" | ||
| + | nb_syslog(" | ||
| + | nb_syslog(" | ||
| + | nb_syslog(" | ||
| + | |||
| + | if (wlan_status == " | ||
| + | // take wlan link for IPsec | ||
| + | wanInterface = " | ||
| + | } else if (wwan_status == " | ||
| + | // take mobile link for IPsec | ||
| + | wanInterface = " | ||
| + | } | ||
| + | if (wanInterface != "" | ||
| + | if (wanInterface == " | ||
| + | addRoute(0, wanInterface, | ||
| + | addRoute(1, wanInterface, | ||
| + | addRoute(2, wanInterface, | ||
| + | nb_syslog(" | ||
| + | } else if (wanInterface == " | ||
| + | addRoute(0, wanInterface, | ||
| + | addRoute(1, wanInterface, | ||
| + | addRoute(2, wanInterface, | ||
| + | nb_syslog(" | ||
| + | } | ||
| + | restartIPsec(); | ||
| + | lastWanInterface = wanInterface; | ||
| + | } | ||
| + | sleep(5); | ||
| + | } | ||
| + | nb_syslog(" | ||
| + | exit(0); | ||
| + | </ | ||