1 From 5f373f373f5baccc282dce257b7b16c8bb4a82c4 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Eivind=20N=C3=A6ss?= <eivnaes@yahoo.com>
3 Date: Sat, 25 Mar 2023 20:51:52 +0000
4 Subject: [PATCH] vpn: Adding support for latest pppd 2.5.0 release
6 The API has gone through a significant overhaul, and this change fixes any compile issues.
7 1) Fixes to configure.ac itself
8 2) Cleanup in pppd plugin itself
10 Adding a libppp-compat.h file to mask for any differences in the version.
12 Upstream-Status: Backport [https://git.kernel.org/pub/scm/network/connman/connman.git/commit/?id=a48864a2e5d2a725dfc6eef567108bc13b43857f]
13 Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
15 configure.ac | 42 ++++++++-----
16 scripts/libppp-compat.h | 127 ++++++++++++++++++++++++++++++++++++++++
17 scripts/libppp-plugin.c | 15 +++--
18 3 files changed, 161 insertions(+), 23 deletions(-)
19 create mode 100644 scripts/libppp-compat.h
21 diff --git a/configure.ac b/configure.ac
22 index a573cef..f34bb38 100644
25 @@ -135,14 +135,6 @@ AC_ARG_ENABLE(l2tp,
26 AC_HELP_STRING([--enable-l2tp], [enable l2tp support]),
27 [enable_l2tp=${enableval}], [enable_l2tp="no"])
28 if (test "${enable_l2tp}" != "no"); then
29 - if (test -z "${path_pppd}"); then
30 - AC_PATH_PROG(PPPD, [pppd], [/usr/sbin/pppd], $PATH:/sbin:/usr/sbin)
35 - AC_CHECK_HEADERS(pppd/pppd.h, dummy=yes,
36 - AC_MSG_ERROR(ppp header files are required))
37 if (test -z "${path_l2tp}"); then
38 AC_PATH_PROG(L2TP, [xl2tpd], [/usr/sbin/xl2tpd], $PATH:/sbin:/usr/sbin)
40 @@ -160,6 +152,18 @@ AC_ARG_ENABLE(pptp,
41 AC_HELP_STRING([--enable-pptp], [enable pptp support]),
42 [enable_pptp=${enableval}], [enable_pptp="no"])
43 if (test "${enable_pptp}" != "no"); then
44 + if (test -z "${path_pptp}"); then
45 + AC_PATH_PROG(PPTP, [pptp], [/usr/sbin/pptp], $PATH:/sbin:/usr/sbin)
51 +AM_CONDITIONAL(PPTP, test "${enable_pptp}" != "no")
52 +AM_CONDITIONAL(PPTP_BUILTIN, test "${enable_pptp}" = "builtin")
54 +if (test "${enable_pptp}" != "no" || test "${enable_l2tp}" != "no"); then
56 if (test -z "${path_pppd}"); then
57 AC_PATH_PROG(PPPD, [pppd], [/usr/sbin/pppd], $PATH:/sbin:/usr/sbin)
59 @@ -168,15 +172,23 @@ if (test "${enable_pptp}" != "no"); then
61 AC_CHECK_HEADERS(pppd/pppd.h, dummy=yes,
62 AC_MSG_ERROR(ppp header files are required))
63 - if (test -z "${path_pptp}"); then
64 - AC_PATH_PROG(PPTP, [pptp], [/usr/sbin/pptp], $PATH:/sbin:/usr/sbin)
68 + AC_CHECK_HEADERS([pppd/chap.h pppd/chap-new.h pppd/chap_ms.h])
70 + PKG_CHECK_EXISTS([pppd],
71 + [AS_VAR_SET([pppd_pkgconfig_support],[yes])])
74 + if test x"$pppd_pkgconfig_support" = xyes; then
75 + PPPD_VERSION=`$PKG_CONFIG --modversion pppd`
78 + AC_DEFINE_UNQUOTED([PPP_VERSION(x,y,z)],
79 + [((x & 0xFF) << 16 | (y & 0xFF) << 8 | (z & 0xFF) << 0)],
80 + [Macro to help determine the particular version of pppd])
81 + PPP_VERSION=$(echo $PPPD_VERSION | sed -e "s/\./\,/g")
82 + AC_DEFINE_UNQUOTED(WITH_PPP_VERSION, PPP_VERSION($PPP_VERSION),
83 + [The real version of pppd represented as an int])
85 -AM_CONDITIONAL(PPTP, test "${enable_pptp}" != "no")
86 -AM_CONDITIONAL(PPTP_BUILTIN, test "${enable_pptp}" = "builtin")
88 AC_CHECK_HEADERS(resolv.h, dummy=yes,
89 AC_MSG_ERROR(resolver header files are required))
90 diff --git a/scripts/libppp-compat.h b/scripts/libppp-compat.h
92 index 0000000..eee1d09
94 +++ b/scripts/libppp-compat.h
96 +/* Copyright (C) Eivind Naess, eivnaes@yahoo.com */
97 +/* SPDX-License-Identifier: GPL-2.0-or-later */
99 +#ifndef __LIBPPP_COMPAT_H__
100 +#define __LIBPPP_COMPAT_H__
102 +/* Define USE_EAPTLS compile with EAP TLS support against older pppd headers,
103 + * pppd >= 2.5.0 use PPP_WITH_EAPTLS and is defined in pppdconf.h */
104 +#define USE_EAPTLS 1
106 +/* Define INET6 to compile with IPv6 support against older pppd headers,
107 + * pppd >= 2.5.0 use PPP_WITH_IPV6CP and is defined in pppdconf.h */
110 +/* PPP < 2.5.0 defines and exports VERSION which overlaps with current package VERSION define.
111 + * this silly macro magic is to work around that. */
113 +#include <pppd/pppd.h>
115 +#ifndef PPPD_VERSION
116 +#define PPPD_VERSION VERSION
119 +#include <pppd/fsm.h>
120 +#include <pppd/ccp.h>
121 +#include <pppd/eui64.h>
122 +#include <pppd/ipcp.h>
123 +#include <pppd/ipv6cp.h>
124 +#include <pppd/eap.h>
125 +#include <pppd/upap.h>
127 +#ifdef HAVE_PPPD_CHAP_H
128 +#include <pppd/chap.h>
131 +#ifdef HAVE_PPPD_CHAP_NEW_H
132 +#include <pppd/chap-new.h>
135 +#ifdef HAVE_PPPD_CHAP_MS_H
136 +#include <pppd/chap_ms.h>
139 +#ifndef PPP_PROTO_CHAP
140 +#define PPP_PROTO_CHAP 0xc223
143 +#ifndef PPP_PROTO_EAP
144 +#define PPP_PROTO_EAP 0xc227
148 +#if WITH_PPP_VERSION < PPP_VERSION(2,5,0)
156 +static inline const char
168 +static inline const char *
175 +ppp_get_mtu (int idx)
177 + return netif_get_mtu(idx);
180 +typedef enum ppp_notify
196 +typedef void (ppp_notify_fn) (void *ctx, int arg);
199 +ppp_add_notify (ppp_notify_t type, ppp_notify_fn *func, void *ctx)
201 + struct notifier **list[NF_MAX_NOTIFY] = {
202 + [NF_PID_CHANGE ] = &pidchange,
203 + [NF_PHASE_CHANGE] = &phasechange,
204 + [NF_EXIT ] = &exitnotify,
205 + [NF_SIGNALED ] = &sigreceived,
206 + [NF_IP_UP ] = &ip_up_notifier,
207 + [NF_IP_DOWN ] = &ip_down_notifier,
208 + [NF_IPV6_UP ] = &ipv6_up_notifier,
209 + [NF_IPV6_DOWN ] = &ipv6_down_notifier,
210 + [NF_AUTH_UP ] = &auth_up_notifier,
211 + [NF_LINK_DOWN ] = &link_down_notifier,
212 + [NF_FORK ] = &fork_notifier,
215 + struct notifier **notify = list[type];
217 + add_notifier(notify, func, ctx);
221 +#endif /* #if WITH_PPP_VERSION < PPP_VERSION(2,5,0) */
222 +#endif /* #if__LIBPPP_COMPAT_H__ */
223 diff --git a/scripts/libppp-plugin.c b/scripts/libppp-plugin.c
224 index 0dd8b47..61641b5 100644
225 --- a/scripts/libppp-plugin.c
226 +++ b/scripts/libppp-plugin.c
228 #include <sys/types.h>
229 #include <sys/stat.h>
231 -#include <pppd/pppd.h>
232 -#include <pppd/fsm.h>
233 -#include <pppd/ipcp.h>
234 #include <netinet/in.h>
235 #include <arpa/inet.h>
237 #include <dbus/dbus.h>
239 +#include "libppp-compat.h"
241 #define INET_ADDRES_LEN (INET_ADDRSTRLEN + 5)
242 #define INET_DNS_LEN (2*INET_ADDRSTRLEN + 9)
244 @@ -47,7 +46,7 @@ static char *path;
245 static DBusConnection *connection;
246 static int prev_phase;
248 -char pppd_version[] = VERSION;
249 +char pppd_version[] = PPPD_VERSION;
251 int plugin_init(void);
253 @@ -170,7 +169,7 @@ static void ppp_up(void *data, int arg)
254 DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING
255 DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
257 - append(&dict, "INTERNAL_IFNAME", ifname);
258 + append(&dict, "INTERNAL_IFNAME", ppp_ifname());
260 inet_ntop(AF_INET, &ipcp_gotoptions[0].ouraddr, buf, INET_ADDRSTRLEN);
261 append(&dict, "INTERNAL_IP4_ADDRESS", buf);
262 @@ -309,9 +308,9 @@ int plugin_init(void)
263 chap_check_hook = ppp_have_secret;
264 pap_check_hook = ppp_have_secret;
266 - add_notifier(&ip_up_notifier, ppp_up, NULL);
267 - add_notifier(&phasechange, ppp_phase_change, NULL);
268 - add_notifier(&exitnotify, ppp_exit, connection);
269 + ppp_add_notify(NF_IP_UP, ppp_up, NULL);
270 + ppp_add_notify(NF_PHASE_CHANGE, ppp_phase_change, NULL);
271 + ppp_add_notify(NF_EXIT, ppp_exit, connection);