@@ -159,6 +159,106 @@ impl From<PerfEventOpts> for libbpf_sys::bpf_perf_event_opts {
159159    } 
160160} 
161161
162+ 
163+ /// Options used when iterating over a map. 
164+ #[ derive( Clone ,  Debug ) ]  
165+ pub  struct  MapIterOpts < ' fd >  { 
166+     /// The file descriptor of the map. 
167+ pub  fd :  BorrowedFd < ' fd > , 
168+     #[ doc( hidden) ]  
169+     pub  _non_exhaustive :  ( ) , 
170+ } 
171+ 
172+ impl < ' fd >  MapIterOpts < ' fd >  { 
173+     /// Create a `MapIterOpts` using the given file descriptor. 
174+ pub  fn  from_fd ( fd :  BorrowedFd < ' fd > )  -> Self  { 
175+         Self  { 
176+             fd, 
177+             _non_exhaustive :  ( ) , 
178+         } 
179+     } 
180+ } 
181+ 
182+ 
183+ /// Iteration order for cgroups. 
184+ #[ non_exhaustive]  
185+ #[ repr( u32 ) ]  
186+ #[ derive( Clone ,  Debug ,  Default ) ]  
187+ pub  enum  CgroupIterOrder  { 
188+     /// Use the default iteration order. 
189+ #[ default]  
190+     Default  = libbpf_sys:: BPF_CGROUP_ITER_ORDER_UNSPEC , 
191+     /// Process only a single object. 
192+ SelfOnly  = libbpf_sys:: BPF_CGROUP_ITER_SELF_ONLY , 
193+     /// Walk descendants in pre-order. 
194+ DescendantsPre  = libbpf_sys:: BPF_CGROUP_ITER_DESCENDANTS_PRE , 
195+     /// Walk descendants in post-order. 
196+ DescendantsPost  = libbpf_sys:: BPF_CGROUP_ITER_DESCENDANTS_POST , 
197+     /// Walk ancestors upward. 
198+ AncestorsUp  = libbpf_sys:: BPF_CGROUP_ITER_ANCESTORS_UP , 
199+ } 
200+ 
201+ /// Options used when iterating over a cgroup. 
202+ #[ derive( Clone ,  Debug ) ]  
203+ pub  struct  CgroupIterOpts < ' fd >  { 
204+     /// The file descriptor of the cgroup. 
205+ pub  fd :  BorrowedFd < ' fd > , 
206+     /// The iteration to use on the cgroup. 
207+ pub  order :  CgroupIterOrder , 
208+     #[ doc( hidden) ]  
209+     pub  _non_exhaustive :  ( ) , 
210+ } 
211+ 
212+ impl < ' fd >  CgroupIterOpts < ' fd >  { 
213+     /// Create a `CgroupIterOpts` using the given file descriptor. 
214+ pub  fn  from_fd ( fd :  BorrowedFd < ' fd > )  -> Self  { 
215+         Self  { 
216+             fd, 
217+             order :  CgroupIterOrder :: default ( ) , 
218+             _non_exhaustive :  ( ) , 
219+         } 
220+     } 
221+ } 
222+ 
223+ 
224+ /// Options to optionally be provided when attaching to an iterator. 
225+ #[ non_exhaustive]  
226+ #[ derive( Clone ,  Debug ) ]  
227+ pub  enum  IterOpts < ' fd >  { 
228+     /// Iterate over a map. 
229+ Map ( MapIterOpts < ' fd > ) , 
230+     /// Iterate over a group. 
231+ Cgroup ( CgroupIterOpts < ' fd > ) , 
232+ } 
233+ 
234+ impl  From < IterOpts < ' _ > >  for  libbpf_sys:: bpf_iter_link_info  { 
235+     fn  from ( opts :  IterOpts )  -> Self  { 
236+         let  mut  linkinfo = libbpf_sys:: bpf_iter_link_info:: default ( ) ; 
237+         match  opts { 
238+             IterOpts :: Map ( map_opts)  => { 
239+                 let  MapIterOpts  { 
240+                     fd, 
241+                     _non_exhaustive :  ( ) , 
242+                 }  = map_opts; 
243+ 
244+                 linkinfo. map . map_fd  = fd. as_raw_fd ( )  as  _ ; 
245+             } 
246+             IterOpts :: Cgroup ( cgroup_opts)  => { 
247+                 let  CgroupIterOpts  { 
248+                     fd, 
249+                     order, 
250+                     _non_exhaustive :  ( ) , 
251+                 }  = cgroup_opts; 
252+ 
253+                 linkinfo. cgroup . cgroup_fd  = fd. as_raw_fd ( )  as  _ ; 
254+                 linkinfo. cgroup . order  = order as  libbpf_sys:: bpf_cgroup_iter_order ; 
255+             } 
256+         } ; 
257+         linkinfo
258+     } 
259+ } 
260+ 
261+ 
162262/// An immutable parsed but not yet loaded BPF program. 
163263pub  type  OpenProgram < ' obj >  = OpenProgramImpl < ' obj > ; 
164264/// A mutable parsed but not yet loaded BPF program. 
@@ -1323,10 +1423,22 @@ impl<'obj> ProgramMut<'obj> {
13231423/// [BPF Iterator](https://www.kernel.org/doc/html/latest/bpf/bpf_iterators.html). 
13241424/// The entry point of the program must be defined with `SEC("iter")` or `SEC("iter.s")`. 
13251425pub  fn  attach_iter ( & self ,  map_fd :  BorrowedFd < ' _ > )  -> Result < Link >  { 
1326-         let  mut  linkinfo = libbpf_sys:: bpf_iter_link_info:: default ( ) ; 
1327-         linkinfo. map . map_fd  = map_fd. as_raw_fd ( )  as  _ ; 
1426+         let  map_opts = MapIterOpts  { 
1427+             fd :  map_fd, 
1428+             _non_exhaustive :  ( ) , 
1429+         } ; 
1430+         self . attach_iter_with_opts ( IterOpts :: Map ( map_opts) ) 
1431+     } 
1432+ 
1433+     /// Attach this program to a 
1434+ /// [BPF Iterator](https://www.kernel.org/doc/html/latest/bpf/bpf_iterators.html), 
1435+ /// providing additional options. 
1436+ /// 
1437+ /// The entry point of the program must be defined with `SEC("iter")` or `SEC("iter.s")`. 
1438+ pub  fn  attach_iter_with_opts ( & self ,  opts :  IterOpts < ' _ > )  -> Result < Link >  { 
1439+         let  mut  linkinfo = libbpf_sys:: bpf_iter_link_info:: from ( opts) ; 
13281440        let  attach_opt = libbpf_sys:: bpf_iter_attach_opts  { 
1329-             link_info :  & mut  linkinfo  as   * mut  libbpf_sys :: bpf_iter_link_info , 
1441+             link_info :  & raw   mut  linkinfo , 
13301442            link_info_len :  size_of :: < libbpf_sys:: bpf_iter_link_info > ( )  as  _ , 
13311443            sz :  size_of :: < libbpf_sys:: bpf_iter_attach_opts > ( )  as  _ , 
13321444            ..Default :: default ( ) 
0 commit comments