ppp, adding support for compiling against pppd-2.5.0

This change does the following
* Adding in nm-pppd-compat.h to mask details regarding different
  versions of pppd.
* Fix the nm-pppd-plugin.c regarding differences in API between
  2.4.9 (current) and latet pppd 2.5.0 in master branch
* Additional fixes to the configure.ac to appropriately set defines used
  for compilation

(cherry picked from commit 8469c09a50)
(cherry picked from commit 521f936567)
This commit is contained in:
Eivind Næss 2023-03-04 22:26:00 +00:00 committed by Thomas Haller
parent f19c9d2097
commit cc1771cfef
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
6 changed files with 158 additions and 24 deletions

View file

@ -3186,6 +3186,7 @@ src_core_ppp_nm_pppd_plugin_la_CPPFLAGS = \
src_core_ppp_nm_pppd_plugin_la_SOURCES = \
src/core/ppp/nm-pppd-plugin.c \
src/core/ppp/nm-pppd-plugin.h \
src/core/ppp/nm-pppd-compat.h \
src/core/ppp/nm-ppp-status.h
src_core_ppp_nm_pppd_plugin_la_LDFLAGS = \

View file

@ -236,6 +236,9 @@
/* Define if you have PPP support */
#mesondefine WITH_PPP
/* Define if you have a more recent version of pppd */
#mesondefine WITH_PPP_VERSION_2_5_OR_NEWER
/* Define to path of pppd binary */
#mesondefine PPPD_PATH

View file

