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

36 Коммитов

Автор SHA1 Сообщение Дата
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
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 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
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
Alan Jowett aa87ee0ce2
Emit either bare code, sys, or dll (#769)
* Emit either bare code, sys, or dll

Resolve #767
2022-02-24 11:18:28 -07: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
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
Dave Thaler f184993c66
Add doxygen comments on all map types and map options (#675)
* Add doxygen comments on all map types and map options

Fixes #672

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

* Address PR comment

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-11-29 11:47:58 -08: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
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
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
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 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
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
Dave Thaler 6d3be2a0c2
Fix netsh "show maps" output (#581)
* Fix netsh "show maps" output

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

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

* Fix rebase

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

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

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

Addresses #549

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-17 18:52:47 -07:00
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 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 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 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 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 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 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
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 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 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 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
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 e825caaa8e
Add doxygen documentation on enum values (#322)
* Make all enum values have a description in the generated API docs
* Also remove SAL annotation from the generated docs, since SAL
  breaks doxygen type detection

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

Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-06-30 10:22:40 -06: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
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