From f52aea2430e31d39c6b454d3387bae8cb62fa02d Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Mon, 16 Jun 2014 15:15:55 +0300 Subject: [PATCH] Dnsmasq: add structure to 'address' and 'server' options This is a backwards incompatible change. --- lenses/dnsmasq.aug | 34 ++++++++++++++++++++++--------- lenses/tests/test_dnsmasq.aug | 47 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 9 deletions(-) diff --git a/lenses/dnsmasq.aug b/lenses/dnsmasq.aug index e19aab8..78ae23a 100644 --- a/lenses/dnsmasq.aug +++ b/lenses/dnsmasq.aug @@ -17,26 +17,42 @@ module Dnsmasq = * USEFUL PRIMITIVES *************************************************************************) -let eol = Util.eol -let spc = Util.del_ws_spc -let comment = Util.comment -let empty = Util.empty +let eol = Util.eol +let spc = Util.del_ws_spc +let comment = Util.comment +let empty = Util.empty -let sep_eq = del /=/ "=" -let sto_to_eol = store /([^ \t\n].*[^ \t\n]|[^ \t\n])/ +let sep_eq = Sep.equal +let sto_to_eol = store /([^ \t\n].*[^ \t\n]|[^ \t\n])/ + +let slash = Util.del_str "/" +let sto_no_slash = store /([^\/ \t\n]+)/ +let domains = slash . [ label "domain" . sto_no_slash . slash ]+ (************************************************************************ - * ENTRIES + * SIMPLE ENTRIES *************************************************************************) -let entry_re = /[A-Za-z0-9._-]+/ +let entry_re = Rx.word - /(address|server)/ let entry = [ key entry_re . (sep_eq . sto_to_eol)? . eol ] (************************************************************************ + * STRUCTURED ENTRIES + *************************************************************************) + +let address = [ key "address" . sep_eq . domains . sto_no_slash . eol ] + +let server = + let port = [ Build.xchgs "#" "port" . store Rx.integer ]? + in let source = [ Build.xchgs "@" "source" . store /[^#\/ \t\n]+/ . port ]? + in let srv_spec = ( store /(#|([^#@\/ \t\n]+))/ . port . source )? + in [ key "server" . sep_eq . domains? . srv_spec . eol ] + +(************************************************************************ * LENS *************************************************************************) -let lns = (comment|empty|entry) * +let lns = (comment|empty|address|server|entry) * let filter = incl "/etc/dnsmasq.conf" . incl "/etc/dnsmasq.d/*" diff --git a/lenses/tests/test_dnsmasq.aug b/lenses/tests/test_dnsmasq.aug index 0abfa6b..c6a63d9 100644 --- a/lenses/tests/test_dnsmasq.aug +++ b/lenses/tests/test_dnsmasq.aug @@ -6,6 +6,16 @@ let conf = "# Configuration file for dnsmasq. conf-dir=/etc/dnsmasq.d selfmx + +address=/foo.com/bar.net/10.1.2.3 + +server=10.4.5.6#1234 +server=/bar.com/foo.net/10.7.8.9 +server=/foo.org/bar.org/10.3.2.1@eth0#5678 +server=/baz.org/# +server=/baz.net/#@eth1 +server=10.6.5.4#1234@eth0#5678 +server=/qux.com/qux.net/ " test Dnsmasq.lns get conf = @@ -15,3 +25,40 @@ test Dnsmasq.lns get conf = {} { "conf-dir" = "/etc/dnsmasq.d" } { "selfmx" } + {} + { "address" = "10.1.2.3" + { "domain" = "foo.com" } + { "domain" = "bar.net" } + } + {} + { "server" = "10.4.5.6" + { "port" = "1234" } + } + { "server" = "10.7.8.9" + { "domain" = "bar.com" } + { "domain" = "foo.net" } + } + { "server" = "10.3.2.1" + { "domain" = "foo.org" } + { "domain" = "bar.org" } + { "source" = "eth0" + { "port" = "5678" } + } + } + { "server" = "#" + { "domain" = "baz.org" } + } + { "server" = "#" + { "domain" = "baz.net" } + { "source" = "eth1" } + } + { "server" = "10.6.5.4" + { "port" = "1234" } + { "source" = "eth0" + { "port" = "5678" } + } + } + { "server" + { "domain" = "qux.com" } + { "domain" = "qux.net" } + } -- 1.8.3.1