Add a zones compiler

This commit is contained in:
jeltz 2022-08-29 12:19:45 +02:00
parent 463513c4c8
commit 2bee462997
Signed by: jeltz
GPG key ID: 800882B66C0C3326
2 changed files with 23 additions and 1 deletions

22
compile.ml Normal file
View 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
View file

@ -1,3 +1,3 @@
(executable (executable
(name firewall) (name firewall)
(libraries yojson ipaddr)) (libraries yojson ipaddr tsort))