static void
get_property (GObject *object, guint prop_id,
		    GValue *value, GParamSpec *pspec)
{
	NMSettingIP4Config *setting = NM_SETTING_IP4_CONFIG (object);
	NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);

	switch (prop_id) {
	case PROP_METHOD:
		g_value_set_string (value, nm_setting_ip4_config_get_method (setting));
		break;
	case PROP_DNS:
		g_value_set_boxed (value, priv->dns);
		break;
	case PROP_DNS_SEARCH:
		g_value_set_boxed (value, priv->dns_search);
		break;
	case PROP_ADDRESSES:
		nm_utils_ip4_addresses_to_gvalue (priv->addresses, value);
		break;
	case PROP_ROUTES:
		nm_utils_ip4_routes_to_gvalue (priv->routes, value);
		break;
	case PROP_IGNORE_AUTO_ROUTES:
		g_value_set_boolean (value, nm_setting_ip4_config_get_ignore_auto_routes (setting));
		break;
	case PROP_IGNORE_AUTO_DNS:
		g_value_set_boolean (value, nm_setting_ip4_config_get_ignore_auto_dns (setting));
		break;
	case PROP_DHCP_CLIENT_ID:
		g_value_set_string (value, nm_setting_ip4_config_get_dhcp_client_id (setting));
		break;
	case PROP_DHCP_SEND_HOSTNAME:
		g_value_set_boolean (value, nm_setting_ip4_config_get_dhcp_send_hostname (setting));
		break;
	case PROP_DHCP_HOSTNAME:
		g_value_set_string (value, nm_setting_ip4_config_get_dhcp_hostname (setting));
		break;
	case PROP_NEVER_DEFAULT:
		g_value_set_boolean (value, priv->never_default);
		break;
	case PROP_MAY_FAIL:
		g_value_set_boolean (value, priv->may_fail);
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}
예제 #2
0
/* Caller owns a reference to the NMDHCPClient on return */
NMDHCPClient *
nm_dhcp_manager_start_ip4 (NMDHCPManager *self,
                           const char *iface,
                           const char *uuid,
                           NMSettingIP4Config *s_ip4,
                           guint32 timeout,
                           guint8 *dhcp_anycast_addr)
{
	NMDHCPManagerPrivate *priv;
	NMDHCPClient *client = NULL;
	const char *hostname = NULL;

	g_return_val_if_fail (self, NULL);
	g_return_val_if_fail (NM_IS_DHCP_MANAGER (self), NULL);

	priv = NM_DHCP_MANAGER_GET_PRIVATE (self);

	if (s_ip4) {
		const char *method = nm_setting_ip4_config_get_method (s_ip4);

		if (method) {
			/* Method must be 'auto' */
			g_return_val_if_fail (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0, NULL);
		}

		/* If we're asked to send the hostname to DHCP server, and the hostname
		 * isn't specified, and a hostname provider is registered: use that
		 */
		if (nm_setting_ip4_config_get_dhcp_send_hostname (s_ip4)) {
			hostname = nm_setting_ip4_config_get_dhcp_hostname (s_ip4);

			/* If we're supposed to send the hostname to the DHCP server but
			 * the user didn't specify one, use the persistent hostname.
			 */
			if (!hostname && priv->hostname_provider) {
				hostname = nm_hostname_provider_get_hostname (priv->hostname_provider);
				if (   hostname
				    && (!strcmp (hostname, "localhost.localdomain") ||
				        !strcmp (hostname, "localhost6.localdomain6")))
					hostname = NULL;
			}
		}
	}

	client = client_start (self, iface, uuid, FALSE, s_ip4, NULL, timeout, dhcp_anycast_addr, hostname, FALSE);

	return client;
}
static void
test_basic_import (NMVpnPluginUiInterface *plugin, const char *dir)
{
	NMConnection *connection;
	NMSettingConnection *s_con;
	NMSettingIP4Config *s_ip4;
	NMSettingVPN *s_vpn;
	NMIP4Route *route;
	struct in_addr tmp;
	const char *expected_id = "Basic VPN";
	const char *expected_route1_dest = "10.0.0.0";
	const char *expected_route1_gw = "0.0.0.0";
	const char *expected_route2_dest = "172.16.0.0";
	const char *expected_route2_gw = "0.0.0.0";

	connection = get_basic_connection ("basic-import", plugin, dir, "basic.pcf");
	ASSERT (connection != NULL, "basic-import", "failed to import connection");

	/* Connection setting */
	s_con = nm_connection_get_setting_connection (connection);
	ASSERT (s_con != NULL,
	        "basic-import", "missing 'connection' setting");

	ASSERT (strcmp (nm_setting_connection_get_id (s_con), expected_id) == 0,
	        "basic-import", "unexpected connection ID");

	ASSERT (nm_setting_connection_get_uuid (s_con) == NULL,
	        "basic-import", "unexpected valid UUID");

	/* IP4 setting */
	s_ip4 = nm_connection_get_setting_ip4_config (connection);
	ASSERT (s_ip4 != NULL,
	        "basic-import", "missing 'ip4-config' setting");

	ASSERT (nm_setting_ip4_config_get_num_addresses (s_ip4) == 0,
	        "basic-import", "unexpected addresses");

	ASSERT (nm_setting_ip4_config_get_never_default (s_ip4) == TRUE,
	        "basic-import", "never-default unexpectedly FALSE");

	ASSERT (nm_setting_ip4_config_get_method (s_ip4) == NULL,
	        "basic-import", "unexpected IPv4 method");

	ASSERT (nm_setting_ip4_config_get_dhcp_client_id (s_ip4) == NULL,
	        "basic-import", "unexpected valid DHCP client ID");

	ASSERT (nm_setting_ip4_config_get_dhcp_hostname (s_ip4) == NULL,
	        "basic-import", "unexpected valid DHCP hostname");

	ASSERT (nm_setting_ip4_config_get_num_dns_searches (s_ip4) == 0,
	        "basic-import", "unexpected DNS searches");

	ASSERT (nm_setting_ip4_config_get_num_dns (s_ip4) == 0,
	        "basic-import", "unexpected DNS servers");

	ASSERT (nm_setting_ip4_config_get_num_routes (s_ip4) == 2,
	        "basic-import", "unexpected number of routes");

	/* Route #1 */
	route = nm_setting_ip4_config_get_route (s_ip4, 0);
	ASSERT (inet_pton (AF_INET, expected_route1_dest, &tmp) > 0,
	        "basic-import", "couldn't convert expected route destination #1");
	ASSERT (nm_ip4_route_get_dest (route) == tmp.s_addr,
	        "basic-import", "unexpected route #1 destination");

	ASSERT (inet_pton (AF_INET, expected_route1_gw, &tmp) > 0,
	        "basic-import", "couldn't convert expected route next hop #1");
	ASSERT (nm_ip4_route_get_next_hop (route) == tmp.s_addr,
	        "basic-import", "unexpected route #1 next hop");

	ASSERT (nm_ip4_route_get_prefix (route) == 8,
	        "basic-import", "unexpected route #1 prefix");
	ASSERT (nm_ip4_route_get_metric (route) == 0,
	        "basic-import", "unexpected route #1 metric");

	/* Route #2 */
	route = nm_setting_ip4_config_get_route (s_ip4, 1);
	ASSERT (inet_pton (AF_INET, expected_route2_dest, &tmp) > 0,
	        "basic-import", "couldn't convert expected route destination #2");
	ASSERT (nm_ip4_route_get_dest (route) == tmp.s_addr,
	        "basic-import", "unexpected route #2 destination");

	ASSERT (inet_pton (AF_INET, expected_route2_gw, &tmp) > 0,
	        "basic-import", "couldn't convert expected route next hop #2");
	ASSERT (nm_ip4_route_get_next_hop (route) == tmp.s_addr,
	        "basic-import", "unexpected route #2 next hop");

	ASSERT (nm_ip4_route_get_prefix (route) == 16,
	        "basic-import", "unexpected route #2 prefix");
	ASSERT (nm_ip4_route_get_metric (route) == 0,
	        "basic-import", "unexpected route #2 metric");

	/* VPN setting */
	s_vpn = nm_connection_get_setting_vpn (connection);
	ASSERT (s_vpn != NULL,
	        "basic-import", "missing 'vpn' setting");

	/* Data items */
	test_items ("basic-import-data", s_vpn, &basic_items[0], FALSE);

	/* Secrets */
	test_items ("basic-import-secrets", s_vpn, &basic_secrets[0], TRUE);

	g_object_unref (connection);
}