Skip to content

Commit

Permalink
Remove dead code (microsoft#381)
Browse files Browse the repository at this point in the history
* Remove dead code

* Address PR feedback

Co-authored-by: Alan Jowett <alanjo@microsoft.com>
shankarseal and Alan-Jowett authored Aug 13, 2021
1 parent e68dece commit 7d779cf
Showing 25 changed files with 98 additions and 693 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -67,7 +67,3 @@ jobs:
- name: Run Unit Tests
working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}}
run: ./unit_tests.exe -s

- name: Run RPC Client Tests
working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}}
run: ./ebpf_client.exe -s
19 changes: 13 additions & 6 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ This will build the following binaries:
* unit_tests.exe: A collection of tests using the Catch framework. These tests are also run as part
of the Github CI/CD so should always pass.
* ebpf_client.exe: A collection of program verification tests that exercises the RPC channel from client to ebpfsvc.
These tests are also run as part of the Github CI/CD so should always pass.
This requires EbpSvc service to be running, and EbpCore and NetEbpfExt drivers to be loaded.
* api_test.exe: A collection of tests that exercises eBPF user mode APIs. This requires EbpSvc service to be running,
and EbpCore and NetEbpfExt drivers to be loaded.
* sample_ebpf_ext.sys: A sample eBPF extension driver that implements a test hook (for a test program type) and test helper functions.
@@ -124,9 +124,10 @@ by having the mocked extensions emit events.
This test does verification for different sample programs by parsing the ELF file and
sending the verification request to ebpfsvc. For the cases when the verification fails,
the test receives and prints the verifier failure message.
If ebpfsvc is not already installed, this test tries to install and start the service before
executing the tests, hence this test should be run as admin if ebpfsvc is not already installed
and running.
This test requires the eBPF user mode service (EbpfSvc), and the
kernel execution context (EbpfCore.sys) and the Network Extension (NetEbpfExt.sys) to be running.
This test is currently *not* part of the CI pipeline. Developers must run this test manually before
checking in changes.

### api_test.exe
This test exercises various eBPF user mode eBPF APIs, including those to load programs,
@@ -140,9 +141,15 @@ This is a test application for the sample eBPF extension. This application loads
and attaches it to the test hook implemented by the sample extension and validates if the eBPF program
executed as expected.

### Running the tests
### Running the tests on a Developer Machine
1. Set the build output folder as the current working directory.
2. Invoke the appropriate exe.
2. Run unit_tests.exe.

