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

148 Коммитов

Автор SHA1 Сообщение Дата
Lorenz Bauer 30a6cf75f1
Return ENOENT from bpf_obj_get when no pinned object exists (#3899)
The current implementation of bpf_obj_get doesn't follow libbpf semantics,
because it always returns -1 on error, instead of returning the negative
error number.

This is especially noticeable when trying to open a non-existant object,
which should return -ENOENT.

See caa17bdcbf/src/bpf.c (L625-L626)
2024-10-09 19:23:31 +00:00
D. Michael Agun a41953dc62
remove --no-verify option from bpf2c and tests using it (#3673)
* remove --no-verify option from bpf2c and tests using it

Closes #3571

* remove builds for unsafe programs in sample.vcxproj

* remove unsafe test cases from netsh_test.cpp

* remove new noverify references

* Revert deletion of netsh tests.

* Add back compilation of unsafe programs (but not bpf2c call)

* remove invalid program tests which used noverify

* remove end_to_end tests using noverify

---------

Co-authored-by: Michael Agun <danielagun@microsoft.com>
2024-09-14 00:45:03 +00:00
Anurag Saxena ffb3638259
Implement `implicit_context` for helper functions. (#3656)
* backup

* backup

* fix build issues

* fix build

* fix analysis failures, fix tests

* seperate out sample for implicit context

* backup

* add ctx as last argument

* fix hash

* block implicit context for jit and interpret

* stabilize tests

* tail call fast path

* add check to reject change in context_header support

* enable implicit context for jit and interpret

* fix

* fix build

* fix analysis build

* update version, update expected files

* fix test failures

* fix test failures

* fix tests

* cleanup

* cleanup

* more cleanup

* enable performance tests

* enable performance tests

* remove tail_call changes

* remove tail_call changes

* remove tail_call changes

* remove tail_call changes

* fix analysis error

* update documentation

* code cleanup

* fix bad merge

* fix test case

* cr comments

* update expected files

* cr comments
2024-07-19 17:12:08 +00:00
Shankar Seal 6b75459f04
UM API to write into a ring buffer map. (#3689)
* UM API to write into a ring buffer map.

* PR Feedback.

* PR feedback.

* PR comments.
2024-07-17 07:57:37 +00:00
Anurag Saxena 00c9138876
Use `context_header` for tail call perf improvement (#3698)
* fix

* fix

* fix

* fix tests

* fix tests

* change to capabilities, add check for prog_array map

* fix analysis build, add tests

* update documentation

* add context_header_support callback for maps

* CR comment

* change capabilities to bitfield

* Apply suggestions from code review

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

* cr comments

* cr comments

* Apply suggestions from code review

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

* CR comments

---------

Co-authored-by: Dave Thaler <dthaler1968@gmail.com>
2024-07-15 16:23:51 +00:00
D. Michael Agun 2efce152dc
Set empty program name to hash of instructions (#3493)
* Move C++ hashing lib from tests/libs/util/ to libs/shared/

This puts hash.cpp/hash.h in a more central location for use by other project files.

* Set empty program name to hash of instructions

ebpf_program_load_bytes now hashes the instructions and uses that for the name
instead of generating a random number.

Closes #3443

* fix signed/unsigned warning (and ensure windows helper id >= 0)

* add bcrypt.dll dependency for ebpfapi.dll

* WIP new test case for ebpf_program_load_bytes with nullptr program name

* WIP ebpf_program_load_bytes testing

* truncate SHA256 hash to 63 bytes to stay under BPF_OBJ_NAME_LEN

* remove bcrypt from release dependencies and suppress analyze warning

* PR feedback - fix comment and bpf2c include paths

---------

Co-authored-by: Michael Agun <danielagun@microsoft.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2024-07-02 14:47:03 +00:00
Alan Jowett 83a35d3c71
Speedup ebpf_handle_table_terminate by avoiding acquire/release of lock (#3605)
* Speedup ebpf_handle_table_terminate by avoiding acquire/release of lock

Signed-off-by: Alan Jowett (from Dev Box) <alanjo@microsoft.com>

* Add workaround for native module handle cleanup delay

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

---------

Signed-off-by: Alan Jowett (from Dev Box) <alanjo@microsoft.com>
Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
Co-authored-by: Alan Jowett <alan.jowett@microsoft.com>
2024-06-25 21:49:39 +00:00
Dave Thaler 7b3f682ded
Implement libbpf autoload APIs (#3592)
* Implement libbpf autoload APIs

Fixes #3555

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

* Suppress spurious compiler warning

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

* Fix test failure

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

* Update tests

Files with no program sections succeed loading

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

* Address PR comment from Anurag

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

* PR feedback

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

* Fix test

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

* Prevent changing prog type of a native program

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

* PR feedback

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

* Remove unused program_type from native load ioctl

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

* Update default autoload value

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

* PR feedback

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

* Fix test

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

* Add check to unit_test to match api_test

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

* Fix api_test

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

---------

Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
2024-06-03 15:28:04 +00:00
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
Anurag Saxena f7ec168340
Add `total_size` to extension header. (#3573)
* change ebpf_extension_header_t to ebpf_version_header_t

* revert to ebpf_version_header_t

* revert to ebpf_version_header_t

* update header

* update doc

* update doc

* use total_size to get the actual struct size

* Apply suggestions from code review

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

---------

Co-authored-by: Dave Thaler <dthaler1968@gmail.com>
2024-05-24 01:05:36 +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
Anurag Saxena fa003d8650
Increase stack depth for PR fault_injection tests (#3489)
* increase stack depth for PR fault_injection tests

* fix memleak in unit tests

---------

Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2024-04-25 18:05:16 +00:00
Anurag Saxena 586fd21d96
Add support for unlimited map size (#3348)
* backup

* fix tests

* update tests

* add tests

* fix tests

* fix test

* fix

* fix tests

* cr comments

* Apply suggestions from code review

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

* cr comments

---------

Co-authored-by: Dave Thaler <dthaler1968@gmail.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2024-04-25 15:16:55 +00:00
Anurag Saxena cf05004d7b
Implement `bpf_get_socket_cookie()` (#3464)
* implement bpf_get_socket_cookie

* fix tests

* fix more tests

* fix tests

* cleanup

* Apply suggestions from code review

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

* fix regression tests

---------

Co-authored-by: Dave Thaler <dthaler1968@gmail.com>
2024-04-24 23:39:57 +00:00
Shankar Seal e9fdc9ed84
fixes. (#3422) 2024-04-03 15:44:59 +00:00
Shankar Seal fc973542c9
extension_header (#3326)
* extension_header

* fix logic error.

* Re-purposing the size field to act as the "minor version". Additional validation checks are added.

* PR Feedback.

* fix break due to bad merge with PR #3372
2024-03-30 17:27:09 +00:00
Anurag Saxena 5011c712f2
Fix the IOCTL numbers so that ebpfapi.dll for x64 and x64-NativeOnly are cross-compatible. (#3305)
* backup

* fix

* update tests

* fix cicd

* fix cicd

* copy usersim.dll from regular build

* fix tests

* fix

* cleanup

* cr comments

* cr comments

* cleanup

* fix

* cr comments
2024-03-05 06:26:48 +00:00
Alan Jowett f4e3bc79cf
Add malformed ELF files to bpf2c corpus (#3198)
* Add crashing ELF file to corpus

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

* Resolve merge conflict

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

* Overhaul of malformed ELF file tests

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

* Fix build break

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

* Fix build failure

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>
2024-01-29 00:18:01 +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
Gianni Trevisiol cd2535d654
Fix ring-buffer map consumer pointer on multiple subscribe/unsubscribe. (#3002)
* fix initialization

* fix typo

* fix initial subscription

* nit

* nit

* fix multiple subscription cases

* wip

* wip

* wip

* wip

* fix init for catch2
2023-11-08 00:44:23 +00:00
Dave Thaler 83de72512b
Update to use latest usersim (#2858)
* Update to use latest usersim

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

* Update to latest usersim

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

* Use NonPagedPoolNx instead of NonPagedPool for netebpfext state

NonPagedPool is executable, which we don't want

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

* Update usersim

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

---------

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2023-09-20 01:07:46 +00:00
Dave Thaler c947ca63b9
Make runtime binaries not depend on usersim (#2783)
* build ebpfcore under usersim

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

* Work around analysis warnings

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

* Fix installer project

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

* Temporarily use ubpf branch with memory fix

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

* WIP

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

* WIP

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

* Create project for files shared between ebpfapi and the ebpf runtime

Move existing files from libs/platform either to:
* libs/shared, if meant to be common between user-mode and ebpf runtime
* libs/runtime, if meant to be used by the ebpf runtime only (whether in
  user or kernel mode)

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

* Move ebpf_tracelog.c to shared

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

* Create shared_user and shared_kernel projects

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

* WIP

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

* WIP

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

* Remove usersim from ebpfsvc

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

* Update to cxplat branch of usersim

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

* Use cxplat_utf8_string

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

* Cleanup

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

* Fix build errors

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

* Fix ebpf_allocate_with_tag

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

* Fixes

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

* Bug fixes

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

* Fix use of ebpf_reallocate to not pass a null pointer

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

* Fix printf tests

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

* Fix memory leaks

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

* Temporary change to help debug double-free in test

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

* Update to latest usersim

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

* Fix analysis warnings

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

* Update to latest usersim

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

* Update usersim to latest

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

* Change native module to use latest usersim

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

* Update nuget package

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

* Only call cxplat_cleanup if cxplat_initialize succeeds

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

* Revert setup_build.vcxproj change

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

* Update usersim to latest

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

---------

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
Co-authored-by: Alan Jowett <alan.jowett@microsoft.com>
2023-09-05 17:57:21 +00:00
Dave Thaler 4e6bed34e8
Build ebpfcore as a DLL for testing (#2744)
* Update to use latest usersim

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

* build ebpfcore under usersim

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

* Update usersim to latest

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

* Fix compilation

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

* Work around analysis warnings

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

* Fix installer project

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

* Fix memory issues in libbpf implementation

Found my latest usersim code

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

* Update usersim to latest

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

* Fix mismatched calloc/free function in ubpf_user.c

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

* Fix mismatched alloc/free in verifier_fuzzer

The verifier_fuzzer used ebpf_allocate() but then called free()

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

* Temporarily use ubpf branch with memory fix

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

* Fix memory issues in ebpfsvc

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

* PR feedback from Anurag

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

---------

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2023-08-17 22:55:15 +00:00
Dave Thaler a29064a1fe
Convert usersim to a DLL (#2683)
* Use usersim as DLL

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

* Convert usersim to a DLL

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

* Make cmake build clear program info state like VS build does

PR #1192 updated the vcxproj file but not the corresponding CMakeLists.txt file
for export_program_info

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

* Pick up latest usersim fix

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

* Fix deadlock in epoch_test_stale_items test

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

* Don't throw exceptions in unit tests

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

* Fix single instance hook initialization in test cases

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

* Fix deadlock in performance test

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

* Add usersim.dll to installer files

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

---------

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2023-07-27 18:36:05 +00:00
Dave Thaler 792d41cd2f
Update use of usersim library to use Ke* DPC APIs (#2662)
* Update usersim library for DPC API support

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

* Flush queued DPCs before terminating usersim platform

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

* Fix fault injection test

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

* Fix test bugs found by fault injection

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

* Use usersim Ke*Timer apis

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

* Fix bad uses of REQUIRE in netebpfext_unit constructors/destructors

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

* Fix mismatched initiate/terminate calls

Move Test-FaultInjection.ps1 to the usersim repo

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

* Use REQUIRE instead of throwing exceptions from unit tests

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

* Don't use REQUIRE in constructors

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

* Fix memory leak bug in netebpf_ext_helper destructor

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

* Fix reference count leak in net_ebpf_extension_sock_ops_flow_established_classify

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

---------

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2023-07-18 06:47:46 +00:00
Dave Thaler a90097517e
More usersim library cleanup (#2636)
* More usersim library cleanup

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

* Fix analyze warning

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

* Use TraceLogging for printk

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

* Fix analysis warnings

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

* Fix deadlock in core_helper_fuzzer

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

* Update usersim library

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

* Fix call to RpcStringFreeA

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

---------

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2023-07-06 23:41:58 +00:00
Dave Thaler ec27659adf
Move usersim code into a separate repo (#2596)
* Use usersim repo

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

* Remove DISPATCH test code from _preprocess_load_native_module

Per Anurag: the code was added earlier to execute the 2 paths in
native module, and it is not needed anmore IIRC, as the "DISPATCH"
code has been removed now from the native module

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

* Bug fixes

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

* Unify some APIs

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

* Fix warnings and clean up code

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

* updated

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

---------

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2023-06-27 15:26:46 +00:00
Dave Thaler 87b6520c34
Remove JIT and interpreter code from NativeOnly builds (#2475)
* Remove JIT and interpreter code from NativeOnly builds

Fixes #2030
Fixes #2488

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

* Try conditional project references

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

* Various test fixes

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

* Native-only fixes to deploy-ebpf.ps1

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

* Native-only support for setup-ebpf.ps1

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

* Native-only support for api_test.exe

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

* Add connect_redirect_tests to deploy-ebpf.ps1

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

* PR feedback from Anurag

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

---------

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2023-06-07 15:49:03 +00:00
Gianni Trevisiol 5950a9785b
Load/Attach/Unload programs only once for connect_redirect tests. (#2450)
* draft

* comments, rename

* nit

* test

* nit

* test

* test

* aggregate globals

* Fix C26495 warnings

* debug

* test

* debug

* debug instrument

* instrument

* comment

* debug

* fix hints and address_info leak

* fix leak

* wip

* fix

* fix

* tests

* Finalize and remove instrumentation.

* Merge bpf_object_ptr definitions

* feedback

* nit

* fixed SAL annotation

* feedback

* nit

* revert
2023-05-17 17:32:04 +00:00
Anurag Saxena 93eb42a908
Revert "socket tests and redirection tests does not clean up bpf_object on failure (#2226)" (#2419)
This reverts commit 6c025904b3.
2023-05-02 04:01:52 +00:00
Delaram Amiri 6c025904b3
socket tests and redirection tests does not clean up bpf_object on failure (#2226)
* wrapper for tests using smart pointer

* address PR comments

* address PR comments

* update connect edirect test

* update connect redirect test

* resolve conflict

* resolve conflict

* test with connect redirect

* test with connect redirect

* change connect redirect test

* address PR comment

* rebase the changes from main

* rebase the changes from main

* Update tests/connect_redirect/connect_redirect_tests.cpp

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

* address PR comment

* modify the bpf object pointer

---------

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2023-04-28 18:27:04 +00:00
Alan Jowett e8f437f364
Raise STATUS_ASSERTION_FAILURE on test timeout (#2272)
* Raise STATUS_ASSERTION_FAILURE on test timeout

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

* PR feedback

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

* Manually generated dump on test timeout

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

---------

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2023-04-06 23:03:43 +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 c55748d6df
Wrap calls from ebpf_drv.c in epoch calls (#2189)
* Replace dynamically sized thread table with fixed
capacity table to avoid memory allocation failures.

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

* Isolate hash-table search logic

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

* Fix code analysis failure and test failure

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-22 22:14:43 +00:00
Anurag Saxena aec1c4060c
Enable leak_detection for "fault_injection" test case. (#2192)
* fix leaks

* update cicd

* fix tests

* fix

* fix

* fix

* add sal
2023-03-17 15:52:39 +00:00
Anurag Saxena 2f1c78e712
Fix native module unit tests for low memory simulation scenario (#2084)
* fix tests

* cr comments

* fix

* Revert "fix"

This reverts commit 25206c5ff7.

* Revert "cr comments"

This reverts commit 4b91cea38e.

* fix
2023-02-19 16:57:12 +00:00
Alan Jowett d88a6abd43
Add option to invoke eBPF programs in batch mode (#2062)
* Add option to invoke eBPF programs in batch mode

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

* Fix use of uninitialized memory

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

* PR feedback and additional testing

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

* Fix code analysis failure

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

* Cleanup and additional test

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

---------

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2023-02-16 15:37:49 +00: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
Dhiren Vispute f50dcb999d
Use weak reference counts for object table entries (#2004)
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2023-02-03 09:33:18 -08:00
Alan Jowett 44602dcb1d
ebpf_program_t computes hash of program info on first attach (#1948)
* ebpf_program_t computes hash of program info on first attach

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

* Provider reload test

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>
2023-01-31 16:14:12 +00:00
Anurag Saxena 319ba6dc6b
Implement sock_addr specific global helper functions (#1847)
* fix

* add native test

* cleanup

* CR comments

* update expected files

* fix

* cr comments

* add 2 helper

* fix proj

* add admin helper

* fix expected files

* test fix

* fix log

* fix

* fix

* fix

* fix test

* implement global helper, add tests

* fix cmake build

* fix analysis failure, update expected files

* update expected fileS

* reuse bpf_get_current_pid_tgid

* fix tests

* fix helper

* fix tests

* update expected files

* backup

* formatting

* fix bad merge

* cleanup

* cleanup

* update issue number

* add header file

* add standard user test

* update helper definition

* fix

* code cleanup

* code cleanup

* fix kernel test

* add check for API calls

* fix test, PR comments

* pr comments

* add debug logs

* add debug logs, fix netebpfext test

* fix netebpfext test

* comment out log

* add traces to debug

* CR comments

* fix netebpfext_unit sock_addr test

* cr comments
2023-01-30 23:44:30 +00:00
Alan Jowett 96f7d6292e
Remove REQUIRE macro from some non-top level test code (#1863)
* Remove REQUIRE macro from some non-top level test code

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

* Fix code analysis warning

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

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2023-01-12 09:04:20 -08:00
Anurag Saxena 8cb62b3fd7
Support for multiple implementations of global helper functions (#1761)
* fix

* add native test

* cleanup

* CR comments

* update expected files

* fix

* cr comments
2022-12-31 10:56:28 -07: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
Alan Jowett 04c1aef91a
Replace _strdup with instrumented ebpf_duplicate_string and fix bugs uncovered (#1717)
* Replace _strdup with ebpf_duplicate_string
* Fix crashes under low memory conditions

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2022-12-08 10:45:20 -08:00
Gianni Trevisiol bc1d699823
Check null return (#1711) 2022-12-05 15:32:18 -07:00
Anurag Saxena ed291b80c9
Return module handle on native module load (#1547)
* kernel and platform changes

* fix

* user mode changes, other fixes

* fix test failure

* change function name

* add tests

* fix failing test

* cr comments

* CR comments

* fix cmake build

* fix

* Apply suggestions from code review

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

* fix assert

* cr comments

* fix analysis failure

* fix test to avoid double close of fd

* test case fixes

* test fix

* fix unit test, analysis failure

* fix tests

* fix memory leak, possible race condition

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2022-11-29 23:36:58 +00:00