@@ -245,6 +245,11 @@ static const struct mctp_test_bind_setup bind_addrany_net2_type2 = {
245
245
.bind_addr = MCTP_ADDR_ANY , .bind_net = 2 , .bind_type = 2 ,
246
246
};
247
247
248
+ static const struct mctp_test_bind_setup bind_addrany_net2_type1_peer9 = {
249
+ .bind_addr = MCTP_ADDR_ANY , .bind_net = 2 , .bind_type = 1 ,
250
+ .have_peer = true, .peer_addr = 9 , .peer_net = 2 ,
251
+ };
252
+
248
253
struct mctp_bind_pair_test {
249
254
const struct mctp_test_bind_setup * bind1 ;
250
255
const struct mctp_test_bind_setup * bind2 ;
@@ -278,19 +283,50 @@ static const struct mctp_bind_pair_test mctp_bind_pair_tests[] = {
278
283
* vs ADDR_ANY, explicit default net 1, OK
279
284
*/
280
285
{ & bind_addrany_netdefault_type1 , & bind_addrany_net1_type1 , 0 },
286
+
287
+ /* specific remote peer doesn't conflict with any-peer bind */
288
+ { & bind_addrany_net2_type1_peer9 , & bind_addrany_net2_type1 , 0 },
289
+
290
+ /* bind() NET_ANY is allowed with a connect() net */
291
+ { & bind_addrany_net2_type1_peer9 , & bind_addrany_netdefault_type1 , 0 },
281
292
};
282
293
283
294
static void mctp_bind_pair_desc (const struct mctp_bind_pair_test * t , char * desc )
284
295
{
296
+ char peer1 [25 ] = {0 }, peer2 [25 ] = {0 };
297
+
298
+ if (t -> bind1 -> have_peer )
299
+ snprintf (peer1 , sizeof (peer1 ), ", peer %d net %d" ,
300
+ t -> bind1 -> peer_addr , t -> bind1 -> peer_net );
301
+ if (t -> bind2 -> have_peer )
302
+ snprintf (peer2 , sizeof (peer2 ), ", peer %d net %d" ,
303
+ t -> bind2 -> peer_addr , t -> bind2 -> peer_net );
304
+
285
305
snprintf (desc , KUNIT_PARAM_DESC_SIZE ,
286
- "{bind(addr %d, type %d, net %d)} {bind(addr %d, type %d, net %d)} -> error %d" ,
287
- t -> bind1 -> bind_addr , t -> bind1 -> bind_type , t -> bind1 -> bind_net ,
288
- t -> bind2 -> bind_addr , t -> bind2 -> bind_type , t -> bind2 -> bind_net ,
289
- t -> error );
306
+ "{bind(addr %d, type %d, net %d%s)} {bind(addr %d, type %d, net %d%s)} -> error %d" ,
307
+ t -> bind1 -> bind_addr , t -> bind1 -> bind_type ,
308
+ t -> bind1 -> bind_net , peer1 ,
309
+ t -> bind2 -> bind_addr , t -> bind2 -> bind_type ,
310
+ t -> bind2 -> bind_net , peer2 , t -> error );
290
311
}
291
312
292
313
KUNIT_ARRAY_PARAM (mctp_bind_pair , mctp_bind_pair_tests , mctp_bind_pair_desc );
293
314
315
+ static void mctp_test_bind_invalid (struct kunit * test )
316
+ {
317
+ struct socket * sock ;
318
+ int rc ;
319
+
320
+ /* bind() fails if the bind() vs connect() networks mismatch. */
321
+ const struct mctp_test_bind_setup bind_connect_net_mismatch = {
322
+ .bind_addr = MCTP_ADDR_ANY , .bind_net = 1 , .bind_type = 1 ,
323
+ .have_peer = true, .peer_addr = 9 , .peer_net = 2 ,
324
+ };
325
+ mctp_test_bind_run (test , & bind_connect_net_mismatch , & rc , & sock );
326
+ KUNIT_EXPECT_EQ (test , - rc , EINVAL );
327
+ sock_release (sock );
328
+ }
329
+
294
330
static int
295
331
mctp_test_bind_conflicts_inner (struct kunit * test ,
296
332
const struct mctp_test_bind_setup * bind1 ,
@@ -348,6 +384,7 @@ static struct kunit_case mctp_test_cases[] = {
348
384
KUNIT_CASE (mctp_test_sock_sendmsg_extaddr ),
349
385
KUNIT_CASE (mctp_test_sock_recvmsg_extaddr ),
350
386
KUNIT_CASE_PARAM (mctp_test_bind_conflicts , mctp_bind_pair_gen_params ),
387
+ KUNIT_CASE (mctp_test_bind_invalid ),
351
388
{}
352
389
};
353
390
0 commit comments