### Running the tests on a Test Machine or VM
1. Read the [instructions](https://github.com/microsoft/ebpf-for-windows/blob/master/docs/vm-setup.md) to prepare your test machine or VM.
2. Run install-ebpf.bat
3. Run run_tests.bat


The Catch2 exes have various command line options to control behavior. Default
behavior is to run all the tests and only print information about failing test
8 changes: 0 additions & 8 deletions docs/eBpfExtensions.md
Original file line number Diff line number Diff line change
@@ -21,14 +21,6 @@ program as well as the list of specific helper functions that are available to s
should not unload until the last NMR client detaches, signifying that no eBPF programs are using helper functions
it provides.

Currently the information is exposed as an opaque blob of
[MS-RPCE](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rpce/290c38b1-92fe-4229-91e6-4fc376610c15)
serialized data with the schema defined by
[ebpf_program_types](https://github.com/microsoft/ebpf-for-windows/blob/master/libs/platform/ebpf_program_types.idl).
Due to current limitations on Windows, it's not possible to serialize the contract from kernel mode. Proposals are
underway to switch the serialization to use [Google FlatBuffers](https://google.github.io/flatbuffers/) as that is
more easily serialized from kernel mode.

## NPI Contract for Attach Type

Attach type NPI contracts are the mechanism that extensions use to invoke eBPF programs when events occur. The
53 changes: 8 additions & 45 deletions ebpf-for-windows.sln
Original file line number Diff line number Diff line change
@@ -81,20 +81,12 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EbpfCore", "ebpfcore\EbpfCore.vcxproj", "{97E52ABB-2F1E-4AD2-AEFD-6EB7FDC0A41D}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NetEbpfExt", "netebpfext\netebpfext.vcxproj", "{55499E36-37D4-4F86-B694-9F2990315758}"
ProjectSection(ProjectDependencies) = postProject
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68} = {FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "service", "service", "{4B0B9AFE-78D9-48AF-9968-88D3BB83770F}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ebpfsvc", "ebpfsvc\eBPFSvc.vcxproj", "{BA065B6A-38F8-4197-8F66-87C84AFAD513}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "encode_program_info", "tools\encode_program_info\encode_program_info.vcxproj", "{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ebpf_client", "tests\client\ebpf_client.vcxproj", "{3C195972-46BB-491D-8820-0500FF4BA8B7}"
ProjectSection(ProjectDependencies) = postProject
{BA065B6A-38F8-4197-8F66-87C84AFAD513} = {BA065B6A-38F8-4197-8F66-87C84AFAD513}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "service", "libs\service\service.vcxproj", "{AF85C549-57CC-40A5-BDFC-DCF1998DE80F}"
EndProject
@@ -710,44 +702,16 @@ Global
{BA065B6A-38F8-4197-8F66-87C84AFAD513}.RelWithDebInfo|x64.Build.0 = Release|x64
{BA065B6A-38F8-4197-8F66-87C84AFAD513}.RelWithDebInfo|x86.ActiveCfg = Release|Win32
{BA065B6A-38F8-4197-8F66-87C84AFAD513}.RelWithDebInfo|x86.Build.0 = Release|Win32
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.Debug|ARM.ActiveCfg = Debug|Win32
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.Debug|ARM64.ActiveCfg = Debug|Win32
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.Debug|x64.ActiveCfg = Debug|x64
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.Debug|x64.Build.0 = Debug|x64
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.Debug|x86.ActiveCfg = Debug|Win32
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.Debug|x86.Build.0 = Debug|Win32
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.MinSizeRel|ARM.ActiveCfg = Debug|Win32
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.MinSizeRel|ARM.Build.0 = Debug|Win32
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.MinSizeRel|ARM64.ActiveCfg = Debug|Win32
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.MinSizeRel|ARM64.Build.0 = Debug|Win32
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.MinSizeRel|x64.ActiveCfg = Debug|x64
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.MinSizeRel|x64.Build.0 = Debug|x64
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.MinSizeRel|x86.ActiveCfg = Debug|Win32
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.MinSizeRel|x86.Build.0 = Debug|Win32
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.Release|ARM.ActiveCfg = Release|Win32
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.Release|ARM64.ActiveCfg = Release|Win32
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.Release|x64.ActiveCfg = Release|x64
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.Release|x64.Build.0 = Release|x64
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.Release|x86.ActiveCfg = Release|Win32
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.Release|x86.Build.0 = Release|Win32
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.RelWithDebInfo|ARM.ActiveCfg = Debug|Win32
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.RelWithDebInfo|ARM.Build.0 = Debug|Win32
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.RelWithDebInfo|ARM64.ActiveCfg = Debug|Win32
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.RelWithDebInfo|ARM64.Build.0 = Debug|Win32
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.RelWithDebInfo|x64.Build.0 = Release|x64
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.RelWithDebInfo|x86.ActiveCfg = Release|Win32
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68}.RelWithDebInfo|x86.Build.0 = Release|Win32
{3C195972-46BB-491D-8820-0500FF4BA8B7}.Debug|ARM.ActiveCfg = Debug|Win32
{3C195972-46BB-491D-8820-0500FF4BA8B7}.Debug|ARM64.ActiveCfg = Debug|Win32
{3C195972-46BB-491D-8820-0500FF4BA8B7}.Debug|x64.ActiveCfg = Debug|x64
{3C195972-46BB-491D-8820-0500FF4BA8B7}.Debug|x64.Build.0 = Debug|x64
{3C195972-46BB-491D-8820-0500FF4BA8B7}.Debug|x86.ActiveCfg = Debug|Win32
{3C195972-46BB-491D-8820-0500FF4BA8B7}.Debug|x86.Build.0 = Debug|Win32
{3C195972-46BB-491D-8820-0500FF4BA8B7}.MinSizeRel|ARM.ActiveCfg = Debug|Win32
{3C195972-46BB-491D-8820-0500FF4BA8B7}.MinSizeRel|ARM.Build.0 = Debug|Win32
{3C195972-46BB-491D-8820-0500FF4BA8B7}.MinSizeRel|ARM64.ActiveCfg = Debug|Win32
{3C195972-46BB-491D-8820-0500FF4BA8B7}.MinSizeRel|ARM64.Build.0 = Debug|Win32
{3C195972-46BB-491D-8820-0500FF4BA8B7}.MinSizeRel|ARM.ActiveCfg = Debug|x64
{3C195972-46BB-491D-8820-0500FF4BA8B7}.MinSizeRel|ARM.Build.0 = Debug|x64
{3C195972-46BB-491D-8820-0500FF4BA8B7}.MinSizeRel|ARM64.ActiveCfg = Debug|x64
{3C195972-46BB-491D-8820-0500FF4BA8B7}.MinSizeRel|ARM64.Build.0 = Debug|x64
{3C195972-46BB-491D-8820-0500FF4BA8B7}.MinSizeRel|x64.ActiveCfg = Debug|x64
{3C195972-46BB-491D-8820-0500FF4BA8B7}.MinSizeRel|x64.Build.0 = Debug|x64
{3C195972-46BB-491D-8820-0500FF4BA8B7}.MinSizeRel|x86.ActiveCfg = Debug|Win32
@@ -758,10 +722,10 @@ Global
{3C195972-46BB-491D-8820-0500FF4BA8B7}.Release|x64.Build.0 = Release|x64
{3C195972-46BB-491D-8820-0500FF4BA8B7}.Release|x86.ActiveCfg = Release|Win32
{3C195972-46BB-491D-8820-0500FF4BA8B7}.Release|x86.Build.0 = Release|Win32
{3C195972-46BB-491D-8820-0500FF4BA8B7}.RelWithDebInfo|ARM.ActiveCfg = Debug|Win32
{3C195972-46BB-491D-8820-0500FF4BA8B7}.RelWithDebInfo|ARM.Build.0 = Debug|Win32
{3C195972-46BB-491D-8820-0500FF4BA8B7}.RelWithDebInfo|ARM64.ActiveCfg = Debug|Win32
{3C195972-46BB-491D-8820-0500FF4BA8B7}.RelWithDebInfo|ARM64.Build.0 = Debug|Win32
{3C195972-46BB-491D-8820-0500FF4BA8B7}.RelWithDebInfo|ARM.ActiveCfg = Debug|x64
{3C195972-46BB-491D-8820-0500FF4BA8B7}.RelWithDebInfo|ARM.Build.0 = Debug|x64
{3C195972-46BB-491D-8820-0500FF4BA8B7}.RelWithDebInfo|ARM64.ActiveCfg = Debug|x64
{3C195972-46BB-491D-8820-0500FF4BA8B7}.RelWithDebInfo|ARM64.Build.0 = Debug|x64
{3C195972-46BB-491D-8820-0500FF4BA8B7}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{3C195972-46BB-491D-8820-0500FF4BA8B7}.RelWithDebInfo|x64.Build.0 = Release|x64
{3C195972-46BB-491D-8820-0500FF4BA8B7}.RelWithDebInfo|x86.ActiveCfg = Release|Win32
@@ -1079,7 +1043,6 @@ Global
{97E52ABB-2F1E-4AD2-AEFD-6EB7FDC0A41D} = {97D3096A-20FB-4ACB-A038-88E652FE61E3}
{55499E36-37D4-4F86-B694-9F2990315758} = {97D3096A-20FB-4ACB-A038-88E652FE61E3}
{BA065B6A-38F8-4197-8F66-87C84AFAD513} = {4B0B9AFE-78D9-48AF-9968-88D3BB83770F}
{FA9BB88D-8259-40C1-9422-BDEDF9E9CE68} = {B09749EC-3D14-414B-BA9B-CD20E218DC84}
{3C195972-46BB-491D-8820-0500FF4BA8B7} = {492C9B22-9237-4996-9E33-CA14D3533616}
{AF85C549-57CC-40A5-BDFC-DCF1998DE80F} = {69CDB6A1-434D-4BC9-9BFF-D12DF7EDBB6B}
{1423245D-0249-40FC-A077-FF7780ACFE3F} = {7978FF80-0017-4BD7-A91D-3B113F1F9F9E}
2 changes: 0 additions & 2 deletions libs/api/Verifier.cpp
Original file line number Diff line number Diff line change
@@ -9,11 +9,9 @@
#include "api_common.hpp"
#include "api_internal.h"
#include "ebpf_api.h"
#include "ebpf_bind_program_data.h"
#include "ebpf_platform.h"
#include "ebpf_program_types.h"
#include "ebpf_verifier_wrapper.hpp"
#include "ebpf_xdp_program_data.h"
#include "elfio_wrapper.hpp"
#include "platform.hpp"
#include "tlv.h"
3 changes: 2 additions & 1 deletion libs/api_common/api_common.vcxproj
Original file line number Diff line number Diff line change
@@ -171,9 +171,10 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="api_common.cpp" />
<ClCompile Include="device_helper.cpp" />
<ClCompile Include="map_descriptors.cpp" />
<ClCompile Include="api_common.cpp" />
<ClCompile Include="midl_alloc.cpp" />
<ClCompile Include="windows_helpers.cpp" />
<ClCompile Include="windows_platform_common.cpp" />
</ItemGroup>
3 changes: 3 additions & 0 deletions libs/api_common/api_common.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -28,6 +28,9 @@
<ClCompile Include="map_descriptors.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="midl_alloc.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="device_helper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
2 changes: 0 additions & 2 deletions libs/api_common/device_helper.cpp
Original file line number Diff line number Diff line change
@@ -8,12 +8,10 @@
#include <stdexcept>
#include "api_common.hpp"
#include "ebpf_api.h"
#include "ebpf_bind_program_data.h"
#include "ebpf_platform.h"
#include "ebpf_program_types.h"
#include "ebpf_protocol.h"
#include "ebpf_result.h"
#include "ebpf_xdp_program_data.h"
#include "platform.h"
#include "platform.hpp"

21 changes: 21 additions & 0 deletions libs/api_common/midl_alloc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation
// SPDX-License-Identifier: MIT

#include "ebpf_platform.h"

extern "C"
{

// The _In_ on size is necessary to avoid inconsistent annotation warnings.
_Must_inspect_result_ _Ret_maybenull_ _Post_writable_byte_size_(size) void* __RPC_USER
MIDL_user_allocate(_In_ size_t size)
{
return ebpf_allocate(size);
}

void __RPC_USER
MIDL_user_free(_Pre_maybenull_ _Post_invalid_ void* p)
{
ebpf_free(p);
}
}
48 changes: 7 additions & 41 deletions libs/api_common/windows_helpers.cpp
Original file line number Diff line number Diff line change
@@ -7,13 +7,11 @@
#include <Windows.h>
#include "api_common.hpp"
#include "device_helper.hpp"
#include "ebpf_bind_program_data.h"
#include "ebpf_platform.h"
#include "ebpf_program_types.h"
#include "ebpf_protocol.h"
#include "ebpf_result.h"
#include "ebpf_serialize.h"
#include "ebpf_xdp_program_data.h"
#include "platform.h"
#include "platform.hpp"

@@ -86,55 +84,23 @@ ebpf_result_t
get_program_type_info(const ebpf_program_info_t** info)
{
const GUID* program_type = reinterpret_cast<const GUID*>(global_program_info.type.platform_specific_data);
ebpf_result_t result;
ebpf_result_t result = EBPF_SUCCESS;
ebpf_program_info_t* program_info;
const uint8_t* encoded_data = nullptr;
size_t encoded_data_size = 0;
bool fall_back = false;

// See if we already have the program info cached.
auto it = _program_info_cache.find(*program_type);
if (it == _program_info_cache.end()) {
// Try to query the info from the execution context.
result = get_program_info_data(*program_type, &program_info);
if (result != EBPF_SUCCESS) {
fall_back = true;
} else {
_program_info_cache[*program_type] = ebpf_program_info_ptr_t(program_info);
}
}

if (fall_back) {
// Fall back to using static data so that verification can be tried
// (e.g., from a netsh command) even if the execution context isn't running.
// TODO: remove this in the future.
auto iter = _static_program_info_cache.find(*program_type);
if (iter == _static_program_info_cache.end()) {
if (memcmp(program_type, &EBPF_PROGRAM_TYPE_XDP, sizeof(*program_type)) == 0) {
encoded_data = _ebpf_encoded_xdp_program_info_data;
encoded_data_size = sizeof(_ebpf_encoded_xdp_program_info_data);
} else if (memcmp(program_type, &EBPF_PROGRAM_TYPE_BIND, sizeof(*program_type)) == 0) {
encoded_data = _ebpf_encoded_bind_program_info_data;
encoded_data_size = sizeof(_ebpf_encoded_bind_program_info_data);
}
ebpf_assert(encoded_data != nullptr);

result = ebpf_program_info_decode(&program_info, encoded_data, (unsigned long)encoded_data_size);
if (result != EBPF_SUCCESS) {
return result;
}

_static_program_info_cache[*program_type] = ebpf_helper::ebpf_memory_ptr(program_info);
}
if (result != EBPF_SUCCESS)
goto Exit;
_program_info_cache[*program_type] = ebpf_program_info_ptr_t(program_info);
}

if (!fall_back) {
*info = (const ebpf_program_info_t*)_program_info_cache[*program_type].get();
} else {
*info = (const ebpf_program_info_t*)_static_program_info_cache[*program_type].get();
}
*info = (const ebpf_program_info_t*)_program_info_cache[*program_type].get();

return EBPF_SUCCESS;
Exit:
return result;
}

static ebpf_helper_function_prototype_t*
6 changes: 0 additions & 6 deletions libs/platform/ebpf_program_types.acf

This file was deleted.

Loading

0 comments on commit 7d779cf

Please sign in to comment.