@@ -3349,45 +3349,72 @@ __bpf_kfunc void __bpf_trap(void)
3349
3349
* __get_kernel_nofault instead of plain dereference to make them safe.
3350
3350
*/
3351
3351
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
+ static int __bpf_strcasecmp (const char * s1 , const char * s2 , bool ignore_case )
3366
3353
{
3367
3354
char c1 , c2 ;
3368
3355
int i ;
3369
3356
3370
- if (!copy_from_kernel_nofault_allowed (s1__ign , 1 ) ||
3371
- !copy_from_kernel_nofault_allowed (s2__ign , 1 )) {
3357
+ if (!copy_from_kernel_nofault_allowed (s1 , 1 ) ||
3358
+ !copy_from_kernel_nofault_allowed (s2 , 1 )) {
3372
3359
return - ERANGE ;
3373
3360
}
3374
3361
3375
3362
guard (pagefault )();
3376
3363
for (i = 0 ; i < XATTR_SIZE_MAX ; i ++ ) {
3377
- __get_kernel_nofault (& c1 , s1__ign , char , err_out );
3378
- __get_kernel_nofault (& c2 , s2__ign , char , err_out );
3364
+ __get_kernel_nofault (& c1 , s1 , char , err_out );
3365
+ __get_kernel_nofault (& c2 , s2 , char , err_out );
3366
+ if (ignore_case ) {
3367
+ c1 = tolower (c1 );
3368
+ c2 = tolower (c2 );
3369
+ }
3379
3370
if (c1 != c2 )
3380
3371
return c1 < c2 ? -1 : 1 ;
3381
3372
if (c1 == '\0' )
3382
3373
return 0 ;
3383
- s1__ign ++ ;
3384
- s2__ign ++ ;
3374
+ s1 ++ ;
3375
+ s2 ++ ;
3385
3376
}
3386
3377
return - E2BIG ;
3387
3378
err_out :
3388
3379
return - EFAULT ;
3389
3380
}
3390
3381
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
+
3391
3418
/**
3392
3419
* bpf_strnchr - Find a character in a length limited string
3393
3420
* @s__ign: The string to be searched
@@ -3832,6 +3859,7 @@ BTF_ID_FLAGS(func, bpf_iter_dmabuf_destroy, KF_ITER_DESTROY | KF_SLEEPABLE)
3832
3859
#endif
3833
3860
BTF_ID_FLAGS (func , __bpf_trap )
3834
3861
BTF_ID_FLAGS (func , bpf_strcmp );
3862
+ BTF_ID_FLAGS (func , bpf_strcasecmp );
3835
3863
BTF_ID_FLAGS (func , bpf_strchr );
3836
3864
BTF_ID_FLAGS (func , bpf_strchrnul );
3837
3865
BTF_ID_FLAGS (func , bpf_strnchr );
0 commit comments