network: treat rule which has l3mdev flag as created by kernel
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 29 Oct 2020 02:55:12 +0000 (11:55 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 12 Mar 2021 16:34:35 +0000 (17:34 +0100)
[#17477,3/5] cherry-picked from e737dce5445ac2359f4f260aa462056b02d68d54

src/network/networkd-routing-policy-rule.c
src/network/networkd-routing-policy-rule.h

index 7b4de05595b04b50c73fa9474f9739f899024034..2896f7d759cd2ee51f19b740557375fa87c8e918 100644 (file)
@@ -718,6 +718,11 @@ static const RoutingPolicyRule kernel_rules[] = {
 static bool routing_policy_rule_is_created_by_kernel(const RoutingPolicyRule *rule) {
         assert(rule);
 
+        if (rule->l3mdev > 0)
+                /* Currently, [RoutingPolicyRule] does not explicitly set FRA_L3MDEV. So, if the flag
+                 * is set, it is safe to treat the rule as created by kernel. */
+                return true;
+
         for (size_t i = 0; i < ELEMENTSOF(kernel_rules); i++)
                 if (routing_policy_rule_equal(rule, &kernel_rules[i]))
                         return true;
@@ -866,6 +871,12 @@ int manager_rtnl_process_rule(sd_netlink *rtnl, sd_netlink_message *message, Man
                 return 0;
         }
 
+        r = sd_netlink_message_read_u8(message, FRA_L3MDEV, &tmp->l3mdev);
+        if (r < 0 && r != -ENODATA) {
+                log_warning_errno(r, "rtnl: could not get FRA_L3MDEV 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");
@@ -1471,6 +1482,12 @@ static int routing_policy_rule_section_verify(RoutingPolicyRule *rule) {
         if (rule->family == AF_UNSPEC && rule->address_family == ADDRESS_FAMILY_NO)
                 rule->family = AF_INET;
 
+        /* Currently, [RoutingPolicyRule] does not have a setting to set FRA_L3MDEV flag. Please also
+         * update routing_policy_rule_is_created_by_kernel() when a new setting which sets the flag is
+         * added in the future. */
+        if (rule->l3mdev > 0)
+                assert_not_reached("FRA_L3MDEV flag should not be configured.");
+
         return 0;
 }
 
index 30ee00b603efee011345a8d488b12b211b4628b4..f5705f1749aa4e93eb7e8c8acc0220446465d09d 100644 (file)
@@ -25,6 +25,7 @@ typedef struct RoutingPolicyRule {
         uint8_t tos;
         uint8_t ipproto; /* FRA_IP_PROTO */
         uint8_t protocol; /* FRA_PROTOCOL */
+        uint8_t l3mdev; /* FRA_L3MDEV */
 
         uint32_t table;
         uint32_t fwmark;