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