-
Notifications
You must be signed in to change notification settings - Fork 0
/
pppoe.fnl
38 lines (34 loc) · 1.34 KB
/
pppoe.fnl
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
(local netdev (require :netdev))
(local ppp (require :ppp))
(local process (require :process))
(local event (require :event))
(local inspect (require :inspect))
(fn f. [fmt ...]
(string.format fmt ...))
(fn nil? [x] (= x nil))
(fn pppoe-daemon [transport-device ppp-device]
(let [ppp-device-name (ppp.device-name ppp-device)
ipstate-script (ppp.ipstate-script ppp-device)
pppd (process.new-process
(f. "pppd %s --ip-up-script %s --ip-down-script %s "
(netdev.device-name transport-device)
ipstate-script
ipstate-script))]
(each [event (event.next-event transport-device pppd)]
(when (pppd:died?) (pppd:backoff))
(when (and (not pppd.running?)
(netdev.link-up? transport-device)
(pppd:backoff-expired?))
(process.join (process.new-process
(f. "ifconfig %s up"
(netdev.device-name transport-device))))
(pppd:start))
(when (and pppd.running?
(not (netdev.link-up? transport-device)))
(pppd:stop))
(when (ppp.up? ppp-device)
(pppd:aver-health))
)))
(lambda main [eth-device-name ppp-device-name]
(let [pppdev (ppp.find-device ppp-device-name)]
(pppoe-daemon (netdev.find-device eth-device-name) pppdev)))