]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/network/test-routing-policy-rule.c
tree-wide: beautify remaining copyright statements
[thirdparty/systemd.git] / src / network / test-routing-policy-rule.c
index a4c568e325b20f69bc8794e0e4b9435a67b412af..e91290e8b08c6cc976a21d386e9b7e7f115012aa 100644 (file)
@@ -1,22 +1,7 @@
 /***
   SPDX-License-Identifier: LGPL-2.1+
 
-  This file is part of systemd.
-
-  Copyright 2017 Zbigniew Jędrzejewski-Szmek
-
-  systemd is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or
-  (at your option) any later version.
-
-  systemd is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+  Copyright © 2017 Zbigniew Jędrzejewski-Szmek
 ***/
 
 #include "fd-util.h"
@@ -34,20 +19,22 @@ static void test_rule_serialization(const char *title, const char *ruleset, cons
         const char *cmd;
         int fd, fd2, fd3;
         _cleanup_fclose_ FILE *f = NULL, *f2 = NULL, *f3 = NULL;
-        _cleanup_set_free_free_ Set *rules = NULL;
+        Set *rules = NULL;
         _cleanup_free_ char *buf = NULL;
         size_t buf_size;
 
         log_info("========== %s ==========", title);
         log_info("put:\n%s\n", ruleset);
 
-        assert_se((fd = mkostemp_safe(pattern)) >= 0);
+        fd = mkostemp_safe(pattern);
+        assert_se(fd >= 0);
         assert_se(f = fdopen(fd, "a+e"));
         assert_se(write_string_stream(f, ruleset, 0) == 0);
 
         assert_se(routing_policy_load_rules(pattern, &rules) == 0);
 
-        assert_se((fd2 = mkostemp_safe(pattern2)) >= 0);
+        fd2 = mkostemp_safe(pattern2);
+        assert_se(fd2 >= 0);
         assert_se(f2 = fdopen(fd2, "a+e"));
 
         assert_se(routing_policy_serialize_rules(rules, f2) == 0);
@@ -57,13 +44,16 @@ static void test_rule_serialization(const char *title, const char *ruleset, cons
 
         log_info("got:\n%s", buf);
 
-        assert_se((fd3 = mkostemp_safe(pattern3)) >= 0);
+        fd3 = mkostemp_safe(pattern3);
+        assert_se(fd3 >= 0);
         assert_se(f3 = fdopen(fd3, "we"));
         assert_se(write_string_stream(f3, expected ?: ruleset, 0) == 0);
 
         cmd = strjoina("diff -u ", pattern3, " ", pattern2);
         log_info("$ %s", cmd);
         assert_se(system(cmd) == 0);
+
+        set_free_with_destructor(rules, routing_policy_rule_free);
 }
 
 int main(int argc, char **argv) {
@@ -89,5 +79,16 @@ int main(int argc, char **argv) {
         test_rule_serialization("default table",
                                 "RULE=from=1::2/64 to=2::3/64", p);
 
+        test_rule_serialization("incoming interface",
+                                "RULE=from=1::2/64 to=2::3/64 table=1 iif=lo",
+                                "RULE=from=1::2/64 to=2::3/64 iif=lo table=1");
+
+        test_rule_serialization("outgoing interface",
+                                "RULE=from=1::2/64 to=2::3/64 oif=eth0 table=1", NULL);
+
+        test_rule_serialization("freeing interface names",
+                                "RULE=from=1::2/64 to=2::3/64 iif=e0 iif=e1 oif=e0 oif=e1 table=1",
+                                "RULE=from=1::2/64 to=2::3/64 iif=e1 oif=e1 table=1");
+
         return 0;
 }