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

57 Коммитов

Автор SHA1 Сообщение Дата
Dave Thaler 3a9958f501
Support "netsh ebpf show sections" with native drivers (#1070)
* WIP: enumerate sections in native code

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

* Make bpf2c emit section names

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

* More of PE section enumeration

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

* Fix program type and map count display for native programs

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

* Update cmake files

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

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

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

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

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

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

* Address PR feedback

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

* Force inlining utility functions inside ebpf programs

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

* Update expected output

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

* More expected output changes

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

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

To match libbpf behavior

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

* Fix test

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

* Resolve analysis warnings

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

* Fix analysis warnings

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

* Address PR comments from Anurag

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

* Fix test

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-05-11 14:06:49 -07:00
Dave Thaler 1e1b18e374
Add support for bpf_program__type (#1074)
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-05-09 10:11:48 -07:00
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
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
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
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 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
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 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
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
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
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
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
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
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
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 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
Dave Thaler 1a17769087
Add program type and attach type to netsh output (#603)
* Add program type to netsh "show programs" output
* Add attach type to netsh "show links" output

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

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

Fixes #575

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-23 19:32:09 -07:00
Dave Thaler 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 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 cdcf793a54
Move generated include to include (#564)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-17 17:13:14 -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
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
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 866f8a6917
Fix non-determinism in build due to multiple projects generating header (#496)
* Fix non-determinism in build due to multiple projects generating header
* Only regenerate git_commit_id.h on change

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-07 13:22:49 -06: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
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 74daa0fcec
Set ps unrestricted (#483)
* Set ExecutionPolicy Unrestricted for PS script in build

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-02 14:54:03 -06:00
Alan Jowett ac9b6282b8
Add version info to ebpfcore.sys, ebpfapi.dll, netebpfext.sys, and ebpfsvc.exe (#478)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-09-01 17:57:35 -06:00
Shankar Seal c764977442
utility general helper functions. (#450) 2021-08-28 11:05:57 -07: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
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
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
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
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
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
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
saxena-anurag c31547cff5
Add ebpf public APIs - #1 (#290)
* add ebpf_program_load(), few other APIs
2021-06-22 20:42:18 -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