]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
traffic-selector: Always print protocol if either protocol or port is set
authorTobias Brunner <tobias@strongswan.org>
Wed, 11 Apr 2018 10:15:55 +0000 (12:15 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 11 Apr 2018 10:31:31 +0000 (12:31 +0200)
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.

src/libstrongswan/selectors/traffic_selector.c
src/libstrongswan/tests/suites/test_traffic_selector.c

index 12f1602241a9be27872c0fa530bfa997520ed4d9..6b85270f34034b08b99a7ea22747cb27d7f8b574 100644 (file)
@@ -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;
index 93361f9bf4e415937cca2348bee9524605318fdb..26f2f8e14067b1a8a0eb65a3b2aadff0913ce237 100644 (file)
@@ -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,