Format config.ml

This commit is contained in:
jeltz 2022-08-29 21:14:06 +02:00
parent 397eebb638
commit 2a837d831d
Signed by: jeltz
GPG key ID: 800882B66C0C3326

View file

@ -7,10 +7,7 @@ type zone =
| ZoneList of zone list | ZoneList of zone list
| ZoneExclude of zone | ZoneExclude of zone
type addrs = type addrs = ZoneName of string | Ipv4 of V4.Prefix.t | Ipv6 of V6.Prefix.t
| ZoneName of string
| Ipv4 of V4.Prefix.t
| Ipv6 of V6.Prefix.t
type l4_rule = type l4_rule =
| TcpRule of { sport : int list; dport : int list } | TcpRule of { sport : int list; dport : int list }
@ -18,34 +15,26 @@ type l4_rule =
| IcmpRule | IcmpRule
type rule = { src : addrs list; dest : addrs list; l4 : l4_rule } type rule = { src : addrs list; dest : addrs list; l4 : l4_rule }
type config = { zones : (string * zone list) list; rules : rule list }
type config = { zones: (string * zone) list; rules: rule list }
(* TODO *) (* TODO *)
let zone_of_json _ = let zone_of_json _ = [ Zone "xxx" ]
Zone "xxx"
let addrs_of_json json = let addrs_of_json json =
let open Yojson.Basic.Util in let open Yojson.Basic.Util in
let value = json |> to_string in let value = json |> to_string in
let addrs = ZoneName value in let addrs = ZoneName value in
let addrs = match V6.Prefix.of_string value with let addrs =
| Ok p -> Ipv6 p match V6.Prefix.of_string value with Ok p -> Ipv6 p | Error _ -> addrs
| Error _ -> addrs
in in
match V4.Prefix.of_string value with match V4.Prefix.of_string value with Ok p -> Ipv4 p | Error _ -> addrs
| Ok p -> Ipv4 p
| Error _ -> addrs
let addrs_list_of_json json = let addrs_list_of_json json =
let open Yojson.Basic.Util in let open Yojson.Basic.Util in
let elems = json |> to_list in let elems = json |> to_list in
List.map addrs_of_json elems List.map addrs_of_json elems
let to_list_force = function let to_list_force = function `List l -> l | _ -> []
| `List l -> l
| _ -> []
let to_int_list json = let to_int_list json =
let open Yojson.Basic.Util in let open Yojson.Basic.Util in