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.
Showing the changes to include/uapi (1 of 4 files). Show all
Unified · Split
| @@ -4983,6 +4983,16 @@ union bpf_attr { · 4982 unmodified lines | ||
| 4983 | 4983 | * Return |
| 4984 | 4984 | * The number of loops performed, **-EINVAL** for invalid **flags**, |
| 4985 | 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 | 4997 | #define __BPF_FUNC_MAPPER(FN) \ |
| 4988 | 4998 | FN(unspec), \ |
| @@ -5167,6 +5177,7 @@ union bpf_attr { · 178 unmodified lines | ||
| 5167 | 5177 | FN(kallsyms_lookup_name), \ |
| 5168 | 5178 | FN(find_vma), \ |
| 5169 | 5179 | FN(loop), \ |
| 5180 | + FN(strncmp), \ | |
| 5170 | 5181 | /* */ |
| 5171 | 5182 | |
| 5172 | 5183 | /* integer value in 'imm' field of BPF_CALL instruction selects which helper |