net/smc/smc_hs_bpf.c

Source file repositories/reference/linux-study-clean/net/smc/smc_hs_bpf.c

File Facts

System
Linux kernel
Corpus path
net/smc/smc_hs_bpf.c
Extension
.c
Size
3397 bytes
Lines
141
Domain
Networking Core
Bucket
Sockets, Protocols, Packet Path, And Network Policy
Inferred role
Networking Core: implementation source
Status
source 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

static int __smc_bpf_stub_set_tcp_option(struct tcp_sock *tp) { return 1; }
static int __smc_bpf_stub_set_tcp_option_cond(const struct tcp_sock *tp,
					      struct inet_request_sock *ireq)
{
	return 1;
}

static struct smc_hs_ctrl __smc_bpf_hs_ctrl = {
	.syn_option	= __smc_bpf_stub_set_tcp_option,
	.synack_option	= __smc_bpf_stub_set_tcp_option_cond,
};

static int smc_bpf_hs_ctrl_init(struct btf *btf) { return 0; }

static int smc_bpf_hs_ctrl_reg(void *kdata, struct bpf_link *link)
{
	if (link)
		return -EOPNOTSUPP;

	return smc_hs_ctrl_reg(kdata);
}

static void smc_bpf_hs_ctrl_unreg(void *kdata, struct bpf_link *link)
{
	smc_hs_ctrl_unreg(kdata);
}

static int smc_bpf_hs_ctrl_init_member(const struct btf_type *t,
				       const struct btf_member *member,
				       void *kdata, const void *udata)
{
	const struct smc_hs_ctrl *u_ctrl;
	struct smc_hs_ctrl *k_ctrl;
	u32 moff;

	u_ctrl = (const struct smc_hs_ctrl *)udata;
	k_ctrl = (struct smc_hs_ctrl *)kdata;

	moff = __btf_member_bit_offset(t, member) / 8;
	switch (moff) {
	case offsetof(struct smc_hs_ctrl, name):
		if (bpf_obj_name_cpy(k_ctrl->name, u_ctrl->name,
				     sizeof(u_ctrl->name)) <= 0)
			return -EINVAL;
		return 1;
	case offsetof(struct smc_hs_ctrl, flags):
		if (u_ctrl->flags & ~SMC_HS_CTRL_ALL_FLAGS)
			return -EINVAL;
		k_ctrl->flags = u_ctrl->flags;
		return 1;
	default:
		break;
	}

	return 0;
}

static const struct bpf_func_proto *
bpf_smc_hs_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
{
	return bpf_base_func_proto(func_id, prog);
}

static const struct bpf_verifier_ops smc_bpf_verifier_ops = {
	.get_func_proto		= bpf_smc_hs_func_proto,
	.is_valid_access	= bpf_tracing_btf_ctx_access,
};

static struct bpf_struct_ops bpf_smc_hs_ctrl_ops = {
	.name		= "smc_hs_ctrl",
	.init		= smc_bpf_hs_ctrl_init,
	.reg		= smc_bpf_hs_ctrl_reg,
	.unreg		= smc_bpf_hs_ctrl_unreg,
	.cfi_stubs	= &__smc_bpf_hs_ctrl,
	.verifier_ops	= &smc_bpf_verifier_ops,
	.init_member	= smc_bpf_hs_ctrl_init_member,
	.owner		= THIS_MODULE,
};

int bpf_smc_hs_ctrl_init(void)
{
	return register_bpf_struct_ops(&bpf_smc_hs_ctrl_ops, smc_hs_ctrl);
}

Annotation

Implementation Notes