]> git.ozlabs.org Git - ppp.git/commitdiff
pppd: Restore adding a default route with different metric (#472)
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Tue, 13 Feb 2024 09:36:08 +0000 (10:36 +0100)
committerGitHub <noreply@github.com>
Tue, 13 Feb 2024 09:36:08 +0000 (20:36 +1100)
For instance, when using a ppp link as backup link, one would want to
add a default route on the ppp link, in *addition* to the existing
default route.

d0ccb87156c2 ("pppd: Add replacedefaultroute option (#200)") however broke
this case: sifdefaultroute was not passing the metric to
defaultroute_exists any more. This commit restores this case.

Fixes #357

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
pppd/sys-linux.c

index a16ab1258ff7a4fc25cf60708f22628831017f72..c0955a05b9a89dbd60afe4e51821df9473646a38 100644 (file)
@@ -2193,11 +2193,27 @@ int sifdefaultroute (int unit, u_int32_t ouraddr, u_int32_t gateway, bool replac
         * - this is normally only the case the doing demand: */
        if (defaultroute_exists(&tmp_rt, -1))
            del_rt = &tmp_rt;
+    } else if (!replace) {
+       /*
+        * We don't want to replace an existing route.
+        * We may however add our route along an existing route with a different
+        * metric.
+        */
+       if (defaultroute_exists(&rt, dfl_route_metric) && strcmp(rt.rt_dev, ifname) != 0) {
+          if (rt.rt_flags & RTF_GATEWAY)
+              error("not replacing existing default route via %I with metric %d",
+                    SIN_ADDR(rt.rt_gateway), dfl_route_metric);
+          else
+              error("not replacing existing default route through %s with metric %d",
+                    rt.rt_dev, dfl_route_metric);
+          return 0;
+       }
     } else if (defaultroute_exists(&old_def_rt, -1           ) &&
                            strcmp( old_def_rt.rt_dev, ifname) != 0) {
        /*
-        * We did not yet replace an existing default route, let's
-        * check if we should save and replace a default route:
+        * We want to replace an existing route and did not replace an existing
+        * default route yet, let's check if we should save and replace an
+        * existing default route:
         */
        u_int32_t old_gateway = SIN_ADDR(old_def_rt.rt_gateway);