@@ -362,6 +362,16 @@ pub trait BoundBoundary: Send {
362362 None
363363 }
364364
365+ /// Optional transport for policy-authorized workload UDP associations.
366+ ///
367+ /// Backends return this only after they can preserve datagram boundaries,
368+ /// socket identity, and bounded cancellation semantics. A backend that
369+ /// returns `None` does not support general UDP; DNS remains available
370+ /// independently through [`Self::dns_mediation_source`].
371+ fn udp_mediation_source ( & self ) -> Option < Arc < dyn UdpMediationSource > > {
372+ None
373+ }
374+
365375 /// Trusted host-side dial target for the well-known host-gateway aliases.
366376 ///
367377 /// Backends return this when the mediation service runs outside the
@@ -746,7 +756,7 @@ impl FromStr for Sha256Digest {
746756 }
747757}
748758
749- /// Immutable socket metadata supplied with a pending external TCP open.
759+ /// Immutable socket metadata supplied with a pending external network open.
750760#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
751761pub struct NetworkSocketMetadata {
752762 /// Kernel socket cookie captured for the exact open-file description.
@@ -831,5 +841,106 @@ pub trait DnsMediationSource: Send + Sync {
831841 async fn accept ( & self ) -> Result < MediatedDnsQuery , BackendError > ;
832842}
833843
844+ /// Opaque identity for one generation-scoped UDP association.
845+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
846+ pub struct UdpAssociationId ( [ u8 ; 16 ] ) ;
847+
848+ impl UdpAssociationId {
849+ /// Construct an association ID from 128 bits of trusted randomness.
850+ #[ must_use]
851+ pub const fn new ( bytes : [ u8 ; 16 ] ) -> Self {
852+ Self ( bytes)
853+ }
854+
855+ /// Return the stable wire bytes for this ID.
856+ #[ must_use]
857+ pub const fn as_bytes ( & self ) -> & [ u8 ; 16 ] {
858+ & self . 0
859+ }
860+ }
861+
862+ impl fmt:: Display for UdpAssociationId {
863+ fn fmt ( & self , formatter : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
864+ for byte in self . 0 {
865+ write ! ( formatter, "{byte:02x}" ) ?;
866+ }
867+ Ok ( ( ) )
868+ }
869+ }
870+
871+ /// One unreliable datagram on a generation-scoped association.
872+ ///
873+ /// Sequence numbers detect accidental duplicate delivery within one active
874+ /// transport generation. They do not add retransmission or reliable-delivery
875+ /// semantics to UDP.
876+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
877+ pub struct UdpDatagram {
878+ /// Monotonically increasing sender-local sequence number.
879+ pub sequence : u64 ,
880+ /// Exact datagram payload. An empty payload is valid.
881+ pub payload : Vec < u8 > ,
882+ }
883+
884+ /// A live datagram-preserving session between one workload association and
885+ /// the supervisor-owned external UDP socket.
886+ ///
887+ /// Concrete backends may multiplex many sessions over one protected channel,
888+ /// but the supervisor consumes each association through this semantic API and
889+ /// never depends on backend framing.
890+ #[ async_trait]
891+ pub trait BoundaryDatagramSession : Send {
892+ /// Receive the next datagram emitted by the workload. `None` means the
893+ /// association was closed cleanly.
894+ async fn receive_from_workload ( & mut self ) -> Result < Option < UdpDatagram > , BackendError > ;
895+
896+ /// Deliver one admitted external datagram to the workload association.
897+ async fn send_to_workload ( & mut self , datagram : UdpDatagram ) -> Result < ( ) , BackendError > ;
898+ }
899+
900+ /// Typed supervisor decision for one pending UDP association.
901+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
902+ pub enum UdpAssociationOpenResult {
903+ /// Policy authorization and the external datagram relay are ready.
904+ RelayReady ,
905+ /// The workload operation remains uncommitted and returns this positive
906+ /// errno.
907+ Denied { errno : i32 } ,
908+ }
909+
910+ /// A staged workload UDP association delivered before its local relay is
911+ /// committed.
912+ ///
913+ /// An unresolved binary identity must be denied and audited. Dropping
914+ /// [`Self::result`] cancels the association without authorizing the workload
915+ /// destination.
916+ pub struct PendingUdpAssociation {
917+ /// Opaque ID scoped to the active sandbox and transport generation.
918+ pub association_id : UdpAssociationId ,
919+ /// Executable identity of the operation that selected the destination.
920+ pub binary_identity : Result < BinaryIdentity , ResolveError > ,
921+ /// Original external destination captured from the workload operation.
922+ pub destination : SocketAddr ,
923+ /// Socket and process identity bound to this association.
924+ pub socket : NetworkSocketMetadata ,
925+ /// Policy generation under which the association was created.
926+ pub policy_generation : u64 ,
927+ /// Datagram-preserving workload transport, activated only after
928+ /// [`UdpAssociationOpenResult::RelayReady`].
929+ pub session : Box < dyn BoundaryDatagramSession > ,
930+ /// Single-use completion channel back to the sandbox broker.
931+ pub result : oneshot:: Sender < UdpAssociationOpenResult > ,
932+ }
933+
934+ /// Logical per-boundary source of staged workload UDP associations.
935+ ///
936+ /// An `Err` means the source itself is unusable and fails general UDP closed.
937+ /// Backends that do not implement this trait return `None` from
938+ /// [`BoundBoundary::udp_mediation_source`].
939+ #[ async_trait]
940+ pub trait UdpMediationSource : Send + Sync {
941+ /// Await the next staged association.
942+ async fn accept ( & self ) -> Result < PendingUdpAssociation , BackendError > ;
943+ }
944+
834945#[ cfg( test) ]
835946mod tests;
0 commit comments