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

234 Коммитов

Автор SHA1 Сообщение Дата
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