static NMActStageReturn act_stage2_config (NMDevice *device, NMDeviceStateReason *out_reason) { NMDeviceAdsl *self = NM_DEVICE_ADSL (device); NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; NMSettingAdsl *s_adsl; const char *protocol; g_assert (out_reason); s_adsl = nm_connection_get_setting_adsl (nm_device_get_applied_connection (device)); g_assert (s_adsl); protocol = nm_setting_adsl_get_protocol (s_adsl); _LOGD (LOGD_ADSL, "using ADSL protocol '%s'", protocol); if (g_strcmp0 (protocol, NM_SETTING_ADSL_PROTOCOL_PPPOE) == 0) { /* PPPoE needs RFC2684 bridging before we can do PPP over it */ ret = br2684_create_iface (self, s_adsl, out_reason); } else if (g_strcmp0 (protocol, NM_SETTING_ADSL_PROTOCOL_PPPOA) == 0) { /* PPPoA doesn't need anything special */ ret = NM_ACT_STAGE_RETURN_SUCCESS; } else _LOGW (LOGD_ADSL, "unhandled ADSL protocol '%s'", protocol); return ret; }
static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { NMSettingAdsl *setting = NM_SETTING_ADSL (object); switch (prop_id) { case PROP_USERNAME: g_value_set_string (value, nm_setting_adsl_get_username (setting)); break; case PROP_PASSWORD: g_value_set_string (value, nm_setting_adsl_get_password (setting)); break; case PROP_PASSWORD_FLAGS: g_value_set_uint (value, nm_setting_adsl_get_password_flags (setting)); break; case PROP_PROTOCOL: g_value_set_string (value, nm_setting_adsl_get_protocol (setting)); break; case PROP_ENCAPSULATION: g_value_set_string (value, nm_setting_adsl_get_encapsulation (setting)); break; case PROP_VPI: g_value_set_uint (value, nm_setting_adsl_get_vpi (setting)); break; case PROP_VCI: g_value_set_uint (value, nm_setting_adsl_get_vci (setting)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static NMActStageReturn act_stage3_ip4_config_start (NMDevice *device, NMIP4Config **out_config, NMDeviceStateReason *reason) { NMDeviceAdsl *self = NM_DEVICE_ADSL (device); NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (self); NMConnection *connection; NMSettingAdsl *s_adsl; NMActRequest *req; GError *err = NULL; NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; const char *iface = nm_device_get_iface (device); const char *ppp_iface; req = nm_device_get_act_request (device); g_assert (req); connection = nm_act_request_get_connection (req); g_assert (req); s_adsl = nm_connection_get_setting_adsl (connection); g_assert (s_adsl); /* PPPoE uses the NAS inteface, not the ATM interface */ if (g_strcmp0 (nm_setting_adsl_get_protocol (s_adsl), NM_SETTING_ADSL_PROTOCOL_PPPOE) == 0) { g_assert (priv->nas_ifname); ppp_iface = priv->nas_ifname; nm_log_dbg (LOGD_ADSL, "(%s): starting PPPoE on NAS interface %s", iface, priv->nas_ifname); } else { ppp_iface = iface; nm_log_dbg (LOGD_ADSL, "(%s): starting PPPoA", iface); } priv->ppp_manager = nm_ppp_manager_new (ppp_iface); if (nm_ppp_manager_start (priv->ppp_manager, req, nm_setting_adsl_get_username (s_adsl), 30, &err)) { g_signal_connect (priv->ppp_manager, "state-changed", G_CALLBACK (ppp_state_changed), self); g_signal_connect (priv->ppp_manager, "ip4-config", G_CALLBACK (ppp_ip4_config), self); ret = NM_ACT_STAGE_RETURN_POSTPONE; } else { nm_log_warn (LOGD_ADSL, "(%s): PPP failed to start: %s", iface, err->message); g_error_free (err); g_object_unref (priv->ppp_manager); priv->ppp_manager = NULL; *reason = NM_DEVICE_STATE_REASON_PPP_START_FAILED; } return ret; }
static NMActStageReturn act_stage2_config (NMDevice *device, NMDeviceStateReason *out_reason) { NMDeviceAdsl *self = NM_DEVICE_ADSL (device); NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (self); NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; NMSettingAdsl *s_adsl; const char *protocol; g_assert (out_reason); s_adsl = nm_connection_get_setting_adsl (nm_device_get_connection (device)); g_assert (s_adsl); protocol = nm_setting_adsl_get_protocol (s_adsl); nm_log_dbg (LOGD_ADSL, "(%s): using ADSL protocol '%s'", nm_device_get_iface (device), protocol); if (g_strcmp0 (protocol, NM_SETTING_ADSL_PROTOCOL_PPPOE) == 0) { /* PPPoE needs RFC2684 bridging before we can do PPP over it */ if (!br2684_create_iface (self, s_adsl)) { *out_reason = NM_DEVICE_STATE_REASON_BR2684_FAILED; goto done; } /* Set up the VCC */ if (!br2684_assign_vcc (self, s_adsl)) { *out_reason = NM_DEVICE_STATE_REASON_BR2684_FAILED; goto done; } /* Watch for the 'nas' interface going away */ priv->lost_link_id = g_signal_connect (nm_platform_get (), "link-removed", G_CALLBACK (lost_link), self); nm_log_dbg (LOGD_ADSL, "(%s): ATM setup successful", nm_device_get_iface (device)); /* otherwise we're good for stage3 */ nm_platform_link_set_up (priv->nas_ifindex); ret = NM_ACT_STAGE_RETURN_SUCCESS; } else if (g_strcmp0 (protocol, NM_SETTING_ADSL_PROTOCOL_PPPOA) == 0) { /* PPPoA doesn't need anything special */ ret = NM_ACT_STAGE_RETURN_SUCCESS; } else { nm_log_warn (LOGD_ADSL, "(%s): unhandled ADSL protocol '%s'", nm_device_get_iface (device), protocol); } done: return ret; }
static NMActStageReturn act_stage3_ip4_config_start (NMDevice *device, NMIP4Config **out_config, NMDeviceStateReason *reason) { NMDeviceAdsl *self = NM_DEVICE_ADSL (device); NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (self); NMSettingAdsl *s_adsl; NMActRequest *req; GError *err = NULL; NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; const char *ppp_iface; req = nm_device_get_act_request (device); g_assert (req); s_adsl = (NMSettingAdsl *) nm_device_get_applied_setting (device, NM_TYPE_SETTING_ADSL); g_assert (s_adsl); /* PPPoE uses the NAS interface, not the ATM interface */ if (g_strcmp0 (nm_setting_adsl_get_protocol (s_adsl), NM_SETTING_ADSL_PROTOCOL_PPPOE) == 0) { g_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_new (ppp_iface); if (nm_ppp_manager_start (priv->ppp_manager, req, nm_setting_adsl_get_username (s_adsl), 30, &err)) { g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_STATE_CHANGED, G_CALLBACK (ppp_state_changed), self); g_signal_connect (priv->ppp_manager, "ip4-config", G_CALLBACK (ppp_ip4_config), self); ret = NM_ACT_STAGE_RETURN_POSTPONE; } else { _LOGW (LOGD_ADSL, "PPP failed to start: %s", err->message); g_error_free (err); nm_exported_object_clear_and_unexport (&priv->ppp_manager); *reason = NM_DEVICE_STATE_REASON_PPP_START_FAILED; } return ret; }
static gboolean check_connection_compatible (NMDevice *device, NMConnection *connection) { NMSettingAdsl *s_adsl; const char *protocol; if (!NM_DEVICE_CLASS (nm_device_adsl_parent_class)->check_connection_compatible (device, connection)) return FALSE; if (!nm_connection_is_type (connection, NM_SETTING_ADSL_SETTING_NAME)) return FALSE; s_adsl = nm_connection_get_setting_adsl (connection); if (!s_adsl) return FALSE; /* FIXME: we don't yet support IPoATM */ protocol = nm_setting_adsl_get_protocol (s_adsl); if (g_strcmp0 (protocol, NM_SETTING_ADSL_PROTOCOL_IPOATM) == 0) return FALSE; return TRUE; }
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; if (!nm_connection_is_type (connection, NM_SETTING_ADSL_SETTING_NAME)) { g_set_error (error, NM_ADSL_ERROR, NM_ADSL_ERROR_CONNECTION_NOT_ADSL, "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_ADSL_ERROR, NM_ADSL_ERROR_CONNECTION_INVALID, "The connection was not a valid ADSL connection."); return FALSE; } /* FIXME: we don't yet support IPoATM */ protocol = nm_setting_adsl_get_protocol (s_adsl); if (g_strcmp0 (protocol, NM_SETTING_ADSL_PROTOCOL_IPOATM) == 0) { g_set_error (error, NM_ADSL_ERROR, NM_ADSL_ERROR_CONNECTION_INVALID, "IPoATM connections are not yet supported."); return FALSE; } return TRUE; }
static NMCmdLine * create_pppd_cmd_line (NMPPPManager *self, NMSettingPpp *setting, NMSettingPppoe *pppoe, NMSettingAdsl *adsl, const char *ppp_name, GError **err) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); const char *pppd_binary = NULL; NMCmdLine *cmd; gboolean ppp_debug; g_return_val_if_fail (setting != NULL, NULL); pppd_binary = nm_utils_find_helper ("pppd", NULL, err); if (!pppd_binary) return NULL; /* Create pppd command line */ cmd = nm_cmd_line_new (); nm_cmd_line_add_string (cmd, pppd_binary); nm_cmd_line_add_string (cmd, "nodetach"); nm_cmd_line_add_string (cmd, "lock"); /* NM handles setting the default route */ nm_cmd_line_add_string (cmd, "nodefaultroute"); /* Allow IPv6 to be configured by IPV6CP */ nm_cmd_line_add_string (cmd, "ipv6"); nm_cmd_line_add_string (cmd, ","); ppp_debug = !!getenv ("NM_PPP_DEBUG"); if (nm_logging_enabled (LOGL_DEBUG, LOGD_PPP)) ppp_debug = TRUE; if (ppp_debug) nm_cmd_line_add_string (cmd, "debug"); if (ppp_name) { nm_cmd_line_add_string (cmd, "user"); nm_cmd_line_add_string (cmd, ppp_name); } if (pppoe) { char *dev_str; const char *pppoe_service; nm_cmd_line_add_string (cmd, "plugin"); nm_cmd_line_add_string (cmd, "rp-pppoe.so"); dev_str = g_strdup_printf ("nic-%s", priv->parent_iface); nm_cmd_line_add_string (cmd, dev_str); g_free (dev_str); pppoe_service = nm_setting_pppoe_get_service (pppoe); if (pppoe_service) { nm_cmd_line_add_string (cmd, "rp_pppoe_service"); nm_cmd_line_add_string (cmd, pppoe_service); } } else if (adsl) { const gchar *protocol = nm_setting_adsl_get_protocol (adsl); if (!strcmp (protocol, NM_SETTING_ADSL_PROTOCOL_PPPOA)) { guint32 vpi = nm_setting_adsl_get_vpi (adsl); guint32 vci = nm_setting_adsl_get_vci (adsl); const char *encaps = nm_setting_adsl_get_encapsulation (adsl); gchar *vpivci; nm_cmd_line_add_string (cmd, "plugin"); nm_cmd_line_add_string (cmd, "pppoatm.so"); vpivci = g_strdup_printf("%d.%d", vpi, vci); nm_cmd_line_add_string (cmd, vpivci); g_free (vpivci); if (g_strcmp0 (encaps, NM_SETTING_ADSL_ENCAPSULATION_LLC) == 0) nm_cmd_line_add_string (cmd, "llc-encaps"); else /*if (g_strcmp0 (encaps, NM_SETTING_ADSL_ENCAPSULATION_VCMUX) == 0)*/ nm_cmd_line_add_string (cmd, "vc-encaps"); } else if (!strcmp (protocol, NM_SETTING_ADSL_PROTOCOL_PPPOE)) { nm_cmd_line_add_string (cmd, "plugin"); nm_cmd_line_add_string (cmd, "rp-pppoe.so"); nm_cmd_line_add_string (cmd, priv->parent_iface); } nm_cmd_line_add_string (cmd, "noipdefault"); } else { nm_cmd_line_add_string (cmd, priv->parent_iface); /* Don't send some random address as the local address */ nm_cmd_line_add_string (cmd, "noipdefault"); } if (nm_setting_ppp_get_baud (setting)) nm_cmd_line_add_int (cmd, nm_setting_ppp_get_baud (setting)); /* noauth by default, because we certainly don't have any information * with which to verify anything the peer gives us if we ask it to * authenticate itself, which is what 'auth' really means. */ nm_cmd_line_add_string (cmd, "noauth"); if (nm_setting_ppp_get_refuse_eap (setting)) nm_cmd_line_add_string (cmd, "refuse-eap"); if (nm_setting_ppp_get_refuse_pap (setting)) nm_cmd_line_add_string (cmd, "refuse-pap"); if (nm_setting_ppp_get_refuse_chap (setting)) nm_cmd_line_add_string (cmd, "refuse-chap"); if (nm_setting_ppp_get_refuse_mschap (setting)) nm_cmd_line_add_string (cmd, "refuse-mschap"); if (nm_setting_ppp_get_refuse_mschapv2 (setting)) nm_cmd_line_add_string (cmd, "refuse-mschap-v2"); if (nm_setting_ppp_get_nobsdcomp (setting)) nm_cmd_line_add_string (cmd, "nobsdcomp"); if (nm_setting_ppp_get_no_vj_comp (setting)) nm_cmd_line_add_string (cmd, "novj"); if (nm_setting_ppp_get_nodeflate (setting)) nm_cmd_line_add_string (cmd, "nodeflate"); if (nm_setting_ppp_get_require_mppe (setting)) nm_cmd_line_add_string (cmd, "require-mppe"); if (nm_setting_ppp_get_require_mppe_128 (setting)) nm_cmd_line_add_string (cmd, "require-mppe-128"); if (nm_setting_ppp_get_mppe_stateful (setting)) nm_cmd_line_add_string (cmd, "mppe-stateful"); if (nm_setting_ppp_get_crtscts (setting)) nm_cmd_line_add_string (cmd, "crtscts"); /* Always ask for DNS, we don't have to use them if the connection * overrides the returned servers. */ nm_cmd_line_add_string (cmd, "usepeerdns"); if (nm_setting_ppp_get_mru (setting)) { nm_cmd_line_add_string (cmd, "mru"); nm_cmd_line_add_int (cmd, nm_setting_ppp_get_mru (setting)); } if (nm_setting_ppp_get_mtu (setting)) { nm_cmd_line_add_string (cmd, "mtu"); nm_cmd_line_add_int (cmd, nm_setting_ppp_get_mtu (setting)); } nm_cmd_line_add_string (cmd, "lcp-echo-failure"); nm_cmd_line_add_int (cmd, nm_setting_ppp_get_lcp_echo_failure (setting)); nm_cmd_line_add_string (cmd, "lcp-echo-interval"); nm_cmd_line_add_int (cmd, nm_setting_ppp_get_lcp_echo_interval (setting)); /* Avoid pppd to exit if no traffic going through */ nm_cmd_line_add_string (cmd, "idle"); nm_cmd_line_add_int (cmd, 0); nm_cmd_line_add_string (cmd, "ipparam"); nm_cmd_line_add_string (cmd, nm_exported_object_get_path (NM_EXPORTED_OBJECT (self))); nm_cmd_line_add_string (cmd, "plugin"); nm_cmd_line_add_string (cmd, NM_PPPD_PLUGIN); return cmd; }