-
Notifications
You must be signed in to change notification settings - Fork 1
/
pm_netifd_bird6.lua
65 lines (56 loc) · 1.63 KB
/
pm_netifd_bird6.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env lua
-- -*-lua-*-
--
-- $Id: pm_netifd_bird6.lua $
--
-- Author: Markus Stenberg <markus [email protected]>
--
-- Copyright (c) 2013 cisco Systems, Inc.
--
-- Created: Wed Oct 9 16:40:25 2013 mstenber
-- Last modified: Thu Oct 10 15:04:32 2013 mstenber
-- Edit time: 10 min
--
-- We assume that we _don't_ really want to run bird6 on every
-- interface any more. Therefore, what we do here, is call a script
-- with the list of the interfaces that are currently _not_ external,
-- but _are_ configured hnet, whenever the list changes.
require 'pm_handler'
module(..., package.seeall)
BIRD6_SCRIPT='/usr/share/hnet/bird6_handler.sh'
local _parent = pm_handler.pm_handler_with_ni
pm_netifd_bird6 = _parent:new_subclass{class='pm_netifd_bird6',
script=BIRD6_SCRIPT}
function pm_netifd_bird6:get_ni_state()
local devices = mst.set:new()
self.ni:iterate_interfaces(function (ifo)
local dev = ifo.l3_device or ifo.device
devices:insert(dev)
end, false, true)
local a = devices:keys()
a:sort()
return a
end
function pm_netifd_bird6:ni_is_changed()
local st = self:get_ni_state()
self:d('run', st)
if mst.repr_equal(st, self.set_ni_state)
then
return
end
self.set_ni_state = st
return true
end
function pm_netifd_bird6:run()
if not self:ni_is_changed()
then
return
end
local st = self.set_ni_state
if st:count() > 0
then
self.shell(self.script .. ' start ' .. st:join(' '))
else
self.shell(self.script .. ' stop')
end
end