Skip to main content

bacnet_server/
audit_notification.rs

1//! Receiver policy for confirmed and unconfirmed AuditNotification services.
2
3use std::sync::Arc;
4
5use bacnet_encoding::npdu::NpduAddress;
6use bacnet_services::audit::AuditNotificationRequest;
7use bacnet_types::primitives::ObjectIdentifier;
8use bacnet_types::MacAddr;
9
10/// Local maximum accepted AuditNotification service payload.
11pub const MAX_AUDIT_NOTIFICATION_BYTES: usize = 64 * 1024;
12/// Local maximum number of notifications in one accepted request.
13pub const MAX_AUDIT_NOTIFICATIONS: usize = 256;
14
15/// Transport provenance and decoded content supplied to the Audit authorizer.
16///
17/// The source/target identities inside `request` are peer-reported audit data,
18/// not authenticated transport provenance. Policy should use `source_network`
19/// for a usable routed origin and `source_mac` for the immediate data-link peer.
20#[derive(Debug, Clone, PartialEq)]
21pub struct AuditNotificationAuthorizationContext {
22    /// Immediate data-link peer (normally a router for routed traffic).
23    pub source_mac: MacAddr,
24    /// Originating NPDU source when one was present.
25    pub source_network: Option<NpduAddress>,
26    /// Outer Confirmed-Request invoke identifier.
27    pub invoke_id: u8,
28    /// Explicitly configured local Audit Log sink.
29    pub audit_log_sink: ObjectIdentifier,
30    /// Decoded peer-reported notification list, preserved verbatim.
31    pub request: AuditNotificationRequest,
32}
33
34/// Fast, nonblocking authorization callback for ConfirmedAuditNotification.
35///
36/// Absence, `false`, or a panic denies the request before storage mutation.
37pub type AuditNotificationAuthorizer =
38    Arc<dyn Fn(&AuditNotificationAuthorizationContext) -> bool + Send + Sync>;
39
40/// Transport provenance and decoded content supplied to the unconfirmed Audit
41/// authorizer.
42///
43/// The source/target identities inside `request` are peer-reported audit data,
44/// not authenticated transport provenance. Policy should use `source_network`
45/// for a usable routed origin and `source_mac` for the immediate data-link peer.
46#[derive(Debug, Clone, PartialEq)]
47pub struct UnconfirmedAuditNotificationAuthorizationContext {
48    /// Immediate data-link peer (normally a router for routed traffic).
49    pub source_mac: MacAddr,
50    /// Originating NPDU source when one was present.
51    pub source_network: Option<NpduAddress>,
52    /// Explicitly configured local Audit Log sink.
53    pub audit_log_sink: ObjectIdentifier,
54    /// Decoded peer-reported notification list, preserved verbatim.
55    pub request: AuditNotificationRequest,
56}
57
58/// Fast, nonblocking authorization callback for UnconfirmedAuditNotification.
59///
60/// Absence, `false`, or a panic silently denies the request before storage
61/// mutation.
62pub type UnconfirmedAuditNotificationAuthorizer =
63    Arc<dyn Fn(&UnconfirmedAuditNotificationAuthorizationContext) -> bool + Send + Sync>;