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 let compile_rule zones { src; dest; l4 } = let match_src = match src with | [] -> [] | l -> [] in let match_dest = match dest with | [] -> [] | l -> [] in let l4_rules = compile_l4 zones l4 in List.flatten [match_src; match_dest; l4_rules] let compile_rules zones = List.map (compile_rule zones)