@@ -3349,20 +3349,7 @@ __bpf_kfunc void __bpf_trap(void)
33493349 * __get_kernel_nofault instead of plain dereference to make them safe.
33503350 */
33513351
3352- /**
3353- * bpf_strcmp - Compare two strings
3354- * @s1__ign: One string
3355- * @s2__ign: Another string
3356- *
3357- * Return:
3358- * * %0 - Strings are equal
3359- * * %-1 - @s1__ign is smaller
3360- * * %1 - @s2__ign is smaller
3361- * * %-EFAULT - Cannot read one of the strings
3362- * * %-E2BIG - One of strings is too large
3363- * * %-ERANGE - One of strings is outside of kernel address space
3364- */
3365- __bpf_kfunc int bpf_strcmp (const char * s1__ign , const char * s2__ign )
3352+ int __bpf_strcasecmp (const char * s1__ign , const char * s2__ign , bool ignore_case )
33663353{
33673354 char c1 , c2 ;
33683355 int i ;
@@ -3376,6 +3363,10 @@ __bpf_kfunc int bpf_strcmp(const char *s1__ign, const char *s2__ign)
33763363 for (i = 0 ; i < XATTR_SIZE_MAX ; i ++ ) {
33773364 __get_kernel_nofault (& c1 , s1__ign , char , err_out );
33783365 __get_kernel_nofault (& c2 , s2__ign , char , err_out );
3366+ if (ignore_case ) {
3367+ c1 = tolower (c1 );
3368+ c2 = tolower (c2 );
3369+ }
33793370 if (c1 != c2 )
33803371 return c1 < c2 ? -1 : 1 ;
33813372 if (c1 == '\0' )
@@ -3388,6 +3379,42 @@ __bpf_kfunc int bpf_strcmp(const char *s1__ign, const char *s2__ign)
33883379 return - EFAULT ;
33893380}
33903381
3382+ /**
3383+ * bpf_strcmp - Compare two strings
3384+ * @s1__ign: One string
3385+ * @s2__ign: Another string
3386+ *
3387+ * Return:
3388+ * * %0 - Strings are equal
3389+ * * %-1 - @s1__ign is smaller
3390+ * * %1 - @s2__ign is smaller
3391+ * * %-EFAULT - Cannot read one of the strings
3392+ * * %-E2BIG - One of strings is too large
3393+ * * %-ERANGE - One of strings is outside of kernel address space
3394+ */
3395+ __bpf_kfunc int bpf_strcmp (const char * s1__ign , const char * s2__ign )
3396+ {
3397+ return __bpf_strcasecmp (s1__ign , s2__ign , false);
3398+ }
3399+
3400+ /**
3401+ * bpf_strcasecmp - Compare two strings, ignoring the case of the characters
3402+ * @s1__ign: One string
3403+ * @s2__ign: Another string
3404+ *
3405+ * Return:
3406+ * * %0 - Strings are equal
3407+ * * %-1 - @s1__ign is smaller
3408+ * * %1 - @s2__ign is smaller
3409+ * * %-EFAULT - Cannot read one of the strings
3410+ * * %-E2BIG - One of strings is too large
3411+ * * %-ERANGE - One of strings is outside of kernel address space
3412+ */
3413+ __bpf_kfunc int bpf_strcasecmp (const char * s1__ign , const char * s2__ign )
3414+ {
3415+ return __bpf_strcasecmp (s1__ign , s2__ign , true);
3416+ }
3417+
33913418/**
33923419 * bpf_strnchr - Find a character in a length limited string
33933420 * @s__ign: The string to be searched
@@ -3832,6 +3859,7 @@ BTF_ID_FLAGS(func, bpf_iter_dmabuf_destroy, KF_ITER_DESTROY | KF_SLEEPABLE)
38323859#endif
38333860BTF_ID_FLAGS (func , __bpf_trap )
38343861BTF_ID_FLAGS (func , bpf_strcmp );
3862+ BTF_ID_FLAGS (func , bpf_strcasecmp );
38353863BTF_ID_FLAGS (func , bpf_strchr );
38363864BTF_ID_FLAGS (func , bpf_strchrnul );
38373865BTF_ID_FLAGS (func , bpf_strnchr );
0 commit comments