@ -790,6 +790,11 @@ fi
AC_DEFINE_UNQUOTED(PPPD_PATH, "$PPPD_PATH", [Define to path of pppd binary])
AC_SUBST(PPPD_PATH)
AC_CHECK_HEADERS(pppd/chap.h)
if test "x$ac_cv_header_pppd_chap_h" = xyes; then
AC_DEFINE(WITH_PPP_VERSION_2_5_OR_NEWER, 1, "Defined if one has a recent version of pppd headers installed")
fi
# ModemManager1 with libmm-glib
AC_ARG_WITH(modem-manager-1,
AS_HELP_STRING([--with-modem-manager-1],

View file

@ -583,6 +583,10 @@ if enable_ppp
if pppd_plugin_dir == ''
pppd_plugin_dir = join_paths(nm_libdir, 'pppd', pppd_version)
endif
if (pppd_dep.found())
config_h.set10('WITH_PPP_VERSION_2_5_OR_NEWER', 1)
endif
endif
config_h.set10('WITH_PPP', enable_ppp)

View file

@ -0,0 +1,122 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) Eivind Næss, eivnaes@yahoo.com
*/
#ifndef __NM_PPPD_COMPAT_H__
#define __NM_PPPD_COMPAT_H__
/* Define INET6 to compile with IPv6 support against older pppd headers,
pppd >= 2.5.0 use PPP_WITH_IPV6CP and is defined in pppdconf.h */
#define INET6 1
/* PPP < 2.5.0 defines and exports VERSION which overlaps with current package VERSION define.
this silly macro magic is to work around that. */
#undef VERSION
#include <pppd/pppd.h>
#ifndef PPPD_VERSION
#define PPPD_VERSION VERSION
#endif
#include <pppd/fsm.h>
#include <pppd/eui64.h>
#include <pppd/ipcp.h>
#include <pppd/ipv6cp.h>
#include <pppd/upap.h>
#ifdef WITH_PPP_VERSION_2_5_OR_NEWER
#include <pppd/chap.h>
#else
#include <pppd/chap-new.h>
#include <pppd/chap_ms.h>
#endif
#ifndef PPP_PROTO_CHAP
#define PPP_PROTO_CHAP 0xc223
#endif
#ifndef PPP_PROTO_EAP
#define PPP_PROTO_EAP 0xc227
#endif
#ifndef WITH_PPP_VERSION_2_5_OR_NEWER
static inline bool
debug_on(void)
{
return debug;
}
static inline const char *
ppp_ipparam(void)
{
return ipparam;
}
static inline int
ppp_ifunit(void)
{
return ifunit;
}
static inline const char *
ppp_ifname(void)
{
return ifname;
}
static inline int
ppp_get_mtu(int idx)
{
return netif_get_mtu(idx);
}
static inline void
ppp_set_ifname(const char *new_name)
{
g_strlcpy(ifname, new_name, IF_NAMESIZE);
}
typedef enum ppp_notify {
NF_PID_CHANGE,
NF_PHASE_CHANGE,
NF_EXIT,
NF_SIGNALED,
NF_IP_UP,
NF_IP_DOWN,
NF_IPV6_UP,
NF_IPV6_DOWN,
NF_AUTH_UP,
NF_LINK_DOWN,
NF_FORK,
NF_MAX_NOTIFY
} ppp_notify_t;
typedef void(ppp_notify_fn)(void *ctx, int arg);
static inline void
ppp_add_notify(ppp_notify_t type, ppp_notify_fn *func, void *ctx)
{
static struct notifier **list[NF_MAX_NOTIFY] = {
[NF_PID_CHANGE] = &pidchange,
[NF_PHASE_CHANGE] = &phasechange,
[NF_EXIT] = &exitnotify,
[NF_SIGNALED] = &sigreceived,
[NF_IP_UP] = &ip_up_notifier,
[NF_IP_DOWN] = &ip_down_notifier,
[NF_IPV6_UP] = &ipv6_up_notifier,
[NF_IPV6_DOWN] = &ipv6_down_notifier,
[NF_AUTH_UP] = &auth_up_notifier,
[NF_LINK_DOWN] = &link_down_notifier,
[NF_FORK] = &fork_notifier,
};
struct notifier **notify = list[type];
if (notify) {
add_notifier(notify, func, ctx);
}
}
#endif /* #ifndef WITH_PPP_VERSION_2_5_OR_NEWER */
#endif /* #ifdef __NM_PPPD_COMPAT_H__ */

View file

@ -7,29 +7,23 @@
#include <config.h>
#define ___CONFIG_H__
#include <pppd/pppd.h>
#include <pppd/fsm.h>
#include <pppd/ipcp.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/if.h>
#include <arpa/inet.h>
#include <dlfcn.h>
#define INET6
#include <pppd/eui64.h>
#include <pppd/ipv6cp.h>
#include "libnm-glib-aux/nm-default-glib.h"
#include "nm-dbus-interface.h"
#include <glib.h>
#include "nm-pppd-plugin.h"
#include "nm-pppd-compat.h"
#include "nm-ppp-status.h"
#include "libnm-glib-aux/nm-default-glib.h"
#include "nm-dbus-interface.h"
int plugin_init(void);
char pppd_version[] = VERSION;
char pppd_version[] = PPPD_VERSION;
static struct {
GDBusConnection *dbus_connection;
@ -125,7 +119,7 @@ nm_phasechange(int arg)
char new_name[IF_NAMESIZE];
int ifindex;
ifindex = if_nametoindex(ifname);
ifindex = if_nametoindex(ppp_ifname());
/* Make a sync call to ensure that when the call
* terminates the interface already has its final
@ -143,9 +137,11 @@ nm_phasechange(int arg)
NULL);
/* Update the name in pppd if NM changed it */
if (if_indextoname(ifindex, new_name) && !nm_streq0(ifname, new_name)) {
g_message("nm-ppp-plugin: interface name changed from '%s' to '%s'", ifname, new_name);
g_strlcpy(ifname, new_name, IF_NAMESIZE);
if (if_indextoname(ifindex, new_name) && !nm_streq0(ppp_ifname(), new_name)) {
g_message("nm-ppp-plugin: interface name changed from '%s' to '%s'",
ppp_ifname(),
new_name);
ppp_set_ifname(new_name);
}
}
}
@ -166,7 +162,7 @@ nm_ip_up(void *data, int arg)
ipcp_options opts = ipcp_gotoptions[0];
ipcp_options peer_opts = ipcp_hisoptions[0];
GVariantBuilder builder;
guint32 pppd_made_up_address = htonl(0x0a404040 + ifunit);
guint32 pppd_made_up_address = htonl(0x0a404040 + ppp_ifunit());
g_return_if_fail(G_IS_DBUS_CONNECTION(gl.dbus_connection));
@ -186,7 +182,7 @@ nm_ip_up(void *data, int arg)
g_variant_builder_add(&builder,
"{sv}",
NM_PPP_IP4_CONFIG_INTERFACE,
g_variant_new_string(ifname));
g_variant_new_string(ppp_ifname()));
g_variant_builder_add(&builder,
"{sv}",
@ -292,7 +288,7 @@ nm_ip6_up(void *data, int arg)
g_variant_builder_add(&builder,
"{sv}",
NM_PPP_IP6_CONFIG_INTERFACE,
g_variant_new_string(ifname));
g_variant_new_string(ppp_ifname()));
g_variant_builder_add(&builder, "{sv}", NM_PPP_IP6_CONFIG_OUR_IID, eui64_to_variant(go->ourid));
g_variant_builder_add(&builder,
"{sv}",
@ -393,6 +389,7 @@ nm_exit_notify(void *data, int arg)
static void
add_ip6_notifier(void)
{
#if WITH_PPP_VERSION < PPP_VERSION(2, 5, 0)
static struct notifier **notifier = NULL;
static gsize load_once = 0;
@ -409,6 +406,9 @@ add_ip6_notifier(void)
add_notifier(notifier, nm_ip6_up, NULL);
else
g_message("nm-ppp-plugin: no IPV6CP notifier support; IPv6 not available");
#else
ppp_add_notify(NF_IPV6_UP, nm_ip6_up, NULL);
#endif
}
int
@ -427,17 +427,16 @@ plugin_init(void)
return -1;
}
gl.ipparam = g_strdup(ipparam);
gl.ipparam = g_strdup(ppp_ipparam());
chap_passwd_hook = get_credentials;
chap_check_hook = get_chap_check;
pap_passwd_hook = get_credentials;
pap_check_hook = get_pap_check;
add_notifier(&phasechange, nm_phasechange_hook, NULL);
add_notifier(&ip_up_notifier, nm_ip_up, NULL);
add_notifier(&exitnotify, nm_exit_notify, NULL);
ppp_add_notify(NF_PHASE_CHANGE, nm_phasechange_hook, NULL);
ppp_add_notify(NF_IP_UP, nm_ip_up, NULL);
ppp_add_notify(NF_EXIT, nm_exit_notify, NULL);
add_ip6_notifier();
return 0;
}