traffic-selector: Always print protocol if either protocol or port is set
This helps to distinguish between port and protocol if only one of them is set. If no protocol is set it's printed as 0, if the traffic selector covers any port (0-65535) the slash that separates the two values and the port is omitted.
This commit is contained in:
@@ -293,15 +293,16 @@ int traffic_selector_printf_hook(printf_hook_data_t *data,
|
||||
written += print_in_hook(data, "%d", this->protocol);
|
||||
}
|
||||
}
|
||||
|
||||
if (has_proto && has_ports)
|
||||
else
|
||||
{
|
||||
written += print_in_hook(data, "/");
|
||||
written += print_in_hook(data, "0");
|
||||
}
|
||||
|
||||
/* build port string */
|
||||
if (has_ports)
|
||||
{
|
||||
written += print_in_hook(data, "/");
|
||||
|
||||
if (this->from_port == this->to_port)
|
||||
{
|
||||
struct servent *serv;
|
||||
|
||||
@@ -72,10 +72,13 @@ START_TEST(test_create_from_cidr)
|
||||
verify("10.1.0.1/32[udp]", "10.1.0.1/32[17]",
|
||||
traffic_selector_create_from_cidr("10.1.0.1/32", IPPROTO_UDP,
|
||||
0, 65535));
|
||||
verify("10.1.0.1/32[0/domain]", "10.1.0.1/32[0/53]",
|
||||
traffic_selector_create_from_cidr("10.1.0.1/32", 0,
|
||||
53, 53));
|
||||
verify("10.1.0.1/32[udp/1234-1235]", "10.1.0.1/32[17/1234-1235]",
|
||||
traffic_selector_create_from_cidr("10.1.0.1/32", IPPROTO_UDP,
|
||||
1234, 1235));
|
||||
verify("10.1.0.0/16[OPAQUE]", NULL,
|
||||
verify("10.1.0.0/16[0/OPAQUE]", NULL,
|
||||
traffic_selector_create_from_cidr("10.1.0.0/16", 0, 65535, 0));
|
||||
|
||||
verify(NULL, NULL,
|
||||
|
||||
Reference in New Issue
Block a user