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
4983 * Return4983 * Return
4984 * The number of loops performed, **-EINVAL** for invalid **flags**,4984 * The number of loops performed, **-EINVAL** for invalid **flags**,
4985 * **-E2BIG** if **nr_loops** exceeds the maximum number of loops.4985 * **-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**.
4986 */4996 */
4987#define __BPF_FUNC_MAPPER(FN) \4997#define __BPF_FUNC_MAPPER(FN) \
4988 FN(unspec), \4998 FN(unspec), \
@@ -5167,6 +5177,7 @@ union bpf_attr { · 178 unmodified lines
5167 FN(kallsyms_lookup_name), \5177 FN(kallsyms_lookup_name), \
5168 FN(find_vma), \5178 FN(find_vma), \
5169 FN(loop), \5179 FN(loop), \
5180 FN(strncmp), \
5170 /* */5181 /* */
5171 5182
5172/* integer value in 'imm' field of BPF_CALL instruction selects which helper5183/* integer value in 'imm' field of BPF_CALL instruction selects which helper