Skip to content

🛣️ Pure clojure/instaparse iproute2 output parser

License

Notifications You must be signed in to change notification settings

lunatic-cat/iproute

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

iproute

Build Status Clojars Project

A library to parse output of iproute2 using EBNF grammar

Usage

;; ip rule / ip route list table all
(def samples "10.8.0.32 dev tun11  proto kernel  scope link  src 10.8.0.31
  169.254.0.0/16 dev eth0  proto kernel  scope link  src 169.254.70.142
  fe80::/64 dev eth1  proto kernel  metric 256  mtu 1500 advmss 1440 hoplimit 0
  127.0.0.0/8 dev lo  scope link")
  
(iproute.route/parse samples)

[{:net {:ip "10.8.0.32"}, :dev "tun11", :proto "kernel", :scope "link", :src "10.8.0.31"}
{:net {:ip "169.254.0.0", :mask "16"}, :dev "eth0", :proto "kernel", :scope "link", :src "169.254.70.142"}
{:net {:ip "fe80::", :mask "64"}, :dev "eth1", :proto "kernel", :metric 256, :mtu 1500, :advmss 1440, :hoplimit 0}
{:net {:ip "127.0.0.0", :mask "8"}, :dev "lo", :scope "link"}]


;; ip route get 192.168.0.101
(def sample-route-get
  "192.168.0.101 via 10.80.255.126 dev ppp0  src 5.166.84.64
    cache  mtu 1492 advmss 1452 hoplimit 64")

(iproute.route/parse sample-route-get)

[{:net {:ip "192.168.0.101"}, :via "10.80.255.126", :dev "ppp0", :src "5.166.84.64", :cache true, :mtu 1492, :advmss 1452, :hoplimit 64}]


;; ip rule
(def rule-samples "0:	from all lookup local
  10097:	from all to 8.8.8.8 lookup ovpnc1
  10098:	from all to 1.1.1.1 lookup ovpnc1
  10099:	from all to 192.168.0.1/24 lookup ovpnc1
  32766:	from all lookup main
  32767:	from all lookup default")

(iproute.rule/parse rule-samples)

[{:pref 0, :from "all", :lookup "local"}
{:pref 10097, :from "all", :to {:ip "8.8.8.8"}, :lookup "ovpnc1"}
{:pref 10098, :from "all", :to {:ip "1.1.1.1"}, :lookup "ovpnc1"}
{:pref 10099, :from "all", :to {:ip "192.168.0.1", :mask "24"}, :lookup "ovpnc1"}
{:pref 32766, :from "all", :lookup "main"}
{:pref 32767, :from "all", :lookup "default"}

REPL Development

Development runs only java-8 due rewrite-clj oddity

lein trampoline run -m rebel-readline.main
(require '[cljsh.repl :refer [save defnc defc]]) (use 'aprint.core) (use 'cljsh.namespaces) (use 'cljsh.deps) (use 'com.rpl.specter) (require 'cljsh.complement) (cljsh.complement/patch) (use 'cljsh.inspect) (require 'cljsh.utils) (require '[cljsh.source :refer [source-expand-ns]]) (require '[clojure.java.io :as io]) (use 'clojure.tools.trace)

Tests

(use 'eftest.runner)
(run-tests (find-tests "test"))

License

Copyright © 2018 Vlad Bokov

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

About

🛣️ Pure clojure/instaparse iproute2 output parser

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published