local-addresses: also save weight of multipath routes

This commit is contained in:
Yu Watanabe
2024-01-20 16:07:19 +09:00
parent 0b2c0c3159
commit eb1f9ed6a0
3 changed files with 16 additions and 8 deletions
+13 -6
View File
@@ -29,6 +29,10 @@ static int address_compare(const struct local_address *a, const struct local_add
if (r != 0)
return r;
r = CMP(a->weight, b->weight);
if (r != 0)
return r;
r = CMP(a->ifindex, b->ifindex);
if (r != 0)
return r;
@@ -64,6 +68,7 @@ static int add_local_address_full(
int ifindex,
unsigned char scope,
uint32_t priority,
uint32_t weight,
int family,
const union in_addr_union *address) {
@@ -80,6 +85,7 @@ static int add_local_address_full(
.ifindex = ifindex,
.scope = scope,
.priority = priority,
.weight = weight,
.family = family,
.address = *address,
};
@@ -95,7 +101,7 @@ static int add_local_address(
int family,
const union in_addr_union *address) {
return add_local_address_full(list, n_list, ifindex, scope, 0, family, address);
return add_local_address_full(list, n_list, ifindex, scope, 0, 0, family, address);
}
int local_addresses(
@@ -216,10 +222,11 @@ static int add_local_gateway(
size_t *n_list,
int ifindex,
uint32_t priority,
uint32_t weight,
int family,
const union in_addr_union *address) {
return add_local_address_full(list, n_list, ifindex, 0, priority, family, address);
return add_local_address_full(list, n_list, ifindex, 0, priority, weight, family, address);
}
int local_gateways(
@@ -329,7 +336,7 @@ int local_gateways(
if (r < 0 && r != -ENODATA)
return r;
if (r >= 0) {
r = add_local_gateway(&list, &n_list, ifi, priority, family, &gateway);
r = add_local_gateway(&list, &n_list, ifi, priority, 0, family, &gateway);
if (r < 0)
return r;
@@ -350,7 +357,7 @@ int local_gateways(
if (via.family != AF_INET6)
return -EBADMSG;
r = add_local_gateway(&list, &n_list, ifi, priority, via.family,
r = add_local_gateway(&list, &n_list, ifi, priority, 0, via.family,
&(union in_addr_union) { .in6 = via.address.in6 });
if (r < 0)
return r;
@@ -381,7 +388,7 @@ int local_gateways(
continue;
union in_addr_union a = mr->gateway.address;
r = add_local_gateway(&list, &n_list, ifi, priority, mr->gateway.family, &a);
r = add_local_gateway(&list, &n_list, ifi, priority, mr->weight, mr->gateway.family, &a);
if (r < 0)
return r;
}
@@ -404,7 +411,7 @@ static int add_local_outbound(
int family,
const union in_addr_union *address) {
return add_local_address_full(list, n_list, ifindex, 0, 0, family, address);
return add_local_address_full(list, n_list, ifindex, 0, 0, 0, family, address);
}
int local_outbounds(
+1
View File
@@ -9,6 +9,7 @@ struct local_address {
int ifindex;
unsigned char scope;
uint32_t priority;
uint32_t weight;
int family;
union in_addr_union address;
};
+2 -2
View File
@@ -10,8 +10,8 @@
static void print_local_addresses(const struct local_address *a, size_t n) {
FOREACH_ARRAY(i, a, n)
log_debug("%s ifindex=%i scope=%u priority=%"PRIu32" address=%s",
af_to_name(i->family), i->ifindex, i->scope, i->priority,
log_debug("%s ifindex=%i scope=%u priority=%"PRIu32" weight=%"PRIu32" address=%s",
af_to_name(i->family), i->ifindex, i->scope, i->priority, i->weight,
IN_ADDR_TO_STRING(i->family, &i->address));
}