Граф коммитов

64 Коммитов

Автор SHA1 Сообщение Дата
Dave Thaler 840269a9ec
Add support for multiple programs per section (#3557)
* Allow multiple programs per section

Temporarily use a fork of ebpf-verifier until
https://github.com/vbpf/ebpf-verifier/pull/642 is merged.

Per https://stackoverflow.com/questions/13147170/attribute-always-inline-failing
the __attribute__((always_inline)) doesn't do anything unless you also
have the "inline" keyword.

Signed-off-by: Dave Thaler <dthaler1968@gmail.com>

* Update verifier to latest

Signed-off-by: Dave Thaler <dthaler1968@gmail.com>

* Address comment from Alan

Signed-off-by: Dave Thaler <dthaler1968@gmail.com>

* Address API compat comment from Anurag

Signed-off-by: Dave Thaler <dthaler1968@gmail.com>

---------

Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
2024-05-29 15:30:20 +00:00
Alan Jowett aed27b488b
Add option to control the level of verbosity emitted by verifier. (#3570)
* Add option to control the level of verbosity emitted by verifier.

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Re-order enums to make normal < informational < verbose

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Apply suggestions from code review

Co-authored-by: Dave Thaler <dthaler1968@gmail.com>

* PR feedback

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Workaround for verifier failure #643

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Revert change in ebpf-service verification path

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

---------

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
Co-authored-by: Alan Jowett <alan.jowett@microsoft.com>
Co-authored-by: Dave Thaler <dthaler1968@gmail.com>
2024-05-23 14:02:34 +00:00
Dave Thaler d096b21ac5
Update copyright to be eBPF for Windows contributors (#3508)
* Update copyright to be eBPF for Windows contributors

Fixes #3507

Signed-off-by: Dave Thaler <dthaler1968@gmail.com>

* Undo gratuitous formatting changes in expected files

---------

Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
2024-05-04 19:55:56 +00:00
Dave Thaler 64e670602f
Update verifier to latest (#3144)
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
2024-01-02 17:33:23 +00:00
Matthew Ige 2000dafc4e
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 17:12:17 +00:00
Dave Thaler 968d33a741
Fix netsh show maps alignment issue (#2918)
Fixes #2917

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2023-09-29 18:13:56 +00:00
Dave Thaler b7f82b66c5
Remove cmake build (#2764)
Other projects can now consume ebpf-for-windows in binary form,
using either nuget or MSI install.  We no longer need to build
ebpf-for-windows both ways, so removing the cmake build to free
up build resources and reduce the development cost of maintaining
both msbuild and cmake builds.

Fixes #2743

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2023-08-18 00:48:10 +00:00
Alan Jowett b6c5762bc5
Reduce reference set from bpf_object__open_file (#2687)
Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
Co-authored-by: Alan Jowett <alan.jowett@microsoft.com>
2023-07-21 16:53:24 +00:00
Dave Thaler 543403af77
Add netsh command to enumerate processes using eBPF (#2379)
* Add netsh command to enumerate processes using eBPF

Addresses part of issue #555

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix build/test issues

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix potential buffer overrun

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix output when running non-elevated

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Exclude [processes] test from CodeCoverage

OpenCodeCoverage uses STATUS_BREAKPOINT and doesn't work reliably
with code that uses TerminateThread().  For now we exclude this
test from code coverage runs.

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

---------

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2023-05-01 20:01:50 +00:00
Dave Thaler 62c0d9e111
Add compartment support to netsh ebpf add program (#2321)
* Add compartment support to netsh ebpf add program

Fixes #2185

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Address PR feedback

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

---------

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2023-04-20 03:32:28 +00:00
Dave Thaler 93b7634d23
Fix sanitizer build of fuzzer (#2201)
* Fix sanitizer build of fuzzer

Fixes #1817

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fixes

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* More fixes

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Disable some build steps for FuzzerDebug

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Update github workflows

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Update verifier to latest

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix execution_context_fuzzer build

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix bpf2c and samples

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix samples compilation

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix custom program type sample

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

---------

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2023-04-13 15:00:49 +00:00
Anurag Saxena dcc2e6470c
Fix memory leaks (#2267)
* cicd.yml change -- revert

* fix leak

* fix leaks

* fix leak

* Revert "cicd.yml change -- revert"

This reverts commit 0ff2cff79b.

* code cleanup

* CR comments
2023-04-04 20:06:30 +00:00
Alan Jowett 240fbb16d8
Convert single line if to if with braces (#2224)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2023-03-27 15:01:21 +00:00
Alan Jowett 4cf0391526
Refactor low memory test into generic fault injection (#2173)
* Refactor low memory test into generic fault injection

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Update number of frames to skip

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* PR feedback

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

---------

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2023-03-11 02:42:28 +00:00
Delaram Amiri f873e2a456
SAL annotation (#2098)
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2023-02-20 03:08:03 +00:00
Delaram Amiri 4283733f25
Replace Windows style type names with types names that match the coding guidelines (#2019)
* clean up code

* fixing the build

* Update libs/ebpfnetsh/elf.cpp

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* fixing the build

* fixing the build

* fixing the build

* fixing the build

* fixing the build

* fixing the build

* revert HRESULT

* change BOOL type

* change BOOL type

* change BOOL type

* change BOOL type

* change BOOL type

* change BOOL type

* revert LPSERVICE_MAIN_FUNCTION

* revert SERVICE_MAIN_FUNCTION*

* SAL annotation for svcmain.cpp

* revert some SAL annotation

* remove some extra spaces

* fix tests

* change to bool type

* Update map_dll.c

* fix according to dll_main prototype

* fix BOOL

* fix according to dll_main prototype

* BOOl type

* BOOl type

* modify doc for self host runner setup

* modify doc for self host runner setup

* update tests with bool

* Update tests/unit/wer_report_test_wrapper.cpp

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* Update libs/platform/user/ebpf_platform_user.cpp

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* Update libs/ebpfnetsh/programs.cpp

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* change _Null_terminated_ to _Field_z_

* address PR comment

---------

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
Co-authored-by: Gianni Trevisiol <gtrevi@users.noreply.github.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2023-02-16 11:56:32 -08:00
Dave Thaler 3d626ff9c1
Clean up order of includes (#2015)
* Clean up order of includes

Fixes #1963

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Update clang-format

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Clean up headers

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Update sort

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* FIx various build errors

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix ordering if including a .c file

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix cmake build

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* More header cleanup

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Update expected bpf2c output

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* More header fixes

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Update expected bpf2c output for custom bpf.c

The generate script does not handle this file.

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix tests

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix more expected bpf2c output

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

---------

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Co-authored-by: Anurag Saxena <43585259+saxena-anurag@users.noreply.github.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2023-02-07 18:32:19 +00:00
Alan Jowett 5bd706092b
Add option to generate .spd files for sample driven PGO (#1931)
* Add option to generate .spd files for sample driven PGO

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Fix test failure

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2023-01-20 23:10:24 +00:00
Alan Jowett 866bc2ac79
First round of memory leak fixes in ebpfapi (#1774)
* First round of memory leak fixes in ebpfapi

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2022-12-29 11:53:16 -08:00
Alan Jowett 0b293ad804
Fix code analysis annotations for In and In_opt parameters by adding const where appropriate or changing to Inout where appropriate. (#1749)
* Fix code analysis annotations for _In_ and _In_opt_ parameters,
add const where appropriate or change to _Inout_ where appropriate.

The following regex expressions were used to find the problems:
Find _In_ or _In_opt_ that are not const and are not followed by _Post_invalid_ or _Frees_ptr_ or _Post_ptr_invalid_:
```_In_[ ]+(?!.*(const|_Post_invalid_|_Frees_ptr_|_Post_ptr_invalid_))```
```_In_opt_[ ]+(?!.*(const|_Post_invalid_|_Frees_ptr_|_Post_ptr_invalid_))```

Some of the _In_ and _In_opt_ parameters are not const due to required compatibility with the Windows API.
Pointers to functions are const by definition, so the const qualifier is not required.

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* PR feedback

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Fix code analysis failure

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* PR feedback

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* PR feedback

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* PR feedback

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2022-12-15 15:58:33 -08:00
Gianni Trevisiol 99b7ece81f
Visual Studio 2022 porting (#1521)
* Draft

* wip - full build

* wip

* Docs & scripts update

* revert test

* Updates to overall GettingStarted.md guide.

* Updated CI/CD scripts

* Update ebpf-verifier cache key

* Fix #1513. Next action forwarded to #1563.

* Bump up epbfverifier to 05bca47

* Fix CRT path.

* Disable sanitizing

* fix cmake build

* Removed unsupported x86 and ARM configurations.

* Test address sanitizer off

* wip -full build w/asan

* asan enabled on ci/cd

* update wdk version to 22621

* wip - full build

* add mock asan

* Update CL param

* wip - proj sync

* wip - ltcg

* wip - driver settings

* wip-build props

* wip - asan opts

* wip-plat asan

* wip-asan

* wip

* wip

* wip-debug

* Branch resync

* Mitigate compiler OOM.

* remove asan mock

* doc update

* doc update

* Removed commented code.

* Added comments for pragma-s
2022-12-08 20:06:57 -07:00
Alan Jowett 0e3f2a5157
Instrument all allocation paths (#1620)
* Instrument all allocation paths

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Fix test failure

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Remove global new/delete until issue can be resolved

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Fix code analysis warning

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Revert ubpf update

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Code analysis failure

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* PR feedback

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Fix code-analysis warning

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Fix code-analysis warning

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Fix codeanalysis failures

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* PR feedback

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Anurag Saxena <43585259+saxena-anurag@users.noreply.github.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-11-19 16:33:27 +00:00
Alan Jowett 0a9be2779e
Annotate remaining code with _Must_inspect_result_ (#1570)
* Annotate remaining code with _Must_inspect_result_

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Fix build

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* PR feedback

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Fix merge failure

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Alan Jowett <alan.jowett@microsoft.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
Co-authored-by: Anurag Saxena <43585259+saxena-anurag@users.noreply.github.com>
2022-11-18 13:36:24 -08:00
Alan Jowett f718581501
Resolve duplicate definition of _ebpf_objects (#1659)
Clear the _ebpf_netsh_objects at the start of the test and verify objects are removed.

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2022-11-16 10:41:39 -07:00
Anurag Saxena 9dec755e7b
netsh fix (#1619) 2022-11-11 16:58:55 -08:00
Alan Jowett c3ab2a3bcc
Check for NULL return from ebpf_enumerate_sections and ebpf_api_elf_disassemble_section (#1606)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-11-11 09:40:53 +00:00
Dave Thaler 568e8f0bdf
Add ability to enumerate maps associated with a program (#1395)
* Add map ids test

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Enumerate maps associated with a program

Fixes #1339

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Initialize info before calling

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Update bpftool

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Make "netsh show prog l=v" show map ids for program

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Return EFAULT if map_ids is not a valid pointer

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix warning

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* More test fixes

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix test

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix socket test

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Add more checks in the socket test

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix socket test

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix netsh

Also fix GettingStarted.md and a missing space in the logs
that were found while testing this fix.

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Set map_ids on output

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-09-30 12:12:12 -07:00
Dave Thaler d8aead85ad
Clean up the deprecated netsh use of bpf_object__for_each_safe() (#1368)
Fixes #1295

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-08-29 13:05:34 -06:00
Dave Thaler 7e0738ee07
Add support for new libbpf APIs (#1288)
* Update to latest libbpf .h files

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Add libbpf_bpf_{prog,attach}_type_str APIs

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Add libbpf_attach_type_by_name

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Add libbpf_bpf_{link,map}_type_str

And add tests for prog type and attach type names

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Add tests

And change type names to match Linux

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix cmake build

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Update tests

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Update docs

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Add bpf_program__insn_cnt()

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Add MSVC deprecated attribute to most deprecated APIs

Still haven't done bpf_object__next() or bpf_prog_load_deprecated()

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Mark bpf_object__next was deprecated

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix some test failures

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Suppress instead of disable deprecated warnings

To simplify diffs

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Merge with latest main

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* PR feedback

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-07-29 14:57:30 -04:00
saxena-anurag 8b96a52b43
fix (#1257)
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-06-30 18:37:33 -07:00
saxena-anurag 96226a7db9
Change default program type to EBPF_PROGRAM_TYPE_UNSPECIFIED (#1173)
* fixes

* update cmakelists

* fix bpf2c tests

* fix cilium tests

* add tests

* update bpf2c issue number

* Apply suggestions from code review

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* fix

* fix

* fix

* cr comments

* fix build break

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2022-06-15 09:59:39 -06:00
Dave Thaler f863a02469
Create bpf_map structures from bpf_object__open() on a native file (#1160)
* Create bpf_map structures from bpf_object__open() on a native file

Fixes #1140

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix map update when loading native object

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Update tests

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix for test

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* More test fixes

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* More test fixes

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* PR feedback

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* PR feedback

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-06-07 19:28:52 -07:00
Dave Thaler 4718bf7a73
Support bpf_object__load() with native programs (#1133)
* Make bpf_object__open_file work with native files

* Update bpf_object__open_file()
* Add bpf_object__open()
* Rename ebpf_enumerate_sections() to ebpf_enumerate_program_sections()

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Remove ebpf_program_load

And add a couple of windows-specific libbpf related APIs

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix bug in enumerate sections hit by tail_call_multiple_um.dll

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix program_name field in object_open

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Cleanup

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix order of PE sections returned

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Bug fix

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Bug fix

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Bug fix and revert enumerate_sections rename

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Updated expected bpf2c output

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix analysis warning

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Updated issue number in TODO comments

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Address Anurag's feedback

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-05-24 14:53:04 -07:00
Dave Thaler eab141f47c
Remove more obsolete APIs (#1110)
* Remove ebpf_get_next_program (bpf_prog_get_next_id should be used
  instead)
* Don't export the internal ebpf_map_pin api

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-05-16 10:02:22 -07:00
Dave Thaler 3a9958f501
Support "netsh ebpf show sections" with native drivers (#1070)
* WIP: enumerate sections in native code

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Make bpf2c emit section names

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* More of PE section enumeration

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix program type and map count display for native programs

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Update cmake files

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Temporarily disable some compiler warnings for the pe-parse project

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Native programs have different sizes for skeleton in debug vs release

Also add text case for section is just ".text"

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Address PR feedback

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Force inlining utility functions inside ebpf programs

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Update expected output

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* More expected output changes

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix ebpfapi to allow a single section of name .text

To match libbpf behavior

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix test

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Resolve analysis warnings

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix analysis warnings

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Address PR comments from Anurag

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix test

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-05-11 14:06:49 -07:00
Dave Thaler 1e1b18e374
Add support for bpf_program__type (#1074)
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-05-09 10:11:48 -07:00
Alan Jowett c5b44d04e1
Add comments for map declarations (#1064)
* Add comments for map declarations

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Emit names instead of constants

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Fix build break

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* PR feedback

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

Co-authored-by: Alan Jowett <alan.jowett@microsoft.com>
2022-05-06 15:39:57 -06:00
Alessandro Gario 6a54714ec2
cmake: Add base targets (#882)
Signed-off-by: Alessandro Gario <alessandro.gario@gmail.com>
2022-04-26 05:39:37 -07:00
Dave Thaler 086b80149d
Nuget package (#999)
* WIP: Developer nuget package

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Add bpf2c utility

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Build nupkg from within VisualStudio

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Don't use relative path to externals

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Update props file in nuget package

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix include and library paths

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix debug build

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

Co-authored-by: saxena-anurag <43585259+saxena-anurag@users.noreply.github.com>
2022-04-25 10:26:56 -07:00
Dave Thaler 69adefb137
More bpftool tests (#986)
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-04-21 10:41:44 -07:00
Alan Jowett 05c92adeba
Call ebpf_verifier prior to code gen (#961)
* Call ebpf_verifier prior to code gen

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Resovle failures after merge

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* PR feedback

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Revert rollback of catch2

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-04-18 12:52:55 -06:00
saxena-anurag 3470d6d7b7
EC and API changes to load generated BPF driver (#811)
* initial_commit

* fix build

* fix build

* fix build break due to merge

* debug build

* api changes, other changes

* bpf2c change to enmit program type, other fixes

* hydrate UM ebpf_object, other fixes

* remove logic to disable programs

* fixes

* fix sal

* build break

* build break

* fix sal errors

* fixes

* fix bpf2c_tests failure

* unload driver when program ref count becomes 0, other minor fixes

* fixes

* tail_call fixes, add test cases, other fixes

* build break

* build break

* code cleanup

* fix bad merge

* code cleanup

* code cleanup

* cleanup

* Apply suggestions from code review

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* cr comments

* Apply suggestions from code review

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* cr comments

* Apply suggestions from code review

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* cr comments

* cr comments

* Apply suggestions from code review

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* address cr comments

* Apply suggestions from code review

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* add tracing in ebpfcore, other fixes

* tracing

* add section for each map in sample

* do not delete the native service

* fix bad merge

* remove code to delete service, other fixes

* cr comments

* bpf2c should read and populate all the maps in ELF file

* add test case for creating map-in-map from native driver

* Apply suggestions from code review

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* cr comments

* add tracing for api code changes

* rename epbf_native_t to ebpf_native_module_t

* fix bad merge

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-04-01 12:52:04 -07:00
Alan Jowett fd94c807a5
Centralize compiler options (#823)
* Centralize all compiler options

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2022-03-29 10:41:09 -06:00
Shankar Seal d5cf5e8622
support interface parameter for loading XDP program in netsh ebpf con… (#790)
* support interface parameter for loading XDP program in netsh ebpf context.

* PR Feedback.

* PR Feedback.
2022-03-09 16:15:58 -08:00
Dave Thaler b9dc141163
Add bpf() API (#711)
* Add bpf() API

Addresses issue #559

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Address code review suggestion

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-01-11 20:47:06 -08:00
Dave Thaler 1664a4f58b
Update to latest verifier code (#652)
* Update to latest verifier code

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Add reference to yaml-cpp vcxproj file

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix verifier tests

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-11-07 10:47:47 -08:00
Dave Thaler 1a17769087
Add program type and attach type to netsh output (#603)
* Add program type to netsh "show programs" output
* Add attach type to netsh "show links" output

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-28 09:45:22 -07:00
Dave Thaler 20d7a6565e
Add more libbpf APIs needed by bpftool (#576)
* Add more libbpf APIs needed by bpftool

* Add missing export for existing bpf_map__name API
* Add bpf_object__load
* Add bpf_object__load_xattr
* Add bpf_object__open_file
* Add bpf_object__unload() API
* Add bpf_program__get_type
* Add bpf_program__set_type
* Add bpf_program__unload() API
* Add libbpf_get_error
* Add libbpf_num_possible_cpus
* Rename BPF_MAP_TYPE_UNSPECIFIED to BPF_MAP_TYPE_UNSPEC for libbpf
  compat
* Rename BPF_PROG_TYPE_UNKNOWN to BPF_PROG_TYPE_UNSPEC for libbpf compat
* Add attach_type to bpf_link_info
* Add map_flags to bpf_map_info (but currently always 0)

Fixes #575

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-23 19:32:09 -07:00
Dave Thaler 6d3be2a0c2
Fix netsh "show maps" output (#581)
* Fix netsh "show maps" output

* Display correct inner map ID
* Display Map ID
* Display count of # paths pinned
* Correct "set program" help text

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix rebase

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-09-21 10:34:13 -06:00
Dave Thaler 52e4acdcdf
Add option to pin all programs added, and show links and maps (#553)
* Add option to pin all programs added and show links and maps

* "add programs" now supports the equivalent of bpftool's "prog loadall"
  in addition to just "prog load"
* add "show links" netsh command
* expose "show maps" netsh command.  It was partially implemented but
  never exposed before.
* remove ebpf_map_query_definition() and test as being redundant with
  bpf_obj_get_info_by_fd() (and in the future, a strongly typed one that
  is map specific but different from the query map definition prototype)
* Fix bug where getting the next ID failed to check for index beyond
  array size.  And add test cases for it.
* Fix bug in ebpf_state.c where after enough tests ran it would start
  returning EBPF_NO_MEMORY because _ebpf_state_next_index was never
  reset.

Addresses #549

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-17 18:52:47 -07:00