pub struct IpGateConfig { /* private fields */ }Expand description
The global IP gate: the parsed whitelist, blacklist, and exempt_ips
lists.
Build it once at startup with IpGateConfig::new (which fails closed on
an invalid entry) and evaluate request IPs with
IpGateConfig::evaluate. The default value is three empty lists: the
gate is inert, denying nobody and exempting nobody.
Implementations§
Source§impl IpGateConfig
impl IpGateConfig
Sourcepub fn new<W, B, E>(
whitelist: W,
blacklist: B,
exempt_ips: E,
) -> Result<Self, IpGateError>where
W: IntoIterator,
W::Item: AsRef<str>,
B: IntoIterator,
B::Item: AsRef<str>,
E: IntoIterator,
E::Item: AsRef<str>,
pub fn new<W, B, E>(
whitelist: W,
blacklist: B,
exempt_ips: E,
) -> Result<Self, IpGateError>where
W: IntoIterator,
W::Item: AsRef<str>,
B: IntoIterator,
B::Item: AsRef<str>,
E: IntoIterator,
E::Item: AsRef<str>,
Parse and validate the three lists, failing closed on the first invalid entry.
Entry semantics match the reference whitelist matcher: a bare IP or a
addr/prefix CIDR range, IPv4-mapped forms included, host bits
cleared. The empty iterator is valid for any list.
§Errors
Returns an IpGateError naming the list and the first entry that is
neither a valid IP nor a valid CIDR range.
Sourcepub fn evaluate(&self, ip: IpAddr) -> IpGateVerdict
pub fn evaluate(&self, ip: IpAddr) -> IpGateVerdict
Evaluate a request IP against the gate.
The ordering is the reference contract’s: with a non-empty whitelist the whitelist gate decides (an unlisted, non-exempt IP is denied; an exempt IP does not pass the gate), otherwise the blacklist decides. The exemption flag is only set on an allowed verdict: it never adds a deny path and never removes one.
Source§impl IpGateConfig
impl IpGateConfig
Sourcepub fn evaluate_unknown(&self) -> IpGateVerdict
pub fn evaluate_unknown(&self) -> IpGateVerdict
Evaluate the unknown client identity (no resolvable client address;
the reference UNKNOWN_CLIENT_IDENTITY, its
_check_unknown_identity_access): with a non-empty whitelist the
identity can never match it, so it is denied; otherwise it passes
with no skip state (it is neither whitelisted nor exempt, and the
blacklist is not consulted). Callers skip this exactly where they
skip IpGateConfig::evaluate (a route whitelist overriding the
global lists).
Trait Implementations§
Source§impl Clone for IpGateConfig
impl Clone for IpGateConfig
Source§impl Debug for IpGateConfig
impl Debug for IpGateConfig
Source§impl Default for IpGateConfig
impl Default for IpGateConfig
impl Eq for IpGateConfig
Source§impl PartialEq for IpGateConfig
impl PartialEq for IpGateConfig
impl StructuralPartialEq for IpGateConfig
Auto Trait Implementations§
impl Freeze for IpGateConfig
impl RefUnwindSafe for IpGateConfig
impl Send for IpGateConfig
impl Sync for IpGateConfig
impl Unpin for IpGateConfig
impl UnsafeUnpin for IpGateConfig
impl UnwindSafe for IpGateConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.