ath79: update WA/XC devices UBNT_VERSION to 8.7.4
[openwrt/staging/wigyori.git] / package / network / services / ppp / patches / 143-pppd-Workaround-for-generating-ppp-unit-id-on-Linux-.patch
1 From 44609bfc974bdafc0316d069aabf5e2903efa805 Mon Sep 17 00:00:00 2001
2 From: pali <7141871+pali@users.noreply.github.com>
3 Date: Tue, 9 Aug 2022 11:20:15 +0200
4 Subject: [PATCH] pppd: Workaround for generating ppp unit id on Linux (#355)
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Linux kernel has nasty bug / feature. If PPPIOCNEWUNIT is called with
10 negative ppp unit id (which is default option when command line argument
11 "unit" is not specified; and tells kernel to choose some free ppp unit id)
12 and the lowest unused/free ppp unit id is present in some existing network
13 interface name prefixed by "ppp" string then this PPPIOCNEWUNIT ioctl
14 fails. In this case kernel is basically unable to create a new ppp
15 interface via PPPIOCNEWUNIT ioctl when user does not specify some unused
16 and non-conflicted unit id.
17
18 Linux kernel should be fixed to choose usable ppp unit id when was
19 requested via PPPIOCNEWUNIT parameter -1.
20
21 Until this happens, add a workaround for pppd to help choosing some random
22 ppp unit id when kernel returns this error.
23
24 Simple test case (run on system when there is no ppp interface):
25
26 sudo ./pppd ifname ppp1 nodefaultroute noauth nolock local nodetach pty "./pppd nodefaultroute noauth nolock local nodetach notty"
27
28 Second pppd process without this patch prints into syslog following error:
29
30 pppd 2.4.10-dev started by pali, uid 0
31 Couldn't create new ppp unit: File exists
32 Exit.
33
34 With this patch it falls back to random ppp unit id and succeeds:
35
36 pppd 2.4.10-dev started by pali, uid 0
37 Using interface ppp1361
38 Connect: ppp1361 <--> /dev/pts/14
39 ...
40
41 Signed-off-by: Pali Rohár <pali@kernel.org>
42 ---
43 pppd/sys-linux.c | 5 +++++
44 1 file changed, 5 insertions(+)
45
46 --- a/pppd/sys-linux.c
47 +++ b/pppd/sys-linux.c
48 @@ -873,6 +873,11 @@ static int make_ppp_unit(void)
49 ifunit = -1;
50 x = ioctl(ppp_dev_fd, PPPIOCNEWUNIT, &ifunit);
51 }
52 + if (x < 0 && errno == EEXIST) {
53 + srand(time(NULL) * getpid());
54 + ifunit = rand() % 10000;
55 + x = ioctl(ppp_dev_fd, PPPIOCNEWUNIT, &ifunit);
56 + }
57 if (x < 0)
58 error("Couldn't create new ppp unit: %m");
59