Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: mctp: tests: Test that outgoing skbs have flow data populated

When CONFIG_MCTP_FLOWS is enabled, outgoing skbs should have their
SKB_EXT_MCTP extension set for drivers to consume.

Add two tests for local-to-output routing that check for the flow
extensions: one for the simple single-packet case, and one for
fragmentation.

We now make MCTP_TEST select MCTP_FLOWS, so we always get coverage of
these flow tests. The tests are skippable if MCTP_FLOWS is (otherwise)
disabled, but that would need manual config tweaking.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Jeremy Kerr and committed by
Paolo Abeni
109a5331 1394c1de

+138
+1
net/mctp/Kconfig
··· 14 14 15 15 config MCTP_TEST 16 16 bool "MCTP core tests" if !KUNIT_ALL_TESTS 17 + select MCTP_FLOWS 17 18 depends on MCTP=y && KUNIT=y 18 19 default KUNIT_ALL_TESTS 19 20
+136
net/mctp/test/route-test.c
··· 837 837 mctp_test_route_input_multiple_nets_key_fini(test, &t2); 838 838 } 839 839 840 + #if IS_ENABLED(CONFIG_MCTP_FLOWS) 841 + 842 + static void mctp_test_flow_init(struct kunit *test, 843 + struct mctp_test_dev **devp, 844 + struct mctp_test_route **rtp, 845 + struct socket **sock, 846 + struct sk_buff **skbp, 847 + unsigned int len) 848 + { 849 + struct mctp_test_route *rt; 850 + struct mctp_test_dev *dev; 851 + struct sk_buff *skb; 852 + 853 + /* we have a slightly odd routing setup here; the test route 854 + * is for EID 8, which is our local EID. We don't do a routing 855 + * lookup, so that's fine - all we require is a path through 856 + * mctp_local_output, which will call rt->output on whatever 857 + * route we provide 858 + */ 859 + __mctp_route_test_init(test, &dev, &rt, sock, MCTP_NET_ANY); 860 + 861 + /* Assign a single EID. ->addrs is freed on mctp netdev release */ 862 + dev->mdev->addrs = kmalloc(sizeof(u8), GFP_KERNEL); 863 + dev->mdev->num_addrs = 1; 864 + dev->mdev->addrs[0] = 8; 865 + 866 + skb = alloc_skb(len + sizeof(struct mctp_hdr) + 1, GFP_KERNEL); 867 + KUNIT_ASSERT_TRUE(test, skb); 868 + __mctp_cb(skb); 869 + skb_reserve(skb, sizeof(struct mctp_hdr) + 1); 870 + memset(skb_put(skb, len), 0, len); 871 + 872 + /* take a ref for the route, we'll decrement in local output */ 873 + refcount_inc(&rt->rt.refs); 874 + 875 + *devp = dev; 876 + *rtp = rt; 877 + *skbp = skb; 878 + } 879 + 880 + static void mctp_test_flow_fini(struct kunit *test, 881 + struct mctp_test_dev *dev, 882 + struct mctp_test_route *rt, 883 + struct socket *sock) 884 + { 885 + __mctp_route_test_fini(test, dev, rt, sock); 886 + } 887 + 888 + /* test that an outgoing skb has the correct MCTP extension data set */ 889 + static void mctp_test_packet_flow(struct kunit *test) 890 + { 891 + struct sk_buff *skb, *skb2; 892 + struct mctp_test_route *rt; 893 + struct mctp_test_dev *dev; 894 + struct mctp_flow *flow; 895 + struct socket *sock; 896 + u8 dst = 8; 897 + int n, rc; 898 + 899 + mctp_test_flow_init(test, &dev, &rt, &sock, &skb, 30); 900 + 901 + rc = mctp_local_output(sock->sk, &rt->rt, skb, dst, MCTP_TAG_OWNER); 902 + KUNIT_ASSERT_EQ(test, rc, 0); 903 + 904 + n = rt->pkts.qlen; 905 + KUNIT_ASSERT_EQ(test, n, 1); 906 + 907 + skb2 = skb_dequeue(&rt->pkts); 908 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, skb2); 909 + 910 + flow = skb_ext_find(skb2, SKB_EXT_MCTP); 911 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, flow); 912 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, flow->key); 913 + KUNIT_ASSERT_PTR_EQ(test, flow->key->sk, sock->sk); 914 + 915 + kfree_skb(skb2); 916 + mctp_test_flow_fini(test, dev, rt, sock); 917 + } 918 + 919 + /* test that outgoing skbs, after fragmentation, all have the correct MCTP 920 + * extension data set. 921 + */ 922 + static void mctp_test_fragment_flow(struct kunit *test) 923 + { 924 + struct mctp_flow *flows[2]; 925 + struct sk_buff *tx_skbs[2]; 926 + struct mctp_test_route *rt; 927 + struct mctp_test_dev *dev; 928 + struct sk_buff *skb; 929 + struct socket *sock; 930 + u8 dst = 8; 931 + int n, rc; 932 + 933 + mctp_test_flow_init(test, &dev, &rt, &sock, &skb, 100); 934 + 935 + rc = mctp_local_output(sock->sk, &rt->rt, skb, dst, MCTP_TAG_OWNER); 936 + KUNIT_ASSERT_EQ(test, rc, 0); 937 + 938 + n = rt->pkts.qlen; 939 + KUNIT_ASSERT_EQ(test, n, 2); 940 + 941 + /* both resulting packets should have the same flow data */ 942 + tx_skbs[0] = skb_dequeue(&rt->pkts); 943 + tx_skbs[1] = skb_dequeue(&rt->pkts); 944 + 945 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, tx_skbs[0]); 946 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, tx_skbs[1]); 947 + 948 + flows[0] = skb_ext_find(tx_skbs[0], SKB_EXT_MCTP); 949 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, flows[0]); 950 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, flows[0]->key); 951 + KUNIT_ASSERT_PTR_EQ(test, flows[0]->key->sk, sock->sk); 952 + 953 + flows[1] = skb_ext_find(tx_skbs[1], SKB_EXT_MCTP); 954 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, flows[1]); 955 + KUNIT_ASSERT_PTR_EQ(test, flows[1]->key, flows[0]->key); 956 + 957 + kfree_skb(tx_skbs[0]); 958 + kfree_skb(tx_skbs[1]); 959 + mctp_test_flow_fini(test, dev, rt, sock); 960 + } 961 + 962 + #else 963 + static void mctp_test_packet_flow(struct kunit *test) 964 + { 965 + kunit_skip(test, "Requires CONFIG_MCTP_FLOWS=y"); 966 + } 967 + 968 + static void mctp_test_fragment_flow(struct kunit *test) 969 + { 970 + kunit_skip(test, "Requires CONFIG_MCTP_FLOWS=y"); 971 + } 972 + #endif 973 + 840 974 static struct kunit_case mctp_test_cases[] = { 841 975 KUNIT_CASE_PARAM(mctp_test_fragment, mctp_frag_gen_params), 842 976 KUNIT_CASE_PARAM(mctp_test_rx_input, mctp_rx_input_gen_params), ··· 981 847 mctp_route_input_sk_keys_gen_params), 982 848 KUNIT_CASE(mctp_test_route_input_multiple_nets_bind), 983 849 KUNIT_CASE(mctp_test_route_input_multiple_nets_key), 850 + KUNIT_CASE(mctp_test_packet_flow), 851 + KUNIT_CASE(mctp_test_fragment_flow), 984 852 {} 985 853 }; 986 854
+1
tools/testing/kunit/configs/all_tests.config
··· 23 23 24 24 CONFIG_NET=y 25 25 CONFIG_MCTP=y 26 + CONFIG_MCTP_FLOWS=y 26 27 27 28 CONFIG_INET=y 28 29 CONFIG_MPTCP=y