tools/net/ynl/lib/ynl.c

Source file repositories/reference/linux-study-clean/tools/net/ynl/lib/ynl.c

File Facts

System
Linux kernel
Corpus path
tools/net/ynl/lib/ynl.c
Extension
.c
Size
24358 bytes
Lines
1069
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (_yse) {						\
			snprintf(_yse->msg, sizeof(_yse->msg) - 1,  _msg); \
			_yse->msg[sizeof(_yse->msg) - 1] = 0;		\
		}							\
	})

#define __yerr_code(yse, _code...)		\
	({					\
		struct ynl_error *_yse = (yse);	\
						\
		if (_yse) {			\
			_yse->code = _code;	\
		}				\
	})

#define __yerr(yse, _code, _msg...)		\
	({					\
		__yerr_msg(yse, _msg);		\
		__yerr_code(yse, _code);	\
	})

#define __perr(yse, _msg)		__yerr(yse, errno, _msg)

#define yerr_msg(_ys, _msg...)		__yerr_msg(&(_ys)->err, _msg)
#define yerr(_ys, _code, _msg...)	__yerr(&(_ys)->err, _code, _msg)
#define perr(_ys, _msg)			__yerr(&(_ys)->err, errno, _msg)

/* -- Netlink boiler plate */
static bool
ynl_err_walk_is_sel(const struct ynl_policy_nest *policy,
		    const struct nlattr *attr)
{
	unsigned int type = ynl_attr_type(attr);

	return policy && type <= policy->max_attr &&
		policy->table[type].is_selector;
}

static const struct ynl_policy_nest *
ynl_err_walk_sel_policy(const struct ynl_policy_attr *policy_attr,
			const struct nlattr *selector)
{
	const struct ynl_policy_nest *policy = policy_attr->nest;
	const char *sel;
	unsigned int i;

	if (!policy_attr->is_submsg)
		return policy;

	sel = ynl_attr_get_str(selector);
	for (i = 0; i <= policy->max_attr; i++) {
		if (!strcmp(sel, policy->table[i].name))
			return policy->table[i].nest;
	}

	return NULL;
}

static int
ynl_err_walk_report_one(const struct ynl_policy_nest *policy,
			const struct nlattr *selector, unsigned int type,
			char *str, int str_sz, int *n)
{
	if (!policy) {
		if (*n < str_sz)
			*n += snprintf(str, str_sz, "!policy");
		return 1;
	}

	if (type > policy->max_attr) {
		if (*n < str_sz)
			*n += snprintf(str, str_sz, "!oob");
		return 1;
	}

	if (!policy->table[type].name) {
		if (*n < str_sz)
			*n += snprintf(str, str_sz, "!name");
		return 1;
	}

	if (*n < str_sz) {
		int sz;

		sz = snprintf(str, str_sz - *n,
			      ".%s", policy->table[type].name);
		*n += sz;
		str += sz;
	}

Annotation

Implementation Notes