Skip to content

Commit 90a690d

Browse files
authored
[aclorch]: Simplify the TCP flags matching code and support exact value match (#1072)
Use similar DSCP value parsing logic for TCP falgs value parsing. Remove the deprecated functions. Signed-off-by: Shu0t1an Cheng <[email protected]>
1 parent 3461710 commit 90a690d

File tree

2 files changed

+7
-53
lines changed

2 files changed

+7
-53
lines changed

orchagent/aclorch.cpp

+7-40
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,6 @@ static acl_ip_type_lookup_t aclIpTypeLookup =
129129
{ IP_TYPE_ARP_REPLY, SAI_ACL_IP_TYPE_ARP_REPLY }
130130
};
131131

132-
inline string trim(const std::string& str, const std::string& whitespace = " \t")
133-
{
134-
const auto strBegin = str.find_first_not_of(whitespace);
135-
if (strBegin == std::string::npos)
136-
return "";
137-
138-
const auto strEnd = str.find_last_not_of(whitespace);
139-
const auto strRange = strEnd - strBegin + 1;
140-
141-
return str.substr(strBegin, strRange);
142-
}
143-
144132
AclRule::AclRule(AclOrch *aclOrch, string rule, string table, acl_table_type_t type, bool createCounter) :
145133
m_pAclOrch(aclOrch),
146134
m_id(rule),
@@ -246,40 +234,19 @@ bool AclRule::validateAddMatch(string attr_name, string attr_value)
246234
}
247235
else if (attr_name == MATCH_TCP_FLAGS)
248236
{
249-
vector<string> flagsData;
250-
string flags, mask;
251-
int val;
252-
char *endp = NULL;
253-
errno = 0;
237+
// Support both exact value match and value/mask match
238+
auto flag_data = tokenize(attr_value, '/');
254239

255-
split(attr_value, flagsData, '/');
240+
value.aclfield.data.u8 = to_uint<uint8_t>(flag_data[0], 0, 0x3F);
256241

257-
if (flagsData.size() != 2) // expect two parts flags and mask separated with '/'
242+
if (flag_data.size() == 2)
258243
{
259-
SWSS_LOG_ERROR("Invalid TCP flags format %s", attr_value.c_str());
260-
return false;
244+
value.aclfield.mask.u8 = to_uint<uint8_t>(flag_data[1], 0, 0x3F);
261245
}
262-
263-
flags = trim(flagsData[0]);
264-
mask = trim(flagsData[1]);
265-
266-
val = (uint32_t)strtol(flags.c_str(), &endp, 0);
267-
if (errno || (endp != flags.c_str() + flags.size()) ||
268-
(val < 0) || (val > UCHAR_MAX))
269-
{
270-
SWSS_LOG_ERROR("TCP flags parse error, value: %s(=%d), errno: %d", flags.c_str(), val, errno);
271-
return false;
272-
}
273-
value.aclfield.data.u8 = (uint8_t)val;
274-
275-
val = (uint32_t)strtol(mask.c_str(), &endp, 0);
276-
if (errno || (endp != mask.c_str() + mask.size()) ||
277-
(val < 0) || (val > UCHAR_MAX))
246+
else
278247
{
279-
SWSS_LOG_ERROR("TCP mask parse error, value: %s(=%d), errno: %d", mask.c_str(), val, errno);
280-
return false;
248+
value.aclfield.mask.u8 = 0x3F;
281249
}
282-
value.aclfield.mask.u8 = (uint8_t)val;
283250
}
284251
else if (attr_name == MATCH_ETHER_TYPE || attr_name == MATCH_L4_SRC_PORT || attr_name == MATCH_L4_DST_PORT)
285252
{

orchagent/aclorch.h

-13
Original file line numberDiff line numberDiff line change
@@ -372,19 +372,6 @@ class AclTable {
372372
void update(SubjectType, void *);
373373
};
374374

375-
template <class Iterable>
376-
inline void split(string str, Iterable& out, char delim = ' ')
377-
{
378-
string val;
379-
380-
istringstream input(str);
381-
382-
while (getline(input, val, delim))
383-
{
384-
out.push_back(val);
385-
}
386-
}
387-
388375
class AclOrch : public Orch, public Observer
389376
{
390377
public:

0 commit comments

Comments
 (0)