]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: set FRA_PROTOCOL to RTPROT_STATIC by default
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 28 Oct 2020 07:54:51 +0000 (16:54 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 29 Dec 2020 07:03:26 +0000 (16:03 +0900)
src/network/networkd-routing-policy-rule.c
src/network/networkd-routing-policy-rule.h
test/test-network/systemd-networkd-tests.py

index 8c9565bda918626e133865329a0869842f66ec64..4ede16e581dff84e41d1c7d60a9456ec77a6c866 100644 (file)
@@ -66,6 +66,7 @@ static int routing_policy_rule_new(RoutingPolicyRule **ret) {
                 .uid_range.start = UID_INVALID,
                 .uid_range.end = UID_INVALID,
                 .suppress_prefixlen = -1,
+                .protocol = RTPROT_UNSPEC,
                 .type = FR_ACT_TO_TBL,
         };
 
@@ -99,6 +100,7 @@ static int routing_policy_rule_new_static(Network *network, const char *filename
 
         rule->network = network;
         rule->section = TAKE_PTR(n);
+        rule->protocol = RTPROT_STATIC;
 
         r = hashmap_ensure_allocated(&network->rules_by_section, &network_config_hash_ops);
         if (r < 0)
@@ -144,6 +146,7 @@ static int routing_policy_rule_copy(RoutingPolicyRule *dest, RoutingPolicyRule *
         dest->table = src->table;
         dest->iif = TAKE_PTR(iif);
         dest->oif = TAKE_PTR(oif);
+        dest->ipproto = src->ipproto;
         dest->protocol = src->protocol;
         dest->sport = src->sport;
         dest->dport = src->dport;
@@ -177,6 +180,7 @@ static void routing_policy_rule_hash_func(const RoutingPolicyRule *rule, struct
                 siphash24_compress(&rule->table, sizeof(rule->table), state);
                 siphash24_compress(&rule->suppress_prefixlen, sizeof(rule->suppress_prefixlen), state);
 
+                siphash24_compress(&rule->ipproto, sizeof(rule->ipproto), state);
                 siphash24_compress(&rule->protocol, sizeof(rule->protocol), state);
                 siphash24_compress(&rule->sport, sizeof(rule->sport), state);
                 siphash24_compress(&rule->dport, sizeof(rule->dport), state);
@@ -250,6 +254,10 @@ static int routing_policy_rule_compare_func(const RoutingPolicyRule *a, const Ro
                 if (r != 0)
                         return r;
 
+                r = CMP(a->ipproto, b->ipproto);
+                if (r != 0)
+                        return r;
+
                 r = CMP(a->protocol, b->protocol);
                 if (r != 0)
                         return r;
@@ -458,10 +466,14 @@ static int routing_policy_rule_set_netlink_message(RoutingPolicyRule *rule, sd_n
                         return log_link_error_errno(link, r, "Could not append FRA_OIFNAME attribute: %m");
         }
 
-        r = sd_netlink_message_append_u8(m, FRA_IP_PROTO, rule->protocol);
+        r = sd_netlink_message_append_u8(m, FRA_IP_PROTO, rule->ipproto);
         if (r < 0)
                 return log_link_error_errno(link, r, "Could not append FRA_IP_PROTO attribute: %m");
 
+        r = sd_netlink_message_append_u8(m, FRA_PROTOCOL, rule->protocol);
+        if (r < 0)
+                return log_link_error_errno(link, r, "Could not append FRA_PROTOCOL attribute: %m");
+
         if (rule->sport.start != 0 || rule->sport.end != 0) {
                 r = sd_netlink_message_append_data(m, FRA_SPORT_RANGE, &rule->sport, sizeof(rule->sport));
                 if (r < 0)
@@ -852,12 +864,18 @@ int manager_rtnl_process_rule(sd_netlink *rtnl, sd_netlink_message *message, Man
         if (r < 0)
                 return log_oom();
 
-        r = sd_netlink_message_read_u8(message, FRA_IP_PROTO, &tmp->protocol);
+        r = sd_netlink_message_read_u8(message, FRA_IP_PROTO, &tmp->ipproto);
         if (r < 0 && r != -ENODATA) {
                 log_warning_errno(r, "rtnl: could not get FRA_IP_PROTO attribute, ignoring: %m");
                 return 0;
         }
 
+        r = sd_netlink_message_read_u8(message, FRA_PROTOCOL, &tmp->protocol);
+        if (r < 0 && r != -ENODATA) {
+                log_warning_errno(r, "rtnl: could not get FRA_PROTOCOL attribute, ignoring: %m");
+                return 0;
+        }
+
         r = sd_netlink_message_read(message, FRA_SPORT_RANGE, sizeof(tmp->sport), &tmp->sport);
         if (r < 0 && r != -ENODATA) {
                 log_warning_errno(r, "rtnl: could not get FRA_SPORT_RANGE attribute, ignoring: %m");
@@ -1271,7 +1289,7 @@ int config_parse_routing_policy_rule_ip_protocol(
                 return 0;
         }
 
-        n->protocol = r;
+        n->ipproto = r;
 
         n = NULL;
 
@@ -1599,10 +1617,10 @@ int routing_policy_serialize_rules(Set *rules, FILE *f) {
                         space = true;
                 }
 
-                if (rule->protocol != 0) {
-                        fprintf(f, "%sprotocol=%hhu",
+                if (rule->ipproto != 0) {
+                        fprintf(f, "%sipproto=%hhu",
                                 space ? " " : "",
-                                rule->protocol);
+                                rule->ipproto);
                         space = true;
                 }
 
@@ -1777,10 +1795,10 @@ int routing_policy_load_rules(const char *state_file, Set **rules) {
 
                                 if (free_and_strdup(&rule->oif, b) < 0)
                                         return log_oom();
-                        } else if (streq(a, "protocol")) {
-                                r = safe_atou8(b, &rule->protocol);
+                        } else if (streq(a, "ipproto")) {
+                                r = safe_atou8(b, &rule->ipproto);
                                 if (r < 0) {
-                                        log_warning_errno(r, "Failed to parse RPDB rule protocol, ignoring: %s", b);
+                                        log_warning_errno(r, "Failed to parse RPDB rule IP protocol, ignoring: %s", b);
                                         continue;
                                 }
                         } else if (streq(a, "sourceport")) {
index 1b574452e2e388e9e1975e667ac386a208454b45..3786eee34bccffc4851027a50a9c4c5b96f4dd7e 100644 (file)
@@ -24,7 +24,8 @@ typedef struct RoutingPolicyRule {
 
         uint8_t tos;
         uint8_t type;
-        uint8_t protocol;
+        uint8_t ipproto; /* FRA_IP_PROTO */
+        uint8_t protocol; /* FRA_PROTOCOL */
         uint8_t to_prefixlen;
         uint8_t from_prefixlen;
 
index 1c4046d4f27a9968c3046ddde9451bea07d49bfc..41d3e7036ba56c1d0e68210edb0b3ae4ad0b8003 100755 (executable)
@@ -3326,7 +3326,7 @@ class NetworkdBridgeTests(unittest.TestCase, Utilities):
 
         output = check_output('ip rule list table 100')
         print(output)
-        self.assertEqual(output, '0:   from all to 8.8.8.8 lookup 100')
+        self.assertIn('0:      from all to 8.8.8.8 lookup 100', output)
 
 class NetworkdLLDPTests(unittest.TestCase, Utilities):
     links = ['veth99']