@@ -1405,7 +1405,7 @@ static void test_map_rdonly(void)
1405
1405
close (fd );
1406
1406
}
1407
1407
1408
- static void test_map_wronly (void )
1408
+ static void test_map_wronly_hash (void )
1409
1409
{
1410
1410
int fd , key = 0 , value = 0 ;
1411
1411
@@ -1429,6 +1429,44 @@ static void test_map_wronly(void)
1429
1429
close (fd );
1430
1430
}
1431
1431
1432
+ static void test_map_wronly_stack_or_queue (enum bpf_map_type map_type )
1433
+ {
1434
+ int fd , value = 0 ;
1435
+
1436
+ assert (map_type == BPF_MAP_TYPE_QUEUE ||
1437
+ map_type == BPF_MAP_TYPE_STACK );
1438
+ fd = bpf_create_map (map_type , 0 , sizeof (value ), MAP_SIZE ,
1439
+ map_flags | BPF_F_WRONLY );
1440
+ /* Stack/Queue maps do not support BPF_F_NO_PREALLOC */
1441
+ if (map_flags & BPF_F_NO_PREALLOC ) {
1442
+ assert (fd < 0 && errno == EINVAL );
1443
+ return ;
1444
+ }
1445
+ if (fd < 0 ) {
1446
+ printf ("Failed to create map '%s'!\n" , strerror (errno ));
1447
+ exit (1 );
1448
+ }
1449
+
1450
+ value = 1234 ;
1451
+ assert (bpf_map_update_elem (fd , NULL , & value , BPF_ANY ) == 0 );
1452
+
1453
+ /* Peek element should fail */
1454
+ assert (bpf_map_lookup_elem (fd , NULL , & value ) == -1 && errno == EPERM );
1455
+
1456
+ /* Pop element should fail */
1457
+ assert (bpf_map_lookup_and_delete_elem (fd , NULL , & value ) == -1 &&
1458
+ errno == EPERM );
1459
+
1460
+ close (fd );
1461
+ }
1462
+
1463
+ static void test_map_wronly (void )
1464
+ {
1465
+ test_map_wronly_hash ();
1466
+ test_map_wronly_stack_or_queue (BPF_MAP_TYPE_STACK );
1467
+ test_map_wronly_stack_or_queue (BPF_MAP_TYPE_QUEUE );
1468
+ }
1469
+
1432
1470
static void prepare_reuseport_grp (int type , int map_fd , size_t map_elem_size ,
1433
1471
__s64 * fds64 , __u64 * sk_cookies ,
1434
1472
unsigned int n )
0 commit comments