pub struct View { /* private fields */ }Expand description
A view is a collection of OID subtrees defining accessible objects.
Views are used by VACM to determine which OIDs a user can access. Each view consists of included and/or excluded subtrees.
§Example
use async_snmp::agent::View;
use async_snmp::oid;
// Create a view that includes the system MIB but excludes sysContact
let view = View::new()
.include(oid!(1, 3, 6, 1, 2, 1, 1)) // system MIB
.exclude(oid!(1, 3, 6, 1, 2, 1, 1, 4)); // sysContact
assert!(view.contains(&oid!(1, 3, 6, 1, 2, 1, 1, 1, 0))); // sysDescr.0
assert!(!view.contains(&oid!(1, 3, 6, 1, 2, 1, 1, 4, 0))); // sysContact.0
assert!(!view.contains(&oid!(1, 3, 6, 1, 2, 1, 2))); // interfaces MIBImplementations§
Source§impl View
impl View
Sourcepub fn include(self, oid: Oid) -> Self
pub fn include(self, oid: Oid) -> Self
Add an included subtree to the view.
All OIDs starting with oid will be included in the view,
unless excluded by a later exclude() call.
§Example
use async_snmp::agent::View;
use async_snmp::oid;
let view = View::new()
.include(oid!(1, 3, 6, 1, 2, 1)) // MIB-2
.include(oid!(1, 3, 6, 1, 4, 1)); // enterprises
assert!(view.contains(&oid!(1, 3, 6, 1, 2, 1, 1, 0)));
assert!(view.contains(&oid!(1, 3, 6, 1, 4, 1, 99999, 1)));Sourcepub fn include_masked(self, oid: Oid, mask: Vec<u8>) -> Self
pub fn include_masked(self, oid: Oid, mask: Vec<u8>) -> Self
Add an included subtree with a wildcard mask.
The mask allows wildcards at specific OID arc positions.
See ViewSubtree::mask for mask format details.
§Example
use async_snmp::agent::View;
use async_snmp::oid;
// Include ifDescr for any interface (mask makes arc 10 a wildcard)
let view = View::new()
.include_masked(
oid!(1, 3, 6, 1, 2, 1, 2, 2, 1, 2), // ifDescr
vec![0xFF, 0xC0] // First 10 arcs must match
);
assert!(view.contains(&oid!(1, 3, 6, 1, 2, 1, 2, 2, 1, 2, 1))); // ifDescr.1
assert!(view.contains(&oid!(1, 3, 6, 1, 2, 1, 2, 2, 1, 2, 100))); // ifDescr.100Sourcepub fn exclude(self, oid: Oid) -> Self
pub fn exclude(self, oid: Oid) -> Self
Add an excluded subtree to the view.
OIDs starting with oid will be excluded, even if they match
an included subtree. Exclusions take precedence.
§Example
use async_snmp::agent::View;
use async_snmp::oid;
let view = View::new()
.include(oid!(1, 3, 6, 1, 2, 1, 1)) // system MIB
.exclude(oid!(1, 3, 6, 1, 2, 1, 1, 6)); // except sysLocation
assert!(view.contains(&oid!(1, 3, 6, 1, 2, 1, 1, 1, 0))); // sysDescr
assert!(!view.contains(&oid!(1, 3, 6, 1, 2, 1, 1, 6, 0))); // sysLocationSourcepub fn exclude_masked(self, oid: Oid, mask: Vec<u8>) -> Self
pub fn exclude_masked(self, oid: Oid, mask: Vec<u8>) -> Self
Add an excluded subtree with a wildcard mask.
See include_masked() for mask usage.
Sourcepub fn contains(&self, oid: &Oid) -> bool
pub fn contains(&self, oid: &Oid) -> bool
Check if an OID is in this view.
Per RFC 3415 Section 5, an OID is in the view if:
- At least one included subtree matches, AND
- No excluded subtree matches
§Example
use async_snmp::agent::View;
use async_snmp::oid;
let view = View::new()
.include(oid!(1, 3, 6, 1, 2, 1))
.exclude(oid!(1, 3, 6, 1, 2, 1, 25)); // host resources
assert!(view.contains(&oid!(1, 3, 6, 1, 2, 1, 1, 0)));
assert!(!view.contains(&oid!(1, 3, 6, 1, 2, 1, 25, 1, 0)));
assert!(!view.contains(&oid!(1, 3, 6, 1, 4, 1))); // not includedSourcepub fn check_subtree(&self, oid: &Oid) -> ViewCheckResult
pub fn check_subtree(&self, oid: &Oid) -> ViewCheckResult
Check subtree access status with 3-state result.
Unlike contains() which checks a single OID,
this method determines the access status for an entire subtree.
This enables optimizations for GETBULK/GETNEXT operations.
Returns:
ViewCheckResult::Included: OID and all descendants are accessibleViewCheckResult::Excluded: OID and all descendants are not accessibleViewCheckResult::Ambiguous: Mixed permissions, check each OID individually