RequestContext

Struct RequestContext 

Source
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: SocketAddr

Source address of the request.

Use this for logging or additional access control beyond VACM.

§version: Version

SNMP version (V1, V2c, or V3).

§security_model: SecurityModel

Security model used for this request.

  • V1 for SNMPv1 community-based
  • V2c for SNMPv2c community-based
  • Usm for SNMPv3 User-based Security Model
§security_name: Bytes

Security name (community string or USM username).

For v1/v2c: the community string For v3: the USM username

§security_level: SecurityLevel

Security level (v3 only, NoAuthNoPriv for v1/v2c).

Indicates whether authentication and/or privacy were used.

§context_name: Bytes

Context name (v3 only, empty for v1/v2c).

SNMPv3 contexts allow partitioning MIB views.

§request_id: i32

Request ID from the PDU.

Useful for correlating requests with responses in logs.

§pdu_type: PduType

PDU 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.

Trait Implementations§

Source§

impl Clone for RequestContext

Source§

fn clone(&self) -> RequestContext

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RequestContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more