Root/package/network/services/ppp/patches/321-multilink_support_custom_iface_names.patch

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

Archive Download this file



interactive