[PATCH 1/2] interface-ip: copy more info for target host route
Felix Fietkau
nbd at nbd.name
Wed Oct 27 09:50:15 PDT 2021
On 2021-10-26 23:59, luizluca at gmail.com wrote:
> From: Luiz Angelo Daros de Luca <luizluca at gmail.com>
>
> interface_ip_add_target_route was adding a host route without
> copying other confs like type, source, online). The result was that this:
>
> unreachable 192.168.0.9 metric 123
>
> was being converted to:
>
> 192.168.0.9 dev lo scope link metric 123
>
> Signed-off-by: Luiz Angelo Daros de Luca <luizluca at gmail.com>
> ---
> interface-ip.c | 23 ++++++++++++++++++++---
> 1 file changed, 20 insertions(+), 3 deletions(-)
>
> diff --git a/interface-ip.c b/interface-ip.c
> index 648f521..7c60fec 100644
> --- a/interface-ip.c
> +++ b/interface-ip.c
> @@ -301,9 +301,26 @@ interface_ip_add_target_route(union if_addr *addr, bool v6, struct interface *if
> route->mask = v6 ? 128 : 32;
> memcpy(&route->addr, addr, addrsize);
> memcpy(&route->nexthop, &r_next->nexthop, sizeof(route->nexthop));
> - route->mtu = r_next->mtu;
> - route->metric = r_next->metric;
> - route->table = r_next->table;
> + if (r_next->flags & DEVROUTE_MTU) {
> + route->mtu = r_next->mtu;
> + route->flags |= DEVROUTE_MTU;
> + }
> + if (r_next->flags & DEVROUTE_METRIC) {
> + route->metric = r_next->metric;
> + route->flags |= DEVROUTE_METRIC;
> + }
> + if (r_next->flags & DEVROUTE_TABLE) {
> + route->table = r_next->table;
> + route->flags |= DEVROUTE_TABLE;
> + }
> + if (r_next->flags & DEVROUTE_TYPE) {
> + route->type = r_next->type;
> + route->flags |= DEVROUTE_TYPE;
> + }
> + if (r_next->flags & DEVROUTE_ONLINK)
> + route->flags |= DEVROUTE_ONLINK;
How about leaving the route->{mtu,metric,table} assignment as-is and
doing something like this:
route->flags |= r->next & (DEVROUTE_MTU | DEVROUTE_METRIC |
DEVROUTE_TYPE | DEVROUTE_ONLINK);
- Felix
More information about the openwrt-devel
mailing list