Skip to content

Commit 2f360af

Browse files
committed
NoC: Remove any ACLs for this fabric
1 parent fbcbcb7 commit 2f360af

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

matter/src/acl.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,17 @@ pub const NOC_CAT_SUBJECT_PREFIX: u64 = 0xFFFF_FFFD_0000_0000;
7878
const NOC_CAT_ID_MASK: u64 = 0xFFFF_0000;
7979
const NOC_CAT_VERSION_MASK: u64 = 0xFFFF;
8080

81+
/// Is this identifier a NOC CAT
8182
fn is_noc_cat(id: u64) -> bool {
8283
(id & NOC_CAT_SUBJECT_PREFIX) == NOC_CAT_SUBJECT_PREFIX
8384
}
8485

86+
/// Get the 16-bit NOC CAT id from the identifier
8587
fn get_noc_cat_id(id: u64) -> u64 {
8688
(id & NOC_CAT_ID_MASK) >> 16
8789
}
8890

91+
/// Get the 16-bit NOC CAT version from the identifier
8992
fn get_noc_cat_version(id: u64) -> u64 {
9093
id & NOC_CAT_VERSION_MASK
9194
}
@@ -96,6 +99,7 @@ pub fn gen_noc_cat(id: u16, version: u16) -> u32 {
9699
((id as u32) << 16) | version as u32
97100
}
98101

102+
/// The Subjects that identify the Accessor
99103
pub struct AccessorSubjects([u64; MAX_ACCESSOR_SUBJECTS]);
100104

101105
impl AccessorSubjects {
@@ -816,4 +820,34 @@ mod tests {
816820
req.set_target_perms(Access::RWVA);
817821
assert_eq!(req.allow(), true);
818822
}
823+
824+
#[test]
825+
fn test_delete_for_fabric() {
826+
let am = Arc::new(AclMgr::new_with(false).unwrap());
827+
am.erase_all();
828+
let path = GenericPath::new(Some(1), Some(1234), None);
829+
let accessor2 = Accessor::new(2, AccessorSubjects::new(112233), AuthMode::Case, am.clone());
830+
let mut req2 = AccessReq::new(&accessor2, &path, Access::READ);
831+
req2.set_target_perms(Access::RWVA);
832+
let accessor3 = Accessor::new(3, AccessorSubjects::new(112233), AuthMode::Case, am.clone());
833+
let mut req3 = AccessReq::new(&accessor3, &path, Access::READ);
834+
req3.set_target_perms(Access::RWVA);
835+
836+
// Allow for subject match - target is wildcard - Fabric idx 2
837+
let mut new = AclEntry::new(2, Privilege::VIEW, AuthMode::Case);
838+
new.add_subject(112233).unwrap();
839+
am.add(new).unwrap();
840+
841+
// Allow for subject match - target is wildcard - Fabric idx 3
842+
let mut new = AclEntry::new(3, Privilege::VIEW, AuthMode::Case);
843+
new.add_subject(112233).unwrap();
844+
am.add(new).unwrap();
845+
846+
// Req for Fabric idx 2 gets denied, and that for Fabric idx 3 is allowed
847+
assert_eq!(req2.allow(), true);
848+
assert_eq!(req3.allow(), true);
849+
am.delete_for_fabric(2).unwrap();
850+
assert_eq!(req2.allow(), false);
851+
assert_eq!(req3.allow(), true);
852+
}
819853
}

matter/src/data_model/sdm/noc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ impl NocCluster {
268268
let req =
269269
RemoveFabricReq::from_tlv(&cmd_req.data).map_err(|_| IMStatusCode::InvalidCommand)?;
270270
if self.fabric_mgr.remove(req.fab_idx).is_ok() {
271+
let _ = self.acl_mgr.delete_for_fabric(req.fab_idx);
271272
cmd_req.trans.terminate();
272273
} else {
273274
NocCluster::create_nocresponse(

0 commit comments

Comments
 (0)