1
0

320-custom_iface_names.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. pppd: Support arbitrary interface names
  2. This patch implements a new string option "ifname" which allows to specify
  3. fully custom PPP interface names on Linux. It does so by renaming the
  4. allocated pppX device immediately after it has been created to the requested
  5. interface name.
  6. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
  7. --- a/pppd/main.c
  8. +++ b/pppd/main.c
  9. @@ -745,8 +745,11 @@ void
  10. set_ifunit(iskey)
  11. int iskey;
  12. {
  13. - info("Using interface %s%d", PPP_DRV_NAME, ifunit);
  14. - slprintf(ifname, sizeof(ifname), "%s%d", PPP_DRV_NAME, ifunit);
  15. + if (use_ifname[0] == 0)
  16. + slprintf(ifname, sizeof(ifname), "%s%d", PPP_DRV_NAME, ifunit);
  17. + else
  18. + slprintf(ifname, sizeof(ifname), "%s", use_ifname);
  19. + info("Using interface %s", ifname);
  20. script_setenv("IFNAME", ifname, iskey);
  21. if (iskey) {
  22. create_pidfile(getpid()); /* write pid to file */
  23. --- a/pppd/options.c
  24. +++ b/pppd/options.c
  25. @@ -112,6 +112,7 @@ int log_to_fd = 1; /* send log messages
  26. bool log_default = 1; /* log_to_fd is default (stdout) */
  27. int maxfail = 10; /* max # of unsuccessful connection attempts */
  28. char linkname[MAXPATHLEN]; /* logical name for link */
  29. +char use_ifname[IFNAMSIZ]; /* physical name for PPP link */
  30. bool tune_kernel; /* may alter kernel settings */
  31. int connect_delay = 1000; /* wait this many ms after connect script */
  32. int req_unit = -1; /* requested interface unit */
  33. @@ -277,6 +278,9 @@ option_t general_options[] = {
  34. { "linkname", o_string, linkname,
  35. "Set logical name for link",
  36. OPT_PRIO | OPT_PRIV | OPT_STATIC, NULL, MAXPATHLEN },
  37. + { "ifname", o_string, use_ifname,
  38. + "Set physical name for PPP interface",
  39. + OPT_PRIO | OPT_PRIV | OPT_STATIC, NULL, IFNAMSIZ },
  40. { "maxfail", o_int, &maxfail,
  41. "Maximum number of unsuccessful connection attempts to allow",
  42. --- a/pppd/pppd.h
  43. +++ b/pppd/pppd.h
  44. @@ -74,6 +74,10 @@
  45. #include "eui64.h"
  46. #endif
  47. +#ifndef IFNAMSIZ
  48. +#define IFNAMSIZ 16
  49. +#endif
  50. +
  51. /*
  52. * Limits.
  53. */
  54. @@ -317,6 +321,7 @@ extern char *record_file; /* File to rec
  55. extern bool sync_serial; /* Device is synchronous serial device */
  56. extern int maxfail; /* Max # of unsuccessful connection attempts */
  57. extern char linkname[MAXPATHLEN]; /* logical name for link */
  58. +extern char use_ifname[IFNAMSIZ]; /* physical name for PPP interface */
  59. extern bool tune_kernel; /* May alter kernel settings as necessary */
  60. extern int connect_delay; /* Time to delay after connect script */
  61. extern int max_data_rate; /* max bytes/sec through charshunt */
  62. --- a/pppd/sys-linux.c
  63. +++ b/pppd/sys-linux.c
  64. @@ -161,6 +161,10 @@ struct in6_ifreq {
  65. /* We can get an EIO error on an ioctl if the modem has hung up */
  66. #define ok_error(num) ((num)==EIO)
  67. +#if !defined(PPP_DRV_NAME)
  68. +#define PPP_DRV_NAME "ppp"
  69. +#endif /* !defined(PPP_DRV_NAME) */
  70. +
  71. static int tty_disc = N_TTY; /* The TTY discipline */
  72. static int ppp_disc = N_PPP; /* The PPP discpline */
  73. static int initfdflags = -1; /* Initial file descriptor flags for fd */
  74. @@ -620,7 +624,8 @@ void generic_disestablish_ppp(int dev_fd
  75. */
  76. static int make_ppp_unit()
  77. {
  78. - int x, flags;
  79. + struct ifreq ifr;
  80. + int x, flags, s;
  81. if (ppp_dev_fd >= 0) {
  82. dbglog("in make_ppp_unit, already had /dev/ppp open?");
  83. @@ -643,6 +648,30 @@ static int make_ppp_unit()
  84. }
  85. if (x < 0)
  86. error("Couldn't create new ppp unit: %m");
  87. +
  88. + if (use_ifname[0] != 0) {
  89. + s = socket(PF_INET, SOCK_DGRAM, 0);
  90. + if (s < 0)
  91. + s = socket(PF_PACKET, SOCK_DGRAM, 0);
  92. + if (s < 0)
  93. + s = socket(PF_INET6, SOCK_DGRAM, 0);
  94. + if (s < 0)
  95. + s = socket(PF_UNIX, SOCK_DGRAM, 0);
  96. + if (s >= 0) {
  97. + slprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s%d", PPP_DRV_NAME, ifunit);
  98. + slprintf(ifr.ifr_newname, sizeof(ifr.ifr_newname), "%s", use_ifname);
  99. + x = ioctl(s, SIOCSIFNAME, &ifr);
  100. + close(s);
  101. + } else {
  102. + x = s;
  103. + }
  104. + if (x < 0) {
  105. + error("Couldn't rename %s to %s", ifr.ifr_name, ifr.ifr_newname);
  106. + close(ppp_dev_fd);
  107. + ppp_dev_fd = -1;
  108. + }
  109. + }
  110. +
  111. return x;
  112. }
  113. --- a/pppstats/pppstats.c
  114. +++ b/pppstats/pppstats.c
  115. @@ -506,10 +506,12 @@ main(argc, argv)
  116. if (argc > 0)
  117. interface = argv[0];
  118. +#if 0
  119. if (sscanf(interface, PPP_DRV_NAME "%d", &unit) != 1) {
  120. fprintf(stderr, "%s: invalid interface '%s' specified\n",
  121. progname, interface);
  122. }
  123. +#endif
  124. #ifndef STREAMS
  125. {