drivers/net/bonding/bond_options.c

Source file repositories/reference/linux-study-clean/drivers/net/bonding/bond_options.c

File Facts

System
Linux kernel
Corpus path
drivers/net/bonding/bond_options.c
Extension
.c
Size
57559 bytes
Lines
1942
Domain
Driver Families
Bucket
drivers/net
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (*p) {
			rv = sscanf(val->string, "%32s", valstr);
		} else {
			rv = sscanf(val->string, "%llu", &val->value);
			checkval = true;
		}
		if (!rv)
			goto out;
	}

	for (i = 0; tbl[i].string; i++) {
		/* Check for exact match */
		if (checkval) {
			if (val->value == tbl[i].value)
				ret = &tbl[i];
		} else {
			if (!strcmp(valstr, "default") &&
			    (tbl[i].flags & BOND_VALFLAG_DEFAULT))
				ret = &tbl[i];

			if (!strcmp(valstr, tbl[i].string))
				ret = &tbl[i];
		}
		/* Found an exact match */
		if (ret)
			goto out;
	}
	/* Possible range match */
	if (checkval && bond_opt_check_range(opt, val->value))
		ret = val;
out:
	return ret;
}

/* Check opt's dependencies against bond mode and currently set options */
static int bond_opt_check_deps(struct bonding *bond,
			       const struct bond_option *opt)
{
	struct bond_params *params = &bond->params;

	if (test_bit(params->mode, &opt->unsuppmodes))
		return -EACCES;
	if ((opt->flags & BOND_OPTFLAG_NOSLAVES) && bond_has_slaves(bond))
		return -ENOTEMPTY;
	if ((opt->flags & BOND_OPTFLAG_IFDOWN) && (bond->dev->flags & IFF_UP))
		return -EBUSY;

	return 0;
}

static void bond_opt_dep_print(struct bonding *bond,
			       const struct bond_option *opt,
			       struct nlattr *bad_attr,
			       struct netlink_ext_ack *extack)
{
	const struct bond_opt_value *modeval;
	struct bond_params *params;

	params = &bond->params;
	modeval = bond_opt_get_val(BOND_OPT_MODE, params->mode);
	if (test_bit(params->mode, &opt->unsuppmodes)) {
		netdev_err(bond->dev, "option %s: mode dependency failed, not supported in mode %s(%llu)\n",
			   opt->name, modeval->string, modeval->value);
		NL_SET_ERR_MSG_ATTR(extack, bad_attr,
				    "option not supported in mode");
	}
}

static void bond_opt_error_interpret(struct bonding *bond,
				     const struct bond_option *opt,
				     int error, const struct bond_opt_value *val,
				     struct nlattr *bad_attr,
				     struct netlink_ext_ack *extack)
{
	const struct bond_opt_value *minval, *maxval;
	char *p;

	switch (error) {
	case -EINVAL:
		NL_SET_ERR_MSG_ATTR(extack, bad_attr, "invalid option value");
		if (val) {
			if (val->string) {
				/* sometimes RAWVAL opts may have new lines */
				p = strchr(val->string, '\n');
				if (p)
					*p = '\0';
				netdev_err(bond->dev, "option %s: invalid value (%s)\n",
					   opt->name, val->string);
			} else {
				netdev_err(bond->dev, "option %s: invalid value (%llu)\n",

Annotation

Implementation Notes