]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
kernel-netlink: Prefer finding a source IP via next hop over interface kernel-netlink-prefer-gw
authorTobias Brunner <tobias@strongswan.org>
Tue, 9 May 2017 12:32:21 +0000 (14:32 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 9 May 2017 12:32:21 +0000 (14:32 +0200)
If there are private and public addresses on an interface we should look
for other routes that use the listed next hop as the order of the
addresses is pretty much random.

src/libcharon/plugins/kernel_netlink/kernel_netlink_net.c

index 2dc76d941ce674b45c02ca5c880b67512e847103..75983e9f86026e7010ebdddc631bb733c04f74b4 100644 (file)
@@ -2035,22 +2035,6 @@ static host_t *get_route(private_kernel_netlink_net_t *this, host_t *dest,
                                continue;
                        }
                }
-               if (route->oif)
-               {       /* no src, but an interface - get address from it */
-                       route->src_host = get_interface_address(this, route->oif,
-                                                                                       msg->rtm_family, dest, candidate);
-                       if (route->src_host)
-                       {       /* more of the same */
-                               if (!candidate ||
-                                        candidate->ip_equals(candidate, route->src_host))
-                               {
-                                       best = route;
-                                       break;
-                               }
-                               best = best ?: route;
-                               continue;
-                       }
-               }
                if (route->gtw.ptr)
                {       /* no src, no iface, but a gateway - lookup src to reach gtw */
                        host_t *gtw;
@@ -2073,6 +2057,22 @@ static host_t *get_route(private_kernel_netlink_net_t *this, host_t *dest,
                                best = best ?: route;
                        }
                }
+               if (route->oif)
+               {       /* no src, but an interface - get address from it */
+                       route->src_host = get_interface_address(this, route->oif,
+                                                                                       msg->rtm_family, dest, candidate);
+                       if (route->src_host)
+                       {       /* more of the same */
+                               if (!candidate ||
+                                        candidate->ip_equals(candidate, route->src_host))
+                               {
+                                       best = route;
+                                       break;
+                               }
+                               best = best ?: route;
+                               continue;
+                       }
+               }
        }
        enumerator->destroy(enumerator);