2024-05-04 22:55:56 +03:00
|
|
|
// Copyright (c) eBPF for Windows contributors
|
Rename ebpf_helpers.h to bpf_helpers.h for cross-plat compat (#472)
Libbpf has bpf_helpers.h which is mostly platform-agnostic, and
bpf_helper_defs.h which is platform-specific but is included
by bpf_helpers.h. Until libbpf is made more platform-agnostic
(issue #351), the workaround is to have a separate pair of files.
Our bpf_helpers.h and our own bpf_helper_defs.h, both of which
would ideally be merged into libbpf's in the future.
Platform-specific defines are in ebpf_struct.h, though that
name may need to change later on. Linux uses "linux/bpf.h"
(e.g., as used in the https://docs.cilium.io/en/v1.8/bpf/ and
https://developers.redhat.com/blog/2021/04/01/get-started-with-xdp
articles) or "vmlinux.h" (e.g., as used in the
https://ruderich.org/simon/notes/xdp-minimal-example article),
and these filenames are hard coded in eBPF programs. In the future,
we should probably settle on a cross-platform name and use include
paths to distinguish them, as opposed to requiring ifdefs in eBPF
programs. However, all of that is part of issue 351 and not this
issue.
Also removed obsolete/unused "repro.c" from tests/samples
Fixes #426
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-09-02 02:30:33 +03:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// Include platform-specific definitions.
|
|
|
|
#include "bpf_helpers_platform.h"
|
2023-02-07 21:32:19 +03:00
|
|
|
#include "ebpf_structs.h"
|
Rename ebpf_helpers.h to bpf_helpers.h for cross-plat compat (#472)
Libbpf has bpf_helpers.h which is mostly platform-agnostic, and
bpf_helper_defs.h which is platform-specific but is included
by bpf_helpers.h. Until libbpf is made more platform-agnostic
(issue #351), the workaround is to have a separate pair of files.
Our bpf_helpers.h and our own bpf_helper_defs.h, both of which
would ideally be merged into libbpf's in the future.
Platform-specific defines are in ebpf_struct.h, though that
name may need to change later on. Linux uses "linux/bpf.h"
(e.g., as used in the https://docs.cilium.io/en/v1.8/bpf/ and
https://developers.redhat.com/blog/2021/04/01/get-started-with-xdp
articles) or "vmlinux.h" (e.g., as used in the
https://ruderich.org/simon/notes/xdp-minimal-example article),
and these filenames are hard coded in eBPF programs. In the future,
we should probably settle on a cross-platform name and use include
paths to distinguish them, as opposed to requiring ifdefs in eBPF
programs. However, all of that is part of issue 351 and not this
issue.
Also removed obsolete/unused "repro.c" from tests/samples
Fixes #426
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-09-02 02:30:33 +03:00
|
|
|
|
2023-09-29 01:54:44 +03:00
|
|
|
#if !defined(_MSVC_VER)
|
|
|
|
|
|
|
|
// BTF macros recreated from Linux kernel docs and dumping the BTF of the
|
|
|
|
// compiled ELF files.
|
|
|
|
//
|
|
|
|
// __uint and __type
|
|
|
|
// https://www.kernel.org/doc/html/latest/bpf/btf.html
|
|
|
|
// __array
|
|
|
|
// https://www.kernel.org/doc/html/next/bpf/map_of_maps.html
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Declare a field with a given size in a BPF map.
|
|
|
|
*/
|
|
|
|
#define __uint(field_name, field_value) int(*field_name)[field_value]
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Declare a field with a given type in a BPF map.
|
|
|
|
*/
|
|
|
|
#define __type(field_name, field_type) typeof(field_type)* field_name
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Declare the value in a BPF map of type map-in-map or program-in-map.
|
|
|
|
*/
|
|
|
|
#define __array(field_name, map_template) typeof(map_template)* field_name[]
|
|
|
|
|
|
|
|
// SEC macro recreated from LLVM docs:
|
|
|
|
// https://clang.llvm.org/docs/AttributeReference.html
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief LLVM attribute to place a variable in a specific ELF section.
|
|
|
|
*/
|
|
|
|
#define SEC(NAME) __attribute__((section(NAME)))
|
|
|
|
|
2022-04-08 04:53:21 +03:00
|
|
|
#define bpf_map_def _ebpf_map_definition_in_file
|
|
|
|
#include "ebpf_nethooks.h"
|
2023-09-29 01:54:44 +03:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(NULL)
|
|
|
|
#define NULL ((void*)0)
|
Rename ebpf_helpers.h to bpf_helpers.h for cross-plat compat (#472)
Libbpf has bpf_helpers.h which is mostly platform-agnostic, and
bpf_helper_defs.h which is platform-specific but is included
by bpf_helpers.h. Until libbpf is made more platform-agnostic
(issue #351), the workaround is to have a separate pair of files.
Our bpf_helpers.h and our own bpf_helper_defs.h, both of which
would ideally be merged into libbpf's in the future.
Platform-specific defines are in ebpf_struct.h, though that
name may need to change later on. Linux uses "linux/bpf.h"
(e.g., as used in the https://docs.cilium.io/en/v1.8/bpf/ and
https://developers.redhat.com/blog/2021/04/01/get-started-with-xdp
articles) or "vmlinux.h" (e.g., as used in the
https://ruderich.org/simon/notes/xdp-minimal-example article),
and these filenames are hard coded in eBPF programs. In the future,
we should probably settle on a cross-platform name and use include
paths to distinguish them, as opposed to requiring ifdefs in eBPF
programs. However, all of that is part of issue 351 and not this
issue.
Also removed obsolete/unused "repro.c" from tests/samples
Fixes #426
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-09-02 02:30:33 +03:00
|
|
|
#endif
|
|
|
|
|
2023-09-29 01:54:44 +03:00
|
|
|
#if !defined(__doxygen)
|
2024-03-27 05:29:26 +03:00
|
|
|
#define EBPF_HELPER(return_type, name, args) typedef return_type(*const name##_t) args
|
Rename ebpf_helpers.h to bpf_helpers.h for cross-plat compat (#472)
Libbpf has bpf_helpers.h which is mostly platform-agnostic, and
bpf_helper_defs.h which is platform-specific but is included
by bpf_helpers.h. Until libbpf is made more platform-agnostic
(issue #351), the workaround is to have a separate pair of files.
Our bpf_helpers.h and our own bpf_helper_defs.h, both of which
would ideally be merged into libbpf's in the future.
Platform-specific defines are in ebpf_struct.h, though that
name may need to change later on. Linux uses "linux/bpf.h"
(e.g., as used in the https://docs.cilium.io/en/v1.8/bpf/ and
https://developers.redhat.com/blog/2021/04/01/get-started-with-xdp
articles) or "vmlinux.h" (e.g., as used in the
https://ruderich.org/simon/notes/xdp-minimal-example article),
and these filenames are hard coded in eBPF programs. In the future,
we should probably settle on a cross-platform name and use include
paths to distinguish them, as opposed to requiring ifdefs in eBPF
programs. However, all of that is part of issue 351 and not this
issue.
Also removed obsolete/unused "repro.c" from tests/samples
Fixes #426
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-09-02 02:30:33 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "bpf_helper_defs.h"
|
2023-09-12 02:14:40 +03:00
|
|
|
|
2023-09-29 01:54:44 +03:00
|
|
|
#if !defined(_WIN32)
|
2023-09-12 02:14:40 +03:00
|
|
|
#define _WIN32
|
|
|
|
#endif
|