示例#1
0
文件: compat.c 项目: mchf/wicked
static xml_node_t *
__ni_compat_generate_dynamic_addrconf(xml_node_t *ifnode, const char *name, ni_bool_t required, unsigned int update)
{
	xml_node_t *aconf;

	aconf = xml_node_new(name, ifnode);
	xml_node_new_element("enabled", aconf, "true");

#if 0	/* This is not yet implemented */
	if (!required)
		xml_node_new_element("optional", aconf, "true");
#endif

	if (update) {
		xml_node_t *child = xml_node_new("update", aconf);
		unsigned int i;

		for (i = 0; update != 0; ++i, update >>= 1) {
			if (update & 1) {
				const char *key = ni_addrconf_update_target_to_name(i);

				if (key)
					xml_node_new(key, child);
			}
		}
	}

	return aconf;
}
示例#2
0
文件: naming.c 项目: gsanso/wicked
static ni_bool_t
ni_objectmodel_pci_describe(const ni_objectmodel_ns_t *ns, const ni_dbus_object_t *object, xml_node_t *parent)
{
	ni_netdev_t *dev;
	ni_pci_dev_t *pci_dev;
	xml_node_t *node;
	char *copy, *s;

	if (!(dev = ni_objectmodel_unwrap_netif(object, NULL)))
		return FALSE;

	if (!(pci_dev = dev->pci_dev))
		return FALSE;

	/* Describe by path */
	node = __describe(ns, parent);
	xml_node_new_element("path", node, pci_dev->path);

	/* Describe by vendor/device */
	node = __describe(ns, parent);
	xml_node_set_uint_hex(xml_node_new("vendor", node), pci_dev->vendor);
	xml_node_set_uint_hex(xml_node_new("device", node), pci_dev->device);

	/* Describe by bridge */
	copy = strdup(pci_dev->path);
	if ((s = strrchr(copy, '/')) != NULL) {
		*s = '\0';
		node = __describe(ns, parent);
		xml_node_new_element("bridge", node, copy);
	}
	free(copy);

	return TRUE;
}
示例#3
0
文件: lease.c 项目: nirmoy/wicked
static int
__ni_dhcp6_lease_ia_addr_to_xml(const ni_dhcp6_ia_addr_t *iadr, uint16_t type,
				xml_node_t *node)
{
	ni_sockaddr_t addr;
	char *tmp = NULL;

	ni_sockaddr_set_ipv6(&addr, iadr->addr, 0);
	switch (type) {
	case NI_DHCP6_OPTION_IA_TA:
	case NI_DHCP6_OPTION_IA_NA:
		xml_node_new_element("address", node, ni_sockaddr_print(&addr));
		break;

	case NI_DHCP6_OPTION_IA_PD:
		ni_string_printf(&tmp, "%s/%u", ni_sockaddr_print(&addr), iadr->plen);
		xml_node_new_element("prefix",  node, tmp);
		ni_string_free(&tmp);
		break;

	default:
		return -1;
	}

	xml_node_new_element_uint("preferred-lft", node, iadr->preferred_lft);
	xml_node_new_element_uint("valid-lft", node, iadr->valid_lft);
	/* xml_node_new_element_uint("flags", node, iadr->flags); */
	__ni_dhcp6_lease_status_to_xml(&iadr->status, node);

	return 0;
}
示例#4
0
文件: lease.c 项目: nirmoy/wicked
static int
__ni_dhcp6_lease_ia_data_to_xml(const ni_dhcp6_ia_t *ia, xml_node_t *node)
{
	const char *ia_address = ni_dhcp6_option_name(NI_DHCP6_OPTION_IA_ADDRESS);
	const char *ia_prefix  = ni_dhcp6_option_name(NI_DHCP6_OPTION_IA_PREFIX);
	const ni_dhcp6_ia_addr_t *iadr;
	xml_node_t *iadr_node;
	unsigned int count = 0;
	char buf[32] = { '\0' };
	int ret;

	switch (ia->type) {
	case NI_DHCP6_OPTION_IA_TA:
		xml_node_new_element_uint("interface-id", node, ia->iaid);
		snprintf(buf, sizeof(buf), "%"PRId64, (int64_t)ia->acquired.tv_sec);
		xml_node_new_element("acquired", node, buf);
		break;
	case NI_DHCP6_OPTION_IA_NA:
	case NI_DHCP6_OPTION_IA_PD:
		xml_node_new_element_uint("interface-id", node, ia->iaid);
		snprintf(buf, sizeof(buf), "%"PRId64, (int64_t)ia->acquired.tv_sec);
		xml_node_new_element("acquired", node, buf);
		xml_node_new_element_uint("renewal-time", node, ia->renewal_time);
		xml_node_new_element_uint("rebind-time", node, ia->rebind_time);
		break;
	default:
		return -1;
	}

	for (iadr = ia->addrs; iadr; iadr = iadr->next) {
		switch (ia->type) {
		case NI_DHCP6_OPTION_IA_NA:
		case NI_DHCP6_OPTION_IA_TA:
			iadr_node = xml_node_new(ia_address, NULL);
			break;
		case NI_DHCP6_OPTION_IA_PD:
			iadr_node = xml_node_new(ia_prefix, NULL);
			break;
		default:
			return -1;
		}
		ret = __ni_dhcp6_lease_ia_addr_to_xml(iadr, ia->type, iadr_node);
		if (ret) {
			xml_node_free(iadr_node);
			if (ret < 0)
				return -1;
		} else {
			count++;
			xml_node_add_child(node, iadr_node);
		}
	}
	__ni_dhcp6_lease_status_to_xml(&ia->status, node);
	return count == 0 ? 1 : 0;
}
示例#5
0
文件: compat.c 项目: mchf/wicked
static ni_bool_t
__ni_compat_generate_vlan(xml_node_t *ifnode, const ni_compat_netdev_t *compat)
{
	ni_vlan_t *vlan;
	xml_node_t *child;

	vlan = ni_netdev_get_vlan(compat->dev);

	child = xml_node_create(ifnode, "vlan");

	xml_node_new_element("device", child, vlan->parent.name);
	xml_node_new_element("tag", child, ni_sprint_uint(vlan->tag));
	return TRUE;
}
示例#6
0
文件: leasefile.c 项目: gsanso/wicked
int
ni_addrconf_lease_ptz_data_to_xml(const ni_addrconf_lease_t *lease, xml_node_t *node)
{
	unsigned int ret = 1;

	if (!ni_string_empty(lease->posix_tz_string)) {
		xml_node_new_element("posix-string", node, lease->posix_tz_string);
		ret = 0;
	}
	if (!ni_string_empty(lease->posix_tz_dbname)) {
		xml_node_new_element("posix-dbname", node, lease->posix_tz_dbname);
		ret = 0;
	}
	return ret;
}
示例#7
0
文件: compat.c 项目: mchf/wicked
static void
__ni_compat_generate_static_route_hops(xml_node_t *rnode, const ni_route_nexthop_t *hops,
					const char *ifname)
{
	const ni_route_nexthop_t *nh;

	for (nh = hops; nh; nh = nh->next) {
		xml_node_t *nhnode;

		if (nh->gateway.ss_family == AF_UNSPEC && !nh->device.name)
			continue;

		nhnode = xml_node_new("nexthop", rnode);
		if (nh->gateway.ss_family != AF_UNSPEC) {
			xml_node_new_element("gateway", nhnode,
				ni_sockaddr_print(&nh->gateway));
		}
		if (nh->device.name && !ni_string_eq(ifname, nh->device.name)) {
			xml_node_new_element("device", nhnode, nh->device.name);
		} else if (ifname) {
			xml_node_new_element("device", nhnode, ifname);
		}
		if (!hops->next)
			continue;

		if (nh->weight > 0) {
			xml_node_new_element("weight", nhnode,
					ni_sprint_uint(nh->weight));
		}
		if (nh->realm > 0) {
			/* Hmm.. */
			xml_node_new_element("realm", nhnode,
					ni_sprint_uint(nh->realm));
		}
		if (nh->flags > 0) {
			ni_string_array_t names = NI_STRING_ARRAY_INIT;
			xml_node_t *fnode = NULL;
			unsigned int i;

			ni_route_nh_flags_get_names(nh->flags, &names);
			for (i = 0; i < names.count; ++i) {
				if (fnode == NULL)
					fnode = xml_node_new("flags", nhnode);
				xml_node_new(names.data[i], fnode);
			}
		}
	}
}
示例#8
0
文件: leasefile.c 项目: gsanso/wicked
static int
ni_addrconf_lease_static_data_to_xml(const ni_addrconf_lease_t *lease, xml_node_t *node)
{
	static const struct group_map {
		const char *name;
		int       (*func)(const ni_addrconf_lease_t *lease, xml_node_t *node);
	} *g, group_map[] = {
		{ NI_ADDRCONF_LEASE_XML_ADDRS_DATA_NODE, ni_addrconf_lease_addrs_data_to_xml },
		{ NI_ADDRCONF_LEASE_XML_ROUTES_DATA_NODE, ni_addrconf_lease_routes_data_to_xml },
		{ NI_ADDRCONF_LEASE_XML_DNS_DATA_NODE, ni_addrconf_lease_dns_data_to_xml },
		{ NULL, NULL }
	};
	xml_node_t *data;

	if (!ni_string_empty(lease->hostname))
		xml_node_new_element("hostname", node, lease->hostname);

	for (g = group_map; g && g->name && g->func; ++g) {
		data = xml_node_new(g->name, NULL);
		if (g->func(lease, data) == 0) {
			xml_node_add_child(node, data);
		} else {
			xml_node_free(data);
		}
	}
	return 0;
}
示例#9
0
文件: device.c 项目: mijos/wicked
/*
 * Apply policy to a virtual (factory) device
 */
