pub struct IpAccessControl { /* private fields */ }Expand description
IP-based access control.
This struct manages allowed and blocked IP ranges for connection filtering. Rules are evaluated in the following order:
- Check if IP is in blocked list → Deny
- If allowed list is non-empty, check if IP is in allowed list → Allow/Deny
- Use default policy (Allow if no allowed list specified)
Implementations§
Source§impl IpAccessControl
impl IpAccessControl
Sourcepub fn from_config(
allowed_ips: &[String],
blocked_ips: &[String],
) -> Result<Self>
pub fn from_config( allowed_ips: &[String], blocked_ips: &[String], ) -> Result<Self>
Sourcepub fn check(&self, ip: &IpAddr) -> AccessPolicy
pub fn check(&self, ip: &IpAddr) -> AccessPolicy
Sourcepub fn allow_cidr(&mut self, cidr: &str) -> Result<()>
pub fn allow_cidr(&mut self, cidr: &str) -> Result<()>
Sourcepub fn block_cidr(&mut self, cidr: &str) -> Result<()>
pub fn block_cidr(&mut self, cidr: &str) -> Result<()>
Sourcepub fn block_ip(&mut self, ip: IpAddr)
pub fn block_ip(&mut self, ip: IpAddr)
Block a single IP address.
This creates a /32 (IPv4) or /128 (IPv6) rule.
Sourcepub fn unblock_ip(&mut self, ip: IpAddr)
pub fn unblock_ip(&mut self, ip: IpAddr)
Unblock a single IP address.
Removes the /32 (IPv4) or /128 (IPv6) rule for this IP.
Sourcepub fn remove_allowed(&mut self, network: &IpNetwork)
pub fn remove_allowed(&mut self, network: &IpNetwork)
Remove an allowed network.
Sourcepub fn remove_blocked(&mut self, network: &IpNetwork)
pub fn remove_blocked(&mut self, network: &IpNetwork)
Remove a blocked network.
Sourcepub fn reload(
&mut self,
allowed_ips: &[String],
blocked_ips: &[String],
) -> Result<()>
pub fn reload( &mut self, allowed_ips: &[String], blocked_ips: &[String], ) -> Result<()>
Reload configuration from allowed and blocked IP lists.
Sourcepub fn allowed_count(&self) -> usize
pub fn allowed_count(&self) -> usize
Get the number of allowed networks.
Sourcepub fn blocked_count(&self) -> usize
pub fn blocked_count(&self) -> usize
Get the number of blocked networks.
Sourcepub fn default_policy(&self) -> AccessPolicy
pub fn default_policy(&self) -> AccessPolicy
Get the default policy.
Sourcepub fn is_whitelist_mode(&self) -> bool
pub fn is_whitelist_mode(&self) -> bool
Check if the access control is in whitelist mode.
Returns true if there are allowed networks configured,
meaning only those networks are allowed.
Sourcepub fn allowed_networks(&self) -> Vec<IpNetwork>
pub fn allowed_networks(&self) -> Vec<IpNetwork>
Get a copy of the allowed networks.
Sourcepub fn blocked_networks(&self) -> Vec<IpNetwork>
pub fn blocked_networks(&self) -> Vec<IpNetwork>
Get a copy of the blocked networks.
Trait Implementations§
Source§impl Clone for IpAccessControl
impl Clone for IpAccessControl
Source§fn clone(&self) -> IpAccessControl
fn clone(&self) -> IpAccessControl
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for IpAccessControl
impl Debug for IpAccessControl
Auto Trait Implementations§
impl Freeze for IpAccessControl
impl RefUnwindSafe for IpAccessControl
impl Send for IpAccessControl
impl Sync for IpAccessControl
impl Unpin for IpAccessControl
impl UnsafeUnpin for IpAccessControl
impl UnwindSafe for IpAccessControl
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request