ff_olsrd_watchdog: delete existing tunnels 1761/head
authorpmelange <pmelange@users.noreply.github.com>
Mon, 23 Apr 2018 20:24:39 +0000 (22:24 +0200)
committerpmelange <isprotejesvalkata@gmail.com>
Wed, 25 Jul 2018 20:50:31 +0000 (22:50 +0200)
When OLSRd crashes, the old tunnels still exist.  This can lead to unexpected behaviour.
The tunnels to be removed start with "tnl_"

See freifunk-berlin/firmware#522

Signed-off-by: pmelange <isprotejesvalkata@gmail.com>
contrib/package/freifunk-common/files/usr/sbin/ff_olsr_watchdog

index 069f4c32179c53e3bf14232de908a7876203d846..8ac803d309c09d9e2d438c77b83757bc18e4d834 100755 (executable)
@@ -23,6 +23,15 @@ if fs.access("/var/run/olsrd.pid") or fs.access("/var/run/olsrd4.pid") then
 
                if not wdgtime or ( systime - wdgtime ) > ( intv * 2 ) then
                        os.execute("logger -t 'OLSR watchdog' 'Process died - restarting!'")
+                       local tnls = io.popen("ip tunnel show | cut -d : -f 1")
+                       while true do
+                               tnl = tnls:read("*line")
+                               if tnl == nil then break end
+                               if string.find(tnl, "tnl_") == 1 then
+                                       os.execute(string.format("logger -t 'OLSR watchdog' 'Deleting stale tunnel %s'", tnl))
+                                       os.execute(string.format("ip link del %s", tnl))
+                               end
+                       end
                        os.execute("/etc/init.d/olsrd restart")
                end
        end