18_all_defaultmetric.patch 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. diff -Nru ppp-2.4.5.orig/pppd/options.c ppp-2.4.5/pppd/options.c
  2. --- ppp-2.4.5.orig/pppd/options.c 2010-08-08 09:44:29.000000000 +0200
  3. +++ ppp-2.4.5/pppd/options.c 2010-08-08 10:07:50.000000000 +0200
  4. @@ -94,6 +94,7 @@
  5. int kdebugflag = 0; /* Tell kernel to print debug messages */
  6. int default_device = 1; /* Using /dev/tty or equivalent */
  7. char devnam[MAXPATHLEN]; /* Device name */
  8. +int defaultmetric = 0; /* Metric of the default route */
  9. bool nodetach = 0; /* Don't detach from controlling tty */
  10. bool updetach = 0; /* Detach once link is up */
  11. int maxconnect = 0; /* Maximum connect time */
  12. @@ -289,6 +290,10 @@
  13. "Number of seconds to wait for child processes at exit",
  14. OPT_PRIO },
  15. + { "defaultmetric", o_int, &defaultmetric,
  16. + "The metric of the default route",
  17. + OPT_LIMITS, 0, 32766 },
  18. +
  19. #ifdef HAVE_MULTILINK
  20. { "multilink", o_bool, &multilink,
  21. "Enable multilink operation", OPT_PRIO | 1 },
  22. diff -Nru ppp-2.4.5.orig/pppd/pppd.8 ppp-2.4.5/pppd/pppd.8
  23. --- ppp-2.4.5.orig/pppd/pppd.8 2010-08-08 10:06:57.000000000 +0200
  24. +++ ppp-2.4.5/pppd/pppd.8 2010-08-08 10:07:50.000000000 +0200
  25. @@ -121,6 +121,9 @@
  26. This entry is removed when the PPP connection is broken. This option
  27. is privileged if the \fInodefaultroute\fR option has been specified.
  28. .TP
  29. +.B defaultmetric \fIn
  30. +The metric of the default route configured by pppd; default is 0.
  31. +.TP
  32. .B disconnect \fIscript
  33. Execute the command specified by \fIscript\fR, by passing it to a
  34. shell, after
  35. diff -Nru ppp-2.4.5.orig/pppd/pppd.h ppp-2.4.5/pppd/pppd.h
  36. --- ppp-2.4.5.orig/pppd/pppd.h 2010-08-08 09:58:19.000000000 +0200
  37. +++ ppp-2.4.5/pppd/pppd.h 2010-08-08 10:07:50.000000000 +0200
  38. @@ -276,6 +276,7 @@
  39. extern int kdebugflag; /* Tell kernel to print debug messages */
  40. extern int default_device; /* Using /dev/tty or equivalent */
  41. extern char devnam[MAXPATHLEN]; /* Device name */
  42. +extern int defaultmetric; /* Metric of the default route */
  43. extern int crtscts; /* Use hardware flow control */
  44. extern bool modem; /* Use modem control lines */
  45. extern int inspeed; /* Input/Output speed requested */
  46. diff -Nru ppp-2.4.5.orig/pppd/sys-linux.c ppp-2.4.5/pppd/sys-linux.c
  47. --- ppp-2.4.5.orig/pppd/sys-linux.c 2010-08-08 09:53:56.000000000 +0200
  48. +++ ppp-2.4.5/pppd/sys-linux.c 2010-08-08 10:07:50.000000000 +0200
  49. @@ -1465,7 +1465,7 @@
  50. FILE *route_fd = (FILE *) 0;
  51. static char route_buffer[512];
  52. static int route_dev_col, route_dest_col, route_gw_col;
  53. -static int route_flags_col, route_mask_col;
  54. +static int route_flags_col, route_mask_col, route_metric_col;
  55. static int route_num_cols;
  56. static int open_route_table (void);
  57. @@ -1508,6 +1508,7 @@
  58. route_dest_col = 1;
  59. route_gw_col = 2;
  60. route_flags_col = 3;
  61. + route_metric_col = 6;
  62. route_mask_col = 7;
  63. route_num_cols = 8;
  64. @@ -1527,6 +1528,8 @@
  65. route_gw_col = col;
  66. else if (strcasecmp(q, "flags") == 0)
  67. route_flags_col = col;
  68. + else if (strcasecmp(q, "metric") == 0)
  69. + route_metric_col = col;
  70. else if (strcasecmp(q, "mask") == 0)
  71. route_mask_col = col;
  72. else
  73. @@ -1569,6 +1572,7 @@
  74. rt->rt_flags = (short) strtoul(cols[route_flags_col], NULL, 16);
  75. rt->rt_dev = cols[route_dev_col];
  76. + rt->rt_metric = (short) strtoul(cols[route_metric_col], NULL, 16);
  77. return 1;
  78. }
  79. @@ -1591,6 +1595,8 @@
  80. if (kernel_version > KVERSION(2,1,0) && SIN_ADDR(rt->rt_genmask) != 0)
  81. continue;
  82. + if (rt->rt_metric != defaultmetric) /* consider only routes with the same metric */
  83. + continue;
  84. if (SIN_ADDR(rt->rt_dst) == 0L) {
  85. result = 1;
  86. break;
  87. @@ -1661,6 +1667,7 @@
  88. SIN_ADDR(rt.rt_gateway) = gateway;
  89. rt.rt_flags = RTF_UP | RTF_GATEWAY;
  90. + rt.rt_metric = defaultmetric + 1; /* +1 for binary compatibility */
  91. if (ioctl(sock_fd, SIOCADDRT, &rt) < 0) {
  92. if ( ! ok_error ( errno ))
  93. error("default route ioctl(SIOCADDRT): %m");
  94. @@ -1696,6 +1703,7 @@
  95. SIN_ADDR(rt.rt_gateway) = gateway;
  96. rt.rt_flags = RTF_UP | RTF_GATEWAY;
  97. + rt.rt_metric = defaultmetric + 1; /* +1 for binary compatibility */
  98. if (ioctl(sock_fd, SIOCDELRT, &rt) < 0 && errno != ESRCH) {
  99. if (still_ppp()) {
  100. if ( ! ok_error ( errno ))