Ignore empty addr sets

This commit is contained in:
jeltz 2022-09-06 22:31:23 +02:00
parent dac7920927
commit 4371d0f445
Signed by: jeltz
GPG key ID: 800882B66C0C3326

View file

@ -83,24 +83,25 @@ module Rules = struct
(* Bon, ce module n'est vraiment pas très joli… *)
let compile_addrs_list getter expr negate zones addrs_list =
Expr.Set
(PrefixSet.fold
PrefixSet.fold
(fun prefix acc -> getter negate prefix @ acc)
(PrefixSet.of_addrs_list zones addrs_list)
[]
|> List.map expr)
|> List.map expr
let compile_match_addrs getter expr field zones addrs_list =
[
Stmt.Match
( Match.Eq,
Expr.Payload field,
compile_addrs_list getter expr false zones addrs_list );
Stmt.Match
( Match.NotEq,
Expr.Payload field,
compile_addrs_list getter expr true zones addrs_list );
]
let equal = compile_addrs_list getter expr false zones addrs_list in
let not_equal = compile_addrs_list getter expr true zones addrs_list in
let stmts =
match equal with
| [] -> []
| _ -> [ Stmt.Match (Match.Eq, Expr.Payload field, Expr.Set equal) ]
in
match not_equal with
| [] -> stmts
| _ ->
Stmt.Match (Match.NotEq, Expr.Payload field, Expr.Set not_equal)
:: stmts
let compile_match_ipv4 field =
compile_match_addrs Prefix.to_ipv4_list Expr.ipv4 (Payload.Ipv4 field)