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

wifi: mac80211: kunit: generalize public action test

Generalize the test to be able to handle arbitrary
action categories and non-action frames, for further
test expansion.

Reviewed-by: Gregory Greenman <gregory.greenman@intel.com>
Link: https://msgid.link/20231220151952.415232-5-benjamin@sipsolutions.net
Signed-off-by: Johannes Berg <johannes.berg@intel.com>

+57 -21
+57 -21
net/mac80211/tests/mfp.c
··· 13 13 14 14 static const struct mfp_test_case { 15 15 const char *desc; 16 - bool sta, mfp, decrypted, unicast, protected_dual; 16 + bool sta, mfp, decrypted, unicast; 17 + u8 category; 18 + u8 stype; 19 + u8 action; 17 20 ieee80211_rx_result result; 18 - } accept_public_action_cases[] = { 21 + } accept_mfp_cases[] = { 19 22 /* regular public action */ 20 23 { 21 24 .desc = "public action: accept unicast from unknown peer", 25 + .stype = IEEE80211_STYPE_ACTION, 26 + .category = WLAN_CATEGORY_PUBLIC, 27 + .action = WLAN_PUB_ACTION_DSE_ENABLEMENT, 22 28 .unicast = true, 23 29 .result = RX_CONTINUE, 24 30 }, 25 31 { 26 32 .desc = "public action: accept multicast from unknown peer", 33 + .stype = IEEE80211_STYPE_ACTION, 34 + .category = WLAN_CATEGORY_PUBLIC, 35 + .action = WLAN_PUB_ACTION_DSE_ENABLEMENT, 27 36 .unicast = false, 28 37 .result = RX_CONTINUE, 29 38 }, 30 39 { 31 40 .desc = "public action: accept unicast without MFP", 41 + .stype = IEEE80211_STYPE_ACTION, 42 + .category = WLAN_CATEGORY_PUBLIC, 43 + .action = WLAN_PUB_ACTION_DSE_ENABLEMENT, 32 44 .unicast = true, 33 45 .sta = true, 34 46 .result = RX_CONTINUE, 35 47 }, 36 48 { 37 49 .desc = "public action: accept multicast without MFP", 50 + .stype = IEEE80211_STYPE_ACTION, 51 + .category = WLAN_CATEGORY_PUBLIC, 52 + .action = WLAN_PUB_ACTION_DSE_ENABLEMENT, 38 53 .unicast = false, 39 54 .sta = true, 40 55 .result = RX_CONTINUE, 41 56 }, 42 57 { 43 58 .desc = "public action: drop unicast with MFP", 59 + .stype = IEEE80211_STYPE_ACTION, 60 + .category = WLAN_CATEGORY_PUBLIC, 61 + .action = WLAN_PUB_ACTION_DSE_ENABLEMENT, 44 62 .unicast = true, 45 63 .sta = true, 46 64 .mfp = true, ··· 66 48 }, 67 49 { 68 50 .desc = "public action: accept multicast with MFP", 51 + .stype = IEEE80211_STYPE_ACTION, 52 + .category = WLAN_CATEGORY_PUBLIC, 53 + .action = WLAN_PUB_ACTION_DSE_ENABLEMENT, 69 54 .unicast = false, 70 55 .sta = true, 71 56 .mfp = true, ··· 77 56 /* protected dual of public action */ 78 57 { 79 58 .desc = "protected dual: drop unicast from unknown peer", 80 - .protected_dual = true, 59 + .stype = IEEE80211_STYPE_ACTION, 60 + .category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION, 61 + .action = WLAN_PUB_ACTION_DSE_ENABLEMENT, 81 62 .unicast = true, 82 63 .result = RX_DROP_U_UNPROT_DUAL, 83 64 }, 84 65 { 85 66 .desc = "protected dual: drop multicast from unknown peer", 86 - .protected_dual = true, 67 + .stype = IEEE80211_STYPE_ACTION, 68 + .category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION, 69 + .action = WLAN_PUB_ACTION_DSE_ENABLEMENT, 87 70 .unicast = false, 88 71 .result = RX_DROP_U_UNPROT_DUAL, 89 72 }, 90 73 { 91 74 .desc = "protected dual: drop unicast without MFP", 92 - .protected_dual = true, 75 + .stype = IEEE80211_STYPE_ACTION, 76 + .category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION, 77 + .action = WLAN_PUB_ACTION_DSE_ENABLEMENT, 93 78 .unicast = true, 94 79 .sta = true, 95 80 .result = RX_DROP_U_UNPROT_DUAL, 96 81 }, 97 82 { 98 83 .desc = "protected dual: drop multicast without MFP", 99 - .protected_dual = true, 84 + .stype = IEEE80211_STYPE_ACTION, 85 + .category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION, 86 + .action = WLAN_PUB_ACTION_DSE_ENABLEMENT, 100 87 .unicast = false, 101 88 .sta = true, 102 89 .result = RX_DROP_U_UNPROT_DUAL, 103 90 }, 104 91 { 105 92 .desc = "protected dual: drop undecrypted unicast with MFP", 106 - .protected_dual = true, 93 + .stype = IEEE80211_STYPE_ACTION, 94 + .category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION, 95 + .action = WLAN_PUB_ACTION_DSE_ENABLEMENT, 107 96 .unicast = true, 108 97 .sta = true, 109 98 .mfp = true, ··· 121 90 }, 122 91 { 123 92 .desc = "protected dual: drop undecrypted multicast with MFP", 124 - .protected_dual = true, 93 + .stype = IEEE80211_STYPE_ACTION, 94 + .category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION, 95 + .action = WLAN_PUB_ACTION_DSE_ENABLEMENT, 125 96 .unicast = false, 126 97 .sta = true, 127 98 .mfp = true, ··· 131 98 }, 132 99 { 133 100 .desc = "protected dual: accept unicast with MFP", 134 - .protected_dual = true, 101 + .stype = IEEE80211_STYPE_ACTION, 102 + .category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION, 103 + .action = WLAN_PUB_ACTION_DSE_ENABLEMENT, 135 104 .decrypted = true, 136 105 .unicast = true, 137 106 .sta = true, ··· 142 107 }, 143 108 { 144 109 .desc = "protected dual: accept multicast with MFP", 145 - .protected_dual = true, 110 + .stype = IEEE80211_STYPE_ACTION, 111 + .category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION, 112 + .action = WLAN_PUB_ACTION_DSE_ENABLEMENT, 146 113 .decrypted = true, 147 114 .unicast = false, 148 115 .sta = true, ··· 153 116 }, 154 117 }; 155 118 156 - KUNIT_ARRAY_PARAM_DESC(accept_public_action, 157 - accept_public_action_cases, 158 - desc); 119 + KUNIT_ARRAY_PARAM_DESC(accept_mfp, accept_mfp_cases, desc); 159 120 160 - static void accept_public_action(struct kunit *test) 121 + static void accept_mfp(struct kunit *test) 161 122 { 162 123 static struct sta_info sta = {}; 163 124 const struct mfp_test_case *params = test->param_value; ··· 165 130 struct ieee80211_rx_status *status; 166 131 struct ieee80211_hdr_3addr hdr = { 167 132 .frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 168 - IEEE80211_STYPE_ACTION), 133 + params->stype), 169 134 .addr1 = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, 170 135 .addr2 = { 0x12, 0x22, 0x33, 0x44, 0x55, 0x66 }, 171 136 /* A3/BSSID doesn't matter here */ ··· 195 160 196 161 skb_put_data(rx.skb, &hdr, sizeof(hdr)); 197 162 198 - if (params->protected_dual) 199 - skb_put_u8(rx.skb, WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION); 200 - else 201 - skb_put_u8(rx.skb, WLAN_CATEGORY_PUBLIC); 202 - skb_put_u8(rx.skb, WLAN_PUB_ACTION_DSE_ENABLEMENT); 163 + switch (params->stype) { 164 + case IEEE80211_STYPE_ACTION: 165 + skb_put_u8(rx.skb, params->category); 166 + skb_put_u8(rx.skb, params->action); 167 + break; 168 + } 203 169 204 170 KUNIT_EXPECT_EQ(test, 205 171 ieee80211_drop_unencrypted_mgmt(&rx), ··· 208 172 } 209 173 210 174 static struct kunit_case mfp_test_cases[] = { 211 - KUNIT_CASE_PARAM(accept_public_action, accept_public_action_gen_params), 175 + KUNIT_CASE_PARAM(accept_mfp, accept_mfp_gen_params), 212 176 {} 213 177 }; 214 178