make netlink socket private (closed over)
This commit is contained in:
parent
8943c1d652
commit
da00b8a3a5
@ -1,8 +1,5 @@
|
|||||||
(local nl (require :netlink))
|
(local nl (require :netlink))
|
||||||
(local view (. (require :fennel) :view))
|
(local view (. (require :fennel) :view))
|
||||||
(print (string.format "All known netlink groups: %s"
|
|
||||||
(table.concat (nl.groups) ", ")))
|
|
||||||
(local nls (nl.socket))
|
|
||||||
|
|
||||||
;; $ grep DEVTYPE /sys/class/net/*/uevent
|
;; $ grep DEVTYPE /sys/class/net/*/uevent
|
||||||
;; /sys/class/net/docker0/uevent:DEVTYPE=bridge
|
;; /sys/class/net/docker0/uevent:DEVTYPE=bridge
|
||||||
@ -57,13 +54,15 @@
|
|||||||
(tset event :quality (wlan-link-quality event.name)))
|
(tset event :quality (wlan-link-quality event.name)))
|
||||||
(when (= dtype "wwan")
|
(when (= dtype "wwan")
|
||||||
;; for wwan, need to determine how to get strength and carrier name
|
;; for wwan, need to determine how to get strength and carrier name
|
||||||
)))
|
true)
|
||||||
|
))
|
||||||
event)
|
event)
|
||||||
|
|
||||||
|
|
||||||
(fn netlunk []
|
(fn netlunk []
|
||||||
(let [links {}
|
(let [links {}
|
||||||
routes {}]
|
routes {}
|
||||||
|
sock (nl.socket)]
|
||||||
(fn handle-event [event]
|
(fn handle-event [event]
|
||||||
(match event
|
(match event
|
||||||
{:event :newlink}
|
{:event :newlink}
|
||||||
@ -77,20 +76,20 @@
|
|||||||
|
|
||||||
{} (print :unhandled event.event)
|
{} (print :unhandled event.event)
|
||||||
))
|
))
|
||||||
(each [_ event (ipairs (nls:query ))]
|
(each [_ event (ipairs (sock:query ))]
|
||||||
(handle-event event))
|
(handle-event event))
|
||||||
|
|
||||||
{
|
{
|
||||||
:refresh #(each [_ event (ipairs (nls:event))]
|
:refresh #(each [_ event (ipairs (sock:event))]
|
||||||
(handle-event event))
|
(handle-event event))
|
||||||
:fd (nls:fd)
|
:fd (sock:fd)
|
||||||
:uplink (fn [self]
|
:uplink (fn [self]
|
||||||
(let [defaultroute routes.default
|
(let [defaultroute routes.default
|
||||||
interface (and defaultroute
|
interface (and defaultroute
|
||||||
(. links defaultroute.index))]
|
(. links defaultroute.index))]
|
||||||
(and interface (= interface.running "yes")
|
(and interface (= interface.running "yes")
|
||||||
(get-network-info interface))))
|
(get-network-info interface))))
|
||||||
:wait #(nls:poll 1000)
|
:wait #(sock:poll 1000)
|
||||||
:interface (fn [self ifnum] (. links ifnum))
|
:interface (fn [self ifnum] (. links ifnum))
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
@ -104,9 +103,3 @@
|
|||||||
nil
|
nil
|
||||||
(print "no default route")
|
(print "no default route")
|
||||||
)))
|
)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;; default route is newroute event without dst
|
|
||||||
|
|
||||||
;; look for newlink event with :running "yes"
|
|
||||||
|
Loading…
Reference in New Issue
Block a user