Format config.ml
This commit is contained in:
parent
397eebb638
commit
2a837d831d
1 changed files with 10 additions and 21 deletions
25
config.ml
25
config.ml
|
@ -7,10 +7,7 @@ type zone =
|
|||
| ZoneList of zone list
|
||||
| ZoneExclude of zone
|
||||
|
||||
type addrs =
|
||||
| ZoneName of string
|
||||
| Ipv4 of V4.Prefix.t
|
||||
| Ipv6 of V6.Prefix.t
|
||||
type addrs = ZoneName of string | Ipv4 of V4.Prefix.t | Ipv6 of V6.Prefix.t
|
||||
|
||||
type l4_rule =
|
||||
| TcpRule of { sport : int list; dport : int list }
|
||||
|
@ -18,34 +15,26 @@ type l4_rule =
|
|||
| IcmpRule
|
||||
|
||||
type rule = { src : addrs list; dest : addrs list; l4 : l4_rule }
|
||||
|
||||
type config = { zones: (string * zone) list; rules: rule list }
|
||||
|
||||
type config = { zones : (string * zone list) list; rules : rule list }
|
||||
|
||||
(* TODO *)
|
||||
let zone_of_json _ =
|
||||
Zone "xxx"
|
||||
let zone_of_json _ = [ Zone "xxx" ]
|
||||
|
||||
let addrs_of_json json =
|
||||
let open Yojson.Basic.Util in
|
||||
let value = json |> to_string in
|
||||
let addrs = ZoneName value in
|
||||
let addrs = match V6.Prefix.of_string value with
|
||||
| Ok p -> Ipv6 p
|
||||
| Error _ -> addrs
|
||||
let addrs =
|
||||
match V6.Prefix.of_string value with Ok p -> Ipv6 p | Error _ -> addrs
|
||||
in
|
||||
match V4.Prefix.of_string value with
|
||||
| Ok p -> Ipv4 p
|
||||
| Error _ -> addrs
|
||||
match V4.Prefix.of_string value with Ok p -> Ipv4 p | Error _ -> addrs
|
||||
|
||||
let addrs_list_of_json json =
|
||||
let open Yojson.Basic.Util in
|
||||
let elems = json |> to_list in
|
||||
List.map addrs_of_json elems
|
||||
|
||||
let to_list_force = function
|
||||
| `List l -> l
|
||||
| _ -> []
|
||||
let to_list_force = function `List l -> l | _ -> []
|
||||
|
||||
let to_int_list json =
|
||||
let open Yojson.Basic.Util in
|
||||
|
|
Loading…
Reference in a new issue