summary refs log tree commit diff
path: root/src/core/devices/adsl
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2021-02-11 18:11:46 +0100
committerMichael Biebl <biebl@debian.org>2021-02-11 18:11:46 +0100
commit80ec1decc49c72efec2a8b87c06245c92c0ab807 (patch)
treee3b229aa94e8dcf0590f2317664176e7b8f7607b /src/core/devices/adsl
parent65f86e8f56267192d42f2b629fc6b0c99fb9cd0c (diff)
New upstream version 1.29.90 upstream/1.29.90
Diffstat (limited to 'src/core/devices/adsl')
-rw-r--r--src/core/devices/adsl/meson.build26
-rw-r--r--src/core/devices/adsl/nm-atm-manager.c271
-rw-r--r--src/core/devices/adsl/nm-device-adsl.c720
-rw-r--r--src/core/devices/adsl/nm-device-adsl.h30
4 files changed, 1047 insertions, 0 deletions
diff --git a/src/core/devices/adsl/meson.build b/src/core/devices/adsl/meson.build
new file mode 100644
index 00000000..95f61d95
--- /dev/null
+++ b/src/core/devices/adsl/meson.build
@@ -0,0 +1,26 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+libnm_device_plugin_adsl = shared_module(
+  'nm-device-plugin-adsl',
+  sources: files(
+    'nm-atm-manager.c',
+    'nm-device-adsl.c',
+  ),
+  dependencies: core_plugin_dep,
+  c_args: daemon_c_flags,
+  link_args: ldflags_linker_script_devices,
+  link_depends: linker_script_devices,
+  install: true,
+  install_dir: nm_plugindir,
+)
+
+core_plugins += libnm_device_plugin_adsl
+
+test(
+  'check-local-devices-adsl',
+  check_exports,
+  args: [
+    libnm_device_plugin_adsl.full_path(),
+    linker_script_devices,
+  ],
+)
diff --git a/src/core/devices/adsl/nm-atm-manager.c b/src/core/devices/adsl/nm-atm-manager.c
new file mode 100644
index 00000000..9be9b5ce
--- /dev/null
+++ b/src/core/devices/adsl/nm-atm-manager.c
@@ -0,0 +1,271 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2009 - 2013 Red Hat, Inc.
+ */
+
+#include "src/core/nm-default-daemon.h"
+
+#include <gmodule.h>
+#include <libudev.h>
+
+#include "nm-setting-adsl.h"
+#include "nm-device-adsl.h"
+#include "devices/nm-device-factory.h"
+#include "platform/nm-platform.h"
+#include "nm-udev-aux/nm-udev-utils.h"
+
+/*****************************************************************************/
+
+#define NM_TYPE_ATM_MANAGER (nm_atm_manager_get_type())
+#define NM_ATM_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_ATM_MANAGER, NMAtmManager))
+#define NM_ATM_MANAGER_CLASS(klass) \
+    (G_TYPE_CHECK_CLASS_CAST((klass), NM_TYPE_ATM_MANAGER, NMAtmManagerClass))
+#define NM_IS_ATM_MANAGER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), NM_TYPE_ATM_MANAGER))
+#define NM_IS_ATM_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NM_TYPE_ATM_MANAGER))
+#define NM_ATM_MANAGER_GET_CLASS(obj) \
+    (G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_ATM_MANAGER, NMAtmManagerClass))
+
+typedef struct {
+    NMUdevClient *udev_client;
+    GSList *      devices;
+} NMAtmManagerPrivate;
+
+typedef struct {
+    NMDeviceFactory     parent;
+    NMAtmManagerPrivate _priv;
+} NMAtmManager;
+
+typedef struct {
+    NMDeviceFactoryClass parent;
+} NMAtmManagerClass;
+
+static GType nm_atm_manager_get_type(void);
+
+G_DEFINE_TYPE(NMAtmManager, nm_atm_manager, NM_TYPE_DEVICE_FACTORY);
+
+#define NM_ATM_MANAGER_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMAtmManager, NM_IS_ATM_MANAGER)
+
+/*****************************************************************************/
+
+NM_DEVICE_FACTORY_DECLARE_TYPES(
+    NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(NM_SETTING_ADSL_SETTING_NAME));
+
+G_MODULE_EXPORT NMDeviceFactory *
+                nm_device_factory_create(GError **error)
+{
+    return g_object_new(NM_TYPE_ATM_MANAGER, NULL);
+}
+
+/*****************************************************************************/
+
+static gboolean
+dev_get_attrs(struct udev_device *udev_device, const char **out_path, char **out_driver)
+{
+    struct udev_device *parent = NULL;
+    const char *        driver, *path;
+
+    g_return_val_if_fail(udev_device != NULL, FALSE);
+    g_return_val_if_fail(out_path != NULL, FALSE);
+    g_return_val_if_fail(out_driver != NULL, FALSE);
+
+    path = udev_device_get_syspath(udev_device);
+    if (!path) {
+        nm_log_warn(LOGD_PLATFORM, "couldn't determine device path; ignoring...");
+        return FALSE;
+    }
+
+    driver = udev_device_get_driver(udev_device);
+    if (!driver) {
+        /* Try the parent */
+        parent = udev_device_get_parent(udev_device);
+        if (parent)
+            driver = udev_device_get_driver(parent);
+    }
+
+    *out_path   = path;
+    *out_driver = g_strdup(driver);
+
+    return TRUE;
+}
+
+static void
+device_destroyed(gpointer user_data, GObject *dead)
+{
+    NMAtmManager *       self = NM_ATM_MANAGER(user_data);
+    NMAtmManagerPrivate *priv = NM_ATM_MANAGER_GET_PRIVATE(self);
+
+    priv->devices = g_slist_remove(priv->devices, dead);
+}
+
+static void
+adsl_add(NMAtmManager *self, struct udev_device *udev_device)
+{
+    NMAtmManagerPrivate *priv = NM_ATM_MANAGER_GET_PRIVATE(self);
+    const char *         ifname, *sysfs_path = NULL;
+    char *               driver         = NULL;
+    gs_free char *       atm_index_path = NULL;
+    int                  atm_index;
+    NMDevice *           device;
+
+    g_return_if_fail(udev_device != NULL);
+
+    ifname = udev_device_get_sysname(udev_device);
+    if (!ifname) {
+        nm_log_warn(LOGD_PLATFORM, "failed to get device's interface name");
+        return;
+    }
+
+    nm_log_dbg(LOGD_PLATFORM, "(%s): found ATM device", ifname);
+
+    atm_index_path =
+        g_strdup_printf("/sys/class/atm/%s/atmindex", NM_ASSERT_VALID_PATH_COMPONENT(ifname));
+    atm_index = (int) nm_platform_sysctl_get_int_checked(NM_PLATFORM_GET,
+                                                         NMP_SYSCTL_PATHID_ABSOLUTE(atm_index_path),
+                                                         10,
+                                                         0,
+                                                         G_MAXINT,
+                                                         -1);
+    if (atm_index < 0) {
+        nm_log_warn(LOGD_PLATFORM, "(%s): failed to get ATM index", ifname);
+        return;
+    }
+
+    if (!dev_get_attrs(udev_device, &sysfs_path, &driver)) {
+        nm_log_warn(LOGD_PLATFORM, "(%s): failed to get ATM attributes", ifname);
+        return;
+    }
+
+    g_assert(sysfs_path);
+
+    device = nm_device_adsl_new(sysfs_path, ifname, driver, atm_index);
+    g_assert(device);
+
+    priv->devices = g_slist_prepend(priv->devices, device);
+    g_object_weak_ref(G_OBJECT(device), device_destroyed, self);
+
+    g_signal_emit_by_name(self, NM_DEVICE_FACTORY_DEVICE_ADDED, device);
+    g_object_unref(device);
+
+    g_free(driver);
+}
+
+static void
+adsl_remove(NMAtmManager *self, struct udev_device *udev_device)
+{
+    NMAtmManagerPrivate *priv  = NM_ATM_MANAGER_GET_PRIVATE(self);
+    const char *         iface = udev_device_get_sysname(udev_device);
+    GSList *             iter;
+
+    nm_log_dbg(LOGD_PLATFORM, "(%s): removing ATM device", iface);
+
+    for (iter = priv->devices; iter; iter = iter->next) {
+        NMDevice *device = iter->data;
+
+        /* Match 'iface' not 'ip_iface' to the ATM device instead of the
+         * NAS bridge interface or PPPoE interface.
+         */
+        if (g_strcmp0(nm_device_get_iface(device), iface) != 0)
+            continue;
+
+        g_object_weak_unref(G_OBJECT(iter->data), device_destroyed, self);
+        priv->devices = g_slist_remove(priv->devices, device);
+        g_signal_emit_by_name(device, NM_DEVICE_REMOVED);
+        break;
+    }
+}
+
+static void
+start(NMDeviceFactory *factory)
+{
+    NMAtmManager *          self = NM_ATM_MANAGER(factory);
+    NMAtmManagerPrivate *   priv = NM_ATM_MANAGER_GET_PRIVATE(self);
+    struct udev_enumerate * enumerate;
+    struct udev_list_entry *devices;
+
+    enumerate = nm_udev_client_enumerate_new(priv->udev_client);
+    udev_enumerate_add_match_is_initialized(enumerate);
+    udev_enumerate_scan_devices(enumerate);
+    devices = udev_enumerate_get_list_entry(enumerate);
+    for (; devices; devices = udev_list_entry_get_next(devices)) {
+        struct udev_device *udevice;
+
+        udevice = udev_device_new_from_syspath(udev_enumerate_get_udev(enumerate),
+                                               udev_list_entry_get_name(devices));
+        if (udevice) {
+            adsl_add(self, udevice);
+            udev_device_unref(udevice);
+        }
+    }
+    udev_enumerate_unref(enumerate);
+}
+
+static void
+handle_uevent(NMUdevClient *client, struct udev_device *device, gpointer user_data)
+{
+    NMAtmManager *self = NM_ATM_MANAGER(user_data);
+    const char *  subsys;
+    const char *  ifindex;
+    guint64       seqnum;
+    const char *  action;
+
+    action = udev_device_get_action(device);
+
+    g_return_if_fail(action != NULL);
+
+    /* A bit paranoid */
+    subsys = udev_device_get_subsystem(device);
+    g_return_if_fail(!g_strcmp0(subsys, "atm"));
+
+    ifindex = udev_device_get_property_value(device, "IFINDEX");
+    seqnum  = udev_device_get_seqnum(device);
+    nm_log_dbg(LOGD_PLATFORM,
+               "UDEV event: action '%s' subsys '%s' device '%s' (%s); seqnum=%" G_GUINT64_FORMAT,
+               action,
+               subsys,
+               udev_device_get_sysname(device),
+               ifindex ?: "unknown",
+               seqnum);
+
+    if (!strcmp(action, "add"))
+        adsl_add(self, device);
+    else if (!strcmp(action, "remove"))
+        adsl_remove(self, device);
+}
+
+/*****************************************************************************/
+
+static void
+nm_atm_manager_init(NMAtmManager *self)
+{
+    NMAtmManagerPrivate *priv = NM_ATM_MANAGER_GET_PRIVATE(self);
+
+    priv->udev_client = nm_udev_client_new(NM_MAKE_STRV("atm"), handle_uevent, self);
+}
+
+static void
+dispose(GObject *object)
+{
+    NMAtmManager *       self = NM_ATM_MANAGER(object);
+    NMAtmManagerPrivate *priv = NM_ATM_MANAGER_GET_PRIVATE(self);
+    GSList *             iter;
+
+    for (iter = priv->devices; iter; iter = iter->next)
+        g_object_weak_unref(G_OBJECT(iter->data), device_destroyed, self);
+    nm_clear_pointer(&priv->devices, g_slist_free);
+
+    priv->udev_client = nm_udev_client_destroy(priv->udev_client);
+
+    G_OBJECT_CLASS(nm_atm_manager_parent_class)->dispose(object);
+}
+
+static void
+nm_atm_manager_class_init(NMAtmManagerClass *klass)
+{
+    GObjectClass *        object_class  = G_OBJECT_CLASS(klass);
+    NMDeviceFactoryClass *factory_class = NM_DEVICE_FACTORY_CLASS(klass);
+
+    object_class->dispose = dispose;
+
+    factory_class->get_supported_types = get_supported_types;
+    factory_class->start               = start;
+}
diff --git a/src/core/devices/adsl/nm-device-adsl.c b/src/core/devices/adsl/nm-device-adsl.c
new file mode 100644
index 00000000..34c062a8
--- /dev/null
+++ b/src/core/devices/adsl/nm-device-adsl.c
@@ -0,0 +1,720 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Pantelis Koukousoulas <pktoss@gmail.com>
+ */
+
+#include "src/core/nm-default-daemon.h"
+
+#include "nm-device-adsl.h"
+
+#include <sys/socket.h>
+#include <linux/atmdev.h>
+#include <linux/atmbr2684.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "nm-ip4-config.h"
+#include "devices/nm-device-private.h"
+#include "platform/nm-platform.h"
+#include "ppp/nm-ppp-manager-call.h"
+#include "ppp/nm-ppp-status.h"
+#include "nm-setting-adsl.h"
+#include "nm-utils.h"
+
+#define _NMLOG_DEVICE_TYPE NMDeviceAdsl
+#include "devices/nm-device-logging.h"
+
+/*****************************************************************************/
+
+NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_ATM_INDEX, );
+
+typedef struct {
+    guint carrier_poll_id;
+    int   atm_index;
+
+    /* PPP */
+    NMPPPManager *ppp_manager;
+
+    /* RFC 2684 bridging (PPPoE over ATM) */
+    int   brfd;
+    int   nas_ifindex;
+    char *nas_ifname;
+    guint nas_update_id;
+    guint nas_update_count;
+} NMDeviceAdslPrivate;
+
+struct _NMDeviceAdsl {
+    NMDevice            parent;
+    NMDeviceAdslPrivate _priv;
+};
+
+struct _NMDeviceAdslClass {
+    NMDeviceClass parent;
+};
+
+G_DEFINE_TYPE(NMDeviceAdsl, nm_device_adsl, NM_TYPE_DEVICE)
+
+#define NM_DEVICE_ADSL_GET_PRIVATE(self) \
+    _NM_GET_PRIVATE(self, NMDeviceAdsl, NM_IS_DEVICE_ADSL, NMDevice)
+
+/*****************************************************************************/
+
+static NMDeviceCapabilities
+get_generic_capabilities(NMDevice *dev)
+{
+    return (NM_DEVICE_CAP_CARRIER_DETECT | NM_DEVICE_CAP_NONSTANDARD_CARRIER
+            | NM_DEVICE_CAP_IS_NON_KERNEL);
+}
+
+static gboolean
+check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
+{
+    NMSettingAdsl *s_adsl;
+    const char *   protocol;
+
+    if (!NM_DEVICE_CLASS(nm_device_adsl_parent_class)
+             ->check_connection_compatible(device, connection, error))
+        return FALSE;
+
+    s_adsl = nm_connection_get_setting_adsl(connection);
+
+    protocol = nm_setting_adsl_get_protocol(s_adsl);
+    if (nm_streq0(protocol, NM_SETTING_ADSL_PROTOCOL_IPOATM)) {
+        /* FIXME: we don't yet support IPoATM */
+        nm_utils_error_set_literal(error,
+                                   NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
+                                   "IPoATM protocol is not yet supported");
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+static gboolean
+complete_connection(NMDevice *           device,
+                    NMConnection *       connection,
+                    const char *         specific_object,
+                    NMConnection *const *existing_connections,
+                    GError **            error)
+{
+    NMSettingAdsl *s_adsl;
+
+    /*
+     * We can't telepathically figure out the username, so if
+     * it wasn't given, we can't complete the connection.
+     */
+    s_adsl = nm_connection_get_setting_adsl(connection);
+    if (s_adsl && !nm_setting_verify(NM_SETTING(s_adsl), NULL, error))
+        return FALSE;
+
+    nm_utils_complete_generic(nm_device_get_platform(device),
+                              connection,
+                              NM_SETTING_ADSL_SETTING_NAME,
+                              existing_connections,
+                              NULL,
+                              _("ADSL connection"),
+                              NULL,
+                              NULL,
+                              FALSE); /* No IPv6 yet by default */
+    return TRUE;
+}
+
+/*****************************************************************************/
+
+static gboolean
+br2684_assign_vcc(NMDeviceAdsl *self, NMSettingAdsl *s_adsl)
+{
+    NMDeviceAdslPrivate *     priv = NM_DEVICE_ADSL_GET_PRIVATE(self);
+    struct sockaddr_atmpvc    addr;
+    struct atm_backend_br2684 be;
+    struct atm_qos            qos;
+    int                       errsv, err, bufsize = 8192;
+    const char *              encapsulation;
+    gboolean                  is_llc;
+
+    g_return_val_if_fail(priv->brfd == -1, FALSE);
+    g_return_val_if_fail(priv->nas_ifname != NULL, FALSE);
+
+    priv->brfd = socket(PF_ATMPVC, SOCK_DGRAM | SOCK_CLOEXEC, ATM_AAL5);
+    if (priv->brfd < 0) {
+        errsv = errno;
+        _LOGE(LOGD_ADSL, "failed to open ATM control socket (%d)", errsv);
+        priv->brfd = -1;
+        return FALSE;
+    }
+
+    err = setsockopt(priv->brfd, SOL_SOCKET, SO_SNDBUF, &bufsize, sizeof(bufsize));
+    if (err != 0) {
+        errsv = errno;
+        _LOGE(LOGD_ADSL, "failed to set SNDBUF option (%d)", errsv);
+        goto error;
+    }
+
+    /* QoS */
+    memset(&qos, 0, sizeof(qos));
+    qos.aal                = ATM_AAL5;
+    qos.txtp.traffic_class = ATM_UBR;
+    qos.txtp.max_sdu       = 1524;
+    qos.txtp.pcr           = ATM_MAX_PCR;
+    qos.rxtp               = qos.txtp;
+
+    err = setsockopt(priv->brfd, SOL_ATM, SO_ATMQOS, &qos, sizeof(qos));
+    if (err != 0) {
+        errsv = errno;
+        _LOGE(LOGD_ADSL, "failed to set QoS (%d)", errsv);
+        goto error;
+    }
+
+    encapsulation = nm_setting_adsl_get_encapsulation(s_adsl);
+
+    /* VPI/VCI */
+    memset(&addr, 0, sizeof(addr));
+    addr.sap_family   = AF_ATMPVC;
+    addr.sap_addr.itf = priv->atm_index;
+    addr.sap_addr.vpi = (guint16) nm_setting_adsl_get_vpi(s_adsl);
+    addr.sap_addr.vci = (int) nm_setting_adsl_get_vci(s_adsl);
+
+    _LOGD(LOGD_ADSL,
+          "assigning address %d.%d.%d encapsulation %s",
+          priv->atm_index,
+          addr.sap_addr.vpi,
+          addr.sap_addr.vci,
+          encapsulation ?: "(none)");
+
+    err = connect(priv->brfd, (struct sockaddr *) &addr, sizeof(addr));
+    if (err != 0) {
+        errsv = errno;
+        _LOGE(LOGD_ADSL, "failed to set VPI/VCI (%d)", errsv);
+        goto error;
+    }
+
+    /* And last attach the VCC to the interface */
+    is_llc = (g_strcmp0(encapsulation, "llc") == 0);
+
+    memset(&be, 0, sizeof(be));
+    be.backend_num   = ATM_BACKEND_BR2684;
+    be.ifspec.method = BR2684_FIND_BYIFNAME;
+    nm_utils_ifname_cpy(be.ifspec.spec.ifname, priv->nas_ifname);
+    be.fcs_in  = BR2684_FCSIN_NO;
+    be.fcs_out = BR2684_FCSOUT_NO;
+    be.encaps  = is_llc ? BR2684_ENCAPS_LLC : BR2684_ENCAPS_VC;
+    err        = ioctl(priv->brfd, ATM_SETBACKEND, &be);
+    if (err != 0) {
+        errsv = errno;
+        _LOGE(LOGD_ADSL, "failed to attach VCC (%d)", errsv);
+        goto error;
+    }
+
+    return TRUE;
+
+error:
+    nm_close(priv->brfd);
+    priv->brfd = -1;
+    return FALSE;
+}
+
+static void
+link_changed_cb(NMPlatform *    platform,
+                int             obj_type_i,
+                int             ifindex,
+                NMPlatformLink *info,
+                int             change_type_i,
+                NMDeviceAdsl *  self)
+{
+    const NMPlatformSignalChangeType change_type = change_type_i;
+
+    if (change_type == NM_PLATFORM_SIGNAL_REMOVED) {
+        NMDeviceAdslPrivate *priv   = NM_DEVICE_ADSL_GET_PRIVATE(self);
+        NMDevice *           device = NM_DEVICE(self);
+
+        /* This only gets called for PPPoE connections and "nas" interfaces */
+
+        if (priv->nas_ifindex > 0 && ifindex == priv->nas_ifindex) {
+            /* NAS device went away for some reason; kill the connection */
+            _LOGD(LOGD_ADSL, "br2684 interface disappeared");
+            nm_device_state_changed(device,
+                                    NM_DEVICE_STATE_FAILED,
+                                    NM_DEVICE_STATE_REASON_BR2684_FAILED);
+        }
+    }
+}
+
+static gboolean
+pppoe_vcc_config(NMDeviceAdsl *self)
+{
+    NMDeviceAdslPrivate *priv   = NM_DEVICE_ADSL_GET_PRIVATE(self);
+    NMDevice *           device = NM_DEVICE(self);
+    NMSettingAdsl *      s_adsl;
+
+    s_adsl = nm_device_get_applied_setting(device, NM_TYPE_SETTING_ADSL);
+
+    g_return_val_if_fail(s_adsl, FALSE);
+
+    /* Set up the VCC */
+    if (!br2684_assign_vcc(self, s_adsl))
+        return FALSE;
+
+    /* Watch for the 'nas' interface going away */
+    g_signal_connect(nm_device_get_platform(device),
+                     NM_PLATFORM_SIGNAL_LINK_CHANGED,
+                     G_CALLBACK(link_changed_cb),
+                     self);
+
+    _LOGD(LOGD_ADSL, "ATM setup successful");
+
+    /* otherwise we're good for stage3 */
+    nm_platform_link_set_up(nm_device_get_platform(device), priv->nas_ifindex, NULL);
+
+    return TRUE;
+}
+
+static gboolean
+nas_update_cb(gpointer user_data)
+{
+    NMDeviceAdsl *       self   = NM_DEVICE_ADSL(user_data);
+    NMDeviceAdslPrivate *priv   = NM_DEVICE_ADSL_GET_PRIVATE(self);
+    NMDevice *           device = NM_DEVICE(self);
+
+    nm_assert(priv->nas_ifname);
+
+    priv->nas_update_count++;
+
+    nm_assert(priv->nas_ifindex <= 0);
+    priv->nas_ifindex =
+        nm_platform_link_get_ifindex(nm_device_get_platform(device), priv->nas_ifname);
+    if (priv->nas_ifindex <= 0) {
+        if (priv->nas_update_count <= 10) {
+            /* Keep waiting for it to appear */
+            return G_SOURCE_CONTINUE;
+        }
+        priv->nas_update_id = 0;
+        _LOGW(LOGD_ADSL,
+              "failed to find br2684 interface %s ifindex after timeout",
+              priv->nas_ifname);
+        nm_device_state_changed(device,
+                                NM_DEVICE_STATE_FAILED,
+                                NM_DEVICE_STATE_REASON_BR2684_FAILED);
+        return G_SOURCE_REMOVE;
+    }
+
+    priv->nas_update_id = 0;
+    _LOGD(LOGD_ADSL, "using br2684 iface '%s' index %d", priv->nas_ifname, priv->nas_ifindex);
+
+    if (!pppoe_vcc_config(self)) {
+        nm_device_state_changed(device,
+                                NM_DEVICE_STATE_FAILED,
+                                NM_DEVICE_STATE_REASON_BR2684_FAILED);
+        return G_SOURCE_REMOVE;
+    }
+
+    nm_device_activate_schedule_stage2_device_config(device, TRUE);
+    return G_SOURCE_REMOVE;
+}
+
+static gboolean
+br2684_create_iface(NMDeviceAdsl *self)
+{
+    NMDeviceAdslPrivate *   priv = NM_DEVICE_ADSL_GET_PRIVATE(self);
+    struct atm_newif_br2684 ni;
+    nm_auto_close int       fd = -1;
+    int                     err, errsv;
+    guint                   num = 0;
+
+    if (nm_clear_g_source(&priv->nas_update_id))
+        nm_assert_not_reached();
+
+    fd = socket(PF_ATMPVC, SOCK_DGRAM | SOCK_CLOEXEC, ATM_AAL5);
+    if (fd < 0) {
+        errsv = errno;
+        _LOGE(LOGD_ADSL, "failed to open ATM control socket (%d)", errsv);
+        return FALSE;
+    }
+
+    memset(&ni, 0, sizeof(ni));
+    ni.backend_num = ATM_BACKEND_BR2684;
+    ni.media       = BR2684_MEDIA_ETHERNET;
+    ni.mtu         = 1500;
+
+    /* Loop attempting to create an interface that doesn't exist yet.  The
+     * kernel can create one for us automatically, but due to API issues it
+     * cannot return that name to us.  Since we want to know the name right
+     * away, just brute-force it.
+     */
+    while (TRUE) {
+        memset(&ni.ifname, 0, sizeof(ni.ifname));
+        g_snprintf(ni.ifname, sizeof(ni.ifname), "nas%u", num++);
+
+        err = ioctl(fd, ATM_NEWBACKENDIF, &ni);
+        if (err != 0) {
+            errsv = errno;
+            if (errsv == EEXIST)
+                continue;
+
+            _LOGW(LOGD_ADSL, "failed to create br2684 interface (%d)", errsv);
+            return FALSE;
+        }
+
+        nm_utils_strdup_reset(&priv->nas_ifname, ni.ifname);
+        _LOGD(LOGD_ADSL, "waiting for br2684 iface '%s' to appear", priv->nas_ifname);
+        priv->nas_update_count = 0;
+        priv->nas_update_id    = g_timeout_add(100, nas_update_cb, self);
+        return TRUE;
+    }
+}
+
+static NMActStageReturn
+act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason)
+{
+    NMDeviceAdsl *       self = NM_DEVICE_ADSL(device);
+    NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE(self);
+    NMSettingAdsl *      s_adsl;
+    const char *         protocol;
+
+    s_adsl = nm_device_get_applied_setting(device, NM_TYPE_SETTING_ADSL);
+
+    g_return_val_if_fail(s_adsl, NM_ACT_STAGE_RETURN_FAILURE);
+
+    protocol = nm_setting_adsl_get_protocol(s_adsl);
+    _LOGD(LOGD_ADSL, "using ADSL protocol '%s'", protocol);
+
+    if (nm_streq0(protocol, NM_SETTING_ADSL_PROTOCOL_PPPOA)) {
+        /* PPPoA doesn't need anything special */
+        return NM_ACT_STAGE_RETURN_SUCCESS;
+    }
+
+    if (nm_streq0(protocol, NM_SETTING_ADSL_PROTOCOL_PPPOE)) {
+        /* PPPoE needs RFC2684 bridging before we can do PPP over it */
+        if (priv->nas_ifindex <= 0) {
+            if (priv->nas_update_id == 0) {
+                if (!br2684_create_iface(self)) {
+                    NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_BR2684_FAILED);
+                    return NM_ACT_STAGE_RETURN_FAILURE;
+                }
+            }
+            return NM_ACT_STAGE_RETURN_POSTPONE;
+        }
+        return NM_ACT_STAGE_RETURN_SUCCESS;
+    }
+
+    _LOGW(LOGD_ADSL, "unhandled ADSL protocol '%s'", protocol);
+    return NM_ACT_STAGE_RETURN_SUCCESS;
+}
+
+static void
+ppp_state_changed(NMPPPManager *ppp_manager, NMPPPStatus status, gpointer user_data)
+{
+    NMDevice *device = NM_DEVICE(user_data);
+
+    switch (status) {
+    case NM_PPP_STATUS_DISCONNECT:
+        nm_device_state_changed(device,
+                                NM_DEVICE_STATE_FAILED,
+                                NM_DEVICE_STATE_REASON_PPP_DISCONNECT);
+        break;
+    case NM_PPP_STATUS_DEAD:
+        nm_device_state_changed(device, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_PPP_FAILED);
+        break;
+    default:
+        break;
+    }
+}
+
+static void
+ppp_ifindex_set(NMPPPManager *ppp_manager, int ifindex, const char *iface, gpointer user_data)
+{
+    NMDevice *device = NM_DEVICE(user_data);
+
+    if (!nm_device_set_ip_ifindex(device, ifindex)) {
+        nm_device_state_changed(device,
+                                NM_DEVICE_STATE_FAILED,
+                                NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE);
+    }
+}
+
+static void
+ppp_ip4_config(NMPPPManager *ppp_manager, NMIP4Config *config, gpointer user_data)
+{
+    NMDevice *device = NM_DEVICE(user_data);
+
+    /* Ignore PPP IP4 events that come in after initial configuration */
+    if (nm_device_activate_ip4_state_in_conf(device))
+        nm_device_activate_schedule_ip_config_result(device, AF_INET, NM_IP_CONFIG_CAST(config));
+}
+
+static NMActStageReturn
+act_stage3_ip4_config_start(NMDevice *           device,
+                            NMIP4Config **       out_config,
+                            NMDeviceStateReason *out_failure_reason)
+{
+    NMDeviceAdsl *       self = NM_DEVICE_ADSL(device);
+    NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE(self);
+    NMSettingAdsl *      s_adsl;
+    NMActRequest *       req;
+    GError *             err = NULL;
+    const char *         ppp_iface;
+
+    req = nm_device_get_act_request(device);
+
+    g_return_val_if_fail(req, NM_ACT_STAGE_RETURN_FAILURE);
+
+    s_adsl = nm_device_get_applied_setting(device, NM_TYPE_SETTING_ADSL);
+
+    g_return_val_if_fail(s_adsl, NM_ACT_STAGE_RETURN_FAILURE);
+
+    /* PPPoE uses the NAS interface, not the ATM interface */
+    if (nm_streq0(nm_setting_adsl_get_protocol(s_adsl), NM_SETTING_ADSL_PROTOCOL_PPPOE)) {
+        nm_assert(priv->nas_ifname);
+        ppp_iface = priv->nas_ifname;
+
+        _LOGD(LOGD_ADSL, "starting PPPoE on br2684 interface %s", priv->nas_ifname);
+    } else {
+        ppp_iface = nm_device_get_iface(device);
+        _LOGD(LOGD_ADSL, "starting PPPoA");
+    }
+
+    priv->ppp_manager = nm_ppp_manager_create(ppp_iface, &err);
+
+    if (priv->ppp_manager) {
+        nm_ppp_manager_set_route_parameters(priv->ppp_manager,
+                                            nm_device_get_route_table(device, AF_INET),
+                                            nm_device_get_route_metric(device, AF_INET),
+                                            nm_device_get_route_table(device, AF_INET6),
+                                            nm_device_get_route_metric(device, AF_INET6));
+    }
+
+    if (!priv->ppp_manager
+        || !nm_ppp_manager_start(priv->ppp_manager,
+                                 req,
+                                 nm_setting_adsl_get_username(s_adsl),
+                                 30,
+                                 0,
+                                 &err)) {
+        _LOGW(LOGD_ADSL, "PPP failed to start: %s", err->message);
+        g_error_free(err);
+
+        g_clear_object(&priv->ppp_manager);
+
+        NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_PPP_START_FAILED);
+        return NM_ACT_STAGE_RETURN_FAILURE;
+    }
+
+    g_signal_connect(priv->ppp_manager,
+                     NM_PPP_MANAGER_SIGNAL_STATE_CHANGED,
+                     G_CALLBACK(ppp_state_changed),
+                     self);
+    g_signal_connect(priv->ppp_manager,
+                     NM_PPP_MANAGER_SIGNAL_IFINDEX_SET,
+                     G_CALLBACK(ppp_ifindex_set),
+                     self);
+    g_signal_connect(priv->ppp_manager,
+                     NM_PPP_MANAGER_SIGNAL_IP4_CONFIG,
+                     G_CALLBACK(ppp_ip4_config),
+                     self);
+    return NM_ACT_STAGE_RETURN_POSTPONE;
+}
+
+static NMActStageReturn
+act_stage3_ip_config_start(NMDevice *           device,
+                           int                  addr_family,
+                           gpointer *           out_config,
+                           NMDeviceStateReason *out_failure_reason)
+{
+    if (addr_family == AF_INET)
+        return act_stage3_ip4_config_start(device, (NMIP4Config **) out_config, out_failure_reason);
+
+    return NM_DEVICE_CLASS(nm_device_adsl_parent_class)
+        ->act_stage3_ip_config_start(device, addr_family, out_config, out_failure_reason);
+}
+
+static void
+adsl_cleanup(NMDeviceAdsl *self)
+{
+    NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE(self);
+
+    if (priv->ppp_manager) {
+        g_signal_handlers_disconnect_by_func(priv->ppp_manager,
+                                             G_CALLBACK(ppp_state_changed),
+                                             self);
+        g_signal_handlers_disconnect_by_func(priv->ppp_manager, G_CALLBACK(ppp_ip4_config), self);
+        nm_ppp_manager_stop(priv->ppp_manager, NULL, NULL, NULL);
+        g_clear_object(&priv->ppp_manager);
+    }
+
+    g_signal_handlers_disconnect_by_func(nm_device_get_platform(NM_DEVICE(self)),
+                                         G_CALLBACK(link_changed_cb),
+                                         self);
+
+    nm_close(priv->brfd);
+    priv->brfd = -1;
+
+    nm_clear_g_source(&priv->nas_update_id);
+
+    /* FIXME: kernel has no way of explicitly deleting the 'nasX' interface yet,
+     * so it gets leaked.  It does get destroyed when it's no longer in use,
+     * but we have no control over that.
+     */
+    priv->nas_ifindex = 0;
+    nm_clear_g_free(&priv->nas_ifname);
+}
+
+static void
+deactivate(NMDevice *device)
+{
+    adsl_cleanup(NM_DEVICE_ADSL(device));
+}
+
+/*****************************************************************************/
+
+static gboolean
+carrier_update_cb(gpointer user_data)
+{
+    NMDeviceAdsl *self = NM_DEVICE_ADSL(user_data);
+    int           carrier;
+    char *        path;
+
+    path    = g_strdup_printf("/sys/class/atm/%s/carrier",
+                           NM_ASSERT_VALID_PATH_COMPONENT(nm_device_get_iface(NM_DEVICE(self))));
+    carrier = (int) nm_platform_sysctl_get_int_checked(nm_device_get_platform(NM_DEVICE(self)),
+                                                       NMP_SYSCTL_PATHID_ABSOLUTE(path),
+                                                       10,
+                                                       0,
+                                                       1,
+                                                       -1);
+    g_free(path);
+
+    if (carrier != -1)
+        nm_device_set_carrier(NM_DEVICE(self), carrier);
+    return TRUE;
+}
+
+/*****************************************************************************/
+
+static void
+get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+    switch (prop_id) {
+    case PROP_ATM_INDEX:
+        g_value_set_int(value, NM_DEVICE_ADSL_GET_PRIVATE(object)->atm_index);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+static void
+set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+    switch (prop_id) {
+    case PROP_ATM_INDEX:
+        /* construct-only */
+        NM_DEVICE_ADSL_GET_PRIVATE(object)->atm_index = g_value_get_int(value);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+/*****************************************************************************/
+
+static void
+nm_device_adsl_init(NMDeviceAdsl *self)
+{}
+
+static void
+constructed(GObject *object)
+{
+    NMDeviceAdsl *       self = NM_DEVICE_ADSL(object);
+    NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE(self);
+
+    G_OBJECT_CLASS(nm_device_adsl_parent_class)->constructed(object);
+
+    priv->carrier_poll_id = g_timeout_add_seconds(5, carrier_update_cb, self);
+
+    _LOGD(LOGD_ADSL, "ATM device index %d", priv->atm_index);
+
+    g_return_if_fail(priv->atm_index >= 0);
+}
+
+NMDevice *
+nm_device_adsl_new(const char *udi, const char *iface, const char *driver, int atm_index)
+{
+    g_return_val_if_fail(udi != NULL, NULL);
+    g_return_val_if_fail(atm_index >= 0, NULL);
+
+    return g_object_new(NM_TYPE_DEVICE_ADSL,
+                        NM_DEVICE_UDI,
+                        udi,
+                        NM_DEVICE_IFACE,
+                        iface,
+                        NM_DEVICE_DRIVER,
+                        driver,
+                        NM_DEVICE_ADSL_ATM_INDEX,
+                        atm_index,
+                        NM_DEVICE_TYPE_DESC,
+                        "ADSL",
+                        NM_DEVICE_DEVICE_TYPE,
+                        NM_DEVICE_TYPE_ADSL,
+                        NULL);
+}
+
+static void
+dispose(GObject *object)
+{
+    adsl_cleanup(NM_DEVICE_ADSL(object));
+
+    nm_clear_g_source(&NM_DEVICE_ADSL_GET_PRIVATE(object)->carrier_poll_id);
+
+    G_OBJECT_CLASS(nm_device_adsl_parent_class)->dispose(object);
+}
+
+static const NMDBusInterfaceInfoExtended interface_info_device_adsl = {
+    .parent = NM_DEFINE_GDBUS_INTERFACE_INFO_INIT(
+        NM_DBUS_INTERFACE_DEVICE_ADSL,
+        .signals    = NM_DEFINE_GDBUS_SIGNAL_INFOS(&nm_signal_info_property_changed_legacy, ),
+        .properties = NM_DEFINE_GDBUS_PROPERTY_INFOS(
+            NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L("Carrier",
+                                                             "b",
+                                                             NM_DEVICE_CARRIER), ), ),
+    .legacy_property_changed = TRUE,
+};
+
+static void
+nm_device_adsl_class_init(NMDeviceAdslClass *klass)
+{
+    GObjectClass *     object_class      = G_OBJECT_CLASS(klass);
+    NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass);
+    NMDeviceClass *    device_class      = NM_DEVICE_CLASS(klass);
+
+    object_class->constructed  = constructed;
+    object_class->dispose      = dispose;
+    object_class->get_property = get_property;
+    object_class->set_property = set_property;
+
+    dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS(&interface_info_device_adsl);
+
+    device_class->connection_type_check_compatible = NM_SETTING_ADSL_SETTING_NAME;
+
+    device_class->get_generic_capabilities = get_generic_capabilities;
+
+    device_class->check_connection_compatible = check_connection_compatible;
+    device_class->complete_connection         = complete_connection;
+
+    device_class->act_stage2_config          = act_stage2_config;
+    device_class->act_stage3_ip_config_start = act_stage3_ip_config_start;
+    device_class->deactivate                 = deactivate;
+
+    obj_properties[PROP_ATM_INDEX] =
+        g_param_spec_int(NM_DEVICE_ADSL_ATM_INDEX,
+                         "",
+                         "",
+                         -1,
+                         G_MAXINT,
+                         -1,
+                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+
+    g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);
+}
diff --git a/src/core/devices/adsl/nm-device-adsl.h b/src/core/devices/adsl/nm-device-adsl.h
new file mode 100644
index 00000000..c5c18901
--- /dev/null
+++ b/src/core/devices/adsl/nm-device-adsl.h
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Author: Pantelis Koukousoulas <pktoss@gmail.com>
+ * Copyright (C) 2009 - 2011 Red Hat Inc.
+ */
+
+#ifndef __NETWORKMANAGER_DEVICE_ADSL_H__
+#define __NETWORKMANAGER_DEVICE_ADSL_H__
+
+#include "devices/nm-device.h"
+
+#define NM_TYPE_DEVICE_ADSL (nm_device_adsl_get_type())
+#define NM_DEVICE_ADSL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_DEVICE_ADSL, NMDeviceAdsl))
+#define NM_DEVICE_ADSL_CLASS(klass) \
+    (G_TYPE_CHECK_CLASS_CAST((klass), NM_TYPE_DEVICE_ADSL, NMDeviceAdslClass))
+#define NM_IS_DEVICE_ADSL(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), NM_TYPE_DEVICE_ADSL))
+#define NM_IS_DEVICE_ADSL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NM_TYPE_DEVICE_ADSL))
+#define NM_DEVICE_ADSL_GET_CLASS(obj) \
+    (G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_DEVICE_ADSL, NMDeviceAdslClass))
+
+#define NM_DEVICE_ADSL_ATM_INDEX "atm-index"
+
+typedef struct _NMDeviceAdsl      NMDeviceAdsl;
+typedef struct _NMDeviceAdslClass NMDeviceAdslClass;
+
+GType nm_device_adsl_get_type(void);
+
+NMDevice *nm_device_adsl_new(const char *udi, const char *iface, const char *driver, int atm_index);
+
+#endif /* NM_DEVICE_ADSL_H */