Lines Matching +full:mctp +full:- +full:handling

1 // SPDX-License-Identifier: GPL-2.0
16 skb_queue_tail(&test_rt->pkts, skb); in mctp_test_route_output()
30 INIT_LIST_HEAD(&rt->rt.list); in mctp_route_test_alloc()
31 refcount_set(&rt->rt.refs, 1); in mctp_route_test_alloc()
32 rt->rt.output = mctp_test_route_output; in mctp_route_test_alloc()
34 skb_queue_head_init(&rt->pkts); in mctp_route_test_alloc()
50 rt->rt.min = eid; in mctp_test_create_route()
51 rt->rt.max = eid; in mctp_test_create_route()
52 rt->rt.mtu = mtu; in mctp_test_create_route()
53 rt->rt.type = RTN_UNSPEC; in mctp_test_create_route()
56 rt->rt.dev = dev; in mctp_test_create_route()
58 list_add_rcu(&rt->rt.list, &net->mctp.routes); in mctp_test_create_route()
69 list_del_rcu(&rt->rt.list); in mctp_test_route_destroy()
72 skb_queue_purge(&rt->pkts); in mctp_test_route_destroy()
73 if (rt->rt.dev) in mctp_test_route_destroy()
74 mctp_dev_put(rt->rt.dev); in mctp_test_route_destroy()
76 refs = refcount_read(&rt->rt.refs); in mctp_test_route_destroy()
79 kfree_rcu(&rt->rt, rcu); in mctp_test_route_destroy()
88 cb->net = READ_ONCE(dev->mdev->net); in mctp_test_skb_set_dev()
89 skb->dev = dev->ndev; in mctp_test_skb_set_dev()
150 params = test->param_value; in mctp_test_fragment()
151 mtu = params->mtu; in mctp_test_fragment()
152 msgsize = params->msgsize; in mctp_test_fragment()
165 rc = mctp_do_fragment_route(&rt->rt, skb, mtu, MCTP_TAG_OWNER); in mctp_test_fragment()
168 n = rt->pkts.qlen; in mctp_test_fragment()
170 KUNIT_EXPECT_EQ(test, n, params->n_frags); in mctp_test_fragment()
179 last = i == (n - 1); in mctp_test_fragment()
181 skb2 = skb_dequeue(&rt->pkts); in mctp_test_fragment()
190 KUNIT_EXPECT_EQ(test, hdr2->ver, hdr.ver); in mctp_test_fragment()
191 KUNIT_EXPECT_EQ(test, hdr2->src, hdr.src); in mctp_test_fragment()
192 KUNIT_EXPECT_EQ(test, hdr2->dest, hdr.dest); in mctp_test_fragment()
193 KUNIT_EXPECT_EQ(test, hdr2->flags_seq_tag & tag_mask, in mctp_test_fragment()
197 !!(hdr2->flags_seq_tag & MCTP_HDR_FLAG_SOM), first); in mctp_test_fragment()
199 !!(hdr2->flags_seq_tag & MCTP_HDR_FLAG_EOM), last); in mctp_test_fragment()
201 seq2 = (hdr2->flags_seq_tag >> MCTP_HDR_SEQ_SHIFT) & in mctp_test_fragment()
212 KUNIT_EXPECT_EQ(test, skb2->len, mtu); in mctp_test_fragment()
214 KUNIT_EXPECT_LE(test, skb2->len, mtu); in mctp_test_fragment()
235 sprintf(desc, "mtu %d len %d -> %d frags", in mctp_frag_test_to_desc()
236 t->msgsize, t->mtu, t->n_frags); in mctp_frag_test_to_desc()
253 params = test->param_value; in mctp_test_rx_input()
258 rt = mctp_test_create_route(&init_net, dev->mdev, 8, 68); in mctp_test_rx_input()
261 skb = mctp_test_create_skb(&params->hdr, 1); in mctp_test_rx_input()
264 mctp_pkttype_receive(skb, dev->ndev, &mctp_packet_type, NULL); in mctp_test_rx_input()
266 KUNIT_EXPECT_EQ(test, !!rt->pkts.qlen, params->input); in mctp_test_rx_input()
285 sprintf(desc, "{%x,%x,%x,%x}", t->hdr.ver, t->hdr.src, t->hdr.dest, in mctp_rx_input_test_to_desc()
286 t->hdr.flags_seq_tag); in mctp_rx_input_test_to_desc()
308 WRITE_ONCE(dev->mdev->net, netid); in __mctp_route_test_init()
310 rt = mctp_test_create_route(&init_net, dev->mdev, 8, 68); in __mctp_route_test_init()
353 params = test->param_value; in mctp_test_route_input_sk()
357 skb = mctp_test_create_skb_data(&params->hdr, &params->type); in mctp_test_route_input_sk()
362 rc = mctp_route_input(&rt->rt, skb); in mctp_test_route_input_sk()
364 if (params->deliver) { in mctp_test_route_input_sk()
367 skb2 = skb_recv_datagram(sock->sk, MSG_DONTWAIT, &rc); in mctp_test_route_input_sk()
369 KUNIT_EXPECT_EQ(test, skb2->len, 1); in mctp_test_route_input_sk()
371 skb_free_datagram(sock->sk, skb2); in mctp_test_route_input_sk()
375 skb2 = skb_recv_datagram(sock->sk, MSG_DONTWAIT, &rc); in mctp_test_route_input_sk()
399 sprintf(desc, "{%x,%x,%x,%x} type %d", t->hdr.ver, t->hdr.src, in mctp_route_input_sk_to_desc()
400 t->hdr.dest, t->hdr.flags_seq_tag, t->type); in mctp_route_input_sk_to_desc()
423 params = test->param_value; in mctp_test_route_input_sk_reasm()
427 for (i = 0; i < params->n_hdrs; i++) { in mctp_test_route_input_sk_reasm()
429 skb = mctp_test_create_skb_data(&params->hdrs[i], &c); in mctp_test_route_input_sk_reasm()
434 rc = mctp_route_input(&rt->rt, skb); in mctp_test_route_input_sk_reasm()
437 skb2 = skb_recv_datagram(sock->sk, MSG_DONTWAIT, &rc); in mctp_test_route_input_sk_reasm()
439 if (params->rx_len) { in mctp_test_route_input_sk_reasm()
441 KUNIT_EXPECT_EQ(test, skb2->len, params->rx_len); in mctp_test_route_input_sk_reasm()
442 skb_free_datagram(sock->sk, skb2); in mctp_test_route_input_sk_reasm()
531 sprintf(desc, "%s", t->name); in mctp_route_input_sk_reasm_to_desc()
562 params = test->param_value; in mctp_test_route_input_sk_keys()
566 net = READ_ONCE(dev->mdev->net); in mctp_test_route_input_sk_keys()
568 rt = mctp_test_create_route(&init_net, dev->mdev, 8, 68); in mctp_test_route_input_sk_keys()
574 msk = container_of(sock->sk, struct mctp_sock, sk); in mctp_test_route_input_sk_keys()
575 mns = &sock_net(sock->sk)->mctp; in mctp_test_route_input_sk_keys()
578 key = mctp_key_alloc(msk, net, params->key_local_addr, in mctp_test_route_input_sk_keys()
579 params->key_peer_addr, params->key_tag, in mctp_test_route_input_sk_keys()
584 spin_lock_irqsave(&mns->keys_lock, flags); in mctp_test_route_input_sk_keys()
586 spin_unlock_irqrestore(&mns->keys_lock, flags); in mctp_test_route_input_sk_keys()
590 skb = mctp_test_create_skb_data(&params->hdr, &c); in mctp_test_route_input_sk_keys()
595 rc = mctp_route_input(&rt->rt, skb); in mctp_test_route_input_sk_keys()
598 skb2 = skb_recv_datagram(sock->sk, MSG_DONTWAIT, &rc); in mctp_test_route_input_sk_keys()
600 if (params->deliver) in mctp_test_route_input_sk_keys()
606 skb_free_datagram(sock->sk, skb2); in mctp_test_route_input_sk_keys()
675 sprintf(desc, "%s", t->name); in mctp_route_input_sk_keys_to_desc()
700 t->msg.data = t->netid; in mctp_test_route_input_multiple_nets_bind_init()
702 __mctp_route_test_init(test, &t->dev, &t->rt, &t->sock, t->netid); in mctp_test_route_input_multiple_nets_bind_init()
704 t->skb = mctp_test_create_skb_data(&hdr, &t->msg); in mctp_test_route_input_multiple_nets_bind_init()
705 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, t->skb); in mctp_test_route_input_multiple_nets_bind_init()
706 mctp_test_skb_set_dev(t->skb, t->dev); in mctp_test_route_input_multiple_nets_bind_init()
713 __mctp_route_test_fini(test, t->dev, t->rt, t->sock); in mctp_test_route_input_multiple_nets_bind_fini()
734 rc = mctp_route_input(&t1.rt->rt, t1.skb); in mctp_test_route_input_multiple_nets_bind()
736 rc = mctp_route_input(&t2.rt->rt, t2.skb); in mctp_test_route_input_multiple_nets_bind()
739 rx_skb1 = skb_recv_datagram(t1.sock->sk, MSG_DONTWAIT, &rc); in mctp_test_route_input_multiple_nets_bind()
741 KUNIT_EXPECT_EQ(test, rx_skb1->len, sizeof(t1.msg)); in mctp_test_route_input_multiple_nets_bind()
747 rx_skb2 = skb_recv_datagram(t2.sock->sk, MSG_DONTWAIT, &rc); in mctp_test_route_input_multiple_nets_bind()
749 KUNIT_EXPECT_EQ(test, rx_skb2->len, sizeof(t2.msg)); in mctp_test_route_input_multiple_nets_bind()
768 t->msg.data = t->netid; in mctp_test_route_input_multiple_nets_key_init()
770 __mctp_route_test_init(test, &t->dev, &t->rt, &t->sock, t->netid); in mctp_test_route_input_multiple_nets_key_init()
772 msk = container_of(t->sock->sk, struct mctp_sock, sk); in mctp_test_route_input_multiple_nets_key_init()
774 t->key = mctp_key_alloc(msk, t->netid, hdr.dest, hdr.src, 1, GFP_KERNEL); in mctp_test_route_input_multiple_nets_key_init()
775 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, t->key); in mctp_test_route_input_multiple_nets_key_init()
777 mns = &sock_net(t->sock->sk)->mctp; in mctp_test_route_input_multiple_nets_key_init()
778 spin_lock_irqsave(&mns->keys_lock, flags); in mctp_test_route_input_multiple_nets_key_init()
779 mctp_reserve_tag(&init_net, t->key, msk); in mctp_test_route_input_multiple_nets_key_init()
780 spin_unlock_irqrestore(&mns->keys_lock, flags); in mctp_test_route_input_multiple_nets_key_init()
782 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, t->key); in mctp_test_route_input_multiple_nets_key_init()
783 t->skb = mctp_test_create_skb_data(&hdr, &t->msg); in mctp_test_route_input_multiple_nets_key_init()
784 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, t->skb); in mctp_test_route_input_multiple_nets_key_init()
785 mctp_test_skb_set_dev(t->skb, t->dev); in mctp_test_route_input_multiple_nets_key_init()
792 mctp_key_unref(t->key); in mctp_test_route_input_multiple_nets_key_fini()
793 __mctp_route_test_fini(test, t->dev, t->rt, t->sock); in mctp_test_route_input_multiple_nets_key_fini()
815 rc = mctp_route_input(&t1.rt->rt, t1.skb); in mctp_test_route_input_multiple_nets_key()
817 rc = mctp_route_input(&t2.rt->rt, t2.skb); in mctp_test_route_input_multiple_nets_key()
820 rx_skb1 = skb_recv_datagram(t1.sock->sk, MSG_DONTWAIT, &rc); in mctp_test_route_input_multiple_nets_key()
822 KUNIT_EXPECT_EQ(test, rx_skb1->len, sizeof(t1.msg)); in mctp_test_route_input_multiple_nets_key()
828 rx_skb2 = skb_recv_datagram(t2.sock->sk, MSG_DONTWAIT, &rc); in mctp_test_route_input_multiple_nets_key()
830 KUNIT_EXPECT_EQ(test, rx_skb2->len, sizeof(t2.msg)); in mctp_test_route_input_multiple_nets_key()
840 /* Input route to socket, using a single-packet message, where sock delivery
841 * fails. Ensure we're handling the failure appropriately.
855 * clamp the minimum to SOCK_MIN_RCVBUF, so we open-code this. in mctp_test_route_input_sk_fail_single()
857 lock_sock(sock->sk); in mctp_test_route_input_sk_fail_single()
858 WRITE_ONCE(sock->sk->sk_rcvbuf, 0); in mctp_test_route_input_sk_fail_single()
859 release_sock(sock->sk); in mctp_test_route_input_sk_fail_single()
868 rc = mctp_route_input(&rt->rt, skb); in mctp_test_route_input_sk_fail_single()
872 KUNIT_EXPECT_EQ(test, refcount_read(&skb->users), 1); in mctp_test_route_input_sk_fail_single()
892 lock_sock(sock->sk); in mctp_test_route_input_sk_fail_frag()
893 WRITE_ONCE(sock->sk->sk_rcvbuf, 0); in mctp_test_route_input_sk_fail_frag()
894 release_sock(sock->sk); in mctp_test_route_input_sk_fail_frag()
907 rc = mctp_route_input(&rt->rt, skbs[0]); in mctp_test_route_input_sk_fail_frag()
911 rc = mctp_route_input(&rt->rt, skbs[1]); in mctp_test_route_input_sk_fail_frag()
915 KUNIT_EXPECT_EQ(test, refcount_read(&skbs[0]->users), 1); in mctp_test_route_input_sk_fail_frag()
918 KUNIT_EXPECT_EQ(test, refcount_read(&skbs[1]->users), 1); in mctp_test_route_input_sk_fail_frag()
939 * lookup, so that's fine - all we require is a path through in mctp_test_flow_init()
940 * mctp_local_output, which will call rt->output on whatever in mctp_test_flow_init()
945 /* Assign a single EID. ->addrs is freed on mctp netdev release */ in mctp_test_flow_init()
946 dev->mdev->addrs = kmalloc(sizeof(u8), GFP_KERNEL); in mctp_test_flow_init()
947 dev->mdev->num_addrs = 1; in mctp_test_flow_init()
948 dev->mdev->addrs[0] = 8; in mctp_test_flow_init()
957 refcount_inc(&rt->rt.refs); in mctp_test_flow_init()
972 /* test that an outgoing skb has the correct MCTP extension data set */
985 rc = mctp_local_output(sock->sk, &rt->rt, skb, dst, MCTP_TAG_OWNER); in mctp_test_packet_flow()
988 n = rt->pkts.qlen; in mctp_test_packet_flow()
991 skb2 = skb_dequeue(&rt->pkts); in mctp_test_packet_flow()
996 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, flow->key); in mctp_test_packet_flow()
997 KUNIT_ASSERT_PTR_EQ(test, flow->key->sk, sock->sk); in mctp_test_packet_flow()
1003 /* test that outgoing skbs, after fragmentation, all have the correct MCTP
1019 rc = mctp_local_output(sock->sk, &rt->rt, skb, dst, MCTP_TAG_OWNER); in mctp_test_fragment_flow()
1022 n = rt->pkts.qlen; in mctp_test_fragment_flow()
1026 tx_skbs[0] = skb_dequeue(&rt->pkts); in mctp_test_fragment_flow()
1027 tx_skbs[1] = skb_dequeue(&rt->pkts); in mctp_test_fragment_flow()
1034 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, flows[0]->key); in mctp_test_fragment_flow()
1035 KUNIT_ASSERT_PTR_EQ(test, flows[0]->key->sk, sock->sk); in mctp_test_fragment_flow()
1039 KUNIT_ASSERT_PTR_EQ(test, flows[1]->key, flows[0]->key); in mctp_test_fragment_flow()
1076 WRITE_ONCE(dev->mdev->net, netid); in mctp_test_route_output_key_create()
1078 rt = mctp_test_create_route(&init_net, dev->mdev, dst, 68); in mctp_test_route_output_key_create()
1084 dev->mdev->addrs = kmalloc(sizeof(u8), GFP_KERNEL); in mctp_test_route_output_key_create()
1085 dev->mdev->num_addrs = 1; in mctp_test_route_output_key_create()
1086 dev->mdev->addrs[0] = src; in mctp_test_route_output_key_create()
1094 refcount_inc(&rt->rt.refs); in mctp_test_route_output_key_create()
1096 mns = &sock_net(sock->sk)->mctp; in mctp_test_route_output_key_create()
1101 spin_lock_irqsave(&mns->keys_lock, flags); in mctp_test_route_output_key_create()
1102 empty = hlist_empty(&mns->keys); in mctp_test_route_output_key_create()
1103 spin_unlock_irqrestore(&mns->keys_lock, flags); in mctp_test_route_output_key_create()
1106 rc = mctp_local_output(sock->sk, &rt->rt, skb, dst, MCTP_TAG_OWNER); in mctp_test_route_output_key_create()
1111 spin_lock_irqsave(&mns->keys_lock, flags); in mctp_test_route_output_key_create()
1112 if (!hlist_empty(&mns->keys)) { in mctp_test_route_output_key_create()
1113 key = hlist_entry(mns->keys.first, struct mctp_sk_key, hlist); in mctp_test_route_output_key_create()
1114 single = hlist_is_singular_node(&key->hlist, &mns->keys); in mctp_test_route_output_key_create()
1116 spin_unlock_irqrestore(&mns->keys_lock, flags); in mctp_test_route_output_key_create()
1121 KUNIT_EXPECT_EQ(test, key->net, netid); in mctp_test_route_output_key_create()
1122 KUNIT_EXPECT_EQ(test, key->local_addr, src); in mctp_test_route_output_key_create()
1123 KUNIT_EXPECT_EQ(test, key->peer_addr, dst); in mctp_test_route_output_key_create()
1125 KUNIT_EXPECT_FALSE(test, key->tag & MCTP_TAG_OWNER); in mctp_test_route_output_key_create()
1151 .name = "mctp",