@@ -63,8 +63,8 @@ int s1, s2, c1, c2, p1, p2;
63
63
int test_cnt ;
64
64
int passed ;
65
65
int failed ;
66
- int map_fd [8 ];
67
- struct bpf_map * maps [8 ];
66
+ int map_fd [9 ];
67
+ struct bpf_map * maps [9 ];
68
68
int prog_fd [11 ];
69
69
70
70
int txmsg_pass ;
@@ -79,7 +79,10 @@ int txmsg_end_push;
79
79
int txmsg_start_pop ;
80
80
int txmsg_pop ;
81
81
int txmsg_ingress ;
82
- int txmsg_skb ;
82
+ int txmsg_redir_skb ;
83
+ int txmsg_ktls_skb ;
84
+ int txmsg_ktls_skb_drop ;
85
+ int txmsg_ktls_skb_redir ;
83
86
int ktls ;
84
87
int peek_flag ;
85
88
@@ -104,7 +107,7 @@ static const struct option long_options[] = {
104
107
{"txmsg_start_pop" , required_argument , NULL , 'w' },
105
108
{"txmsg_pop" , required_argument , NULL , 'x' },
106
109
{"txmsg_ingress" , no_argument , & txmsg_ingress , 1 },
107
- {"txmsg_skb " , no_argument , & txmsg_skb , 1 },
110
+ {"txmsg_redir_skb " , no_argument , & txmsg_redir_skb , 1 },
108
111
{"ktls" , no_argument , & ktls , 1 },
109
112
{"peek" , no_argument , & peek_flag , 1 },
110
113
{"whitelist" , required_argument , NULL , 'n' },
@@ -169,7 +172,8 @@ static void test_reset(void)
169
172
txmsg_start_push = txmsg_end_push = 0 ;
170
173
txmsg_pass = txmsg_drop = txmsg_redir = 0 ;
171
174
txmsg_apply = txmsg_cork = 0 ;
172
- txmsg_ingress = txmsg_skb = 0 ;
175
+ txmsg_ingress = txmsg_redir_skb = 0 ;
176
+ txmsg_ktls_skb = txmsg_ktls_skb_drop = txmsg_ktls_skb_redir = 0 ;
173
177
}
174
178
175
179
static int test_start_subtest (const struct _test * t , struct sockmap_options * o )
@@ -502,14 +506,41 @@ static int msg_alloc_iov(struct msghdr *msg,
502
506
503
507
static int msg_verify_data (struct msghdr * msg , int size , int chunk_sz )
504
508
{
505
- int i , j , bytes_cnt = 0 ;
509
+ int i , j = 0 , bytes_cnt = 0 ;
506
510
unsigned char k = 0 ;
507
511
508
512
for (i = 0 ; i < msg -> msg_iovlen ; i ++ ) {
509
513
unsigned char * d = msg -> msg_iov [i ].iov_base ;
510
514
511
- for (j = 0 ;
512
- j < msg -> msg_iov [i ].iov_len && size ; j ++ ) {
515
+ /* Special case test for skb ingress + ktls */
516
+ if (i == 0 && txmsg_ktls_skb ) {
517
+ if (msg -> msg_iov [i ].iov_len < 4 )
518
+ return - EIO ;
519
+ if (txmsg_ktls_skb_redir ) {
520
+ if (memcmp (& d [13 ], "PASS" , 4 ) != 0 ) {
521
+ fprintf (stderr ,
522
+ "detected redirect ktls_skb data error with skb ingress update @iov[%i]:%i \"%02x %02x %02x %02x\" != \"PASS\"\n" , i , 0 , d [13 ], d [14 ], d [15 ], d [16 ]);
523
+ return - EIO ;
524
+ }
525
+ d [13 ] = 0 ;
526
+ d [14 ] = 1 ;
527
+ d [15 ] = 2 ;
528
+ d [16 ] = 3 ;
529
+ j = 13 ;
530
+ } else if (txmsg_ktls_skb ) {
531
+ if (memcmp (d , "PASS" , 4 ) != 0 ) {
532
+ fprintf (stderr ,
533
+ "detected ktls_skb data error with skb ingress update @iov[%i]:%i \"%02x %02x %02x %02x\" != \"PASS\"\n" , i , 0 , d [0 ], d [1 ], d [2 ], d [3 ]);
534
+ return - EIO ;
535
+ }
536
+ d [0 ] = 0 ;
537
+ d [1 ] = 1 ;
538
+ d [2 ] = 2 ;
539
+ d [3 ] = 3 ;
540
+ }
541
+ }
542
+
543
+ for (; j < msg -> msg_iov [i ].iov_len && size ; j ++ ) {
513
544
if (d [j ] != k ++ ) {
514
545
fprintf (stderr ,
515
546
"detected data corruption @iov[%i]:%i %02x != %02x, %02x ?= %02x\n" ,
@@ -724,7 +755,7 @@ static int sendmsg_test(struct sockmap_options *opt)
724
755
rxpid = fork ();
725
756
if (rxpid == 0 ) {
726
757
iov_buf -= (txmsg_pop - txmsg_start_pop + 1 );
727
- if (opt -> drop_expected )
758
+ if (opt -> drop_expected || txmsg_ktls_skb_drop )
728
759
_exit (0 );
729
760
730
761
if (!iov_buf ) /* zero bytes sent case */
@@ -911,8 +942,28 @@ static int run_options(struct sockmap_options *options, int cg_fd, int test)
911
942
return err ;
912
943
}
913
944
945
+ /* Attach programs to TLS sockmap */
946
+ if (txmsg_ktls_skb ) {
947
+ err = bpf_prog_attach (prog_fd [0 ], map_fd [8 ],
948
+ BPF_SK_SKB_STREAM_PARSER , 0 );
949
+ if (err ) {
950
+ fprintf (stderr ,
951
+ "ERROR: bpf_prog_attach (TLS sockmap %i->%i): %d (%s)\n" ,
952
+ prog_fd [0 ], map_fd [8 ], err , strerror (errno ));
953
+ return err ;
954
+ }
955
+
956
+ err = bpf_prog_attach (prog_fd [2 ], map_fd [8 ],
957
+ BPF_SK_SKB_STREAM_VERDICT , 0 );
958
+ if (err ) {
959
+ fprintf (stderr , "ERROR: bpf_prog_attach (TLS sockmap): %d (%s)\n" ,
960
+ err , strerror (errno ));
961
+ return err ;
962
+ }
963
+ }
964
+
914
965
/* Attach to cgroups */
915
- err = bpf_prog_attach (prog_fd [2 ], cg_fd , BPF_CGROUP_SOCK_OPS , 0 );
966
+ err = bpf_prog_attach (prog_fd [3 ], cg_fd , BPF_CGROUP_SOCK_OPS , 0 );
916
967
if (err ) {
917
968
fprintf (stderr , "ERROR: bpf_prog_attach (groups): %d (%s)\n" ,
918
969
err , strerror (errno ));
@@ -928,15 +979,15 @@ static int run_options(struct sockmap_options *options, int cg_fd, int test)
928
979
929
980
/* Attach txmsg program to sockmap */
930
981
if (txmsg_pass )
931
- tx_prog_fd = prog_fd [3 ];
932
- else if (txmsg_redir )
933
982
tx_prog_fd = prog_fd [4 ];
934
- else if (txmsg_apply )
983
+ else if (txmsg_redir )
935
984
tx_prog_fd = prog_fd [5 ];
936
- else if (txmsg_cork )
985
+ else if (txmsg_apply )
937
986
tx_prog_fd = prog_fd [6 ];
938
- else if (txmsg_drop )
987
+ else if (txmsg_cork )
939
988
tx_prog_fd = prog_fd [7 ];
989
+ else if (txmsg_drop )
990
+ tx_prog_fd = prog_fd [8 ];
940
991
else
941
992
tx_prog_fd = 0 ;
942
993
@@ -1108,7 +1159,35 @@ static int run_options(struct sockmap_options *options, int cg_fd, int test)
1108
1159
}
1109
1160
}
1110
1161
1111
- if (txmsg_skb ) {
1162
+ if (txmsg_ktls_skb ) {
1163
+ int ingress = BPF_F_INGRESS ;
1164
+
1165
+ i = 0 ;
1166
+ err = bpf_map_update_elem (map_fd [8 ], & i , & p2 , BPF_ANY );
1167
+ if (err ) {
1168
+ fprintf (stderr ,
1169
+ "ERROR: bpf_map_update_elem (c1 sockmap): %d (%s)\n" ,
1170
+ err , strerror (errno ));
1171
+ }
1172
+
1173
+ if (txmsg_ktls_skb_redir ) {
1174
+ i = 1 ;
1175
+ err = bpf_map_update_elem (map_fd [7 ],
1176
+ & i , & ingress , BPF_ANY );
1177
+ if (err ) {
1178
+ fprintf (stderr ,
1179
+ "ERROR: bpf_map_update_elem (txmsg_ingress): %d (%s)\n" ,
1180
+ err , strerror (errno ));
1181
+ }
1182
+ }
1183
+
1184
+ if (txmsg_ktls_skb_drop ) {
1185
+ i = 1 ;
1186
+ err = bpf_map_update_elem (map_fd [7 ], & i , & i , BPF_ANY );
1187
+ }
1188
+ }
1189
+
1190
+ if (txmsg_redir_skb ) {
1112
1191
int skb_fd = (test == SENDMSG || test == SENDPAGE ) ?
1113
1192
p2 : p1 ;
1114
1193
int ingress = BPF_F_INGRESS ;
@@ -1123,8 +1202,7 @@ static int run_options(struct sockmap_options *options, int cg_fd, int test)
1123
1202
}
1124
1203
1125
1204
i = 3 ;
1126
- err = bpf_map_update_elem (map_fd [0 ],
1127
- & i , & skb_fd , BPF_ANY );
1205
+ err = bpf_map_update_elem (map_fd [0 ], & i , & skb_fd , BPF_ANY );
1128
1206
if (err ) {
1129
1207
fprintf (stderr ,
1130
1208
"ERROR: bpf_map_update_elem (c1 sockmap): %d (%s)\n" ,
@@ -1158,9 +1236,12 @@ static int run_options(struct sockmap_options *options, int cg_fd, int test)
1158
1236
fprintf (stderr , "unknown test\n" );
1159
1237
out :
1160
1238
/* Detatch and zero all the maps */
1161
- bpf_prog_detach2 (prog_fd [2 ], cg_fd , BPF_CGROUP_SOCK_OPS );
1239
+ bpf_prog_detach2 (prog_fd [3 ], cg_fd , BPF_CGROUP_SOCK_OPS );
1162
1240
bpf_prog_detach2 (prog_fd [0 ], map_fd [0 ], BPF_SK_SKB_STREAM_PARSER );
1163
1241
bpf_prog_detach2 (prog_fd [1 ], map_fd [0 ], BPF_SK_SKB_STREAM_VERDICT );
1242
+ bpf_prog_detach2 (prog_fd [0 ], map_fd [8 ], BPF_SK_SKB_STREAM_PARSER );
1243
+ bpf_prog_detach2 (prog_fd [2 ], map_fd [8 ], BPF_SK_SKB_STREAM_VERDICT );
1244
+
1164
1245
if (tx_prog_fd >= 0 )
1165
1246
bpf_prog_detach2 (tx_prog_fd , map_fd [1 ], BPF_SK_MSG_VERDICT );
1166
1247
@@ -1229,8 +1310,10 @@ static void test_options(char *options)
1229
1310
}
1230
1311
if (txmsg_ingress )
1231
1312
strncat (options , "ingress," , OPTSTRING );
1232
- if (txmsg_skb )
1233
- strncat (options , "skb," , OPTSTRING );
1313
+ if (txmsg_redir_skb )
1314
+ strncat (options , "redir_skb," , OPTSTRING );
1315
+ if (txmsg_ktls_skb )
1316
+ strncat (options , "ktls_skb," , OPTSTRING );
1234
1317
if (ktls )
1235
1318
strncat (options , "ktls," , OPTSTRING );
1236
1319
if (peek_flag )
@@ -1362,6 +1445,40 @@ static void test_txmsg_ingress_redir(int cgrp, struct sockmap_options *opt)
1362
1445
test_send (opt , cgrp );
1363
1446
}
1364
1447
1448
+ static void test_txmsg_skb (int cgrp , struct sockmap_options * opt )
1449
+ {
1450
+ bool data = opt -> data_test ;
1451
+ int k = ktls ;
1452
+
1453
+ opt -> data_test = true;
1454
+ ktls = 1 ;
1455
+
1456
+ txmsg_pass = txmsg_drop = 0 ;
1457
+ txmsg_ingress = txmsg_redir = 0 ;
1458
+ txmsg_ktls_skb = 1 ;
1459
+ txmsg_pass = 1 ;
1460
+
1461
+ /* Using data verification so ensure iov layout is
1462
+ * expected from test receiver side. e.g. has enough
1463
+ * bytes to write test code.
1464
+ */
1465
+ opt -> iov_length = 100 ;
1466
+ opt -> iov_count = 1 ;
1467
+ opt -> rate = 1 ;
1468
+ test_exec (cgrp , opt );
1469
+
1470
+ txmsg_ktls_skb_drop = 1 ;
1471
+ test_exec (cgrp , opt );
1472
+
1473
+ txmsg_ktls_skb_drop = 0 ;
1474
+ txmsg_ktls_skb_redir = 1 ;
1475
+ test_exec (cgrp , opt );
1476
+
1477
+ opt -> data_test = data ;
1478
+ ktls = k ;
1479
+ }
1480
+
1481
+
1365
1482
/* Test cork with hung data. This tests poor usage patterns where
1366
1483
* cork can leave data on the ring if user program is buggy and
1367
1484
* doesn't flush them somehow. They do take some time however
@@ -1542,11 +1659,13 @@ char *map_names[] = {
1542
1659
"sock_bytes" ,
1543
1660
"sock_redir_flags" ,
1544
1661
"sock_skb_opts" ,
1662
+ "tls_sock_map" ,
1545
1663
};
1546
1664
1547
1665
int prog_attach_type [] = {
1548
1666
BPF_SK_SKB_STREAM_PARSER ,
1549
1667
BPF_SK_SKB_STREAM_VERDICT ,
1668
+ BPF_SK_SKB_STREAM_VERDICT ,
1550
1669
BPF_CGROUP_SOCK_OPS ,
1551
1670
BPF_SK_MSG_VERDICT ,
1552
1671
BPF_SK_MSG_VERDICT ,
@@ -1558,6 +1677,7 @@ int prog_attach_type[] = {
1558
1677
};
1559
1678
1560
1679
int prog_type [] = {
1680
+ BPF_PROG_TYPE_SK_SKB ,
1561
1681
BPF_PROG_TYPE_SK_SKB ,
1562
1682
BPF_PROG_TYPE_SK_SKB ,
1563
1683
BPF_PROG_TYPE_SOCK_OPS ,
@@ -1620,6 +1740,7 @@ struct _test test[] = {
1620
1740
{"txmsg test redirect" , test_txmsg_redir },
1621
1741
{"txmsg test drop" , test_txmsg_drop },
1622
1742
{"txmsg test ingress redirect" , test_txmsg_ingress_redir },
1743
+ {"txmsg test skb" , test_txmsg_skb },
1623
1744
{"txmsg test apply" , test_txmsg_apply },
1624
1745
{"txmsg test cork" , test_txmsg_cork },
1625
1746
{"txmsg test hanging corks" , test_txmsg_cork_hangs },
0 commit comments