Skip to content
Draft
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', 'bf_set_foreach', 'bf_vector_foreach']
IncludeBlocks: Regroup
IncludeCategories:
# net/if.h needs to be included BEFORE linux/if.h to avoid conflicts
Expand Down
2 changes: 1 addition & 1 deletion src/bfcli/chain.c
Copy link
Contributor

Choose a reason for hiding this comment

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

Not fan of bpfilter/data_structures/... path. As we're moving to daemon-less, I would suggest bpfilter/core/..., which will later on contain other core structures of the project (e.g. bf_chain).

Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include <bpfilter/bpfilter.h>
#include <bpfilter/chain.h>
#include <bpfilter/counter.h>
#include <bpfilter/data_structures/list.h>
#include <bpfilter/helper.h>
#include <bpfilter/hook.h>
#include <bpfilter/list.h>
#include <bpfilter/logger.h>
#include <bpfilter/set.h>

Expand Down
2 changes: 1 addition & 1 deletion src/bfcli/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

#include <bpfilter/bpfilter.h>
#include <bpfilter/chain.h>
#include <bpfilter/data_structures/list.h>
#include <bpfilter/helper.h>
#include <bpfilter/hook.h>
#include <bpfilter/list.h>
#include <bpfilter/logger.h>
#include <bpfilter/request.h>
#include <bpfilter/response.h>
Expand Down
2 changes: 1 addition & 1 deletion src/bfcli/opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <bpfilter/helper.h>

#include "bpfilter/list.h"
#include "bpfilter/data_structures/list.h"
#include "chain.h"
#include "ruleset.h"

Expand Down
4 changes: 2 additions & 2 deletions src/bfcli/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <stdlib.h>
#include <stdbool.h>

#include <bpfilter/list.h>
#include <bpfilter/data_structures/list.h>
#include <bpfilter/if.h>

#include "ruleset.h"
Expand All @@ -30,7 +30,7 @@
#include <bpfilter/verdict.h>
#include <bpfilter/hook.h>
#include <bpfilter/matcher.h>
#include <bpfilter/list.h>
#include <bpfilter/data_structures/list.h>
#include <bpfilter/rule.h>
#include <bpfilter/chain.h>
#include <bpfilter/runtime.h>
Expand Down
45 changes: 23 additions & 22 deletions src/bfcli/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

