Package: ppp
Version: 2.4.4rel-10.2
Severity: wishlist
Tags: patch

At the moment, with options defaultroute and replacedefaultroute, ppp
considers all default routes equally. If there is one, it will be left
alone or replaced, regardless of its metric.

The proposed patch allows to optionally specify a route metric to
1) set the metric on the default route going through the ppp device,
2) limit the search for existing default routes which may be replaced or
prevent pppd from setting its own.

The default value is -1, which triggers the normal (unpatched)
behaviour: checking for the presence of any default route, and possibly
replacing it. Setting the option to any value > 0 will have ppp limit
itself to checking default routes with this metric. If any is found,
pppd will depend on options defaultroute and replacedefaultroute to
decide what to do, as in the normal case.

My ppp-2.4.4rel-10.2 is just a local fork of ppp-2.4.4rel-10.1 including
the following patch.  It may have an impact on Bug#425163.

================ cifdefaultroute-metric.dif =======================
Default route metric

Define the metric of the default route and only add it if there
is no other default route with the same metric.  With the default
value of -1, the route is only added if there is no default route at
all.

This patch is to be applied on top of the replacedefaultroute patch
from Debian.

Olivier Mehani <olivier.meh...@nicta.com.au>
Index: ppp-2.4.4/pppd/options.c
===================================================================
--- ppp-2.4.4.orig/pppd/options.c       2010-04-22 17:04:46.000000000 +1000
+++ ppp-2.4.4/pppd/options.c    2010-04-22 17:04:58.000000000 +1000
@@ -121,6 +121,7 @@
 bool   dryrun;                 /* print out option values and exit */
 char   *domain;                /* domain name set by domain option */
 int    child_wait = 5;         /* # seconds to wait for children at exit */
+int    dfl_route_metric = -1;  /* metric of the default route to set over the 
PPP link */
 
 #ifdef MAXOCTETS
 unsigned int  maxoctets = 0;    /* default - no limit */
@@ -290,6 +291,10 @@
       "Set pathname of ip-down script",
       OPT_PRIV|OPT_STATIC, NULL, MAXPATHLEN },
 
+    { "defaultroute-metric", o_int, &dfl_route_metric,
+      "Metric to use for the default route (Linux only; -1 for default 
behavior)",
+      OPT_PRIV|OPT_LLIMIT|OPT_INITONLY, NULL, 0, -1 },
+
 #ifdef HAVE_MULTILINK
     { "multilink", o_bool, &multilink,
       "Enable multilink operation", OPT_PRIO | 1 },
Index: ppp-2.4.4/pppd/sys-linux.c
===================================================================
--- ppp-2.4.4.orig/pppd/sys-linux.c     2010-04-22 17:04:46.000000000 +1000
+++ ppp-2.4.4/pppd/sys-linux.c  2010-04-22 17:05:38.000000000 +1000
@@ -234,7 +234,7 @@
 static void close_route_table (void);
 static int open_route_table (void);
 static int read_route_table (struct rtentry *rt);
-static int defaultroute_exists (struct rtentry *rt);
+static int defaultroute_exists (struct rtentry *rt, int metric);
 static int get_ether_addr (u_int32_t ipaddr, struct sockaddr *hwaddr,
                           char *name, int namelen);
 static void decode_version (char *buf, int *version, int *mod, int *patch);
@@ -244,6 +244,8 @@
 
 extern u_char  inpacket_buf[]; /* borrowed from main.c */
 
+extern int dfl_route_metric;
+
 /*
  * SET_SA_FAMILY - set the sa_family field of a struct sockaddr,
  * if it exists.
@@ -1538,9 +1540,10 @@
 /********************************************************************
  *
  * defaultroute_exists - determine if there is a default route
+ * with the given metric (or negative for any)
  */
 
