tools/testing/selftests/bpf/progs/crypto_common.h

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/crypto_common.h

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/progs/crypto_common.h
Extension
.h
Size
1735 bytes
Lines
67
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

struct __crypto_ctx_value {
	struct bpf_crypto_ctx __kptr * ctx;
};

struct array_map {
	__uint(type, BPF_MAP_TYPE_ARRAY);
	__type(key, int);
	__type(value, struct __crypto_ctx_value);
	__uint(max_entries, 1);
} __crypto_ctx_map SEC(".maps");

static inline struct __crypto_ctx_value *crypto_ctx_value_lookup(void)
{
	u32 key = 0;

	return bpf_map_lookup_elem(&__crypto_ctx_map, &key);
}

static inline int crypto_ctx_insert(struct bpf_crypto_ctx *ctx)
{
	struct __crypto_ctx_value local, *v;
	struct bpf_crypto_ctx *old;
	u32 key = 0;
	int err;

	local.ctx = NULL;
	err = bpf_map_update_elem(&__crypto_ctx_map, &key, &local, 0);
	if (err) {
		bpf_crypto_ctx_release(ctx);
		return err;
	}

	v = bpf_map_lookup_elem(&__crypto_ctx_map, &key);
	if (!v) {
		bpf_crypto_ctx_release(ctx);
		return -ENOENT;
	}

	old = bpf_kptr_xchg(&v->ctx, ctx);
	if (old) {
		bpf_crypto_ctx_release(old);
		return -EEXIST;
	}

	return 0;
}

#endif /* _CRYPTO_COMMON_H */

Annotation

Implementation Notes