aboutsummaryrefslogtreecommitdiffstats
path: root/package/network/services/ppp/patches/321-multilink_support_custom_iface_names.patch
blob: bba5884fa4683ee5cf85e198e8b7194165ab2460 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
From: George Kashperko <george@znau.edu.ua>

Make mlppp support more generic interface naming other than pppX
Signed-off-by: George Kashperko <george@znau.edu.ua>
---
 pppd/multilink.c |   55 +++++++++++++++++++++++++++++++++------------
 pppd/sys-linux.c |   12 +++++++++
 2 files changed, 53 insertions(+), 14 deletions(-)
--- a/pppd/multilink.c
+++ b/pppd/multilink.c
@@ -56,7 +56,8 @@ static void iterate_bundle_links __P((vo
 
 static int get_default_epdisc __P((struct epdisc *));
 static int parse_num __P((char *str, const char *key, int *valp));
-static int owns_unit __P((TDB_DATA pid, int unit));
+static int parse_str __P((char *str, const char *key, char *buf, int buflen));
+static int owns_link __P((TDB_DATA pid, char *ifname));
 
 #define set_ip_epdisc(ep, addr) do {	\
 	ep->length = 4;			\
@@ -197,35 +198,38 @@ mp_join_bundle()
 	key.dptr = bundle_id;
 	key.dsize = p - bundle_id;
 	pid = tdb_fetch(pppdb, key);
+
 	if (pid.dptr != NULL) {
+		char tmp[IFNAMSIZ];
+
 		/* bundle ID exists, see if the pppd record exists */
 		rec = tdb_fetch(pppdb, pid);
+
 		if (rec.dptr != NULL && rec.dsize > 0) {
 			/* make sure the string is null-terminated */
 			rec.dptr[rec.dsize-1] = 0;
-			/* parse the interface number */
-			parse_num(rec.dptr, "IFNAME=ppp", &unit);
+
 			/* check the pid value */
 			if (!parse_num(rec.dptr, "PPPD_PID=", &pppd_pid)
+			    || !parse_str(rec.dptr, "IFNAME=", tmp, sizeof(tmp))
+			    || !parse_num(rec.dptr, "IFUNIT=", &unit)
 			    || !process_exists(pppd_pid)
-			    || !owns_unit(pid, unit))
+			    || !owns_link(pid, tmp))
 				unit = -1;
 			free(rec.dptr);
 		}
 		free(pid.dptr);
-	}
 
-	if (unit >= 0) {
 		/* attach to existing unit */
-		if (bundle_attach(unit)) {
+		if (unit >= 0 && bundle_attach(unit)) {
 			set_ifunit(0);
 			script_setenv("BUNDLE", bundle_id + 7, 0);
 			make_bundle_links(1);
 			unlock_db();
-			info("Link attached to %s", ifname);
+			info("Link attached to %s", tmp);
 			return 1;
+			/* attach failed because bundle doesn't exist */
 		}
-		/* attach failed because bundle doesn't exist */
 	}
 
 	/* we have to make a new bundle */
@@ -408,22 +412,45 @@ parse_num(str, key, valp)
 	return 0;
 }
 
+static int
+parse_str(str, key, buf, buflen)
+     char *str;
+     const char *key;
+     char *buf;
+     int buflen;
+{
+	char *p, *endp;
+	int i;
+
+	p = strstr(str, key);
+	if (p) {
+		p += strlen(key);
+		while (--buflen && *p != 0 && *p != ';')
+			*(buf++) = *(p++);
+		*buf = 0;
+		return 1;
+	}
+	return 0;
+}
+
 /*
- * Check whether the pppd identified by `key' still owns ppp unit `unit'.
+ * Check whether the pppd identified by `key' still owns ppp link `ifname'.
  */
 static int
-owns_unit(key, unit)
+owns_link(key, ifname)
      TDB_DATA key;
-     int unit;
+     char *ifname;
 {
-	char ifkey[32];
+	char ifkey[7 + IFNAMSIZ];
 	TDB_DATA kd, vd;
 	int ret = 0;
 
-	slprintf(ifkey, sizeof(ifkey), "IFNAME=ppp%d", unit);
+	slprintf(ifkey, sizeof(ifkey), "IFNAME=%s", ifname);
+
 	kd.dptr = ifkey;
 	kd.dsize = strlen(ifkey);
 	vd = tdb_fetch(pppdb, kd);
+
 	if (vd.dptr != NULL) {
 		ret = vd.dsize == key.dsize
 			&& memcmp(vd.dptr, key.dptr, vd.dsize) == 0;
--- a/pppd/sys-linux.c
+++ b/pppd/sys-linux.c
@@ -698,6 +698,16 @@ void cfg_bundle(int mrru, int mtru, int
 	add_fd(ppp_dev_fd);
 }
 
+static void
+setenv_ifunit(void)
+{
+#ifdef USE_TDB
+	char tmp[11];
+	slprintf(tmp, sizeof(tmp), "%d", ifunit);
+	script_setenv("IFUNIT", tmp, 0);
+#endif
+}
+
 /*
  * make_new_bundle - create a new PPP unit (i.e. a bundle)
  * and connect our channel to it.  This should only get called
@@ -716,6 +726,8 @@ void make_new_bundle(int mrru, int mtru,
 
 	/* set the mrru and flags */
 	cfg_bundle(mrru, mtru, rssn, tssn);
+
+	setenv_ifunit();
 }
 
 /*