Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: Always
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros: ['bf_list_foreach', 'bf_list_foreach_rev', 'bf_rpack_array_foreach']
ForEachMacros: ['bf_hashset_foreach', 'bf_list_foreach', 'bf_list_foreach_rev', 'bf_rpack_array_foreach']
IncludeBlocks: Regroup
IncludeCategories:
# net/if.h needs to be included BEFORE linux/if.h to avoid conflicts
Expand Down
10 changes: 4 additions & 6 deletions src/bfcli/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,15 @@ void bfc_chain_dump(struct bf_chain *chain, struct bf_hookopts *hookopts,
}
(void)fprintf(stdout, ") in {\n");

bf_list_foreach (&set->elems, elem_node) {
bf_hashset_foreach (&set->elems, node) {
uint32_t payload_idx = 0;
void *payload = bf_list_node_get_data(elem_node);

(void)fprintf(stdout, " ");
for (size_t i = 0; i < set->n_comps; ++i) {
const struct bf_matcher_meta *meta =
bf_matcher_get_meta(set->key[i]);

meta->ops[BF_MATCHER_IN].print(payload + payload_idx);
meta->ops[BF_MATCHER_IN].print(node->data + payload_idx);
payload_idx += meta->ops[BF_MATCHER_IN].ref_payload_size;

if (i != set->n_comps - 1)
Expand Down Expand Up @@ -220,16 +219,15 @@ void bfc_chain_dump(struct bf_chain *chain, struct bf_hookopts *hookopts,
} else {
(void)fprintf(stdout, ") in {\n");

bf_list_foreach (&set->elems, elem_node) {
bf_hashset_foreach (&set->elems, node) {
uint32_t payload_idx = 0;
void *payload = bf_list_node_get_data(elem_node);

(void)fprintf(stdout, " ");
for (size_t i = 0; i < set->n_comps; ++i) {
const struct bf_matcher_meta *meta =
bf_matcher_get_meta(set->key[i]);

meta->ops[BF_MATCHER_IN].print(payload +
meta->ops[BF_MATCHER_IN].print(node->data +
payload_idx);
payload_idx +=
meta->ops[BF_MATCHER_IN].ref_payload_size;
Expand Down
2 changes: 2 additions & 0 deletions src/libbpfilter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(libbpfilter_srcs
${CMAKE_CURRENT_SOURCE_DIR}/include/bpfilter/hook.h
${CMAKE_CURRENT_SOURCE_DIR}/include/bpfilter/if.h
${CMAKE_CURRENT_SOURCE_DIR}/include/bpfilter/io.h
${CMAKE_CURRENT_SOURCE_DIR}/include/bpfilter/core/hashset.h
${CMAKE_CURRENT_SOURCE_DIR}/include/bpfilter/core/list.h
${CMAKE_CURRENT_SOURCE_DIR}/include/bpfilter/logger.h
${CMAKE_CURRENT_SOURCE_DIR}/include/bpfilter/matcher.h
Expand All @@ -45,6 +46,7 @@ set(libbpfilter_srcs
${CMAKE_CURRENT_SOURCE_DIR}/hook.c
${CMAKE_CURRENT_SOURCE_DIR}/if.c
${CMAKE_CURRENT_SOURCE_DIR}/io.c
${CMAKE_CURRENT_SOURCE_DIR}/core/hashset.c
${CMAKE_CURRENT_SOURCE_DIR}/core/list.c
${CMAKE_CURRENT_SOURCE_DIR}/logger.c
${CMAKE_CURRENT_SOURCE_DIR}/matcher.c
Expand Down
2 changes: 1 addition & 1 deletion src/libbpfilter/cgen/prog/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ int bf_map_new_from_set(struct bf_map **map, const char *name,
return _bf_map_new(map, name, BF_MAP_TYPE_SET,
set->use_trie ? BF_BPF_MAP_TYPE_LPM_TRIE :
BF_BPF_MAP_TYPE_HASH,
set->elem_size, 1, bf_list_size(&set->elems));
set->elem_size, 1, bf_hashset_size(&set->elems));
}

int bf_map_new_from_pack(struct bf_map **map, int dir_fd, bf_rpack_node_t node)
Expand Down
8 changes: 3 additions & 5 deletions src/libbpfilter/cgen/program.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ static int _bf_program_load_sets_maps(struct bf_program *new_prog)
_free_bf_map_ struct bf_map *map = NULL;
_cleanup_free_ uint8_t *values = NULL;
_cleanup_free_ uint8_t *keys = NULL;
size_t nelems = bf_list_size(&set->elems);
size_t nelems = bf_hashset_size(&set->elems);
size_t idx = 0;

if (!nelems) {
Expand All @@ -748,10 +748,8 @@ static int _bf_program_load_sets_maps(struct bf_program *new_prog)
if (!keys)
return bf_err_r(errno, "failed to allocate map keys");

bf_list_foreach (&set->elems, elem_node) {
void *elem = bf_list_node_get_data(elem_node);

memcpy(keys + (idx * set->elem_size), elem, set->elem_size);
bf_hashset_foreach (&set->elems, elem) {
memcpy(keys + (idx * set->elem_size), elem->data, set->elem_size);
values[idx] = 1;
++idx;
}
Expand Down
Loading
Loading