Skip to content

Commit 79b96c9

Browse files
sedmichaLukas Hutak
authored andcommitted
Iemgr: Allow alias names with special prefixes to contain space
1 parent 1f3d0b0 commit 79b96c9

3 files changed

Lines changed: 48 additions & 2 deletions

File tree

src/iemgr/iemgr_alias.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ alias_destroy(fds_iemgr_alias *alias);
1212

1313
using unique_alias = std::unique_ptr<fds_iemgr_alias, decltype(&::alias_destroy)>;
1414

15+
static bool
16+
check_valid_alias_name(const char *s)
17+
{
18+
std::array<const char *, 6> prefixes { "in ", "out ", "ingress " ,"egress ", "src " ,"dst " };
19+
for (auto p : prefixes) {
20+
if (strncmp(s, p, strlen(p)) == 0) {
21+
s += strlen(p);
22+
break;
23+
}
24+
}
25+
return check_valid_name(s);
26+
}
27+
1528
/**
1629
* Create a new empty alias
1730
*/
@@ -309,11 +322,12 @@ read_element(fds_iemgr_t *mgr, fds_xml_ctx_t *xml_ctx)
309322
mgr->err_msg = "Alias cannot be empty.";
310323
return FDS_ERR_FORMAT;
311324
}
312-
if (!check_valid_name(cont->ptr_string)) {
325+
if (!check_valid_alias_name(cont->ptr_string)) {
313326
mgr->err_msg =
314327
"Invalid characters in alias '" + std::string(cont->ptr_string) + "'. "
315328
"Aliases must only consist of alphanumeric characters and underscores and "
316-
"must not begin with a number.";
329+
"must not begin with a number. Special prefixes 'src ', 'dst ', 'in ', 'out ', "
330+
"'ingress ', 'egress ' are permitted.";
317331
return FDS_ERR_FORMAT;
318332
}
319333
if (!alias_add_aliased_name(alias.get(), cont->ptr_string)) {

tests/unit_tests/iemgr/iemgr_alias.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ TEST_F(Fill, alias_valid)
4545
EXPECT_EQ(elem_e->aliases_cnt, 0);
4646
}
4747

48+
TEST_F(Fill, alias_valid_special_prefix)
49+
{
50+
EXPECT_EQ(fds_iemgr_alias_read_file(mgr, FILES_VALID "aliases_special_prefix.xml"), FDS_OK);
51+
EXPECT_NO_ERROR;
52+
53+
EXPECT_NE(fds_iemgr_alias_find(mgr, "src d"), nullptr);
54+
EXPECT_NE(fds_iemgr_alias_find(mgr, "dst d"), nullptr);
55+
EXPECT_NE(fds_iemgr_alias_find(mgr, "in d"), nullptr);
56+
EXPECT_NE(fds_iemgr_alias_find(mgr, "out d"), nullptr);
57+
EXPECT_NE(fds_iemgr_alias_find(mgr, "ingress d"), nullptr);
58+
EXPECT_NE(fds_iemgr_alias_find(mgr, "egress d"), nullptr);
59+
}
60+
61+
4862
TEST_F(Fill, alias_duplicate)
4963
{
5064
EXPECT_NE(fds_iemgr_alias_read_file(mgr, FILES_INVALID "alias_duplicate.xml"), FDS_OK);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ipfix-aliases>
3+
<element>
4+
<name>D</name>
5+
6+
<alias>src d</alias>
7+
<alias>dst d</alias>
8+
<alias>in d</alias>
9+
<alias>out d</alias>
10+
<alias>ingress d</alias>
11+
<alias>egress d</alias>
12+
13+
<source>
14+
<id>iana:d</id>
15+
</source>
16+
</element>
17+
</ipfix-aliases>
18+

0 commit comments

Comments
 (0)