ppp/pppoe-discovery: fix -W option
[openwrt/openwrt.git] / package / network / services / ppp / patches / 520-fix_-W_option_for_pppoe-discovery_utility.patch
1 From 22d9c14ae3930fe10f26bafc3eab45e3a17eb3fa Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali@kernel.org>
3 Date: Sun, 19 Jul 2020 11:55:43 +0200
4 Subject: [PATCH] Fix -W option for pppoe-discovery utility
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 pppoe-discovery's -W option is totally broken. pppoe-discovery currently
10 expects that Host-Unique attribute equals to its own process pid if set.
11
12 This patch fixes parsing received PPPoE PADO packets when -W option is set.
13 Same implementation is in pppd pppoe plugin.
14
15 Signed-off-by: Pali Rohár <pali@kernel.org>
16 ---
17 pppd/plugins/rp-pppoe/pppoe-discovery.c | 18 +++++++-----------
18 1 file changed, 7 insertions(+), 11 deletions(-)
19
20 --- a/pppd/plugins/rp-pppoe/pppoe-discovery.c
21 +++ b/pppd/plugins/rp-pppoe/pppoe-discovery.c
22 @@ -327,14 +327,10 @@ void
23 parseForHostUniq(UINT16_t type, UINT16_t len, unsigned char *data,
24 void *extra)
25 {
26 - int *val = (int *) extra;
27 - if (type == TAG_HOST_UNIQ && len == sizeof(pid_t)) {
28 - pid_t tmp;
29 - memcpy(&tmp, data, len);
30 - if (tmp == getpid()) {
31 - *val = 1;
32 - }
33 - }
34 + PPPoETag *tag = extra;
35 +
36 + if (type == TAG_HOST_UNIQ && len == ntohs(tag->length))
37 + tag->length = memcmp(data, tag->payload, len);
38 }
39
40 /**********************************************************************
41 @@ -351,7 +347,7 @@ parseForHostUniq(UINT16_t type, UINT16_t
42 int
43 packetIsForMe(PPPoEConnection *conn, PPPoEPacket *packet)
44 {
45 - int forMe = 0;
46 + PPPoETag hostUniq = conn->hostUniq;
47
48 /* If packet is not directed to our MAC address, forget it */
49 if (memcmp(packet->ethHdr.h_dest, conn->myEth, ETH_ALEN)) return 0;
50 @@ -359,8 +355,8 @@ packetIsForMe(PPPoEConnection *conn, PPP
51 /* If we're not using the Host-Unique tag, then accept the packet */
52 if (!conn->hostUniq.length) return 1;
53
54 - parsePacket(packet, parseForHostUniq, &forMe);
55 - return forMe;
56 + parsePacket(packet, parseForHostUniq, &hostUniq);
57 + return !hostUniq.length;
58 }
59
60 /**********************************************************************