tools/testing/selftests/bpf/progs/sk_storage_omem_uncharge.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/sk_storage_omem_uncharge.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/progs/sk_storage_omem_uncharge.c
Extension
.c
Size
1024 bytes
Lines
54
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

// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2023 Facebook */
#include "vmlinux.h"
#include "bpf_tracing_net.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_core_read.h>

void *sk_ptr = NULL;
int cookie_found = 0;
__u64 cookie = 0;
__u32 omem = 0;

struct {
	__uint(type, BPF_MAP_TYPE_SK_STORAGE);
	__uint(map_flags, BPF_F_NO_PREALLOC);
	__type(key, int);
	__type(value, int);
} sk_storage SEC(".maps");

SEC("fexit/bpf_sk_storage_free")
int BPF_PROG(bpf_sk_storage_free, struct sock *sk)
{
	if (sk_ptr != sk)
		return 0;

	if (sk->sk_cookie.counter != cookie)
		return 0;

	cookie_found++;
	omem = sk->sk_omem_alloc.counter;

	return 0;
}

SEC("fentry/inet6_sock_destruct")
int BPF_PROG(inet6_sock_destruct, struct sock *sk)
{
	int *value;

	if (!cookie || sk->sk_cookie.counter != cookie)
		return 0;

	value = bpf_sk_storage_get(&sk_storage, sk, 0, 0);
	if (value && *value == 0xdeadbeef) {
		cookie_found++;
		sk_ptr = sk;
	}

	return 0;
}

char _license[] SEC("license") = "GPL";

Annotation

Implementation Notes