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