libnm: refactor the routing rule validation for from/to property

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
This commit is contained in:
Wen Liang 2023-10-31 08:55:46 -04:00
parent 85bcf2d99f
commit 60f3c9faeb
2 changed files with 12 additions and 4 deletions

View file

@ -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, ));
}

View file

@ -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);
}