Simplify nftables.ml types

develop
jeltz 2 years ago
parent 9d300de0f3
commit e8b7c08b27
Signed by: jeltz
GPG Key ID: 800882B66C0C3326

@ -50,9 +50,13 @@ type rule = {
expr : unit stmt list;
}
type add_object = AddTable of table | AddChain of chain | AddRule of rule
type flush_object = FlushRuleset | FlushTable of table | FlushChain of chain
type command = Add of add_object | Flush of flush_object
type command =
| FlushRuleset
| AddTable of table
| FlushTable of table
| AddChain of chain
| FlushChain of chain
| AddRule of rule
let string_of_udp : type a. a udp -> string = function
| UdpSport -> "sport"
@ -164,19 +168,13 @@ let json_of_rule { family; table; chain; expr } =
("expr", `List (List.map json_of_stmt expr));
])
let json_of_add_object = function
| AddTable t -> json_of_table t
| AddChain c -> json_of_chain c
| AddRule r -> json_of_rule r
let json_of_flush_object = function
| FlushRuleset -> assoc_one "ruleset" `Null
| FlushTable t -> json_of_table t
| FlushChain c -> json_of_chain c
let json_of_command = function
| Add a -> assoc_one "add" (json_of_add_object a)
| Flush a -> assoc_one "flush" (json_of_flush_object a)
| FlushRuleset -> assoc_one "flush" (assoc_one "ruleset" `Null)
| AddTable t -> assoc_one "add" (json_of_table t)
| FlushTable t -> assoc_one "flush" (json_of_table t)
| AddChain c -> assoc_one "add" (json_of_chain c)
| FlushChain c -> assoc_one "flush" (json_of_chain c)
| AddRule r -> assoc_one "add" (json_of_rule r)
let json_of_nftables n =
assoc_one "nftables" (`List (List.map json_of_command n))

Loading…
Cancel
Save