#include <bpfilter/chain.h>
#include <bpfilter/counter.h>
#include <bpfilter/data_structures/list.h>
#include <bpfilter/helper.h>
#include <bpfilter/hook.h>
#include <bpfilter/list.h>
#include <bpfilter/logger.h>
#include <bpfilter/matcher.h>
#include <bpfilter/rule.h>
Expand Down Expand Up @@ -148,31 +148,31 @@ void bfc_chain_dump(struct bf_chain *chain, struct bf_hookopts *hookopts,
bf_list_foreach (&chain->sets, set_node) {
struct bf_set *set = bf_list_node_get_data(set_node);

if (!set->name)
if (!bf_set_get_name(set))
continue;

(void)fprintf(stdout, " set %s (", set->name);
for (size_t i = 0; i < set->n_comps; ++i) {
(void)fprintf(stdout, "%s", bf_matcher_type_to_str(set->key[i]));
(void)fprintf(stdout, " set %s (", bf_set_get_name(set));
for (size_t i = 0; i < bf_set_get_n_comps(set); ++i) {
(void)fprintf(stdout, "%s",
bf_matcher_type_to_str(bf_set_get_key_comp(set, i)));

if (i != set->n_comps - 1)
if (i != bf_set_get_n_comps(set) - 1)
(void)fprintf(stdout, ", ");
}
(void)fprintf(stdout, ") in {\n");

bf_list_foreach (&set->elems, elem_node) {
bf_set_foreach (set, payload) {
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) {
for (size_t i = 0; i < bf_set_get_n_comps(set); ++i) {
const struct bf_matcher_meta *meta =
bf_matcher_get_meta(set->key[i]);
bf_matcher_get_meta(bf_set_get_key_comp(set, i));

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

if (i != set->n_comps - 1)
if (i != bf_set_get_n_comps(set) - 1)
(void)fprintf(stdout, ", ");
}
(void)fprintf(stdout, "\n");
Expand All @@ -196,34 +196,35 @@ void bfc_chain_dump(struct bf_chain *chain, struct bf_hookopts *hookopts,
bf_chain_get_set_for_matcher(chain, matcher);

(void)fprintf(stdout, " (");
for (size_t i = 0; i < set->n_comps; ++i) {
(void)fprintf(stdout, "%s",
bf_matcher_type_to_str(set->key[i]));
for (size_t i = 0; i < bf_set_get_n_comps(set); ++i) {
(void)fprintf(
stdout, "%s",
bf_matcher_type_to_str(bf_set_get_key_comp(set, i)));

if (i != set->n_comps - 1)
if (i != bf_set_get_n_comps(set) - 1)
(void)fprintf(stdout, ", ");
}

if (set->name) {
(void)fprintf(stdout, ") in %s", set->name);
if (bf_set_get_name(set)) {
(void)fprintf(stdout, ") in %s", bf_set_get_name(set));
} else {
(void)fprintf(stdout, ") in {\n");

bf_list_foreach (&set->elems, elem_node) {
bf_set_foreach (set, payload) {
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) {
for (size_t i = 0; i < bf_set_get_n_comps(set); ++i) {
const struct bf_matcher_meta *meta =
bf_matcher_get_meta(set->key[i]);
bf_matcher_get_meta(
bf_set_get_key_comp(set, i));

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

if (i != set->n_comps - 1)
if (i != bf_set_get_n_comps(set) - 1)
(void)fprintf(stdout, ", ");
}
(void)fprintf(stdout, "\n");
Expand Down
2 changes: 1 addition & 1 deletion src/bfcli/print.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <stdbool.h>

#include <bpfilter/list.h>
#include <bpfilter/data_structures/list.h>
#include <bpfilter/runtime.h>

struct bf_chain;
Expand Down
2 changes: 1 addition & 1 deletion src/bfcli/ruleset.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#pragma once

#include <bpfilter/chain.h>
#include <bpfilter/data_structures/list.h>
#include <bpfilter/hook.h>
#include <bpfilter/list.h>
#include <bpfilter/set.h>

#define bfc_ruleset_default() \
Expand Down
2 changes: 1 addition & 1 deletion src/bpfilter/cgen/cgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
#include <bpfilter/bpf.h>
#include <bpfilter/chain.h>
#include <bpfilter/counter.h>
#include <bpfilter/data_structures/list.h>
#include <bpfilter/dump.h>
#include <bpfilter/helper.h>
#include <bpfilter/hook.h>
#include <bpfilter/io.h>
#include <bpfilter/list.h>
#include <bpfilter/logger.h>
#include <bpfilter/ns.h>
#include <bpfilter/pack.h>
Expand Down
2 changes: 1 addition & 1 deletion src/bpfilter/cgen/cgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <stdint.h>

#include <bpfilter/counter.h>
#include <bpfilter/data_structures/list.h>
#include <bpfilter/dump.h>
#include <bpfilter/list.h>
#include <bpfilter/pack.h>

struct bf_chain;
Expand Down
2 changes: 1 addition & 1 deletion src/bpfilter/cgen/elfstub.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <stddef.h>

#include <bpfilter/list.h>
#include <bpfilter/data_structures/list.h>

/**
* @file elfstub.h
Expand Down
2 changes: 1 addition & 1 deletion src/bpfilter/cgen/handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

#include <bpfilter/bpf.h>
#include <bpfilter/counter.h>
#include <bpfilter/data_structures/list.h>
#include <bpfilter/dump.h>
#include <bpfilter/helper.h>
#include <bpfilter/hook.h>
#include <bpfilter/list.h>
#include <bpfilter/logger.h>
#include <bpfilter/pack.h>

Expand Down
2 changes: 1 addition & 1 deletion src/bpfilter/cgen/handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

#include <linux/bpf.h>

#include <bpfilter/data_structures/list.h>
#include <bpfilter/dump.h>
#include <bpfilter/hook.h>
#include <bpfilter/list.h>
#include <bpfilter/pack.h>

struct bf_link;
Expand Down
2 changes: 1 addition & 1 deletion src/bpfilter/cgen/printer.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include <stdlib.h>
#include <string.h>

#include <bpfilter/data_structures/list.h>
#include <bpfilter/dump.h>
#include <bpfilter/helper.h>
#include <bpfilter/list.h>
#include <bpfilter/logger.h>
#include <bpfilter/pack.h>

Expand Down
2 changes: 1 addition & 1 deletion src/bpfilter/cgen/prog/link.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

#include <linux/bpf.h>

#include <bpfilter/data_structures/list.h>
#include <bpfilter/dump.h>
#include <bpfilter/hook.h>
#include <bpfilter/list.h>
#include <bpfilter/pack.h>

/**
Expand Down
2 changes: 1 addition & 1 deletion src/bpfilter/cgen/prog/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,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_set_size(set));
}

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/bpfilter/cgen/program.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
#include <bpfilter/btf.h>
#include <bpfilter/chain.h>
#include <bpfilter/counter.h>
#include <bpfilter/data_structures/list.h>
#include <bpfilter/dump.h>
#include <bpfilter/flavor.h>
#include <bpfilter/helper.h>
#include <bpfilter/hook.h>
#include <bpfilter/io.h>
#include <bpfilter/list.h>
#include <bpfilter/logger.h>
#include <bpfilter/matcher.h>
#include <bpfilter/pack.h>
Expand Down Expand Up @@ -697,7 +697,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_set_size(set);
size_t idx = 0;

if (!nelems) {
Expand All @@ -721,9 +721,7 @@ 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);

bf_set_foreach (set, elem) {
memcpy(keys + (idx * set->elem_size), elem, set->elem_size);
values[idx] = 1;
++idx;
Expand Down
2 changes: 1 addition & 1 deletion src/bpfilter/cgen/program.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#include <stdint.h>

#include <bpfilter/chain.h>
#include <bpfilter/data_structures/list.h>
#include <bpfilter/dump.h>
#include <bpfilter/flavor.h>
#include <bpfilter/helper.h>
#include <bpfilter/list.h>
#include <bpfilter/pack.h>

#include "cgen/elfstub.h"
Expand Down
2 changes: 1 addition & 1 deletion src/bpfilter/cgen/swich.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include <stdlib.h>
#include <string.h>

#include <bpfilter/data_structures/list.h>
#include <bpfilter/helper.h>
#include <bpfilter/list.h>
#include <bpfilter/logger.h>

#include "cgen/jmp.h"
Expand Down
2 changes: 1 addition & 1 deletion src/bpfilter/cgen/swich.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <stddef.h>
#include <stdint.h>

#include <bpfilter/data_structures/list.h>
#include <bpfilter/helper.h>
#include <bpfilter/list.h>

/**
* @file swich.h
Expand Down
2 changes: 1 addition & 1 deletion src/bpfilter/ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
#include <bpfilter/bpf.h>
#include <bpfilter/btf.h>
#include <bpfilter/chain.h>
#include <bpfilter/data_structures/list.h>
#include <bpfilter/dump.h>
#include <bpfilter/helper.h>
#include <bpfilter/hook.h>
#include <bpfilter/io.h>
#include <bpfilter/list.h>
#include <bpfilter/logger.h>
#include <bpfilter/ns.h>
#include <bpfilter/pack.h>
Expand Down
2 changes: 1 addition & 1 deletion src/bpfilter/ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <stdbool.h>
#include <stdint.h>

#include <bpfilter/data_structures/list.h>
#include <bpfilter/dump.h>
#include <bpfilter/list.h>

#include "cgen/elfstub.h"

Expand Down
2 changes: 1 addition & 1 deletion src/bpfilter/xlate.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

#include <bpfilter/chain.h>
#include <bpfilter/counter.h>
#include <bpfilter/data_structures/list.h>
#include <bpfilter/helper.h>
#include <bpfilter/hook.h>
#include <bpfilter/io.h>
#include <bpfilter/list.h>
#include <bpfilter/logger.h>
#include <bpfilter/pack.h>
#include <bpfilter/request.h>
Expand Down
8 changes: 6 additions & 2 deletions src/libbpfilter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ 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/list.h
${CMAKE_CURRENT_SOURCE_DIR}/include/bpfilter/data_structures/hashset.h
${CMAKE_CURRENT_SOURCE_DIR}/include/bpfilter/data_structures/list.h
${CMAKE_CURRENT_SOURCE_DIR}/include/bpfilter/logger.h
${CMAKE_CURRENT_SOURCE_DIR}/include/bpfilter/matcher.h
${CMAKE_CURRENT_SOURCE_DIR}/include/bpfilter/ns.h
Expand All @@ -29,6 +30,7 @@ set(libbpfilter_srcs
${CMAKE_CURRENT_SOURCE_DIR}/include/bpfilter/rule.h
${CMAKE_CURRENT_SOURCE_DIR}/include/bpfilter/runtime.h
${CMAKE_CURRENT_SOURCE_DIR}/include/bpfilter/set.h
${CMAKE_CURRENT_SOURCE_DIR}/include/bpfilter/data_structures/vector.h
${CMAKE_CURRENT_SOURCE_DIR}/include/bpfilter/verdict.h

# Private sources and headers
Expand All @@ -44,7 +46,8 @@ 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}/list.c
${CMAKE_CURRENT_SOURCE_DIR}/data_structures/hashset.c
${CMAKE_CURRENT_SOURCE_DIR}/data_structures/list.c
${CMAKE_CURRENT_SOURCE_DIR}/logger.c
${CMAKE_CURRENT_SOURCE_DIR}/matcher.c
${CMAKE_CURRENT_SOURCE_DIR}/pack.c
Expand All @@ -53,6 +56,7 @@ set(libbpfilter_srcs
${CMAKE_CURRENT_SOURCE_DIR}/response.c
${CMAKE_CURRENT_SOURCE_DIR}/rule.c
${CMAKE_CURRENT_SOURCE_DIR}/set.c
${CMAKE_CURRENT_SOURCE_DIR}/data_structures/vector.c
${CMAKE_CURRENT_SOURCE_DIR}/verdict.c
${CMAKE_CURRENT_SOURCE_DIR}/version.c

Expand Down
Loading
Loading