diff --git a/multiple-v6-watchdoog/luasrc/usr/sbin/multiple-v6-watchdoog b/multiple-v6-watchdoog/luasrc/usr/sbin/multiple-v6-watchdoog new file mode 100755 index 0000000000000000000000000000000000000000..4d56d12872402f887acd5480fcc7e0918a3d1528 --- /dev/null +++ b/multiple-v6-watchdoog/luasrc/usr/sbin/multiple-v6-watchdoog @@ -0,0 +1,52 @@ +#!/usr/bin/lua +local pidPath="/var/run/multiple-v6-watchdoog.pid" + +if io.open(pidPath, "r") ~=nil then + io.stderr:write("The multiple-v6-watchdoog is still running.\n") + os.exit(1) +else + io.close(io.open(pidPath, "w")) +end + +local uci = require('luci.model.uci').cursor() +-- initialization done + +-- Program terminating function including removing of PID file +local function exit() + if io.open(pidPath, "r") ~=nil then + os.remove(pidPath) + end + os.exit(0) +end + +local function brclient_restart() + os.execute('ifconfig br-client down') + os.execute('ifconfig br-client up') + io.stderr:write('Interface br-client restarted.\n') +end + +local found_br_client = false +local puplicv6found = 0 +for ifout in io.popen(string.format("ifconfig 2> /dev/null"),'r'):lines() do + if string.find(ifout,"br%-client") then + found_br_client = true + end + if found_br_client then + if ifout == '' then + break + end + if string.find(ifout,"inet6 addr") then + local address = ifout:split(' ')[13] + local group1 = address:split(':')[1] + if (group1 ~= "fe80" and group1 ~= "fd74") then + if puplicv6found == 1 then + brclient_restart() + exit() + end + puplicv6found = 1 + end + end + end +end +io.stderr:write('Only one Puplic v6 address.\n') +exit()