add anoia.nl, a convenience wrapper on netlink
This commit is contained in:
parent
35909c9a23
commit
5184ff63f7
3 changed files with 40 additions and 22 deletions
15
pkgs/anoia/nl.fnl
Normal file
15
pkgs/anoia/nl.fnl
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
(local netlink (require :netlink))
|
||||||
|
|
||||||
|
(local { : view } (require :fennel))
|
||||||
|
|
||||||
|
(fn events [groups]
|
||||||
|
(let [sock (netlink.socket)]
|
||||||
|
(coroutine.wrap
|
||||||
|
(fn []
|
||||||
|
(each [_ e (ipairs (sock:query groups))]
|
||||||
|
(coroutine.yield e))
|
||||||
|
(while (sock:poll)
|
||||||
|
(each [_ e (ipairs (sock:event))]
|
||||||
|
(coroutine.yield e)))))))
|
||||||
|
|
||||||
|
{ : events }
|
7
pkgs/anoia/test-nl.fnl
Normal file
7
pkgs/anoia/test-nl.fnl
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
(local nl (require :anoia.nl))
|
||||||
|
(local { : view } (require :fennel))
|
||||||
|
|
||||||
|
(let [events (nl.events {:link true})]
|
||||||
|
(each [ev events]
|
||||||
|
(print "got one ")
|
||||||
|
(print (view ev))))
|
|
@ -1,5 +1,4 @@
|
||||||
(local netlink (require :netlink))
|
(local nl (require :anoia.nl))
|
||||||
(local sock (netlink.socket))
|
|
||||||
|
|
||||||
; (local { : view} (require :fennel))
|
; (local { : view} (require :fennel))
|
||||||
|
|
||||||
|
@ -22,31 +21,28 @@
|
||||||
(parse-args arg)
|
(parse-args arg)
|
||||||
(assert false (.. "Usage: " (. arg 0) " [-v] ifname [present|up|running]"))))
|
(assert false (.. "Usage: " (. arg 0) " [-v] ifname [present|up|running]"))))
|
||||||
|
|
||||||
(fn run-events [evs]
|
(fn run-event [v]
|
||||||
(each [_ v (ipairs evs)]
|
(let [got
|
||||||
(let [got
|
(match v
|
||||||
(match v
|
;; - up: Reflects the administrative state of the interface (IFF_UP)
|
||||||
;; - up: Reflects the administrative state of the interface (IFF_UP)
|
;; - running: Reflects the operational state (IFF_RUNNING).
|
||||||
;; - running: Reflects the operational state (IFF_RUNNING).
|
{:event "newlink" :name parameters.link :up :yes :running :yes}
|
||||||
{:event "newlink" :name parameters.link :up :yes :running :yes}
|
{:present true :up true :running true}
|
||||||
{:present true :up true :running true}
|
|
||||||
|
|
||||||
{:event "newlink" :name parameters.link :up :yes}
|
{:event "newlink" :name parameters.link :up :yes}
|
||||||
{:present :true :up true}
|
{:present :true :up true}
|
||||||
|
|
||||||
{:event "newlink" :name parameters.link}
|
{:event "newlink" :name parameters.link}
|
||||||
{:present true }
|
{:present true }
|
||||||
|
|
||||||
_
|
|
||||||
{})]
|
|
||||||
(when (. got parameters.expecting)
|
|
||||||
(os.exit 0)))))
|
|
||||||
|
|
||||||
|
_
|
||||||
|
{})]
|
||||||
|
(when (. got parameters.expecting)
|
||||||
|
(os.exit 0))))
|
||||||
|
|
||||||
(when parameters.verbose
|
(when parameters.verbose
|
||||||
(print (.. (. arg 0) ": waiting for "
|
(print (.. (. arg 0) ": waiting for "
|
||||||
parameters.link " to be " parameters.expecting)))
|
parameters.link " to be " parameters.expecting)))
|
||||||
|
|
||||||
(run-events (sock:query {:link true}))
|
(each [event (nl.events {:link true})]
|
||||||
|
(run-event event))
|
||||||
(while (sock:poll) (run-events (sock:event)))
|
|
||||||
|
|
Loading…
Reference in a new issue