mbedtls: fix build on GCC 14
[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(void (*
20
21 static int get_default_epdisc(struct epdisc *);
22 static int parse_num(char *str, const char *key, int *valp);
23 -static int owns_unit(TDB_DATA pid, int unit);
24 +static int parse_str(char *str, const char *key, char *buf, int buflen);
25 +static int owns_link(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(void)
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, "UNIT=", &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 @@ -405,20 +410,39 @@ parse_num(char *str, const char *key, in
77 return 0;
78 }
79
80 +static int
81 +parse_str(char *str, const char *key, char *buf, int buflen)
82 +{
83 + char *p, *endp;
84 + int i;
85 +
86 + p = strstr(str, key);
87 + if (p) {
88 + p += strlen(key);
89 + while (--buflen && *p != 0 && *p != ';')
90 + *(buf++) = *(p++);
91 + *buf = 0;
92 + return 1;
93 + }
94 + return 0;
95 +}
96 +
97 /*
98 - * Check whether the pppd identified by `key' still owns ppp unit `unit'.
99 + * Check whether the pppd identified by `key' still owns ppp link `ifname'.
100 */
101 static int
102 -owns_unit(TDB_DATA key, int unit)
103 +owns_link(TDB_DATA key, char *ifname)
104 {
105 - char ifkey[32];
106 + char ifkey[7 + IFNAMSIZ];
107 TDB_DATA kd, vd;
108 int ret = 0;
109
110 - slprintf(ifkey, sizeof(ifkey), "UNIT=%d", unit);
111 + slprintf(ifkey, sizeof(ifkey), "IFNAME=%s", ifname);
112 +
113 kd.dptr = ifkey;
114 kd.dsize = strlen(ifkey);
115 vd = tdb_fetch(pppdb, kd);
116 +
117 if (vd.dptr != NULL) {
118 ret = vd.dsize == key.dsize
119 && memcmp(vd.dptr, key.dptr, vd.dsize) == 0;
120 --- a/pppd/sys-linux.c
121 +++ b/pppd/sys-linux.c
122 @@ -923,6 +923,16 @@ void cfg_bundle(int mrru, int mtru, int
123 add_fd(ppp_dev_fd);
124 }
125
126 +static void
127 +setenv_ifunit(void)
128 +{
129 +#ifdef USE_TDB
130 + char tmp[11];
131 + slprintf(tmp, sizeof(tmp), "%d", ifunit);
132 + script_setenv("IFUNIT", tmp, 0);
133 +#endif
134 +}
135 +
136 /*
137 * make_new_bundle - create a new PPP unit (i.e. a bundle)
138 * and connect our channel to it. This should only get called
139 @@ -941,6 +951,8 @@ void make_new_bundle(int mrru, int mtru,
140
141 /* set the mrru and flags */
142 cfg_bundle(mrru, mtru, rssn, tssn);
143 +
144 + setenv_ifunit();
145 }
146
147 /*