History

bpf: Add bpf_strncmp helper

The helper compares two strings: one string is a null-terminated read-only string, and another string has const max storage size but doesn't need to be null-terminated. It can be used to compare file name in tracing or LSM program.

Hou Tao committed 4 years ago

Commit c5fb1991 parent 259172b4 files · +39 −0Browse files

Showing the changes to include/uapi (1 of 4 files). Show all

Unified · Split

include/uapi/linux/bpf.h+11−0
@@ -4983,6 +4983,16 @@ union bpf_attr { · 4982 unmodified lines
49834983 * Return
49844984 * The number of loops performed, **-EINVAL** for invalid **flags**,
49854985 * **-E2BIG** if **nr_loops** exceeds the maximum number of loops.
4986+ *
4987+ * long bpf_strncmp(const char *s1, u32 s1_sz, const char *s2)
4988+ * Description
4989+ * Do strncmp() between **s1** and **s2**. **s1** doesn't need
4990+ * to be null-terminated and **s1_sz** is the maximum storage
4991+ * size of **s1**. **s2** must be a read-only string.
4992+ * Return
4993+ * An integer less than, equal to, or greater than zero
4994+ * if the first **s1_sz** bytes of **s1** is found to be
4995+ * less than, to match, or be greater than **s2**.
49864996 */
49874997 #define __BPF_FUNC_MAPPER(FN) \
49884998 FN(unspec), \
@@ -5167,6 +5177,7 @@ union bpf_attr { · 178 unmodified lines
51675177 FN(kallsyms_lookup_name), \
51685178 FN(find_vma), \
51695179 FN(loop), \
5180+ FN(strncmp), \
51705181 /* */
51715182
51725183 /* integer value in 'imm' field of BPF_CALL instruction selects which helper