static void release_slave (NMDevice *device, NMDevice *slave, gboolean configure) { NMDeviceTeam *self = NM_DEVICE_TEAM (device); gboolean success, no_firmware = FALSE; if (configure) { success = nm_platform_link_release (NM_PLATFORM_GET, nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); if (success) _LOGI (LOGD_TEAM, "released team port %s", nm_device_get_ip_iface (slave)); else _LOGW (LOGD_TEAM, "failed to release team port %s", nm_device_get_ip_iface (slave)); /* Kernel team code "closes" the port when releasing it, (which clears * IFF_UP), so we must bring it back up here to ensure carrier changes and * other state is noticed by the now-released port. */ if (!nm_device_bring_up (slave, TRUE, &no_firmware)) _LOGW (LOGD_TEAM, "released team port %s could not be brought up", nm_device_get_ip_iface (slave)); } else _LOGI (LOGD_TEAM, "team port %s was released", nm_device_get_ip_iface (slave)); }
static void child_quit (NMDnsPlugin *plugin, gint status) { NMDnsDnsmasq *self = NM_DNS_DNSMASQ (plugin); gboolean failed = TRUE; int err; if (WIFEXITED (status)) { err = WEXITSTATUS (status); if (err) { _LOGW ("dnsmasq exited with error: %s (%d)", dm_exit_code_to_msg (err), err); } else failed = FALSE; } else if (WIFSTOPPED (status)) _LOGW ("dnsmasq stopped unexpectedly with signal %d", WSTOPSIG (status)); else if (WIFSIGNALED (status)) _LOGW ("dnsmasq died with signal %d", WTERMSIG (status)); else _LOGW ("dnsmasq died from an unknown cause"); unlink (CONFFILE); if (failed) g_signal_emit_by_name (self, NM_DNS_PLUGIN_FAILED); }
static void release_slave (NMDevice *device, NMDevice *slave, gboolean configure) { NMDeviceBond *self = NM_DEVICE_BOND (device); gboolean success, no_firmware = FALSE; if (configure) { success = nm_platform_link_release (nm_device_get_platform (device), nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); if (success) { _LOGI (LOGD_BOND, "released bond slave %s", nm_device_get_ip_iface (slave)); } else { _LOGW (LOGD_BOND, "failed to release bond slave %s", nm_device_get_ip_iface (slave)); } /* Kernel bonding code "closes" the slave when releasing it, (which clears * IFF_UP), so we must bring it back up here to ensure carrier changes and * other state is noticed by the now-released slave. */ if (!nm_device_bring_up (slave, TRUE, &no_firmware)) _LOGW (LOGD_BOND, "released bond slave could not be brought up."); } else { _LOGI (LOGD_BOND, "bond slave %s was released", nm_device_get_ip_iface (slave)); } }
static void child_quit (NMDnsPlugin *plugin, gint status) { NMDnsDnsmasq *self = NM_DNS_DNSMASQ (plugin); NMDnsDnsmasqPrivate *priv = NM_DNS_DNSMASQ_GET_PRIVATE (self); gboolean failed = TRUE; int err; if (WIFEXITED (status)) { err = WEXITSTATUS (status); if (err) { _LOGW ("dnsmasq exited with error: %s", nm_utils_dnsmasq_status_to_string (err, NULL, 0)); } else { _LOGD ("dnsmasq exited normally"); failed = FALSE; } } else if (WIFSTOPPED (status)) _LOGW ("dnsmasq stopped unexpectedly with signal %d", WSTOPSIG (status)); else if (WIFSIGNALED (status)) _LOGW ("dnsmasq died with signal %d", WTERMSIG (status)); else _LOGW ("dnsmasq died from an unknown cause"); priv->running = FALSE; if (failed) g_signal_emit_by_name (self, NM_DNS_PLUGIN_FAILED); }
static void bound4_handle (NMDhcpSystemd *self) { NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (self); const char *iface = nm_dhcp_client_get_iface (NM_DHCP_CLIENT (self)); sd_dhcp_lease *lease; NMIP4Config *ip4_config; GHashTable *options; GError *error = NULL; int r; r = sd_dhcp_client_get_lease (priv->client4, &lease); if (r < 0 || !lease) { _LOGW ("no lease!"); nm_dhcp_client_set_state (NM_DHCP_CLIENT (self), NM_DHCP_STATE_FAIL, NULL, NULL); return; } _LOGD ("lease available"); options = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free); ip4_config = lease_to_ip4_config (iface, nm_dhcp_client_get_ifindex (NM_DHCP_CLIENT (self)), lease, options, nm_dhcp_client_get_priority (NM_DHCP_CLIENT (self)), TRUE, &error); if (ip4_config) { const uint8_t *client_id = NULL; size_t client_id_len = 0; uint8_t type = 0; add_requests_to_options (options, dhcp4_requests); dhcp_lease_save (lease, priv->lease_file); sd_dhcp_client_get_client_id(priv->client4, &type, &client_id, &client_id_len); if (client_id) _save_client_id (self, type, client_id, client_id_len); nm_dhcp_client_set_state (NM_DHCP_CLIENT (self), NM_DHCP_STATE_BOUND, G_OBJECT (ip4_config), options); } else { _LOGW ("%s", error->message); nm_dhcp_client_set_state (NM_DHCP_CLIENT (self), NM_DHCP_STATE_FAIL, NULL, NULL); g_clear_error (&error); } g_hash_table_destroy (options); g_clear_object (&ip4_config); }
static void ppp_secrets_cb (NMActRequest *req, NMActRequestGetSecretsCallId call_id, NMSettingsConnection *settings_connection, /* unused (we pass NULL here) */ GError *error, gpointer user_data) { NMPPPManager *self = NM_PPP_MANAGER (user_data); NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); const char *username = NULL; const char *password = NULL; GError *local = NULL; NMConnection *applied_connection; g_return_if_fail (priv->pending_secrets_context != NULL); g_return_if_fail (req == priv->act_req); g_return_if_fail (call_id == priv->secrets_id); if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) goto out; if (error) { _LOGW ("%s", error->message); g_dbus_method_invocation_return_gerror (priv->pending_secrets_context, error); goto out; } applied_connection = nm_act_request_get_applied_connection (req); if (!extract_details_from_connection (applied_connection, priv->secrets_setting_name, &username, &password, &local)) { _LOGW ("%s", local->message); g_dbus_method_invocation_take_error (priv->pending_secrets_context, local); goto out; } /* This is sort of a hack but... * pppd plugin only ever needs username and password. Passing the full * connection there would mean some bloat: the plugin would need to link * against libnm just to parse this. So instead, let's just send what * it needs. */ g_dbus_method_invocation_return_value ( priv->pending_secrets_context, g_variant_new ("(ss)", username ? username : "", password ? password : "")); out: priv->pending_secrets_context = NULL; priv->secrets_id = NULL; priv->secrets_setting_name = NULL; }
static GObject* constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params) { GObject *object; GObjectClass *klass; NMDeviceOlpcMesh *self; NMDeviceWifiCapabilities caps; klass = G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class); object = klass->constructor (type, n_construct_params, construct_params); if (!object) return NULL; self = NM_DEVICE_OLPC_MESH (object); if (!nm_platform_wifi_get_capabilities (nm_device_get_ifindex (NM_DEVICE (self)), &caps)) { _LOGW (LOGD_HW | LOGD_OLPC, "failed to initialize WiFi driver"); g_object_unref (object); return NULL; } g_signal_connect (nm_manager_get (), "device-added", G_CALLBACK (device_added_cb), self); g_signal_connect (nm_manager_get (), "device-removed", G_CALLBACK (device_removed_cb), self); /* shorter timeout for mesh connectivity */ nm_device_set_dhcp_timeout (NM_DEVICE (self), 20); return object; }
static void teamd_process_watch_cb (GPid pid, gint status, gpointer user_data) { NMDeviceTeam *self = NM_DEVICE_TEAM (user_data); NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (self); NMDevice *device = NM_DEVICE (self); NMDeviceState state = nm_device_get_state (device); g_return_if_fail (priv->teamd_process_watch); _LOGD (LOGD_TEAM, "teamd died with status %d", status); priv->teamd_pid = 0; priv->teamd_process_watch = 0; /* If teamd quit within 5 seconds of starting, it's probably hosed * and will just die again, so fail the activation. */ if (priv->teamd_timeout && (state >= NM_DEVICE_STATE_PREPARE) && (state <= NM_DEVICE_STATE_ACTIVATED)) { _LOGW (LOGD_TEAM, "teamd process quit unexpectedly; failing activation"); teamd_cleanup (device, TRUE); nm_device_state_changed (device, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_TEAMD_CONTROL_FAILED); } }
static void release_slave (NMDevice *device, NMDevice *slave, gboolean configure) { NMDeviceBridge *self = NM_DEVICE_BRIDGE (device); gboolean success; if (configure) { success = nm_platform_link_release (NM_PLATFORM_GET, nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); if (success) { _LOGI (LOGD_BRIDGE, "detached bridge port %s", nm_device_get_ip_iface (slave)); } else { _LOGW (LOGD_BRIDGE, "failed to detach bridge port %s", nm_device_get_ip_iface (slave)); } } else { _LOGI (LOGD_BRIDGE, "bridge port %s was detached", nm_device_get_ip_iface (slave)); } }
static void update_connection (NMDevice *device, NMConnection *connection) { NMDeviceBridge *self = NM_DEVICE_BRIDGE (device); NMSettingBridge *s_bridge = nm_connection_get_setting_bridge (connection); int ifindex = nm_device_get_ifindex (device); const Option *option; if (!s_bridge) { s_bridge = (NMSettingBridge *) nm_setting_bridge_new (); nm_connection_add_setting (connection, (NMSetting *) s_bridge); } for (option = master_options; option->name; option++) { gs_free char *str = nm_platform_sysctl_master_get_option (NM_PLATFORM_GET, ifindex, option->sysname); int value; if (str) { value = strtol (str, NULL, 10); /* See comments in set_sysfs_uint() about centiseconds. */ if (option->user_hz_compensate) value /= 100; g_object_set (s_bridge, option->name, value, NULL); } else _LOGW (LOGD_BRIDGE, "failed to read bridge setting '%s'", option->sysname); } }
static void constructed (GObject *object) { NMFirewallManager *self = (NMFirewallManager *) object; NMFirewallManagerPrivate *priv = NM_FIREWALL_MANAGER_GET_PRIVATE (self); gs_free char *owner = NULL; gs_free_error GError *error = NULL; G_OBJECT_CLASS (nm_firewall_manager_parent_class)->constructed (object); priv->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, NULL, FIREWALL_DBUS_SERVICE, FIREWALL_DBUS_PATH, FIREWALL_DBUS_INTERFACE_ZONE, NULL, &error); if (priv->proxy) { g_signal_connect (priv->proxy, "notify::g-name-owner", G_CALLBACK (name_owner_changed), self); owner = g_dbus_proxy_get_name_owner (priv->proxy); priv->running = (owner != NULL); } else { _LOGW (NULL, "could not connect to system D-Bus (%s)", error->message); } _LOGD (NULL, "firewall constructed (%srunning)", priv->running ? "" : "not"); }
static void update_properties (NMDevice *device) { NMDeviceMacvlan *self = NM_DEVICE_MACVLAN (device); NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE (device); GObject *object = G_OBJECT (device); const NMPlatformLnkMacvlan *props; const NMPlatformLink *plink; props = nm_platform_link_get_lnk_macvlan (NM_PLATFORM_GET, nm_device_get_ifindex (device), &plink); if (!props) { _LOGW (LOGD_HW, "could not get macvlan properties"); return; } g_object_freeze_notify (object); if (priv->parent_ifindex != plink->parent) g_object_notify (object, NM_DEVICE_MACVLAN_PARENT); if (g_strcmp0 (priv->props.mode, props->mode) != 0) g_object_notify (object, NM_DEVICE_MACVLAN_MODE); if (priv->props.no_promisc != props->no_promisc) g_object_notify (object, NM_DEVICE_MACVLAN_NO_PROMISC); priv->parent_ifindex = plink->parent; priv->props = *props; g_object_thaw_notify (object); }
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 dnsmasq_update_done (GDBusProxy *proxy, GAsyncResult *res, gpointer user_data) { NMDnsDnsmasq *self; NMDnsDnsmasqPrivate *priv; gs_free_error GError *error = NULL; gs_unref_variant GVariant *response = NULL; response = g_dbus_proxy_call_finish (proxy, res, &error); if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) return; self = NM_DNS_DNSMASQ (user_data); priv = NM_DNS_DNSMASQ_GET_PRIVATE (self); if (!response) _LOGW ("dnsmasq update failed: %s", error->message); else { g_dbus_proxy_call (priv->dnsmasq, "ClearCache", NULL, G_DBUS_CALL_FLAGS_NONE, -1, priv->update_cancellable, (GAsyncReadyCallback) dnsmasq_clear_cache_done, self); } }
static void dhcp_event_cb (sd_dhcp_client *client, int event, gpointer user_data) { NMDhcpSystemd *self = NM_DHCP_SYSTEMD (user_data); NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (self); g_assert (priv->client4 == client); _LOGD ("client event %d", event); switch (event) { case SD_DHCP_CLIENT_EVENT_EXPIRED: nm_dhcp_client_set_state (NM_DHCP_CLIENT (user_data), NM_DHCP_STATE_EXPIRE, NULL, NULL); break; case SD_DHCP_CLIENT_EVENT_STOP: nm_dhcp_client_set_state (NM_DHCP_CLIENT (user_data), NM_DHCP_STATE_FAIL, NULL, NULL); break; case SD_DHCP_CLIENT_EVENT_RENEW: case SD_DHCP_CLIENT_EVENT_IP_CHANGE: case SD_DHCP_CLIENT_EVENT_IP_ACQUIRE: bound4_handle (self); break; default: _LOGW ("unhandled DHCP event %d", event); break; } }
static void dhcp6_event_cb (sd_dhcp6_client *client, int event, gpointer user_data) { NMDhcpSystemd *self = NM_DHCP_SYSTEMD (user_data); NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (self); g_assert (priv->client6 == client); _LOGD ("client event %d", event); switch (event) { case SD_DHCP6_CLIENT_EVENT_RETRANS_MAX: nm_dhcp_client_set_state (NM_DHCP_CLIENT (user_data), NM_DHCP_STATE_TIMEOUT, NULL, NULL); break; case SD_DHCP6_CLIENT_EVENT_RESEND_EXPIRE: case SD_DHCP6_CLIENT_EVENT_STOP: nm_dhcp_client_set_state (NM_DHCP_CLIENT (user_data), NM_DHCP_STATE_FAIL, NULL, NULL); break; case SD_DHCP6_CLIENT_EVENT_IP_ACQUIRE: case SD_DHCP6_CLIENT_EVENT_INFORMATION_REQUEST: bound6_handle (self); break; default: _LOGW ("unhandled event %d", event); break; } }
static gboolean component_added (NMDevice *device, GObject *component) { NMDeviceVlan *self = NM_DEVICE_VLAN (device); NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self); NMDevice *added_device; int parent_ifindex = -1; if (priv->parent) return FALSE; if (!NM_IS_DEVICE (component)) return FALSE; added_device = NM_DEVICE (component); if (!nm_platform_vlan_get_info (NM_PLATFORM_GET, nm_device_get_ifindex (device), &parent_ifindex, NULL)) { _LOGW (LOGD_VLAN, "failed to get VLAN interface info while checking added component."); return FALSE; } if ( parent_ifindex <= 0 || nm_device_get_ifindex (added_device) != parent_ifindex) return FALSE; nm_device_vlan_set_parent (self, added_device); /* Don't claim parent exclusively */ return FALSE; }
static void update_properties (NMDevice *device) { NMDeviceMacvlan *self = NM_DEVICE_MACVLAN (device); NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE (device); GObject *object = G_OBJECT (device); NMPlatformMacvlanProperties props; if (!nm_platform_macvlan_get_properties (NM_PLATFORM_GET, nm_device_get_ifindex (device), &props)) { _LOGW (LOGD_HW, "could not read macvlan properties"); return; } g_object_freeze_notify (object); if (priv->props.parent_ifindex != props.parent_ifindex) g_object_notify (object, NM_DEVICE_MACVLAN_PARENT); if (g_strcmp0 (priv->props.mode, props.mode) != 0) g_object_notify (object, NM_DEVICE_MACVLAN_MODE); if (priv->props.no_promisc != props.no_promisc) g_object_notify (object, NM_DEVICE_MACVLAN_NO_PROMISC); memcpy (&priv->props, &props, sizeof (NMPlatformMacvlanProperties)); g_object_thaw_notify (object); }
static char * plugin_get_hostname (SCPluginIfcfg *plugin) { shvarFile *network; char *hostname; gboolean ignore_localhost; if (g_file_get_contents (HOSTNAME_FILE, &hostname, NULL, NULL)) { g_strchomp (hostname); return hostname; } network = svOpenFile (SC_NETWORK_FILE, NULL); if (!network) { _LOGW ("Could not get hostname: failed to read " SC_NETWORK_FILE); return NULL; } hostname = svGetValue (network, "HOSTNAME", FALSE); ignore_localhost = svTrueValue (network, "NM_IGNORE_HOSTNAME_LOCALHOST", FALSE); if (ignore_localhost) { /* Ignore a default hostname ('localhost[6]' or 'localhost[6].localdomain[6]') * to preserve 'network' service behavior. */ if (hostname && !nm_utils_is_specific_hostname (hostname)) { g_free (hostname); hostname = NULL; } } svCloseFile (network); return hostname; }
static void dispatcher_done_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) { DispatchInfo *info = user_data; GVariant *ret; GVariantIter *results; GError *error = NULL; ret = _nm_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, G_VARIANT_TYPE ("(a(sus))"), &error); if (ret) { g_variant_get (ret, "(a(sus))", &results); dispatcher_results_process (info->request_id, info->action, results); g_variant_iter_free (results); g_variant_unref (ret); } else { if (_nm_dbus_error_has_name (error, "org.freedesktop.systemd1.LoadFailed")) { g_dbus_error_strip_remote_error (error); _LOGW ("(%u) failed to call dispatcher scripts: %s", info->request_id, error->message); } else { _LOGD ("(%u) failed to call dispatcher scripts: %s", info->request_id, error->message); } g_clear_error (&error); } if (info->callback) info->callback (info->request_id, info->user_data); dispatcher_info_cleanup (info); }
static void set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { NMConnectivity *self = NM_CONNECTIVITY (object); NMConnectivityPrivate *priv = NM_CONNECTIVITY_GET_PRIVATE (self); const char *uri, *response; guint interval; gboolean changed; switch (property_id) { case PROP_URI: uri = g_value_get_string (value); if (uri && !*uri) uri = NULL; changed = g_strcmp0 (uri, priv->uri) != 0; #if WITH_CONCHECK if (uri) { SoupURI *soup_uri = soup_uri_new (uri); if (!soup_uri || !SOUP_URI_VALID_FOR_HTTP (soup_uri)) { _LOGE ("invalid uri '%s' for connectivity check.", uri); uri = NULL; } if (uri && soup_uri && changed && soup_uri_get_scheme(soup_uri) == SOUP_URI_SCHEME_HTTPS) _LOGW ("use of HTTPS for connectivity checking is not reliable and is discouraged (URI: %s)", uri); if (soup_uri) soup_uri_free (soup_uri); } #endif if (changed) { g_free (priv->uri); priv->uri = g_strdup (uri); _reschedule_periodic_checks (self, TRUE); } break; case PROP_INTERVAL: interval = g_value_get_uint (value); if (priv->interval != interval) { priv->interval = interval; _reschedule_periodic_checks (self, TRUE); } break; case PROP_RESPONSE: response = g_value_get_string (value); if (g_strcmp0 (response, priv->response) != 0) { /* a response %NULL means, NM_CONFIG_DEFAULT_CONNECTIVITY_RESPONSE. Any other response * (including "") is accepted. */ g_free (priv->response); priv->response = g_strdup (response); _reschedule_periodic_checks (self, TRUE); } break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } }
static void helper_failed (GDBusProxy *proxy, const char *reason) { GError *err = NULL; _LOGW ("nm-openvpn-service-openvpn-helper did not receive a valid %s from openvpn", reason); if (!g_dbus_proxy_call_sync (proxy, "SetFailure", g_variant_new ("(s)", reason), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err)) { _LOGW ("Could not send failure information: %s", err->message); g_error_free (err); } exit (1); }
static void constructed (GObject *object) { NMDeviceVlan *self = NM_DEVICE_VLAN (object); NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self); int ifindex = nm_device_get_ifindex (NM_DEVICE (self)); int parent_ifindex = -1, itype; int vlan_id; if (G_OBJECT_CLASS (nm_device_vlan_parent_class)->constructed) G_OBJECT_CLASS (nm_device_vlan_parent_class)->constructed (object); if (!priv->parent) { _LOGE (LOGD_VLAN, "no parent specified."); priv->invalid = TRUE; return; } itype = nm_platform_link_get_type (ifindex); if (itype != NM_LINK_TYPE_VLAN) { _LOGE (LOGD_VLAN, "failed to get VLAN interface type."); priv->invalid = TRUE; return; } if (!nm_platform_vlan_get_info (ifindex, &parent_ifindex, &vlan_id)) { _LOGW (LOGD_VLAN, "failed to get VLAN interface info."); priv->invalid = TRUE; return; } if ( parent_ifindex < 0 || parent_ifindex != nm_device_get_ip_ifindex (priv->parent) || vlan_id < 0) { _LOGW (LOGD_VLAN, "VLAN parent ifindex (%d) or VLAN ID (%d) invalid.", parent_ifindex, priv->vlan_id); priv->invalid = TRUE; return; } priv->vlan_id = vlan_id; _LOGI (LOGD_HW | LOGD_VLAN, "VLAN ID %d with parent %s", priv->vlan_id, nm_device_get_iface (priv->parent)); }
static gboolean enslave_slave (NMDevice *device, NMDevice *slave, NMConnection *connection, gboolean configure) { NMDeviceTeam *self = NM_DEVICE_TEAM (device); NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (device); gboolean success = TRUE, no_firmware = FALSE; const char *slave_iface = nm_device_get_ip_iface (slave); NMSettingTeamPort *s_team_port; nm_device_master_check_slave_physical_port (device, slave, LOGD_TEAM); if (configure) { nm_device_take_down (slave, TRUE); s_team_port = nm_connection_get_setting_team_port (connection); if (s_team_port) { const char *config = nm_setting_team_port_get_config (s_team_port); if (config) { if (!priv->tdc) { _LOGW (LOGD_TEAM, "enslaved team port %s config not changed, not connected to teamd", slave_iface); } else { int err; char *sanitized_config; sanitized_config = g_strdelimit (g_strdup (config), "\r\n", ' '); err = teamdctl_port_config_update_raw (priv->tdc, slave_iface, sanitized_config); g_free (sanitized_config); if (err != 0) { _LOGE (LOGD_TEAM, "failed to update config for port %s (err=%d)", slave_iface, err); return FALSE; } } } } success = nm_platform_link_enslave (NM_PLATFORM_GET, nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); nm_device_bring_up (slave, TRUE, &no_firmware); if (!success) return FALSE; _LOGI (LOGD_TEAM, "enslaved team port %s", slave_iface); } else _LOGI (LOGD_TEAM, "team port %s was enslaved", slave_iface); g_object_notify (G_OBJECT (device), NM_DEVICE_TEAM_SLAVES); return TRUE; }
static void update_properties (NMDevice *device) { NMDeviceVxlan *self = NM_DEVICE_VXLAN (device); NMDeviceVxlanPrivate *priv = NM_DEVICE_VXLAN_GET_PRIVATE (device); GObject *object = G_OBJECT (device); NMPlatformVxlanProperties props; if (!nm_platform_vxlan_get_properties (NM_PLATFORM_GET, nm_device_get_ifindex (device), &props)) { _LOGW (LOGD_HW, "could not read vxlan properties"); return; } g_object_freeze_notify (object); if (priv->props.parent_ifindex != props.parent_ifindex) g_object_notify (object, NM_DEVICE_VXLAN_PARENT); if (priv->props.id != props.id) g_object_notify (object, NM_DEVICE_VXLAN_ID); if (priv->props.group != props.group) g_object_notify (object, NM_DEVICE_VXLAN_GROUP); if (priv->props.local != props.local) g_object_notify (object, NM_DEVICE_VXLAN_LOCAL); if (memcmp (&priv->props.group6, &props.group6, sizeof (props.group6)) != 0) g_object_notify (object, NM_DEVICE_VXLAN_GROUP); if (memcmp (&priv->props.local6, &props.local6, sizeof (props.local6)) != 0) g_object_notify (object, NM_DEVICE_VXLAN_LOCAL); if (priv->props.tos != props.tos) g_object_notify (object, NM_DEVICE_VXLAN_TOS); if (priv->props.ttl != props.ttl) g_object_notify (object, NM_DEVICE_VXLAN_TTL); if (priv->props.learning != props.learning) g_object_notify (object, NM_DEVICE_VXLAN_LEARNING); if (priv->props.ageing != props.ageing) g_object_notify (object, NM_DEVICE_VXLAN_AGEING); if (priv->props.limit != props.limit) g_object_notify (object, NM_DEVICE_VXLAN_LIMIT); if (priv->props.dst_port != props.dst_port) g_object_notify (object, NM_DEVICE_VXLAN_DST_PORT); if (priv->props.src_port_min != props.src_port_min) g_object_notify (object, NM_DEVICE_VXLAN_SRC_PORT_MIN); if (priv->props.src_port_max != props.src_port_max) g_object_notify (object, NM_DEVICE_VXLAN_SRC_PORT_MAX); if (priv->props.proxy != props.proxy) g_object_notify (object, NM_DEVICE_VXLAN_PROXY); if (priv->props.rsc != props.rsc) g_object_notify (object, NM_DEVICE_VXLAN_RSC); if (priv->props.l2miss != props.l2miss) g_object_notify (object, NM_DEVICE_VXLAN_L2MISS); if (priv->props.l3miss != props.l3miss) g_object_notify (object, NM_DEVICE_VXLAN_L3MISS); memcpy (&priv->props, &props, sizeof (NMPlatformVxlanProperties)); g_object_thaw_notify (object); }
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 *ppp_iface; req = nm_device_get_act_request (device); g_assert (req); connection = nm_act_request_get_applied_connection (req); g_assert (req); s_adsl = nm_connection_get_setting_adsl (connection); 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 NAS 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, "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); g_object_unref (priv->ppp_manager); priv->ppp_manager = NULL; *reason = NM_DEVICE_STATE_REASON_PPP_START_FAILED; } return ret; }
static void send_announcements (NMArpingManager *self, const char *mode_arg) { NMArpingManagerPrivate *priv = NM_ARPING_MANAGER_GET_PRIVATE (self); const char *argv[] = { NULL, mode_arg, "-q", "-I", NULL, "-c", "1", NULL, NULL }; int ip_arg = G_N_ELEMENTS (argv) - 2; GError *error = NULL; GHashTableIter iter; AddressInfo *info; argv[4] = nm_platform_link_get_name (NM_PLATFORM_GET, priv->ifindex); g_return_if_fail (argv[4]); argv[0] = nm_utils_find_helper ("arping", NULL, NULL); if (!argv[0]) { _LOGW ("arping could not be found; no ARPs will be sent"); return; } g_hash_table_iter_init (&iter, priv->addresses); while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &info)) { gs_free char *tmp_str = NULL; gboolean success; if (info->duplicate) continue; argv[ip_arg] = nm_utils_inet4_ntop (info->address, NULL); _LOGD ("run %s", (tmp_str = g_strjoinv (" ", (char **) argv))); success = g_spawn_async (NULL, (char **) argv, NULL, G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, NULL, &error); if (!success) { _LOGW ("could not send ARP for address %s: %s", argv[ip_arg], error->message); g_clear_error (&error); } } }
static gboolean br2684_create_iface (NMDeviceAdsl *self, NMSettingAdsl *s_adsl) { NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (self); struct atm_newif_br2684 ni; int err, fd, errsv; gboolean success = FALSE; guint num = 0; g_return_val_if_fail (s_adsl != NULL, FALSE); fd = socket (PF_ATMPVC, SOCK_DGRAM, 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 (num < 10000) { memset (&ni.ifname, 0, sizeof (ni.ifname)); g_snprintf (ni.ifname, sizeof (ni.ifname), "nas%d", num); err = ioctl (fd, ATM_NEWBACKENDIF, &ni); if (err == 0) { set_nas_iface (self, -1, ni.ifname); _LOGI (LOGD_ADSL, "using NAS interface %s (%d)", priv->nas_ifname, priv->nas_ifindex); success = TRUE; break; } else { errsv = errno; if (errsv == -EEXIST) { /* Try again */ num++; } else { _LOGW (LOGD_ADSL, "failed to create br2684 interface (%d)", errsv); break; } } } close (fd); return success; }
static void _dbus_connection_closed (GDBusConnection *connection, gboolean remote_peer_vanished, GError *error, gpointer user_data) { _LOGW ("dbus: %s bus closed", IFCFGRH1_DBUS_SERVICE_NAME); _dbus_clear (SETTINGS_PLUGIN_IFCFG (user_data)); /* Retry or recover? */ }
static gboolean set_bond_attr (NMDevice *device, const char *attr, const char *value) { NMDeviceBond *self = NM_DEVICE_BOND (device); gboolean ret; int ifindex = nm_device_get_ifindex (device); ret = nm_platform_sysctl_master_set_option (nm_device_get_platform(device), ifindex, attr, value); if (!ret) _LOGW (LOGD_HW, "failed to set bonding attribute '%s' to '%s'", attr, value); return ret; }