Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions libs/ebpfnetsh/pins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,26 @@ handle_ebpf_show_pins(
// Read all pin paths. Currently we get them in a non-deterministic
// order, so we use a std::set to sort them in code point order.
char pinpath[EBPF_MAX_PIN_PATH_LENGTH] = "";
ebpf_object_type_t object_type = EBPF_OBJECT_PROGRAM;
std::set<std::string> paths;
ebpf_object_type_t object_type = EBPF_OBJECT_UNKNOWN;
std::set<std::string> program_paths;
std::set<std::string> map_paths;
while (ebpf_get_next_pinned_object_path(pinpath, pinpath, sizeof(pinpath), &object_type) == EBPF_SUCCESS) {
paths.insert(pinpath);
switch (object_type) {
case EBPF_OBJECT_PROGRAM:
program_paths.insert(pinpath);
break;
case EBPF_OBJECT_MAP:
map_paths.insert(pinpath);
break;
default:
// Ignore.
break;
}
object_type = EBPF_OBJECT_UNKNOWN;
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting object_type to EBPF_OBJECT_UNKNOWN after each iteration appears unnecessary. The ebpf_get_next_pinned_object_path function should set the object_type as an output parameter for each call.

Suggested change
object_type = EBPF_OBJECT_UNKNOWN;
// object_type = EBPF_OBJECT_UNKNOWN; // Unnecessary, removed.

Copilot uses AI. Check for mistakes.
}

// Now walk through all paths in code point order.
for (auto path : paths) {
for (auto path : program_paths) {
int program_fd = bpf_obj_get(path.c_str());
if (program_fd < 0) {
continue;
Expand All @@ -62,5 +74,19 @@ handle_ebpf_show_pins(

Platform::_close(program_fd);
}
for (auto path : map_paths) {
int map_fd = bpf_obj_get(path.c_str());
if (map_fd < 0) {
continue;
}

struct bpf_map_info info = {};
uint32_t info_size = (uint32_t)sizeof(info);
if (bpf_obj_get_info_by_fd(map_fd, &info, &info_size) == 0) {
printf("%7u Map %s\n", info.id, path.c_str());
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The output format string uses different spacing/alignment compared to the program output format. Consider using consistent formatting between program and map entries for better readability.

Suggested change
printf("%7u Map %s\n", info.id, path.c_str());
printf("%7u %-7s %s\n", info.id, "Map", path.c_str());

Copilot uses AI. Check for mistakes.
}

Platform::_close(map_fd);
}
return NO_ERROR;
}
Loading