int
ni_factory_device_apply_policy(ni_fsm_t *fsm, ni_ifworker_t *w, ni_managed_policy_t *mpolicy)
{
	const char *type_name;
	ni_fsm_policy_t *policy = mpolicy->fsm_policy;
	xml_node_t *config = NULL;

	ni_debug_nanny("%s: configuring factory device using policy %s",
		w->name, ni_fsm_policy_name(policy));

	/* This returns "modem" or "interface" */
	type_name = ni_ifworker_type_to_string(w->type);

	config = xml_node_new(type_name, NULL);
	xml_node_new_element("name", config, w->name);

	config = ni_fsm_policy_transform_document(config, &policy, 1);
	if (config == NULL) {
		ni_error("%s: error when applying policy to %s document",
			w->name, type_name);
		return -1;
	}
	ni_debug_nanny("%s: using device config", w->name);
	xml_node_print_debug(config, 0);

	ni_ifworker_set_config(w, config, ni_fsm_policy_get_origin(policy));

	/* Now do the fandango */
	return ni_factory_device_up(fsm, w);
}
示例#10
0
文件: device.c 项目: mijos/wicked
/*
 * Apply policy to a device
 */
int
ni_managed_device_apply_policy(ni_managed_device_t *mdev, ni_managed_policy_t *mpolicy)
{
	ni_ifworker_t *w = mdev->worker;
	const char *type_name;
	ni_fsm_policy_t *policy = mpolicy->fsm_policy;
	xml_node_t *config = NULL;

	/* If the device is up and running, do not reconfigure unless the policy
	 * has really changed */
	switch (mdev->state) {
	case NI_MANAGED_STATE_STOPPING:
	case NI_MANAGED_STATE_STOPPED:
	case NI_MANAGED_STATE_LIMBO:
		/* Just install the new policy and reconfigure. */
		break;

	case NI_MANAGED_STATE_STARTING:
	case NI_MANAGED_STATE_RUNNING:
	case NI_MANAGED_STATE_FAILED:
		if (mdev->selected_policy == mpolicy && mdev->selected_policy_seq == mpolicy->seqno) {
			ni_debug_nanny("%s: keep using policy %s", w->name, ni_fsm_policy_name(policy));
			return -1;
		}

		/* Just install the new policy and reconfigure. */
		break;

	case NI_MANAGED_STATE_BINDING:
		ni_error("%s(%s): should not get here in state %s",
				__func__, w->name, ni_managed_state_to_string(mdev->state));
		return -1;
	}

	ni_debug_nanny("%s: using policy %s", w->name, ni_fsm_policy_name(policy));

	/* This returns "modem" or "interface" */
	type_name = ni_ifworker_type_to_string(w->type);

	config = xml_node_new(type_name, NULL);
	xml_node_new_element("name", config, w->name);

	config = ni_fsm_policy_transform_document(config, &policy, 1);
	if (config == NULL) {
		ni_error("%s: error when applying policy to %s document", w->name, type_name);
#if 0
		if (mdev->state != NI_MANAGED_STATE_STOPPED)
			ni_nanny_schedule_recheck(&mdev->nanny->down, w);
#endif
		return -1;
	}
	ni_debug_nanny("%s: using device config", w->name);
	xml_node_print_debug(config, 0);

	ni_managed_device_set_policy(mdev, mpolicy, config);

	/* Now do the fandango */
	return ni_managed_device_up(mdev, ni_fsm_policy_get_origin(policy));
}
示例#11
0
文件: lease.c 项目: nirmoy/wicked
int
__ni_dhcp6_lease_boot_to_xml(const ni_addrconf_lease_t *lease, xml_node_t *node)
{
	xml_node_t *data;
	unsigned int i;

	if (ni_string_empty(lease->dhcp6.boot_url) || !lease->dhcp6.boot_params.count)
		return 1;

	data = xml_node_new("boot", node);
	xml_node_new_element("url", data, lease->dhcp6.boot_url);
	for (i = 0; i < lease->dhcp6.boot_params.count; ++i) {
		if (ni_string_empty(lease->dhcp6.boot_params.data[i]))
			continue;
		xml_node_new_element("param", data, lease->dhcp6.boot_params.data[i]);
	}
	return 0;
}
示例#12
0
文件: leasefile.c 项目: gsanso/wicked
int
ni_addrconf_lease_routes_data_to_xml(const ni_addrconf_lease_t *lease, xml_node_t *node)
{
	ni_route_table_t *tab;
	ni_route_nexthop_t *nh;
	xml_node_t *route, *hop;
	ni_route_t *rp;
	unsigned int count = 0;
	unsigned int i;

	/* A very limitted view */
	for (tab = lease->routes; tab; tab = tab->next) {
		if (tab->tid != 254) /* RT_TABLE_MAIN for now */
			continue;

		for (i = 0; i < tab->routes.count; ++i) {
			if (!(rp = tab->routes.data[i]))
				continue;

			route = xml_node_new("route", NULL);
			if (ni_sockaddr_is_specified(&rp->destination)) {
				xml_node_new_element("destination", route,
					ni_sockaddr_prefix_print(&rp->destination,
								rp->prefixlen));
			}
			for (nh = &rp->nh; nh; nh = nh->next) {
				if (!ni_sockaddr_is_specified(&nh->gateway))
					continue;

				hop = xml_node_new("nexthop", route);
				xml_node_new_element("gateway", hop,
					ni_sockaddr_print(&nh->gateway));
			}
			if (route->children) {
				xml_node_add_child(node, route);
				count++;
			} else {
				xml_node_free(route);
			}
		}
	}
	return count ? 0 : 1;
}
示例#13
0
文件: leasefile.c 项目: gsanso/wicked
int
ni_addrconf_lease_addrs_data_to_xml(const ni_addrconf_lease_t *lease, xml_node_t *node)
{
	unsigned int count = 0;
	xml_node_t *anode;
	ni_address_t *ap;

	for (ap = lease->addrs; ap; ap = ap->next) {
		if (lease->family != ap->local_addr.ss_family ||
			!ni_sockaddr_is_specified(&ap->local_addr))
			continue;

		count++;
		anode = xml_node_new("address", node);
		xml_node_new_element("local", anode, ni_sockaddr_prefix_print
				(&ap->local_addr, ap->prefixlen));

		if (ap->peer_addr.ss_family == ap->family) {
			xml_node_new_element("peer", anode, ni_sockaddr_print
					(&ap->peer_addr));
		}
		if (ap->anycast_addr.ss_family == ap->family) {
			xml_node_new_element("anycast", anode, ni_sockaddr_print
					(&ap->anycast_addr));
		}
		if (ap->bcast_addr.ss_family == ap->family) {
			xml_node_new_element("broadcast", anode, ni_sockaddr_print
					(&ap->bcast_addr));
		}
		if (ap->family == AF_INET && ap->label)
			xml_node_new_element("label", anode, ap->label);

		if (ap->ipv6_cache_info.preferred_lft || ap->ipv6_cache_info.valid_lft) {
			xml_node_t *cnode = xml_node_new("cache-info", anode);
			xml_node_new_element_uint("preferred-lifetime", cnode,
					ap->ipv6_cache_info.preferred_lft);
			xml_node_new_element_uint("valid-lifetime", cnode,
					ap->ipv6_cache_info.valid_lft);
		}
	}
	return count ? 0 : 1;
}
示例#14
0
文件: leasefile.c 项目: gsanso/wicked
int
ni_addrconf_lease_smb_data_to_xml(const ni_addrconf_lease_t *lease, xml_node_t *node)
{
	unsigned int count = 0;
	const char *nbt;

	if (__ni_string_array_to_xml(&lease->netbios_name_servers, "name-server", node) == 0)
		count++;
	if (__ni_string_array_to_xml(&lease->netbios_dd_servers, "dd-server", node) == 0)
		count++;
	if (!ni_string_empty(lease->netbios_scope)) {
		count++;
		xml_node_new_element("scope", node, lease->netbios_scope);
	}
	if ((nbt = ni_netbios_node_type_to_name(lease->netbios_type))) {
		count++;
		xml_node_new_element("type", node, nbt);
	}
	return count ? 0 : 1;
}
示例#15
0
文件: leasefile.c 项目: gsanso/wicked
int
ni_addrconf_lease_nis_data_to_xml(const ni_addrconf_lease_t *lease, xml_node_t *node)
{
	unsigned int count = 0;
	unsigned int i, j;
	ni_nis_info_t *nis;
	xml_node_t *data;

	nis = lease->nis;
	if (!nis)
		return 1;

	/* Default domain */
	data = xml_node_new("default", NULL);
	if (!ni_string_empty(nis->domainname)) {
		count++;
		xml_node_new_element("domain", data, nis->domainname);
	}
	if (nis->default_binding == NI_NISCONF_BROADCAST ||
	    nis->default_binding == NI_NISCONF_STATIC) {
		/* no SLP here */
		count++;
		xml_node_new_element("binding", data,
			ni_nis_binding_type_to_name(nis->default_binding));
	}
	/* Only in when static binding? */
	for (i = 0; i < nis->default_servers.count; ++i) {
		const char *server = nis->default_servers.data[i];
		if (ni_string_empty(server))
			continue;
		count++;
		xml_node_new_element("server", data, server);
	}
	if (count) {
		xml_node_add_child(node, data);
	}

	/* Further domains */
	for (i = 0; i < nis->domains.count; ++i) {
		ni_nis_domain_t *dom = nis->domains.data[i];
		if (!dom || ni_string_empty(dom->domainname))
			continue;

		count++;
		data = xml_node_new("domain", node);
		xml_node_new_element("domain", data, dom->domainname);
		if (ni_nis_binding_type_to_name(nis->default_binding)) {
			xml_node_new_element("binding", data,
				ni_nis_binding_type_to_name(nis->default_binding));
		}
		for (j = 0; j < dom->servers.count; ++j) {
			const char *server = dom->servers.data[j];
			if (ni_string_empty(server))
				continue;
			xml_node_new_element("server", data, server);
		}
	}

	return count ? 0 : 1;
}
示例#16
0
文件: compat.c 项目: mchf/wicked
static xml_node_t *
__ni_compat_generate_static_address_list(xml_node_t *ifnode, ni_address_t *addr_list, unsigned int af)
{
	ni_address_t *ap;
	const char *afname;
	xml_node_t *aconf = NULL;

	afname = ni_addrfamily_type_to_name(af);
	if (!afname) {
		ni_error("%s: unknown address family %u", __func__, af);
		return NULL;
	}

	for (ap = addr_list; ap; ap = ap->next) {
		xml_node_t *anode;

		if (ap->family != af)
			continue;

		if (aconf == NULL) {
			char buffer[64];

			snprintf(buffer, sizeof(buffer), "%s:static", afname);
			aconf = xml_node_create(ifnode, buffer);
		}

		anode = xml_node_new("address", aconf);
		xml_node_new_element("local", anode, ni_sockaddr_prefix_print(&ap->local_addr, ap->prefixlen));

		if (ap->peer_addr.ss_family != AF_UNSPEC)
			xml_node_new_element("peer", anode, ni_sockaddr_print(&ap->peer_addr));
		if (ap->bcast_addr.ss_family != AF_UNSPEC)
			xml_node_new_element("broadcast", anode, ni_sockaddr_print(&ap->bcast_addr));
		if (ap->label)
			xml_node_new_element("label", anode, ap->label);
	}

	return aconf;
}
示例#17
0
文件: lease.c 项目: nirmoy/wicked
/*
 * dhcp6 lease data to xml
 */
