A caller that evaluates a flow instead of a frame, such as a driver that offloads flows to hardware, has no frame for a filter classifier and may lack parameters that a classifier selects. A descriptor that did not match for that reason could still match a frame of the flow, so the caller must not derive a per flow rule from the verdict. Add an undecided flag to the verdict. It is set when a descriptor that did not match selects a parameter that the flow does not carry, and matched on nothing else. The transmit path ignores it, since a frame without the parameter cannot match. Signed-off-by: Felix Fietkau --- include/net/cfg80211.h | 4 ++- net/wireless/scs.c | 28 +++++++++++----- net/wireless/tests/scs.c | 74 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 98 insertions(+), 8 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 58b28c53a86b..2d670828d664 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4299,11 +4299,15 @@ struct cfg80211_mscs_desc { * struct cfg80211_scs_verdict - result of an SCS evaluation * * @match: an SCS descriptor matched the MSDU + * @undecided: a descriptor that did not match selects a parameter that the + * MSDU lacks. A caller that evaluates a flow instead of a frame must + * not derive a flow rule from this verdict. * @scsid: identifier of the matching descriptor * @up: user priority to assign */ struct cfg80211_scs_verdict { bool match; + bool undecided; u8 scsid; u8 up; }; diff --git a/net/wireless/scs.c b/net/wireless/scs.c index 22c0b9d6930e..11094e77b440 100644 --- a/net/wireless/scs.c +++ b/net/wireless/scs.c @@ -760,14 +760,18 @@ static bool tclas_filter_offset(const struct cfg80211_flow_info *info, } static bool tclas_filter_match(const struct cfg80211_tclas *t, - const struct cfg80211_flow_info *info) + const struct cfg80211_flow_info *info, + bool *undecided) { const struct cfg80211_tclas_filter *f = &t->filter; u8 buf[CFG80211_TCLAS_FILTER_LEN], *p; unsigned int i, off; - if (!info->skb) + if (!info->skb) { + *undecided = true; + return false; + } if (!tclas_filter_offset(info, f, &off)) return false; @@ -784,16 +788,19 @@ static bool tclas_filter_match(const struct cfg80211_tclas *t, } static bool tclas_match(const struct cfg80211_tclas *t, - const struct cfg80211_flow_info *info) + const struct cfg80211_flow_info *info, bool *undecided) { struct cfg80211_flow_key key; if (t->type == CFG80211_TCLAS_FILTER) - return tclas_filter_match(t, info); + return tclas_filter_match(t, info, undecided); if (!cfg80211_flow_key_build(info, t->fields, CFG80211_FLOW_AS_IS, - &key)) + &key)) { + *undecided = true; + return false; + } return !memcmp(&key, &t->key, sizeof(key)); } @@ -811,13 +818,14 @@ static u16 tclas_param_count(const struct cfg80211_tclas *t) } static bool scs_desc_match(const struct cfg80211_scs_desc *desc, - const struct cfg80211_flow_info *info) + const struct cfg80211_flow_info *info, + bool *undecided) { unsigned int i; bool any = false; for (i = 0; i < desc->n_tclas; i++) { - if (tclas_match(&desc->tclas[i], info)) { + if (tclas_match(&desc->tclas[i], info, undecided)) { any = true; continue; } @@ -870,10 +878,14 @@ void cfg80211_scs_evaluate(struct cfg80211_scs_desc * const *desc, u8 n_desc, memset(verdict, 0, sizeof(*verdict)); for (i = 0; i < n_desc; i++) { + bool undecided = false; u16 count; - if (!scs_desc_match(desc[i], info)) + if (!scs_desc_match(desc[i], info, &undecided)) { + /* A missing parameter only matters without a match */ + verdict->undecided |= undecided; continue; + } count = scs_desc_param_count(desc[i]); if (count <= best) diff --git a/net/wireless/tests/scs.c b/net/wireless/tests/scs.c index d3636bd45964..19e05974c7ee 100644 --- a/net/wireless/tests/scs.c +++ b/net/wireless/tests/scs.c @@ -175,6 +175,7 @@ static void scs_granularity(struct kunit *test) KUNIT_EXPECT_TRUE(test, verdict.match); KUNIT_EXPECT_EQ(test, verdict.scsid, 1); KUNIT_EXPECT_EQ(test, verdict.up, 3); + KUNIT_EXPECT_TRUE(test, verdict.undecided); } /* A key learned from an uplink frame must describe the downlink direction */ @@ -322,6 +323,70 @@ static void tclas_refused(struct kunit *test) &fields)); } +/* A descriptor that matched leaves nothing undecided */ +static void scs_undecided(struct kunit *test) +{ + static const u8 addr_or_port[] = { + WLAN_EID_TCLAS, 19, + 255, + 4, 0x02, /* source address */ + 4, + 192, 168, 1, 1, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, + + WLAN_EID_TCLAS, 19, + 255, + 4, 0x08, /* source port */ + 4, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0x13, 0x88, 0, 0, + 0, 0, 0, + + WLAN_EID_TCLAS_PROCESSING, 1, 1, + }; + static const u8 port_only[] = { + WLAN_EID_TCLAS, 19, + 255, + 4, 0x08, + 4, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0x13, 0x88, 0, 0, + 0, 0, 0, + }; + struct cfg80211_scs_verdict verdict; + struct cfg80211_flow_info info; + struct cfg80211_scs_desc *list[1]; + + list[0] = test_scs_desc(test, 1, 4, addr_or_port, sizeof(addr_or_port)); + KUNIT_ASSERT_EQ(test, list[0]->n_tclas, 2); + KUNIT_ASSERT_EQ(test, list[0]->tclas_processing, 1); + + KUNIT_ASSERT_TRUE(test, + cfg80211_flow_parse(TEST_SKB(test, udp_frame), + &info)); + cfg80211_scs_evaluate(list, 1, &info, &verdict); + KUNIT_EXPECT_TRUE(test, verdict.match); + KUNIT_EXPECT_FALSE(test, verdict.undecided); + + /* A later fragment has no ports, but the address element matches */ + KUNIT_ASSERT_TRUE(test, + cfg80211_flow_parse(TEST_SKB(test, udp_fragment), + &info)); + cfg80211_scs_evaluate(list, 1, &info, &verdict); + KUNIT_EXPECT_TRUE(test, verdict.match); + KUNIT_EXPECT_FALSE(test, verdict.undecided); + + /* With nothing else to match on, the same fragment is undecided */ + list[0] = test_scs_desc(test, 2, 4, port_only, sizeof(port_only)); + cfg80211_scs_evaluate(list, 1, &info, &verdict); + KUNIT_EXPECT_FALSE(test, verdict.match); + KUNIT_EXPECT_TRUE(test, verdict.undecided); +} + /* The presence bitmap decides where every optional field starts */ static void qos_characteristics(struct kunit *test) { @@ -466,11 +531,20 @@ static void scs_filter(struct kunit *test) list[0] = test_scs_desc(test, 2, 5, wrong_sport, sizeof(wrong_sport)); cfg80211_scs_evaluate(list, 1, &info, &verdict); KUNIT_EXPECT_FALSE(test, verdict.match); + KUNIT_EXPECT_FALSE(test, verdict.undecided); + + /* Without a frame, a filter classifier cannot decide the flow */ + list[0] = test_scs_desc(test, 3, 5, udp_sport, sizeof(udp_sport)); + info.skb = NULL; + cfg80211_scs_evaluate(list, 1, &info, &verdict); + KUNIT_EXPECT_FALSE(test, verdict.match); + KUNIT_EXPECT_TRUE(test, verdict.undecided); } static struct kunit_case scs_cases[] = { KUNIT_CASE(flow_parse_fragment), KUNIT_CASE(scs_granularity), + KUNIT_CASE(scs_undecided), KUNIT_CASE(scs_filter), KUNIT_CASE(flow_key_mirror), KUNIT_CASE(flow_key_mirror_eth), -- git-series 0.9.1