Add a zones compiler
This commit is contained in:
parent
463513c4c8
commit
2bee462997
2 changed files with 23 additions and 1 deletions
22
compile.ml
Normal file
22
compile.ml
Normal file
|
@ -0,0 +1,22 @@
|
|||
open Config
|
||||
|
||||
let rec deps_of_zone = function
|
||||
| ZoneIpv4 _ | ZoneIpv6 _ -> []
|
||||
| Zone z -> [z]
|
||||
| ZoneList l -> List.flatten (List.map deps_of_zone l)
|
||||
| ZoneExclude e -> deps_of_zone e
|
||||
|
||||
let deps_of_zones zone =
|
||||
List.map (fun (a, b) -> (a, deps_of_zone b)) zone
|
||||
|
||||
let compile_zone _ _ = []
|
||||
|
||||
let compile_zones zones =
|
||||
let deps = deps_of_zones zones in
|
||||
match Tsort.sort deps with
|
||||
| Tsort.Sorted sorted ->
|
||||
List.fold_right (fun name acc ->
|
||||
let values = List.assoc name zones in
|
||||
let compiled = compile_zone acc values in
|
||||
(name, compiled) :: acc) sorted []
|
||||
| _ -> assert false
|
2
dune
2
dune
|
@ -1,3 +1,3 @@
|
|||
(executable
|
||||
(name firewall)
|
||||
(libraries yojson ipaddr))
|
||||
(libraries yojson ipaddr tsort))
|
||||
|
|
Loading…
Reference in a new issue