Root/package/network/services/ppp/patches/320-custom_iface_names.patch

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

Archive Download this file



interactive