-static int defaultroute_exists (struct rtentry *rt)
+static int defaultroute_exists (struct rtentry *rt, int metric)
 {
     int result = 0;
 
@@ -1553,7 +1556,8 @@
 
        if (kernel_version > KVERSION(2,1,0) && SIN_ADDR(rt->rt_genmask) != 0)
            continue;
-       if (SIN_ADDR(rt->rt_dst) == 0L) {
+       if (SIN_ADDR(rt->rt_dst) == 0L && (metric < 0 ||
+                        (metric >= 0 && (rt->rt_metric + 1) == metric))) {
            result = 1;
            break;
        }
@@ -1614,16 +1618,16 @@
           are called again, we will delete the current default route
           and set the new default route in this function.
           - this is normally only the case the doing demand: */
-       if (defaultroute_exists(&tmp_rt))
+       if (defaultroute_exists(&tmp_rt, dfl_route_metric))
            del_rt = &tmp_rt;
-    } else if (defaultroute_exists(&old_def_rt) &&
+    } else if (defaultroute_exists(&old_def_rt, dfl_route_metric) &&
               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: */
        if (old_def_rt.rt_flags & RTF_GATEWAY) {
            if (!replace) {
-               error("not replacing existing default route via %I",
-                     SIN_ADDR(old_def_rt.rt_gateway));
+               error("not replacing existing default route via %I with metric 
%d",
+                     SIN_ADDR(old_def_rt.rt_gateway), dfl_route_metric);
                return 0;
            } else {
                /* we need to copy rt_dev because we need it permanent too: */
@@ -1631,20 +1635,22 @@
                strcpy(tmp_dev, old_def_rt.rt_dev);
                old_def_rt.rt_dev = tmp_dev;
 
-               notice("replacing old default route to %s [%I]",
-                       old_def_rt.rt_dev, SIN_ADDR(old_def_rt.rt_gateway));
+               notice("replacing old default route to %s [%I, metric %d]",
+                       old_def_rt.rt_dev, SIN_ADDR(old_def_rt.rt_gateway),
+                       dfl_route_metric);
                default_rt_repl_rest = 1;
                del_rt = &old_def_rt;
            }
        } else
-           error("not replacing existing default route through %s",
-                 old_def_rt.rt_dev);
+           error("not replacing existing default route through %s with metric 
%d",
+                 old_def_rt.rt_dev, dfl_route_metric);
     }
 
     memset (&rt, 0, sizeof (rt));
     SET_SA_FAMILY (rt.rt_dst, AF_INET);
 
     rt.rt_dev = ifname;
+    rt.rt_metric = dfl_route_metric + 1; /* +1 for binary compatibility */
 
     if (kernel_version > KVERSION(2,1,0)) {
        SET_SA_FAMILY (rt.rt_genmask, AF_INET);
@@ -1683,6 +1689,9 @@
     SET_SA_FAMILY (rt.rt_dst,     AF_INET);
     SET_SA_FAMILY (rt.rt_gateway, AF_INET);
 
+    rt.rt_dev = ifname;
+    rt.rt_metric = dfl_route_metric + 1; /* +1 for binary compatibility */
+
     if (kernel_version > KVERSION(2,1,0)) {
        SET_SA_FAMILY (rt.rt_genmask, AF_INET);
        SIN_ADDR(rt.rt_genmask) = 0L;
Index: ppp-2.4.4/pppd/pppd.8
===================================================================
--- ppp-2.4.4.orig/pppd/pppd.8  2010-04-22 17:04:46.000000000 +1000
+++ ppp-2.4.4/pppd/pppd.8       2010-04-22 17:04:58.000000000 +1000
@@ -126,6 +126,12 @@
 set and this flag is also set, pppd replaces an existing default route
 with the new default route.
 .TP
+.B defaultroute-metric
+Define the metric of the \fIdefaultroute\fR and only add (or replace
+if \fIreplacedefaultroute\fR is used) it if there is no other default
+route with the same metric.  With the default value of -1, the route
+is only added if there is no default route at all.
+.TP
 .B disconnect \fIscript
 Execute the command specified by \fIscript\fR, by passing it to a
 shell, after

-- System Information:
Debian Release: 5.0.4
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: i386 (i686)

Kernel: Linux 2.6.26-2-web100-mipl-686 (SMP w/1 CPU core)
Locale: LANG=en_AU.UTF-8, LC_CTYPE=en_AU.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages ppp depends on:
ii  libc6                     2.7-18lenny2   GNU C Library: Shared libraries
ii  libpam-modules            1.0.1-5+lenny1 Pluggable Authentication Modules f
ii  libpam-runtime            1.0.1-5+lenny1 Runtime support for the PAM librar
ii  libpam0g                  1.0.1-5+lenny1 Pluggable Authentication Modules l
ii  libpcap0.8                0.9.8-5        system interface for user-level pa
ii  netbase                   4.34           Basic TCP/IP networking system
ii  procps                    1:3.2.7-11     /proc file system utilities

ppp recommends no packages.

Versions of packages ppp suggests:
ii  iptables                      1.4.2-6    administration tools for packet fi

-- no debconf information

Attachment: pgpkMHUmqZJ7t.pgp
Description: Cryptographic signature

Reply via email to