• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include <kunit/test.h>
4 
5 #include "utils.h"
6 
7 struct mctp_test_route {
8 	struct mctp_route	rt;
9 	struct sk_buff_head	pkts;
10 };
11 
mctp_test_route_output(struct mctp_route * rt,struct sk_buff * skb)12 static int mctp_test_route_output(struct mctp_route *rt, struct sk_buff *skb)
13 {
14 	struct mctp_test_route *test_rt = container_of(rt, struct mctp_test_route, rt);
15 
16 	skb_queue_tail(&test_rt->pkts, skb);
17 
18 	return 0;
19 }
20 
21 /* local version of mctp_route_alloc() */
mctp_route_test_alloc(void)22 static struct mctp_test_route *mctp_route_test_alloc(void)
23 {
24 	struct mctp_test_route *rt;
25 
26 	rt = kzalloc(sizeof(*rt), GFP_KERNEL);
27 	if (!rt)
28 		return NULL;
29 
30 	INIT_LIST_HEAD(&rt->rt.list);
31 	refcount_set(&rt->rt.refs, 1);
32 	rt->rt.output = mctp_test_route_output;
33 
34 	skb_queue_head_init(&rt->pkts);
35 
36 	return rt;
37 }
38 
mctp_test_create_route(struct net * net,struct mctp_dev * dev,mctp_eid_t eid,unsigned int mtu)39 static struct mctp_test_route *mctp_test_create_route(struct net *net,
40 						      struct mctp_dev *dev,
41 						      mctp_eid_t eid,
42 						      unsigned int mtu)
43 {
44 	struct mctp_test_route *rt;
45 
46 	rt = mctp_route_test_alloc();
47 	if (!rt)
48 		return NULL;
49 
50 	rt->rt.min = eid;
51 	rt->rt.max = eid;
52 	rt->rt.mtu = mtu;
53 	rt->rt.type = RTN_UNSPEC;
54 	if (dev)
55 		mctp_dev_hold(dev);
56 	rt->rt.dev = dev;
57 
58 	list_add_rcu(&rt->rt.list, &net->mctp.routes);
59 
60 	return rt;
61 }
62 
mctp_test_route_destroy(struct kunit * test,struct mctp_test_route * rt)63 static void mctp_test_route_destroy(struct kunit *test,
64 				    struct mctp_test_route *rt)
65 {
66 	unsigned int refs;
67 
68 	rtnl_lock();
69 	list_del_rcu(&rt->rt.list);
70 	rtnl_unlock();
71 
72 	skb_queue_purge(&rt->pkts);
73 	if (rt->rt.dev)
74 		mctp_dev_put(rt->rt.dev);
75 
76 	refs = refcount_read(&rt->rt.refs);
77 	KUNIT_ASSERT_EQ_MSG(test, refs, 1, "route ref imbalance");
78 
79 	kfree_rcu(&rt->rt, rcu);
80 }
81 
mctp_test_create_skb(const struct mctp_hdr * hdr,unsigned int data_len)82 static struct sk_buff *mctp_test_create_skb(const struct mctp_hdr *hdr,
83 					    unsigned int data_len)
84 {
85 	size_t hdr_len = sizeof(*hdr);
86 	struct sk_buff *skb;
87 	unsigned int i;
88 	u8 *buf;
89 
90 	skb = alloc_skb(hdr_len + data_len, GFP_KERNEL);
91 	if (!skb)
92 		return NULL;
93 
94 	memcpy(skb_put(skb, hdr_len), hdr, hdr_len);
95 
96 	buf = skb_put(skb, data_len);
97 	for (i = 0; i < data_len; i++)
98 		buf[i] = i & 0xff;
99 
100 	return skb;
101 }
102 
__mctp_test_create_skb_data(const struct mctp_hdr * hdr,const void * data,size_t data_len)103 static struct sk_buff *__mctp_test_create_skb_data(const struct mctp_hdr *hdr,
104 						   const void *data,
105 						   size_t data_len)
106 {
107 	size_t hdr_len = sizeof(*hdr);
108 	struct sk_buff *skb;
109 
110 	skb = alloc_skb(hdr_len + data_len, GFP_KERNEL);
111 	if (!skb)
112 		return NULL;
113 
114 	memcpy(skb_put(skb, hdr_len), hdr, hdr_len);
115 	memcpy(skb_put(skb, data_len), data, data_len);
116 
117 	return skb;
118 }
119 
120 #define mctp_test_create_skb_data(h, d) \
121 	__mctp_test_create_skb_data(h, d, sizeof(*d))
122 
123 struct mctp_frag_test {
124 	unsigned int mtu;
125 	unsigned int msgsize;
126 	unsigned int n_frags;
127 };
128 
mctp_test_fragment(struct kunit * test)129 static void mctp_test_fragment(struct kunit *test)
130 {
131 	const struct mctp_frag_test *params;
132 	int rc, i, n, mtu, msgsize;
133 	struct mctp_test_route *rt;
134 	struct sk_buff *skb;
135 	struct mctp_hdr hdr;
136 	u8 seq;
137 
138 	params = test->param_value;
139 	mtu = params->mtu;
140 	msgsize = params->msgsize;
141 
142 	hdr.ver = 1;
143 	hdr.src = 8;
144 	hdr.dest = 10;
145 	hdr.flags_seq_tag = MCTP_HDR_FLAG_TO;
146 
147 	skb = mctp_test_create_skb(&hdr, msgsize);
148 	KUNIT_ASSERT_TRUE(test, skb);
149 
150 	rt = mctp_test_create_route(&init_net, NULL, 10, mtu);
151 	KUNIT_ASSERT_TRUE(test, rt);
152 
153 	rc = mctp_do_fragment_route(&rt->rt, skb, mtu, MCTP_TAG_OWNER);
154 	KUNIT_EXPECT_FALSE(test, rc);
155 
156 	n = rt->pkts.qlen;
157 
158 	KUNIT_EXPECT_EQ(test, n, params->n_frags);
159 
160 	for (i = 0;; i++) {
161 		struct mctp_hdr *hdr2;
162 		struct sk_buff *skb2;
163 		u8 tag_mask, seq2;
164 		bool first, last;
165 
166 		first = i == 0;
167 		last = i == (n - 1);
168 
169 		skb2 = skb_dequeue(&rt->pkts);
170 
171 		if (!skb2)
172 			break;
173 
174 		hdr2 = mctp_hdr(skb2);
175 
176 		tag_mask = MCTP_HDR_TAG_MASK | MCTP_HDR_FLAG_TO;
177 
178 		KUNIT_EXPECT_EQ(test, hdr2->ver, hdr.ver);
179 		KUNIT_EXPECT_EQ(test, hdr2->src, hdr.src);
180 		KUNIT_EXPECT_EQ(test, hdr2->dest, hdr.dest);
181 		KUNIT_EXPECT_EQ(test, hdr2->flags_seq_tag & tag_mask,
182 				hdr.flags_seq_tag & tag_mask);
183 
184 		KUNIT_EXPECT_EQ(test,
185 				!!(hdr2->flags_seq_tag & MCTP_HDR_FLAG_SOM), first);
186 		KUNIT_EXPECT_EQ(test,
187 				!!(hdr2->flags_seq_tag & MCTP_HDR_FLAG_EOM), last);
188 
189 		seq2 = (hdr2->flags_seq_tag >> MCTP_HDR_SEQ_SHIFT) &
190 			MCTP_HDR_SEQ_MASK;
191 
192 		if (first) {
193 			seq = seq2;
194 		} else {
195 			seq++;
196 			KUNIT_EXPECT_EQ(test, seq2, seq & MCTP_HDR_SEQ_MASK);
197 		}
198 
199 		if (!last)
200 			KUNIT_EXPECT_EQ(test, skb2->len, mtu);
201 		else
202 			KUNIT_EXPECT_LE(test, skb2->len, mtu);
203 
204 		kfree_skb(skb2);
205 	}
206 
207 	mctp_test_route_destroy(test, rt);
208 }
209 
210 static const struct mctp_frag_test mctp_frag_tests[] = {
211 	{.mtu = 68, .msgsize = 63, .n_frags = 1},
212 	{.mtu = 68, .msgsize = 64, .n_frags = 1},
213 	{.mtu = 68, .msgsize = 65, .n_frags = 2},
214 	{.mtu = 68, .msgsize = 66, .n_frags = 2},
215 	{.mtu = 68, .msgsize = 127, .n_frags = 2},
216 	{.mtu = 68, .msgsize = 128, .n_frags = 2},
217 	{.mtu = 68, .msgsize = 129, .n_frags = 3},
218 	{.mtu = 68, .msgsize = 130, .n_frags = 3},
219 };
220 
mctp_frag_test_to_desc(const struct mctp_frag_test * t,char * desc)221 static void mctp_frag_test_to_desc(const struct mctp_frag_test *t, char *desc)
222 {
223 	sprintf(desc, "mtu %d len %d -> %d frags",
224 		t->msgsize, t->mtu, t->n_frags);
225 }
226 
227 KUNIT_ARRAY_PARAM(mctp_frag, mctp_frag_tests, mctp_frag_test_to_desc);
228 
229 struct mctp_rx_input_test {
230 	struct mctp_hdr hdr;
231 	bool input;
232 };
233 
mctp_test_rx_input(struct kunit * test)234 static void mctp_test_rx_input(struct kunit *test)
235 {
236 	const struct mctp_rx_input_test *params;
237 	struct mctp_test_route *rt;
238 	struct mctp_test_dev *dev;
239 	struct sk_buff *skb;
240 
241 	params = test->param_value;
242 
243 	dev = mctp_test_create_dev();
244 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
245 
246 	rt = mctp_test_create_route(&init_net, dev->mdev, 8, 68);
247 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, rt);
248 
249 	skb = mctp_test_create_skb(&params->hdr, 1);
250 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, skb);
251 
252 	__mctp_cb(skb);
253 
254 	mctp_pkttype_receive(skb, dev->ndev, &mctp_packet_type, NULL);
255 
256 	KUNIT_EXPECT_EQ(test, !!rt->pkts.qlen, params->input);
257 
258 	mctp_test_route_destroy(test, rt);
259 	mctp_test_destroy_dev(dev);
260 }
261 
262 #define RX_HDR(_ver, _src, _dest, _fst) \
263 	{ .ver = _ver, .src = _src, .dest = _dest, .flags_seq_tag = _fst }
264 
265 /* we have a route for EID 8 only */
266 static const struct mctp_rx_input_test mctp_rx_input_tests[] = {
267 	{ .hdr = RX_HDR(1, 10, 8, 0), .input = true },
268 	{ .hdr = RX_HDR(1, 10, 9, 0), .input = false }, /* no input route */
269 	{ .hdr = RX_HDR(2, 10, 8, 0), .input = false }, /* invalid version */
270 };
271 
mctp_rx_input_test_to_desc(const struct mctp_rx_input_test * t,char * desc)272 static void mctp_rx_input_test_to_desc(const struct mctp_rx_input_test *t,
273 				       char *desc)
274 {
275 	sprintf(desc, "{%x,%x,%x,%x}", t->hdr.ver, t->hdr.src, t->hdr.dest,
276 		t->hdr.flags_seq_tag);
277 }
278 
279 KUNIT_ARRAY_PARAM(mctp_rx_input, mctp_rx_input_tests,
280 		  mctp_rx_input_test_to_desc);
281 
282 /* set up a local dev, route on EID 8, and a socket listening on type 0 */
__mctp_route_test_init(struct kunit * test,struct mctp_test_dev ** devp,struct mctp_test_route ** rtp,struct socket ** sockp)283 static void __mctp_route_test_init(struct kunit *test,
284 				   struct mctp_test_dev **devp,
285 				   struct mctp_test_route **rtp,
286 				   struct socket **sockp)
287 {
288 	struct sockaddr_mctp addr = {0};
289 	struct mctp_test_route *rt;
290 	struct mctp_test_dev *dev;
291 	struct socket *sock;
292 	int rc;
293 
294 	dev = mctp_test_create_dev();
295 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
296 
297 	rt = mctp_test_create_route(&init_net, dev->mdev, 8, 68);
298 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, rt);
299 
300 	rc = sock_create_kern(&init_net, AF_MCTP, SOCK_DGRAM, 0, &sock);
301 	KUNIT_ASSERT_EQ(test, rc, 0);
302 
303 	addr.smctp_family = AF_MCTP;
304 	addr.smctp_network = MCTP_NET_ANY;
305 	addr.smctp_addr.s_addr = 8;
306 	addr.smctp_type = 0;
307 	rc = kernel_bind(sock, (struct sockaddr *)&addr, sizeof(addr));
308 	KUNIT_ASSERT_EQ(test, rc, 0);
309 
310 	*rtp = rt;
311 	*devp = dev;
312 	*sockp = sock;
313 }
314 
__mctp_route_test_fini(struct kunit * test,struct mctp_test_dev * dev,struct mctp_test_route * rt,struct socket * sock)315 static void __mctp_route_test_fini(struct kunit *test,
316 				   struct mctp_test_dev *dev,
317 				   struct mctp_test_route *rt,
318 				   struct socket *sock)
319 {
320 	sock_release(sock);
321 	mctp_test_route_destroy(test, rt);
322 	mctp_test_destroy_dev(dev);
323 }
324 
325 struct mctp_route_input_sk_test {
326 	struct mctp_hdr hdr;
327 	u8 type;
328 	bool deliver;
329 };
330 
mctp_test_route_input_sk(struct kunit * test)331 static void mctp_test_route_input_sk(struct kunit *test)
332 {
333 	const struct mctp_route_input_sk_test *params;
334 	struct sk_buff *skb, *skb2;
335 	struct mctp_test_route *rt;
336 	struct mctp_test_dev *dev;
337 	struct socket *sock;
338 	int rc;
339 
340 	params = test->param_value;
341 
342 	__mctp_route_test_init(test, &dev, &rt, &sock);
343 
344 	skb = mctp_test_create_skb_data(&params->hdr, &params->type);
345 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, skb);
346 
347 	skb->dev = dev->ndev;
348 	__mctp_cb(skb);
349 
350 	rc = mctp_route_input(&rt->rt, skb);
351 
352 	if (params->deliver) {
353 		KUNIT_EXPECT_EQ(test, rc, 0);
354 
355 		skb2 = skb_recv_datagram(sock->sk, MSG_DONTWAIT, &rc);
356 		KUNIT_EXPECT_NOT_ERR_OR_NULL(test, skb2);
357 		KUNIT_EXPECT_EQ(test, skb->len, 1);
358 
359 		skb_free_datagram(sock->sk, skb2);
360 
361 	} else {
362 		KUNIT_EXPECT_NE(test, rc, 0);
363 		skb2 = skb_recv_datagram(sock->sk, MSG_DONTWAIT, &rc);
364 		KUNIT_EXPECT_NULL(test, skb2);
365 	}
366 
367 	__mctp_route_test_fini(test, dev, rt, sock);
368 }
369 
370 #define FL_S	(MCTP_HDR_FLAG_SOM)
371 #define FL_E	(MCTP_HDR_FLAG_EOM)
372 #define FL_TO	(MCTP_HDR_FLAG_TO)
373 #define FL_T(t)	((t) & MCTP_HDR_TAG_MASK)
374 
375 static const struct mctp_route_input_sk_test mctp_route_input_sk_tests[] = {
376 	{ .hdr = RX_HDR(1, 10, 8, FL_S | FL_E | FL_TO), .type = 0, .deliver = true },
377 	{ .hdr = RX_HDR(1, 10, 8, FL_S | FL_E | FL_TO), .type = 1, .deliver = false },
378 	{ .hdr = RX_HDR(1, 10, 8, FL_S | FL_E), .type = 0, .deliver = false },
379 	{ .hdr = RX_HDR(1, 10, 8, FL_E | FL_TO), .type = 0, .deliver = false },
380 	{ .hdr = RX_HDR(1, 10, 8, FL_TO), .type = 0, .deliver = false },
381 	{ .hdr = RX_HDR(1, 10, 8, 0), .type = 0, .deliver = false },
382 };
383 
mctp_route_input_sk_to_desc(const struct mctp_route_input_sk_test * t,char * desc)384 static void mctp_route_input_sk_to_desc(const struct mctp_route_input_sk_test *t,
385 					char *desc)
386 {
387 	sprintf(desc, "{%x,%x,%x,%x} type %d", t->hdr.ver, t->hdr.src,
388 		t->hdr.dest, t->hdr.flags_seq_tag, t->type);
389 }
390 
391 KUNIT_ARRAY_PARAM(mctp_route_input_sk, mctp_route_input_sk_tests,
392 		  mctp_route_input_sk_to_desc);
393 
394 struct mctp_route_input_sk_reasm_test {
395 	const char *name;
396 	struct mctp_hdr hdrs[4];
397 	int n_hdrs;
398 	int rx_len;
399 };
400 
mctp_test_route_input_sk_reasm(struct kunit * test)401 static void mctp_test_route_input_sk_reasm(struct kunit *test)
402 {
403 	const struct mctp_route_input_sk_reasm_test *params;
404 	struct sk_buff *skb, *skb2;
405 	struct mctp_test_route *rt;
406 	struct mctp_test_dev *dev;
407 	struct socket *sock;
408 	int i, rc;
409 	u8 c;
410 
411 	params = test->param_value;
412 
413 	__mctp_route_test_init(test, &dev, &rt, &sock);
414 
415 	for (i = 0; i < params->n_hdrs; i++) {
416 		c = i;
417 		skb = mctp_test_create_skb_data(&params->hdrs[i], &c);
418 		KUNIT_ASSERT_NOT_ERR_OR_NULL(test, skb);
419 
420 		skb->dev = dev->ndev;
421 		__mctp_cb(skb);
422 
423 		rc = mctp_route_input(&rt->rt, skb);
424 	}
425 
426 	skb2 = skb_recv_datagram(sock->sk, MSG_DONTWAIT, &rc);
427 
428 	if (params->rx_len) {
429 		KUNIT_EXPECT_NOT_ERR_OR_NULL(test, skb2);
430 		KUNIT_EXPECT_EQ(test, skb2->len, params->rx_len);
431 		skb_free_datagram(sock->sk, skb2);
432 
433 	} else {
434 		KUNIT_EXPECT_NULL(test, skb2);
435 	}
436 
437 	__mctp_route_test_fini(test, dev, rt, sock);
438 }
439 
440 #define RX_FRAG(f, s) RX_HDR(1, 10, 8, FL_TO | (f) | ((s) << MCTP_HDR_SEQ_SHIFT))
441 
442 static const struct mctp_route_input_sk_reasm_test mctp_route_input_sk_reasm_tests[] = {
443 	{
444 		.name = "single packet",
445 		.hdrs = {
446 			RX_FRAG(FL_S | FL_E, 0),
447 		},
448 		.n_hdrs = 1,
449 		.rx_len = 1,
450 	},
451 	{
452 		.name = "single packet, offset seq",
453 		.hdrs = {
454 			RX_FRAG(FL_S | FL_E, 1),
455 		},
456 		.n_hdrs = 1,
457 		.rx_len = 1,
458 	},
459 	{
460 		.name = "start & end packets",
461 		.hdrs = {
462 			RX_FRAG(FL_S, 0),
463 			RX_FRAG(FL_E, 1),
464 		},
465 		.n_hdrs = 2,
466 		.rx_len = 2,
467 	},
468 	{
469 		.name = "start & end packets, offset seq",
470 		.hdrs = {
471 			RX_FRAG(FL_S, 1),
472 			RX_FRAG(FL_E, 2),
473 		},
474 		.n_hdrs = 2,
475 		.rx_len = 2,
476 	},
477 	{
478 		.name = "start & end packets, out of order",
479 		.hdrs = {
480 			RX_FRAG(FL_E, 1),
481 			RX_FRAG(FL_S, 0),
482 		},
483 		.n_hdrs = 2,
484 		.rx_len = 0,
485 	},
486 	{
487 		.name = "start, middle & end packets",
488 		.hdrs = {
489 			RX_FRAG(FL_S, 0),
490 			RX_FRAG(0,    1),
491 			RX_FRAG(FL_E, 2),
492 		},
493 		.n_hdrs = 3,
494 		.rx_len = 3,
495 	},
496 	{
497 		.name = "missing seq",
498 		.hdrs = {
499 			RX_FRAG(FL_S, 0),
500 			RX_FRAG(FL_E, 2),
501 		},
502 		.n_hdrs = 2,
503 		.rx_len = 0,
504 	},
505 	{
506 		.name = "seq wrap",
507 		.hdrs = {
508 			RX_FRAG(FL_S, 3),
509 			RX_FRAG(FL_E, 0),
510 		},
511 		.n_hdrs = 2,
512 		.rx_len = 2,
513 	},
514 };
515 
mctp_route_input_sk_reasm_to_desc(const struct mctp_route_input_sk_reasm_test * t,char * desc)516 static void mctp_route_input_sk_reasm_to_desc(
517 				const struct mctp_route_input_sk_reasm_test *t,
518 				char *desc)
519 {
520 	sprintf(desc, "%s", t->name);
521 }
522 
523 KUNIT_ARRAY_PARAM(mctp_route_input_sk_reasm, mctp_route_input_sk_reasm_tests,
524 		  mctp_route_input_sk_reasm_to_desc);
525 
526 struct mctp_route_input_sk_keys_test {
527 	const char	*name;
528 	mctp_eid_t	key_peer_addr;
529 	mctp_eid_t	key_local_addr;
530 	u8		key_tag;
531 	struct mctp_hdr hdr;
532 	bool		deliver;
533 };
534 
535 /* test packet rx in the presence of various key configurations */
mctp_test_route_input_sk_keys(struct kunit * test)536 static void mctp_test_route_input_sk_keys(struct kunit *test)
537 {
538 	const struct mctp_route_input_sk_keys_test *params;
539 	struct mctp_test_route *rt;
540 	struct sk_buff *skb, *skb2;
541 	struct mctp_test_dev *dev;
542 	struct mctp_sk_key *key;
543 	struct netns_mctp *mns;
544 	struct mctp_sock *msk;
545 	struct socket *sock;
546 	unsigned long flags;
547 	int rc;
548 	u8 c;
549 
550 	params = test->param_value;
551 
552 	dev = mctp_test_create_dev();
553 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
554 
555 	rt = mctp_test_create_route(&init_net, dev->mdev, 8, 68);
556 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, rt);
557 
558 	rc = sock_create_kern(&init_net, AF_MCTP, SOCK_DGRAM, 0, &sock);
559 	KUNIT_ASSERT_EQ(test, rc, 0);
560 
561 	msk = container_of(sock->sk, struct mctp_sock, sk);
562 	mns = &sock_net(sock->sk)->mctp;
563 
564 	/* set the incoming tag according to test params */
565 	key = mctp_key_alloc(msk, params->key_local_addr, params->key_peer_addr,
566 			     params->key_tag, GFP_KERNEL);
567 
568 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, key);
569 
570 	spin_lock_irqsave(&mns->keys_lock, flags);
571 	mctp_reserve_tag(&init_net, key, msk);
572 	spin_unlock_irqrestore(&mns->keys_lock, flags);
573 
574 	/* create packet and route */
575 	c = 0;
576 	skb = mctp_test_create_skb_data(&params->hdr, &c);
577 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, skb);
578 
579 	skb->dev = dev->ndev;
580 	__mctp_cb(skb);
581 
582 	rc = mctp_route_input(&rt->rt, skb);
583 
584 	/* (potentially) receive message */
585 	skb2 = skb_recv_datagram(sock->sk, MSG_DONTWAIT, &rc);
586 
587 	if (params->deliver)
588 		KUNIT_EXPECT_NOT_ERR_OR_NULL(test, skb2);
589 	else
590 		KUNIT_EXPECT_PTR_EQ(test, skb2, NULL);
591 
592 	if (skb2)
593 		skb_free_datagram(sock->sk, skb2);
594 
595 	mctp_key_unref(key);
596 	__mctp_route_test_fini(test, dev, rt, sock);
597 }
598 
599 static const struct mctp_route_input_sk_keys_test mctp_route_input_sk_keys_tests[] = {
600 	{
601 		.name = "direct match",
602 		.key_peer_addr = 9,
603 		.key_local_addr = 8,
604 		.key_tag = 1,
605 		.hdr = RX_HDR(1, 9, 8, FL_S | FL_E | FL_T(1)),
606 		.deliver = true,
607 	},
608 	{
609 		.name = "flipped src/dest",
610 		.key_peer_addr = 8,
611 		.key_local_addr = 9,
612 		.key_tag = 1,
613 		.hdr = RX_HDR(1, 9, 8, FL_S | FL_E | FL_T(1)),
614 		.deliver = false,
615 	},
616 	{
617 		.name = "peer addr mismatch",
618 		.key_peer_addr = 9,
619 		.key_local_addr = 8,
620 		.key_tag = 1,
621 		.hdr = RX_HDR(1, 10, 8, FL_S | FL_E | FL_T(1)),
622 		.deliver = false,
623 	},
624 	{
625 		.name = "tag value mismatch",
626 		.key_peer_addr = 9,
627 		.key_local_addr = 8,
628 		.key_tag = 1,
629 		.hdr = RX_HDR(1, 9, 8, FL_S | FL_E | FL_T(2)),
630 		.deliver = false,
631 	},
632 	{
633 		.name = "TO mismatch",
634 		.key_peer_addr = 9,
635 		.key_local_addr = 8,
636 		.key_tag = 1,
637 		.hdr = RX_HDR(1, 9, 8, FL_S | FL_E | FL_T(1) | FL_TO),
638 		.deliver = false,
639 	},
640 	{
641 		.name = "broadcast response",
642 		.key_peer_addr = MCTP_ADDR_ANY,
643 		.key_local_addr = 8,
644 		.key_tag = 1,
645 		.hdr = RX_HDR(1, 11, 8, FL_S | FL_E | FL_T(1)),
646 		.deliver = true,
647 	},
648 	{
649 		.name = "any local match",
650 		.key_peer_addr = 12,
651 		.key_local_addr = MCTP_ADDR_ANY,
652 		.key_tag = 1,
653 		.hdr = RX_HDR(1, 12, 8, FL_S | FL_E | FL_T(1)),
654 		.deliver = true,
655 	},
656 };
657 
mctp_route_input_sk_keys_to_desc(const struct mctp_route_input_sk_keys_test * t,char * desc)658 static void mctp_route_input_sk_keys_to_desc(
659 				const struct mctp_route_input_sk_keys_test *t,
660 				char *desc)
661 {
662 	sprintf(desc, "%s", t->name);
663 }
664 
665 KUNIT_ARRAY_PARAM(mctp_route_input_sk_keys, mctp_route_input_sk_keys_tests,
666 		  mctp_route_input_sk_keys_to_desc);
667 
668 static struct kunit_case mctp_test_cases[] = {
669 	KUNIT_CASE_PARAM(mctp_test_fragment, mctp_frag_gen_params),
670 	KUNIT_CASE_PARAM(mctp_test_rx_input, mctp_rx_input_gen_params),
671 	KUNIT_CASE_PARAM(mctp_test_route_input_sk, mctp_route_input_sk_gen_params),
672 	KUNIT_CASE_PARAM(mctp_test_route_input_sk_reasm,
673 			 mctp_route_input_sk_reasm_gen_params),
674 	KUNIT_CASE_PARAM(mctp_test_route_input_sk_keys,
675 			 mctp_route_input_sk_keys_gen_params),
676 	{}
677 };
678 
679 static struct kunit_suite mctp_test_suite = {
680 	.name = "mctp",
681 	.test_cases = mctp_test_cases,
682 };
683 
684 kunit_test_suite(mctp_test_suite);
685