GHashTable *config,
GError **err);
+static gboolean impl_ppp_manager_set_ip6_config (NMPPPManager *manager,
+ GHashTable *config,
+ GError **err);
+
#include "nm-ppp-manager-glue.h"
static void _ppp_cleanup (NMPPPManager *manager);
enum {
STATE_CHANGED,
IP4_CONFIG,
+ IP6_CONFIG,
STATS,
LAST_SIGNAL
static void
nm_ppp_manager_init (NMPPPManager *manager)
{
+ NM_PPP_MANAGER_GET_PRIVATE (manager)->monitor_fd = -1;
}
static void
G_TYPE_STRING,
G_TYPE_OBJECT);
+ signals[IP6_CONFIG] =
+ g_signal_new ("ip6-config",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (NMPPPManagerClass, ip6_config),
+ NULL, NULL, NULL,
+ G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_OBJECT);
+
signals[STATS] =
g_signal_new ("stats",
G_OBJECT_CLASS_TYPE (object_class),
{
NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager);
+ /* already monitoring */
+ if (priv->monitor_fd >= 0)
+ return;
+
priv->monitor_fd = socket (AF_INET, SOCK_DGRAM, 0);
- if (priv->monitor_fd > 0) {
+ if (priv->monitor_fd >= 0) {
g_warn_if_fail (priv->monitor_id == 0);
if (priv->monitor_id)
g_source_remove (priv->monitor_id);
return TRUE;
}
+static gboolean
+set_ip_config_common (NMPPPManager *self,
+ GHashTable *hash,
+ const char *iface_prop,
+ guint32 *out_mtu)
+{
+ NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self);
+ NMConnection *connection;
+ NMSettingPPP *s_ppp;
+ GValue *val;
+
+ val = g_hash_table_lookup (hash, iface_prop);
+ if (!val || !G_VALUE_HOLDS_STRING (val)) {
+ nm_log_err (LOGD_PPP, "no interface received!");
+ return FALSE;
+ }
+ if (priv->ip_iface == NULL)
+ priv->ip_iface = g_value_dup_string (val);
+
+ /* Got successful IP config; obviously the secrets worked */
+ connection = nm_act_request_get_connection (priv->act_req);
+ g_assert (connection);
+ g_object_set_data (G_OBJECT (connection), PPP_MANAGER_SECRET_TRIES, NULL);
+
+ /* Get any custom MTU */
+ s_ppp = nm_connection_get_setting_ppp (connection);
+ if (s_ppp && out_mtu)
+ *out_mtu = nm_setting_ppp_get_mtu (s_ppp);
+
+ monitor_stats (self);
+ return TRUE;
+}
+
static gboolean
impl_ppp_manager_set_ip4_config (NMPPPManager *manager,
GHashTable *config_hash,
GError **err)
{
NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager);
- NMConnection *connection;
- NMSettingPPP *s_ppp;
NMIP4Config *config;
NMPlatformIP4Address address;
GValue *val;
int i;
+ guint32 mtu = 0;
- nm_log_info (LOGD_PPP, "PPP manager(IP Config Get) reply received.");
+ nm_log_info (LOGD_PPP, "PPP manager (IPv4 Config Get) reply received.");
remove_timeout_handler (manager);
nm_ip4_config_add_wins (config, g_array_index (wins, guint, i));
}
- val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_INTERFACE);
- if (!val || !G_VALUE_HOLDS_STRING (val)) {
- nm_log_err (LOGD_PPP, "no interface received!");
+ if (!set_ip_config_common (manager, config_hash, NM_PPP_IP4_CONFIG_INTERFACE, &mtu))
goto out;
+
+ if (mtu)
+ nm_ip4_config_set_mtu (config, mtu);
+
+ /* Push the IP4 config up to the device */
+ g_signal_emit (manager, signals[IP4_CONFIG], 0, priv->ip_iface, config);
+
+out:
+ g_object_unref (config);
+ return TRUE;
+}
+
+/* Converts the named Interface Identifier item to an IPv6 LL address and
+ * returns the IID.
+ */
+static gboolean
+iid_value_to_ll6_addr (GHashTable *hash,
+ const char *prop,
+ struct in6_addr *out_addr,
+ NMUtilsIPv6IfaceId *out_iid)
+{
+ GValue *val;
+ guint64 iid;
+
+ val = g_hash_table_lookup (hash, prop);
+ if (!val || !G_VALUE_HOLDS (val, G_TYPE_UINT64)) {
+ nm_log_dbg (LOGD_PPP, "pppd plugin property '%s' missing or not a uint64", prop);
+ return FALSE;
}
- priv->ip_iface = g_value_dup_string (val);
- /* Got successful IP4 config; obviously the secrets worked */
- connection = nm_act_request_get_connection (priv->act_req);
- g_assert (connection);
- g_object_set_data (G_OBJECT (connection), PPP_MANAGER_SECRET_TRIES, NULL);
+ iid = g_value_get_uint64 (val);
+ g_return_val_if_fail (iid != 0, FALSE);
- /* Merge in custom MTU */
- s_ppp = nm_connection_get_setting_ppp (connection);
- if (s_ppp) {
- guint32 mtu = nm_setting_ppp_get_mtu (s_ppp);
+ /* Construct an IPv6 LL address from the interface identifier. See
+ * http://tools.ietf.org/html/rfc4291#section-2.5.1 (IPv6) and
+ * http://tools.ietf.org/html/rfc5072#section-4.1 (IPv6 over PPP).
+ */
+ memset (out_addr->s6_addr, 0, sizeof (out_addr->s6_addr));
+ out_addr->s6_addr16[0] = htons (0xfe80);
+ memcpy (out_addr->s6_addr + 8, &iid, sizeof (iid));
+ if (out_iid)
+ nm_utils_ipv6_interface_identfier_get_from_addr (out_iid, out_addr);
+ return TRUE;
+}
+
+static gboolean
+impl_ppp_manager_set_ip6_config (NMPPPManager *manager,
+ GHashTable *hash,
+ GError **err)
+{
+ NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager);
+ NMIP6Config *config;
+ NMPlatformIP6Address addr;
+ struct in6_addr a;
+ NMUtilsIPv6IfaceId iid = NM_UTILS_IPV6_IFACE_ID_INIT;
+
+ nm_log_info (LOGD_PPP, "PPP manager (IPv6 Config Get) reply received.");
+
+ remove_timeout_handler (manager);
+
+ config = nm_ip6_config_new ();
+
+ memset (&addr, 0, sizeof (addr));
+ addr.plen = 64;
- if (mtu)
- nm_ip4_config_set_mtu (config, mtu);
+ if (iid_value_to_ll6_addr (hash, NM_PPP_IP6_CONFIG_PEER_IID, &a, NULL)) {
+ nm_ip6_config_set_gateway (config, &a);
+ addr.peer_address = a;
}
- /* Push the IP4 config up to the device */
- g_signal_emit (manager, signals[IP4_CONFIG], 0, priv->ip_iface, config);
+ if (iid_value_to_ll6_addr (hash, NM_PPP_IP6_CONFIG_OUR_IID, &addr.address, &iid)) {
+ nm_ip6_config_add_address (config, &addr);
- monitor_stats (manager);
+ if (set_ip_config_common (manager, hash, NM_PPP_IP6_CONFIG_INTERFACE, NULL)) {
+ /* Push the IPv6 config and interface identifier up to the device */
+ g_signal_emit (manager, signals[IP6_CONFIG], 0, priv->ip_iface, &iid, config);
+ }
+ } else
+ nm_log_err (LOGD_PPP, "invalid IPv6 address received!");
- out:
g_object_unref (config);
-
return TRUE;
}
priv->monitor_id = 0;
}
- if (priv->monitor_fd) {
+ if (priv->monitor_fd >= 0) {
/* Get the stats one last time */
monitor_cb (manager);
close (priv->monitor_fd);
- priv->monitor_fd = 0;
+ priv->monitor_fd = -1;
}
if (priv->ppp_timeout_handler) {
* Copyright (C) 2008 Red Hat, Inc.
*/
+#include <config.h>
#include <string.h>
#include <pppd/pppd.h>
#include <pppd/fsm.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <dlfcn.h>
#include <glib.h>
#include <glib-object.h>
#include <dbus/dbus-glib.h>
+#define INET6
+#include <pppd/eui64.h>
+#include <pppd/ipv6cp.h>
+
#include "NetworkManager.h"
#include "nm-pppd-plugin.h"
#include "nm-ppp-status.h"
val = g_slice_new0 (GValue);
g_value_init (val, G_TYPE_STRING);
g_value_set_string (val, str);
-
return val;
}
val = g_slice_new0 (GValue);
g_value_init (val, G_TYPE_UINT);
g_value_set_uint (val, i);
-
return val;
}
g_hash_table_insert (hash, NM_PPP_IP4_CONFIG_WINS, val);
}
- g_message ("nm-ppp-plugin: (%s): sending Ip4Config to NetworkManager...", __func__);
+ g_message ("nm-ppp-plugin: (%s): sending IPv4 config to NetworkManager...", __func__);
dbus_g_proxy_call_no_reply (proxy, "SetIp4Config",
DBUS_TYPE_G_MAP_OF_VARIANT, hash, G_TYPE_INVALID,
g_hash_table_destroy (hash);
}
+static GValue *
+eui64_to_gvalue (eui64_t eui)
+{
+ GValue *val;
+ guint64 iid;
+
+ G_STATIC_ASSERT (sizeof (iid) == sizeof (eui));
+
+ val = g_slice_new0 (GValue);
+ g_value_init (val, G_TYPE_UINT64);
+ memcpy (&iid, &eui, sizeof (eui));
+ g_value_set_uint64 (val, iid);
+ return val;
+}
+
+static void
+nm_ip6_up (void *data, int arg)
+{
+ ipv6cp_options *ho = &ipv6cp_hisoptions[0];
+ ipv6cp_options *go = &ipv6cp_gotoptions[0];
+ GHashTable *hash;
+
+ g_return_if_fail (DBUS_IS_G_PROXY (proxy));
+
+ g_message ("nm-ppp-plugin: (%s): ip6-up event", __func__);
+
+ hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, value_destroy);
+ g_hash_table_insert (hash, NM_PPP_IP6_CONFIG_INTERFACE, str_to_gvalue (ifname));
+ g_hash_table_insert (hash, NM_PPP_IP6_CONFIG_OUR_IID, eui64_to_gvalue (go->ourid));
+ g_hash_table_insert (hash, NM_PPP_IP6_CONFIG_PEER_IID, eui64_to_gvalue (ho->hisid));
+
+ /* DNS is done via DHCPv6 or router advertisements */
+
+ g_message ("nm-ppp-plugin: (%s): sending IPv6 config to NetworkManager...", __func__);
+
+ dbus_g_proxy_call_no_reply (proxy, "SetIp6Config",
+ DBUS_TYPE_G_MAP_OF_VARIANT, hash, G_TYPE_INVALID,
+ G_TYPE_INVALID);
+
+ g_hash_table_destroy (hash);
+}
+
static int
get_chap_check (void)
{
proxy = NULL;
}
+static void
+add_ip6_notifier (void)
+{
+ static struct notifier **notifier = NULL;
+ static gsize load_once = 0;
+
+ if (g_once_init_enter (&load_once)) {
+ void *handle = dlopen(NULL, RTLD_NOW | RTLD_GLOBAL);
+
+ if (handle) {
+ notifier = dlsym (handle, "ipv6_up_notifier");
+ dlclose (handle);
+ }
+ g_once_init_leave (&load_once, 1);
+ }
+ if (notifier)
+ add_notifier (notifier, nm_ip6_up, NULL);
+ else
+ g_message ("nm-ppp-plugin: no IPV6CP notifier support; IPv6 not available");
+}
+
int
plugin_init (void)
{
add_notifier (&phasechange, nm_phasechange, NULL);
add_notifier (&ip_up_notifier, nm_ip_up, NULL);
add_notifier (&exitnotify, nm_exit_notify, proxy);
+ add_ip6_notifier ();
return 0;
}