Skip to content

Commit 69c5c5c

Browse files
committed
feat: add register_helper_set function
For different types of ebpf programs, the kernel specifies a set of helpers that can be used. Therefore, we should allow registering a batch of helper functions at a time. For better flexibility, we can keep the registration of a single helper function. Signed-off-by: Godones <[email protected]>
1 parent ae35123 commit 69c5c5c

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/lib.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,20 @@ impl<'a> EbpfVmMbuff<'a> {
371371
Ok(())
372372
}
373373

374+
/// Register a set of built-in or user-defined helper functions in order to use them later from
375+
/// within the eBPF program. It is a convenience function to register multiple helpers at once.
376+
/// See [EbpfVmMbuff::register_helper] for more information.
377+
///
378+
/// # Warning
379+
/// This function will replace any previously registered helpers with the new set.
380+
pub fn register_helper_set(
381+
&mut self,
382+
helpers: HashMap<u32, ebpf::Helper>,
383+
) -> Result<(), Error> {
384+
self.helpers = helpers;
385+
Ok(())
386+
}
387+
374388
/// Register a set of addresses that the eBPF program is allowed to load and store.
375389
///
376390
/// When using certain helpers, typically map lookups, the Linux kernel will return pointers
@@ -983,6 +997,19 @@ impl<'a> EbpfVmFixedMbuff<'a> {
983997
self.parent.register_helper(key, function)
984998
}
985999

1000+
/// Register a set of built-in or user-defined helper functions in order to use them later from
1001+
/// within the eBPF program. It is a convenience function to register multiple helpers at once.
1002+
/// See [EbpfVmFixedMbuff::register_helper] for more information.
1003+
///
1004+
/// # Warning
1005+
/// This function will replace any previously registered helpers with the new set.
1006+
pub fn register_helper_set(
1007+
&mut self,
1008+
helpers: HashMap<u32, ebpf::Helper>,
1009+
) -> Result<(), Error> {
1010+
self.parent.register_helper_set(helpers)
1011+
}
1012+
9861013
/// Register an object that the eBPF program is allowed to load and store.
9871014
///
9881015
/// When using certain helpers, typically map lookups, the Linux kernel will return pointers
@@ -1513,6 +1540,19 @@ impl<'a> EbpfVmRaw<'a> {
15131540
self.parent.register_helper(key, function)
15141541
}
15151542

1543+
/// Register a set of built-in or user-defined helper functions in order to use them later from
1544+
/// within the eBPF program. It is a convenience function to register multiple helpers at once.
1545+
/// See [EbpfVmRaw::register_helper] for more information.
1546+
///
1547+
/// # Warning
1548+
/// This function will replace any previously registered helpers with the new set.
1549+
pub fn register_helper_set(
1550+
&mut self,
1551+
helpers: HashMap<u32, ebpf::Helper>,
1552+
) -> Result<(), Error> {
1553+
self.parent.register_helper_set(helpers)
1554+
}
1555+
15161556
/// Register an object that the eBPF program is allowed to load and store.
15171557
///
15181558
/// When using certain helpers, typically map lookups, the Linux kernel will return pointers
@@ -1951,6 +1991,19 @@ impl<'a> EbpfVmNoData<'a> {
19511991
self.parent.register_helper(key, function)
19521992
}
19531993

1994+
/// Register a set of built-in or user-defined helper functions in order to use them later from
1995+
/// within the eBPF program. It is a convenience function to register multiple helpers at once.
1996+
/// See [EbpfVmNoData::register_helper] for more information.
1997+
///
1998+
/// # Warning
1999+
/// This function will replace any previously registered helpers with the new set.
2000+
pub fn register_helper_set(
2001+
&mut self,
2002+
helpers: HashMap<u32, ebpf::Helper>,
2003+
) -> Result<(), Error> {
2004+
self.parent.register_helper_set(helpers)
2005+
}
2006+
19542007
/// Register an object that the eBPF program is allowed to load and store.
19552008
///
19562009
/// When using certain helpers, typically map lookups, the Linux kernel will return pointers

0 commit comments

Comments
 (0)