diff -urN ppp-2.4.4.orig/pppd/auth.c ppp-2.4.4/pppd/auth.c --- ppp-2.4.4.orig/pppd/auth.c Tue Jan 1 14:44:37 2008 +++ ppp-2.4.4/pppd/auth.c Tue Jan 1 14:45:12 2008 @@ -647,8 +647,10 @@ } if (!hungup) lcp_lowerdown(0); - if (!doing_multilink && !demand) + if (!doing_multilink && !demand) { script_unsetenv("IFNAME"); + script_unsetenv("IFUNIT"); + } /* * Run disconnector script, if requested. diff -urN ppp-2.4.4.orig/pppd/main.c ppp-2.4.4/pppd/main.c --- ppp-2.4.4.orig/pppd/main.c Tue Jan 1 14:44:37 2008 +++ ppp-2.4.4/pppd/main.c Tue Jan 1 14:45:12 2008 @@ -739,9 +739,14 @@ set_ifunit(iskey) int iskey; { - info("Using interface %s%d", PPP_DRV_NAME, ifunit); slprintf(ifname, sizeof(ifname), "%s%d", PPP_DRV_NAME, ifunit); - script_setenv("IFNAME", ifname, iskey); + info("Using interface %s", ifname); + script_setenv("IFUNIT", ifname, iskey); + if (req_ifname[0] && sys_change_ifname(ifname, req_ifname)) { + slprintf(ifname, sizeof(ifname), "%s", req_ifname); + info("Changing interface to %s", ifname); + } + script_setenv("IFNAME", ifname, 0); if (iskey) { create_pidfile(getpid()); /* write pid to file */ create_linkpidfile(getpid()); diff -urN ppp-2.4.4.orig/pppd/multilink.c ppp-2.4.4/pppd/multilink.c --- ppp-2.4.4.orig/pppd/multilink.c Tue Jan 1 14:44:37 2008 +++ ppp-2.4.4/pppd/multilink.c Tue Jan 1 14:45:12 2008 @@ -204,7 +204,7 @@ /* make sure the string is null-terminated */ rec.dptr[rec.dsize-1] = 0; /* parse the interface number */ - parse_num(rec.dptr, "IFNAME=ppp", &unit); + parse_num(rec.dptr, "IFUNIT=ppp", &unit); /* check the pid value */ if (!parse_num(rec.dptr, "PPPD_PID=", &pppd_pid) || !process_exists(pppd_pid) @@ -417,7 +417,7 @@ TDB_DATA kd, vd; int ret = 0; - slprintf(ifkey, sizeof(ifkey), "IFNAME=ppp%d", unit); + slprintf(ifkey, sizeof(ifkey), "IFUNIT=ppp%d", unit); kd.dptr = ifkey; kd.dsize = strlen(ifkey); vd = tdb_fetch(pppdb, kd); diff -urN ppp-2.4.4.orig/pppd/options.c ppp-2.4.4/pppd/options.c --- ppp-2.4.4.orig/pppd/options.c Tue Jan 1 14:44:37 2008 +++ ppp-2.4.4/pppd/options.c Tue Jan 1 14:46:03 2008 @@ -113,6 +113,7 @@ bool tune_kernel; /* may alter kernel settings */ int connect_delay = 1000; /* wait this many ms after connect script */ int req_unit = -1; /* requested interface unit */ +char req_ifname[16]; /* requested interface name */ char path_ipup[MAXPATHLEN]; /* pathname of ip-up script */ char path_ipdown[MAXPATHLEN];/* pathname of ip-down script */ bool multilink = 0; /* Enable multilink operation */ @@ -273,6 +274,10 @@ { "unit", o_int, &req_unit, "PPP interface unit number to use if possible", OPT_PRIO | OPT_LLIMIT, 0, 0 }, + + { "ifname", o_string, req_ifname, + "PPP interface name to use if possible", + OPT_PRIO | OPT_PRIV | OPT_STATIC, NULL, sizeof(req_ifname) }, { "dump", o_bool, &dump_options, "Print out option values after parsing all options", 1 }, diff -urN ppp-2.4.4.orig/pppd/pppd.h ppp-2.4.4/pppd/pppd.h --- ppp-2.4.4.orig/pppd/pppd.h Tue Jan 1 14:44:37 2008 +++ ppp-2.4.4/pppd/pppd.h Tue Jan 1 14:46:39 2008 @@ -312,6 +312,7 @@ extern int connect_delay; /* Time to delay after connect script */ extern int max_data_rate; /* max bytes/sec through charshunt */ extern int req_unit; /* interface unit number to use */ +extern char req_ifname[16]; /* interface name to use */ extern char path_ipup[MAXPATHLEN]; /* pathname of ip-up script */ extern char path_ipdown[MAXPATHLEN]; /* pathname of ip-down script */ extern bool multilink; /* enable multilink operation */ @@ -670,6 +671,7 @@ #endif int get_if_hwaddr __P((u_char *addr, char *name)); char *get_first_ethernet __P((void)); +int sys_change_ifname __P((const char *, const char *)); /* Procedures exported from options.c */ int setipaddr __P((char *, char **, int)); /* Set local/remote ip addresses */ diff -urN ppp-2.4.4.orig/pppd/sys-linux.c ppp-2.4.4/pppd/sys-linux.c --- ppp-2.4.4.orig/pppd/sys-linux.c Tue Jan 1 14:44:37 2008 +++ ppp-2.4.4/pppd/sys-linux.c Tue Jan 1 14:45:12 2008 @@ -2931,4 +2931,29 @@ return 1; } #endif + +int +sys_change_ifname(const char *old, const char *new) +{ + struct ifreq ifr; + + SYSDEBUG ((LOG_DEBUG, "sys_change_ifname: %s -> %s\n", old, new)); + + memset (&ifr, '\0', sizeof (ifr)); + strlcpy(ifr.ifr_name, old, sizeof (ifr.ifr_name)); + strlcpy(ifr.ifr_newname, new, sizeof (ifr.ifr_newname)); + +#ifndef SIOCSIFNAME +#define SIOCSIFNAME 0x8923 +#endif + if (ioctl(sock_fd, SIOCSIFNAME, (caddr_t) &ifr) < 0) { + if (errno == EEXIST) + warn("Couldn't change name to %s as it is already in use", new); + else + error("Couldn't change name from %s to %s: %m", old, new); + return 0; + } + return 1; +} +