diff --git a/src/libcharon/kernel/kernel_interface.h b/src/libcharon/kernel/kernel_interface.h index 21cabe7f0..a8c9d6f41 100644 --- a/src/libcharon/kernel/kernel_interface.h +++ b/src/libcharon/kernel/kernel_interface.h @@ -312,6 +312,8 @@ struct kernel_interface_t { * The returned host is allocated and must be destroyed. * An optional src address can be used to check if a route is available * for the given source to dest. + * 0.0.0.0/:: may get returend if an interface but no next hop can be + * determined. * * @param dest target destination address * @param prefix prefix length if dest is a subnet, -1 for auto diff --git a/src/libcharon/kernel/kernel_net.h b/src/libcharon/kernel/kernel_net.h index 2dc247e90..ece59ad4d 100644 --- a/src/libcharon/kernel/kernel_net.h +++ b/src/libcharon/kernel/kernel_net.h @@ -85,6 +85,8 @@ struct kernel_net_t { * The returned host is allocated and must be destroyed. * An optional src address can be used to check if a route is available * for the given source to dest. + * 0.0.0.0/:: may get returend if an interface but no next hop can be + * determined. * * @param dest target destination address * @param prefix prefix length if dest is a subnet, -1 for auto diff --git a/src/libcharon/plugins/kernel_netlink/kernel_netlink_ipsec.c b/src/libcharon/plugins/kernel_netlink/kernel_netlink_ipsec.c index dc1486b0f..810b07e61 100644 --- a/src/libcharon/plugins/kernel_netlink/kernel_netlink_ipsec.c +++ b/src/libcharon/plugins/kernel_netlink/kernel_netlink_ipsec.c @@ -3008,7 +3008,7 @@ static void install_route(private_kernel_netlink_ipsec_t *this, policy->route = NULL; } - DBG2(DBG_KNL, "installing route: %R via %H src %H dev %s", out->dst_ts, + DBG2(DBG_KNL, "installing route: %R via %+H src %H dev %s", out->dst_ts, route->gateway, route->src_ip, route->if_name); switch (charon->kernel->add_route(charon->kernel, route->dst_net, route->prefixlen, route->gateway, diff --git a/src/libcharon/plugins/kernel_netlink/kernel_netlink_net.c b/src/libcharon/plugins/kernel_netlink/kernel_netlink_net.c index 416ae7811..6742b618d 100644 --- a/src/libcharon/plugins/kernel_netlink/kernel_netlink_net.c +++ b/src/libcharon/plugins/kernel_netlink/kernel_netlink_net.c @@ -2075,9 +2075,9 @@ static host_t *get_route(private_kernel_netlink_net_t *this, host_t *dest, *iface = get_interface_name_by_index(this, best->oif); } } - if (!addr && !match_net) - { /* fallback to destination address */ - addr = dest->clone(dest); + if (!addr && !match_net && iface && *iface) + { + addr = host_create_any(dest->get_family(dest)); } } else @@ -2600,7 +2600,8 @@ static status_t manage_srcroute(private_kernel_netlink_net_t *this, { chunk = src_ip->get_address(src_ip); netlink_add_attribute(hdr, RTA_PREFSRC, chunk, sizeof(request)); - if (gateway && gateway->get_family(gateway) == src_ip->get_family(src_ip)) + if (gateway && !gateway->is_anyaddr(gateway) && + gateway->get_family(gateway) == src_ip->get_family(src_ip)) { chunk = gateway->get_address(gateway); netlink_add_attribute(hdr, RTA_GATEWAY, chunk, sizeof(request)); diff --git a/testing/tests/ikev2/shunt-manual-prio/hosts/carol/etc/strongswan.conf b/testing/tests/ikev2/shunt-manual-prio/hosts/carol/etc/strongswan.conf index 203f1a7b9..0fe180ced 100755 --- a/testing/tests/ikev2/shunt-manual-prio/hosts/carol/etc/strongswan.conf +++ b/testing/tests/ikev2/shunt-manual-prio/hosts/carol/etc/strongswan.conf @@ -6,4 +6,6 @@ charon-systemd { load = random nonce openssl pem pkcs1 revocation curl kernel-netlink socket-default updown vici + # conflicts with the route via moon we have installed to reach hosts in its subnet directly + install_routes = no } diff --git a/testing/tests/ikev2/shunt-manual-prio/hosts/dave/etc/strongswan.conf b/testing/tests/ikev2/shunt-manual-prio/hosts/dave/etc/strongswan.conf index 203f1a7b9..0fe180ced 100755 --- a/testing/tests/ikev2/shunt-manual-prio/hosts/dave/etc/strongswan.conf +++ b/testing/tests/ikev2/shunt-manual-prio/hosts/dave/etc/strongswan.conf @@ -6,4 +6,6 @@ charon-systemd { load = random nonce openssl pem pkcs1 revocation curl kernel-netlink socket-default updown vici + # conflicts with the route via moon we have installed to reach hosts in its subnet directly + install_routes = no }