Example #1
0
/**
 * Print information about cache manager
 * @arg mngr		Cache manager
 * @arg p		Dumping parameters
 *
 * Prints information about the cache manager including all managed caches.
 *
 * @note This is a debugging function.
 */
void nl_cache_mngr_info(struct nl_cache_mngr *mngr, struct nl_dump_params *p)
{
	char buf[128];
	int i;

	nl_dump_line(p, "cache-manager <%p>\n", mngr);
	nl_dump_line(p, "  .protocol = %s\n",
		     nl_nlfamily2str(mngr->cm_protocol, buf, sizeof(buf)));
	nl_dump_line(p, "  .flags    = %#x\n", mngr->cm_flags);
	nl_dump_line(p, "  .nassocs  = %u\n", mngr->cm_nassocs);
	nl_dump_line(p, "  .sock     = <%p>\n", mngr->cm_sock);

	for (i = 0; i < mngr->cm_nassocs; i++) {
		struct nl_cache_assoc *assoc = &mngr->cm_assocs[i];

		if (assoc->ca_cache) {
			nl_dump_line(p, "  .cache[%d] = <%p> {\n", i, assoc->ca_cache);
			nl_dump_line(p, "    .name = %s\n", assoc->ca_cache->c_ops->co_name);
			nl_dump_line(p, "    .change_func = <%p>\n", assoc->ca_change);
			nl_dump_line(p, "    .change_data = <%p>\n", assoc->ca_change_data);
			nl_dump_line(p, "    .nitems = %u\n", nl_cache_nitems(assoc->ca_cache));
			nl_dump_line(p, "    .objects = {\n");

			p->dp_prefix += 6;
			nl_cache_dump(assoc->ca_cache, p);
			p->dp_prefix -= 6;

			nl_dump_line(p, "    }\n");
			nl_dump_line(p, "  }\n");
		}
	}
}
static void print(struct nl_cache_ops *ops, void *arg)
{
	char buf[64];

	printf("%s:\n" \
	       "    hdrsize: %d bytes\n" \
	       "    protocol: %s\n" \
	       "    request-update: %s\n" \
	       "    msg-parser: %s\n",
	       ops->co_name, ops->co_hdrsize,
	       nl_nlfamily2str(ops->co_protocol, buf, sizeof(buf)),
	       ops->co_request_update ? "yes" : "no",
	       ops->co_msg_parser ? "yes" : "no");

	if (ops->co_obj_ops) {
		struct nl_object_ops *obj_ops = ops->co_obj_ops;
		const char *dump_names[NL_DUMP_MAX+1] = {
			"brief",
			"detailed",
			"stats",
		};
		int i;

		printf("    cacheable object:\n" \
		       "        name: %s:\n" \
		       "        size: %zu bytes\n" \
		       "        constructor: %s\n" \
		       "        free-data: %s\n" \
		       "        clone: %s\n" \
		       "        compare: %s\n" \
		       "        id attributes: %s\n" \
		       "        dump: ",
		       obj_ops->oo_name, obj_ops->oo_size,
		       obj_ops->oo_constructor ? "yes" : "no",
		       obj_ops->oo_free_data ? "yes" : "no",
		       obj_ops->oo_clone ? "yes" : "no",
		       obj_ops->oo_compare ? "yes" : "no",
		       id_attr_list(obj_ops, buf, sizeof(buf)));

		for (i = 0; i <= NL_DUMP_MAX; i++)
			if (obj_ops->oo_dump[i])
				printf("%s%s",
				i == 0 ? "" : ", ",
				dump_names[i]);

		printf("\n");
	}

	if (ops->co_genl) {
		struct genl_ops *genl_ops = ops->co_genl;

		printf("    genl:\n" \
		       "        name: %s\n" \
		       "        user-hdr: %d\n" \
		       "        id: %d\n",
		       genl_ops->o_name, genl_ops->o_hdrsize, genl_ops->o_id);

		if (genl_ops->o_ncmds) {
			int i;

			printf("        cmds:\n");

			for (i = 0; i < genl_ops->o_ncmds; i++) {
				struct genl_cmd *cmd = &genl_ops->o_cmds[i];

				printf("            %s:\n"
				       "                id: %d\n" \
				       "                maxattr: %d\n" \
				       "                msg-parser: %s\n" \
				       "                attr-policy: %s\n",
				       cmd->c_name, cmd->c_id, cmd->c_maxattr,
				       cmd->c_msg_parser ? "yes" : "no",
				       cmd->c_attr_policy ? "yes" : "no");
			}
		}
	}
}