From 6ea5fa6d97e249c40b6bea379598536672e9605a Mon Sep 17 00:00:00 2001 From: Jan-Tarek Butt <tarek@ring0.de> Date: Tue, 10 Jan 2017 13:36:20 +0100 Subject: [PATCH] multiple-v6-watchdoog: move multiple-v6-watchdoog to luasrc/usr/sbin --- .../luasrc/usr/sbin/multiple-v6-watchdoog | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 multiple-v6-watchdoog/luasrc/usr/sbin/multiple-v6-watchdoog 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 0000000..4d56d12 --- /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() -- GitLab