
For the finale, this is the libnm-glib and nmcli part of the support, with this you can now make a full pppoatm connection from NetworkManager by configuring it in system scope in a keyfile. As an example, here is mine: (password and username snipped for obvious reasons) [connection] id=MYISP uuid=34d04e69-fdd9-4231-af2c-25ed1f34dc1e type=adsl timestamp=1304621332 [adsl] username=user@myisp.com password=mypassword vpi=8 vci=35 encapsulation=vcmux protocol=pppoa [ipv6] method=ignore [ipv4] method=auto Extract from logs: NetworkManager[29155]: <info> Activation (ueagle-atm0) starting connection 'MYISP' NetworkManager[29155]: <info> (ueagle-atm0): device state change: disconnected -> prepare (reason 'none') [30 40 0] NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 1 of 5 (Device Prepare) scheduled... NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 1 of 5 (Device Prepare) started... NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 2 of 5 (Device Configure) scheduled... NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 1 of 5 (Device Prepare) complete. NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 2 of 5 (Device Configure) starting... NetworkManager[29155]: <info> (ueagle-atm0): device state change: prepare -> config (reason 'none') [40 50 0] NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 2 of 5 (Device Configure) successful. NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 3 of 5 (IP Configure Start) scheduled. NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 2 of 5 (Device Configure) complete. NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 3 of 5 (IP Configure Start) started... NetworkManager[29155]: <info> (ueagle-atm0): device state change: config -> ip-config (reason 'none') [50 70 0] NetworkManager[29155]: <info> starting PPP connection NetworkManager[29155]: <debug> [1304671146.590156] [nm-ppp-manager.c:1047] nm_ppp_manager_start(): command line: /usr/sbin/pppd nodetach lock nodefaultroute user user@myisp.com plugin pppoatm.so 8.35 noipdefault noauth usepeerdns lcp-echo-failure 0 lcp-echo-interval 0 ipparam /org/freedesktop/NetworkManager/PPP/0 plugin /opt/nmadsl/lib/pppd/2.4.5/nm-pppd-plugin.so NetworkManager[29155]: <info> pppd started with pid 29175 NetworkManager[29155]: <debug> [1304671146.591235] [NetworkManagerUtils.c:816] nm_utils_get_proc_sys_net_value(): (ueagle-atm0): error reading /proc/sys/net/ipv6/conf/ueagle-atm0/accept_ra: (4) Failed to open file '/proc/sys/net/ipv6/conf/ueagle-atm0/accept_ra': No such file or directory NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 3 of 5 (IP Configure Start) complete. Plugin pppoatm.so loaded. Plugin /opt/nmadsl/lib/pppd/2.4.5/nm-pppd-plugin.so loaded. ** Message: nm-ppp-plugin: (plugin_init): initializing ** Message: nm-ppp-plugin: (nm_phasechange): status 3 / phase 'serial connection' NetworkManager[29155]: <debug> [1304671146.612937] [nm-udev-manager.c:621] handle_uevent(): UDEV event: action 'add' subsys 'net' device 'ppp0' NetworkManager[29155]: <debug> [1304671146.613134] [nm-udev-manager.c:525] net_add(): ignoring interface with type 512 NetworkManager[29155]: <debug> [1304671146.617308] [nm-netlink-monitor.c:117] link_msg_handler(): netlink link message: iface idx 35 flags 0x1090 Using interface ppp0 Connect: ppp0 <--> 8.35 ** Message: nm-ppp-plugin: (nm_phasechange): status 5 / phase 'establish' ** Message: nm-ppp-plugin: (nm_phasechange): status 6 / phase 'authenticate' ** Message: nm-ppp-plugin: (get_credentials): passwd-hook, requesting credentials... NetworkManager[29155]: <debug> [1304671149.639511] [nm-agent-manager.c:1044] nm_agent_manager_get_secrets(): Secrets requested for connection /org/freedesktop/NetworkManager/Settings/0 (adsl) NetworkManager[29155]: <debug> [1304671149.639684] [nm-settings-connection.c:717] nm_settings_connection_get_secrets(): (34d04e69-fdd9-4231-af2c-25ed1f34dc1e/adsl:1) secrets requested flags 0x1 hint 'password' NetworkManager[29155]: <debug> [1304671149.640950] [nm-agent-manager.c:959] get_start(): (0x9b4ad10/adsl) system settings secrets sufficient NetworkManager[29155]: <debug> [1304671149.641332] [nm-settings-connection.c:573] agent_secrets_done_cb(): (34d04e69-fdd9-4231-af2c-25ed1f34dc1e/adsl:1) existing secrets returned NetworkManager[29155]: <debug> [1304671149.641541] [nm-settings-connection.c:579] agent_secrets_done_cb(): (34d04e69-fdd9-4231-af2c-25ed1f34dc1e/adsl:1) secrets request completed NetworkManager[29155]: <debug> [1304671149.643074] [nm-settings-connection.c:618] agent_secrets_done_cb(): (34d04e69-fdd9-4231-af2c-25ed1f34dc1e/adsl:1) new agent secrets processed ** Message: nm-ppp-plugin: (get_credentials): got credentials from NetworkManager PAP authentication succeeded ** Message: nm-ppp-plugin: (nm_phasechange): status 8 / phase 'network' local IP address 94.70.90.201 remote IP address 80.106.108.12 primary DNS address 195.170.0.1 secondary DNS address 195.170.2.2 ** Message: nm-ppp-plugin: (nm_phasechange): status 9 / phase 'running' ** Message: nm-ppp-plugin: (nm_ip_up): ip-up event ** Message: nm-ppp-plugin: (nm_ip_up): sending Ip4Config to NetworkManager... NetworkManager[29155]: <debug> [1304671150.607440] [nm-netlink-monitor.c:117] link_msg_handler(): netlink link message: iface idx 35 flags 0x110D1 NetworkManager[29155]: <info> PPP manager(IP Config Get) reply received. NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 4 of 5 (IP4 Configure Get) scheduled... NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 4 of 5 (IP4 Configure Get) started... NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 5 of 5 (IP Configure Commit) scheduled... NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 4 of 5 (IP4 Configure Get) complete. NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 5 of 5 (IP Configure Commit) started... NetworkManager[29155]: <debug> [1304671150.608918] [nm-system.c:222] sync_addresses(): (ppp0): syncing addresses (family 2) NetworkManager[29155]: <info> (ueagle-atm0): device state change: ip-config -> activated (reason 'none') [70 100 0] NetworkManager[29155]: <info> Policy set 'MYISP' (ppp0) as default for IPv4 routing and DNS. NetworkManager[29155]: <info> Activation (ueagle-atm0) successful, device activated. NetworkManager[29155]: <info> Activation (ueagle-atm0) Stage 5 of 5 (IP Configure Commit) complete. Signed-off-by: Pantelis Koukousoulas <pktoss@gmail.com>
246 lines
6.4 KiB
C
246 lines
6.4 KiB
C
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
|
/*
|
|
* libnm_glib -- Access network status & information from glib applications
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the
|
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
* Boston, MA 02110-1301 USA.
|
|
*
|
|
* author: Pantelis Koukousoulas <pktoss@gmail.com>
|
|
* Copyright 2009 - 2011 Red Hat, Inc.
|
|
*/
|
|
|
|
#include "nm-device-adsl.h"
|
|
#include "nm-device-private.h"
|
|
#include "nm-object-private.h"
|
|
|
|
#include "nm-setting-adsl.h"
|
|
|
|
#include <string.h>
|
|
|
|
G_DEFINE_TYPE (NMDeviceAdsl, nm_device_adsl, NM_TYPE_DEVICE)
|
|
|
|
#define NM_DEVICE_ADSL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_ADSL, NMDeviceAdslPrivate))
|
|
|
|
typedef struct {
|
|
DBusGProxy *proxy;
|
|
|
|
gboolean carrier;
|
|
|
|
gboolean disposed;
|
|
} NMDeviceAdslPrivate;
|
|
|
|
enum {
|
|
PROP_0,
|
|
PROP_CARRIER,
|
|
LAST_PROP
|
|
};
|
|
#define DBUS_PROP_CARRIER "Carrier"
|
|
|
|
/**
|
|
* nm_device_adsl_error_quark:
|
|
*
|
|
* Registers an error quark for #NMDeviceAdsl if necessary.
|
|
*
|
|
* Returns: the error quark used for #NMDeviceAdsl errors.
|
|
**/
|
|
GQuark
|
|
nm_device_adsl_error_quark (void)
|
|
{
|
|
static GQuark quark = 0;
|
|
|
|
if (G_UNLIKELY (quark == 0))
|
|
quark = g_quark_from_static_string ("nm-device-adsl-error-quark");
|
|
return quark;
|
|
}
|
|
|
|
/**
|
|
* nm_device_adsl_new:
|
|
* @connection: the #DBusGConnection
|
|
* @path: the DBus object path of the device
|
|
*
|
|
* Creates a new #NMDeviceAdsl.
|
|
*
|
|
* Returns: a new device
|
|
**/
|
|
GObject *
|
|
nm_device_adsl_new (DBusGConnection *connection, const char *path)
|
|
{
|
|
GObject *device;
|
|
|
|
g_return_val_if_fail (connection != NULL, NULL);
|
|
g_return_val_if_fail (path != NULL, NULL);
|
|
|
|
device = g_object_new (NM_TYPE_DEVICE_ADSL,
|
|
NM_OBJECT_DBUS_CONNECTION, connection,
|
|
NM_OBJECT_DBUS_PATH, path,
|
|
NULL);
|
|
_nm_object_ensure_inited (NM_OBJECT (device));
|
|
return device;
|
|
}
|
|
|
|
/**
|
|
* nm_device_adsl_get_carrier:
|
|
* @device: a #NMDeviceAdsl
|
|
*
|
|
* Whether the device has carrier.
|
|
*
|
|
* Returns: %TRUE if the device has carrier
|
|
**/
|
|
gboolean
|
|
nm_device_adsl_get_carrier (NMDeviceAdsl *device)
|
|
{
|
|
g_return_val_if_fail (NM_IS_DEVICE_ADSL (device), FALSE);
|
|
|
|
_nm_object_ensure_inited (NM_OBJECT (device));
|
|
return NM_DEVICE_ADSL_GET_PRIVATE (device)->carrier;
|
|
}
|
|
|
|
static gboolean
|
|
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
|
|
{
|
|
NMSettingConnection *s_con;
|
|
NMSettingAdsl *s_adsl;
|
|
const char *ctype;
|
|
|
|
s_con = nm_connection_get_setting_connection (connection);
|
|
g_assert (s_con);
|
|
|
|
ctype = nm_setting_connection_get_connection_type (s_con);
|
|
if (strcmp (ctype, NM_SETTING_ADSL_SETTING_NAME) != 0) {
|
|
g_set_error (error, NM_DEVICE_ADSL_ERROR, NM_DEVICE_ADSL_ERROR_NOT_ADSL_CONNECTION,
|
|
"The connection was not an ADSL connection.");
|
|
return FALSE;
|
|
}
|
|
|
|
s_adsl = nm_connection_get_setting_adsl (connection);
|
|
if (!s_adsl) {
|
|
g_set_error (error, NM_DEVICE_ADSL_ERROR, NM_DEVICE_ADSL_ERROR_INVALID_ADSL_CONNECTION,
|
|
"The connection was not a valid ADSL connection.");
|
|
return FALSE;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
/******************************************************************/
|
|
|
|
static void
|
|
nm_device_adsl_init (NMDeviceAdsl *device)
|
|
{
|
|
_nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_ADSL);
|
|
}
|
|
|
|
static void
|
|
register_properties (NMDeviceAdsl *device)
|
|
{
|
|
NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (device);
|
|
const NMPropertiesInfo property_info[] = {
|
|
{ NM_DEVICE_ADSL_CARRIER, &priv->carrier },
|
|
{ NULL },
|
|
};
|
|
|
|
_nm_object_register_properties (NM_OBJECT (device),
|
|
priv->proxy,
|
|
property_info);
|
|
}
|
|
|
|
static void
|
|
constructed (GObject *object)
|
|
{
|
|
NMDeviceAdslPrivate *priv;
|
|
|
|
G_OBJECT_CLASS (nm_device_adsl_parent_class)->constructed (object);
|
|
|
|
priv = NM_DEVICE_ADSL_GET_PRIVATE (object);
|
|
|
|
priv->proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (NM_OBJECT (object)),
|
|
NM_DBUS_SERVICE,
|
|
nm_object_get_path (NM_OBJECT (object)),
|
|
NM_DBUS_INTERFACE_DEVICE_ADSL);
|
|
|
|
register_properties (NM_DEVICE_ADSL (object));
|
|
}
|
|
|
|
static void
|
|
dispose (GObject *object)
|
|
{
|
|
NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (object);
|
|
|
|
if (priv->disposed) {
|
|
G_OBJECT_CLASS (nm_device_adsl_parent_class)->dispose (object);
|
|
return;
|
|
}
|
|
|
|
priv->disposed = TRUE;
|
|
|
|
g_object_unref (priv->proxy);
|
|
|
|
G_OBJECT_CLASS (nm_device_adsl_parent_class)->dispose (object);
|
|
}
|
|
|
|
static void
|
|
finalize (GObject *object)
|
|
{
|
|
G_OBJECT_CLASS (nm_device_adsl_parent_class)->finalize (object);
|
|
}
|
|
|
|
static void
|
|
get_property (GObject *object,
|
|
guint prop_id,
|
|
GValue *value,
|
|
GParamSpec *pspec)
|
|
{
|
|
NMDeviceAdsl *device = NM_DEVICE_ADSL (object);
|
|
|
|
switch (prop_id) {
|
|
case PROP_CARRIER:
|
|
g_value_set_boolean (value, nm_device_adsl_get_carrier (device));
|
|
break;
|
|
default:
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
break;
|
|
}
|
|
}
|
|
|
|
static void
|
|
nm_device_adsl_class_init (NMDeviceAdslClass *adsl_class)
|
|
{
|
|
GObjectClass *object_class = G_OBJECT_CLASS (adsl_class);
|
|
NMDeviceClass *device_class = NM_DEVICE_CLASS (adsl_class);
|
|
|
|
g_type_class_add_private (object_class, sizeof (NMDeviceAdslPrivate));
|
|
|
|
/* virtual methods */
|
|
object_class->constructed = constructed;
|
|
object_class->dispose = dispose;
|
|
object_class->finalize = finalize;
|
|
object_class->get_property = get_property;
|
|
device_class->connection_compatible = connection_compatible;
|
|
|
|
/* properties */
|
|
/**
|
|
* NMDeviceAdsl:carrier:
|
|
*
|
|
* Whether the device has carrier.
|
|
**/
|
|
g_object_class_install_property
|
|
(object_class, PROP_CARRIER,
|
|
g_param_spec_boolean (NM_DEVICE_ADSL_CARRIER,
|
|
"Carrier",
|
|
"Carrier",
|
|
FALSE,
|
|
G_PARAM_READABLE));
|
|
}
|