Ticket #6892: defaultroute-metric.patch

File defaultroute-metric.patch, 4.3 KB (added by Olivier Mehani <olivier.mehani@…>, 7 years ago)

Check the existing default route metric before adding.

  • pppd/options.c

    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
    
    Olivier Mehani <olivier.mehani@nicta.com.au>
    old new  
    121121bool    dryrun;                 /* print out option values and exit */ 
    122122char    *domain;                /* domain name set by domain option */ 
    123123int     child_wait = 5;         /* # seconds to wait for children at exit */ 
     124int     dfl_route_metric = -1   /* metric of the default route to set over the PPP link */ 
    124125 
    125126#ifdef MAXOCTETS 
    126127unsigned int  maxoctets = 0;    /* default - no limit */ 
     
    290291      "Set pathname of ip-down script", 
    291292      OPT_PRIV|OPT_STATIC, NULL, MAXPATHLEN }, 
    292293 
     294    { "defaultroute-metric", o_int, &dfl_route_metric, 
     295      "Metric to use for the default route (Linux only; -1 for default behavior)", 
     296      OPT_PRIV|OPT_LLIMIT|OPT_INITONLY, NULL, 0, -1 }, 
     297 
    293298#ifdef HAVE_MULTILINK 
    294299    { "multilink", o_bool, &multilink, 
    295300      "Enable multilink operation", OPT_PRIO | 1 }, 
  • pppd/sys-linux.c

    old new  
    232232static void close_route_table (void); 
    233233static int open_route_table (void); 
    234234static int read_route_table (struct rtentry *rt); 
    235 static int defaultroute_exists (struct rtentry *rt); 
     235static int defaultroute_exists (struct rtentry *rt, int metric); 
    236236static int get_ether_addr (u_int32_t ipaddr, struct sockaddr *hwaddr, 
    237237                           char *name, int namelen); 
    238238static void decode_version (char *buf, int *version, int *mod, int *patch); 
     
    15261526/******************************************************************** 
    15271527 * 
    15281528 * defaultroute_exists - determine if there is a default route 
     1529 * with the given metric (or negative for any) 
    15291530 */ 
    15301531 
    1531 static int defaultroute_exists (struct rtentry *rt) 
     1532static int defaultroute_exists (struct rtentry *rt, int metric) 
    15321533{ 
    15331534    int result = 0; 
    15341535 
     
    15411542 
    15421543        if (kernel_version > KVERSION(2,1,0) && SIN_ADDR(rt->rt_genmask) != 0) 
    15431544            continue; 
    1544         if (SIN_ADDR(rt->rt_dst) == 0L) { 
     1545        if (SIN_ADDR(rt->rt_dst) == 0L && (metric < 0 || 
     1546                         (metric >= 0 && (rt->rt_metric + 1) == metric))) { 
    15451547            result = 1; 
    15461548            break; 
    15471549        } 
     
    15871589int sifdefaultroute (int unit, u_int32_t ouraddr, u_int32_t gateway) 
    15881590{ 
    15891591    struct rtentry rt; 
     1592    int metric = ; 
    15901593 
    1591     if (defaultroute_exists(&rt) && strcmp(rt.rt_dev, ifname) != 0) { 
     1594    if (defaultroute_exists(&rt, dfl_route_metric) && strcmp(rt.rt_dev, ifname) != 0) { 
    15921595        if (rt.rt_flags & RTF_GATEWAY) 
    1593             error("not replacing existing default route via %I", 
    1594                   SIN_ADDR(rt.rt_gateway)); 
     1596            error("not replacing existing default route via %I with metric %d", 
     1597                  SIN_ADDR(rt.rt_gateway, dfl_route_metric)); 
    15951598        else 
    1596             error("not replacing existing default route through %s", 
    1597                   rt.rt_dev); 
     1599            error("not replacing existing default route through %s with metric %d", 
     1600                  rt.rt_dev, dfl_route_metric); 
    15981601        return 0; 
    15991602    } 
    16001603 
     
    16021605    SET_SA_FAMILY (rt.rt_dst, AF_INET); 
    16031606 
    16041607    rt.rt_dev = ifname; 
     1608    rt.rt_metric = dfl_route_metric + 1; /* +1 for binary compatibility */ 
    16051609 
    16061610    if (kernel_version > KVERSION(2,1,0)) { 
    16071611        SET_SA_FAMILY (rt.rt_genmask, AF_INET); 
  • pppd/pppd.8

    old new  
    121121This entry is removed when the PPP connection is broken.  This option 
    122122is privileged if the \fInodefaultroute\fR option has been specified. 
    123123.TP 
     124.B defaultroute-metric 
     125Define the metric of the \fIdefaultroute\fR and only add it if there 
     126is no other default route with the same metric.  With the default 
     127value of -1, the route is only added if there is no default route at 
     128all. 
     129.TP 
    124130.B disconnect \fIscript 
    125131Execute the command specified by \fIscript\fR, by passing it to a 
    126132shell, after