2021-09-14 03:46:23 +03:00
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
// SPDX-License-Identifier: MIT
|
2021-09-21 18:46:35 +03:00
|
|
|
#pragma once
|
|
|
|
|
2023-09-05 20:57:21 +03:00
|
|
|
#include "ebpf_extension.h"
|
2021-09-14 03:46:23 +03:00
|
|
|
#include "ebpf_nethooks.h"
|
2023-02-07 21:32:19 +03:00
|
|
|
#include "ebpf_program_types.h"
|
2023-09-05 20:57:21 +03:00
|
|
|
#include "ebpf_shared_framework.h"
|
2021-09-14 03:46:23 +03:00
|
|
|
|
|
|
|
#define XDP_EXT_HELPER_FUNCTION_START EBPF_MAX_GENERAL_HELPER_FUNCTION
|
|
|
|
|
Remove XDP hook support from netebpfext.sys (#3040)
* replace XDP guids with XDP_TEST guids
* updated missde instance
* update bpf2c
* leave xdp_hook as is
* remove extra files
* update with new XDP_TEST guid, update other tests to use sample_ext
* update some tests, update test_helper
* update fuzzer
* temporarily remove bpftool tests
* update execution context test
* replace XDP guids with XDP_TEST guids
* updated missde instance
* update bpf2c
* leave xdp_hook as is
* remove extra files
* update with new XDP_TEST guid, update other tests to use sample_ext
* update some tests, update test_helper
* update fuzzer
* temporarily remove bpftool tests
* update execution context test
* build failures
* update sample ext with context_allocate and destroy
* update vm script to use xdp_test
* switch api tests to use sample program
* rename to xdp_Test
* update sample ext
* update incorrect SAL, update netsh tests
* update sample, update tests to use sample where applicable
* update tests
* fix up tests
* fix libbpf tets
* revert unnecessary changes
* remove extra prints
* add back in bpftool tests
* update to use xdp instead of xdp_test for bpftool test
* update atomic_instructions_others.o
* extra debug logs
* updated expected, update bpftool tests
* correct bpftool tests
* more debug logs
* add reg debug
* clear program info
* Attempt fix of buffer overrun
* remove debug logs, minor cleanup, set XDP guids back to their original names
* update docs with xdp_test
* fix guid usage
* CR: remove program, update comments, fix commented out tests, update bpf_program__attach_xdp
* revert changes in libbpf, as they need to use the actual XDP guids
* update comment
* update some XDP tests to use sample ext, comment out some expected failing tests
* update bpftool tests
* fix up bpf prog test run expected output, move to #if instead of comments
* fix up return code issue
* fix bpftool testes
* add some failed xdp tests, set some params to null for sample tests
* update comment
* tmp commit - move to xdp mock
* update unit tests to use mock XDP where possible
* made some samples back to XDP type
* netebpfext unit tests should use xdp_test
* CR
2023-12-06 20:12:17 +03:00
|
|
|
// XDP_TEST helper function prototype descriptors.
|
|
|
|
static const ebpf_helper_function_prototype_t _xdp_test_ebpf_extension_helper_function_prototype[] = {
|
2021-09-14 03:46:23 +03:00
|
|
|
{XDP_EXT_HELPER_FUNCTION_START + 1,
|
|
|
|
"bpf_xdp_adjust_head",
|
|
|
|
EBPF_RETURN_TYPE_INTEGER,
|
2024-02-15 05:06:29 +03:00
|
|
|
{EBPF_ARGUMENT_TYPE_PTR_TO_CTX, EBPF_ARGUMENT_TYPE_ANYTHING}}};
|
2021-09-14 03:46:23 +03:00
|
|
|
|
Remove XDP hook support from netebpfext.sys (#3040)
* replace XDP guids with XDP_TEST guids
* updated missde instance
* update bpf2c
* leave xdp_hook as is
* remove extra files
* update with new XDP_TEST guid, update other tests to use sample_ext
* update some tests, update test_helper
* update fuzzer
* temporarily remove bpftool tests
* update execution context test
* replace XDP guids with XDP_TEST guids
* updated missde instance
* update bpf2c
* leave xdp_hook as is
* remove extra files
* update with new XDP_TEST guid, update other tests to use sample_ext
* update some tests, update test_helper
* update fuzzer
* temporarily remove bpftool tests
* update execution context test
* build failures
* update sample ext with context_allocate and destroy
* update vm script to use xdp_test
* switch api tests to use sample program
* rename to xdp_Test
* update sample ext
* update incorrect SAL, update netsh tests
* update sample, update tests to use sample where applicable
* update tests
* fix up tests
* fix libbpf tets
* revert unnecessary changes
* remove extra prints
* add back in bpftool tests
* update to use xdp instead of xdp_test for bpftool test
* update atomic_instructions_others.o
* extra debug logs
* updated expected, update bpftool tests
* correct bpftool tests
* more debug logs
* add reg debug
* clear program info
* Attempt fix of buffer overrun
* remove debug logs, minor cleanup, set XDP guids back to their original names
* update docs with xdp_test
* fix guid usage
* CR: remove program, update comments, fix commented out tests, update bpf_program__attach_xdp
* revert changes in libbpf, as they need to use the actual XDP guids
* update comment
* update some XDP tests to use sample ext, comment out some expected failing tests
* update bpftool tests
* fix up bpf prog test run expected output, move to #if instead of comments
* fix up return code issue
* fix bpftool testes
* add some failed xdp tests, set some params to null for sample tests
* update comment
* tmp commit - move to xdp mock
* update unit tests to use mock XDP where possible
* made some samples back to XDP type
* netebpfext unit tests should use xdp_test
* CR
2023-12-06 20:12:17 +03:00
|
|
|
// XDP_TEST program information.
|
|
|
|
static const ebpf_context_descriptor_t _ebpf_xdp_test_context_descriptor = {
|
2021-09-14 03:46:23 +03:00
|
|
|
sizeof(xdp_md_t),
|
|
|
|
EBPF_OFFSET_OF(xdp_md_t, data),
|
|
|
|
EBPF_OFFSET_OF(xdp_md_t, data_end),
|
|
|
|
EBPF_OFFSET_OF(xdp_md_t, data_meta)};
|
2023-02-22 23:43:23 +03:00
|
|
|
|
Remove XDP hook support from netebpfext.sys (#3040)
* replace XDP guids with XDP_TEST guids
* updated missde instance
* update bpf2c
* leave xdp_hook as is
* remove extra files
* update with new XDP_TEST guid, update other tests to use sample_ext
* update some tests, update test_helper
* update fuzzer
* temporarily remove bpftool tests
* update execution context test
* replace XDP guids with XDP_TEST guids
* updated missde instance
* update bpf2c
* leave xdp_hook as is
* remove extra files
* update with new XDP_TEST guid, update other tests to use sample_ext
* update some tests, update test_helper
* update fuzzer
* temporarily remove bpftool tests
* update execution context test
* build failures
* update sample ext with context_allocate and destroy
* update vm script to use xdp_test
* switch api tests to use sample program
* rename to xdp_Test
* update sample ext
* update incorrect SAL, update netsh tests
* update sample, update tests to use sample where applicable
* update tests
* fix up tests
* fix libbpf tets
* revert unnecessary changes
* remove extra prints
* add back in bpftool tests
* update to use xdp instead of xdp_test for bpftool test
* update atomic_instructions_others.o
* extra debug logs
* updated expected, update bpftool tests
* correct bpftool tests
* more debug logs
* add reg debug
* clear program info
* Attempt fix of buffer overrun
* remove debug logs, minor cleanup, set XDP guids back to their original names
* update docs with xdp_test
* fix guid usage
* CR: remove program, update comments, fix commented out tests, update bpf_program__attach_xdp
* revert changes in libbpf, as they need to use the actual XDP guids
* update comment
* update some XDP tests to use sample ext, comment out some expected failing tests
* update bpftool tests
* fix up bpf prog test run expected output, move to #if instead of comments
* fix up return code issue
* fix bpftool testes
* add some failed xdp tests, set some params to null for sample tests
* update comment
* tmp commit - move to xdp mock
* update unit tests to use mock XDP where possible
* made some samples back to XDP type
* netebpfext unit tests should use xdp_test
* CR
2023-12-06 20:12:17 +03:00
|
|
|
static const ebpf_program_info_t _ebpf_xdp_test_program_info = {
|
|
|
|
{"xdp_test", &_ebpf_xdp_test_context_descriptor, EBPF_PROGRAM_TYPE_XDP_TEST_GUID, BPF_PROG_TYPE_XDP_TEST},
|
|
|
|
EBPF_COUNT_OF(_xdp_test_ebpf_extension_helper_function_prototype),
|
|
|
|
_xdp_test_ebpf_extension_helper_function_prototype};
|
|
|
|
|
|
|
|
static const ebpf_program_section_info_t _ebpf_xdp_test_section_info[] = {
|
|
|
|
{(const wchar_t*)L"xdp_test",
|
|
|
|
&EBPF_PROGRAM_TYPE_XDP_TEST,
|
|
|
|
&EBPF_ATTACH_TYPE_XDP_TEST,
|
|
|
|
BPF_PROG_TYPE_XDP_TEST,
|
|
|
|
BPF_XDP_TEST}};
|
2022-04-01 05:49:13 +03:00
|
|
|
|
|
|
|
// Bind program information.
|
2023-04-12 20:47:39 +03:00
|
|
|
static const ebpf_context_descriptor_t _ebpf_bind_context_descriptor = {
|
2022-04-01 05:49:13 +03:00
|
|
|
sizeof(bind_md_t), EBPF_OFFSET_OF(bind_md_t, app_id_start), EBPF_OFFSET_OF(bind_md_t, app_id_end), -1};
|
2023-02-22 23:43:23 +03:00
|
|
|
|
2023-04-12 20:47:39 +03:00
|
|
|
static const ebpf_program_info_t _ebpf_bind_program_info = {
|
|
|
|
{"bind", &_ebpf_bind_context_descriptor, EBPF_PROGRAM_TYPE_BIND_GUID, BPF_PROG_TYPE_BIND}, 0, NULL};
|
2023-02-22 23:43:23 +03:00
|
|
|
|
2023-04-12 20:47:39 +03:00
|
|
|
static const ebpf_program_section_info_t _ebpf_bind_section_info[] = {
|
2022-07-01 02:53:03 +03:00
|
|
|
{L"bind", &EBPF_PROGRAM_TYPE_BIND, &EBPF_ATTACH_TYPE_BIND, BPF_PROG_TYPE_BIND, BPF_ATTACH_TYPE_BIND}};
|
2022-04-01 05:49:13 +03:00
|
|
|
|
2023-02-22 23:43:23 +03:00
|
|
|
// CGROUP_SOCK_ADDR extension specific helper function prototypes.
|
2023-04-12 20:47:39 +03:00
|
|
|
static const ebpf_helper_function_prototype_t _sock_addr_ebpf_extension_helper_function_prototype[] = {
|
2023-02-22 23:43:23 +03:00
|
|
|
{BPF_FUNC_sock_addr_get_current_pid_tgid,
|
|
|
|
"bpf_sock_addr_get_current_pid_tgid",
|
|
|
|
EBPF_RETURN_TYPE_INTEGER,
|
2023-09-12 01:40:33 +03:00
|
|
|
{EBPF_ARGUMENT_TYPE_PTR_TO_CTX}},
|
|
|
|
{BPF_FUNC_sock_addr_set_redirect_context,
|
|
|
|
"bpf_sock_addr_set_redirect_context",
|
|
|
|
EBPF_RETURN_TYPE_INTEGER,
|
|
|
|
{EBPF_ARGUMENT_TYPE_PTR_TO_CTX, EBPF_ARGUMENT_TYPE_PTR_TO_READABLE_MEM, EBPF_ARGUMENT_TYPE_CONST_SIZE}}};
|
2023-02-22 23:43:23 +03:00
|
|
|
|
2023-01-31 02:44:30 +03:00
|
|
|
// CGROUP_SOCK_ADDR global helper function prototypes.
|
2023-04-12 20:47:39 +03:00
|
|
|
static const ebpf_helper_function_prototype_t _ebpf_sock_addr_global_helper_function_prototype[] = {
|
2023-01-31 02:44:30 +03:00
|
|
|
{BPF_FUNC_get_current_logon_id,
|
|
|
|
"bpf_get_current_logon_id",
|
|
|
|
EBPF_RETURN_TYPE_INTEGER,
|
|
|
|
{EBPF_ARGUMENT_TYPE_PTR_TO_CTX}},
|
|
|
|
{BPF_FUNC_is_current_admin, "bpf_is_current_admin", EBPF_RETURN_TYPE_INTEGER, {EBPF_ARGUMENT_TYPE_PTR_TO_CTX}}};
|
|
|
|
|
2022-04-01 05:49:13 +03:00
|
|
|
// CGROUP_SOCK_ADDR program information.
|
2023-04-12 20:47:39 +03:00
|
|
|
static const ebpf_context_descriptor_t _ebpf_sock_addr_context_descriptor = {
|
2022-04-01 05:49:13 +03:00
|
|
|
sizeof(bpf_sock_addr_t),
|
|
|
|
-1, // Offset into ctx struct for pointer to data, or -1 if none.
|
|
|
|
-1, // Offset into ctx struct for pointer to data, or -1 if none.
|
|
|
|
-1, // Offset into ctx struct for pointer to metadata, or -1 if none.
|
|
|
|
};
|
2023-02-22 23:43:23 +03:00
|
|
|
|
2023-04-12 20:47:39 +03:00
|
|
|
static const ebpf_program_info_t _ebpf_sock_addr_program_info = {
|
|
|
|
{"sock_addr",
|
|
|
|
&_ebpf_sock_addr_context_descriptor,
|
|
|
|
EBPF_PROGRAM_TYPE_CGROUP_SOCK_ADDR_GUID,
|
|
|
|
BPF_PROG_TYPE_CGROUP_SOCK_ADDR},
|
2023-02-22 23:43:23 +03:00
|
|
|
EBPF_COUNT_OF(_sock_addr_ebpf_extension_helper_function_prototype),
|
|
|
|
_sock_addr_ebpf_extension_helper_function_prototype,
|
2023-01-31 02:44:30 +03:00
|
|
|
EBPF_COUNT_OF(_ebpf_sock_addr_global_helper_function_prototype),
|
|
|
|
_ebpf_sock_addr_global_helper_function_prototype};
|
2023-02-22 23:43:23 +03:00
|
|
|
|
2023-04-12 20:47:39 +03:00
|
|
|
static const ebpf_program_section_info_t _ebpf_sock_addr_section_info[] = {
|
2022-07-01 02:53:03 +03:00
|
|
|
{L"cgroup/connect4",
|
|
|
|
&EBPF_PROGRAM_TYPE_CGROUP_SOCK_ADDR,
|
|
|
|
&EBPF_ATTACH_TYPE_CGROUP_INET4_CONNECT,
|
|
|
|
BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
|
|
|
|
BPF_CGROUP_INET4_CONNECT},
|
|
|
|
{L"cgroup/connect6",
|
|
|
|
&EBPF_PROGRAM_TYPE_CGROUP_SOCK_ADDR,
|
|
|
|
&EBPF_ATTACH_TYPE_CGROUP_INET6_CONNECT,
|
|
|
|
BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
|
|
|
|
BPF_CGROUP_INET6_CONNECT},
|
|
|
|
{L"cgroup/recv_accept4",
|
|
|
|
&EBPF_PROGRAM_TYPE_CGROUP_SOCK_ADDR,
|
|
|
|
&EBPF_ATTACH_TYPE_CGROUP_INET4_RECV_ACCEPT,
|
|
|
|
BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
|
|
|
|
BPF_CGROUP_INET4_RECV_ACCEPT},
|
|
|
|
{L"cgroup/recv_accept6",
|
|
|
|
&EBPF_PROGRAM_TYPE_CGROUP_SOCK_ADDR,
|
|
|
|
&EBPF_ATTACH_TYPE_CGROUP_INET6_RECV_ACCEPT,
|
|
|
|
BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
|
|
|
|
BPF_CGROUP_INET6_RECV_ACCEPT}};
|
2022-04-15 01:09:54 +03:00
|
|
|
|
|
|
|
// SOCK_OPS program information.
|
2023-04-12 20:47:39 +03:00
|
|
|
static const ebpf_context_descriptor_t _ebpf_sock_ops_context_descriptor = {
|
2022-04-15 01:09:54 +03:00
|
|
|
sizeof(bpf_sock_ops_t),
|
|
|
|
-1, // Offset into ctx struct for pointer to data, or -1 if none.
|
|
|
|
-1, // Offset into ctx struct for pointer to data, or -1 if none.
|
|
|
|
-1, // Offset into ctx struct for pointer to metadata, or -1 if none.
|
|
|
|
};
|
2023-02-22 23:43:23 +03:00
|
|
|
|
2023-04-12 20:47:39 +03:00
|
|
|
static const ebpf_program_info_t _ebpf_sock_ops_program_info = {
|
|
|
|
{"sockops", &_ebpf_sock_ops_context_descriptor, EBPF_PROGRAM_TYPE_SOCK_OPS_GUID, BPF_PROG_TYPE_SOCK_OPS}, 0, NULL};
|
2023-02-22 23:43:23 +03:00
|
|
|
|
2023-04-12 20:47:39 +03:00
|
|
|
static const ebpf_program_section_info_t _ebpf_sock_ops_section_info[] = {
|
2022-07-01 02:53:03 +03:00
|
|
|
{L"sockops",
|
|
|
|
&EBPF_PROGRAM_TYPE_SOCK_OPS,
|
|
|
|
&EBPF_ATTACH_TYPE_CGROUP_SOCK_OPS,
|
|
|
|
BPF_PROG_TYPE_SOCK_OPS,
|
2023-04-12 20:47:39 +03:00
|
|
|
BPF_CGROUP_SOCK_OPS}};
|