@@ -1042,6 +1042,59 @@ static void test_sockmap_vsock_unconnected(void)
1042
1042
xclose (map );
1043
1043
}
1044
1044
1045
+ void * close_thread (void * arg )
1046
+ {
1047
+ int * fd = (int * )arg ;
1048
+
1049
+ sleep (1 );
1050
+ close (* fd );
1051
+ * fd = -1 ;
1052
+ return NULL ;
1053
+ }
1054
+
1055
+ void test_sockmap_with_close_on_write (int family , int sotype )
1056
+ {
1057
+ struct test_sockmap_pass_prog * skel ;
1058
+ int err , map , verdict ;
1059
+ pthread_t tid ;
1060
+ int zero = 0 ;
1061
+ int c = -1 , p = -1 ;
1062
+
1063
+ skel = test_sockmap_pass_prog__open_and_load ();
1064
+ if (!ASSERT_OK_PTR (skel , "open_and_load" ))
1065
+ return ;
1066
+
1067
+ verdict = bpf_program__fd (skel -> progs .prog_skb_verdict );
1068
+ map = bpf_map__fd (skel -> maps .sock_map_rx );
1069
+
1070
+ err = bpf_prog_attach (verdict , map , BPF_SK_SKB_STREAM_VERDICT , 0 );
1071
+ if (!ASSERT_OK (err , "bpf_prog_attach" ))
1072
+ goto out ;
1073
+
1074
+ err = create_pair (family , sotype , & c , & p );
1075
+ if (!ASSERT_OK (err , "create_pair" ))
1076
+ goto out ;
1077
+
1078
+ err = bpf_map_update_elem (map , & zero , & p , BPF_ANY );
1079
+ if (!ASSERT_OK (err , "bpf_map_update_elem" ))
1080
+ goto out ;
1081
+
1082
+ err = pthread_create (& tid , 0 , close_thread , & p );
1083
+ if (!ASSERT_OK (err , "pthread_create" ))
1084
+ goto out ;
1085
+
1086
+ while (p > 0 )
1087
+ send (c , "a" , 1 , MSG_NOSIGNAL );
1088
+
1089
+ pthread_join (tid , NULL );
1090
+ out :
1091
+ if (c > 0 )
1092
+ close (c );
1093
+ if (p > 0 )
1094
+ close (p );
1095
+ test_sockmap_pass_prog__destroy (skel );
1096
+ }
1097
+
1045
1098
void test_sockmap_basic (void )
1046
1099
{
1047
1100
if (test__start_subtest ("sockmap create_update_free" ))
@@ -1108,4 +1161,11 @@ void test_sockmap_basic(void)
1108
1161
test_sockmap_skb_verdict_vsock_poll ();
1109
1162
if (test__start_subtest ("sockmap vsock unconnected" ))
1110
1163
test_sockmap_vsock_unconnected ();
1164
+ if (test__start_subtest ("sockmap with write on close" )) {
1165
+ test_sockmap_with_close_on_write (AF_UNIX , SOCK_STREAM );
1166
+ test_sockmap_with_close_on_write (AF_UNIX , SOCK_DGRAM );
1167
+ test_sockmap_with_close_on_write (AF_INET , SOCK_STREAM );
1168
+ test_sockmap_with_close_on_write (AF_INET , SOCK_DGRAM );
1169
+ test_sockmap_with_close_on_write (AF_VSOCK , SOCK_STREAM );
1170
+ }
1111
1171
}
0 commit comments