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