ppp: update to version 2.4.7.git-2019-10-04
[openwrt/openwrt.git] / package / network / services / ppp / patches / 321-multilink_support_custom_iface_names.patch
1 From: George Kashperko <george@znau.edu.ua>
2
3 Make mlppp support more generic interface naming other than pppX
4 Signed-off-by: George Kashperko <george@znau.edu.ua>
5 ---
6 pppd/multilink.c | 55 +++++++++++++++++++++++++++++++++------------
7 pppd/sys-linux.c | 12 +++++++++
8 2 files changed, 53 insertions(+), 14 deletions(-)
9 --- a/pppd/multilink.c
10 +++ b/pppd/multilink.c
11 @@ -35,6 +35,7 @@
12 #include <signal.h>
13 #include <netinet/in.h>
14 #include <unistd.h>
15 +#include <net/if.h>
16
17 #include "pppd.h"
18 #include "fsm.h"
19 @@ -56,7 +57,8 @@ static void iterate_bundle_links __P((vo
20
21 static int get_default_epdisc __P((struct epdisc *));
22 static int parse_num __P((char *str, const char *key, int *valp));
23 -static int owns_unit __P((TDB_DATA pid, int unit));
24 +static int parse_str __P((char *str, const char *key, char *buf, int buflen));
25 +static int owns_link __P((TDB_DATA pid, char *ifname));
26
27 #define set_ip_epdisc(ep, addr) do { \
28 ep->length = 4; \
29 @@ -197,35 +199,38 @@ mp_join_bundle()
30 key.dptr = bundle_id;
31 key.dsize = p - bundle_id;
32 pid = tdb_fetch(pppdb, key);
33 +
34 if (pid.dptr != NULL) {
35 + char tmp[IFNAMSIZ];
36 +
37 /* bundle ID exists, see if the pppd record exists */
38 rec = tdb_fetch(pppdb, pid);
39 +
40 if (rec.dptr != NULL && rec.dsize > 0) {
41 /* make sure the string is null-terminated */
42 rec.dptr[rec.dsize-1] = 0;
43 - /* parse the interface number */
44 - parse_num(rec.dptr, "IFNAME=ppp", &unit);
45 +
46 /* check the pid value */
47 if (!parse_num(rec.dptr, "PPPD_PID=", &pppd_pid)
48 + || !parse_str(rec.dptr, "IFNAME=", tmp, sizeof(tmp))
49 + || !parse_num(rec.dptr, "IFUNIT=", &unit)
50 || !process_exists(pppd_pid)
51 - || !owns_unit(pid, unit))
52 + || !owns_link(pid, tmp))
53 unit = -1;
54 free(rec.dptr);
55 }
56 free(pid.dptr);
57 - }
58
59 - if (unit >= 0) {
60 /* attach to existing unit */
61 - if (bundle_attach(unit)) {
62 + if (unit >= 0 && bundle_attach(unit)) {
63 set_ifunit(0);
64 script_setenv("BUNDLE", bundle_id + 7, 0);
65 make_bundle_links(1);
66 unlock_db();
67 - info("Link attached to %s", ifname);
68 + info("Link attached to %s", tmp);
69 return 1;
70 + /* attach failed because bundle doesn't exist */
71 }
72 - /* attach failed because bundle doesn't exist */
73 }
74
75 /* we have to make a new bundle */
76 @@ -408,22 +413,45 @@ parse_num(str, key, valp)
77 return 0;
78 }
79
80 +static int
81 +parse_str(str, key, buf, buflen)
82 + char *str;
83 + const char *key;
84 + char *buf;
85 + int buflen;
86 +{
87 + char *p, *endp;
88 + int i;
89 +
90 + p = strstr(str, key);
91 + if (p) {
92 + p += strlen(key);
93 + while (--buflen && *p != 0 && *p != ';')
94 + *(buf++) = *(p++);
95 + *buf = 0;
96 + return 1;
97 + }
98 + return 0;
99 +}
100 +
101 /*
102 - * Check whether the pppd identified by `key' still owns ppp unit `unit'.
103 + * Check whether the pppd identified by `key' still owns ppp link `ifname'.
104 */
105 static int
106 -owns_unit(key, unit)
107 +owns_link(key, ifname)
108 TDB_DATA key;
109 - int unit;
110 + char *ifname;
111 {
112 - char ifkey[32];
113 + char ifkey[7 + IFNAMSIZ];
114 TDB_DATA kd, vd;
115 int ret = 0;
116
117 - slprintf(ifkey, sizeof(ifkey), "IFNAME=ppp%d", unit);
118 + slprintf(ifkey, sizeof(ifkey), "IFNAME=%s", ifname);
119 +
120 kd.dptr = ifkey;
121 kd.dsize = strlen(ifkey);
122 vd = tdb_fetch(pppdb, kd);
123 +
124 if (vd.dptr != NULL) {
125 ret = vd.dsize == key.dsize
126 && memcmp(vd.dptr, key.dptr, vd.dsize) == 0;
127 --- a/pppd/sys-linux.c
128 +++ b/pppd/sys-linux.c
129 @@ -693,6 +693,16 @@ void cfg_bundle(int mrru, int mtru, int
130 add_fd(ppp_dev_fd);
131 }
132
133 +static void
134 +setenv_ifunit(void)
135 +{
136 +#ifdef USE_TDB
137 + char tmp[11];
138 + slprintf(tmp, sizeof(tmp), "%d", ifunit);
139 + script_setenv("IFUNIT", tmp, 0);
140 +#endif
141 +}
142 +
143 /*
144 * make_new_bundle - create a new PPP unit (i.e. a bundle)
145 * and connect our channel to it. This should only get called
146 @@ -711,6 +721,8 @@ void make_new_bundle(int mrru, int mtru,
147
148 /* set the mrru and flags */
149 cfg_bundle(mrru, mtru, rssn, tssn);
150 +
151 + setenv_ifunit();
152 }
153
154 /*