void nm_ip6_manager_begin_addrconf (NMIP6Manager *manager, int ifindex) { NMIP6ManagerPrivate *priv; NMIP6Device *device; CallbackInfo *info; g_return_if_fail (NM_IS_IP6_MANAGER (manager)); g_return_if_fail (ifindex > 0); priv = NM_IP6_MANAGER_GET_PRIVATE (manager); device = (NMIP6Device *) g_hash_table_lookup (priv->devices, GINT_TO_POINTER (ifindex)); g_return_if_fail (device != NULL); nm_log_info (LOGD_IP6, "Activation (%s) Beginning IP6 addrconf.", device->iface); device->addrconf_complete = FALSE; device->ra_flags = 0; /* Set up a timeout on the transaction to kill it after the timeout */ info = callback_info_new (device, FALSE); device->finish_addrconf_id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, NM_IP6_TIMEOUT, finish_addrconf, info, (GDestroyNotify) g_free); /* Bounce IPv6 on the interface to ensure the kernel will start looking for * new RAs; there doesn't seem to be a better way to do this right now. */ if (device->target_state >= NM_IP6_DEVICE_GOT_ADDRESS) { nm_utils_do_sysctl (device->disable_ip6_path, "1"); /* Wait until all existing IPv6 addresses have been removed from the link, * to ensure they don't confuse our IPv6 addressing state machine. */ wait_for_no_addresses (manager, device); nm_utils_do_sysctl (device->disable_ip6_path, "0"); } device->ip6flags_poll_id = g_timeout_add_seconds (1, poll_ip6_flags, priv->monitor); /* Kick off the initial IPv6 flags request */ nm_netlink_monitor_request_ip6_info (priv->monitor, NULL); /* Sync flags, etc, from netlink; this will also notice if the * device is already fully configured and schedule the * ADDRCONF_COMPLETE signal in that case. */ nm_ip6_device_sync_from_netlink (device); }
static void nm_ip6_device_destroy (NMIP6Device *device) { g_return_if_fail (device != NULL); /* reset the saved IPv6 value */ if (device->disable_ip6_save_valid) { nm_utils_do_sysctl (device->disable_ip6_path, device->disable_ip6_save ? "1\n" : "0\n"); } if (device->finish_addrconf_id) g_source_remove (device->finish_addrconf_id); if (device->config_changed_id) g_source_remove (device->config_changed_id); g_free (device->iface); if (device->rdnss_servers) g_array_free (device->rdnss_servers, TRUE); if (device->rdnss_timeout_id) g_source_remove (device->rdnss_timeout_id); if (device->dnssl_domains) g_array_free (device->dnssl_domains, TRUE); if (device->dnssl_timeout_id) g_source_remove (device->dnssl_timeout_id); if (device->ip6flags_poll_id) g_source_remove (device->ip6flags_poll_id); g_slice_free (NMIP6Device, device); }
gboolean nm_ip6_manager_prepare_interface (NMIP6Manager *manager, int ifindex, const guint8 *hwaddr, guint hwaddr_len, NMSettingIP6Config *s_ip6, const char *accept_ra_path) { NMIP6ManagerPrivate *priv; NMIP6Device *device; const char *method = NULL; g_return_val_if_fail (NM_IS_IP6_MANAGER (manager), FALSE); g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (hwaddr != NULL, FALSE); g_return_val_if_fail (hwaddr_len > 0, FALSE); g_return_val_if_fail (hwaddr_len <= NM_UTILS_HWADDR_LEN_MAX, FALSE); priv = NM_IP6_MANAGER_GET_PRIVATE (manager); device = nm_ip6_device_new (manager, ifindex, hwaddr, hwaddr_len); g_return_val_if_fail (device != NULL, FALSE); g_return_val_if_fail ( strchr (device->iface, '/') == NULL && strcmp (device->iface, "all") != 0 && strcmp (device->iface, "default") != 0, FALSE); if (s_ip6) method = nm_setting_ip6_config_get_method (s_ip6); if (!method) method = NM_SETTING_IP6_CONFIG_METHOD_AUTO; /* Establish target state and turn router advertisement acceptance on or off */ if (!strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL)) { device->target_state = NM_IP6_DEVICE_GOT_LINK_LOCAL; nm_utils_do_sysctl (accept_ra_path, "0"); } else { device->target_state = NM_IP6_DEVICE_GOT_ADDRESS; nm_utils_do_sysctl (accept_ra_path, "2"); } return TRUE; }
static void set_sysfs_uint (const char *iface, GObject *obj, const char *obj_prop, const char *dir, const char *sysfs_prop, gboolean default_if_zero, gboolean user_hz_compensate) { char *path, *s; GParamSpec *pspec; GValue val = { 0 }; guint32 uval = 0; pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (obj), obj_prop); g_return_if_fail (pspec != NULL); /* Get the property's value */ g_value_init (&val, G_PARAM_SPEC_VALUE_TYPE (pspec)); g_object_get_property (obj, obj_prop, &val); if (G_VALUE_HOLDS_BOOLEAN (&val)) uval = g_value_get_boolean (&val) ? 1 : 0; else if (G_VALUE_HOLDS_UINT (&val)) { uval = g_value_get_uint (&val); /* zero means "unspecified" for some NM properties but isn't in the * allowed kernel range, so reset the property to the default value. */ if (default_if_zero && uval == 0) { g_value_unset (&val); g_value_init (&val, G_PARAM_SPEC_VALUE_TYPE (pspec)); g_param_value_set_default (pspec, &val); uval = g_value_get_uint (&val); } } else g_assert_not_reached (); g_value_unset (&val); /* Linux kernel bridge interfaces use 'centiseconds' for time-based values. * In reality it's not centiseconds, but depends on HZ and USER_HZ, which * is almost always works out to be a multiplier of 100, so we can assume * centiseconds. See clock_t_to_jiffies(). */ if (user_hz_compensate) uval *= 100; path = g_strdup_printf ("/sys/class/net/%s/%s/%s", iface, dir, sysfs_prop); s = g_strdup_printf ("%u", uval); /* FIXME: how should failure be handled? */ nm_utils_do_sysctl (path, s); g_free (path); g_free (s); }
static NMActStageReturn real_act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason) { NMActRequest *req; NMConnection *connection; NMSettingInfiniband *s_infiniband; const char *transport_mode; char *mode_path, *mode_value; gboolean ok; g_return_val_if_fail (reason != NULL, NM_ACT_STAGE_RETURN_FAILURE); req = nm_device_get_act_request (dev); g_return_val_if_fail (req != NULL, NM_ACT_STAGE_RETURN_FAILURE); connection = nm_act_request_get_connection (req); g_assert (connection); s_infiniband = nm_connection_get_setting_infiniband (connection); g_assert (s_infiniband); transport_mode = nm_setting_infiniband_get_transport_mode (s_infiniband); mode_path = g_strdup_printf ("/sys/class/net/%s/mode", nm_device_get_iface (dev)); if (!g_file_test (mode_path, G_FILE_TEST_EXISTS)) { g_free (mode_path); if (!strcmp (transport_mode, "datagram")) return NM_ACT_STAGE_RETURN_SUCCESS; else { *reason = NM_DEVICE_STATE_REASON_INFINIBAND_MODE; return NM_ACT_STAGE_RETURN_FAILURE; } } mode_value = g_strdup_printf ("%s\n", transport_mode); ok = nm_utils_do_sysctl (mode_path, mode_value); g_free (mode_value); g_free (mode_path); if (!ok) { *reason = NM_DEVICE_STATE_REASON_CONFIG_FAILED; return NM_ACT_STAGE_RETURN_FAILURE; } return NM_DEVICE_CLASS (nm_device_infiniband_parent_class)->act_stage1_prepare (dev, reason); }