소스 검색

aya: add Bpf::maps() to get all the maps

Alessandro Decina 4 년 전
부모
커밋
0a493baed6
1개의 변경된 파일11개의 추가작업 그리고 0개의 파일을 삭제
  1. 11 0
      aya/src/bpf.rs

+ 11 - 0
aya/src/bpf.rs

@@ -183,6 +183,17 @@ impl Bpf {
             .transpose()
     }
 
+    pub fn maps<'a>(&'a self) -> impl Iterator<Item = (&'a str, Result<MapRef, MapError>)> + 'a {
+        let ret = self.maps.iter().map(|(name, lock)| {
+            (
+                name.as_str(),
+                lock.try_read()
+                    .map_err(|_| MapError::BorrowError { name: name.clone() }),
+            )
+        });
+        ret
+    }
+
     pub fn program<'a, 'slf: 'a, T: TryFrom<&'a Program>>(
         &'slf self,
         name: &str,