net/devlink/param.c

Source file repositories/reference/linux-study-clean/net/devlink/param.c

File Facts

System
Linux kernel
Corpus path
net/devlink/param.c
Extension
.c
Size
27530 bytes
Lines
1012
Domain
Networking Core
Bucket
Sockets, Protocols, Packet Path, And Network Policy
Inferred role
Networking Core: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.

Dependency Surface

Detected Declarations

Annotated Snippet

if (flag_as_u8) {
			if (nla_put_u8(msg, nla_type, val->vbool))
				return -EMSGSIZE;
		} else {
			if (val->vbool && nla_put_flag(msg, nla_type))
				return -EMSGSIZE;
		}
		break;
	case DEVLINK_PARAM_TYPE_U64_ARRAY:
		if (val->u64arr.size > __DEVLINK_PARAM_MAX_ARRAY_SIZE)
			return -EMSGSIZE;

		for (int i = 0; i < val->u64arr.size; i++) {
			if (nla_put_uint(msg, nla_type, val->u64arr.val[i]))
				return -EMSGSIZE;
		}
		break;
	}
	return 0;
}

static int
devlink_nl_param_value_fill_one(struct sk_buff *msg,
				enum devlink_param_type type,
				enum devlink_param_cmode cmode,
				union devlink_param_value *val,
				union devlink_param_value *default_val,
				bool has_default)
{
	struct nlattr *param_value_attr;
	int err = -EMSGSIZE;

	param_value_attr = nla_nest_start_noflag(msg,
						 DEVLINK_ATTR_PARAM_VALUE);
	if (!param_value_attr)
		return -EMSGSIZE;

	if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_VALUE_CMODE, cmode))
		goto value_nest_cancel;

	err = devlink_nl_param_value_put(msg, type,
					 DEVLINK_ATTR_PARAM_VALUE_DATA,
					 val, false);
	if (err)
		goto value_nest_cancel;

	if (has_default) {
		err = devlink_nl_param_value_put(msg, type,
						 DEVLINK_ATTR_PARAM_VALUE_DEFAULT,
						 default_val, true);
		if (err)
			goto value_nest_cancel;
	}

	nla_nest_end(msg, param_value_attr);
	return 0;

value_nest_cancel:
	nla_nest_cancel(msg, param_value_attr);
	return err;
}

static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,
				 unsigned int port_index,
				 struct devlink_param_item *param_item,
				 enum devlink_command cmd,
				 u32 portid, u32 seq, int flags,
				 struct netlink_ext_ack *extack)
{
	bool default_value_set[DEVLINK_PARAM_CMODE_MAX + 1] = {};
	bool param_value_set[DEVLINK_PARAM_CMODE_MAX + 1] = {};
	const struct devlink_param *param = param_item->param;
	union devlink_param_value *default_value;
	union devlink_param_value *param_value;
	struct devlink_param_gset_ctx *ctx;
	struct nlattr *param_values_list;
	struct nlattr *param_attr;
	void *hdr;
	int err;
	int i;

	default_value = kcalloc(DEVLINK_PARAM_CMODE_MAX + 1,
				sizeof(*default_value), GFP_KERNEL);
	if (!default_value)
		return -ENOMEM;

	param_value = kcalloc(DEVLINK_PARAM_CMODE_MAX + 1,
			      sizeof(*param_value), GFP_KERNEL);
	if (!param_value) {
		kfree(default_value);

Annotation

Implementation Notes