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

29 Коммитов

Автор SHA1 Сообщение Дата
Sharmi 54632eb360
Set errno for bpf_object__find_map_by_name (#3712)
* Initial Commit

* Initialize errno

* Set errno for bpf_object__find_map_by_name

* Added Doxygen comment
2024-07-23 18:32:28 +00:00
Sharmi ee17c08a11
Add batch map APIs in Doxygen documentation (#3652)
* Added doxygen style doc for batch map APIs supported.

* Removed dot.

* Updated bpf_map_lookup_and_delete_batch keys, values

* Updated docs for the batch APIs

* Updated docs for the batch APIs
2024-07-10 05:26:39 +00:00
Dave Thaler 7b3f682ded
Implement libbpf autoload APIs (#3592)
* Implement libbpf autoload APIs

Fixes #3555

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

* Suppress spurious compiler warning

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

* Fix test failure

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

* Update tests

Files with no program sections succeed loading

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

* Address PR comment from Anurag

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

* PR feedback

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

* Fix test

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

* Prevent changing prog type of a native program

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

* PR feedback

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

* Remove unused program_type from native load ioctl

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

* Update default autoload value

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

* PR feedback

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

* Fix test

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

* Add check to unit_test to match api_test

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

* Fix api_test

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

---------

Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
2024-06-03 15:28:04 +00:00
Dave Thaler d096b21ac5
Update copyright to be eBPF for Windows contributors (#3508)
* Update copyright to be eBPF for Windows contributors

Fixes #3507

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

* Undo gratuitous formatting changes in expected files

---------

Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
2024-05-04 19:55:56 +00:00
Dave Thaler 3d626ff9c1
Clean up order of includes (#2015)
* Clean up order of includes

Fixes #1963

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

* Update clang-format

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

* Clean up headers

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

* Update sort

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

* FIx various build errors

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

* Fix ordering if including a .c file

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

* Fix cmake build

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

* More header cleanup

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

* Update expected bpf2c output

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

* More header fixes

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

* Update expected bpf2c output for custom bpf.c

The generate script does not handle this file.

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

* Fix tests

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

* Fix more expected bpf2c output

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

---------

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Co-authored-by: Anurag Saxena <43585259+saxena-anurag@users.noreply.github.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2023-02-07 18:32:19 +00:00
Dave Thaler d4ca06954c
Change global variable to a static member per DevelopmentGuide (#1858)
* Change global variable to a static member per development guide

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

* Fix comment in include file

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

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2023-01-11 19:02:31 +00:00
Alan Jowett 0b293ad804
Fix code analysis annotations for In and In_opt parameters by adding const where appropriate or changing to Inout where appropriate. (#1749)
* Fix code analysis annotations for _In_ and _In_opt_ parameters,
add const where appropriate or change to _Inout_ where appropriate.

The following regex expressions were used to find the problems:
Find _In_ or _In_opt_ that are not const and are not followed by _Post_invalid_ or _Frees_ptr_ or _Post_ptr_invalid_:
```_In_[ ]+(?!.*(const|_Post_invalid_|_Frees_ptr_|_Post_ptr_invalid_))```
```_In_opt_[ ]+(?!.*(const|_Post_invalid_|_Frees_ptr_|_Post_ptr_invalid_))```

Some of the _In_ and _In_opt_ parameters are not const due to required compatibility with the Windows API.
Pointers to functions are const by definition, so the const qualifier is not required.

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

* PR feedback

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

* Fix code analysis failure

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

* PR feedback

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

* PR feedback

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

* PR feedback

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

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2022-12-15 15:58:33 -08:00
Alan Jowett 58cdfdcf8a
Spelling (#1601)
* Fix spelling in docs

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

* Fix spelling in ebpfsvc

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

* Fix include

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

* Fix libs part 1

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

* Fix libs part 2

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

* Fix tests

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

* Fix tools

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

* Fix build

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

* PR feedback

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

* Fix generated files

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

* PR feedback

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

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Anurag Saxena <43585259+saxena-anurag@users.noreply.github.com>
2022-11-16 14:06:14 -07:00
Dave Thaler 568e8f0bdf
Add ability to enumerate maps associated with a program (#1395)
* Add map ids test

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

* Enumerate maps associated with a program

Fixes #1339

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

* Initialize info before calling

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

* Update bpftool

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

* Make "netsh show prog l=v" show map ids for program

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

* Return EFAULT if map_ids is not a valid pointer

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

* Fix warning

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

* More test fixes

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

* Fix test

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

* Fix socket test

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

* Add more checks in the socket test

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

* Fix socket test

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

* Fix netsh

Also fix GettingStarted.md and a missing space in the logs
that were found while testing this fix.

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

* Set map_ids on output

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

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-09-30 12:12:12 -07:00
Shankar Seal 782244b4f0
remove deprecated prog_load API. (#1352)
* remove deprecated prog_load API.

* PR Feedback.

* PR Feedback.
2022-08-25 09:18:05 -06:00
Dave Thaler 6888b14533
bpf_object__open_file() should allow null opts (#1363)
Fixes #1354

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

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-08-23 21:11:27 -07:00
Dave Thaler 61eddd268d
Update bpftool (#1337)
* Update bpftool

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

* Fix cmake build

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

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-08-23 13:46:29 -07:00
Shankar Seal e4ccdc8b1c
Implement `bpf_prog_detach` and `bpf_prog_detach2` APIs. (#1311)
* Implement bpf_prog_detach and bpf_prog_detach2 APIs.

* fix SAL break.

* PR feedback.

* PR feedback and test changes.

* PR feedback.
2022-08-07 17:21:23 -07:00
Dave Thaler 7e0738ee07
Add support for new libbpf APIs (#1288)
* Update to latest libbpf .h files

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

* Add libbpf_bpf_{prog,attach}_type_str APIs

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

* Add libbpf_attach_type_by_name

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

* Add libbpf_bpf_{link,map}_type_str

And add tests for prog type and attach type names

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

* Add tests

And change type names to match Linux

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

* Fix cmake build

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

* Update tests

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

* Update docs

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

* Add bpf_program__insn_cnt()

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

* Add MSVC deprecated attribute to most deprecated APIs

Still haven't done bpf_object__next() or bpf_prog_load_deprecated()

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

* Mark bpf_object__next was deprecated

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

* Fix some test failures

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

* Suppress instead of disable deprecated warnings

To simplify diffs

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

* Merge with latest main

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

* PR feedback

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-07-29 14:57:30 -04:00
Dave Thaler 063ed2a4f8
Update to latest libbpf and bpftool (#1155)
* Update to latest libbpf and bpftool

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

* Fix test

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

* Update to latest verifier commit

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-05-31 17:43:39 -07:00
Dave Thaler bec56bc8c3
Add (non-deprecated) bpf_prog_load API support (#1130)
* Add bpf_prog_load()
* Move prototype for bpf_prog_load_deprecated() from libbpf.h to bpf.h
  to match libbpf
* Mark as deprecated bpf_object__load_xattr(), bpf_load_program(), and
  bpf_load_program_xattr() to match libbpf
* Make bpf_load_program_xattr() support the program name field, where
  previously it was ignored and a random name was used.

Fixes #1073

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-05-24 16:12:00 -07:00
Dave Thaler 4718bf7a73
Support bpf_object__load() with native programs (#1133)
* Make bpf_object__open_file work with native files

* Update bpf_object__open_file()
* Add bpf_object__open()
* Rename ebpf_enumerate_sections() to ebpf_enumerate_program_sections()

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

* Remove ebpf_program_load

And add a couple of windows-specific libbpf related APIs

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

* Fix bug in enumerate sections hit by tail_call_multiple_um.dll

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

* Fix program_name field in object_open

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

* Cleanup

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

* Fix order of PE sections returned

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

* Bug fix

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

* Bug fix

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

* Bug fix and revert enumerate_sections rename

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

* Updated expected bpf2c output

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

* Fix analysis warning

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

* Updated issue number in TODO comments

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

* Address Anurag's feedback

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-05-24 14:53:04 -07:00
Dave Thaler b7df2bec27
Document whether to close fds returned from various APIs (#1095)
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-05-12 16:21:16 -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
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
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
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
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
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
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 599230fd3f
Libbpf doxygen fixes (#608)
* Libbpf doxygen fixes

* Add missing bpf_map__name
* Move bpf_object__unload to be in alphabetical order

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-28 17:22:31 -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