-
Notifications
You must be signed in to change notification settings - Fork 1
/
pm.lua
130 lines (113 loc) · 3.79 KB
/
pm.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env lua
-- -*-lua-*-
--
-- $Id: pm.lua $
--
-- Author: Markus Stenberg <[email protected]>
--
-- Copyright (c) 2012 cisco Systems, Inc.
--
-- Created: Thu Oct 4 19:38:48 2012 mstenber
-- Last modified: Mon Oct 28 14:03:58 2013 mstenber
-- Edit time: 47 min
--
-- 'prefix manager' (name still temporary)
--
-- it is responsible for keeping the skv state and system state in
-- sync, by listening to skv change notifications, and attempting to
-- make the local state reflect skv state
-- (add/remove interface IPv6 addresses, and possibly rewrite
-- radvd.conf/dhcp/... configurations and kick them in the head etc
-- later on)
require 'mst'
require 'mst_cliargs'
require 'pm_core'
require 'skv'
require 'ssloop'
require 'skvtool_core'
-- how often we run stuff that is bound to run every 'tick'? (these
-- may involve e.g. shell commands to check system state, so it should
-- not be too short)
DEFAULT_TICK_INTERVAL=10
local loop = ssloop.loop()
_TEST = false
local args = mst_cliargs.parse{
options={
{name='fakedhcpv6d',
desc="use fakedhcpv6d to respond to DHCPv6 queries",
flag=1},
{name='dnsmasq', alias='m',
desc="use dnsmasq instead of ISC dhcpd + radvd",
flag=1},
{alias='h', name='use_hp_ospf',
desc='use hybrid DNS proxy instead of dnsmasq for DNS (requires --dnsmasq to be present too)',
flag=1},
{name=pa.CONFIG_DISABLE_ULA,
desc='disable ULA generation altogether',
flag=1},
{name=pa.CONFIG_DISABLE_ALWAYS_ULA,
desc='disable ULAs if global addresses present',
flag=1},
{name=pa.CONFIG_DISABLE_IPV4,
desc='disable generation of NATted IPv4 sub-prefixes',
flag=1},
{name='openwrt',
desc='use netifd to interface with the system, and assume we get client info somehow',
flag=1},
{name='debug',
value='file',
desc='enable debugging (to stdout if value 1, otherwise to given file)'
},
{value='skv',
desc='SKV values to set (key=value style)',
max=10},
}
}
-- handle debugging
if args.debug then mst.set_enable_debug(args.debug) end
mst.d('initializing skv')
local s = skv.skv:new{long_lived=true}
if args.skv
then
-- handle setting of key=values as appropriate
skvtool_core.stc:new{skv=s, disable_wait=true}:process_keys(args.skv)
end
-- set up the pa configuration
local config = {}
for _, k in ipairs(pa.CONFIGS)
do
if args[k]
then
config[k] = args[k]
end
end
-- pa_config means that prefix assignment should even run; without it,
-- nothing happens. so we have to send it, even if it's empty (this is
-- meaningful only on very constrained machines).
s:set(elsa_pa.PA_CONFIG_SKV_KEY, config)
mst.d('initializing pm')
local pm = pm_core.pm:new{shell=mst.execute_to_string, skv=s,
config={radvd='radvd -m logfile',
use_dnsmasq=args.dnsmasq,
use_fakedhcpv6d=args.fakedhcpv6d,
use_hp_ospf=args.use_hp_ospf,
openwrt=args.openwrt,
},
}
function pm:schedule_run()
local t
t = loop:new_timeout_delta(0,
function ()
-- call run
pm:run()
-- get rid of the timeout
t:done()
end):start()
end
ssloop.repeat_every_timedelta(DEFAULT_TICK_INTERVAL,
function ()
-- call tick
pm:tick()
end)
mst.d('entering event loop')
loop:loop()