static int
__ni_dhcp6_lease_head_to_xml(const ni_addrconf_lease_t *lease, xml_node_t *node)
{
	ni_sockaddr_t addr;

	xml_node_new_element("client-id", node,
				ni_duid_print_hex(&lease->dhcp6.client_id));
	xml_node_new_element("server-id", node,
				ni_duid_print_hex(&lease->dhcp6.server_id));
	ni_sockaddr_set_ipv6(&addr, lease->dhcp6.server_addr, 0);
	xml_node_new_element("server-address", node,
				ni_sockaddr_print(&addr));
	xml_node_new_element_uint("server-preference", node,
				lease->dhcp6.server_pref);
	if (lease->dhcp6.rapid_commit)
		xml_node_new_element("rapid-commit", node, NULL);

	if (!ni_string_empty(lease->hostname))
		xml_node_new_element("hostname", node, lease->hostname);

	return 0;
}
示例#18
0
static xml_node_t *
__ni_ifup_generate_match_type_dev(ni_netdev_t *dev)
{
	const char *type;
	xml_node_t *ret;

	if (!dev || dev->link.type == NI_IFTYPE_UNKNOWN)
		return NULL;

	if (!(type = ni_linktype_type_to_name(dev->link.type)))
		return NULL;

	if (!(ret = xml_node_new(NI_NANNY_IFPOLICY_MATCH_COND_AND, NULL)))
		return NULL;

	if (!xml_node_new_element(NI_NANNY_IFPOLICY_MATCH_DEV, ret, dev->name) ||
	    !xml_node_new_element(NI_NANNY_IFPOLICY_MATCH_LINK_TYPE, ret, type)) {
		xml_node_free(ret);
		return NULL;
	}
	return ret;
}
示例#19
0
文件: compat.c 项目: mchf/wicked
static ni_bool_t
__ni_compat_generate_infiniband(xml_node_t *ifnode, const ni_compat_netdev_t *compat)
{
	ni_infiniband_t *ib = ni_netdev_get_infiniband(compat->dev);
	xml_node_t *child;
	const char *value;
	char *pkey = NULL;

	switch (compat->dev->link.type) {
	case NI_IFTYPE_INFINIBAND:
		value = "infiniband";
		break;
	case NI_IFTYPE_INFINIBAND_CHILD:
		value = "infiniband-child";
		break;
	default:
		return FALSE;
	}
	if (!(child = xml_node_new(value, ifnode)))
		return FALSE;

	if ((value = ni_infiniband_get_mode_name(ib->mode)))
		xml_node_new_element("mode", child, value);

	if ((value = ni_infiniband_get_umcast_name(ib->umcast)))
		xml_node_new_element("multicast", child, value);

	if (ib->parent.name) {
		if (!ni_string_printf(&pkey, "0x%04x", ib->pkey))
			return FALSE;

		xml_node_new_element("parent", child, ib->parent.name);
		xml_node_new_element("pkey",   child, pkey);
		ni_string_free(&pkey);
	}

	return TRUE;
}
示例#20
0
文件: compat.c 项目: mchf/wicked
/*
 * Functions for generating XML
 */
