static void dump_device (NMDevice *device) { const char *str; NMDeviceState state; str = nm_device_get_iface (device); g_print ("Interface: %s\n", str); str = nm_device_get_udi (device); g_print ("Udi: %s\n", str); str = nm_device_get_driver (device); g_print ("Driver: %s\n", str); str = nm_device_get_vendor (device); g_print ("Vendor: %s\n", str); str = nm_device_get_product (device); g_print ("Product: %s\n", str); state = nm_device_get_state (device); g_print ("State: %d\n", state); if (state == NM_DEVICE_STATE_ACTIVATED) dump_ip4_config (nm_device_get_ip4_config (device)); if (NM_IS_DEVICE_ETHERNET (device)) dump_wired (NM_DEVICE_ETHERNET (device)); else if (NM_IS_DEVICE_WIFI (device)) dump_wireless (NM_DEVICE_WIFI (device)); dump_dhcp4_config (nm_device_get_dhcp4_config (device)); }
static void fill_device_props (NMDevice *device, GVariantBuilder *dev_builder, GVariantBuilder *proxy_builder, GVariantBuilder *ip4_builder, GVariantBuilder *ip6_builder, GVariant **dhcp4_props, GVariant **dhcp6_props) { NMProxyConfig *proxy_config; NMIP4Config *ip4_config; NMIP6Config *ip6_config; NMDhcp4Config *dhcp4_config; NMDhcp6Config *dhcp6_config; /* If the action is for a VPN, send the VPN's IP interface instead of the device's */ g_variant_builder_add (dev_builder, "{sv}", NMD_DEVICE_PROPS_IP_INTERFACE, g_variant_new_string (nm_device_get_ip_iface (device))); g_variant_builder_add (dev_builder, "{sv}", NMD_DEVICE_PROPS_INTERFACE, g_variant_new_string (nm_device_get_iface (device))); g_variant_builder_add (dev_builder, "{sv}", NMD_DEVICE_PROPS_TYPE, g_variant_new_uint32 (nm_device_get_device_type (device))); g_variant_builder_add (dev_builder, "{sv}", NMD_DEVICE_PROPS_STATE, g_variant_new_uint32 (nm_device_get_state (device))); if (nm_exported_object_is_exported (NM_EXPORTED_OBJECT (device))) g_variant_builder_add (dev_builder, "{sv}", NMD_DEVICE_PROPS_PATH, g_variant_new_object_path (nm_exported_object_get_path (NM_EXPORTED_OBJECT (device)))); proxy_config = nm_device_get_proxy_config (device); if (proxy_config) dump_proxy_to_props (proxy_config, proxy_builder); ip4_config = nm_device_get_ip4_config (device); if (ip4_config) dump_ip4_to_props (ip4_config, ip4_builder); ip6_config = nm_device_get_ip6_config (device); if (ip6_config) dump_ip6_to_props (ip6_config, ip6_builder); dhcp4_config = nm_device_get_dhcp4_config (device); if (dhcp4_config) *dhcp4_props = nm_dhcp4_config_get_options (dhcp4_config); dhcp6_config = nm_device_get_dhcp6_config (device); if (dhcp6_config) *dhcp6_props = nm_dhcp6_config_get_options (dhcp6_config); }
static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { NMDevice *device = NM_DEVICE (object); switch (prop_id) { case PROP_UDI: g_value_set_string (value, nm_device_get_udi (device)); break; case PROP_INTERFACE: g_value_set_string (value, nm_device_get_iface (device)); break; case PROP_DRIVER: g_value_set_string (value, nm_device_get_driver (device)); break; case PROP_CAPABILITIES: g_value_set_uint (value, nm_device_get_capabilities (device)); break; case PROP_MANAGED: g_value_set_boolean (value, nm_device_get_managed (device)); break; case PROP_IP4_CONFIG: g_value_set_object (value, nm_device_get_ip4_config (device)); break; case PROP_DHCP4_CONFIG: g_value_set_object (value, nm_device_get_dhcp4_config (device)); break; case PROP_IP6_CONFIG: g_value_set_object (value, nm_device_get_ip6_config (device)); break; case PROP_STATE: g_value_set_uint (value, nm_device_get_state (device)); break; case PROP_PRODUCT: g_value_set_string (value, nm_device_get_product (device)); break; case PROP_VENDOR: g_value_set_string (value, nm_device_get_vendor (device)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void update_system_hostname (NMPolicy *policy, NMDevice *best4, NMDevice *best6) { char *configured_hostname = NULL; NMActRequest *best_req4 = NULL; NMActRequest *best_req6 = NULL; const char *dhcp_hostname, *p; g_return_if_fail (policy != NULL); if (policy->lookup) { hostname_thread_kill (policy->lookup); policy->lookup = NULL; } /* Hostname precedence order: * * 1) a configured hostname (from system-settings) * 2) automatic hostname from the default device's config (DHCP, VPN, etc) * 3) the original hostname when NM started * 4) reverse-DNS of the best device's IPv4 address * */ /* Try a persistent hostname first */ g_object_get (G_OBJECT (policy->manager), NM_MANAGER_HOSTNAME, &configured_hostname, NULL); if (configured_hostname) { _set_hostname (policy, TRUE, configured_hostname, "from system configuration"); g_free (configured_hostname); return; } /* Try automatically determined hostname from the best device's IP config */ if (!best4) best4 = get_best_ip4_device (policy->manager, &best_req4); if (!best6) best6 = get_best_ip6_device (policy->manager, &best_req6); if (!best4 && !best6) { /* No best device; fall back to original hostname or if there wasn't * one, 'localhost.localdomain' */ _set_hostname (policy, TRUE, policy->orig_hostname, "no default device"); return; } if (best4) { NMDHCP4Config *dhcp4_config; /* Grab a hostname out of the device's DHCP4 config */ dhcp4_config = nm_device_get_dhcp4_config (best4); if (dhcp4_config) { p = dhcp_hostname = nm_dhcp4_config_get_option (dhcp4_config, "host_name"); if (dhcp_hostname && strlen (dhcp_hostname)) { /* Sanity check; strip leading spaces */ while (*p) { if (!isblank (*p++)) { _set_hostname (policy, TRUE, dhcp_hostname, "from DHCPv4"); return; } } nm_log_warn (LOGD_DNS, "DHCPv4-provided hostname '%s' looks invalid; ignoring it", dhcp_hostname); } } } else if (best6) { NMDHCP6Config *dhcp6_config; /* Grab a hostname out of the device's DHCP4 config */ dhcp6_config = nm_device_get_dhcp6_config (best6); if (dhcp6_config) { p = dhcp_hostname = nm_dhcp6_config_get_option (dhcp6_config, "host_name"); if (dhcp_hostname && strlen (dhcp_hostname)) { /* Sanity check; strip leading spaces */ while (*p) { if (!isblank (*p++)) { _set_hostname (policy, TRUE, dhcp_hostname, "from DHCPv6"); return; } } nm_log_warn (LOGD_DNS, "DHCPv6-provided hostname '%s' looks invalid; ignoring it", dhcp_hostname); } } } /* If no automatically-configured hostname, try using the hostname from * when NM started up. */ if (policy->orig_hostname) { _set_hostname (policy, TRUE, policy->orig_hostname, "from system startup"); return; } /* No configured hostname, no automatically determined hostname, and no * bootup hostname. Start reverse DNS of the current IPv4 or IPv6 address. */ if (best4) { NMIP4Config *ip4_config; NMIP4Address *addr4; ip4_config = nm_device_get_ip4_config (best4); if ( !ip4_config || (nm_ip4_config_get_num_nameservers (ip4_config) == 0) || (nm_ip4_config_get_num_addresses (ip4_config) == 0)) { /* No valid IP4 config (!!); fall back to localhost.localdomain */ _set_hostname (policy, TRUE, NULL, "no IPv4 config"); return; } addr4 = nm_ip4_config_get_address (ip4_config, 0); g_assert (addr4); /* checked for > 1 address above */ /* Start the hostname lookup thread */ policy->lookup = hostname4_thread_new (nm_ip4_address_get_address (addr4), lookup_callback, policy); } else if (best6) { NMIP6Config *ip6_config; NMIP6Address *addr6; ip6_config = nm_device_get_ip6_config (best6); if ( !ip6_config || (nm_ip6_config_get_num_nameservers (ip6_config) == 0) || (nm_ip6_config_get_num_addresses (ip6_config) == 0)) { /* No valid IP6 config (!!); fall back to localhost.localdomain */ _set_hostname (policy, TRUE, NULL, "no IPv6 config"); return; } addr6 = nm_ip6_config_get_address (ip6_config, 0); g_assert (addr6); /* checked for > 1 address above */ /* Start the hostname lookup thread */ policy->lookup = hostname6_thread_new (nm_ip6_address_get_address (addr6), lookup_callback, policy); } if (!policy->lookup) { /* Fall back to 'localhost.localdomain' */ _set_hostname (policy, TRUE, NULL, "error starting hostname thread"); } }