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

384 Коммитов

Автор SHA1 Сообщение Дата
Alan Jowett 04dc2904c1
Add negative tests for maps and programs (#1072)
* Add negative tests for maps and programs

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

* Tweak tests

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

* Tweak tests

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

* Add pin coverage

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

* Fix code analysis failure

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

* Add negative tests for maps and programs

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

* Tweak tests

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

* Tweak tests

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

* Add pin coverage

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

* Fix code analysis failure

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

* PR feedback

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

* PR feedback

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

* PR feedback

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

* PR feedback

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

* PR feedback

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

* PR feedback

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

* PR feedback

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-11 12:20:08 -06: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
Dave Thaler 033c3cc955
Add more bpf() api tests (#1043)
Fixes #1021

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-05-02 17:40:00 -06:00
Alan Jowett cd017611cf
Add coverage in bitmap, epoch, and ringbuffer. (#1007)
* Add coverage in bitmap, epoch, and ringbuffer.

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-02 12:39:58 -06:00
saxena-anurag dafd950314
Add negative native module tests (#1039)
* add tests, bugfix

* mark tests for Debug only

* fix build failure

* update cmake file

* Apply suggestions from code review

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

* fix cmakelists

* fix build break

* fix typo

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-05-01 16:26:41 -07:00
saxena-anurag b99986ab6c
Random crash fix - preemptible workitems (#1042) 2022-05-01 15:23:37 -07:00
saxena-anurag 24f098b869
workaround (#1040) 2022-04-29 18:20:12 -07:00
Dave Thaler 1e495e15d2
Add more libbpf api tests (#1029)
Addresses most of #1021

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

Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2022-04-28 15:31:33 -06:00
saxena-anurag 5be88a6432
Implement preemptible work items for user mode (#1025)
* fix

* cr comments
2022-04-28 09:03:55 -06:00
saxena-anurag ece1044444
Add Cilium regression tests (#1015)
* add cilium tests

* bugfix, fix include path for new tests

* disable verification for Debug build, disable code coverage

* cr comments
2022-04-26 13:59:00 -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
Alan Jowett 1989d26873
Remove ebpf_verify_program API (#997)
* Remove ebpf_verify_program API

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

* Remove old test

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

* Cleanup runners

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

* PR feedback

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

* Cleanup old artifacts

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

Co-authored-by: Alan Jowett <alan.jowett@microsoft.com>
2022-04-25 10:46:22 -06:00
Shankar Seal a40b87d61d
Fix issues in NMR module implementations. (#988)
* bug fix.

* fix NMR modules bug.

* PR Feedback.

* PR feedback 2.
2022-04-21 17:41:24 -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 29e0d8a1a4
Extend fuzzing to other map types (#982)
* Extend fuzzing to other map types

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

* Limit fuzzing process memory

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

* PR feedback

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

Co-authored-by: saxena-anurag <43585259+saxena-anurag@users.noreply.github.com>
2022-04-20 19:59:51 -06:00
Dave Thaler 10e3375d68
Update test scripts (#975)
* Update test scripts

* Make KM runner execute bpftool tests
* Make the run_tests.bat script also execute bpftool tests
* Make deploy-ebpf.ps1 -t copy all files needed for testing

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

* Fix test

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

* Fix merge error

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

Co-authored-by: saxena-anurag <43585259+saxena-anurag@users.noreply.github.com>
2022-04-20 15:59:17 -07:00
Dave Thaler 2f484db0c7
Fix push/pop APIs on queues (#985)
* Fix push/pop APIs on queues

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

* Fix SAL warning

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

* Remove deprecated code

Fixes #980

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-04-20 15:09:36 -07:00
Dave Thaler 5eddf01178
Add initial bpftool tests and another libbpf test (#960)
* Add initial bpftool tests and another libbpf test

And fix various bugs hit by the tests.
This PR only adds a couple of initial tests.
A future PR will add many more tests.

bpftool_tests.exe is meant to be run on a machine with the drivers
installed.  A future PR will add it to the KM test runner in CI/CD.

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

* Fix release build

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

* Fix test

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

* Fix test

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

* Send stderr to bpf2c_tests log

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

* Update expected bpf2c output for map.o

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

* Fix bpf2c map output

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

Co-authored-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: saxena-anurag <43585259+saxena-anurag@users.noreply.github.com>
2022-04-19 16:24:01 -07:00
saxena-anurag 56d2bd377f
bugfix (#976) 2022-04-19 13:06:54 -07:00
Alan Jowett 17379737cf
Add all program types to get_program_type_info in offline mode (#972)
* Encode all program info types

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

* Expand hard coded program types and helper functions

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

* Fix tail_call_map verification failure

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

* Fix tail_call_map verification failure

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2022-04-18 17:41:01 -06: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
Dave Thaler b01dea6d55
Fix reply id/length on failure in KM (#950)
* Fix reply id/length on failure in KM

And make UM and KM more closely follow the same logic to catch this sort
of bug in the future.  Before this, UM would succeed and KM would fail,
and there were only UM tests for this case.

Fixes #946

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

* Fix device_helper.hpp

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

* Fix reply length

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

* Cleanup

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

* PR feedback

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

Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2022-04-18 10:26:29 -06:00
saxena-anurag a956ce1749
Fix ZwUnloadDriver failure issue (#965)
* fix zwunloaddriver failure issue

* build break

* fix failing unit test
2022-04-16 11:39:03 -07:00
saxena-anurag 81a855e88f
Enable unit tests for native driver (#953)
* add native tests, bugfixes

* cr comments, fix test failures, fix bad merge

* fix analysis build break

* test failure
2022-04-15 18:26:41 -07:00
Shankar Seal a1a2c6ad92
Sockops 1 (#952)
* remove dependabot from the fork.

* Revert "remove dependabot from the fork."

This reverts commit c542c6cd44.

* add sock_ops program and attach types.

* PR Feedback.
2022-04-14 15:09:54 -07:00
Dave Thaler 1c2cae9e75
Update bpftool (#945)
Signed-off-by: Dave Thaler <dthaler@microsoft.com>

Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2022-04-14 08:31:26 -06:00
Alan Jowett 11c7721f08
Integrate changes from upstream ubpf (#936)
* Integrate changes from upstream ubpf

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

* Suppress code analysis warning

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

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-04-11 22:08:29 -06:00
Dave Thaler e22fcdb281
Remove unused ebpf_get_next_map API (#910)
ebpf_get_next_map was obsoleted by standard libbpf apis
(specifically bpf_map_get_next_id and bpf_map_get_fd_by_id)
and isn't called by anything including test code.

This increases our code coverage percentage.

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

Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2022-04-08 14:32:49 -07:00
Dave Thaler d00377f074
Make map definition more cross-platform compatible (#904)
Fixes #903

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-04-07 18:53:21 -07:00
Shankar Seal a9ab3370d5
`bpf_prog_attach` API and other changes. (#891)
* remove dependabot from the fork.

* Revert "remove dependabot from the fork."

This reverts commit c542c6cd44.

* Program info and hook NPI providers for sock_addr.

* Program info and hook NPI providers for sock_addr.

* PR Feedback.

* PR Feedback 2.

* wfp callout for sock_addr hook.

* PR Feedback.

* fix build break.
2022-04-07 18:18:53 -07:00
Alan Jowett 59716dfa16
Fuzz testing of execution context (#896)
* Fuzz testing of execution context

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

* Fix workflow

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

* Fix fuzzing workflow

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

* Fix formatting

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

* Fix tests

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

* PR feedbac

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

* Fix analysis failures

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

* Fixup edit

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

* Fix build

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

* Fix break found during fuzzing

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2022-04-07 10:50:52 -07:00
saxena-anurag 54516ec2c7
Add mock layer to run native module test cases in user mode (#889)
* add mock layer to test native module load

* Apply suggestions from code review

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

* make unit_test dependent on dll projects

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2022-04-06 17:43:28 -07:00
Dave Thaler b9d46ae8e4
Use upstream main branch for ebpf-verifier (#894)
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-04-05 11:01:36 -07: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
Shankar Seal f896c5244e
Add BPF_PROG_TYPE_CGROUP_SOCK_ADDR support (#858)
* Add BPF_PROG_TYPE_CGROUP_SOCK_ADDR program type and CGROUP_INET4/6_CONNECT/RECV_ACCEPT attach types.

* PR Feedback #1.

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-03-31 19:49:13 -07:00
Alan Jowett b52d9efe22
Enable building with Address Sanitizer (#821)
* Enable building with Address Sanitizer

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

* Grab clang binaries

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

* Fix read overrun in map_crud_operations_lpm_trie_32

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

* Fix potential read of uninitialized memory

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

* Really fix read overrun

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

* Fix second overrun

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

* Remove RPC client test for now

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

* PR feedback

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

* Apply suggestions from code review

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

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

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-03-30 12:32:29 -06: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
saxena-anurag e56e80e51c
Fix race condition between ebpf_epoch_terminate() and _ebpf_epoch_stale_worker() (#850)
* bugfix

* bugfix
2022-03-28 13:39:29 -07:00
Shankar Seal ecea57b4d8
Change extensions npiid (#841)
* remove dependabot from the fork.

* change extension provider NPI IDs.

* PR feedback.

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-03-28 11:26:19 -07:00
saxena-anurag edd6d974d5
Fix calling ObReferenceObjectByHandle at DISPATCH (#840)
* bugfix, add test cases

* fix build break

* cr comments

* cr comments

* cr comments
2022-03-28 10:25:12 -07:00
dependabot[bot] 7b2c9c08ce
Bump external/ebpf-verifier from `e7e7017` to `5356ffe` (#824)
* Bump external/ebpf-verifier from `e7e7017` to `5356ffe`

Bumps [external/ebpf-verifier](https://github.com/dthaler/ebpf-verifier) from `e7e7017` to `5356ffe`.
- [Release notes](https://github.com/dthaler/ebpf-verifier/releases)
- [Commits](e7e701712d...5356ffe3be)

---
updated-dependencies:
- dependency-name: external/ebpf-verifier
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update to match latest verifier

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-03-21 19:35:43 -06:00
Alan Jowett b4b6e15d73
Move common interlocked API's into their own file (#815)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2022-03-17 18:27:47 -06:00
Alan Jowett 2709dac138
Flush free_list if it's stale (#814)
Add an additional flag per CPU EBPF_EPOCH_PER_CPU_STALE.
This flag is accessed by ebpf_epoch_exit and by the flush timer.

This flag is set to on by the flush timer if the free_list is not empty.
This flag is set to off by ebpf_epoch_exit (if set).

If the flush timer sees this flag on and the free_list is not empty, then it will schedule an _ebpf_epoch_stale_worker DPC on the CPU (this DPC calls ebpf_epoch_enter/ebpf_epoch_exit).

Resolves: #813

Signed-off-by: Alan Jowett alanjo@microsoft.com
2022-03-17 14:44:22 -06:00
Shankar Seal a8e3a30767
Support attaching XDP program per NIC. (#803)
* Support attaching XDP program per NIC.

* PR Feedback.

* fix bug.

* PR Feedback.
2022-03-14 15:16:11 -07:00
Alan Jowett c6d36834f2
Add mutual auth for RPC client / server. (#804)
* Add mutual auth for RPC client / server.

RPC client and server should authenticate each other, to ensure:

Only admin client makes a call to ebpfsvc.
Client is talking only to ebpfsvc.

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2022-03-14 15:26:55 -06:00
Alan Jowett 16760b2b3d
Add queue and stack helper functions (#801)
* Add queue and stack helper functions

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2022-03-11 17:16:02 -07:00
Dave Thaler 727451f3b4
Add support for integer arguments to bpf_printk helper (#797)
* Initial printk numeric args support

Also add a verification failure test case if trying to print a pointer

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

* Add varargs support to printk

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

* Validate printk format specifiers

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

* Verify that printk specifier count and arg count match

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

* Update doxygen docs

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

Co-authored-by: saxena-anurag <43585259+saxena-anurag@users.noreply.github.com>
2022-03-10 17:16:45 -08: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 08c2cbb9a7
Add support for bpf_printk helper without additional arguments (#796)
* Initial version of bpf_printk support

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

* Convert printk.c sample to use bind hook instead of xdp hook

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

* Add wprp file to deployment script

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

* Unify UM and KM platforms as much as possible for printk support

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

* Fix annotation

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

* Work around compiler warning

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

* Fix comment

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

* Fix keyword

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

* Fix test when -s is used

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-03-08 16:38:48 -08:00
saxena-anurag 2384d6c123
rename ebpf_object to ebpf_core_object (#793) 2022-03-07 09:07:10 -08:00
Alan Jowett 9890a6bf66
Add test to trigger division by zero handler (#791)
* Add test to trigger division by zero handler

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

* Fix bugcheck in interpreter on division by zero

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

* PR feedback

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2022-03-03 14:30:01 -07:00
Alan Jowett bd2aa504e1
Refactor ebpf_provider_load/ebpf_extension_load and move generation of module_id to caller (#773)
* Move generation of module_id into caller of ebpf platform NMR wrapper

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2022-02-28 09:09:33 -07:00
Alan Jowett 960e0a0a2a
Pickup latest ebpf-verifier to resolve #630 (#765)
* Pickup latest ebpf-verifier to resolve this issue

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

* Strip paths from netsh output

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

* Pickup latest ebpf-verifier changes

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

* Switch to run CI/CD on Server 2019 + VS2019

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

* Pickup fix for https://github.com/vbpf/ebpf-verifier/issues/306

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

* Pickup fix for https://github.com/vbpf/ebpf-verifier/issues/306

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

* PR feedback

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

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-02-25 16:17:23 -08:00
Dave Thaler ecf4ac988e
Fix bpf_map_update_elem prototype used by the verifier (#781)
It had four arguments in:
* https://github.com/microsoft/ebpf-for-windows/blob/master/include/bpf_helper_defs.h#L33
* https://github.com/microsoft/ebpf-for-windows/blob/master/libs/execution_context/ebpf_core.c#L1261

but only three arguments in ebpf_general_helpers.c

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-02-25 15:44:28 -08:00
Dave Thaler 59c0b4e185
Allow attaching an XDP program to a specific ifindex (#755)
* Allow attaching an XDP program to a specific ifindex
* Update tests since droppacket.o changed
* Add ifindex use back to droppacket.c for testing purposes
* Verify xdp program to unlink is actually an XDP program
* Add comment re moving xdp fd replace logic to execution context
* Add libbpf test and add support for bpf_xdp_query_id

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-02-14 16:40:56 -08:00
Dave Thaler 34598edf84
Update bpftool and libbpf dependencies (#744)
* Update bpftool

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

* Update paths to libbpf and bpftool

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

* Add more libbpf APIs

* Added bpf_map_create, bpf_object__next_map, bpf_object__next_program, bpf_object__prev_map, bpf_object__prev_program
* Removed obsolete exports ebpf_create_map and ebpf_create_map_name
* Updated prototype of bpf_program__attach and bpf_progam__attach_xdp to
  match latest libbpf header

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

* Address code review feedback

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-02-08 13:21:19 -08:00
Alan Jowett d98a296d42
Add option EBPF_JIT_ALWAYS_ON to permit building EC with no interpreter (#742)
* Add option EBPF_JIT_ALWAYS_ON to permit building EC with no interpreter

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

* Add documentation on using compile time options

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

* Set EBPF_JIT_ALWAYS_ON for release builds

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

* Tests should expect interpret to fail if EBPF_JIT_ALWAYS_ON is defined

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

* Rename EBPF_JIT_ALWAYS_ON to CONFIG_BPF_JIT_ALWAYS_ON

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

* Tests should expect interpret to fail if EBPF_JIT_ALWAYS_ON is defined

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

* Update docs/GettingStarted.md

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

* Load returns EBPF_PROGRAM_LOAD_FAILED

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

* Split up load into individual test cases

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

* Program load fails with EBPF_PROGRAM_LOAD_FAILED

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

* Skip tests that depend on interpret mode when it's disabled

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

* PR feedback

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

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-02-04 10:41:52 -07:00
Shankar Seal 48f0ff60e2
fix CICD script to throw on test failure. (#741)
* fix script.

* temporary workaround.

* fix test.
2022-01-31 21:23:23 -08:00
saxena-anurag 6b4dda75a1
remove ebpf_api_initiate, ebpf_api_terminate from sources (#738)
* remove ebpf_api_initiate, ebpf_api_terminate from sources

* cleaup traces

* cleanup traces
2022-01-31 08:32:28 -08:00
Shankar Seal a782d86ce1
refactor maps (#719)
* refactor maps

* PR Feedback.
2022-01-24 18:26:45 -08:00
Dave Thaler 8dc0f5e1b5
Support map fds with bpf_load_program (#718)
* Support map fds with bpf_load_program

Fixes #714

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

* Address code review feedback

Also do some code cleanup

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

* Address feedback

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-01-14 14:11:19 -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 41f5fd1b29
Add bpf_load_program, bpf_load_program_xattr APIs (#710)
* Add bpf_load_program, bpf_load_program_xattr APIs

Fixes #186

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

* Address review feedback

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

* Address code review feedback

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-01-07 10:31:31 -08:00
saxena-anurag eecc851f32
Add support to clear prog array entry (#680)
* add support to clear prog array entry

* cr comments

* cr comments

Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-12-13 12:22:35 -07:00
Shankar Seal 91e74be955
ring buffer map. (#659)
* ring buffer map.

* PR Feedback iteration 0.

* PR Feedback iteration 1

* Fix race.

* PR Feedback iteration 2

* bugfix.

* Bug fix.

* Fix test issue

* PR Feedback.

* Update libs/api_common/device_helper.cpp

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-12-03 13:19:21 -08:00
saxena-anurag 5328bf3f14
tail_call fix (#670)
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-11-23 12:38:29 -08:00
Alan Jowett f920f9d1f5
Fix crash in kernel on divide by zero (#667)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-11-19 11:56:32 -08:00
saxena-anurag 3b118fa779
netebpfext fix (#663) 2021-11-18 14:24:55 -08:00
Alan Jowett 123e7a2626
Fix driver verifier failure due to not setting the flag to indicate pages are locked (#653)
* Fix driver verifier failure due to not setting the flag to indicate pages are locked

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

* PR feedback

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-11-10 13:48:58 -07: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
Alan Jowett f3a10a1b0e
Update external/ubpf to latest (#650)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-11-03 10:24:54 -06:00
Alan Jowett 260a8d77dc
Instrument eBPF for Windows platform layer (#647)
* Instrument eBPF Core with tracing

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-11-03 09:33:40 -06:00
Alan Jowett 043f16691e
Add initial infrastructure to trace function entry/exit in eBPF (#646)
* Add initial infrastructure to trace function entry/exit in eBPF

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

* Offline feedback

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

* Fix verifier false positive

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-10-27 09:57:23 -06:00
Dave Thaler f15fd232c7
Preserve ebpf_result values up through user mode APIs (#642)
* Rename win32 error code APIs for internal consistency

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

* Update error mappings

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

* Replace unstable NTSTATUS code with a documented one

STATUS_FILE_NOT_SUPPORTED does not appear in MS-ERREF and support varies
by OS version so cannot be relied on.  Replaced with
STATUS_INVALID_IMAGE_FORMAT.

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-10-25 14:35:25 -07:00
Alan Jowett be119ea8b6
Add code in mock layer and driver to handle async requests (#632)
* Add logic to track asynchronous operations

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-10-14 14:22:35 -06:00
Alan Jowett ee6a81bc74
Add logic to track asynchronous ebpf operations (#626)
* Add logic to track asynchronous operations

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>

* Switch to American spelling

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

* Update libs/platform/ebpf_completion.h

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

* Update libs/platform/ebpf_completion.h

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

* Rename ebpf_completion to ebpf_async

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

* Backport fixes from #632

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

* PR feedback

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

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-10-11 16:03:22 -06:00
Alan Jowett 01f9c471c9
Implement simple version of BPF_MAP_TYPE_STACK (#617)
* Implement simple version of BPF_MAP_TYPE_STACK

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

* PR feedback

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

* Update libs/execution_context/ebpf_maps.c

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

* Update libs/execution_context/ebpf_maps.c

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

* Fix rename of error code on merge

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

* PR feedback

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

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-10-07 12:44:36 -06:00
Alan Jowett 8cb38f9837
Core platform support for ring buffer. (#606)
* Add support for ebpf_ring_buffer_t construct to core platform

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

* PR feedback

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

* Fix build break

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

* PR feedback

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

* Eliminate undefined behavior around calculating remaining space

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-10-05 15:18:28 -06:00
Shankar Seal 4dfff59f49
make bpf_csum_diff a global helper. (#625)
* make bpf_csum_diff a global helper.
2021-10-04 11:29:36 -07:00
Alan Jowett 244325d8cd
Add performance test for LRU map (#607)
* Add performance test for LRU map

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

* Add additional test for BPF_MAP_TYPE_LRU_HASH

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

* More bug fixes

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

* Fix build break

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-10-01 18:07:19 -06:00
saxena-anurag 1bbbc41233
add auto-pinning option for maps. (#612)
* add auto-pinning option

* Apply suggestions from code review

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

* Configure custom pin_root_path using bpf_object_open_opts

* use new api for map-in-map, remove pinning restriction for inner map, remove workaround for inner map id

* code cleanup

* cr comments

* Apply suggestions from code review

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

* fix bad merge

Co-authored-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-10-01 09:01:39 -06:00
saxena-anurag ea5add0cc6
add inner_id support for map of map (#619)
* add inner_id support

* cleanup

* cr comments

* cr comments
2021-09-30 15:14:26 -07:00
Dave Thaler 80c953280e
Add libbpf bpf_prog_bind_map() API (#611)
* Add libbpf bpf_prog_bind_map() API

Fixes #379

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

* Fix SAL annotation

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

* Fix leak

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

* Address feedback

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

* Make program lock protect the set of maps associated with the program

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

Co-authored-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: saxena-anurag <43585259+saxena-anurag@users.noreply.github.com>
2021-09-30 11:43:06 -06:00
Alan Jowett a3d035bc38
Provide more details on how ebpf_bitmap_t works. (#610)
* PR feedback to clarify how bitmap works

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-29 20:10:01 -07:00
Alan Jowett bc104c03f3
Add support for bpf_map_lookup_and_delete_elem & BPF_MAP_TYPE_QUEUE (#605)
* Add support for BPF_MAP_TYPE_QUEUE
* Expose bpf_map_lookup_and_delete_elem helper and API

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-09-29 18:47:30 -06:00
Dave Thaler cd77fe694b
Add libbpf bpf_create_map_in_map() API (#613)
* Add libbpf bpf_create_map_in_map() API

* bpf_create_map() now fails for outer maps.  You must use
  bpf_create_map_in_map() instead.
* Fix bug where EBPF_INVALID_FD was incorrectly converted to
  EBPF_INVALID_ARGUMENT by ioctl handling code (part of issue #595)
  One symptom of this bug was that errno was being set to EINVAL
  in a number of cases which should have been EBADF.
* Fix bug where a HASH_OF_MAPS (unlike ARRAY_OF_MAPS) wasn't enforcing
  that an inner map value had to match the inner map template.
  Refactored the code in ebpf_maps.c so the checking is in done in one
  place called by both maps, to ensure consistency.
* Fix bug in HASH_OF_MAPS where if an update failed, it would leave
  the old entry but incorrectly drop the reference it held.  It now
  preserves the reference since the entry is unchanged.
* Added test case for ARRAY_OF_MAPS created via libbpf.  Previously
  only HASH_OF_MAPS creation was tested for that path.

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

* Fix bug caught by kernel test

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-29 14:13:24 -07:00
Alan Jowett 082d938501
Implement BPF_MAP_TYPE_LPM_TRIE over lock-free hashmap. (#572)
* Implement BPF_MAP_TYPE_LPM_TRIE over lock-free hashmap.

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-28 13:27:50 -07: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
Alan Jowett 6bb51b9e0d
Fix stack overrun and fix EC to return correct size (#604)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-24 21:05:03 -07:00
Dave Thaler 65390d8baa
Simple error code conversion fixes (#596)
Addresses part of issue #595
A more comprehensive fix is left for a separate PR.
This PR fixes some bad error messages from bpftool.

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-24 10:58:57 -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
Alan Jowett 73eb08680f
Implement trivial version of BPF_MAP_TYPE_LPM_TRIE (#565)
* Implement trivial lpm trie map implementation

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-22 18:36:37 -06:00
Alan Jowett c31901ce43
Fix ebpf_set_current_thread_affinity (#592)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-22 13:48:21 -06:00
Alan Jowett c794dc9141
Move release of maps to program release (#590)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-21 19:03:54 -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
Alan Jowett 3305fae5df
Set thread affinity during ioctl calls (#580)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-09-21 10:17:27 -06:00
Shankar Seal 9d01eb45c1
Fix EbpfProgramType for sample extension. (#569)
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-09-20 13:00:21 -07:00
Alan Jowett 107d915b0d
Switch ebpf_pinning_table_get_next_name to use ebpf_utf8_string_t (#552)
* Switch ebpf_pinning_table_get_next_name to use ebpf_utf8_string_t

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-20 13:42:22 -06:00
Dave Thaler d806803a8a
Add libbpf bpf_create_map_xattr() API (#571)
* Add libbpf bpf_create_map_xattr() API

Needed for bpftool and other apps

* Add bpf_create_map_xattr() which allows creating maps with extended
  attributes such as name
* Remove unused ebpf_api_create_map()

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-20 11:58:00 -07: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
Dave Thaler 956244fb72
Improve netsh show programs functionality (#548)
* Improve netsh show programs functionality

* Rename ebpf_get_next_pinned_program_name to ebpf_get_next_pinned_program_path for clarity
* Show link count and pinned path count
* Support "level=verbose" format
* Support filtering by attached and/or pinned

Fixes #188

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-17 16:41:43 -07:00
Alan Jowett 9903a29409
Add BPF_MAP_TYPE_LRU_HASH (#556)
* Add LRU HASH map

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-17 10:28:49 -07:00
Dave Thaler f0cbb6da84
Fix bugs in ebpf_state and ebpf_object (#554)
* Fix bug where getting the next ID failed to check for index beyond array size.

* 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.

The tests in PR #553 cover both of these bugs.

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

Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-09-16 18:00:38 -06:00
Alan Jowett 967990f700
Disable /ZI and incremental linking (#546)
* Disable /ZI and incremental linking

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-16 16:49:02 -06:00
Dave Thaler 872999db06
Add netsh capability to unpin programs (#539)
* Add netsh capability to unpin programs

* The netsh "set program id=<id> pinned=" (with no value) will now unpin a
  program from all paths
* The netsh "delete program <id>" will now unpin a program from all
  paths before and releasing any reference held by netsh itself
* Make the "attached=<string>" argument to netsh set programs work
  with a section name like string
* Add libbpf api bpf_obj_get()
* Add ebpf_get_next_pinned_program_name() API to enumerate pinned
  programs

Fixes #190 #373

This is required for #188 which will update the "show programs"
and also add an option to "add program" to pin all programs rather
than just the first one in a file, like bpftool has such an option.

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

* Update mock netsh behavior since PR 540 changed the underlying requirements

PreprocessCommand now correctly matches tags so you can specify a later
optional tag without having to specify earlier optional tags

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-15 18:40:44 -07:00
Dave Thaler aa09128ae0
Add libpf's libbpf_prog_type_by_name() API (#534)
* Add libpf's libbpf_prog_type_by_name() API

And add an ebpf_get_program_type_by_name() that returns the GUIDs
instead of ints.

This also removes the hard-coding of GUIDs or ints from the netsh
helper.

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-15 12:08:18 -07:00
Alan Jowett 7b9b6a7b1a
Fail link initialize if loading extension fails (#540)
* Fail link initialize if loading extension fails

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-15 12:11:13 -06:00
Alan Jowett 36784bbac4
Provide blurb to explain how pinning table works (#538)
* Provide blurb to explain how pinning table works

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-15 10:21:06 -07:00
Dave Thaler 12bb2e7195
Update netsh commands to use more standard libbpf apis (#527)
* Update netsh commands to use more standard libbpf apis

* Add support for libbpf bpf_obj_pin() API
* Add support for libbpf bpf_object__next() API
* Rename BPF_{PROG,ATTACH}_TYPE_UNKNOWN to ...UNSPEC for libbpf compat
* Remove now-unused handle APIs ebpf_api_load_program and
  ebpf_api_pin_object, which is part of issue #383
  * netsh set/delete program now uses the ID to identify the program,
    like bpftool does, so that it can work even if the program wasn't
    loaded from an ELF file

Fixes #191

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-14 10:59:57 -07:00
Alan Jowett f5ba5c5d7c
Use CRT library to map handles to fds (#513)
* Use CRT library to map handles to fds

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-14 09:25:56 -06:00
Alan Jowett e553150b1b
Switch from MultiThreadedDebug to MultiThreadedDebugDll (#528)
* Switch from MultiThreadedDebug to MultiThreadedDebugDll
* Pull in latest ebpf-verifier

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-14 08:46:01 -06:00
Shankar Seal e84efdf092
Xdp adjust head part1 (#522)
xdp_adjust_head : Part 1
2021-09-13 17:46:23 -07:00
Dave Thaler b6a0fb84b9
Add support for libbpf bpf_obj_get_info_by_fd API (#510)
* Add support for libbpf bpf_obj_get_info_by_fd API

This is the last libbpf api needed to enable the bpftool
flow to detach an already loaded program.

The count of maps is changed from size_t to uint32_t for
consistency with libbpf and because it's not actually a size
in the sizeof() sense, it's a count in the countof() sense.

Also fix bug where map_name was never being set in the kernel

Fixes #372

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-10 21:54:07 -07:00
Alan Jowett f0a07e7dd0
Switch to ExAllocatePoolZero (#509)
Resolves: #506

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-10 17:35:03 -06:00
Alan Jowett 7e12a6f920
Add support for bpf_ktime_get_ns (#511)
* Add support for bpf_ktime_get_ns

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-10 12:45:52 -06:00
Dave Thaler 38952de71a
Require all inner map attributes to match (#508)
Updated the map_in_map.c test to use HASH instead of ARRAY as the inner
map type, to make it possible to test key_size mismatch (since key_size
must be 4 for all ARRAY maps, it can't be tested with ARRAY).

Fixes #507

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-09 21:11:19 -07:00
Dave Thaler c8d3ab9e73
Store ID in maps instead of fds and object pointers (#497)
Fixes #396

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-09 16:02:42 -07:00
Dave Thaler 2349de2a46
Add object IDs (#487)
* Add object IDs

Add support for the following libbpf APIs:
* bpf_{link,map,prog}_get_fd_by_id
* bpf_{link,map,prog}_get_next_id

Addresses the main part of #396.
A subsequent PR will handle the rest of 396 which includes:
* remove "extra_value" complexity from maps

The changes in api_common.hpp and libbpf_internal.h are from PR 482 and so will go
away in a rebase once that PR is merged.

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

* Address PR feedback

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

* Address PR feedback

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

* Address PR feedback

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-07 09:54:08 -07:00
Shankar Seal dae2a4def5
clean up test code (#492)
* cleanup test code.

* PR feedback.
2021-09-07 08:46:07 -07:00
Dave Thaler 5f5e2c0d1f
Add bpf_link_detach and bpf_link__fd APIs (#482)
* Add bpf_link_detach and bpf_link__fd APIs

Fixes #372

Addresses leftover TODO comments referencing issue 81.

Fixes bug where errno was not being set to correct errno values

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-03 14:51:50 -07:00
saxena-anurag cec8bd0014
Fix bpf_link__destroy(), add bpf_link__disconnect() (#485)
* api changes

* fix

* Apply suggestions from code review

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

* changes

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-09-03 12:21:04 -07:00
Alan Jowett f6d46d1b38
BPF_MAP_TYPE_PERCPU* should pad values to EBPF_CACHE_LINE_SIZE (#486)
* Cache align map structures

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-02 20:06:32 -07:00
Shankar Seal ec68058a36
Test utility helper functions. (#480)
* Test utility helper functions.

* fix build break.

* PR feedback.

* PR feedback.
2021-09-02 17:23:16 -07:00
Alan Jowett ffdc71166e
ebpf_epoch: _ebpf_flush_timer_set should be per-CPU (#481)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-02 13:55:45 -06:00
Dave Thaler dd3f1b427c
Rename ebpf_helpers.h to bpf_helpers.h for cross-plat compat (#472)
Libbpf has bpf_helpers.h which is mostly platform-agnostic, and
bpf_helper_defs.h which is platform-specific but is included
by bpf_helpers.h.   Until libbpf is made more platform-agnostic
(issue #351), the workaround is to have a separate pair of files.
Our bpf_helpers.h and our own bpf_helper_defs.h, both of which
would ideally be merged into libbpf's in the future.

Platform-specific defines are in ebpf_struct.h, though that
name may need to change later on.  Linux uses "linux/bpf.h"
(e.g., as used in the https://docs.cilium.io/en/v1.8/bpf/ and
https://developers.redhat.com/blog/2021/04/01/get-started-with-xdp
articles) or "vmlinux.h" (e.g., as used in the
https://ruderich.org/simon/notes/xdp-minimal-example article),
and these filenames are hard coded in eBPF programs.  In the future,
we should probably settle on a cross-platform name and use include
paths to distinguish them, as opposed to requiring ifdefs in eBPF
programs.  However, all of that is part of issue 351 and not this
issue.

Also removed obsolete/unused "repro.c" from tests/samples

Fixes #426

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

Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-09-01 16:30:33 -07:00
Dave Thaler d5c275acb3
Add netsh command to show maps (#476)
Signed-off-by: Dave Thaler <dthaler@microsoft.com>

Co-authored-by: saxena-anurag <43585259+saxena-anurag@users.noreply.github.com>
2021-09-01 08:10:39 -07:00
Alan Jowett 2aaa711f7d
Revert untested changes to epbf_epoch.c (#475)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-08-31 21:19:31 -07:00
Alan Jowett 27c4c8f681
All per-CPU structures should be allocated on EBPF_CACHE_LINE_SIZE boundaries (#471)
* All per-CPU structures should be allocated on EBPF_CACHE_LINE_SIZE boundaries

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-08-31 18:21:00 -06:00
Alan Jowett ff47814b90
Workaround for issue where ProcDump64 swallows return codes. (#469)
* Set ProcDump64 as Just-In-Time debugger and set to capture dumps.
Fail test if dumps are generated.

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-08-31 14:21:22 -07:00
Alan Jowett 2e62286c9c
Simplified epoch tracking code to fix bugs hit in non-preemptive path. (#446)
* Fix epoch bugs and add performance tests
* Align ebpf_epoch_cpu_entry_t to CPU cache size to avoid false sharing

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-08-31 09:00:21 -06:00
Shankar Seal 16856deb0a
Pass program handle in GET_PROGRAM_INFO message. (#463)
* fix

* PR feedback.

* Apply suggestions from code review

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

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-08-30 20:15:09 -07:00
Dave Thaler 0a1555956e
Add map-in-map type checking (#451)
* Add map-in-map type checking

This PR enforces that all inner maps must be of the same type
as the inner map template used for verification.  Other fields
might need to match too, and if so those will be updated in
a subsequent PR once it is confirmed which fields must match.

A few pieces of this PR related to map_id are prerequisites
for issue #396 which will add IDs for programs, maps, and links.

Finally, there are multiple definitions of bpf_map, since the
version used to write eBPF programs is different from what is
stored in memory (which uses map IDs) so to avoid confusion in
code and allow the compiler to do type checking to catch some
bugs, this splits ebpf_map_definition_t into two, one for
in_memory and one for in_file (meaning in an eBPF program).
This will also allow the future PR for issue 396 to be more
understandable, but also aids clarity in some parts of this PR.

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-08-30 19:14:08 -07:00
Shankar Seal c764977442
utility general helper functions. (#450) 2021-08-28 11:05:57 -07:00
Shankar Seal 7be9ef61dc
Fix bugs in kernel platform library. (#447)
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-08-27 11:59:58 -06:00
Alan Jowett f5e18cd4d8
Partition epoch thread list (#436)
* Partition epoch thread list
Perform memory free on epoch_exit

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-08-26 19:00:15 -06:00
Alan Jowett 4be43a7ea1
Include required Clang version (#431)
* Update Getting Started to recommend current release version of Clang/LLVM

Clang-format behaves differently depending on the version of Clang installed.
Update getting started guide to recommend Clang / LLVM 10.0.0.
Update the development guide to indicate that Clang 10 or higher is required for consistent formatting.
Reformat all code using Clang 10.0.0

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-08-25 09:01:16 -06:00
Alan Jowett c9d40f09c4
Fix bug in epoch rundown and flush timer (#432)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-08-24 16:17:24 -06:00
Dave Thaler ea3765fc7c
Add tests for libbpf bpf_map_*_elem APIs (#429)
* Add tests for libbpf bpf_map_*_elem APIs

* Return correct error between EBPF_OBJECT_ALREADY_EXISTS (A program or
map is already pinned with the *same* path) vs
EBPF_ALREADY_PINNED (The program or map already pinned to a *different*
path).

* Update vs lookup elem were inconsistent in whether returning
  EBPF_KEY_NOT_FOUND vs EBPF_INVALID_ARGUMENT when passing an array
  index >= max_entries.  Made them be consistent in using
  EBPF_INVALID_ARGUMENT.

Fixes #376

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-08-24 11:33:00 -07:00
Dave Thaler f45e80d385
Add map-in-map support (#408)
* Add map-in-map support

Replace UM ebpf_map_update/delete_element with libbpf-compliant
bpf_map_update/delete_elem

This adds the basic functionality needed for #375

Not in this PR, but in a subsequent PR:
* ensure that all inner maps match the one specified by inner_map_idx,
  much like prog_types have to match in a prog_array.
* ensure that putting a prog_array in an array of maps adheres to the
  prog_array contract that any associated progs have to match the
  type of the calling program.
* read a map id not fd when UM reads the value (will be done together
  with issue #396 since also affects prog_arrays)

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-08-23 18:46:24 -07:00
Alan Jowett 2035ef7366
Add support for stack unwind on success. (#367)
Signed-off-by: Alan Jowett alanjo@microsoft.com
2021-08-23 17:24:22 -06:00
Alan Jowett 764fd17222
Fully support BPF flags for map operations (#425)
* Fully support BPF flags for map operations

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-08-23 15:49:50 -06:00
Alan Jowett 024abd4534
PR feedback from #418 (#424)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-08-23 14:49:26 -06:00
Shankar Seal 5519c26f5b
Register program type specific helper functions to uBPF in interpreted mode (#402)
* Register program type specific helper functions to uBPF in interpreted mode.

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-08-23 12:24:45 -07:00
Alan Jowett b917cc5ba8
Partition epoch free list by CPU (#418)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-08-23 08:58:59 -06:00
Alan Jowett 9b184645eb
Stop searching once key is matched (#413)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-08-21 10:13:15 -06:00
Alan Jowett ea821f3f21
Immediately delete memory during rundown (#407)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-08-20 21:41:54 -06:00
Alan Jowett 16a951c2c3
Switch to hash table from AVL. Lock free in the presence of epoch allocator. (#389)
* Switch to hash table from AVL.
Lock free in the presence of epoch allocator.

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-08-20 18:29:11 -06:00
Shankar Seal d61c905e43
fix epoch bug (#410) 2021-08-20 17:16:24 -07:00
Dave Thaler c99a43e5e9
Revert "Remove dead code (#381)" (#401)
This reverts commit 7d779cf117.
2021-08-20 12:07:57 -07:00
Alan Jowett 6ac7be59a4
ebpf_program_t.links should be initialized (#395)
* Fix issue #394

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-08-20 11:04:32 -07:00
Alan Jowett da3b0a0cc1
Fix leak of ebpf_core_map_t.name.value (#393)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-08-20 11:02:21 -06:00
Dave Thaler 74c456e6b7
Update UM map APIs for libbpf compat (#388)
Since there is a name conflict between KM helpers and UM libbpf APIs,
the end-to-end tests need to _not_ include the KM helper prototypes,
so removed ebpf_helpers.h from ebpf.h and made samples include it
directly.

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-08-18 21:06:58 -07:00
Alan Jowett 184b1945d6
Adds support for querying per-CPU maps from user mode and returning a merged view of the per-CPU data (#384)
* Implement per-cpu maps using trivial option

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-08-17 17:22:32 -06:00
Shankar Seal 7d779cf117
Remove dead code (#381)
* Remove dead code

* Address PR feedback

Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-08-13 14:56:36 -06:00
Alan Jowett e68dece71d
Explicit key and value lengths passed to map layer (#380)
* Explicit key and value lengths passed to map layer

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-08-13 13:13:16 -06:00
Alan Jowett 8cc5a7f5be
Add support for per-cpu hash and array maps - Part 1 (#378)
Add support for per-cpu hash and array maps

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-08-11 16:39:54 -06:00
Dave Thaler 7c12adb067
Prevent mismatched program types in PROG_ARRAY maps (#374)
* Prevent mismatched program types in PROG_ARRAY maps

* Each prog array map has a natural progtype, determined when
  asociating it from a program, or when adding the first program
  to it, if not associated with any program.
* Trying to add a program with mismatching type will fail
* Added libbpf bpf_create_map() API
* Fixed error returns from several libbpf APIs to be negative
* For efficiency, ebpf_program_get_properties now returns a
  pointer rather than copying the data inside the execution
  context, and is renamed to ebpf_program_get_parameters()
  to match what its return type always was.
* Fixed a bug in map size calculation that resulted in a huge
  amount of memory being allocated
* Updated return type of bpf_tail_call to the value meant
  to signal stack unwind needed

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-08-11 12:17:10 -07:00
saxena-anurag 014ee34392
Add eBPF UM APIs (#368)
* parse map names from elf file
* add apis, change test code

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-08-10 17:04:07 -07:00
Dave Thaler 8f46b4020f
Revert "Add code to propagate flags for helper functions. (#365)" (#366)
This reverts commit e9a565fd0a.
2021-08-09 14:37:40 -07:00
Alan Jowett e9a565fd0a
Add code to propagate flags for helper functions. (#365)
* Add code to propagate flags for helper functions.

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-08-09 13:33:31 -07:00
Dave Thaler 30246d0025
Fix return values from bpf_map_delete_elem etc helpers (#362)
Per https://github.com/iovisor/bpf-docs/blob/master/bpf_helpers.rst
negative numbers indicate failure.

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-08-09 09:41:15 -06:00
Shankar Seal be67121fda
Test Extension Part 2 (#361)
* Test Extension Part 2

* rename test extension to sample extension and update Getting-started doc.

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-08-07 14:19:00 -07:00
Alan Jowett 0fee94598b
Pull latest ubpf (#360)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-08-06 15:35:36 -07:00
Dave Thaler a321179cee
Add prog array map type and bpf_tail_call() helper (#359)
* Add prog array map type and bpf_tail_call()

This also fixes a bug where bpf_object__find_program_by_name
could only find the first program because program->object
was always null.

Also fixes tests to correctly use a signed int for what hooks return,
instead of an unsigned int.

Not done in this PR, but will be in a separate PR:
* make tail call replace stack frame instead of simply calling into the callee
* limit number of tail calls to 32
* require the same program type for caller and callee
* test with load byte array instead of from a file

Addresses part of #344

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

* Address PR feedback

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

* Address PR feedback

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

* Add missing file

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

* Disable warning due to C enum types used in C++

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-08-06 14:18:47 -06:00
Alan Jowett e706d82daa
Change bpf_map_update_elem to return result of insertion (#358)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-08-05 14:32:44 -06:00
Dave Thaler 2617349903
Remove duplicate public APIs where standard libbpf APIs exist (#356)
* Remove duplicate public APIs where standard libbpf APIs exist

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-08-03 17:25:50 -07:00
saxena-anurag 14248601d3
Add DETACH operation to detach a program from a hook. (#352)
* add UNLINK operation

* Some fixes:

1. Added attach_lock to synchronize multiple detach calls on same link object.
2. ebpf_extension_unload() should be called from ebpf_link_detach_program()
3. Changed return type of ebpf_program_get_properties to void.

* Update libs/execution_context/ebpf_program.c

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-07-30 17:17:16 -07:00
Dave Thaler 8006f181e0
Libbpf API compatibility (#350)
* Libbpf API compatibility

Libbpf is incorporated as a submodule just for the header file.
As discussed in issue #84, we cannot currently use the implementation
since it is very Linux and GCC specific.

This PR also fixes a bug where the user-mode API was calling
CloseHandle directly instead of Platform::CloseHandle which is needed
to make tests work with the mock platform.

Addresses #84

Some code will be cleaner once issue #81 is done

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-07-30 15:34:21 -07:00
Alan Jowett 4bebd3aaa1
Verify that program type is supported by attach provider (#348)
* Verify that program type is supported by attach provider

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-07-27 16:33:58 -07:00
Shankar Seal 18456999b7
move map helper function prototypes to EC (#337)
* move map helper function prototypes to EC
* replace 'generic' by 'general'

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-07-22 15:31:01 -07:00
Shankar Seal 266578ee63
test extension - Part 1 (#336)
* test extension
2021-07-14 14:40:34 -07:00
Dave Thaler 4d0ac1bd4d
Replace "information" with "info" for consistency (#331)
Previously some places had "info" and some had "information".
Both appear in dictionaries, so guidance to avoid abbreviations does not apply.

Fixes #314

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-07-07 11:16:35 -07:00
Dave Thaler 569da02a8f
Add main API reference page (#329)
Which will fill in content visible at https://microsoft.github.io/ebpf-for-windows/

Fixes #259

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-07-07 10:39:59 -07:00
Alan Jowett 9681a918ad
Fix issues flagged by CodeQL code scan (#324)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-06-30 11:11:27 -06:00
Shankar Seal f96522ecd4
fix sal on safeint functions (#321)
* fix sal on safeint functions

Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-06-29 21:42:40 -07:00
Alan Jowett 0cf75fef7d
Fix C6386 warning in ebpf_epoch_initiate (#320)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-06-29 17:13:13 -06:00
Dave Thaler d8a26f2b6d
Revert C6011 override (#319)
Fixes #309

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

Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-06-29 16:39:03 -06:00
Alan Jowett 7870921e02
Additional analysis fixes (#315)
* Fix C26110,C28023,C28193,C6001,C6031,C6054
* Fix C6101

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

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-06-29 15:51:41 -06:00
Shankar Seal a93f4ba714
program information serialization (#302)
* program information serialization.

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-06-28 16:47:34 -07:00
Alan Jowett a0801d410c
Suppress C26451 (#312)
* Suppress C26451 and related errors

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-06-28 16:13:29 -07:00
Alan Jowett a7e7b69661
C6387 fixes (#311)
* C6387 fixes

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>
2021-06-25 16:02:05 -06:00
Alan Jowett 9d798031b4
Fix warnings due to C6011 - NULL pointer deref (#307)
* Switch from _Pre_maybenull_ to _In_opt_

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

* Fix C6011

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

* Fix C6011 in PreprocessCommand

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-06-25 10:24:03 -06:00
Alan Jowett 7101b164bd
Fix inconsistent annotation (#303)
* Fix inconsistent annotation

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

* Suppress mismatched annotation from ntintsafe.h

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

* Fix annotation

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

* Fix inconsistent annotation

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

* Suppress wrong annotation from ntintsafe.h

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

* Fix annotation

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>

* Revert incorrect SAL change

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-06-24 16:39:27 -06:00
Dave Thaler 5a5dbc63a7
Add additional netsh tests (#298)
Fix a couple bugs that the tests uncovered
Remove duplicate "error: error:" prefix in messages on verification

Fixes #240

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

Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-06-23 19:12:20 -06:00
saxena-anurag b0bb08907b
add execution type to ebpf_program_load() (#297)
* add execution type to ebpf_program_load()

* cr comments
2021-06-23 18:54:03 -06:00
Dave Thaler 360aa224ea
Add some netsh tests (#295)
Adds tests for "show sections" and "show disassembly"

Addresses part of issue #240

Signed-off-by: Dave Thaler <dthaler@ntdev.microsoft.com>
2021-06-23 09:54:36 -07:00
saxena-anurag c31547cff5
Add ebpf public APIs - #1 (#290)
* add ebpf_program_load(), few other APIs
2021-06-22 20:42:18 -07:00
Alan Jowett 3027b82df0
Unify unit tests (#294)
* Unify unit tests

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

* PR feedback

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-06-22 12:22:50 -06:00
Dave Thaler dc157726da
Add some more SAL annotations and clean up some code analysis warnings (#277)
* Make a couple of `_In_` arguments be const
* Add `_opt_` to a number of arguments that can be NULL
* Add SAL annotation to a few more APIs that were missing it
* Remove annotations like
  `_Pre_readable_byte_size_(hash_table->key_size)` since they just give
  code analysis warnings such as:
  ```
  c:\git\dthaler\ebpf-for-windows\libs\platform\ebpf_platform.h(445):
  warning C28230: The type of '_Param_(1)' has no member 'key_size'.
  c:\git\dthaler\ebpf-for-windows\libs\platform\ebpf_platform.h(445):
  warning C28285: For function 'ebpf_hash_table_delete' '_Param_(2)'
  syntax error in
  'SAL_readableTo(byteCount(__formal(0,hash_table)->key_size))' near
  'key_size))'.
  ```

Signed-off-by: Dave Thaler <dthaler@ntdev.microsoft.com>
2021-06-16 13:27:22 -07:00
Dave Thaler 2200ab915f
Merge eBPF types with the types in ebpf-verifier (#282)
Remove duplicate types:
* ebpf_helper_return_type_t
* ebpf_helper_argument_type_t
* ebpf_context_descriptor_t

https://github.com/vbpf/ebpf-verifier/pull/238 already made the
necessary changes in the PREVAIL project, which got rid of the
issue with VOID and so the 'undef VOID' workarounds are removed
in the present PR.

Signed-off-by: Dave Thaler <dthaler@ntdev.microsoft.com>
2021-06-16 11:53:21 -07:00
Dave Thaler a46b00c2e3
Add VM setup scripts and docs (#281)
* Create an install script rather than having to manually do lots
  of steps
* Make Debug build use vcruntime as static libs to avoid adding
  another prerequisite on a machine before installing eBPF.  This
  isn't required for Release builds as vcruntime release DLLs
  are part of Windows, unlike vcruntime debug DLLs

Fixes #248

Signed-off-by: Dave Thaler <dthaler@ntdev.microsoft.com>
2021-06-15 08:44:43 -07:00
Alan Jowett 9e8b88a41a
Switch to approved license header format (#268)
* Switch to approved license header format

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-06-10 12:02:00 -07:00
Alan Jowett 877cb22ec0
First pass of adding SAL annotations (#253)
* First pass of adding SAL annotations

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

* Finish annotating platform

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

* Cleanup annotation to get lock tracking work correctly

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

* PR feedback and fix static analysis issues

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>

* Fix build break from merge

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-06-10 10:45:23 -06:00
Shankar Seal 613ee57092
Core review comments from PR 246 (#261)
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-06-09 20:28:23 -07:00
Dave Thaler 6be20d7aad
Simplify names of some ebpf_result codes (#256)
* Simplify names of some ebpf_result codes

* Remove _ERROR_ for consistency
* Combine EBPF_INVALID_HANDLE and EBPF_INVALID_OBJECT
* Rename EBPF_ERROR_NOT_FOUND to EBPF_KEY_NOT_FOUND for consistency with the associated description.
* Change code that returned EBPF_ERROR_NOT_FOUND for a case other than a
key, to use a different appropriate result, so the description stays correct.

Fixes #212

Signed-off-by: Dave Thaler <dthaler@ntdev.microsoft.com>
2021-06-09 19:32:57 -07:00
Shankar Seal 27f8d49888
API to create map and enumerate all pinned maps. (#246)
* API to create map and enumerate all pinned maps.

* Apply suggestions from code review

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

* Address code review comments

* Address code review comments #2

* Address code review comments #3

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-06-09 09:44:24 -06:00
Alan Jowett a69d6f55ad
Synchronize client detach and hook invocation (#255)
* Synchonize client detach and hook invocation

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

* Check for detached program before invoking

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

* PR feedback

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-06-09 09:17:50 -06:00
Alan Jowett 4e4c19314f
Remap helper_ids to range [0,63] (#252)
* Remap helper_ids to range [0,63]

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

* PR feedback

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-06-08 15:33:00 -06:00