diff options
author | Wen Liang <liangwen12year@gmail.com> | 2023-10-31 08:55:46 -0400 |
---|---|---|
committer | Wen Liang <liangwen12year@gmail.com> | 2023-11-07 09:30:04 -0500 |
commit | 60f3c9faeb620e1bf4d28e7f9dc273e18d8ee2ec (patch) | |
tree | 211f74dd623c55233ab55986d3d7f223ad7d266b | |
parent | 85bcf2d99ffc5563193963ed2f4b464b3fd071be (diff) |
libnm: refactor the routing rule validation for from/to propertywl/routing_rule_fix
The function which does the routing rule validation should be
`nm_ip_routing_rule_validate()`, therefore, move the check for
0 prefix length over into `nm_ip_routing_rule_validate()`.
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1755
-rw-r--r-- | src/core/platform/tests/test-route.c | 6 | ||||
-rw-r--r-- | src/libnm-core-impl/nm-setting-ip-config.c | 10 |
2 files changed, 12 insertions, 4 deletions
diff --git a/src/core/platform/tests/test-route.c b/src/core/platform/tests/test-route.c index 9aa21a9ac6..55ff6e8b08 100644 --- a/src/core/platform/tests/test-route.c +++ b/src/core/platform/tests/test-route.c @@ -1620,6 +1620,12 @@ test_rule(gconstpointer test_data) g_ptr_array_add(objs, RR(.addr_family = AF_INET, .priority = 51, .iifname = DEVICE_NAME, )); + g_ptr_array_add(objs, + RR(.addr_family = AF_INET, + .priority = 70, + .src = {{nmtst_inet4_from_string("0.0.0.0")}}, + .src_len = 0, )); + if (TEST_IDX == 1) { g_ptr_array_add(objs, RR(.addr_family = AF_INET, .table = 10000, )); } diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c index 3184c2747a..825df0f8c3 100644 --- a/src/libnm-core-impl/nm-setting-ip-config.c +++ b/src/libnm-core-impl/nm-setting-ip-config.c @@ -2766,7 +2766,8 @@ nm_ip_routing_rule_validate(const NMIPRoutingRule *self, GError **error) } if (self->from_len == 0) { - if (self->from_has) { + if (self->from_has + && !nm_ip_addr_is_null(_ip_routing_rule_get_addr_family(self), &self->from_bin)) { g_set_error_literal(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, @@ -2797,7 +2798,8 @@ nm_ip_routing_rule_validate(const NMIPRoutingRule *self, GError **error) } if (self->to_len == 0) { - if (self->to_has) { + if (self->to_has + && !nm_ip_addr_is_null(_ip_routing_rule_get_addr_family(self), &self->to_bin)) { g_set_error_literal(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, @@ -3743,11 +3745,11 @@ next_words_consumed: if (i64_suppress_prefixlength != -1) nm_ip_routing_rule_set_suppress_prefixlength(self, i64_suppress_prefixlength); - if (val_from_len > 0 || (val_from_len == 0 && !nm_ip_addr_is_null(addr_family, &val_from))) { + if (val_from_len >= 0) { nm_ip_routing_rule_set_from_bin(self, &val_from, val_from_len); } - if (val_to_len > 0 || (val_to_len == 0 && !nm_ip_addr_is_null(addr_family, &val_to))) { + if (val_to_len >= 0) { nm_ip_routing_rule_set_to_bin(self, &val_to, val_to_len); } |