From 22f0d812ce38590d99872ce4d21e44229a81f61f Mon Sep 17 00:00:00 2001 From: Ravi Vantipalli Date: Wed, 4 Dec 2024 10:28:49 -0800 Subject: [PATCH] Minor SAI UDF manager fixes Summary: Return value and mask for L3 and L4 match types. Using kMaskAny is leading to matching on 0 ethertype for some configs. Reviewed By: zechengh09 Differential Revision: D66530733 fbshipit-source-id: 3043f0c6d47dd4f95cfac2b05d4244f68208671a --- fboss/agent/hw/sai/switch/SaiUdfManager.cpp | 34 +++++++++++++-------- fboss/agent/hw/sai/switch/SaiUdfManager.h | 6 ++-- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/fboss/agent/hw/sai/switch/SaiUdfManager.cpp b/fboss/agent/hw/sai/switch/SaiUdfManager.cpp index 7462e8f868517..375474dae1b8b 100644 --- a/fboss/agent/hw/sai/switch/SaiUdfManager.cpp +++ b/fboss/agent/hw/sai/switch/SaiUdfManager.cpp @@ -49,12 +49,12 @@ SaiUdfMatchTraits::CreateAttributes SaiUdfManager::udfMatchAttr( const std::shared_ptr swUdfMatch) const { // L2 Match Type - match l3 protocol auto l2MatchType = cfgL3MatchTypeToSai(swUdfMatch->getUdfl3PktType()); - auto l2MatchAttr = SaiUdfMatchTraits::Attributes::L2Type{ - AclEntryFieldU16(std::make_pair(l2MatchType, kMaskAny))}; + auto l2MatchAttr = + SaiUdfMatchTraits::Attributes::L2Type{AclEntryFieldU16(l2MatchType)}; // L3 Match Type - match l4 protocol auto l3MatchType = cfgL4MatchTypeToSai(swUdfMatch->getUdfl4PktType()); - auto l3MatchAttr = SaiUdfMatchTraits::Attributes::L3Type{AclEntryFieldU8( - std::make_pair(l3MatchType, static_cast(kMaskAny)))}; + auto l3MatchAttr = + SaiUdfMatchTraits::Attributes::L3Type{AclEntryFieldU8(l3MatchType)}; #if SAI_API_VERSION >= SAI_VERSION(1, 12, 0) // L4 Dst Port auto l4DstPortAttr = SaiUdfMatchTraits::Attributes::L4DstPortType{ @@ -160,26 +160,36 @@ void SaiUdfManager::removeUdfMatch( udfMatchHandles_.erase(swUdfMatch->getName()); } -uint8_t SaiUdfManager::cfgL4MatchTypeToSai(cfg::UdfMatchL4Type cfgType) const { +std::pair SaiUdfManager::cfgL4MatchTypeToSai( + cfg::UdfMatchL4Type cfgType) const { switch (cfgType) { case cfg::UdfMatchL4Type::UDF_L4_PKT_TYPE_ANY: - return 0; + return std::make_pair(0, kMaskDontCare); case cfg::UdfMatchL4Type::UDF_L4_PKT_TYPE_UDP: - return static_cast(IP_PROTO::IP_PROTO_UDP); + return std::make_pair( + static_cast(IP_PROTO::IP_PROTO_UDP), + static_cast(kMaskAny)); case cfg::UdfMatchL4Type::UDF_L4_PKT_TYPE_TCP: - return static_cast(IP_PROTO::IP_PROTO_TCP); + return std::make_pair( + static_cast(IP_PROTO::IP_PROTO_TCP), + static_cast(kMaskAny)); } throw FbossError("Invalid udf l2 match type: ", cfgType); } -uint16_t SaiUdfManager::cfgL3MatchTypeToSai(cfg::UdfMatchL3Type cfgType) const { +std::pair SaiUdfManager::cfgL3MatchTypeToSai( + cfg::UdfMatchL3Type cfgType) const { switch (cfgType) { case cfg::UdfMatchL3Type::UDF_L3_PKT_TYPE_ANY: - return 0; + return std::make_pair(0, kMaskDontCare); case cfg::UdfMatchL3Type::UDF_L3_PKT_TYPE_IPV4: - return static_cast(ETHERTYPE::ETHERTYPE_IPV4); + return std::make_pair( + static_cast(ETHERTYPE::ETHERTYPE_IPV4), + static_cast(kMaskAny)); case cfg::UdfMatchL3Type::UDF_L3_PKT_TYPE_IPV6: - return static_cast(ETHERTYPE::ETHERTYPE_IPV6); + return std::make_pair( + static_cast(ETHERTYPE::ETHERTYPE_IPV6), + static_cast(kMaskAny)); } throw FbossError("Invalid udf l3 match type: ", cfgType); } diff --git a/fboss/agent/hw/sai/switch/SaiUdfManager.h b/fboss/agent/hw/sai/switch/SaiUdfManager.h index 00a1f10082948..de07e9edfcc40 100644 --- a/fboss/agent/hw/sai/switch/SaiUdfManager.h +++ b/fboss/agent/hw/sai/switch/SaiUdfManager.h @@ -94,8 +94,10 @@ class SaiUdfManager { } private: - uint8_t cfgL4MatchTypeToSai(cfg::UdfMatchL4Type cfgType) const; - uint16_t cfgL3MatchTypeToSai(cfg::UdfMatchL3Type cfgType) const; + std::pair cfgL4MatchTypeToSai( + cfg::UdfMatchL4Type cfgType) const; + std::pair cfgL3MatchTypeToSai( + cfg::UdfMatchL3Type cfgType) const; sai_udf_base_t cfgBaseToSai(cfg::UdfBaseHeaderType cfgType) const; UdfMatchHandles udfMatchHandles_;