@@ -240,6 +240,80 @@ static void test_sockmap_ktls_tx_cork(int family, int sotype, bool push)
240240 test_sockmap_ktls__destroy (skel );
241241}
242242
243+ static void test_sockmap_ktls_tx_no_buf (int family , int sotype , bool push )
244+ {
245+ int c = -1 , p = -1 , one = 1 , two = 2 ;
246+ struct test_sockmap_ktls * skel ;
247+ unsigned char * data = NULL ;
248+ struct msghdr msg = {0 };
249+ struct iovec iov [2 ];
250+ int prog_fd , map_fd ;
251+ int txrx_buf = 1024 ;
252+ int iov_length = 8192 ;
253+ int err ;
254+
255+ skel = test_sockmap_ktls__open_and_load ();
256+ if (!ASSERT_TRUE (skel , "open ktls skel" ))
257+ return ;
258+
259+ err = create_pair (family , sotype , & c , & p );
260+ if (!ASSERT_OK (err , "create_pair()" ))
261+ goto out ;
262+
263+ err = setsockopt (c , SOL_SOCKET , SO_RCVBUFFORCE , & txrx_buf , sizeof (int ));
264+ err |= setsockopt (p , SOL_SOCKET , SO_SNDBUFFORCE , & txrx_buf , sizeof (int ));
265+ if (!ASSERT_OK (err , "set buf limit" ))
266+ goto out ;
267+
268+ prog_fd = bpf_program__fd (skel -> progs .prog_sk_policy_redir );
269+ map_fd = bpf_map__fd (skel -> maps .sock_map );
270+
271+ err = bpf_prog_attach (prog_fd , map_fd , BPF_SK_MSG_VERDICT , 0 );
272+ if (!ASSERT_OK (err , "bpf_prog_attach sk msg" ))
273+ goto out ;
274+
275+ err = bpf_map_update_elem (map_fd , & one , & c , BPF_NOEXIST );
276+ if (!ASSERT_OK (err , "bpf_map_update_elem(c)" ))
277+ goto out ;
278+
279+ err = bpf_map_update_elem (map_fd , & two , & p , BPF_NOEXIST );
280+ if (!ASSERT_OK (err , "bpf_map_update_elem(p)" ))
281+ goto out ;
282+
283+ skel -> bss -> apply_bytes = 1024 ;
284+
285+ err = init_ktls_pairs (c , p );
286+ if (!ASSERT_OK (err , "init_ktls_pairs(c, p)" ))
287+ goto out ;
288+
289+ data = calloc (iov_length , sizeof (char ));
290+ if (!data )
291+ goto out ;
292+
293+ iov [0 ].iov_base = data ;
294+ iov [0 ].iov_len = iov_length ;
295+ iov [1 ].iov_base = data ;
296+ iov [1 ].iov_len = iov_length ;
297+ msg .msg_iov = iov ;
298+ msg .msg_iovlen = 2 ;
299+
300+ for (;;) {
301+ err = sendmsg (c , & msg , MSG_DONTWAIT );
302+ if (err <= 0 )
303+ break ;
304+ }
305+
306+ out :
307+ if (data )
308+ free (data );
309+ if (c != -1 )
310+ close (c );
311+ if (p != -1 )
312+ close (p );
313+
314+ test_sockmap_ktls__destroy (skel );
315+ }
316+
243317static void run_tests (int family , enum bpf_map_type map_type )
244318{
245319 int map ;
@@ -262,6 +336,8 @@ static void run_ktls_test(int family, int sotype)
262336 test_sockmap_ktls_tx_cork (family , sotype , false);
263337 if (test__start_subtest ("tls tx cork with push" ))
264338 test_sockmap_ktls_tx_cork (family , sotype , true);
339+ if (test__start_subtest ("tls tx egress with no buf" ))
340+ test_sockmap_ktls_tx_no_buf (family , sotype , true);
265341}
266342
267343void test_sockmap_ktls (void )
0 commit comments