Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
/*
 * 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;
}