use vstd::prelude::*;
use super::cbpf::*;
use super::policy::*;
verus! {
impl Policy {
pub open spec fn eval_chain(policies: Seq<Policy>, ev: Event, act: Action) -> bool {
||| policies.len() == 0 && act == Action::Allow
||| exists |i: int| {
&&& 0 <= i < policies.len()
&&& #[trigger] policies[i].eval(ev, act)
&&& forall |j: int, other: Action| 0 <= j < policies.len()
&& #[trigger] policies[j].eval(ev, other) ==> {
||| other.precedence() < act.precedence()
||| other.precedence() == act.precedence() && j <= i
}
}
}
}
impl Program {
pub open spec fn eval_chain(filters: Seq<Program>, data: &[u8], ret: u32) -> bool {
||| ret == Action::RET_ALLOW && forall |j: int| 0 <= j < filters.len() ==> {
&&& #[trigger] filters[j].eval(data) matches Outcome::Return(other)
&&& other & Action::RET_ACTION == Action::RET_ALLOW
}
||| exists |i: int| {
&&& 0 <= i < filters.len()
&&& #[trigger] filters[i].eval(data) == Outcome::Return(ret)
&&& ((ret & Action::RET_ACTION) as i32) < (Action::RET_ALLOW as i32)
&&& forall |j: int| 0 <= j < filters.len() ==> {
&&& #[trigger] filters[j].eval(data) matches Outcome::Return(other)
&&& {
let priority = (ret & Action::RET_ACTION) as i32;
let other_priority = (other & Action::RET_ACTION) as i32;
priority < other_priority || (priority == other_priority && j <= i)
}
}
}
}
}
}