-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6deaa9d
commit f026933
Showing
11 changed files
with
277 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// Copyright (c) Microsoft Corporation. | ||
// | ||
|
||
#include <stdio.h> | ||
#include <windows.h> | ||
// | ||
// Work around various eBPF compilation bugs. | ||
// | ||
#define USER_MODE 1 | ||
#pragma warning(push) | ||
#pragma warning(disable:4005) // 'WIN32_LEAN_AND_MEAN': macro redefinition | ||
#include <ebpf_store_helper.h> | ||
#include <ebpfstore.h> | ||
#pragma warning(pop) | ||
#undef USER_MODE | ||
|
||
INT | ||
__cdecl | ||
main( | ||
INT argc, | ||
CHAR *argv[] | ||
) | ||
{ | ||
ebpf_result_t result; | ||
int exit_code = 0; | ||
|
||
if (argc == 2 && !_strcmpi("--clear", argv[1])) { | ||
for (uint32_t i = 0; i < RTL_NUMBER_OF(EbpfXdpSectionInfo); i++) { | ||
result = ebpf_store_delete_section_information(&EbpfXdpSectionInfo[i]); | ||
if (result != EBPF_SUCCESS) { | ||
fprintf(stderr, "ebpf_store_delete_section_information failed: %u\n", result); | ||
exit_code = -1; | ||
} | ||
} | ||
|
||
result = ebpf_store_delete_program_information(&EbpfXdpProgramInfo); | ||
if (result != EBPF_SUCCESS) { | ||
fprintf(stderr, "ebpf_store_delete_program_information failed: %u\n", result); | ||
exit_code = -1; | ||
} | ||
} else { | ||
result = ebpf_store_update_section_information(&EbpfXdpSectionInfo[0], RTL_NUMBER_OF(EbpfXdpSectionInfo)); | ||
if (result != EBPF_SUCCESS) { | ||
fprintf(stderr, "ebpf_store_update_section_information failed: %u\n", result); | ||
exit_code = -1; | ||
} | ||
|
||
result = ebpf_store_update_program_information(&EbpfXdpProgramInfo, 1); | ||
if (result != EBPF_SUCCESS) { | ||
fprintf(stderr, "ebpf_store_update_program_information failed: %u\n", result); | ||
exit_code = -1; | ||
} | ||
} | ||
|
||
return exit_code; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// Copyright (C) Microsoft. All rights reserved. | ||
// | ||
|
||
// | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
// | ||
|
||
#include <windows.h> | ||
#include <xdpversion.h> | ||
|
||
#define VER_FILETYPE VFT_APP | ||
#define VER_FILESUBTYPE VFT2_UNKNOWN | ||
|
||
#define VER_FILEVERSION XDP_MAJOR_VERSION, XDP_MINOR_VERSION, XDP_PATCH_VERSION, 0 | ||
#define VER_FILEVERSION_STR STR(XDP_MAJOR_VERSION) "." STR(XDP_MINOR_VERSION) "." STR(XDP_PATCH_VERSION) ".0\0" | ||
#define VER_PRODUCTVERSION_STR XDP_VERSION_STR | ||
|
||
#define VER_FILEDESCRIPTION_STR "Microsoft\256 XDP eBPF Export Tool" | ||
#define VER_ORIGINALFILENAME_STR "bpfexport.exe" | ||
|
||
#define VER_COMPANYNAME_STR "Microsoft Corporation" | ||
#define VER_LEGALCOPYRIGHT_STR "\251 Microsoft Corporation. All rights reserved." | ||
#define VER_PRODUCTNAME_STR "Microsoft\256 XDP" | ||
#define VER_INTERNALNAME_STR "bpfexport" | ||
|
||
VS_VERSION_INFO VERSIONINFO | ||
FILEVERSION VER_FILEVERSION | ||
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK | ||
FILEFLAGS 0 | ||
FILEOS VOS_NT_WINDOWS32 | ||
FILETYPE VER_FILETYPE | ||
FILESUBTYPE VER_FILESUBTYPE | ||
|
||
BEGIN | ||
BLOCK "StringFileInfo" | ||
BEGIN | ||
BLOCK "040904B0" | ||
BEGIN | ||
VALUE "CompanyName", VER_COMPANYNAME_STR | ||
VALUE "FileDescription", VER_FILEDESCRIPTION_STR | ||
VALUE "FileVersion", VER_FILEVERSION_STR | ||
VALUE "InternalName", VER_INTERNALNAME_STR | ||
VALUE "LegalCopyright", VER_LEGALCOPYRIGHT_STR | ||
VALUE "OriginalFilename", VER_ORIGINALFILENAME_STR | ||
VALUE "ProductName", VER_PRODUCTNAME_STR | ||
VALUE "ProductVersion", VER_PRODUCTVERSION_STR | ||
END | ||
END | ||
|
||
BLOCK "VarFileInfo" | ||
BEGIN | ||
VALUE "Translation", 0x0409, 0x04B0 | ||
END | ||
END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(SolutionDir)src\xdp.props" /> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
<Import Project="$(SolutionDir)src\xdp.cpp.default.props" /> | ||
<Import Project="$(EbpfPackagePath)build\native\ebpf-for-windows.props" Condition="Exists('$(EbpfPackagePath)build\native\ebpf-for-windows.props')" /> | ||
<ItemGroup> | ||
<ClCompile Include="bpfexport.c" /> | ||
</ItemGroup> | ||
<PropertyGroup Label="Globals"> | ||
<VCProjectVersion>16.0</VCProjectVersion> | ||
<Keyword>Win32Proj</Keyword> | ||
<ProjectGuid>{8f8830ff-1648-4772-87ed-f5da091fc931}</ProjectGuid> | ||
<RootNamespace>bpfexport</RootNamespace> | ||
</PropertyGroup> | ||
<PropertyGroup Label="Configuration"> | ||
<TargetVersion>Windows10</TargetVersion> | ||
<PlatformToolset>WindowsApplicationForDrivers10.0</PlatformToolset> | ||
<ConfigurationType>Application</ConfigurationType> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
<Import Project="$(SolutionDir)src\xdp.cpp.props" /> | ||
<Import Project="$(SolutionDir)src\xdp.cpp.user.props" /> | ||
<ImportGroup Label="ExtensionSettings" /> | ||
<ImportGroup Label="PropertySheets"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<PropertyGroup Label="UserMacros" /> | ||
<PropertyGroup> | ||
<TargetName>xdp_bpfexport</TargetName> | ||
<OutDir>$(SolutionDir)artifacts\bin\$(Platform)_$(Configuration)\</OutDir> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ResourceCompile Include="bpfexport.rc"> | ||
<AdditionalIncludeDirectories> | ||
$(SolutionDir)published\private; | ||
%(AdditionalIncludeDirectories) | ||
</AdditionalIncludeDirectories> | ||
<PreprocessorDefinitions> | ||
XDP_MAJOR_VERSION=$(XdpMajorVersion); | ||
XDP_MINOR_VERSION=$(XdpMinorVersion); | ||
XDP_PATCH_VERSION=$(XdpPatchVersion); | ||
%(PreprocessorDefinitions) | ||
</PreprocessorDefinitions> | ||
<PreprocessorDefinitions Condition="'$(BUILD_BUILDID)' != ''"> | ||
XDP_BUILD_VERSION=$(BUILD_BUILDID); | ||
%(PreprocessorDefinitions) | ||
</PreprocessorDefinitions> | ||
</ResourceCompile> | ||
</ItemGroup> | ||
<ItemDefinitionGroup> | ||
<ClCompile> | ||
<AdditionalIncludeDirectories> | ||
$(SolutionDir)src\xdp; | ||
%(AdditionalIncludeDirectories) | ||
</AdditionalIncludeDirectories> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<AdditionalDependencies> | ||
onecore.lib; | ||
%(AdditionalDependencies) | ||
</AdditionalDependencies> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
<ImportGroup Label="ExtensionTargets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// Copyright (c) Microsoft Corporation. | ||
// | ||
|
||
#pragma once | ||
|
||
#include <ebpf_extension.h> | ||
#include <ebpf_extension_uuids.h> | ||
#include <ebpf_nethooks.h> | ||
#include <ebpf_program_attach_type_guids.h> | ||
#include <ebpf_program_types.h> | ||
#include <ebpf_structs.h> | ||
#include <ebpf_private_extension.h> | ||
|
||
static const ebpf_context_descriptor_t EbpfXdpContextDescriptor = { | ||
.size = sizeof(xdp_md_t), | ||
.data = FIELD_OFFSET(xdp_md_t, data), | ||
.end = FIELD_OFFSET(xdp_md_t, data_end), | ||
.meta = FIELD_OFFSET(xdp_md_t, data_meta), | ||
}; | ||
|
||
#define XDP_EXT_HELPER_FUNCTION_START EBPF_MAX_GENERAL_HELPER_FUNCTION | ||
|
||
// XDP helper function prototype descriptors. | ||
static const ebpf_helper_function_prototype_t EbpfXdpHelperFunctionPrototype[] = { | ||
{ | ||
.helper_id = XDP_EXT_HELPER_FUNCTION_START + 1, | ||
.name = "bpf_xdp_adjust_head", | ||
.return_type = EBPF_RETURN_TYPE_INTEGER, | ||
.arguments = { | ||
EBPF_ARGUMENT_TYPE_PTR_TO_CTX, | ||
EBPF_ARGUMENT_TYPE_ANYTHING, | ||
}, | ||
}, | ||
}; | ||
|
||
#pragma warning(suppress:4090) // 'initializing': different 'const' qualifiers | ||
const ebpf_program_info_t EbpfXdpProgramInfo = { | ||
#pragma warning(suppress:4090) // 'initializing': different 'const' qualifiers | ||
.program_type_descriptor = { | ||
.name = "xdp", | ||
.context_descriptor = &EbpfXdpContextDescriptor, | ||
.program_type = EBPF_PROGRAM_TYPE_XDP_INIT, | ||
BPF_PROG_TYPE_XDP, | ||
}, | ||
.count_of_program_type_specific_helpers = RTL_NUMBER_OF(EbpfXdpHelperFunctionPrototype), | ||
.program_type_specific_helper_prototype = EbpfXdpHelperFunctionPrototype, | ||
}; | ||
|
||
#define DECLARE_XDP_SECTION(_section_name) \ | ||
(const wchar_t*)_section_name, &EBPF_PROGRAM_TYPE_XDP, &EBPF_ATTACH_TYPE_XDP, \ | ||
BPF_PROG_TYPE_XDP, BPF_XDP | ||
|
||
const ebpf_program_section_info_t DECLSPEC_SELECTANY EbpfXdpSectionInfo[] = { | ||
{ | ||
DECLARE_XDP_SECTION(L"xdp") | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.