static ni_bool_t
__ni_compat_generate_ethernet(xml_node_t *ifnode, const ni_compat_netdev_t *compat)
{
	const ni_netdev_t *dev = compat->dev;
	xml_node_t *child;

	child = xml_node_new("ethernet", ifnode);
	if (dev->link.hwaddr.len)
		xml_node_new_element("address", child, ni_link_address_print(&dev->link.hwaddr));

	/* generate offload and other information */

	return TRUE;
}
示例#21
0
文件: leasefile.c 项目: gsanso/wicked
/*
 * utils to dump lease or a part of to xml
 */
static int
__ni_string_array_to_xml(const ni_string_array_t *array, const char *name, xml_node_t *node)
{
	unsigned int i, count = 0;

	for (i = 0; i < array->count; ++i) {
		const char *item = array->data[i];
		if (ni_string_empty(item))
			continue;
		count++;
		xml_node_new_element(name, node, item);
	}
	return count ? 0 : 1;
}
示例#22
0
文件: leasefile.c 项目: gsanso/wicked
int
ni_addrconf_lease_nds_data_to_xml(const ni_addrconf_lease_t *lease, xml_node_t *node)
{
	unsigned int count = 0;

	if (__ni_string_array_to_xml(&lease->nds_servers, "server", node) == 0)
		count++;
	if (__ni_string_array_to_xml(&lease->nds_context, "context", node) == 0)
		count++;
	if (!ni_string_empty(lease->nds_tree)) {
		count++;
		xml_node_new_element("tree", node, lease->nds_tree);
	}
	return count ? 0 : 1;
}
示例#23
0
文件: lease.c 项目: nirmoy/wicked
static int
__ni_dhcp6_lease_status_to_xml(const ni_dhcp6_status_t *status, xml_node_t *node)
{
	xml_node_t *snode;

	if (status->code != NI_DHCP6_STATUS_SUCCESS ||
	    !ni_string_empty(status->message)) {
		snode = xml_node_new("status", node);

		xml_node_new_element_uint("code", snode, status->code);
		if (status->message) {
			xml_node_new_element("message", snode, status->message);
		}
	}
	return 0;
}
示例#24
0
文件: compat.c 项目: mchf/wicked
static xml_node_t *
ni_compat_generate_ifcfg(const ni_compat_netdev_t *compat, xml_document_t *doc)
{
	xml_node_t *ifnode, *namenode;

	ifnode = xml_node_new("interface", doc->root);

	namenode = xml_node_new("name", ifnode);
	if (compat->identify.hwaddr.type == NI_IFTYPE_ETHERNET) {
		xml_node_add_attr(namenode, "namespace", "ethernet");
		xml_node_new_element("permanent-address", namenode,
				ni_link_address_print(&compat->identify.hwaddr));
	} else {
		xml_node_set_cdata(namenode, compat->dev->name);
	}

	__ni_compat_generate_ifcfg(ifnode, compat);
	return ifnode;
}
示例#25
0
static xml_node_t *
__ni_ifup_generate_match_dev(xml_node_t *node, ni_ifworker_t *w)
{
	if (!node || !w || !w->name)
		return NULL;

	/* TODO: the type has to be from config, _not_ from device
	 * (dev is probably a not ready one just using our name),
	 * but this info is lost in translation... isn't it?
	 */
	if (w->device && ni_string_eq(w->name, w->device->name)) {
		xml_node_t * ret = NULL;

		if ((ret = __ni_ifup_generate_match_type_dev(w->device))) {
			xml_node_add_child(node, ret);
			return ret;
		}
	}
	return xml_node_new_element(NI_NANNY_IFPOLICY_MATCH_DEV, node, w->name);
}
示例#26
0
文件: naming.c 项目: gsanso/wicked
static ni_bool_t
ni_objectmodel_ether_describe(const ni_objectmodel_ns_t *ns, const ni_dbus_object_t *object, xml_node_t *parent)
{
	ni_netdev_t *dev;
	ni_ethernet_t *eth;
	xml_node_t *node;

	if (!(dev = ni_objectmodel_unwrap_netif(object, NULL)))
		return FALSE;

	if (!(eth = dev->ethernet))
		return FALSE;

	if (eth->permanent_address.len) {
		node = __describe(ns, parent);
		xml_node_new_element("permanent-address", node,
				ni_link_address_print(&eth->permanent_address));
	}

	return TRUE;
}
示例#27
0
文件: leasefile.c 项目: gsanso/wicked
int
__ni_addrconf_lease_info_to_xml(const ni_addrconf_lease_t *lease, xml_node_t *node)
{
	char hex[32] = { '\0' };

	xml_node_new_element("family", node, ni_addrfamily_type_to_name(lease->family));
	xml_node_new_element("type", node, ni_addrconf_type_to_name(lease->type));
	if (!ni_string_empty(lease->owner))
		xml_node_new_element("owner", node, lease->owner);
	if (!ni_uuid_is_null(&lease->uuid))
		xml_node_new_element("uuid", node, ni_uuid_print(&lease->uuid));
	xml_node_new_element("state", node, ni_addrconf_state_to_name(lease->state));
	snprintf(hex, sizeof(hex), "0x%08x", lease->update);
	xml_node_new_element("update", node, hex);
	xml_node_new_element_uint("acquired", node, lease->time_acquired);
	return 0;
}
示例#28
0
文件: leasefile.c 项目: gsanso/wicked
int
ni_addrconf_lease_dns_data_to_xml(const ni_addrconf_lease_t *lease, xml_node_t *node)
{
	ni_resolver_info_t *dns;
	unsigned int count = 0;

	dns = lease->resolver;
	if (!dns || (ni_string_empty(dns->default_domain) &&
			dns->dns_servers.count == 0 &&
			dns->dns_search.count == 0))
		return 1;

	if (dns->default_domain) {
		xml_node_new_element("domain", node, dns->default_domain);
		count++;
	}
	if (__ni_string_array_to_xml(&dns->dns_servers, "server", node) == 0)
		count++;
	if (__ni_string_array_to_xml(&dns->dns_search, "search", node) == 0)
		count++;

	return count ? 0 : 1;
}
示例#29
0
文件: compat.c 项目: mchf/wicked
void
__ni_compat_generate_static_route(xml_node_t *aconf, const ni_route_t *rp, const char *ifname)
{
	xml_node_t *rnode, *mnode, *knode;
	char *tmp = NULL;
	const char *ptr;

	rnode = xml_node_new("route", aconf);

	if (rp->destination.ss_family != AF_UNSPEC && rp->prefixlen != 0) {
		xml_node_new_element("destination", rnode,
			ni_sockaddr_prefix_print(&rp->destination, rp->prefixlen));
	}

	__ni_compat_generate_static_route_hops(rnode, &rp->nh, ifname);

	knode = NULL;
	if (rp->table != RT_TABLE_UNSPEC && rp->table != RT_TABLE_MAIN) {
		if (!(ptr = ni_route_table_type_to_name(rp->table)))
			ptr = ni_sprint_uint(rp->table);
		if (knode == NULL)
			knode = xml_node_new("kern", rnode);
		xml_node_new_element("table", knode, ptr);
	}
	if (rp->type != RTN_UNSPEC && rp->type != RTN_UNICAST) {
		if (!(ptr = ni_route_type_type_to_name(rp->type)))
			ptr = ni_sprint_uint(rp->type);
		if (knode == NULL)
			knode = xml_node_new("kern", rnode);
		xml_node_new_element("type", knode, ptr);
	}
	if (rp->scope != RT_SCOPE_UNIVERSE) {
		if (!(ptr = ni_route_scope_type_to_name(rp->scope)))
			ptr = ni_sprint_uint(rp->scope);
		if (knode == NULL)
			knode = xml_node_new("kern", rnode);
		xml_node_new_element("scope", knode, ptr);
	}
	if (rp->protocol != RTPROT_UNSPEC && rp->protocol != RTPROT_BOOT) {
		if (!(ptr = ni_route_protocol_type_to_name(rp->protocol)))
			ptr = ni_sprint_uint(rp->protocol);
		if (knode == NULL)
			knode = xml_node_new("kern", rnode);
		xml_node_new_element("protocol", knode, ptr);
	}

	if (rp->priority > 0) {
		xml_node_new_element("priority", rnode, ni_sprint_uint(rp->priority));
	}
	if (ni_sockaddr_is_specified(&rp->pref_src)) {
		xml_node_new_element("source", rnode, ni_sockaddr_print(&rp->pref_src));
	}
	if (rp->realm > 0) {
		/* Hmm */
		xml_node_new_element("realm", rnode, ni_sprint_uint(rp->realm));
	}
	if (rp->mark > 0 && ni_string_printf(&tmp, "0x%02x", rp->mark)) {
		xml_node_new_element("mark", rnode, tmp);
		ni_string_free(&tmp);
	}
	if (rp->flags > 0) {
		ni_string_array_t names = NI_STRING_ARRAY_INIT;
		xml_node_t *fnode = NULL;
		unsigned int i;

		ni_route_flags_get_names(rp->flags, &names);
		for (i = 0; i < names.count; ++i) {
			if (fnode == NULL)
				fnode = xml_node_new("flags", rnode);
			xml_node_new(names.data[i], fnode);
		}
	}
	if (rp->tos > 0 && ni_string_printf(&tmp, "0x%02x", rp->tos)) {
		xml_node_new_element("tos", rnode, tmp);
		ni_string_free(&tmp);
	}

	mnode = xml_node_new("metrics", NULL);
	__ni_compat_generate_static_route_metrics(mnode, rp);
	if (mnode->children || mnode->attrs.count || mnode->cdata)
		xml_node_add_child(rnode, mnode);
	else
		xml_node_free(mnode);
}
示例#30
0
文件: compat.c 项目: mchf/wicked
static ni_bool_t
__ni_compat_generate_ifcfg(xml_node_t *ifnode, const ni_compat_netdev_t *compat)
{
	const ni_netdev_t *dev = compat->dev;
	xml_node_t *linknode;

	if (compat->control) {
		const ni_ifworker_control_t *control = compat->control;
		xml_node_t *child, *linkdet;

		child = xml_node_create(ifnode, "control");
		if (control->mode)
			xml_node_new_element("mode", child, control->mode);
		if (control->boot_stage)
			xml_node_new_element("boot-stage", child, control->boot_stage);

		if (control->link_timeout || control->link_required) {
			linkdet = xml_node_create(child, "link-detection");
			if (control->link_timeout)
				xml_node_new_element("timeout", linkdet,
						ni_sprint_timeout(control->link_timeout));
			if (control->link_required)
				(void) xml_node_new("require-link", linkdet);
		}
	}

	switch (dev->link.type) {
	case NI_IFTYPE_ETHERNET:
		__ni_compat_generate_ethernet(ifnode, compat);
		break;

	case NI_IFTYPE_INFINIBAND:
	case NI_IFTYPE_INFINIBAND_CHILD:
		__ni_compat_generate_infiniband(ifnode, compat);
		break;

	case NI_IFTYPE_BOND:
		__ni_compat_generate_bonding(ifnode, compat);
		break;

	case NI_IFTYPE_BRIDGE:
		__ni_compat_generate_bridge(ifnode, compat);
		break;

	case NI_IFTYPE_VLAN:
		__ni_compat_generate_vlan(ifnode, compat);
		break;

	case NI_IFTYPE_WIRELESS:
		__ni_compat_generate_wireless(ifnode, compat);
		break;

	default: ;
	}

	linknode = xml_node_new("link", ifnode);
	if (dev->link.mtu)
		xml_node_new_element("mtu", linknode, ni_sprint_uint(dev->link.mtu));

	__ni_compat_generate_static_addrconf(ifnode, compat);

	__ni_compat_generate_dhcp4_addrconf(ifnode, compat);
	__ni_compat_generate_dhcp6_addrconf(ifnode, compat);

	return TRUE;
}