pub struct RequestContext {
pub source: SocketAddr,
pub version: Version,
pub security_model: SecurityModel,
pub security_name: Bytes,
pub security_level: SecurityLevel,
pub context_name: Bytes,
pub request_id: i32,
pub pdu_type: PduType,
pub group_name: Option<Bytes>,
pub read_view: Option<Bytes>,
pub write_view: Option<Bytes>,
}Expand description
Request context passed to MIB handlers.
Contains information about the incoming request for authorization decisions, including VACM-resolved access control information when VACM is enabled.
§Fields
The context provides:
- Request origin: Source address and request ID
- Security info: Version, model, level, and security name (community/username)
- VACM info: Group name and view names (when VACM is configured)
§Example
use async_snmp::handler::{MibHandler, RequestContext, GetResult, BoxFuture};
use async_snmp::{Oid, Value, oid};
struct LoggingHandler;
impl MibHandler for LoggingHandler {
fn get<'a>(&'a self, ctx: &'a RequestContext, oid: &'a Oid) -> BoxFuture<'a, GetResult> {
Box::pin(async move {
// Log request details
println!(
"GET {} from {} (user: {:?}, version: {:?})",
oid, ctx.source, ctx.security_name, ctx.version
);
if oid == &oid!(1, 3, 6, 1, 4, 1, 99999, 1, 0) {
GetResult::Value(Value::Integer(42))
} else {
GetResult::NoSuchObject
}
})
}
fn get_next<'a>(
&'a self,
_ctx: &'a RequestContext,
_oid: &'a Oid,
) -> BoxFuture<'a, async_snmp::handler::GetNextResult> {
Box::pin(async { async_snmp::handler::GetNextResult::EndOfMibView })
}
}Fields§
§source: SocketAddrSource address of the request.
Use this for logging or additional access control beyond VACM.
version: VersionSNMP version (V1, V2c, or V3).
security_model: SecurityModelSecurity model used for this request.
V1for SNMPv1 community-basedV2cfor SNMPv2c community-basedUsmfor SNMPv3 User-based Security Model
security_name: BytesSecurity name (community string or USM username).
For v1/v2c: the community string For v3: the USM username
security_level: SecurityLevelSecurity level (v3 only, NoAuthNoPriv for v1/v2c).
Indicates whether authentication and/or privacy were used.
context_name: BytesContext name (v3 only, empty for v1/v2c).
SNMPv3 contexts allow partitioning MIB views.
request_id: i32Request ID from the PDU.
Useful for correlating requests with responses in logs.
pdu_type: PduTypePDU type (GetRequest, GetNextRequest, SetRequest, etc.).
group_name: Option<Bytes>Resolved group name (if VACM enabled).
Set when VACM successfully maps the security name to a group.
read_view: Option<Bytes>Read view name (if VACM enabled).
The view that controls which OIDs can be read.
write_view: Option<Bytes>Write view name (if VACM enabled).
The view that controls which OIDs can be written.
Implementations§
Source§impl RequestContext
impl RequestContext
Sourcepub fn test_context() -> Self
pub fn test_context() -> Self
Create a minimal context for unit testing.
Trait Implementations§
Source§impl Clone for RequestContext
impl Clone for RequestContext
Source§fn clone(&self) -> RequestContext
fn clone(&self) -> RequestContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !Freeze for RequestContext
impl RefUnwindSafe for RequestContext
impl Send for RequestContext
impl Sync for RequestContext
impl Unpin for RequestContext
impl UnsafeUnpin for RequestContext
impl UnwindSafe for RequestContext
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<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>
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>
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 more