Skip to content

Commit

Permalink
Feature #884 fix tcpprep -x -X include to EOF
Browse files Browse the repository at this point in the history
A rule such as `75-` needs to include packet 75 to the last packet in the file.
  • Loading branch information
fklassen committed Jun 24, 2024
1 parent 724bdaf commit ea0351f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
3 changes: 2 additions & 1 deletion docs/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
06/08/2024 Version 4.5.0-beta2
06/23/2024 Version 4.5.0-beta3
- tcpreplay --include / --exclude to control which packets are replayed (#884)
- add -w (--suppress-warnings) option to suppress warning messages (#878)
- AF_XDP compile issue due to merge issue (#876)
- memory leak in tcpprep when using include/exclude (#869)
Expand Down
44 changes: 21 additions & 23 deletions src/common/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ new_list()
return (newlist);
}

static void
add_to_list(tcpr_list_t *list_ptr, const char *first, const char *second)
{
list_ptr->min = strtoull(first, NULL, 0);
if (second != NULL) {
if (second[0] == '\0') {
list_ptr->max = 0;
} else {
list_ptr->max = strtoull(second, NULL, 0);
}
} else {
list_ptr->max = list_ptr->min;
}
}

/**
* Processes a string (ourstr) containing the list in human readable
* format and places the data in **list and finally returns 1 for
Expand All @@ -57,7 +72,7 @@ parse_list(tcpr_list_t **listdata, char *ourstr)
char *first, *second;
int rcode;
regex_t preg;
char regex[] = "^[0-9]+(-[0-9]+)?$";
char regex[] = "^[0-9]+(-([0-9]+|\\s*))?$";
char *token = NULL;
u_int i;

Expand Down Expand Up @@ -91,12 +106,7 @@ parse_list(tcpr_list_t **listdata, char *ourstr)
}
}

list_ptr->min = strtoull(first, NULL, 0);
if (second != NULL) {
list_ptr->max = strtoull(second, NULL, 0);
} else {
list_ptr->max = list_ptr->min;
}
add_to_list(list_ptr, first, second);

while (1) {
this = strtok_r(NULL, ",", &token);
Expand All @@ -123,12 +133,7 @@ parse_list(tcpr_list_t **listdata, char *ourstr)
}
}

listcur->min = strtoull(first, NULL, 0);
if (second != NULL) {
listcur->max = strtoull(second, NULL, 0);
} else {
listcur->max = listcur->min;
}
add_to_list(listcur, first, second);
}

regfree(&preg);
Expand All @@ -144,10 +149,8 @@ tcpr_dir_t
check_list(tcpr_list_t *list, COUNTER value)
{
tcpr_list_t *current;
current = list;

do {
if ((current->min != 0) && (current->max != 0)) {
for (current = list; current; current = current->next) {
if (current->min != 0 && current->max != 0) {
if ((value >= current->min) && (value <= current->max))
return 1;
} else if (current->min == 0) {
Expand All @@ -157,12 +160,7 @@ check_list(tcpr_list_t *list, COUNTER value)
if (value >= current->min)
return 1;
}

if (current->next != NULL)
current = current->next;
else
current = NULL;
} while (current != NULL);
}

return 0;
}
Expand Down

0 comments on commit ea0351f

Please sign in to comment.