From 33fed971c8375d844107805693b85523ea2c5ceb Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Fri, 21 Jun 2024 14:37:48 +0200 Subject: [PATCH] treewide: rename the project to grout Signed-off-by: Robin Jarry --- .clang-format | 2 +- .github/workflows/ci.yml | 6 +- README.md | 45 ++-- api/br_bitops.h | 13 -- api/{br_api.h => gr_api.h} | 24 +-- ...api_client_impl.h => gr_api_client_impl.h} | 22 +- api/gr_bitops.h | 13 ++ api/{br_macro.h => gr_macro.h} | 4 +- api/{br_net_types.h => gr_net_types.h} | 16 +- api/{br_stb_ds.h => gr_stb_ds.h} | 4 +- api/{br_string.h => gr_string.h} | 4 +- api/meson.build | 8 +- api/stb_ds_impl.c | 4 +- api/string.c | 2 +- cli/complete.c | 2 +- cli/complete.h | 4 +- cli/ec_node_devargs.c | 2 +- cli/ec_node_dyn.c | 20 +- cli/ecoli.c | 6 +- cli/exec.c | 16 +- cli/exec.h | 10 +- cli/{br_cli.h => gr_cli.h} | 26 +-- cli/{br_table.h => gr_table.h} | 4 +- cli/interact.c | 8 +- cli/interact.h | 8 +- cli/log.c | 2 +- cli/log.h | 4 +- cli/main.c | 30 +-- cli/quit.c | 8 +- cli/table.c | 2 +- docs/graph.svg | 4 +- docs/{br.1.scd => grout.1.scd} | 12 +- docs/meson.build | 2 +- main/control.c | 46 ++-- main/control.h | 10 +- main/dpdk.c | 24 +-- main/dpdk.h | 8 +- main/{br.h => gr.h} | 8 +- main/{br_cmocka.h => gr_cmocka.h} | 0 main/{br_control.h => gr_control.h} | 24 +-- main/{br_log.h => gr_log.h} | 14 +- main/{br_queue.h => gr_queue.h} | 4 +- main/main.c | 30 +-- main/signals.c | 2 +- main/signals.h | 4 +- meson.build | 12 +- modules/infra/api/br_infra.h | 200 ------------------ modules/infra/api/gr_infra.h | 200 ++++++++++++++++++ modules/infra/api/graph.c | 16 +- modules/infra/api/iface.c | 64 +++--- modules/infra/api/meson.build | 2 +- modules/infra/api/rxq.c | 32 +-- modules/infra/api/stats.c | 46 ++-- .../cli/{br_cli_iface.h => gr_cli_iface.h} | 22 +- modules/infra/cli/graph.c | 16 +- modules/infra/cli/iface.c | 128 +++++------ modules/infra/cli/port.c | 82 +++---- modules/infra/cli/stats.c | 46 ++-- modules/infra/cli/vlan.c | 78 +++---- .../infra/control/{br_graph.h => gr_graph.h} | 26 +-- .../infra/control/{br_iface.h => gr_iface.h} | 8 +- .../infra/control/{br_port.h => gr_port.h} | 6 +- .../infra/control/{br_vlan.h => gr_vlan.h} | 6 +- .../control/{br_worker.h => gr_worker.h} | 4 +- modules/infra/control/graph.c | 48 ++--- modules/infra/control/graph_priv.h | 6 +- modules/infra/control/iface.c | 30 +-- modules/infra/control/port.c | 68 +++--- modules/infra/control/vlan.c | 34 +-- modules/infra/control/worker.c | 28 +-- modules/infra/control/worker_priv.h | 6 +- modules/infra/control/worker_test.c | 24 +-- modules/infra/datapath/br_eth_input.h | 18 -- modules/infra/datapath/drop.c | 4 +- modules/infra/datapath/eth_input.c | 20 +- modules/infra/datapath/eth_output.c | 22 +- .../datapath/{br_datapath.h => gr_datapath.h} | 10 +- modules/infra/datapath/gr_eth_input.h | 18 ++ .../{br_eth_output.h => gr_eth_output.h} | 10 +- .../infra/datapath/{br_mbuf.h => gr_mbuf.h} | 20 +- modules/infra/datapath/{br_rx.h => gr_rx.h} | 4 +- modules/infra/datapath/{br_tx.h => gr_tx.h} | 4 +- modules/infra/datapath/main_loop.c | 20 +- modules/infra/datapath/mbuf.c | 20 +- modules/infra/datapath/rx.c | 22 +- modules/infra/datapath/tx.c | 16 +- modules/ip/api/br_ip4.h | 177 ---------------- modules/ip/api/gr_ip4.h | 177 ++++++++++++++++ modules/ip/api/meson.build | 2 +- modules/ip/cli/address.c | 48 ++--- modules/ip/cli/ip.h | 6 +- modules/ip/cli/nexthop.c | 48 ++--- modules/ip/cli/route.c | 52 ++--- modules/ip/control/address.c | 56 ++--- .../{br_ip4_control.h => gr_ip4_control.h} | 10 +- modules/ip/control/nexthop.c | 80 +++---- modules/ip/control/route.c | 62 +++--- modules/ip/datapath/arp_input.c | 38 ++-- modules/ip/datapath/arp_output_reply.c | 18 +- modules/ip/datapath/arp_output_request.c | 20 +- .../{br_ip4_datapath.h => gr_ip4_datapath.h} | 16 +- modules/ip/datapath/icmp_input.c | 24 +-- modules/ip/datapath/icmp_output.c | 16 +- modules/ip/datapath/ip_forward.c | 8 +- modules/ip/datapath/ip_input.c | 28 +-- modules/ip/datapath/ip_local.c | 12 +- modules/ip/datapath/ip_output.c | 36 ++-- modules/ipip/br_ipip.h | 27 --- modules/ipip/cli.c | 52 ++--- modules/ipip/control.c | 30 +-- modules/ipip/datapath_in.c | 24 +-- modules/ipip/datapath_out.c | 30 +-- modules/ipip/gr_ipip.h | 27 +++ modules/ipip/ipip_priv.h | 4 +- modules/ipip/meson.build | 2 +- smoke/_init.sh | 26 +-- smoke/config_test.sh | 22 +- smoke/ip_forward_test.sh | 8 +- smoke/ipip_encap_test.sh | 12 +- smoke/run.sh | 4 +- smoke/vlan_forward_test.sh | 12 +- smoke/vrf_forward_test.sh | 16 +- 122 files changed, 1592 insertions(+), 1595 deletions(-) delete mode 100644 api/br_bitops.h rename api/{br_api.h => gr_api.h} (53%) rename api/{br_api_client_impl.h => gr_api_client_impl.h} (82%) create mode 100644 api/gr_bitops.h rename api/{br_macro.h => gr_macro.h} (85%) rename api/{br_net_types.h => gr_net_types.h} (82%) rename api/{br_stb_ds.h => gr_stb_ds.h} (89%) rename api/{br_string.h => gr_string.h} (86%) rename cli/{br_cli.h => gr_cli.h} (86%) rename cli/{br_table.h => gr_table.h} (86%) rename docs/{br.1.scd => grout.1.scd} (55%) rename main/{br.h => gr.h} (71%) rename main/{br_cmocka.h => gr_cmocka.h} (100%) rename main/{br_control.h => gr_control.h} (58%) rename main/{br_log.h => gr_log.h} (83%) rename main/{br_queue.h => gr_queue.h} (97%) delete mode 100644 modules/infra/api/br_infra.h create mode 100644 modules/infra/api/gr_infra.h rename modules/infra/cli/{br_cli_iface.h => gr_cli_iface.h} (79%) rename modules/infra/control/{br_graph.h => gr_graph.h} (66%) rename modules/infra/control/{br_iface.h => gr_iface.h} (95%) rename modules/infra/control/{br_port.h => gr_port.h} (90%) rename modules/infra/control/{br_vlan.h => gr_vlan.h} (82%) rename modules/infra/control/{br_worker.h => gr_worker.h} (96%) delete mode 100644 modules/infra/datapath/br_eth_input.h rename modules/infra/datapath/{br_datapath.h => gr_datapath.h} (96%) create mode 100644 modules/infra/datapath/gr_eth_input.h rename modules/infra/datapath/{br_eth_output.h => gr_eth_output.h} (64%) rename modules/infra/datapath/{br_mbuf.h => gr_mbuf.h} (53%) rename modules/infra/datapath/{br_rx.h => gr_rx.h} (86%) rename modules/infra/datapath/{br_tx.h => gr_tx.h} (82%) delete mode 100644 modules/ip/api/br_ip4.h create mode 100644 modules/ip/api/gr_ip4.h rename modules/ip/control/{br_ip4_control.h => gr_ip4_control.h} (94%) rename modules/ip/datapath/{br_ip4_datapath.h => gr_ip4_datapath.h} (79%) delete mode 100644 modules/ipip/br_ipip.h create mode 100644 modules/ipip/gr_ipip.h diff --git a/.clang-format b/.clang-format index 4c2e9d0a..24e916c5 100644 --- a/.clang-format +++ b/.clang-format @@ -90,7 +90,7 @@ IncludeBlocks: Regroup IncludeCategories: - Regex: '^".*' Priority: -1 - - Regex: '^<(br_|br\.)' + - Regex: '^<(gr_|gr\.)' Priority: 100 - Regex: '^<(rte_|event|ecoli|stb_|numa.h|libsmartcols.h)' Priority: 500 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 05b80675..6a11badc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,8 +32,8 @@ jobs: - uses: actions/upload-artifact@v4 with: path: | - build/br - build/br-cli + build/grout + build/grcli build/subprojects/ecoli/src/libecoli.so retention-days: 5 - run: make unit-tests @@ -57,7 +57,7 @@ jobs: with: path: build merge-multiple: true - - run: chmod -c a+x build/br* build/subprojects/ecoli/src/libecoli.so + - run: chmod -c a+x build/grout* build/subprojects/ecoli/src/libecoli.so - run: sudo smoke/run.sh build lint: runs-on: ubuntu-latest diff --git a/README.md b/README.md index 3357561e..499e4b8f 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,7 @@ -# Boring Router: a sample router based on DPDK +# Grout: a graph router based on DPDK -`brouter` stands for *Boring Router*. *Boring* because it should work in all -circumstances, without any fuss nor extended configuration/tuning. - -*Boring Router* is a DPDK based network processing application. It uses the -`rte_graph` library for data path processing. +Grout is a DPDK based network processing application. It uses the `rte_graph` +library for data path processing. It comes with a client library to configure it over a standard UNIX socket and a CLI that uses that library. The CLI can be used as an interactive shell, but @@ -31,21 +28,21 @@ apt install build-essential gcovr libcmocka-dev libedit-dev libevent-dev \ ### Build ``` -git clone https://github.com/rjarry/brouter -cd brouter +git clone https://github.com/rjarry/grout +cd grout make ``` -### Start the router +### Start the router daemon ```console -[root@dio brouter]$ taskset --cpu-list 6-19,26-39 ./build/br -v -BR: dpdk_init: DPDK version: DPDK 23.11.0 -BR: dpdk_init: EAL arguments: -l 6 -a 0000:00:00.0 --in-memory --log-level=*:info +[root@dio grout]$ taskset --cpu-list 6-19,26-39 ./build/grout -v +GROUT: dpdk_init: DPDK version: DPDK 23.11.0 +GROUT: dpdk_init: EAL arguments: -l 6 -a 0000:00:00.0 --in-memory --log-level=*:info EAL: Detected CPU lcores: 40 EAL: Detected NUMA nodes: 1 ... -BR: listen_api_socket: listening on API socket /run/br.sock +GROUT: listen_api_socket: listening on API socket /run/grout.sock ``` ### Start the CLI @@ -53,10 +50,10 @@ BR: listen_api_socket: listening on API socket /run/br.sock By default, the CLI will start an interactive shell with command completion: ```console -[root@dio brouter]$ ./build/br-cli -Welcome to the boring router CLI. +[root@dio grout]$ ./build/grcli +Welcome to the grout CLI. Use ? for help and for command completion. -br# ? +grout# ? quit Exit the CLI. add Create objects in the configuration. del Delete objects from the configuration. @@ -68,7 +65,7 @@ set Modify existing objects in the configuration. Multiple commands can be piped into standard input: ```console -[root@dio brouter]$ ./build/br-cli -ex < commands.list +[root@dio grout]$ ./build/grcli -ex < commands.list + add interface port p0 devargs 0000:18:00.0 rxqs 1 qsize 2048 Created interface 0 + add interface port p1 devargs 0000:18:00.1 rxqs 1 qsize 2048 @@ -115,8 +112,8 @@ IP MAC IFACE AGE STATE The CLI can be used as a one-shot command (with bash completion built-in): ```console -[root@dio brouter]$ complete -o default -C './build/br-cli -c' ./build/br-cli -[root@dio brouter]$ ./build/br-cli +[root@dio grout]$ complete -o default -C './build/grcli -c' ./build/grcli +[root@dio grout]$ ./build/grcli add (Create objects in the configuration.) clear (Clear counters or temporary entries.) del (Delete objects from the configuration.) @@ -131,16 +128,16 @@ show (Display information about the configuration.) -s (Path to the control plane API socket.) --trace-commands (Print executed commands.) -x (Print executed commands.) -[root@dio brouter]$ ./build/br-cli show +[root@dio grout]$ ./build/grcli show graph (Show packet processing graph info.) interface (Display interface details.) ip (Show IPv4 stack details.) port (Display DPDK port information.) stats (Print statistics.) -[root@dio brouter]$ ./build/br-cli show stats +[root@dio grout]$ ./build/grcli show stats hardware (Print hardware stats.) software (Print software stats.) -[root@dio brouter]$ ./build/br-cli show stats software +[root@dio grout]$ ./build/grcli show stats software NODE CALLS PACKETS PKTS/CALL CYCLES/CALL CYCLES/PKT port_rx 757792 22623757 29.9 1776.4 59.5 ip_input 333675 22623757 67.8 3091.0 45.6 @@ -154,10 +151,10 @@ ip_forward 333675 22623757 67.8 691.8 10.2 ## Packet graph ```console -[root@dio brouter]$ ./build/br-cli show graph dot | dot -Tsvg > docs/graph.svg +[root@dio grout]$ ./build/grcli show graph dot | dot -Tsvg > docs/graph.svg ``` -![docs/graph.svg](https://raw.githubusercontent.com/rjarry/brouter/main/docs/graph.svg) +![docs/graph.svg](https://raw.githubusercontent.com/rjarry/grout/main/docs/graph.svg) ## License diff --git a/api/br_bitops.h b/api/br_bitops.h deleted file mode 100644 index 34887a0c..00000000 --- a/api/br_bitops.h +++ /dev/null @@ -1,13 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// Copyright (c) 2024 Robin Jarry - -#ifndef _BR_BITOPS -#define _BR_BITOPS - -#include - -#define BR_BIT16(n) (UINT16_C(1) << (n)) -#define BR_BIT32(n) (UINT32_C(1) << (n)) -#define BR_BIT64(n) (UINT64_C(1) << (n)) - -#endif diff --git a/api/br_api.h b/api/gr_api.h similarity index 53% rename from api/br_api.h rename to api/gr_api.h index 29129230..72cfab9e 100644 --- a/api/br_api.h +++ b/api/gr_api.h @@ -1,39 +1,39 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#ifndef _BR_API -#define _BR_API +#ifndef _GR_API +#define _GR_API #include #include -struct br_api_request { +struct gr_api_request { uint32_t id; uint32_t type; uint32_t payload_len; }; -struct br_api_response { - uint32_t for_id; // matches br_api_request.id +struct gr_api_response { + uint32_t for_id; // matches gr_api_request.id uint32_t status; // uses errno values uint32_t payload_len; }; -#define BR_API_MAX_MSG_LEN (128 * 1024) +#define GR_API_MAX_MSG_LEN (128 * 1024) #define REQUEST_TYPE(module, id) (((uint32_t)(0xffff & module) << 16) | (0xffff & id)) #define PAYLOAD(header) ((void *)(header + 1)) -#define BR_DEFAULT_SOCK_PATH "/run/br.sock" +#define GR_DEFAULT_SOCK_PATH "/run/grout.sock" -struct br_api_client; +struct gr_api_client; -struct br_api_client *br_api_client_connect(const char *sock_path); +struct gr_api_client *gr_api_client_connect(const char *sock_path); -int br_api_client_disconnect(struct br_api_client *); +int gr_api_client_disconnect(struct gr_api_client *); -int br_api_client_send_recv( - const struct br_api_client *, +int gr_api_client_send_recv( + const struct gr_api_client *, uint32_t req_type, size_t tx_len, const void *tx_data, diff --git a/api/br_api_client_impl.h b/api/gr_api_client_impl.h similarity index 82% rename from api/br_api_client_impl.h rename to api/gr_api_client_impl.h index edc3eef3..909b1c02 100644 --- a/api/br_api_client_impl.h +++ b/api/gr_api_client_impl.h @@ -3,10 +3,10 @@ // This file must be included in *one* of your client application files. -#ifndef _BR_API_CLIENT_IMPL -#define _BR_API_CLIENT_IMPL +#ifndef _GR_API_CLIENT_IMPL +#define _GR_API_CLIENT_IMPL -#include "br_api.h" +#include "gr_api.h" #include #include @@ -18,17 +18,17 @@ #include #include -struct br_api_client { +struct gr_api_client { int sock_fd; }; -struct br_api_client *br_api_client_connect(const char *sock_path) { +struct gr_api_client *gr_api_client_connect(const char *sock_path) { union { struct sockaddr_un un; struct sockaddr a; } addr; - struct br_api_client *client = calloc(1, sizeof(*client)); + struct gr_api_client *client = calloc(1, sizeof(*client)); if (client == NULL) goto err; @@ -49,7 +49,7 @@ struct br_api_client *br_api_client_connect(const char *sock_path) { return NULL; } -int br_api_client_disconnect(struct br_api_client *client) { +int gr_api_client_disconnect(struct gr_api_client *client) { if (client == NULL) return 0; int ret = close(client->sock_fd); @@ -57,15 +57,15 @@ int br_api_client_disconnect(struct br_api_client *client) { return ret; } -int br_api_client_send_recv( - const struct br_api_client *client, +int gr_api_client_send_recv( + const struct gr_api_client *client, uint32_t req_type, size_t tx_len, const void *tx_data, void **rx_data ) { - struct br_api_request *req = NULL; - struct br_api_response resp; + struct gr_api_request *req = NULL; + struct gr_api_response resp; static uint32_t message_id; uint32_t id = ++message_id; void *payload = NULL; diff --git a/api/gr_bitops.h b/api/gr_bitops.h new file mode 100644 index 00000000..9b23536d --- /dev/null +++ b/api/gr_bitops.h @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: BSD-3-Clause +// Copyright (c) 2024 Robin Jarry + +#ifndef _GR_BITOPS +#define _GR_BITOPS + +#include + +#define GR_BIT16(n) (UINT16_C(1) << (n)) +#define GR_BIT32(n) (UINT32_C(1) << (n)) +#define GR_BIT64(n) (UINT64_C(1) << (n)) + +#endif diff --git a/api/br_macro.h b/api/gr_macro.h similarity index 85% rename from api/br_macro.h rename to api/gr_macro.h index e4741d05..7cf76cb1 100644 --- a/api/br_macro.h +++ b/api/gr_macro.h @@ -1,8 +1,8 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#ifndef _BR_MACRO -#define _BR_MACRO +#ifndef _GR_MACRO +#define _GR_MACRO #define ARRAY_DIM(array) (sizeof(array) / sizeof(array[0])) #define MEMBER_SIZE(type, member) (sizeof(((type *)0)->member)) diff --git a/api/br_net_types.h b/api/gr_net_types.h similarity index 82% rename from api/br_net_types.h rename to api/gr_net_types.h index cc93f0b4..e8e0153b 100644 --- a/api/br_net_types.h +++ b/api/gr_net_types.h @@ -1,8 +1,8 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#ifndef _BR_NET_TYPES -#define _BR_NET_TYPES +#ifndef _GR_NET_TYPES +#define _GR_NET_TYPES #include #include @@ -22,16 +22,16 @@ struct eth_addr { uint8_t bytes[6]; }; -static inline bool br_eth_addr_eq(const struct eth_addr *a, const struct eth_addr *b) { +static inline bool gr_eth_addr_eq(const struct eth_addr *a, const struct eth_addr *b) { return memcmp(a->bytes, b->bytes, sizeof(a->bytes)) == 0; } -static inline bool br_eth_addr_is_zero(const struct eth_addr *mac) { +static inline bool gr_eth_addr_is_zero(const struct eth_addr *mac) { struct eth_addr zero = {0}; - return br_eth_addr_eq(mac, &zero); + return gr_eth_addr_eq(mac, &zero); } -static inline int br_eth_addr_parse(const char *s, struct eth_addr *mac) { +static inline int gr_eth_addr_parse(const char *s, struct eth_addr *mac) { if (s == NULL) goto err; int ret = sscanf( @@ -63,7 +63,7 @@ struct ip4_net { uint8_t prefixlen; }; -static inline int br_ip4_net_parse(const char *s, struct ip4_net *net, bool zero_mask) { +static inline int gr_ip4_net_parse(const char *s, struct ip4_net *net, bool zero_mask) { char *addr = NULL; int ret = -1; @@ -89,7 +89,7 @@ static inline int br_ip4_net_parse(const char *s, struct ip4_net *net, bool zero return ret; } -static inline int br_ip4_net_format(const struct ip4_net *net, char *buf, size_t len) { +static inline int gr_ip4_net_format(const struct ip4_net *net, char *buf, size_t len) { const char *tmp; int n; diff --git a/api/br_stb_ds.h b/api/gr_stb_ds.h similarity index 89% rename from api/br_stb_ds.h rename to api/gr_stb_ds.h index 2afca643..2c0b5a6e 100644 --- a/api/br_stb_ds.h +++ b/api/gr_stb_ds.h @@ -1,8 +1,8 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#ifndef _BR_CORE_STB_DS -#define _BR_CORE_STB_DS +#ifndef _GR_CORE_STB_DS +#define _GR_CORE_STB_DS #include diff --git a/api/br_string.h b/api/gr_string.h similarity index 86% rename from api/br_string.h rename to api/gr_string.h index 48ae3999..f19fad2f 100644 --- a/api/br_string.h +++ b/api/gr_string.h @@ -1,8 +1,8 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#ifndef _BR_STRING -#define _BR_STRING +#ifndef _GR_STRING +#define _GR_STRING #include diff --git a/api/meson.build b/api/meson.build index f61ca8dc..83dda58e 100644 --- a/api/meson.build +++ b/api/meson.build @@ -2,10 +2,10 @@ # Copyright (c) 2024 Robin Jarry api_headers += files( - 'br_api.h', - 'br_api_client_impl.h', - 'br_bitops.h', - 'br_net_types.h', + 'gr_api.h', + 'gr_api_client_impl.h', + 'gr_bitops.h', + 'gr_net_types.h', ) src += files( diff --git a/api/stb_ds_impl.c b/api/stb_ds_impl.c index 6a4da699..1270c938 100644 --- a/api/stb_ds_impl.c +++ b/api/stb_ds_impl.c @@ -2,8 +2,8 @@ // Copyright (c) 2024 Robin Jarry #define STB_DS_IMPLEMENTATION -#include -#include +#include +#include #include diff --git a/api/string.c b/api/string.c index f518b00d..85acac51 100644 --- a/api/string.c +++ b/api/string.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include "br_string.h" +#include "gr_string.h" #include #include diff --git a/cli/complete.c b/cli/complete.c index 1a0b0262..6e7011d3 100644 --- a/cli/complete.c +++ b/cli/complete.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#include "br_cli.h" +#include "gr_cli.h" #include "complete.h" #include diff --git a/cli/complete.h b/cli/complete.h index f88a71ac..7dab201c 100644 --- a/cli/complete.h +++ b/cli/complete.h @@ -1,8 +1,8 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#ifndef _BR_CLI_COMPLETE -#define _BR_CLI_COMPLETE +#ifndef _GR_CLI_COMPLETE +#define _GR_CLI_COMPLETE #include diff --git a/cli/ec_node_devargs.c b/cli/ec_node_devargs.c index d31a0819..85bb5163 100644 --- a/cli/ec_node_devargs.c +++ b/cli/ec_node_devargs.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#include +#include #include diff --git a/cli/ec_node_dyn.c b/cli/ec_node_dyn.c index 38266974..944c1ea6 100644 --- a/cli/ec_node_dyn.c +++ b/cli/ec_node_dyn.c @@ -1,9 +1,9 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#include "br_cli.h" +#include "gr_cli.h" -#include +#include #include @@ -32,13 +32,13 @@ static int ec_node_dyn_parse( } static void disconnect_client(void *ptr) { - br_api_client_disconnect(ptr); + gr_api_client_disconnect(ptr); } -static struct br_api_client *connect_client(struct ec_comp *comp) { +static struct gr_api_client *connect_client(struct ec_comp *comp) { const struct ec_pnode *pstate = ec_comp_get_cur_pstate(comp); const char *sock_path = NULL; - struct br_api_client *client; + struct gr_api_client *client; // find the root of the parsed tree while (ec_pnode_get_parent(pstate) != NULL) @@ -52,9 +52,9 @@ static struct br_api_client *connect_client(struct ec_comp *comp) { sock_path = ec_strvec_val(vec, 0); } if (sock_path == NULL) - sock_path = BR_DEFAULT_SOCK_PATH; // not specified, use default + sock_path = GR_DEFAULT_SOCK_PATH; // not specified, use default - client = br_api_client_connect(sock_path); + client = gr_api_client_connect(sock_path); if (client != NULL) { // attach the connected client to the complete tree so that it is // automatically disconnected when the tree is freed. @@ -64,9 +64,9 @@ static struct br_api_client *connect_client(struct ec_comp *comp) { return client; } -static const struct br_api_client *get_client(struct ec_comp *comp) { +static const struct gr_api_client *get_client(struct ec_comp *comp) { struct ec_pnode *pstate = ec_comp_get_cur_pstate(comp); - const struct br_api_client *client = NULL; + const struct gr_api_client *client = NULL; while (client == NULL && pstate != NULL) { const struct ec_node *node = ec_pnode_get_node(pstate); @@ -85,7 +85,7 @@ static int ec_node_dyn_complete( const struct ec_strvec *strvec ) { const struct ec_node_dyn *priv = ec_node_priv(node); - const struct br_api_client *client; + const struct gr_api_client *client; assert(priv->cb != NULL); diff --git a/cli/ecoli.c b/cli/ecoli.c index 9f583905..3bc016ee 100644 --- a/cli/ecoli.c +++ b/cli/ecoli.c @@ -1,10 +1,10 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#include "br_cli.h" +#include "gr_cli.h" #include "exec.h" -#include +#include #include @@ -154,7 +154,7 @@ int arg_eth_addr(const struct ec_pnode *p, const char *id, struct eth_addr *val) } const char *str = ec_strvec_val(v, 0); - if (br_eth_addr_parse(str, val) < 0) { + if (gr_eth_addr_parse(str, val) < 0) { errno = EINVAL; goto err; } diff --git a/cli/exec.c b/cli/exec.c index 1eb52cf6..a891a912 100644 --- a/cli/exec.c +++ b/cli/exec.c @@ -3,23 +3,23 @@ #include "exec.h" -#include +#include #include #include -static STAILQ_HEAD(, br_cli_context) contexts = STAILQ_HEAD_INITIALIZER(contexts); +static STAILQ_HEAD(, gr_cli_context) contexts = STAILQ_HEAD_INITIALIZER(contexts); -void register_context(struct br_cli_context *ctx) { +void register_context(struct gr_cli_context *ctx) { STAILQ_INSERT_HEAD(&contexts, ctx, entries); } struct ec_node *init_commands(void) { - struct br_cli_context *ctx; + struct gr_cli_context *ctx; struct ec_node *root; - if ((root = ec_node("or", "br-cli")) == NULL) + if ((root = ec_node("or", "grcli")) == NULL) goto fail; STAILQ_FOREACH (ctx, &contexts, entries) { @@ -49,7 +49,7 @@ static cmd_cb_t *find_cmd_callback(struct ec_pnode *parsed) { } static exec_status_t exec_strvec( - const struct br_api_client *client, + const struct gr_api_client *client, const struct ec_node *cmdlist, const struct ec_strvec *vec ) { @@ -86,7 +86,7 @@ static exec_status_t exec_strvec( } exec_status_t -exec_line(const struct br_api_client *client, const struct ec_node *cmdlist, const char *line) { +exec_line(const struct gr_api_client *client, const struct ec_node *cmdlist, const char *line) { exec_status_t status = EXEC_SUCCESS; struct ec_strvec *vec = NULL; @@ -110,7 +110,7 @@ exec_line(const struct br_api_client *client, const struct ec_node *cmdlist, con } exec_status_t exec_args( - const struct br_api_client *client, + const struct gr_api_client *client, const struct ec_node *cmdlist, size_t argc, const char *const *argv diff --git a/cli/exec.h b/cli/exec.h index bd54112d..3afd9738 100644 --- a/cli/exec.h +++ b/cli/exec.h @@ -1,10 +1,10 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#ifndef _BR_CLI_EXEC -#define _BR_CLI_EXEC +#ifndef _GR_CLI_EXEC +#define _GR_CLI_EXEC -#include +#include #include @@ -23,10 +23,10 @@ typedef enum { #define CALLBACK_ATTR "callback" -exec_status_t exec_line(const struct br_api_client *, const struct ec_node *, const char *line); +exec_status_t exec_line(const struct gr_api_client *, const struct ec_node *, const char *line); exec_status_t exec_args( - const struct br_api_client *, + const struct gr_api_client *, const struct ec_node *, size_t argc, const char *const *argv diff --git a/cli/br_cli.h b/cli/gr_cli.h similarity index 86% rename from cli/br_cli.h rename to cli/gr_cli.h index bea1f6c9..f66e6a56 100644 --- a/cli/br_cli.h +++ b/cli/gr_cli.h @@ -1,25 +1,25 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#ifndef _BR_CLI -#define _BR_CLI +#ifndef _GR_CLI +#define _GR_CLI -#include -#include +#include +#include #include #include -typedef int(br_cli_ctx_init_t)(struct ec_node *root); +typedef int(gr_cli_ctx_init_t)(struct ec_node *root); -struct br_cli_context { +struct gr_cli_context { const char *name; - br_cli_ctx_init_t *init; - STAILQ_ENTRY(br_cli_context) entries; + gr_cli_ctx_init_t *init; + STAILQ_ENTRY(gr_cli_context) entries; }; -void register_context(struct br_cli_context *); +void register_context(struct gr_cli_context *); void errorf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); @@ -29,7 +29,7 @@ typedef enum { CMD_EXIT, } cmd_status_t; -typedef cmd_status_t(cmd_cb_t)(const struct br_api_client *, const struct ec_pnode *); +typedef cmd_status_t(cmd_cb_t)(const struct gr_api_client *, const struct ec_pnode *); struct ec_node *with_help(const char *help, struct ec_node *node); @@ -80,7 +80,7 @@ static inline int arg_u16(const struct ec_pnode *p, const char *id, uint16_t *va #define CTX_CLEAR CTX_ARG("clear", "Clear counters or temporary entries.") typedef int (*ec_node_dyn_comp_t)( - const struct br_api_client *, + const struct gr_api_client *, const struct ec_node *, struct ec_comp *, const char *arg, @@ -89,7 +89,7 @@ typedef int (*ec_node_dyn_comp_t)( struct ec_node *ec_node_dyn(const char *id, ec_node_dyn_comp_t cb, void *cb_arg); -#define CLIENT_ATTR "br_api_client" -#define SOCK_PATH_ID "br_api_sock_path" +#define CLIENT_ATTR "gr_api_client" +#define SOCK_PATH_ID "gr_api_sock_path" #endif diff --git a/cli/br_table.h b/cli/gr_table.h similarity index 86% rename from cli/br_table.h rename to cli/gr_table.h index 2d465535..0893b520 100644 --- a/cli/br_table.h +++ b/cli/gr_table.h @@ -1,8 +1,8 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#ifndef _BR_TABLE -#define _BR_TABLE +#ifndef _GR_TABLE +#define _GR_TABLE struct libscols_line; diff --git a/cli/interact.c b/cli/interact.c index e081d57f..41112b13 100644 --- a/cli/interact.c +++ b/cli/interact.c @@ -5,7 +5,7 @@ #include "interact.h" #include "log.h" -#include +#include #include @@ -13,7 +13,7 @@ #include #include -#define __PROMPT "br#" +#define __PROMPT "grout#" #define PROMPT __PROMPT " " #define DELIM "\x1e" #define COLOR_PROMPT DELIM CYAN_SGR DELIM __PROMPT DELIM RESET_SGR DELIM " " @@ -61,14 +61,14 @@ const char *__lsan_default_options(void) { } #endif -int interact(const struct br_api_client *client, struct ec_node *cmdlist) { +int interact(const struct gr_api_client *client, struct ec_node *cmdlist) { int flags = EC_EDITLINE_DEFAULT_SIGHANDLER; struct ec_editline *edit = NULL; struct ec_node *shlex = NULL; char *line = NULL; int ret = -1; - if ((edit = ec_editline("br-cli", stdin, stdout, stderr, flags)) == NULL) { + if ((edit = ec_editline("grcli", stdin, stdout, stderr, flags)) == NULL) { errorf("ec_editline: %s", strerror(errno)); goto end; } diff --git a/cli/interact.h b/cli/interact.h index e9e917eb..51be8af6 100644 --- a/cli/interact.h +++ b/cli/interact.h @@ -1,13 +1,13 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#ifndef _BR_CLI_INTERACT -#define _BR_CLI_INTERACT +#ifndef _GR_CLI_INTERACT +#define _GR_CLI_INTERACT -#include +#include #include -int interact(const struct br_api_client *, struct ec_node *); +int interact(const struct gr_api_client *, struct ec_node *); #endif diff --git a/cli/log.c b/cli/log.c index f9f9e82e..f9d24474 100644 --- a/cli/log.c +++ b/cli/log.c @@ -3,7 +3,7 @@ #include "log.h" -#include +#include #include diff --git a/cli/log.h b/cli/log.h index 5bfa1e25..e3f64a75 100644 --- a/cli/log.h +++ b/cli/log.h @@ -1,8 +1,8 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#ifndef _BR_CLI_LOG -#define _BR_CLI_LOG +#ifndef _GR_CLI_LOG +#define _GR_CLI_LOG #include "exec.h" diff --git a/cli/main.c b/cli/main.c index f11e328a..99008572 100644 --- a/cli/main.c +++ b/cli/main.c @@ -1,14 +1,14 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#include "br_cli.h" +#include "gr_cli.h" #include "complete.h" #include "exec.h" #include "interact.h" #include "log.h" -#include -#include +#include +#include #include @@ -32,21 +32,21 @@ static void help(void) { puts("options:"); puts(" -h, --help Show this help message and exit."); puts(" -s PATH, --socket PATH Path to the control plane API socket."); - puts(" Default: BR_SOCK_PATH from env or"); - printf(" %s).\n", BR_DEFAULT_SOCK_PATH); + puts(" Default: GROUT_SOCK_PATH from env or"); + printf(" %s).\n", GR_DEFAULT_SOCK_PATH); puts(" -e, --err-exit Abort on first error."); puts(" -x, --trace-commands Print executed commands."); puts(" -c, --bash-complete For use in bash completion:"); - puts(" complete -o default -C 'br-cli -c' br-cli"); + puts(" complete -o default -C 'grcli -c' grcli"); } -struct br_cli_opts { +struct gr_cli_opts { const char *sock_path; bool err_exit; bool trace_commands; }; -struct br_cli_opts opts; +struct gr_cli_opts opts; static int parse_args(int argc, char **argv) { int c; @@ -62,7 +62,7 @@ static int parse_args(int argc, char **argv) { opterr = 0; // disable getopt default error reporting - opts.sock_path = getenv("BR_SOCK_PATH"); + opts.sock_path = getenv("GROUT_SOCK_PATH"); while ((c = getopt_long(argc, argv, FLAGS, long_options, NULL)) != -1) { switch (c) { @@ -95,13 +95,13 @@ static int parse_args(int argc, char **argv) { } if (opts.sock_path == NULL) - opts.sock_path = BR_DEFAULT_SOCK_PATH; + opts.sock_path = GR_DEFAULT_SOCK_PATH; return optind; } int main(int argc, char **argv) { - struct br_api_client *client = NULL; + struct gr_api_client *client = NULL; struct ec_node *cmdlist = NULL; exec_status_t status; int ret, c; @@ -130,8 +130,8 @@ int main(int argc, char **argv) { argc -= c; argv += c; - if ((client = br_api_client_connect(opts.sock_path)) == NULL) { - errorf("br_connect: %s", strerror(errno)); + if ((client = gr_api_client_connect(opts.sock_path)) == NULL) { + errorf("gr_connect: %s", strerror(errno)); goto end; } @@ -158,8 +158,8 @@ int main(int argc, char **argv) { ret = EXIT_SUCCESS; end: - if (br_api_client_disconnect(client) < 0) { - errorf("br_disconnect: %s", strerror(errno)); + if (gr_api_client_disconnect(client) < 0) { + errorf("gr_disconnect: %s", strerror(errno)); ret = EXIT_FAILURE; } ec_node_free(cmdlist); diff --git a/cli/quit.c b/cli/quit.c index 6cac8729..a53ede66 100644 --- a/cli/quit.c +++ b/cli/quit.c @@ -1,10 +1,10 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#include -#include +#include +#include -static cmd_status_t quit(const struct br_api_client *c, const struct ec_pnode *p) { +static cmd_status_t quit(const struct gr_api_client *c, const struct ec_pnode *p) { (void)c; (void)p; return CMD_EXIT; @@ -14,7 +14,7 @@ static int ctx_init(struct ec_node *root) { return CLI_COMMAND(root, "quit", quit, "Exit the CLI."); } -static struct br_cli_context ctx = { +static struct gr_cli_context ctx = { .name = "quit", .init = ctx_init, }; diff --git a/cli/table.c b/cli/table.c index 10f189c0..31e91d79 100644 --- a/cli/table.c +++ b/cli/table.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include "br_table.h" +#include "gr_table.h" #include diff --git a/docs/graph.svg b/docs/graph.svg index b899a256..f68accac 100644 --- a/docs/graph.svg +++ b/docs/graph.svg @@ -3,11 +3,11 @@ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> - + -br-0003 +gr-0003 diff --git a/docs/br.1.scd b/docs/grout.1.scd similarity index 55% rename from docs/br.1.scd rename to docs/grout.1.scd index 0407acdc..25ca5e7d 100644 --- a/docs/br.1.scd +++ b/docs/grout.1.scd @@ -1,29 +1,29 @@ -BR(1) +GROUT(1) ; SPDX-License-Identifier: BSD-3-Clause ; Copyright (c) 2024 Robin Jarry # NAME -*br* -- boring router +*grout* -- graph router daemon # DESCRIPTION -*br* is a software router. +Grout is a software router based on DPDK rte_graph. # SYNOPSIS -*br* [*-h*] [*-t*] [*-c* _FILE_] [*-s* _PATH_] +*grout* [*-h*] [*-t*] [*-c* _FILE_] [*-s* _PATH_] # OPTIONS *-v*, *--verbose* Increase verbosity. *-t*, *--test-mode* - Run in test mode (no hugepages). + Run in test mode (no huge pages). *-s* _PATH_, *--socket* _PATH_ Path the control plane API socket. - Default: *BR_SOCK_PATH* from env or _/run/br.sock_). + Default: *GROUT_SOCK_PATH* from environment or _/run/grout.sock_). # AUTHORS diff --git a/docs/meson.build b/docs/meson.build index 00762850..004ec14c 100644 --- a/docs/meson.build +++ b/docs/meson.build @@ -6,7 +6,7 @@ scdoc = find_program(scdoc_dep.get_variable(pkgconfig: 'scdoc'), native: true) mandir = get_option('mandir') man_src = [ - 'br.1.scd', + 'grout.1.scd', ] foreach m : man_src diff --git a/main/control.c b/main/control.c index 32981ef4..b443f0fc 100644 --- a/main/control.c +++ b/main/control.c @@ -3,20 +3,20 @@ #include "control.h" -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include #include -static STAILQ_HEAD(, br_api_handler) handlers = STAILQ_HEAD_INITIALIZER(handlers); +static STAILQ_HEAD(, gr_api_handler) handlers = STAILQ_HEAD_INITIALIZER(handlers); -void br_register_api_handler(struct br_api_handler *handler) { - const struct br_api_handler *h; +void gr_register_api_handler(struct gr_api_handler *handler) { + const struct gr_api_handler *h; assert(handler != NULL); assert(handler->callback != NULL); @@ -30,8 +30,8 @@ void br_register_api_handler(struct br_api_handler *handler) { STAILQ_INSERT_TAIL(&handlers, handler, entries); } -const struct br_api_handler *lookup_api_handler(const struct br_api_request *req) { - const struct br_api_handler *handler; +const struct gr_api_handler *lookup_api_handler(const struct gr_api_request *req) { + const struct gr_api_handler *handler; STAILQ_FOREACH (handler, &handlers, entries) { if (handler->request_type == req->type) @@ -41,25 +41,25 @@ const struct br_api_handler *lookup_api_handler(const struct br_api_request *req return NULL; } -static STAILQ_HEAD(, br_module) modules = STAILQ_HEAD_INITIALIZER(modules); +static STAILQ_HEAD(, gr_module) modules = STAILQ_HEAD_INITIALIZER(modules); -void br_register_module(struct br_module *mod) { +void gr_register_module(struct gr_module *mod) { STAILQ_INSERT_TAIL(&modules, mod, entries); } static int module_init_prio_order(const void *a, const void *b) { - const struct br_module *const *mod_a = a; - const struct br_module *const *mod_b = b; + const struct gr_module *const *mod_a = a; + const struct gr_module *const *mod_b = b; return (*mod_a)->init_prio - (*mod_b)->init_prio; } void modules_init(struct event_base *ev_base) { - struct br_module *mod, **mods = NULL; + struct gr_module *mod, **mods = NULL; STAILQ_FOREACH (mod, &modules, entries) arrpush(mods, mod); // NOLINT - qsort(mods, arrlen(mods), sizeof(struct br_module *), module_init_prio_order); + qsort(mods, arrlen(mods), sizeof(struct gr_module *), module_init_prio_order); for (int i = 0; i < arrlen(mods); i++) { mod = mods[i]; @@ -73,18 +73,18 @@ void modules_init(struct event_base *ev_base) { } static int module_fini_prio_order(const void *a, const void *b) { - const struct br_module *const *mod_a = a; - const struct br_module *const *mod_b = b; + const struct gr_module *const *mod_a = a; + const struct gr_module *const *mod_b = b; return (*mod_a)->fini_prio - (*mod_b)->fini_prio; } void modules_fini(struct event_base *ev_base) { - struct br_module *mod, **mods = NULL; + struct gr_module *mod, **mods = NULL; STAILQ_FOREACH (mod, &modules, entries) arrpush(mods, mod); // NOLINT - qsort(mods, arrlen(mods), sizeof(struct br_module *), module_fini_prio_order); + qsort(mods, arrlen(mods), sizeof(struct gr_module *), module_fini_prio_order); for (int i = 0; i < arrlen(mods); i++) { mod = mods[i]; @@ -97,8 +97,8 @@ void modules_fini(struct event_base *ev_base) { arrfree(mods); } -void br_modules_dp_init(void) { - struct br_module *mod; +void gr_modules_dp_init(void) { + struct gr_module *mod; STAILQ_FOREACH (mod, &modules, entries) { if (mod->init_dp != NULL) { @@ -108,8 +108,8 @@ void br_modules_dp_init(void) { } } -void br_modules_dp_fini(void) { - struct br_module *mod; +void gr_modules_dp_fini(void) { + struct gr_module *mod; STAILQ_FOREACH (mod, &modules, entries) { if (mod->fini_dp != NULL) { diff --git a/main/control.h b/main/control.h index 697b980c..55def488 100644 --- a/main/control.h +++ b/main/control.h @@ -1,15 +1,15 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#ifndef _BR_CONTROL_PRIV -#define _BR_CONTROL_PRIV +#ifndef _GR_CONTROL_PRIV +#define _GR_CONTROL_PRIV -#include -#include +#include +#include #include -const struct br_api_handler *lookup_api_handler(const struct br_api_request *); +const struct gr_api_handler *lookup_api_handler(const struct gr_api_request *); void modules_init(struct event_base *); diff --git a/main/dpdk.c b/main/dpdk.c index 2f5a4911..635f1585 100644 --- a/main/dpdk.c +++ b/main/dpdk.c @@ -1,12 +1,12 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#include "br.h" +#include "gr.h" #include "dpdk.h" -#include -#include -#include +#include +#include +#include #include #include @@ -17,9 +17,9 @@ #include -int br_rte_log_type; +int gr_rte_log_type; -int dpdk_init(struct br_args *args) { +int dpdk_init(struct gr_args *args) { char main_lcore[32] = {0}; char **eal_args = NULL; int ret = -1; @@ -36,7 +36,7 @@ int dpdk_init(struct br_args *args) { goto end; } - arrpush(eal_args, "br"); + arrpush(eal_args, ""); arrpush(eal_args, "-l"); arrpush(eal_args, main_lcore); arrpush(eal_args, "-a"); @@ -54,19 +54,19 @@ int dpdk_init(struct br_args *args) { if (args->log_level > RTE_LOG_DEBUG) { arrpush(eal_args, "--log-level=*:debug"); } else if (args->log_level >= RTE_LOG_DEBUG) { - arrpush(eal_args, "--log-level=br:debug"); + arrpush(eal_args, "--log-level=gr:debug"); } else if (args->log_level >= RTE_LOG_INFO) { - arrpush(eal_args, "--log-level=br:info"); + arrpush(eal_args, "--log-level=gr:info"); } LOG(INFO, "%s", rte_version()); - br_rte_log_type = rte_log_register_type_and_pick_level("br", RTE_LOG_INFO); - if (br_rte_log_type < 0) + gr_rte_log_type = rte_log_register_type_and_pick_level("gr", RTE_LOG_INFO); + if (gr_rte_log_type < 0) goto end; char *buf = arrjoin(eal_args, " "); - LOG(INFO, "EAL arguments: %s", buf); + LOG(INFO, "EAL arguments:%s", buf); free(buf); if (rte_eal_init(arrlen(eal_args), eal_args) < 0) diff --git a/main/dpdk.h b/main/dpdk.h index 1e8e5371..5d5f29f1 100644 --- a/main/dpdk.h +++ b/main/dpdk.h @@ -1,12 +1,12 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#ifndef _BR_CORE_DPDK -#define _BR_CORE_DPDK +#ifndef _GR_CORE_DPDK +#define _GR_CORE_DPDK -#include "br.h" +#include "gr.h" -int dpdk_init(struct br_args *); +int dpdk_init(struct gr_args *); void dpdk_fini(void); #endif diff --git a/main/br.h b/main/gr.h similarity index 71% rename from main/br.h rename to main/gr.h index e5c5a76b..e9aad74b 100644 --- a/main/br.h +++ b/main/gr.h @@ -1,18 +1,18 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#ifndef _BR -#define _BR +#ifndef _GR +#define _GR #include -struct br_args { +struct gr_args { const char *api_sock_path; unsigned log_level; bool test_mode; bool poll_mode; }; -const struct br_args *br_args(void); +const struct gr_args *gr_args(void); #endif diff --git a/main/br_cmocka.h b/main/gr_cmocka.h similarity index 100% rename from main/br_cmocka.h rename to main/gr_cmocka.h diff --git a/main/br_control.h b/main/gr_control.h similarity index 58% rename from main/br_control.h rename to main/gr_control.h index b6e2d1cc..4f7a3875 100644 --- a/main/br_control.h +++ b/main/gr_control.h @@ -1,8 +1,8 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#ifndef _BR_CONTROL -#define _BR_CONTROL +#ifndef _GR_CONTROL +#define _GR_CONTROL #include @@ -19,18 +19,18 @@ static inline struct api_out api_out(uint32_t status, uint32_t len) { return out; } -typedef struct api_out (*br_api_handler_func)(const void *request, void **response); +typedef struct api_out (*gr_api_handler_func)(const void *request, void **response); -struct br_api_handler { +struct gr_api_handler { const char *name; uint32_t request_type; - br_api_handler_func callback; - STAILQ_ENTRY(br_api_handler) entries; + gr_api_handler_func callback; + STAILQ_ENTRY(gr_api_handler) entries; }; -void br_register_api_handler(struct br_api_handler *); +void gr_register_api_handler(struct gr_api_handler *); -struct br_module { +struct gr_module { const char *name; int init_prio; void (*init)(struct event_base *); @@ -38,13 +38,13 @@ struct br_module { void (*fini)(struct event_base *); void (*init_dp)(void); void (*fini_dp)(void); - STAILQ_ENTRY(br_module) entries; + STAILQ_ENTRY(gr_module) entries; }; -void br_register_module(struct br_module *); +void gr_register_module(struct gr_module *); -void br_modules_dp_init(void); +void gr_modules_dp_init(void); -void br_modules_dp_fini(void); +void gr_modules_dp_fini(void); #endif diff --git a/main/br_log.h b/main/gr_log.h similarity index 83% rename from main/br_log.h rename to main/gr_log.h index 0810efb6..555c3946 100644 --- a/main/br_log.h +++ b/main/gr_log.h @@ -1,23 +1,23 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#ifndef _BR_CORE_LOG -#define _BR_CORE_LOG +#ifndef _GR_CORE_LOG +#define _GR_CORE_LOG #include #include #include -extern int br_rte_log_type; -#define RTE_LOGTYPE_BR br_rte_log_type +extern int gr_rte_log_type; +#define RTE_LOGTYPE_GR gr_rte_log_type #define LOG(level, fmt, ...) \ do { \ static_assert( \ !__builtin_strchr(fmt, '\n'), "This log format string contains a \\n" \ ); \ - RTE_LOG(level, BR, "%s: " fmt "\n", __func__ __VA_OPT__(, ) __VA_ARGS__); \ + RTE_LOG(level, GR, "%s: " fmt "\n", __func__ __VA_OPT__(, ) __VA_ARGS__); \ } while (0) #define ABORT(fmt, ...) \ @@ -27,7 +27,7 @@ extern int br_rte_log_type; } while (0) static inline int __errno_log(int errnum, const char *func, const char *what) { - RTE_LOG(ERR, BR, "%s: %s: %s\n", func, what, rte_strerror(errnum)); + RTE_LOG(ERR, GR, "%s: %s: %s\n", func, what, rte_strerror(errnum)); errno = errnum; return -errnum; } @@ -35,7 +35,7 @@ static inline int __errno_log(int errnum, const char *func, const char *what) { #define errno_log(err, what) __errno_log(err, __func__, what) static inline void *__errno_log_null(int errnum, const char *func, const char *what) { - RTE_LOG(ERR, BR, "%s: %s: %s\n", func, what, rte_strerror(errnum)); + RTE_LOG(ERR, GR, "%s: %s: %s\n", func, what, rte_strerror(errnum)); errno = errnum; return NULL; } diff --git a/main/br_queue.h b/main/gr_queue.h similarity index 97% rename from main/br_queue.h rename to main/gr_queue.h index 154a0675..f9ebadf8 100644 --- a/main/br_queue.h +++ b/main/gr_queue.h @@ -2,8 +2,8 @@ // Copyright (c) 1991, 1993 The Regents of the University of California // Copyright (c) 2023 Robin Jarry -#ifndef _BR_QUEUE -#define _BR_QUEUE +#ifndef _GR_QUEUE +#define _GR_QUEUE #include diff --git a/main/main.c b/main/main.c index 9b4a55c3..596c79b0 100644 --- a/main/main.c +++ b/main/main.c @@ -1,14 +1,14 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#include "br.h" +#include "gr.h" #include "control.h" #include "dpdk.h" #include "signals.h" -#include -#include -#include +#include +#include +#include #include #include @@ -40,13 +40,13 @@ static void usage(const char *prog) { puts(" -t, --test-mode Run in test mode (no hugepages)."); puts(" -p, --poll-mode Disable automatic micro-sleep."); puts(" -s PATH, --socket PATH Path the control plane API socket."); - puts(" Default: BR_SOCK_PATH from env or"); - printf(" %s).\n", BR_DEFAULT_SOCK_PATH); + puts(" Default: GROUT_SOCK_PATH from env or"); + printf(" %s).\n", GR_DEFAULT_SOCK_PATH); } -static struct br_args args; +static struct gr_args args; -const struct br_args *br_args(void) { +const struct gr_args *gr_args(void) { return &args; } @@ -65,7 +65,7 @@ static int parse_args(int argc, char **argv) { opterr = 0; // disable getopt default error reporting - args.api_sock_path = getenv("BR_SOCK_PATH"); + args.api_sock_path = getenv("GROUT_SOCK_PATH"); args.log_level = RTE_LOG_NOTICE; while ((c = getopt_long(argc, argv, FLAGS, long_options, NULL)) != -1) { @@ -104,7 +104,7 @@ static int parse_args(int argc, char **argv) { } if (args.api_sock_path == NULL) - args.api_sock_path = BR_DEFAULT_SOCK_PATH; + args.api_sock_path = GR_DEFAULT_SOCK_PATH; return 0; } @@ -114,7 +114,7 @@ static void finalize_close_fd(struct event *ev, void *priv) { close(event_get_fd(ev)); } -static ssize_t send_response(evutil_socket_t sock, struct br_api_response *resp) { +static ssize_t send_response(evutil_socket_t sock, struct gr_api_response *resp) { if (resp == NULL) { errno = ENOMEM; return -1; @@ -135,7 +135,7 @@ static struct event_base *ev_base; static void api_write_cb(evutil_socket_t sock, short what, void *priv) { struct event *ev = event_base_get_running_event(ev_base); - struct br_api_response *resp = priv; + struct gr_api_response *resp = priv; (void)what; @@ -162,8 +162,8 @@ static void api_write_cb(evutil_socket_t sock, short what, void *priv) { static void api_read_cb(evutil_socket_t sock, short what, void *ctx) { struct event *ev = event_base_get_running_event(ev_base); void *req_payload = NULL, *resp_payload = NULL; - struct br_api_response *resp = NULL; - struct br_api_request req; + struct gr_api_response *resp = NULL; + struct gr_api_request req; struct event *write_ev; struct api_out out; ssize_t len; @@ -199,7 +199,7 @@ static void api_read_cb(evutil_socket_t sock, short what, void *ctx) { } } - const struct br_api_handler *handler = lookup_api_handler(&req); + const struct gr_api_handler *handler = lookup_api_handler(&req); if (handler == NULL) { out.status = ENOTSUP; out.len = 0; diff --git a/main/signals.c b/main/signals.c index 3ba2c740..feab2657 100644 --- a/main/signals.c +++ b/main/signals.c @@ -3,7 +3,7 @@ #include "signals.h" -#include +#include #include diff --git a/main/signals.h b/main/signals.h index ce5342ce..c85f0bc0 100644 --- a/main/signals.h +++ b/main/signals.h @@ -1,8 +1,8 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#ifndef _BR_SIGNALS -#define _BR_SIGNALS +#ifndef _GR_SIGNALS +#define _GR_SIGNALS #include diff --git a/meson.build b/meson.build index 8d7c3266..b119b9b4 100644 --- a/meson.build +++ b/meson.build @@ -2,7 +2,7 @@ # Copyright (c) 2023 Robin Jarry project( - 'boring-router', + 'grout', 'c', version: '0.1', license: 'BSD-3-Clause', @@ -62,17 +62,17 @@ subdir('main') subdir('modules') subdir('cli') -install_headers(api_headers, subdir: 'br') +install_headers(api_headers, subdir: 'grout') -br_exe = executable( - 'br', src, +grout_exe = executable( + 'grout', src, include_directories: inc, dependencies: [dpdk_dep, event_dep, numa_dep, stb_dep], install: true, ) -br_cli_exe = executable( - 'br-cli', cli_src, +grcli_exe = executable( + 'grcli', cli_src, include_directories: cli_inc, dependencies: [ecoli_dep, smartcols_dep], install: true, diff --git a/modules/infra/api/br_infra.h b/modules/infra/api/br_infra.h deleted file mode 100644 index 65205493..00000000 --- a/modules/infra/api/br_infra.h +++ /dev/null @@ -1,200 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// Copyright (c) 2023 Robin Jarry - -#ifndef _BR_INFRA_API -#define _BR_INFRA_API - -#include -#include -#include -#include - -#include -#include -#include -#include - -// Value for br_iface.type -#define BR_IFACE_TYPE_UNDEF 0x0000 -#define BR_IFACE_TYPE_PORT 0x0001 -#define BR_IFACE_TYPE_VLAN 0x0002 - -// Interface configure flags -#define BR_IFACE_F_UP BR_BIT16(0) -#define BR_IFACE_F_PROMISC BR_BIT16(1) -#define BR_IFACE_F_ALLMULTI BR_BIT16(2) -// Interface state flags -#define BR_IFACE_S_RUNNING BR_BIT16(0) - -// Interface reconfig attributes -#define BR_IFACE_SET_FLAGS BR_BIT64(0) -#define BR_IFACE_SET_MTU BR_BIT64(1) -#define BR_IFACE_SET_NAME BR_BIT64(2) -#define BR_IFACE_SET_VRF BR_BIT64(3) - -// Generic struct for all network interfaces. -struct br_iface { - uint16_t id; // Interface unique index. - uint16_t type; // Interface type. Uses values from BR_IFACE_TYPE_*. - uint16_t flags; // Interface flags. Bit mask of BR_IFACE_F_*. - uint16_t state; // Interface state. Bit mask of BR_IFACE_S_*. - uint16_t mtu; // Maximum transmission unit size (incl. headers). - uint16_t vrf_id; // L3 addressing and routing domain -#define BR_IFACE_NAME_SIZE 64 - char name[BR_IFACE_NAME_SIZE]; // Interface name (utf-8 encoded, nul terminated). - uint8_t info[256]; // Type specific interface info. -}; - -// Port reconfig attributes -#define BR_PORT_SET_N_RXQS BR_BIT64(32) -#define BR_PORT_SET_N_TXQS BR_BIT64(33) -#define BR_PORT_SET_Q_SIZE BR_BIT64(34) -#define BR_PORT_SET_MAC BR_BIT64(35) - -// Info for BR_IFACE_TYPE_PORT interfaces -struct br_iface_info_port { -#define BR_PORT_DEVARGS_SIZE 64 - char devargs[BR_PORT_DEVARGS_SIZE]; - uint16_t n_rxq; - uint16_t n_txq; - uint16_t rxq_size; - uint16_t txq_size; - struct eth_addr mac; -}; - -static_assert(sizeof(struct br_iface_info_port) <= MEMBER_SIZE(struct br_iface, info)); - -// VLAN reconfig attributes -#define BR_VLAN_SET_PARENT BR_BIT64(32) -#define BR_VLAN_SET_VLAN BR_BIT64(33) -#define BR_VLAN_SET_MAC BR_BIT64(34) - -// Info for BR_IFACE_TYPE_VLAN interfaces -struct br_iface_info_vlan { - uint16_t parent_id; - uint16_t vlan_id; - struct eth_addr mac; -}; - -static_assert(sizeof(struct br_iface_info_vlan) <= MEMBER_SIZE(struct br_iface, info)); - -struct br_port_rxq_map { - uint16_t iface_id; - uint16_t rxq_id; - uint16_t cpu_id; - uint16_t enabled; -}; - -struct br_infra_stat { - char name[64]; - uint64_t objs; - uint64_t calls; - uint64_t cycles; -}; - -#define BR_INFRA_MODULE 0xacdc - -// ifaces /////////////////////////////////////////////////////////////////////// -#define BR_INFRA_IFACE_ADD REQUEST_TYPE(BR_INFRA_MODULE, 0x0001) - -struct br_infra_iface_add_req { - // iface id is ignored and should be zeroed - struct br_iface iface; -}; - -struct br_infra_iface_add_resp { - uint16_t iface_id; -}; - -#define BR_INFRA_IFACE_DEL REQUEST_TYPE(BR_INFRA_MODULE, 0x0002) - -struct br_infra_iface_del_req { - uint16_t iface_id; -}; - -// struct br_infra_iface_del_resp { }; - -#define BR_INFRA_IFACE_GET REQUEST_TYPE(BR_INFRA_MODULE, 0x0003) - -struct br_infra_iface_get_req { - uint16_t iface_id; -}; - -struct br_infra_iface_get_resp { - struct br_iface iface; -}; - -#define BR_INFRA_IFACE_LIST REQUEST_TYPE(BR_INFRA_MODULE, 0x0004) - -struct br_infra_iface_list_req { - uint16_t type; // use BR_IFACE_TYPE_UNDEF for all -}; - -struct br_infra_iface_list_resp { - uint16_t n_ifaces; - struct br_iface ifaces[/* n_ifaces */]; -}; - -#define BR_INFRA_IFACE_SET REQUEST_TYPE(BR_INFRA_MODULE, 0x0005) - -struct br_infra_iface_set_req { - struct br_iface iface; - uint64_t set_attrs; -}; - -// struct br_infra_iface_set_resp { }; - -// iface rxqs /////////////////////////////////////////////////////////////////// -#define BR_INFRA_RXQ_LIST REQUEST_TYPE(BR_INFRA_MODULE, 0x0010) - -// struct br_infra_rxq_list_req { }; - -struct br_infra_rxq_list_resp { - uint16_t n_rxqs; - struct br_port_rxq_map rxqs[/* n_rxq */]; -}; - -#define BR_INFRA_RXQ_SET REQUEST_TYPE(BR_INFRA_MODULE, 0x0011) - -struct br_infra_rxq_set_req { - uint16_t iface_id; - uint16_t rxq_id; - uint16_t cpu_id; -}; - -// struct br_infra_rxq_set_resp { }; - -// stats /////////////////////////////////////////////////////////////////////// -#define BR_INFRA_STAT_F_SW BR_BIT16(0) //!< include software stats -#define BR_INFRA_STAT_F_HW BR_BIT16(1) //!< include hardware stats -#define BR_INFRA_STAT_F_ZERO BR_BIT16(2) //!< include zero value stats -typedef uint16_t br_infra_stats_flags_t; - -#define BR_INFRA_STATS_GET REQUEST_TYPE(BR_INFRA_MODULE, 0x0020) - -struct br_infra_stats_get_req { - br_infra_stats_flags_t flags; - char pattern[64]; // optional glob pattern -}; - -struct br_infra_stats_get_resp { - uint16_t n_stats; - struct br_infra_stat stats[/* n_stats */]; -}; - -#define BR_INFRA_STATS_RESET REQUEST_TYPE(BR_INFRA_MODULE, 0x0021) - -// struct br_infra_stats_reset_req { }; -// struct br_infra_stats_reset_resp { }; - -// graph /////////////////////////////////////////////////////////////////////// -#define BR_INFRA_GRAPH_DUMP REQUEST_TYPE(BR_INFRA_MODULE, 0x0030) - -// struct br_infra_graph_dump_req { }; - -struct br_infra_graph_dump_resp { - uint32_t len; - char dot[/* len */]; -}; - -#endif diff --git a/modules/infra/api/gr_infra.h b/modules/infra/api/gr_infra.h new file mode 100644 index 00000000..3a5409ba --- /dev/null +++ b/modules/infra/api/gr_infra.h @@ -0,0 +1,200 @@ +// SPDX-License-Identifier: BSD-3-Clause +// Copyright (c) 2023 Robin Jarry + +#ifndef _GR_INFRA_API +#define _GR_INFRA_API + +#include +#include +#include +#include + +#include +#include +#include +#include + +// Value for gr_iface.type +#define GR_IFACE_TYPE_UNDEF 0x0000 +#define GR_IFACE_TYPE_PORT 0x0001 +#define GR_IFACE_TYPE_VLAN 0x0002 + +// Interface configure flags +#define GR_IFACE_F_UP GR_BIT16(0) +#define GR_IFACE_F_PROMISC GR_BIT16(1) +#define GR_IFACE_F_ALLMULTI GR_BIT16(2) +// Interface state flags +#define GR_IFACE_S_RUNNING GR_BIT16(0) + +// Interface reconfig attributes +#define GR_IFACE_SET_FLAGS GR_BIT64(0) +#define GR_IFACE_SET_MTU GR_BIT64(1) +#define GR_IFACE_SET_NAME GR_BIT64(2) +#define GR_IFACE_SET_VRF GR_BIT64(3) + +// Generic struct for all network interfaces. +struct gr_iface { + uint16_t id; // Interface unique index. + uint16_t type; // Interface type. Uses values from GR_IFACE_TYPE_*. + uint16_t flags; // Interface flags. Bit mask of GR_IFACE_F_*. + uint16_t state; // Interface state. Bit mask of GR_IFACE_S_*. + uint16_t mtu; // Maximum transmission unit size (incl. headers). + uint16_t vrf_id; // L3 addressing and routing domain +#define GR_IFACE_NAME_SIZE 64 + char name[GR_IFACE_NAME_SIZE]; // Interface name (utf-8 encoded, nul terminated). + uint8_t info[256]; // Type specific interface info. +}; + +// Port reconfig attributes +#define GR_PORT_SET_N_RXQS GR_BIT64(32) +#define GR_PORT_SET_N_TXQS GR_BIT64(33) +#define GR_PORT_SET_Q_SIZE GR_BIT64(34) +#define GR_PORT_SET_MAC GR_BIT64(35) + +// Info for GR_IFACE_TYPE_PORT interfaces +struct gr_iface_info_port { +#define GR_PORT_DEVARGS_SIZE 64 + char devargs[GR_PORT_DEVARGS_SIZE]; + uint16_t n_rxq; + uint16_t n_txq; + uint16_t rxq_size; + uint16_t txq_size; + struct eth_addr mac; +}; + +static_assert(sizeof(struct gr_iface_info_port) <= MEMBER_SIZE(struct gr_iface, info)); + +// VLAN reconfig attributes +#define GR_VLAN_SET_PARENT GR_BIT64(32) +#define GR_VLAN_SET_VLAN GR_BIT64(33) +#define GR_VLAN_SET_MAC GR_BIT64(34) + +// Info for GR_IFACE_TYPE_VLAN interfaces +struct gr_iface_info_vlan { + uint16_t parent_id; + uint16_t vlan_id; + struct eth_addr mac; +}; + +static_assert(sizeof(struct gr_iface_info_vlan) <= MEMBER_SIZE(struct gr_iface, info)); + +struct gr_port_rxq_map { + uint16_t iface_id; + uint16_t rxq_id; + uint16_t cpu_id; + uint16_t enabled; +}; + +struct gr_infra_stat { + char name[64]; + uint64_t objs; + uint64_t calls; + uint64_t cycles; +}; + +#define GR_INFRA_MODULE 0xacdc + +// ifaces /////////////////////////////////////////////////////////////////////// +#define GR_INFRA_IFACE_ADD REQUEST_TYPE(GR_INFRA_MODULE, 0x0001) + +struct gr_infra_iface_add_req { + // iface id is ignored and should be zeroed + struct gr_iface iface; +}; + +struct gr_infra_iface_add_resp { + uint16_t iface_id; +}; + +#define GR_INFRA_IFACE_DEL REQUEST_TYPE(GR_INFRA_MODULE, 0x0002) + +struct gr_infra_iface_del_req { + uint16_t iface_id; +}; + +// struct gr_infra_iface_del_resp { }; + +#define GR_INFRA_IFACE_GET REQUEST_TYPE(GR_INFRA_MODULE, 0x0003) + +struct gr_infra_iface_get_req { + uint16_t iface_id; +}; + +struct gr_infra_iface_get_resp { + struct gr_iface iface; +}; + +#define GR_INFRA_IFACE_LIST REQUEST_TYPE(GR_INFRA_MODULE, 0x0004) + +struct gr_infra_iface_list_req { + uint16_t type; // use GR_IFACE_TYPE_UNDEF for all +}; + +struct gr_infra_iface_list_resp { + uint16_t n_ifaces; + struct gr_iface ifaces[/* n_ifaces */]; +}; + +#define GR_INFRA_IFACE_SET REQUEST_TYPE(GR_INFRA_MODULE, 0x0005) + +struct gr_infra_iface_set_req { + struct gr_iface iface; + uint64_t set_attrs; +}; + +// struct gr_infra_iface_set_resp { }; + +// iface rxqs /////////////////////////////////////////////////////////////////// +#define GR_INFRA_RXQ_LIST REQUEST_TYPE(GR_INFRA_MODULE, 0x0010) + +// struct gr_infra_rxq_list_req { }; + +struct gr_infra_rxq_list_resp { + uint16_t n_rxqs; + struct gr_port_rxq_map rxqs[/* n_rxq */]; +}; + +#define GR_INFRA_RXQ_SET REQUEST_TYPE(GR_INFRA_MODULE, 0x0011) + +struct gr_infra_rxq_set_req { + uint16_t iface_id; + uint16_t rxq_id; + uint16_t cpu_id; +}; + +// struct gr_infra_rxq_set_resp { }; + +// stats /////////////////////////////////////////////////////////////////////// +#define GR_INFRA_STAT_F_SW GR_BIT16(0) //!< include software stats +#define GR_INFRA_STAT_F_HW GR_BIT16(1) //!< include hardware stats +#define GR_INFRA_STAT_F_ZERO GR_BIT16(2) //!< include zero value stats +typedef uint16_t gr_infra_stats_flags_t; + +#define GR_INFRA_STATS_GET REQUEST_TYPE(GR_INFRA_MODULE, 0x0020) + +struct gr_infra_stats_get_req { + gr_infra_stats_flags_t flags; + char pattern[64]; // optional glob pattern +}; + +struct gr_infra_stats_get_resp { + uint16_t n_stats; + struct gr_infra_stat stats[/* n_stats */]; +}; + +#define GR_INFRA_STATS_RESET REQUEST_TYPE(GR_INFRA_MODULE, 0x0021) + +// struct gr_infra_stats_reset_req { }; +// struct gr_infra_stats_reset_resp { }; + +// graph /////////////////////////////////////////////////////////////////////// +#define GR_INFRA_GRAPH_DUMP REQUEST_TYPE(GR_INFRA_MODULE, 0x0030) + +// struct gr_infra_graph_dump_req { }; + +struct gr_infra_graph_dump_resp { + uint32_t len; + char dot[/* len */]; +}; + +#endif diff --git a/modules/infra/api/graph.c b/modules/infra/api/graph.c index 8ce51c32..f03bd861 100644 --- a/modules/infra/api/graph.c +++ b/modules/infra/api/graph.c @@ -1,11 +1,11 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include "br_infra.h" +#include "gr_infra.h" -#include -#include -#include +#include +#include +#include #include @@ -14,7 +14,7 @@ #include static struct api_out graph_dump(const void *request, void **response) { - struct br_infra_graph_dump_resp *resp; + struct gr_infra_graph_dump_resp *resp; size_t buf_len = 0, resp_len = 0; const char *graph_name; struct worker *worker; @@ -56,12 +56,12 @@ static struct api_out graph_dump(const void *request, void **response) { return api_out(-ret, resp_len); } -static struct br_api_handler graph_dump_handler = { +static struct gr_api_handler graph_dump_handler = { .name = "graph dump", - .request_type = BR_INFRA_GRAPH_DUMP, + .request_type = GR_INFRA_GRAPH_DUMP, .callback = graph_dump, }; RTE_INIT(graph_init) { - br_register_api_handler(&graph_dump_handler); + gr_register_api_handler(&graph_dump_handler); } diff --git a/modules/infra/api/iface.c b/modules/infra/api/iface.c index 8fbac784..42427679 100644 --- a/modules/infra/api/iface.c +++ b/modules/infra/api/iface.c @@ -1,19 +1,19 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include "br_infra.h" +#include "gr_infra.h" -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include -static void iface_to_api(struct br_iface *to, const struct iface *from) { +static void iface_to_api(struct gr_iface *to, const struct iface *from) { struct iface_type *type = iface_type_get(from->type_id); to->id = from->id; to->type = from->type_id; @@ -26,8 +26,8 @@ static void iface_to_api(struct br_iface *to, const struct iface *from) { } static struct api_out iface_add(const void *request, void **response) { - const struct br_infra_iface_add_req *req = request; - struct br_infra_iface_add_resp *resp; + const struct gr_infra_iface_add_req *req = request; + struct gr_infra_iface_add_resp *resp; struct iface *iface; iface = iface_create( @@ -53,7 +53,7 @@ static struct api_out iface_add(const void *request, void **response) { } static struct api_out iface_del(const void *request, void **response) { - const struct br_infra_iface_del_req *req = request; + const struct gr_infra_iface_del_req *req = request; int ret; (void)response; @@ -64,8 +64,8 @@ static struct api_out iface_del(const void *request, void **response) { } static struct api_out iface_get(const void *request, void **response) { - const struct br_infra_iface_get_req *req = request; - struct br_infra_iface_get_resp *resp = NULL; + const struct gr_infra_iface_get_req *req = request; + struct gr_infra_iface_get_resp *resp = NULL; struct iface *iface; if ((iface = iface_from_id(req->iface_id)) == NULL) @@ -81,15 +81,15 @@ static struct api_out iface_get(const void *request, void **response) { } static struct api_out iface_list(const void *request, void **response) { - const struct br_infra_iface_list_req *req = request; - struct br_infra_iface_list_resp *resp = NULL; + const struct gr_infra_iface_list_req *req = request; + struct gr_infra_iface_list_resp *resp = NULL; const struct iface *iface = NULL; uint16_t n_ifaces; size_t len; n_ifaces = ifaces_count(req->type); - len = sizeof(*resp) + n_ifaces * sizeof(struct br_iface); + len = sizeof(*resp) + n_ifaces * sizeof(struct gr_iface); if ((resp = calloc(1, len)) == NULL) return api_out(ENOMEM, 0); @@ -102,7 +102,7 @@ static struct api_out iface_list(const void *request, void **response) { } static struct api_out iface_set(const void *request, void **response) { - const struct br_infra_iface_set_req *req = request; + const struct gr_infra_iface_set_req *req = request; int ret; (void)response; @@ -122,36 +122,36 @@ static struct api_out iface_set(const void *request, void **response) { return api_out(0, 0); } -static struct br_api_handler iface_add_handler = { +static struct gr_api_handler iface_add_handler = { .name = "iface add", - .request_type = BR_INFRA_IFACE_ADD, + .request_type = GR_INFRA_IFACE_ADD, .callback = iface_add, }; -static struct br_api_handler iface_del_handler = { +static struct gr_api_handler iface_del_handler = { .name = "iface del", - .request_type = BR_INFRA_IFACE_DEL, + .request_type = GR_INFRA_IFACE_DEL, .callback = iface_del, }; -static struct br_api_handler iface_get_handler = { +static struct gr_api_handler iface_get_handler = { .name = "iface get", - .request_type = BR_INFRA_IFACE_GET, + .request_type = GR_INFRA_IFACE_GET, .callback = iface_get, }; -static struct br_api_handler iface_list_handler = { +static struct gr_api_handler iface_list_handler = { .name = "iface list", - .request_type = BR_INFRA_IFACE_LIST, + .request_type = GR_INFRA_IFACE_LIST, .callback = iface_list, }; -static struct br_api_handler iface_set_handler = { +static struct gr_api_handler iface_set_handler = { .name = "iface set", - .request_type = BR_INFRA_IFACE_SET, + .request_type = GR_INFRA_IFACE_SET, .callback = iface_set, }; RTE_INIT(infra_api_init) { - br_register_api_handler(&iface_add_handler); - br_register_api_handler(&iface_del_handler); - br_register_api_handler(&iface_get_handler); - br_register_api_handler(&iface_list_handler); - br_register_api_handler(&iface_set_handler); + gr_register_api_handler(&iface_add_handler); + gr_register_api_handler(&iface_del_handler); + gr_register_api_handler(&iface_get_handler); + gr_register_api_handler(&iface_list_handler); + gr_register_api_handler(&iface_set_handler); } diff --git a/modules/infra/api/meson.build b/modules/infra/api/meson.build index f2e95258..a3467969 100644 --- a/modules/infra/api/meson.build +++ b/modules/infra/api/meson.build @@ -8,6 +8,6 @@ src += files( 'stats.c', ) -api_headers += files('br_infra.h') +api_headers += files('gr_infra.h') inc += include_directories('.') cli_inc += include_directories('.') diff --git a/modules/infra/api/rxq.c b/modules/infra/api/rxq.c index 32209728..1e68a19b 100644 --- a/modules/infra/api/rxq.c +++ b/modules/infra/api/rxq.c @@ -1,20 +1,20 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include "br_infra.h" +#include "gr_infra.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include #include static struct api_out rxq_list(const void *request, void **response) { - struct br_infra_rxq_list_resp *resp = NULL; + struct gr_infra_rxq_list_resp *resp = NULL; struct queue_map *qmap; struct worker *worker; uint16_t n_rxqs = 0; @@ -25,7 +25,7 @@ static struct api_out rxq_list(const void *request, void **response) { STAILQ_FOREACH (worker, &workers, next) n_rxqs += arrlen(worker->rxqs); - len = sizeof(*resp) + n_rxqs * sizeof(struct br_port_rxq_map); + len = sizeof(*resp) + n_rxqs * sizeof(struct gr_port_rxq_map); if ((resp = malloc(len)) == NULL) return api_out(ENOMEM, 0); @@ -34,7 +34,7 @@ static struct api_out rxq_list(const void *request, void **response) { n_rxqs = 0; STAILQ_FOREACH (worker, &workers, next) { arrforeach (qmap, worker->rxqs) { - struct br_port_rxq_map *q = &resp->rxqs[n_rxqs]; + struct gr_port_rxq_map *q = &resp->rxqs[n_rxqs]; q->iface_id = port_get_iface(qmap->port_id)->id; q->rxq_id = qmap->queue_id; q->cpu_id = worker->cpu_id; @@ -49,7 +49,7 @@ static struct api_out rxq_list(const void *request, void **response) { } static struct api_out rxq_set(const void *request, void **response) { - const struct br_infra_rxq_set_req *req = request; + const struct gr_infra_rxq_set_req *req = request; struct iface *iface = iface_from_id(req->iface_id); struct iface_info_port *port; @@ -65,18 +65,18 @@ static struct api_out rxq_set(const void *request, void **response) { return api_out(0, 0); } -static struct br_api_handler rxq_list_handler = { +static struct gr_api_handler rxq_list_handler = { .name = "rxq list", - .request_type = BR_INFRA_RXQ_LIST, + .request_type = GR_INFRA_RXQ_LIST, .callback = rxq_list, }; -static struct br_api_handler rxq_set_handler = { +static struct gr_api_handler rxq_set_handler = { .name = "rxq set", - .request_type = BR_INFRA_RXQ_SET, + .request_type = GR_INFRA_RXQ_SET, .callback = rxq_set, }; RTE_INIT(rxq_init) { - br_register_api_handler(&rxq_list_handler); - br_register_api_handler(&rxq_set_handler); + gr_register_api_handler(&rxq_list_handler); + gr_register_api_handler(&rxq_set_handler); } diff --git a/modules/infra/api/stats.c b/modules/infra/api/stats.c index 6fd30cb3..731633a9 100644 --- a/modules/infra/api/stats.c +++ b/modules/infra/api/stats.c @@ -1,13 +1,13 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -27,8 +27,8 @@ struct stat_entry { }; static struct api_out stats_get(const void *request, void **response) { - const struct br_infra_stats_get_req *req = request; - struct br_infra_stats_get_resp *resp = NULL; + const struct gr_infra_stats_get_req *req = request; + struct gr_infra_stats_get_resp *resp = NULL; struct stat_entry *smap = NULL; size_t len, n_stats; char name[64]; @@ -36,7 +36,7 @@ static struct api_out stats_get(const void *request, void **response) { sh_new_arena(smap); - if (req->flags & BR_INFRA_STAT_F_SW) { + if (req->flags & GR_INFRA_STAT_F_SW) { struct worker *worker; STAILQ_FOREACH (worker, &workers, next) { @@ -63,13 +63,13 @@ static struct api_out stats_get(const void *request, void **response) { } } - if (req->flags & BR_INFRA_STAT_F_HW) { + if (req->flags & GR_INFRA_STAT_F_HW) { struct rte_eth_xstat_name *names = NULL; struct rte_eth_xstat *xstats = NULL; struct iface *iface = NULL; unsigned num; - while ((iface = iface_next(BR_IFACE_TYPE_PORT, iface)) != NULL) { + while ((iface = iface_next(GR_IFACE_TYPE_PORT, iface)) != NULL) { struct iface_info_port *port = (struct iface_info_port *)iface->info; // call first with NULL/0 to get the exact count @@ -112,7 +112,7 @@ static struct api_out stats_get(const void *request, void **response) { n_stats = 0; for (unsigned i = 0; i < shlenu(smap); i++) { struct stat_entry *e = &smap[i]; - if (e->value.objs == 0 && !(req->flags & BR_INFRA_STAT_F_ZERO)) + if (e->value.objs == 0 && !(req->flags & GR_INFRA_STAT_F_ZERO)) continue; switch (fnmatch(req->pattern, e->key, 0)) { case 0: @@ -126,7 +126,7 @@ static struct api_out stats_get(const void *request, void **response) { } // allocate correct response size - len = sizeof(*resp) + n_stats * sizeof(struct br_infra_stat); + len = sizeof(*resp) + n_stats * sizeof(struct gr_infra_stat); if ((resp = calloc(1, len)) == NULL) { ret = -ENOMEM; goto err; @@ -135,8 +135,8 @@ static struct api_out stats_get(const void *request, void **response) { // fill in response for (unsigned i = 0; i < shlenu(smap); i++) { struct stat_entry *e = &smap[i]; - struct br_infra_stat *s; - if (e->value.objs == 0 && !(req->flags & BR_INFRA_STAT_F_ZERO)) + struct gr_infra_stat *s; + if (e->value.objs == 0 && !(req->flags & GR_INFRA_STAT_F_ZERO)) continue; switch (fnmatch(req->pattern, e->key, 0)) { case 0: @@ -174,7 +174,7 @@ static struct api_out stats_reset(const void *request, void **response) { atomic_store(&worker->stats_reset, true); iface = NULL; - while ((iface = iface_next(BR_IFACE_TYPE_PORT, iface)) != NULL) { + while ((iface = iface_next(GR_IFACE_TYPE_PORT, iface)) != NULL) { struct iface_info_port *port = (struct iface_info_port *)iface->info; if ((ret = rte_eth_stats_reset(port->port_id)) < 0) return api_out(-ret, 0); @@ -185,19 +185,19 @@ static struct api_out stats_reset(const void *request, void **response) { return api_out(0, 0); } -static struct br_api_handler stats_get_handler = { +static struct gr_api_handler stats_get_handler = { .name = "stats get", - .request_type = BR_INFRA_STATS_GET, + .request_type = GR_INFRA_STATS_GET, .callback = stats_get, }; -static struct br_api_handler stats_reset_handler = { +static struct gr_api_handler stats_reset_handler = { .name = "stats reset", - .request_type = BR_INFRA_STATS_RESET, + .request_type = GR_INFRA_STATS_RESET, .callback = stats_reset, }; RTE_INIT(infra_stats_init) { - br_register_api_handler(&stats_get_handler); - br_register_api_handler(&stats_reset_handler); + gr_register_api_handler(&stats_get_handler); + gr_register_api_handler(&stats_reset_handler); } diff --git a/modules/infra/cli/br_cli_iface.h b/modules/infra/cli/gr_cli_iface.h similarity index 79% rename from modules/infra/cli/br_cli_iface.h rename to modules/infra/cli/gr_cli_iface.h index 37379f3e..52e2fd91 100644 --- a/modules/infra/cli/br_cli_iface.h +++ b/modules/infra/cli/gr_cli_iface.h @@ -1,10 +1,10 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#ifndef _BR_CLI_IFACE -#define _BR_CLI_IFACE +#ifndef _GR_CLI_IFACE +#define _GR_CLI_IFACE -#include +#include #include @@ -15,29 +15,29 @@ struct cli_iface_type { STAILQ_ENTRY(cli_iface_type) next; uint16_t type_id; const char *name; - void (*show)(const struct br_api_client *c, const struct br_iface *); - void (*list_info)(const struct br_api_client *c, const struct br_iface *, char *, size_t); + void (*show)(const struct gr_api_client *c, const struct gr_iface *); + void (*list_info)(const struct gr_api_client *c, const struct gr_iface *, char *, size_t); }; void register_iface_type(struct cli_iface_type *); const struct cli_iface_type *type_from_name(const char *name); const struct cli_iface_type *type_from_id(uint16_t type_id); -int iface_from_name(const struct br_api_client *c, const char *name, struct br_iface *iface); -int iface_from_id(const struct br_api_client *c, uint16_t ifid, struct br_iface *iface); +int iface_from_name(const struct gr_api_client *c, const char *name, struct gr_iface *iface); +int iface_from_id(const struct gr_api_client *c, uint16_t ifid, struct gr_iface *iface); struct ec_node; struct ec_comp; int complete_iface_types( - const struct br_api_client *c, + const struct gr_api_client *c, const struct ec_node *node, struct ec_comp *comp, const char *arg, void *cb_arg ); int complete_iface_names( - const struct br_api_client *c, + const struct gr_api_client *c, const struct ec_node *node, struct ec_comp *comp, const char *arg, @@ -63,9 +63,9 @@ int complete_iface_names( ) uint64_t parse_iface_args( - const struct br_api_client *c, + const struct gr_api_client *c, const struct ec_pnode *p, - struct br_iface *iface, + struct gr_iface *iface, bool update ); diff --git a/modules/infra/cli/graph.c b/modules/infra/cli/graph.c index 718e7a7f..2c0c2a3e 100644 --- a/modules/infra/cli/graph.c +++ b/modules/infra/cli/graph.c @@ -1,23 +1,23 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include -static cmd_status_t graph_dump(const struct br_api_client *c, const struct ec_pnode *p) { - const struct br_infra_graph_dump_resp *resp; +static cmd_status_t graph_dump(const struct gr_api_client *c, const struct ec_pnode *p) { + const struct gr_infra_graph_dump_resp *resp; void *resp_ptr = NULL; (void)p; - if (br_api_client_send_recv(c, BR_INFRA_GRAPH_DUMP, 0, NULL, &resp_ptr) < 0) + if (gr_api_client_send_recv(c, GR_INFRA_GRAPH_DUMP, 0, NULL, &resp_ptr) < 0) return CMD_ERROR; resp = resp_ptr; @@ -42,7 +42,7 @@ static int ctx_init(struct ec_node *root) { return 0; } -static struct br_cli_context ctx = { +static struct gr_cli_context ctx = { .name = "graph", .init = ctx_init, }; diff --git a/modules/infra/cli/iface.c b/modules/infra/cli/iface.c index d66f78c2..00ba26f1 100644 --- a/modules/infra/cli/iface.c +++ b/modules/infra/cli/iface.c @@ -1,14 +1,14 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#include "br_cli_iface.h" +#include "gr_cli_iface.h" -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include @@ -39,7 +39,7 @@ const struct cli_iface_type *type_from_name(const char *name) { } int complete_iface_types( - const struct br_api_client *c, + const struct gr_api_client *c, const struct ec_node *node, struct ec_comp *comp, const char *arg, @@ -70,24 +70,24 @@ const struct cli_iface_type *type_from_id(uint16_t type_id) { } int complete_iface_names( - const struct br_api_client *c, + const struct gr_api_client *c, const struct ec_node *node, struct ec_comp *comp, const char *arg, void *cb_arg ) { - struct br_infra_iface_list_req req = {.type = (uintptr_t)cb_arg}; - const struct br_infra_iface_list_resp *resp; + struct gr_infra_iface_list_req req = {.type = (uintptr_t)cb_arg}; + const struct gr_infra_iface_list_resp *resp; void *resp_ptr = NULL; int ret = -1; - if (br_api_client_send_recv(c, BR_INFRA_IFACE_LIST, sizeof(req), &req, &resp_ptr) < 0) + if (gr_api_client_send_recv(c, GR_INFRA_IFACE_LIST, sizeof(req), &req, &resp_ptr) < 0) goto fail; resp = resp_ptr; for (uint16_t i = 0; i < resp->n_ifaces; i++) { - const struct br_iface *iface = &resp->ifaces[i]; + const struct gr_iface *iface = &resp->ifaces[i]; if (!ec_str_startswith(iface->name, arg)) continue; if (!ec_comp_add_item(comp, node, EC_COMP_FULL, arg, iface->name)) @@ -100,9 +100,9 @@ int complete_iface_names( return ret; } -int iface_from_name(const struct br_api_client *c, const char *name, struct br_iface *iface) { - struct br_infra_iface_list_req req = {.type = BR_IFACE_TYPE_UNDEF}; - const struct br_infra_iface_list_resp *resp; +int iface_from_name(const struct gr_api_client *c, const char *name, struct gr_iface *iface) { + struct gr_infra_iface_list_req req = {.type = GR_IFACE_TYPE_UNDEF}; + const struct gr_infra_iface_list_resp *resp; void *resp_ptr = NULL; int ret = -1; @@ -111,12 +111,12 @@ int iface_from_name(const struct br_api_client *c, const char *name, struct br_i goto out; } - if (br_api_client_send_recv(c, BR_INFRA_IFACE_LIST, sizeof(req), &req, &resp_ptr) < 0) + if (gr_api_client_send_recv(c, GR_INFRA_IFACE_LIST, sizeof(req), &req, &resp_ptr) < 0) goto out; resp = resp_ptr; for (uint16_t i = 0; i < resp->n_ifaces; i++) { - const struct br_iface *iter = &resp->ifaces[i]; + const struct gr_iface *iter = &resp->ifaces[i]; if (strcmp(iter->name, name) == 0) { memcpy(iface, iter, sizeof(*iface)); ret = 0; @@ -130,12 +130,12 @@ int iface_from_name(const struct br_api_client *c, const char *name, struct br_i return ret; } -int iface_from_id(const struct br_api_client *c, uint16_t iface_id, struct br_iface *iface) { - struct br_infra_iface_get_req req = {.iface_id = iface_id}; - const struct br_infra_iface_get_resp *resp; +int iface_from_id(const struct gr_api_client *c, uint16_t iface_id, struct gr_iface *iface) { + struct gr_infra_iface_get_req req = {.iface_id = iface_id}; + const struct gr_infra_iface_get_resp *resp; void *resp_ptr = NULL; - if (br_api_client_send_recv(c, BR_INFRA_IFACE_GET, sizeof(req), &req, &resp_ptr) < 0) + if (gr_api_client_send_recv(c, GR_INFRA_IFACE_GET, sizeof(req), &req, &resp_ptr) < 0) return -1; resp = resp_ptr; @@ -146,9 +146,9 @@ int iface_from_id(const struct br_api_client *c, uint16_t iface_id, struct br_if } uint64_t parse_iface_args( - const struct br_api_client *c, + const struct gr_api_client *c, const struct ec_pnode *p, - struct br_iface *iface, + struct gr_iface *iface, bool update ) { const char *name, *promisc, *allmulti; @@ -166,71 +166,71 @@ uint64_t parse_iface_args( errno = ENAMETOOLONG; goto err; } - set_attrs |= BR_IFACE_SET_NAME; + set_attrs |= GR_IFACE_SET_NAME; memccpy(iface->name, name, 0, sizeof(iface->name)); } if (arg_str(p, "up")) { - iface->flags |= BR_IFACE_F_UP; - set_attrs |= BR_IFACE_SET_FLAGS; + iface->flags |= GR_IFACE_F_UP; + set_attrs |= GR_IFACE_SET_FLAGS; } else if (arg_str(p, "down")) { - iface->flags &= ~BR_IFACE_F_UP; - set_attrs |= BR_IFACE_SET_FLAGS; + iface->flags &= ~GR_IFACE_F_UP; + set_attrs |= GR_IFACE_SET_FLAGS; } promisc = arg_str(p, "PROMISC"); if (promisc != NULL && strcmp(promisc, "on") == 0) { - iface->flags |= BR_IFACE_F_PROMISC; - set_attrs |= BR_IFACE_SET_FLAGS; + iface->flags |= GR_IFACE_F_PROMISC; + set_attrs |= GR_IFACE_SET_FLAGS; } else if (promisc != NULL && strcmp(promisc, "off") == 0) { - iface->flags &= ~BR_IFACE_F_PROMISC; - set_attrs |= BR_IFACE_SET_FLAGS; + iface->flags &= ~GR_IFACE_F_PROMISC; + set_attrs |= GR_IFACE_SET_FLAGS; } allmulti = arg_str(p, "ALLMULTI"); if (allmulti != NULL && strcmp(allmulti, "on") == 0) { - iface->flags |= BR_IFACE_F_ALLMULTI; - set_attrs |= BR_IFACE_SET_FLAGS; + iface->flags |= GR_IFACE_F_ALLMULTI; + set_attrs |= GR_IFACE_SET_FLAGS; } else if (allmulti != NULL && strcmp(allmulti, "off") == 0) { - iface->flags &= ~BR_IFACE_F_ALLMULTI; - set_attrs |= BR_IFACE_SET_FLAGS; + iface->flags &= ~GR_IFACE_F_ALLMULTI; + set_attrs |= GR_IFACE_SET_FLAGS; } if (arg_u16(p, "MTU", &iface->mtu) == 0) - set_attrs |= BR_IFACE_SET_MTU; + set_attrs |= GR_IFACE_SET_MTU; if (arg_u16(p, "VRF", &iface->vrf_id) == 0) - set_attrs |= BR_IFACE_SET_VRF; + set_attrs |= GR_IFACE_SET_VRF; return set_attrs; err: return 0; } -static cmd_status_t iface_del(const struct br_api_client *c, const struct ec_pnode *p) { - struct br_infra_iface_del_req req; - struct br_iface iface; +static cmd_status_t iface_del(const struct gr_api_client *c, const struct ec_pnode *p) { + struct gr_infra_iface_del_req req; + struct gr_iface iface; if (iface_from_name(c, arg_str(p, "NAME"), &iface) < 0) return CMD_ERROR; req.iface_id = iface.id; - if (br_api_client_send_recv(c, BR_INFRA_IFACE_DEL, sizeof(req), &req, NULL) < 0) + if (gr_api_client_send_recv(c, GR_INFRA_IFACE_DEL, sizeof(req), &req, NULL) < 0) return CMD_ERROR; return CMD_SUCCESS; } static int iface_order(const void *ia, const void *ib) { - const struct br_iface *a = ia; - const struct br_iface *b = ib; + const struct gr_iface *a = ia; + const struct gr_iface *b = ib; return a->id - b->id; } -static cmd_status_t iface_list(const struct br_api_client *c, const struct ec_pnode *p) { +static cmd_status_t iface_list(const struct gr_api_client *c, const struct ec_pnode *p) { struct libscols_table *table = scols_new_table(); - struct br_infra_iface_list_resp *resp; - struct br_infra_iface_list_req req; + struct gr_infra_iface_list_resp *resp; + struct gr_infra_iface_list_req req; const struct cli_iface_type *type; void *resp_ptr = NULL; @@ -239,11 +239,11 @@ static cmd_status_t iface_list(const struct br_api_client *c, const struct ec_pn type = type_from_name(arg_str(p, "TYPE")); if (type == NULL) - req.type = BR_IFACE_TYPE_UNDEF; + req.type = GR_IFACE_TYPE_UNDEF; else req.type = type->type_id; - if (br_api_client_send_recv(c, BR_INFRA_IFACE_LIST, sizeof(req), &req, &resp_ptr) < 0) + if (gr_api_client_send_recv(c, GR_INFRA_IFACE_LIST, sizeof(req), &req, &resp_ptr) < 0) return CMD_ERROR; resp = resp_ptr; @@ -258,7 +258,7 @@ static cmd_status_t iface_list(const struct br_api_client *c, const struct ec_pn scols_table_set_column_separator(table, " "); for (size_t i = 0; i < resp->n_ifaces; i++) { - const struct br_iface *iface = &resp->ifaces[i]; + const struct gr_iface *iface = &resp->ifaces[i]; const struct cli_iface_type *type = type_from_id(iface->type); struct libscols_line *line = scols_table_new_line(table, NULL); char buf[BUFSIZ]; @@ -271,15 +271,15 @@ static cmd_status_t iface_list(const struct br_api_client *c, const struct ec_pn scols_line_sprintf(line, 1, "%u", iface->id); // flags - if (iface->flags & BR_IFACE_F_UP) + if (iface->flags & GR_IFACE_F_UP) n += snprintf(buf + n, sizeof(buf) - n, "up"); else n += snprintf(buf + n, sizeof(buf) - n, "down"); - if (iface->state & BR_IFACE_S_RUNNING) + if (iface->state & GR_IFACE_S_RUNNING) n += snprintf(buf + n, sizeof(buf) - n, " running"); - if (iface->flags & BR_IFACE_F_PROMISC) + if (iface->flags & GR_IFACE_F_PROMISC) n += snprintf(buf + n, sizeof(buf) - n, " promisc"); - if (iface->flags & BR_IFACE_F_ALLMULTI) + if (iface->flags & GR_IFACE_F_ALLMULTI) n += snprintf(buf + n, sizeof(buf) - n, " allmulti"); scols_line_set_data(line, 2, buf); @@ -308,9 +308,9 @@ static cmd_status_t iface_list(const struct br_api_client *c, const struct ec_pn return CMD_SUCCESS; } -static cmd_status_t iface_show(const struct br_api_client *c, const struct ec_pnode *p) { +static cmd_status_t iface_show(const struct gr_api_client *c, const struct ec_pnode *p) { const struct cli_iface_type *type; - struct br_iface iface; + struct gr_iface iface; if (arg_str(p, "all") != NULL || arg_str(p, "TYPE") != NULL) return iface_list(c, p); @@ -323,15 +323,15 @@ static cmd_status_t iface_show(const struct br_api_client *c, const struct ec_pn printf("name: %s\n", iface.name); printf("id: %u\n", iface.id); printf("flags: "); - if (iface.flags & BR_IFACE_F_UP) + if (iface.flags & GR_IFACE_F_UP) printf("up"); else printf("down"); - if (iface.state & BR_IFACE_S_RUNNING) + if (iface.state & GR_IFACE_S_RUNNING) printf(" running"); - if (iface.flags & BR_IFACE_F_PROMISC) + if (iface.flags & GR_IFACE_F_PROMISC) printf(" promisc"); - if (iface.flags & BR_IFACE_F_ALLMULTI) + if (iface.flags & GR_IFACE_F_ALLMULTI) printf(" allmulti"); printf("\n"); printf("vrf: %u\n", iface.vrf_id); @@ -357,7 +357,7 @@ static int ctx_init(struct ec_node *root) { "Delete an existing interface.", with_help( "Interface name.", - ec_node_dyn("NAME", complete_iface_names, INT2PTR(BR_IFACE_TYPE_UNDEF)) + ec_node_dyn("NAME", complete_iface_names, INT2PTR(GR_IFACE_TYPE_UNDEF)) ) ); if (ret < 0) @@ -370,7 +370,7 @@ static int ctx_init(struct ec_node *root) { with_help("Show all interfaces.", ec_node_str("all", "all")), with_help( "Show only this interface.", - ec_node_dyn("NAME", complete_iface_names, INT2PTR(BR_IFACE_TYPE_UNDEF)) + ec_node_dyn("NAME", complete_iface_names, INT2PTR(GR_IFACE_TYPE_UNDEF)) ), with_help( "Show only this type of interface.", @@ -381,7 +381,7 @@ static int ctx_init(struct ec_node *root) { return 0; } -static struct br_cli_context ctx = { +static struct gr_cli_context ctx = { .name = "infra iface", .init = ctx_init, }; diff --git a/modules/infra/cli/port.c b/modules/infra/cli/port.c index e74666bd..ac0c65fa 100644 --- a/modules/infra/cli/port.c +++ b/modules/infra/cli/port.c @@ -1,13 +1,13 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#include "br_cli_iface.h" +#include "gr_cli_iface.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include @@ -15,8 +15,8 @@ #include #include -static void port_show(const struct br_api_client *, const struct br_iface *iface) { - const struct br_iface_info_port *port = (const struct br_iface_info_port *)iface->info; +static void port_show(const struct gr_api_client *, const struct gr_iface *iface) { + const struct gr_iface_info_port *port = (const struct gr_iface_info_port *)iface->info; printf("devargs: %s\n", port->devargs); printf("mac: " ETH_ADDR_FMT "\n", ETH_BYTES_SPLIT(port->mac.bytes)); printf("n_rxq: %u\n", port->n_rxq); @@ -26,8 +26,8 @@ static void port_show(const struct br_api_client *, const struct br_iface *iface } static void -port_list_info(const struct br_api_client *, const struct br_iface *iface, char *buf, size_t len) { - const struct br_iface_info_port *port = (const struct br_iface_info_port *)iface->info; +port_list_info(const struct gr_api_client *, const struct gr_iface *iface, char *buf, size_t len) { + const struct gr_iface_info_port *port = (const struct gr_iface_info_port *)iface->info; snprintf( buf, len, @@ -38,23 +38,23 @@ port_list_info(const struct br_api_client *, const struct br_iface *iface, char } static struct cli_iface_type port_type = { - .type_id = BR_IFACE_TYPE_PORT, + .type_id = GR_IFACE_TYPE_PORT, .name = "port", .show = port_show, .list_info = port_list_info, }; static uint64_t parse_port_args( - const struct br_api_client *c, + const struct gr_api_client *c, const struct ec_pnode *p, - struct br_iface *iface, + struct gr_iface *iface, bool update ) { uint64_t set_attrs = parse_iface_args(c, p, iface, update); - struct br_iface_info_port *port; + struct gr_iface_info_port *port; const char *devargs; - port = (struct br_iface_info_port *)iface->info; + port = (struct gr_iface_info_port *)iface->info; devargs = arg_str(p, "DEVARGS"); if (devargs != NULL) { if (strlen(devargs) >= sizeof(port->devargs)) { @@ -63,15 +63,15 @@ static uint64_t parse_port_args( } memccpy(port->devargs, devargs, 0, sizeof(port->devargs)); } - if (br_eth_addr_parse(arg_str(p, "MAC"), &port->mac) == 0) - set_attrs |= BR_PORT_SET_MAC; + if (gr_eth_addr_parse(arg_str(p, "MAC"), &port->mac) == 0) + set_attrs |= GR_PORT_SET_MAC; if (arg_u16(p, "N_RXQ", &port->n_rxq) == 0) - set_attrs |= BR_PORT_SET_N_RXQS; + set_attrs |= GR_PORT_SET_N_RXQS; if (arg_u16(p, "Q_SIZE", &port->rxq_size) == 0) { port->txq_size = port->rxq_size; - set_attrs |= BR_PORT_SET_Q_SIZE; + set_attrs |= GR_PORT_SET_Q_SIZE; } if (set_attrs == 0) @@ -81,17 +81,17 @@ static uint64_t parse_port_args( return 0; } -static cmd_status_t port_add(const struct br_api_client *c, const struct ec_pnode *p) { - const struct br_infra_iface_add_resp *resp; - struct br_infra_iface_add_req req = { - .iface = {.type = BR_IFACE_TYPE_PORT, .flags = BR_IFACE_F_UP} +static cmd_status_t port_add(const struct gr_api_client *c, const struct ec_pnode *p) { + const struct gr_infra_iface_add_resp *resp; + struct gr_infra_iface_add_req req = { + .iface = {.type = GR_IFACE_TYPE_PORT, .flags = GR_IFACE_F_UP} }; void *resp_ptr = NULL; if (parse_port_args(c, p, &req.iface, false) == 0) return CMD_ERROR; - if (br_api_client_send_recv(c, BR_INFRA_IFACE_ADD, sizeof(req), &req, &resp_ptr) < 0) + if (gr_api_client_send_recv(c, GR_INFRA_IFACE_ADD, sizeof(req), &req, &resp_ptr) < 0) return CMD_ERROR; resp = resp_ptr; @@ -100,21 +100,21 @@ static cmd_status_t port_add(const struct br_api_client *c, const struct ec_pnod return CMD_SUCCESS; } -static cmd_status_t port_set(const struct br_api_client *c, const struct ec_pnode *p) { - struct br_infra_iface_set_req req = {0}; +static cmd_status_t port_set(const struct gr_api_client *c, const struct ec_pnode *p) { + struct gr_infra_iface_set_req req = {0}; if ((req.set_attrs = parse_port_args(c, p, &req.iface, true)) == 0) return CMD_ERROR; - if (br_api_client_send_recv(c, BR_INFRA_IFACE_SET, sizeof(req), &req, NULL) < 0) + if (gr_api_client_send_recv(c, GR_INFRA_IFACE_SET, sizeof(req), &req, NULL) < 0) return CMD_ERROR; return CMD_SUCCESS; } -static cmd_status_t rxq_set(const struct br_api_client *c, const struct ec_pnode *p) { - struct br_infra_rxq_set_req req; - struct br_iface iface; +static cmd_status_t rxq_set(const struct gr_api_client *c, const struct ec_pnode *p) { + struct gr_infra_rxq_set_req req; + struct gr_iface iface; if (iface_from_name(c, arg_str(p, "NAME"), &iface) < 0) return CMD_ERROR; @@ -126,15 +126,15 @@ static cmd_status_t rxq_set(const struct br_api_client *c, const struct ec_pnode if (arg_u16(p, "CPU", &req.cpu_id) < 0) return CMD_ERROR; - if (br_api_client_send_recv(c, BR_INFRA_RXQ_SET, sizeof(req), &req, NULL) < 0) + if (gr_api_client_send_recv(c, GR_INFRA_RXQ_SET, sizeof(req), &req, NULL) < 0) return CMD_ERROR; return CMD_SUCCESS; } static int rxqs_order(const void *a, const void *b) { - const struct br_port_rxq_map *rxq_a = a; - const struct br_port_rxq_map *rxq_b = b; + const struct gr_port_rxq_map *rxq_a = a; + const struct gr_port_rxq_map *rxq_b = b; int v = rxq_a->iface_id - rxq_b->iface_id; if (v != 0) return v; @@ -144,9 +144,9 @@ static int rxqs_order(const void *a, const void *b) { return rxq_a->cpu_id - rxq_b->cpu_id; } -static cmd_status_t rxq_list(const struct br_api_client *c, const struct ec_pnode *p) { +static cmd_status_t rxq_list(const struct gr_api_client *c, const struct ec_pnode *p) { struct libscols_table *table = scols_new_table(); - struct br_infra_rxq_list_resp *resp; + struct gr_infra_rxq_list_resp *resp; void *resp_ptr = NULL; (void)p; @@ -154,7 +154,7 @@ static cmd_status_t rxq_list(const struct br_api_client *c, const struct ec_pnod if (table == NULL) return CMD_ERROR; - if (br_api_client_send_recv(c, BR_INFRA_RXQ_LIST, 0, NULL, &resp_ptr) < 0) + if (gr_api_client_send_recv(c, GR_INFRA_RXQ_LIST, 0, NULL, &resp_ptr) < 0) return CMD_ERROR; resp = resp_ptr; @@ -168,8 +168,8 @@ static cmd_status_t rxq_list(const struct br_api_client *c, const struct ec_pnod for (size_t i = 0; i < resp->n_rxqs; i++) { struct libscols_line *line = scols_table_new_line(table, NULL); - const struct br_port_rxq_map *q = &resp->rxqs[i]; - struct br_iface iface; + const struct gr_port_rxq_map *q = &resp->rxqs[i]; + struct gr_iface iface; if (iface_from_id(c, q->iface_id, &iface) == 0) scols_line_sprintf(line, 0, "%s", iface.name); @@ -215,7 +215,7 @@ static int ctx_init(struct ec_node *root) { "Modify port parameters.", with_help( "Interface name.", - ec_node_dyn("NAME", complete_iface_names, INT2PTR(BR_IFACE_TYPE_PORT)) + ec_node_dyn("NAME", complete_iface_names, INT2PTR(GR_IFACE_TYPE_PORT)) ), with_help("New interface name.", ec_node("any", "NEW_NAME")), PORT_ATTRS_ARGS @@ -229,7 +229,7 @@ static int ctx_init(struct ec_node *root) { "Set DPDK port queue mapping.", with_help( "Interface name.", - ec_node_dyn("NAME", complete_iface_names, INT2PTR(BR_IFACE_TYPE_PORT)) + ec_node_dyn("NAME", complete_iface_names, INT2PTR(GR_IFACE_TYPE_PORT)) ), with_help("RX queue ID.", ec_node_uint("RXQ", 0, UINT16_MAX - 1, 10)), with_help("Worker CPU ID.", ec_node_uint("CPU", 0, UINT16_MAX - 1, 10)) @@ -248,7 +248,7 @@ static int ctx_init(struct ec_node *root) { return 0; } -static struct br_cli_context ctx = { +static struct gr_cli_context ctx = { .name = "infra port", .init = ctx_init, }; diff --git a/modules/infra/cli/stats.c b/modules/infra/cli/stats.c index 5d265c9f..1808b756 100644 --- a/modules/infra/cli/stats.c +++ b/modules/infra/cli/stats.c @@ -1,11 +1,11 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include @@ -14,14 +14,14 @@ #include static int stats_order_name(const void *sa, const void *sb) { - const struct br_infra_stat *a = sa; - const struct br_infra_stat *b = sb; + const struct gr_infra_stat *a = sa; + const struct gr_infra_stat *b = sb; return strncmp(a->name, b->name, sizeof(a->name)); } static int stats_order_cycles(const void *sa, const void *sb) { - const struct br_infra_stat *a = sa; - const struct br_infra_stat *b = sb; + const struct gr_infra_stat *a = sa; + const struct gr_infra_stat *b = sb; if (a->cycles == b->cycles) return 0; if (a->cycles > b->cycles) @@ -29,34 +29,34 @@ static int stats_order_cycles(const void *sa, const void *sb) { return 1; } -static cmd_status_t stats_get(const struct br_api_client *c, const struct ec_pnode *p) { - struct br_infra_stats_get_req req = {.flags = 0}; +static cmd_status_t stats_get(const struct gr_api_client *c, const struct ec_pnode *p) { + struct gr_infra_stats_get_req req = {.flags = 0}; bool brief = arg_str(p, "brief") != NULL; - struct br_infra_stats_get_resp *resp; + struct gr_infra_stats_get_resp *resp; void *resp_ptr = NULL; const char *pattern; if (arg_str(p, "software") != NULL) - req.flags |= BR_INFRA_STAT_F_SW; + req.flags |= GR_INFRA_STAT_F_SW; else if (arg_str(p, "hardware") != NULL) - req.flags |= BR_INFRA_STAT_F_HW; + req.flags |= GR_INFRA_STAT_F_HW; if (arg_str(p, "zero") != NULL) - req.flags |= BR_INFRA_STAT_F_ZERO; + req.flags |= GR_INFRA_STAT_F_ZERO; pattern = arg_str(p, "PATTERN"); if (pattern == NULL) pattern = "*"; snprintf(req.pattern, sizeof(req.pattern), "%s", pattern); - if (br_api_client_send_recv(c, BR_INFRA_STATS_GET, sizeof(req), &req, &resp_ptr) < 0) + if (gr_api_client_send_recv(c, GR_INFRA_STATS_GET, sizeof(req), &req, &resp_ptr) < 0) goto fail; resp = resp_ptr; - if (req.flags & BR_INFRA_STAT_F_HW || brief) { + if (req.flags & GR_INFRA_STAT_F_HW || brief) { qsort(resp->stats, resp->n_stats, sizeof(*resp->stats), stats_order_name); for (size_t i = 0; i < resp->n_stats; i++) { - const struct br_infra_stat *s = &resp->stats[i]; - if (req.flags & BR_INFRA_STAT_F_HW || brief) + const struct gr_infra_stat *s = &resp->stats[i]; + if (req.flags & GR_INFRA_STAT_F_HW || brief) printf("%s %lu\n", s->name, s->objs); } } else { @@ -75,7 +75,7 @@ static cmd_status_t stats_get(const struct br_api_client *c, const struct ec_pno for (size_t i = 0; i < resp->n_stats; i++) { struct libscols_line *line = scols_table_new_line(table, NULL); double pkt_call = 0, cycles_pkt = 0, cycles_call = 0; - const struct br_infra_stat *s = &resp->stats[i]; + const struct gr_infra_stat *s = &resp->stats[i]; if (s->calls != 0) { pkt_call = ((double)s->objs) / ((double)s->calls); @@ -103,10 +103,10 @@ static cmd_status_t stats_get(const struct br_api_client *c, const struct ec_pno return CMD_ERROR; } -static cmd_status_t stats_reset(const struct br_api_client *c, const struct ec_pnode *p) { +static cmd_status_t stats_reset(const struct gr_api_client *c, const struct ec_pnode *p) { (void)p; - if (br_api_client_send_recv(c, BR_INFRA_STATS_RESET, 0, NULL, NULL) < 0) + if (gr_api_client_send_recv(c, GR_INFRA_STATS_RESET, 0, NULL, NULL) < 0) return CMD_ERROR; return CMD_SUCCESS; @@ -137,7 +137,7 @@ static int ctx_init(struct ec_node *root) { return 0; } -static struct br_cli_context ctx = { +static struct gr_cli_context ctx = { .name = "stats", .init = ctx_init, }; diff --git a/modules/infra/cli/vlan.c b/modules/infra/cli/vlan.c index a4ea4cf5..009733a1 100644 --- a/modules/infra/cli/vlan.c +++ b/modules/infra/cli/vlan.c @@ -1,13 +1,13 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#include "br_cli_iface.h" +#include "gr_cli_iface.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include @@ -15,9 +15,9 @@ #include #include -static void vlan_show(const struct br_api_client *c, const struct br_iface *iface) { - const struct br_iface_info_vlan *vlan = (const struct br_iface_info_vlan *)iface->info; - struct br_iface parent; +static void vlan_show(const struct gr_api_client *c, const struct gr_iface *iface) { + const struct gr_iface_info_vlan *vlan = (const struct gr_iface_info_vlan *)iface->info; + struct gr_iface parent; if (iface_from_id(c, vlan->parent_id, &parent) < 0) printf("parent: %u\n", vlan->parent_id); @@ -27,9 +27,9 @@ static void vlan_show(const struct br_api_client *c, const struct br_iface *ifac } static void -vlan_list_info(const struct br_api_client *c, const struct br_iface *iface, char *buf, size_t len) { - const struct br_iface_info_vlan *vlan = (const struct br_iface_info_vlan *)iface->info; - struct br_iface parent; +vlan_list_info(const struct gr_api_client *c, const struct gr_iface *iface, char *buf, size_t len) { + const struct gr_iface_info_vlan *vlan = (const struct gr_iface_info_vlan *)iface->info; + struct gr_iface parent; if (iface_from_id(c, vlan->parent_id, &parent) < 0) snprintf(buf, len, "parent=%u vlan_id=%u", vlan->parent_id, vlan->vlan_id); @@ -38,52 +38,52 @@ vlan_list_info(const struct br_api_client *c, const struct br_iface *iface, char } static struct cli_iface_type vlan_type = { - .type_id = BR_IFACE_TYPE_VLAN, + .type_id = GR_IFACE_TYPE_VLAN, .name = "vlan", .show = vlan_show, .list_info = vlan_list_info, }; static uint64_t parse_vlan_args( - const struct br_api_client *c, + const struct gr_api_client *c, const struct ec_pnode *p, - struct br_iface *iface, + struct gr_iface *iface, bool update ) { uint64_t set_attrs = parse_iface_args(c, p, iface, update); - struct br_iface_info_vlan *vlan; + struct gr_iface_info_vlan *vlan; const char *parent_name; - struct br_iface parent; + struct gr_iface parent; - vlan = (struct br_iface_info_vlan *)iface->info; + vlan = (struct gr_iface_info_vlan *)iface->info; parent_name = arg_str(p, "PARENT"); if (parent_name != NULL) { if (iface_from_name(c, parent_name, &parent) < 0) return 0; - if (parent.type != BR_IFACE_TYPE_PORT) { + if (parent.type != GR_IFACE_TYPE_PORT) { errno = EMEDIUMTYPE; return 0; } vlan->parent_id = parent.id; - set_attrs |= BR_VLAN_SET_PARENT; + set_attrs |= GR_VLAN_SET_PARENT; } if (arg_u16(p, "VLAN", &vlan->vlan_id) == 0) - set_attrs |= BR_VLAN_SET_VLAN; + set_attrs |= GR_VLAN_SET_VLAN; - if (br_eth_addr_parse(arg_str(p, "MAC"), &vlan->mac) == 0) { - set_attrs |= BR_VLAN_SET_MAC; + if (gr_eth_addr_parse(arg_str(p, "MAC"), &vlan->mac) == 0) { + set_attrs |= GR_VLAN_SET_MAC; } else if (!update) { - const struct br_iface_info_port *port; + const struct gr_iface_info_port *port; if (parent_name == NULL && iface_from_id(c, vlan->parent_id, &parent) < 0) return 0; - if (parent.type != BR_IFACE_TYPE_PORT) { + if (parent.type != GR_IFACE_TYPE_PORT) { errno = EMEDIUMTYPE; return 0; } - port = (const struct br_iface_info_port *)parent.info; + port = (const struct gr_iface_info_port *)parent.info; memcpy(&vlan->mac, &port->mac, sizeof(vlan->mac)); - set_attrs |= BR_VLAN_SET_MAC; + set_attrs |= GR_VLAN_SET_MAC; } if (set_attrs == 0) @@ -91,17 +91,17 @@ static uint64_t parse_vlan_args( return set_attrs; } -static cmd_status_t vlan_add(const struct br_api_client *c, const struct ec_pnode *p) { - const struct br_infra_iface_add_resp *resp; - struct br_infra_iface_add_req req = { - .iface = {.type = BR_IFACE_TYPE_VLAN, .flags = BR_IFACE_F_UP} +static cmd_status_t vlan_add(const struct gr_api_client *c, const struct ec_pnode *p) { + const struct gr_infra_iface_add_resp *resp; + struct gr_infra_iface_add_req req = { + .iface = {.type = GR_IFACE_TYPE_VLAN, .flags = GR_IFACE_F_UP} }; void *resp_ptr = NULL; if (parse_vlan_args(c, p, &req.iface, false) == 0) return CMD_ERROR; - if (br_api_client_send_recv(c, BR_INFRA_IFACE_ADD, sizeof(req), &req, &resp_ptr) < 0) + if (gr_api_client_send_recv(c, GR_INFRA_IFACE_ADD, sizeof(req), &req, &resp_ptr) < 0) return CMD_ERROR; resp = resp_ptr; @@ -110,13 +110,13 @@ static cmd_status_t vlan_add(const struct br_api_client *c, const struct ec_pnod return CMD_SUCCESS; } -static cmd_status_t vlan_set(const struct br_api_client *c, const struct ec_pnode *p) { - struct br_infra_iface_set_req req = {0}; +static cmd_status_t vlan_set(const struct gr_api_client *c, const struct ec_pnode *p) { + struct gr_infra_iface_set_req req = {0}; if ((req.set_attrs = parse_vlan_args(c, p, &req.iface, true)) == 0) return CMD_ERROR; - if (br_api_client_send_recv(c, BR_INFRA_IFACE_SET, sizeof(req), &req, NULL) < 0) + if (gr_api_client_send_recv(c, GR_INFRA_IFACE_SET, sizeof(req), &req, NULL) < 0) return CMD_ERROR; return CMD_SUCCESS; @@ -138,7 +138,7 @@ static int ctx_init(struct ec_node *root) { with_help("Interface name.", ec_node("any", "NAME")), with_help( "Parent port interface.", - ec_node_dyn("PARENT", complete_iface_names, INT2PTR(BR_IFACE_TYPE_PORT)) + ec_node_dyn("PARENT", complete_iface_names, INT2PTR(GR_IFACE_TYPE_PORT)) ), with_help("VLAN ID.", ec_node_uint("VLAN", 1, 4095, 10)), VLAN_ATTRS_ARGS @@ -152,12 +152,12 @@ static int ctx_init(struct ec_node *root) { "Modify VLAN parameters.", with_help( "Interface name.", - ec_node_dyn("NAME", complete_iface_names, INT2PTR(BR_IFACE_TYPE_VLAN)) + ec_node_dyn("NAME", complete_iface_names, INT2PTR(GR_IFACE_TYPE_VLAN)) ), with_help("New interface name.", ec_node("any", "NEW_NAME")), with_help( "Parent port interface.", - ec_node_dyn("PARENT", complete_iface_names, INT2PTR(BR_IFACE_TYPE_PORT)) + ec_node_dyn("PARENT", complete_iface_names, INT2PTR(GR_IFACE_TYPE_PORT)) ), with_help("VLAN ID.", ec_node_uint("VLAN", 1, 4095, 10)), VLAN_ATTRS_ARGS @@ -168,7 +168,7 @@ static int ctx_init(struct ec_node *root) { return 0; } -static struct br_cli_context ctx = { +static struct gr_cli_context ctx = { .name = "infra vlan", .init = ctx_init, }; diff --git a/modules/infra/control/br_graph.h b/modules/infra/control/gr_graph.h similarity index 66% rename from modules/infra/control/br_graph.h rename to modules/infra/control/gr_graph.h index cc8959f2..205f0fce 100644 --- a/modules/infra/control/br_graph.h +++ b/modules/infra/control/gr_graph.h @@ -1,46 +1,46 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#ifndef _BR_INFRA_GRAPH -#define _BR_INFRA_GRAPH +#ifndef _GR_INFRA_GRAPH +#define _GR_INFRA_GRAPH #include #include #include -void *br_node_data_get(const char *graph, const char *node); +void *gr_node_data_get(const char *graph, const char *node); -int br_node_data_set(const char *graph, const char *node, void *data); +int gr_node_data_set(const char *graph, const char *node, void *data); -rte_edge_t br_node_attach_parent(const char *parent, const char *node); +rte_edge_t gr_node_attach_parent(const char *parent, const char *node); uint16_t drop_packets(struct rte_graph *, struct rte_node *, void **, uint16_t); -struct br_node_info { +struct gr_node_info { struct rte_node_register *node; void (*register_callback)(void); void (*unregister_callback)(void); - STAILQ_ENTRY(br_node_info) next; + STAILQ_ENTRY(gr_node_info) next; }; -STAILQ_HEAD(node_infos, br_node_info); +STAILQ_HEAD(node_infos, gr_node_info); extern struct node_infos node_infos; -#define BR_NODE_REGISTER(info) \ - RTE_INIT(br_node_register_##info) { \ +#define GR_NODE_REGISTER(info) \ + RTE_INIT(gr_node_register_##info) { \ STAILQ_INSERT_TAIL(&node_infos, &info, next); \ } -#define BR_DROP_REGISTER(node_name) \ +#define GR_DROP_REGISTER(node_name) \ static struct rte_node_register drop_node_##node_name = { \ .name = #node_name, \ .process = drop_packets, \ }; \ - static struct br_node_info drop_info_##node_name = { \ + static struct gr_node_info drop_info_##node_name = { \ .node = &drop_node_##node_name, \ }; \ - RTE_INIT(br_drop_register_##node_name) { \ + RTE_INIT(gr_drop_register_##node_name) { \ STAILQ_INSERT_TAIL(&node_infos, &drop_info_##node_name, next); \ } diff --git a/modules/infra/control/br_iface.h b/modules/infra/control/gr_iface.h similarity index 95% rename from modules/infra/control/br_iface.h rename to modules/infra/control/gr_iface.h index a2b28e66..5da550a9 100644 --- a/modules/infra/control/br_iface.h +++ b/modules/infra/control/gr_iface.h @@ -1,11 +1,11 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#ifndef _BR_INFRA_IFACE -#define _BR_INFRA_IFACE +#ifndef _GR_INFRA_IFACE +#define _GR_INFRA_IFACE -#include -#include +#include +#include #include diff --git a/modules/infra/control/br_port.h b/modules/infra/control/gr_port.h similarity index 90% rename from modules/infra/control/br_port.h rename to modules/infra/control/gr_port.h index 9eb4b8a4..b2c94c3c 100644 --- a/modules/infra/control/br_port.h +++ b/modules/infra/control/gr_port.h @@ -1,10 +1,10 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#ifndef _BR_INFRA_PORT -#define _BR_INFRA_PORT +#ifndef _GR_INFRA_PORT +#define _GR_INFRA_PORT -#include +#include #include #include diff --git a/modules/infra/control/br_vlan.h b/modules/infra/control/gr_vlan.h similarity index 82% rename from modules/infra/control/br_vlan.h rename to modules/infra/control/gr_vlan.h index 1b64efc7..f9957742 100644 --- a/modules/infra/control/br_vlan.h +++ b/modules/infra/control/gr_vlan.h @@ -1,10 +1,10 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#ifndef _BR_INFRA_VLAN_PRIV -#define _BR_INFRA_VLAN_PRIV +#ifndef _GR_INFRA_VLAN_PRIV +#define _GR_INFRA_VLAN_PRIV -#include +#include #include #include diff --git a/modules/infra/control/br_worker.h b/modules/infra/control/gr_worker.h similarity index 96% rename from modules/infra/control/br_worker.h rename to modules/infra/control/gr_worker.h index 79e9b8b7..05629fac 100644 --- a/modules/infra/control/br_worker.h +++ b/modules/infra/control/gr_worker.h @@ -1,8 +1,8 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#ifndef _BR_INFRA_WORKER -#define _BR_INFRA_WORKER +#ifndef _GR_INFRA_WORKER +#define _GR_INFRA_WORKER #include #include diff --git a/modules/infra/control/graph.c b/modules/infra/control/graph.c index d9709c20..6f4960f3 100644 --- a/modules/infra/control/graph.c +++ b/modules/infra/control/graph.c @@ -3,18 +3,18 @@ #include "graph_priv.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -44,7 +44,7 @@ static void set_key(struct node_data_key *key, const char *graph, const char *no memccpy(key->node, node, 0, sizeof(key->node)); } -void *br_node_data_get(const char *graph, const char *node) { +void *gr_node_data_get(const char *graph, const char *node) { struct node_data_key key; void *data = NULL; @@ -56,7 +56,7 @@ void *br_node_data_get(const char *graph, const char *node) { return data; } -int br_node_data_set(const char *graph, const char *node, void *data) { +int gr_node_data_set(const char *graph, const char *node, void *data) { struct node_data_key key; void *old_data = NULL; @@ -72,7 +72,7 @@ int br_node_data_set(const char *graph, const char *node, void *data) { return 0; } -rte_edge_t br_node_attach_parent(const char *parent, const char *node) { +rte_edge_t gr_node_attach_parent(const char *parent, const char *node) { rte_node_t parent_id; rte_edge_t edge; char **names; @@ -154,7 +154,7 @@ static int worker_graph_new(struct worker *worker, uint8_t index) { // unique suffix for this graph graph_uid = (worker->cpu_id << 1) | (0x1 & index); - snprintf(name, sizeof(name), "br-%04x", graph_uid); + snprintf(name, sizeof(name), "gr-%04x", graph_uid); // build rx & tx nodes data len = sizeof(*rx) + n_rxqs * sizeof(struct rx_port_queue); @@ -164,7 +164,7 @@ static int worker_graph_new(struct worker *worker, uint8_t index) { goto err; } n_rxqs = 0; - if (br_args()->poll_mode) + if (gr_args()->poll_mode) max_sleep_us = 0; else max_sleep_us = 1000; // unreasonably long maximum (1ms) @@ -178,7 +178,7 @@ static int worker_graph_new(struct worker *worker, uint8_t index) { qmap->queue_id); rx->queues[n_rxqs].port_id = qmap->port_id; rx->queues[n_rxqs].rxq_id = qmap->queue_id; - if (!br_args()->poll_mode) { + if (!gr_args()->poll_mode) { // divide buffer size by two to take into account // the time to wakeup from sleep rx_buffer_us = port_get_rxq_buffer_us(qmap->port_id, qmap->queue_id) / 2; @@ -188,7 +188,7 @@ static int worker_graph_new(struct worker *worker, uint8_t index) { n_rxqs++; } rx->n_queues = n_rxqs; - if (br_node_data_set(name, "port_rx", rx) < 0) { + if (gr_node_data_set(name, "port_rx", rx) < 0) { if (rte_errno == 0) rte_errno = EINVAL; ret = -rte_errno; @@ -213,7 +213,7 @@ static int worker_graph_new(struct worker *worker, uint8_t index) { qmap->queue_id); tx->txq_ids[qmap->port_id] = qmap->queue_id; } - if (br_node_data_set(name, "port_tx", tx) < 0) { + if (gr_node_data_set(name, "port_tx", tx) < 0) { if (rte_errno == 0) rte_errno = EINVAL; ret = -rte_errno; @@ -276,7 +276,7 @@ int worker_graph_reload_all(void) { static void graph_init(struct event_base *) { struct rte_node_register *reg; - struct br_node_info *info; + struct gr_node_info *info; // register nodes first STAILQ_FOREACH (info, &node_infos, next) { @@ -308,7 +308,7 @@ static void graph_init(struct event_base *) { } static void graph_fini(struct event_base *) { - struct br_node_info *info; + struct gr_node_info *info; const void *key = NULL; void *data = NULL; uint32_t iter; @@ -331,7 +331,7 @@ static void graph_fini(struct event_base *) { node_names = NULL; } -static struct br_module graph_module = { +static struct gr_module graph_module = { .name = "graph", .init = graph_init, .fini = graph_fini, @@ -339,5 +339,5 @@ static struct br_module graph_module = { }; RTE_INIT(control_graph_init) { - br_register_module(&graph_module); + gr_register_module(&graph_module); } diff --git a/modules/infra/control/graph_priv.h b/modules/infra/control/graph_priv.h index ade64921..8b0c9295 100644 --- a/modules/infra/control/graph_priv.h +++ b/modules/infra/control/graph_priv.h @@ -1,10 +1,10 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#ifndef _BR_CONTROL_GRAPH -#define _BR_CONTROL_GRAPH +#ifndef _GR_CONTROL_GRAPH +#define _GR_CONTROL_GRAPH -#include +#include int worker_graph_reload_all(void); void worker_graph_free(struct worker *); diff --git a/modules/infra/control/iface.c b/modules/infra/control/iface.c index 37aad75e..292fabcf 100644 --- a/modules/infra/control/iface.c +++ b/modules/infra/control/iface.c @@ -1,12 +1,12 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include "br_iface.h" +#include "gr_iface.h" -#include -#include -#include -#include +#include +#include +#include +#include #include #include @@ -60,7 +60,7 @@ struct iface *iface_create( if (type == NULL) goto fail; - if (utf8_check(name, BR_IFACE_NAME_SIZE) < 0) + if (utf8_check(name, GR_IFACE_NAME_SIZE) < 0) goto fail; iface = rte_zmalloc(__func__, sizeof(*iface) + type->info_size, RTE_CACHE_LINE_SIZE); @@ -77,7 +77,7 @@ struct iface *iface_create( iface->mtu = mtu; iface->vrf_id = vrf_id; // this is only accessed by the API, no need to copy the name to DPDK memory (hugepages) - iface->name = strndup(name, BR_IFACE_NAME_SIZE); + iface->name = strndup(name, GR_IFACE_NAME_SIZE); if (iface->name == NULL) goto fail; @@ -110,16 +110,16 @@ int iface_reconfig( return errno_set(EINVAL); if ((iface = iface_from_id(ifid)) == NULL) return -1; - if (set_attrs & BR_IFACE_SET_NAME) { - if (utf8_check(name, BR_IFACE_NAME_SIZE) < 0) + if (set_attrs & GR_IFACE_SET_NAME) { + if (utf8_check(name, GR_IFACE_NAME_SIZE) < 0) return -1; const struct iface *i = NULL; - while ((i = iface_next(BR_IFACE_TYPE_UNDEF, i)) != NULL) + while ((i = iface_next(GR_IFACE_TYPE_UNDEF, i)) != NULL) if (i != iface && strcmp(name, i->name) == 0) return errno_set(EEXIST); - char *new_name = strndup(name, BR_IFACE_NAME_SIZE); + char *new_name = strndup(name, GR_IFACE_NAME_SIZE); if (new_name == NULL) return -1; free(iface->name); @@ -135,7 +135,7 @@ uint16_t ifaces_count(uint16_t type_id) { for (uint16_t ifid = 0; ifid < MAX_IFACES; ifid++) { struct iface *iface = ifaces[ifid]; - if (iface != NULL && (type_id == BR_IFACE_TYPE_UNDEF || iface->type_id == type_id)) + if (iface != NULL && (type_id == GR_IFACE_TYPE_UNDEF || iface->type_id == type_id)) count++; } @@ -152,7 +152,7 @@ struct iface *iface_next(uint16_t type_id, const struct iface *prev) { for (uint16_t ifid = start_id; ifid < MAX_IFACES; ifid++) { struct iface *iface = ifaces[ifid]; - if (iface != NULL && (type_id == BR_IFACE_TYPE_UNDEF || iface->type_id == type_id)) + if (iface != NULL && (type_id == GR_IFACE_TYPE_UNDEF || iface->type_id == type_id)) return iface; } @@ -217,7 +217,7 @@ static void iface_fini(struct event_base *) { ifaces = NULL; } -static struct br_module iface_module = { +static struct gr_module iface_module = { .name = "iface", .init = iface_init, .fini = iface_fini, @@ -225,5 +225,5 @@ static struct br_module iface_module = { }; RTE_INIT(iface_constructor) { - br_register_module(&iface_module); + gr_register_module(&iface_module); } diff --git a/modules/infra/control/port.c b/modules/infra/control/port.c index d43c7069..d5a987ba 100644 --- a/modules/infra/control/port.c +++ b/modules/infra/control/port.c @@ -3,13 +3,13 @@ #include "worker_priv.h" -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -221,19 +221,19 @@ int iface_port_reconfig( const void *api_info ) { struct iface_info_port *p = (struct iface_info_port *)iface->info; - const struct br_iface_info_port *api = api_info; + const struct gr_iface_info_port *api = api_info; bool stopped = false; int ret; if ((ret = port_unplug(p->port_id)) < 0) return ret; - if (set_attrs & (BR_PORT_SET_N_RXQS | BR_PORT_SET_N_TXQS | BR_PORT_SET_Q_SIZE)) { - if (set_attrs & BR_PORT_SET_N_RXQS) + if (set_attrs & (GR_PORT_SET_N_RXQS | GR_PORT_SET_N_TXQS | GR_PORT_SET_Q_SIZE)) { + if (set_attrs & GR_PORT_SET_N_RXQS) p->n_rxq = api->n_rxq; - if (set_attrs & BR_PORT_SET_N_TXQS) + if (set_attrs & GR_PORT_SET_N_TXQS) p->n_txq = api->n_txq; - if (set_attrs & BR_PORT_SET_Q_SIZE) { + if (set_attrs & GR_PORT_SET_Q_SIZE) { p->rxq_size = api->rxq_size; p->txq_size = api->rxq_size; } @@ -241,7 +241,7 @@ int iface_port_reconfig( } if (!p->configured - || (set_attrs & (BR_IFACE_SET_FLAGS | BR_IFACE_SET_MTU | BR_PORT_SET_MAC))) { + || (set_attrs & (GR_IFACE_SET_FLAGS | GR_IFACE_SET_MTU | GR_PORT_SET_MAC))) { if ((ret = rte_eth_dev_stop(p->port_id)) < 0) return errno_log(-ret, "rte_eth_dev_stop"); stopped = true; @@ -249,35 +249,35 @@ int iface_port_reconfig( if (!p->configured && (ret = port_configure(p)) < 0) return ret; - if (set_attrs & BR_IFACE_SET_FLAGS) { - if (flags & BR_IFACE_F_PROMISC) + if (set_attrs & GR_IFACE_SET_FLAGS) { + if (flags & GR_IFACE_F_PROMISC) ret = rte_eth_promiscuous_enable(p->port_id); else ret = rte_eth_promiscuous_disable(p->port_id); if (ret < 0) errno_log(-ret, "rte_eth_promiscuous_{en,dis}able"); if (rte_eth_promiscuous_get(p->port_id) == 1) - iface->flags |= BR_IFACE_F_PROMISC; + iface->flags |= GR_IFACE_F_PROMISC; else - iface->flags &= ~BR_IFACE_F_PROMISC; + iface->flags &= ~GR_IFACE_F_PROMISC; - if (flags & BR_IFACE_F_ALLMULTI) + if (flags & GR_IFACE_F_ALLMULTI) ret = rte_eth_allmulticast_enable(p->port_id); else ret = rte_eth_allmulticast_disable(p->port_id); if (ret < 0) errno_log(-ret, "rte_eth_allmulticast_{en,dis}able"); if (rte_eth_allmulticast_get(p->port_id) == 1) - iface->flags |= BR_IFACE_F_ALLMULTI; + iface->flags |= GR_IFACE_F_ALLMULTI; else - iface->flags &= ~BR_IFACE_F_ALLMULTI; + iface->flags &= ~GR_IFACE_F_ALLMULTI; - if (flags & BR_IFACE_F_UP) { + if (flags & GR_IFACE_F_UP) { ret = rte_eth_dev_set_link_up(p->port_id); - iface->flags |= BR_IFACE_F_UP; + iface->flags |= GR_IFACE_F_UP; } else { ret = rte_eth_dev_set_link_down(p->port_id); - iface->flags &= ~BR_IFACE_F_UP; + iface->flags &= ~GR_IFACE_F_UP; } if (ret < 0) errno_log(-ret, "rte_eth_dev_set_link_{up,down}"); @@ -285,13 +285,13 @@ int iface_port_reconfig( struct rte_eth_link link; if (rte_eth_link_get(p->port_id, &link) == 0) { if (link.link_status == RTE_ETH_LINK_UP) - iface->state |= BR_IFACE_S_RUNNING; + iface->state |= GR_IFACE_S_RUNNING; else - iface->state &= ~BR_IFACE_S_RUNNING; + iface->state &= ~GR_IFACE_S_RUNNING; } } - if ((set_attrs & BR_IFACE_SET_MTU) && mtu != 0) { + if ((set_attrs & GR_IFACE_SET_MTU) && mtu != 0) { if ((ret = rte_eth_dev_set_mtu(p->port_id, mtu)) < 0) return errno_log(-ret, "rte_eth_dev_set_mtu"); iface->mtu = mtu; @@ -300,10 +300,10 @@ int iface_port_reconfig( return errno_log(-ret, "rte_eth_dev_get_mtu"); } - if (set_attrs & BR_IFACE_SET_VRF) + if (set_attrs & GR_IFACE_SET_VRF) iface->vrf_id = vrf_id; - if ((set_attrs & BR_PORT_SET_MAC) && !br_eth_addr_is_zero(&api->mac)) { + if ((set_attrs & GR_PORT_SET_MAC) && !gr_eth_addr_is_zero(&api->mac)) { struct rte_ether_addr mac; memcpy(&mac, &api->mac, sizeof(mac)); if ((ret = rte_eth_dev_default_mac_addr_set(p->port_id, &mac)) < 0) @@ -364,11 +364,11 @@ static int iface_port_fini(struct iface *iface) { if (worker_count() != n_workers) { // update the number of tx queues for all ports struct iface *iface = NULL; - while ((iface = iface_next(BR_IFACE_TYPE_PORT, iface)) != NULL) { + while ((iface = iface_next(GR_IFACE_TYPE_PORT, iface)) != NULL) { struct iface_info_port p = {.n_txq = 0}; ret = iface_port_reconfig( iface, - BR_PORT_SET_N_TXQS, + GR_PORT_SET_N_TXQS, iface->flags, iface->mtu, iface->vrf_id, @@ -384,7 +384,7 @@ static int iface_port_fini(struct iface *iface) { static int iface_port_init(struct iface *iface, const void *api_info) { struct iface_info_port *port = (struct iface_info_port *)iface->info; - const struct br_iface_info_port *api = api_info; + const struct gr_iface_info_port *api = api_info; uint16_t port_id = RTE_MAX_ETHPORTS; struct rte_dev_iterator iterator; int ret; @@ -405,7 +405,7 @@ static int iface_port_init(struct iface *iface, const void *api_info) { return errno_set(EIDRM); port->port_id = port_id; - port->devargs = strndup(api->devargs, BR_PORT_DEVARGS_SIZE); + port->devargs = strndup(api->devargs, GR_PORT_DEVARGS_SIZE); if (port->devargs == NULL) goto fail; @@ -436,7 +436,7 @@ static int iface_port_get_eth_addr(const struct iface *iface, struct rte_ether_a static void port_to_api(void *info, const struct iface *iface) { const struct iface_info_port *port = (const struct iface_info_port *)iface->info; - struct br_iface_info_port *api = info; + struct gr_iface_info_port *api = info; memccpy(api->devargs, port->devargs, 0, sizeof(api->devargs)); memcpy(&api->mac, &port->mac, sizeof(api->mac)); @@ -447,7 +447,7 @@ static void port_to_api(void *info, const struct iface *iface) { } static struct iface_type iface_type_port = { - .id = BR_IFACE_TYPE_PORT, + .id = GR_IFACE_TYPE_PORT, .name = "port", .info_size = sizeof(struct iface_info_port), .init = iface_port_init, diff --git a/modules/infra/control/vlan.c b/modules/infra/control/vlan.c index 4064a96c..5aaa38c1 100644 --- a/modules/infra/control/vlan.c +++ b/modules/infra/control/vlan.c @@ -1,13 +1,13 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include "br_vlan.h" +#include "gr_vlan.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include @@ -38,7 +38,7 @@ static int get_parent_port_id(uint16_t parent_id, uint16_t *port_id) { if (parent == NULL) return -1; - if (parent->type_id != BR_IFACE_TYPE_PORT) + if (parent->type_id != GR_IFACE_TYPE_PORT) return errno_set(EMEDIUMTYPE); port = (const struct iface_info_port *)parent->info; @@ -70,7 +70,7 @@ static int iface_vlan_reconfig( const void *api_info ) { struct iface_info_vlan *cur = (struct iface_info_vlan *)iface->info; - const struct br_iface_info_vlan *next = api_info; + const struct gr_iface_info_vlan *next = api_info; struct vlan_key cur_key = {cur->parent_id, cur->vlan_id}; struct vlan_key next_key = {next->parent_id, next->vlan_id}; uint16_t cur_port_id, next_port_id; @@ -81,7 +81,7 @@ static int iface_vlan_reconfig( if (get_parent_port_id(next->parent_id, &next_port_id) < 0) return -1; - if (set_attrs & (BR_VLAN_SET_PARENT | BR_VLAN_SET_VLAN)) { + if (set_attrs & (GR_VLAN_SET_PARENT | GR_VLAN_SET_VLAN)) { if (rte_hash_lookup(vlan_hash, &next_key) >= 0) return errno_set(EADDRINUSE); @@ -104,7 +104,7 @@ static int iface_vlan_reconfig( return errno_log(-ret, "rte_hash_add_key_data"); } - if (set_attrs & BR_VLAN_SET_MAC) { + if (set_attrs & GR_VLAN_SET_MAC) { struct rte_ether_addr next_mac; memcpy(&next_mac, &next->mac, sizeof(next_mac)); @@ -124,11 +124,11 @@ static int iface_vlan_reconfig( rte_ether_addr_copy(&next_mac, &cur->mac); } - if (set_attrs & BR_IFACE_SET_FLAGS) + if (set_attrs & GR_IFACE_SET_FLAGS) iface->flags = flags; - if (set_attrs & BR_IFACE_SET_MTU) + if (set_attrs & GR_IFACE_SET_MTU) iface->mtu = mtu; - if (set_attrs & BR_IFACE_SET_VRF) + if (set_attrs & GR_IFACE_SET_VRF) iface->vrf_id = vrf_id; return 0; @@ -181,7 +181,7 @@ static int iface_vlan_get_eth_addr(const struct iface *iface, struct rte_ether_a static void vlan_to_api(void *info, const struct iface *iface) { const struct iface_info_vlan *vlan = (const struct iface_info_vlan *)iface->info; - struct br_iface_info_vlan *api = info; + struct gr_iface_info_vlan *api = info; api->parent_id = vlan->parent_id; api->vlan_id = vlan->vlan_id; @@ -189,7 +189,7 @@ static void vlan_to_api(void *info, const struct iface *iface) { } static struct iface_type iface_type_vlan = { - .id = BR_IFACE_TYPE_VLAN, + .id = GR_IFACE_TYPE_VLAN, .name = "vlan", .info_size = sizeof(struct iface_info_vlan), .init = iface_vlan_init, @@ -218,7 +218,7 @@ static void vlan_fini(struct event_base *) { vlan_hash = NULL; } -static struct br_module vlan_module = { +static struct gr_module vlan_module = { .name = "vlan", .init = vlan_init, .fini = vlan_fini, @@ -226,6 +226,6 @@ static struct br_module vlan_module = { }; RTE_INIT(vlan_constructor) { - br_register_module(&vlan_module); + gr_register_module(&vlan_module); iface_type_register(&iface_type_vlan); } diff --git a/modules/infra/control/worker.c b/modules/infra/control/worker.c index 1ddae6a6..8f537b95 100644 --- a/modules/infra/control/worker.c +++ b/modules/infra/control/worker.c @@ -4,14 +4,14 @@ #include "graph_priv.h" #include "worker_priv.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -42,7 +42,7 @@ int worker_create(unsigned cpu_id) { worker->cpu_id = cpu_id; worker->lcore_id = LCORE_ID_ANY; - if (!!(ret = pthread_create(&worker->thread, NULL, br_datapath_loop, worker))) { + if (!!(ret = pthread_create(&worker->thread, NULL, gr_datapath_loop, worker))) { pthread_cancel(worker->thread); rte_free(worker); return errno_log(-ret, "pthread_create"); @@ -241,13 +241,13 @@ int worker_rxq_assign(uint16_t port_id, uint16_t rxq_id, uint16_t cpu_id) { if (reconfig) { // number of workers changed, adjust number of tx queues - struct br_iface_info_port p = {0}; + struct gr_iface_info_port p = {0}; struct iface *iface = NULL; - while ((iface = iface_next(BR_IFACE_TYPE_PORT, iface)) != NULL) { + while ((iface = iface_next(GR_IFACE_TYPE_PORT, iface)) != NULL) { ret = iface_port_reconfig( iface, - BR_PORT_SET_N_TXQS, + GR_PORT_SET_N_TXQS, iface->flags, iface->mtu, iface->vrf_id, @@ -290,7 +290,7 @@ static void worker_fini(struct event_base *) { STAILQ_INIT(&workers); } -static struct br_module worker_module = { +static struct gr_module worker_module = { .name = "worker", .init = worker_init, .fini = worker_fini, @@ -298,5 +298,5 @@ static struct br_module worker_module = { }; RTE_INIT(control_infra_init) { - br_register_module(&worker_module); + gr_register_module(&worker_module); } diff --git a/modules/infra/control/worker_priv.h b/modules/infra/control/worker_priv.h index d46d5c06..4a142ccf 100644 --- a/modules/infra/control/worker_priv.h +++ b/modules/infra/control/worker_priv.h @@ -1,10 +1,10 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#ifndef _BR_CONTROL_WORKER -#define _BR_CONTROL_WORKER +#ifndef _GR_CONTROL_WORKER +#define _GR_CONTROL_WORKER -#include "br_worker.h" +#include "gr_worker.h" int port_unplug(uint16_t port_id); int port_plug(uint16_t port_id); diff --git a/modules/infra/control/worker_test.c b/modules/infra/control/worker_test.c index 2f31ed98..f8b2276e 100644 --- a/modules/infra/control/worker_test.c +++ b/modules/infra/control/worker_test.c @@ -3,14 +3,14 @@ #include "worker_priv.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -22,9 +22,9 @@ static struct worker w3 = {.cpu_id = 3, .started = true}; static struct rte_eth_dev_info dev_info = {.nb_rx_queues = 2}; // mocked types/functions -int br_rte_log_type; -void br_register_api_handler(struct br_api_handler *) { } -void br_register_module(struct br_module *) { } +int gr_rte_log_type; +void gr_register_api_handler(struct gr_api_handler *) { } +void gr_register_module(struct gr_module *) { } void iface_type_register(struct iface_type *) { } struct iface *iface_next(uint16_t type_id, const struct iface *prev) { @@ -41,7 +41,7 @@ struct iface *iface_next(uint16_t type_id, const struct iface *prev) { mock_func(int, worker_graph_reload_all(void)); mock_func(void, worker_graph_free(struct worker *)); -mock_func(void *, br_datapath_loop(void *)); +mock_func(void *, gr_datapath_loop(void *)); mock_func(void, __wrap_rte_free(void *)); mock_func(int, __wrap_rte_eth_dev_stop(uint16_t)); mock_func( diff --git a/modules/infra/datapath/br_eth_input.h b/modules/infra/datapath/br_eth_input.h deleted file mode 100644 index 8ff2d3ac..00000000 --- a/modules/infra/datapath/br_eth_input.h +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// Copyright (c) 2024 Robin Jarry - -#ifndef _BR_INFRA_ETH_INPUT -#define _BR_INFRA_ETH_INPUT - -#include "br_mbuf.h" - -#include - -#include -#include - -BR_MBUF_PRIV_DATA_TYPE(eth_input_mbuf_data, { const struct iface *iface; }); - -void br_eth_input_add_type(rte_be16_t eth_type, rte_edge_t edge); - -#endif diff --git a/modules/infra/datapath/drop.c b/modules/infra/datapath/drop.c index f16d08cc..1b16fe9b 100644 --- a/modules/infra/datapath/drop.c +++ b/modules/infra/datapath/drop.c @@ -1,8 +1,8 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include -#include +#include +#include #include #include diff --git a/modules/infra/datapath/eth_input.c b/modules/infra/datapath/eth_input.c index 0f4192b0..84574adf 100644 --- a/modules/infra/datapath/eth_input.c +++ b/modules/infra/datapath/eth_input.c @@ -1,11 +1,11 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include "br_eth_input.h" +#include "gr_eth_input.h" -#include -#include -#include +#include +#include +#include #include #include @@ -21,7 +21,7 @@ enum { static rte_edge_t l2l3_edges[1 << 16] = {UNKNOWN_ETHER_TYPE}; -void br_eth_input_add_type(rte_be16_t eth_type, rte_edge_t edge) { +void gr_eth_input_add_type(rte_be16_t eth_type, rte_edge_t edge) { l2l3_edges[eth_type] = edge; LOG(DEBUG, "eth_input: type=0x%04x -> edge %u", rte_be_to_cpu_16(eth_type), edge); } @@ -88,15 +88,15 @@ static struct rte_node_register node = { .next_nodes = { [UNKNOWN_ETHER_TYPE] = "eth_input_unknown_type", [UNKNOWN_VLAN] = "eth_input_unknown_vlan", - // other edges are updated dynamically with br_eth_input_add_type + // other edges are updated dynamically with gr_eth_input_add_type }, }; -static struct br_node_info info = { +static struct gr_node_info info = { .node = &node, }; -BR_NODE_REGISTER(info); +GR_NODE_REGISTER(info); -BR_DROP_REGISTER(eth_input_unknown_type); -BR_DROP_REGISTER(eth_input_unknown_vlan); +GR_DROP_REGISTER(eth_input_unknown_type); +GR_DROP_REGISTER(eth_input_unknown_vlan); diff --git a/modules/infra/datapath/eth_output.c b/modules/infra/datapath/eth_output.c index 7443e661..645a2859 100644 --- a/modules/infra/datapath/eth_output.c +++ b/modules/infra/datapath/eth_output.c @@ -1,13 +1,13 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include "br_datapath.h" -#include "br_eth_output.h" +#include "gr_datapath.h" +#include "gr_eth_output.h" -#include -#include -#include -#include +#include +#include +#include +#include #include #include @@ -35,7 +35,7 @@ eth_output_process(struct rte_graph *graph, struct rte_node *node, void **objs, priv = eth_output_mbuf_data(mbuf); switch (priv->iface->type_id) { - case BR_IFACE_TYPE_VLAN: + case GR_IFACE_TYPE_VLAN: sub = (struct iface_info_vlan *)priv->iface->info; vlan = (struct rte_vlan_hdr *)rte_pktmbuf_prepend(mbuf, sizeof(*vlan)); vlan->vlan_tci = rte_cpu_to_be_16(sub->vlan_id); @@ -45,7 +45,7 @@ eth_output_process(struct rte_graph *graph, struct rte_node *node, void **objs, src_mac = &sub->mac; port = (const struct iface_info_port *)priv->iface->info; break; - case BR_IFACE_TYPE_PORT: + case GR_IFACE_TYPE_PORT: port = (const struct iface_info_port *)priv->iface->info; src_mac = &port->mac; break; @@ -78,10 +78,10 @@ static struct rte_node_register node= { }, }; -static struct br_node_info info = { +static struct gr_node_info info = { .node = &node, }; -BR_NODE_REGISTER(info); +GR_NODE_REGISTER(info); -BR_DROP_REGISTER(eth_output_inval); +GR_DROP_REGISTER(eth_output_inval); diff --git a/modules/infra/datapath/br_datapath.h b/modules/infra/datapath/gr_datapath.h similarity index 96% rename from modules/infra/datapath/br_datapath.h rename to modules/infra/datapath/gr_datapath.h index 0b5ca93b..147bf1aa 100644 --- a/modules/infra/datapath/br_datapath.h +++ b/modules/infra/datapath/gr_datapath.h @@ -1,11 +1,11 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#ifndef _BR_INFRA_DATAPATH -#define _BR_INFRA_DATAPATH +#ifndef _GR_INFRA_DATAPATH +#define _GR_INFRA_DATAPATH -#include -#include +#include +#include #include #include @@ -16,7 +16,7 @@ #include #include -void *br_datapath_loop(void *priv); +void *gr_datapath_loop(void *priv); #ifdef TRACE_PACKETS static inline void trace_packet(const char *node, const char *iface, const struct rte_mbuf *m) { diff --git a/modules/infra/datapath/gr_eth_input.h b/modules/infra/datapath/gr_eth_input.h new file mode 100644 index 00000000..4641dae9 --- /dev/null +++ b/modules/infra/datapath/gr_eth_input.h @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: BSD-3-Clause +// Copyright (c) 2024 Robin Jarry + +#ifndef _GR_INFRA_ETH_INPUT +#define _GR_INFRA_ETH_INPUT + +#include "gr_mbuf.h" + +#include + +#include +#include + +GR_MBUF_PRIV_DATA_TYPE(eth_input_mbuf_data, { const struct iface *iface; }); + +void gr_eth_input_add_type(rte_be16_t eth_type, rte_edge_t edge); + +#endif diff --git a/modules/infra/datapath/br_eth_output.h b/modules/infra/datapath/gr_eth_output.h similarity index 64% rename from modules/infra/datapath/br_eth_output.h rename to modules/infra/datapath/gr_eth_output.h index daf2d077..88e4e018 100644 --- a/modules/infra/datapath/br_eth_output.h +++ b/modules/infra/datapath/gr_eth_output.h @@ -1,12 +1,12 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#ifndef _BR_INFRA_ETH_OUTPUT -#define _BR_INFRA_ETH_OUTPUT +#ifndef _GR_INFRA_ETH_OUTPUT +#define _GR_INFRA_ETH_OUTPUT -#include "br_mbuf.h" +#include "gr_mbuf.h" -#include +#include #include #include @@ -14,7 +14,7 @@ #include -BR_MBUF_PRIV_DATA_TYPE(eth_output_mbuf_data, { +GR_MBUF_PRIV_DATA_TYPE(eth_output_mbuf_data, { const struct iface *iface; struct rte_ether_addr dst; rte_be16_t ether_type; diff --git a/modules/infra/datapath/br_mbuf.h b/modules/infra/datapath/gr_mbuf.h similarity index 53% rename from modules/infra/datapath/br_mbuf.h rename to modules/infra/datapath/gr_mbuf.h index 0ed08902..f35befa8 100644 --- a/modules/infra/datapath/br_mbuf.h +++ b/modules/infra/datapath/gr_mbuf.h @@ -1,10 +1,10 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#ifndef _BR_MBUF -#define _BR_MBUF +#ifndef _GR_MBUF +#define _GR_MBUF -#include +#include #include #include @@ -13,19 +13,19 @@ #include #include -#define BR_MBUF_PRIV_MAX_SIZE 32 +#define GR_MBUF_PRIV_MAX_SIZE 32 -static_assert(BR_MBUF_PRIV_MAX_SIZE <= MEMBER_SIZE(struct rte_mbuf, dynfield1)); +static_assert(GR_MBUF_PRIV_MAX_SIZE <= MEMBER_SIZE(struct rte_mbuf, dynfield1)); -extern int br_mdyn_offset; +extern int gr_mdyn_offset; -#define BR_MBUF_PRIV_DATA_TYPE(type_name, fields) \ +#define GR_MBUF_PRIV_DATA_TYPE(type_name, fields) \ struct type_name fields; \ static inline struct type_name *type_name(struct rte_mbuf *m) { \ - static_assert(sizeof(struct type_name) <= BR_MBUF_PRIV_MAX_SIZE); \ - return RTE_MBUF_DYNFIELD(m, br_mdyn_offset, struct type_name *); \ + static_assert(sizeof(struct type_name) <= GR_MBUF_PRIV_MAX_SIZE); \ + return RTE_MBUF_DYNFIELD(m, gr_mdyn_offset, struct type_name *); \ } -BR_MBUF_PRIV_DATA_TYPE(queue_mbuf_data, { struct rte_mbuf *next; }); +GR_MBUF_PRIV_DATA_TYPE(queue_mbuf_data, { struct rte_mbuf *next; }); #endif diff --git a/modules/infra/datapath/br_rx.h b/modules/infra/datapath/gr_rx.h similarity index 86% rename from modules/infra/datapath/br_rx.h rename to modules/infra/datapath/gr_rx.h index ec2680a9..e47530d4 100644 --- a/modules/infra/datapath/br_rx.h +++ b/modules/infra/datapath/gr_rx.h @@ -1,8 +1,8 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#ifndef _BR_INFRA_RX -#define _BR_INFRA_RX +#ifndef _GR_INFRA_RX +#define _GR_INFRA_RX #include diff --git a/modules/infra/datapath/br_tx.h b/modules/infra/datapath/gr_tx.h similarity index 82% rename from modules/infra/datapath/br_tx.h rename to modules/infra/datapath/gr_tx.h index 86f6b3c3..b34bb3aa 100644 --- a/modules/infra/datapath/br_tx.h +++ b/modules/infra/datapath/gr_tx.h @@ -1,8 +1,8 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#ifndef _BR_INFRA_TX -#define _BR_INFRA_TX +#ifndef _GR_INFRA_TX +#define _GR_INFRA_TX #include diff --git a/modules/infra/datapath/main_loop.c b/modules/infra/datapath/main_loop.c index 2d1d2f76..42af9253 100644 --- a/modules/infra/datapath/main_loop.c +++ b/modules/infra/datapath/main_loop.c @@ -1,11 +1,11 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include @@ -114,7 +114,7 @@ static int stats_reload(const struct rte_graph *graph, struct stats_context *ctx // The default timer resolution is around 50us, make it more precise #define SLEEP_RESOLUTION_NS 1000 -void *br_datapath_loop(void *priv) { +void *gr_datapath_loop(void *priv) { struct stats_context ctx = {.last_count = 0}; uint64_t timestamp, timestamp_tmp, cycles; uint32_t sleep, max_sleep_us; @@ -143,12 +143,12 @@ void *br_datapath_loop(void *priv) { } w->lcore_id = rte_lcore_id(); - snprintf(name, 15, "br:loop-c%d", w->cpu_id); + snprintf(name, 15, "gr:loop-c%d", w->cpu_id); if (pthread_setname_np(pthread_self(), name)) { log(ERR, "pthread_setname_np: %s", rte_strerror(rte_errno)); return NULL; } - if (!br_args()->poll_mode) { + if (!gr_args()->poll_mode) { if (prctl(PR_SET_TIMERSLACK, SLEEP_RESOLUTION_NS) < 0) { log(ERR, "prctl(PR_SET_TIMERSLACK): %s", strerror(errno)); return NULL; @@ -180,7 +180,7 @@ void *br_datapath_loop(void *priv) { goto shutdown; atomic_store(&w->stats, ctx.w_stats); - br_modules_dp_init(); + gr_modules_dp_init(); log(INFO, "reconfigured max_sleep=%uus", max_sleep_us); @@ -192,7 +192,7 @@ void *br_datapath_loop(void *priv) { if (++loop == 32) { if (atomic_load(&w->shutdown) || atomic_load(&w->next_config) != cur) { - br_modules_dp_fini(); + gr_modules_dp_fini(); goto reconfig; } diff --git a/modules/infra/datapath/mbuf.c b/modules/infra/datapath/mbuf.c index 3eb09197..24f7dec8 100644 --- a/modules/infra/datapath/mbuf.c +++ b/modules/infra/datapath/mbuf.c @@ -1,10 +1,10 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include "br_mbuf.h" +#include "gr_mbuf.h" -#include -#include +#include +#include #include #include @@ -12,24 +12,24 @@ #include static const struct rte_mbuf_dynfield dyn_desc = { - .name = "br_priv", - .size = BR_MBUF_PRIV_MAX_SIZE, + .name = "gr_priv", + .size = GR_MBUF_PRIV_MAX_SIZE, .align = alignof(void *), }; -int br_mdyn_offset = -1; +int gr_mdyn_offset = -1; static void mbuf_init(struct event_base *) { - br_mdyn_offset = rte_mbuf_dynfield_register(&dyn_desc); - if (br_mdyn_offset < 0) + gr_mdyn_offset = rte_mbuf_dynfield_register(&dyn_desc); + if (gr_mdyn_offset < 0) ABORT("rte_mbuf_dynfield_register(): %s", rte_strerror(rte_errno)); } -static struct br_module mbuf_module = { +static struct gr_module mbuf_module = { .name = "infra mbuf", .init = mbuf_init, }; RTE_INIT(init) { - br_register_module(&mbuf_module); + gr_register_module(&mbuf_module); } diff --git a/modules/infra/datapath/rx.c b/modules/infra/datapath/rx.c index 7d8cddde..3c0eed3e 100644 --- a/modules/infra/datapath/rx.c +++ b/modules/infra/datapath/rx.c @@ -1,14 +1,14 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#include "br_datapath.h" -#include "br_eth_input.h" -#include "br_rx.h" +#include "gr_datapath.h" +#include "gr_eth_input.h" +#include "gr_rx.h" -#include -#include -#include -#include +#include +#include +#include +#include #include #include @@ -70,7 +70,7 @@ static int rx_init(const struct rte_graph *graph, struct rte_node *node) { (void)graph; - if ((data = br_node_data_get(graph->name, node->name)) == NULL) + if ((data = gr_node_data_get(graph->name, node->name)) == NULL) return -1; ctx = rte_zmalloc( @@ -108,10 +108,10 @@ static struct rte_node_register node = { }, }; -static struct br_node_info info = { +static struct gr_node_info info = { .node = &node, }; -BR_NODE_REGISTER(info); +GR_NODE_REGISTER(info); -BR_DROP_REGISTER(port_rx_no_iface); +GR_DROP_REGISTER(port_rx_no_iface); diff --git a/modules/infra/datapath/tx.c b/modules/infra/datapath/tx.c index a7f59633..90df7116 100644 --- a/modules/infra/datapath/tx.c +++ b/modules/infra/datapath/tx.c @@ -1,11 +1,11 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2023 Robin Jarry -#include "br_tx.h" +#include "gr_tx.h" -#include -#include -#include +#include +#include +#include #include #include @@ -80,7 +80,7 @@ static int tx_init(const struct rte_graph *graph, struct rte_node *node) { (void)graph; - if ((data = br_node_data_get(graph->name, node->name)) == NULL) + if ((data = gr_node_data_get(graph->name, node->name)) == NULL) return -1; ctx = rte_malloc(__func__, sizeof(*ctx), RTE_CACHE_LINE_SIZE); @@ -112,10 +112,10 @@ static struct rte_node_register node = { }, }; -static struct br_node_info info = { +static struct gr_node_info info = { .node = &node, }; -BR_NODE_REGISTER(info); +GR_NODE_REGISTER(info); -BR_DROP_REGISTER(port_tx_error); +GR_DROP_REGISTER(port_tx_error); diff --git a/modules/ip/api/br_ip4.h b/modules/ip/api/br_ip4.h deleted file mode 100644 index d93cac14..00000000 --- a/modules/ip/api/br_ip4.h +++ /dev/null @@ -1,177 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// Copyright (c) 2024 Robin Jarry - -#ifndef _BR_IP4_MSG -#define _BR_IP4_MSG - -#include -#include -#include - -#include - -struct br_ip4_ifaddr { - uint16_t iface_id; - struct ip4_net addr; -}; - -#define BR_IP4_NH_F_PENDING BR_BIT16(0) // ARP probe sent -#define BR_IP4_NH_F_REACHABLE BR_BIT16(1) // ARP reply received -#define BR_IP4_NH_F_STALE BR_BIT16(2) // Reachable lifetime expired, need ARP refresh -#define BR_IP4_NH_F_FAILED BR_BIT16(3) // All ARP probes sent without reply -#define BR_IP4_NH_F_STATIC BR_BIT16(4) // Configured by user -#define BR_IP4_NH_F_LOCAL BR_BIT16(5) // Local address -#define BR_IP4_NH_F_GATEWAY BR_BIT16(6) // Gateway route -#define BR_IP4_NH_F_LINK BR_BIT16(7) // Connected link route -typedef uint16_t br_ip4_nh_flags_t; - -static inline const char *br_ip4_nh_f_name(const br_ip4_nh_flags_t flag) { - switch (flag) { - case BR_IP4_NH_F_PENDING: - return "pending"; - case BR_IP4_NH_F_REACHABLE: - return "reachable"; - case BR_IP4_NH_F_STALE: - return "stale"; - case BR_IP4_NH_F_FAILED: - return "failed"; - case BR_IP4_NH_F_STATIC: - return "static"; - case BR_IP4_NH_F_LOCAL: - return "local"; - case BR_IP4_NH_F_GATEWAY: - return "gateway"; - case BR_IP4_NH_F_LINK: - return "link"; - } - return ""; -} - -#define BR_VRF_ID_ALL UINT16_MAX - -struct br_ip4_nh { - ip4_addr_t host; - struct eth_addr mac; - uint16_t vrf_id; - uint16_t iface_id; - br_ip4_nh_flags_t flags; - uint16_t age; // +#include +#include + +#include + +struct gr_ip4_ifaddr { + uint16_t iface_id; + struct ip4_net addr; +}; + +#define GR_IP4_NH_F_PENDING GR_BIT16(0) // ARP probe sent +#define GR_IP4_NH_F_REACHABLE GR_BIT16(1) // ARP reply received +#define GR_IP4_NH_F_STALE GR_BIT16(2) // Reachable lifetime expired, need ARP refresh +#define GR_IP4_NH_F_FAILED GR_BIT16(3) // All ARP probes sent without reply +#define GR_IP4_NH_F_STATIC GR_BIT16(4) // Configured by user +#define GR_IP4_NH_F_LOCAL GR_BIT16(5) // Local address +#define GR_IP4_NH_F_GATEWAY GR_BIT16(6) // Gateway route +#define GR_IP4_NH_F_LINK GR_BIT16(7) // Connected link route +typedef uint16_t gr_ip4_nh_flags_t; + +static inline const char *gr_ip4_nh_f_name(const gr_ip4_nh_flags_t flag) { + switch (flag) { + case GR_IP4_NH_F_PENDING: + return "pending"; + case GR_IP4_NH_F_REACHABLE: + return "reachable"; + case GR_IP4_NH_F_STALE: + return "stale"; + case GR_IP4_NH_F_FAILED: + return "failed"; + case GR_IP4_NH_F_STATIC: + return "static"; + case GR_IP4_NH_F_LOCAL: + return "local"; + case GR_IP4_NH_F_GATEWAY: + return "gateway"; + case GR_IP4_NH_F_LINK: + return "link"; + } + return ""; +} + +#define GR_VRF_ID_ALL UINT16_MAX + +struct gr_ip4_nh { + ip4_addr_t host; + struct eth_addr mac; + uint16_t vrf_id; + uint16_t iface_id; + gr_ip4_nh_flags_t flags; + uint16_t age; // -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include #include -static cmd_status_t addr_add(const struct br_api_client *c, const struct ec_pnode *p) { - struct br_ip4_addr_add_req req = {.exist_ok = true}; - struct br_iface iface; +static cmd_status_t addr_add(const struct gr_api_client *c, const struct ec_pnode *p) { + struct gr_ip4_addr_add_req req = {.exist_ok = true}; + struct gr_iface iface; - if (br_ip4_net_parse(arg_str(p, "IP_NET"), &req.addr.addr, false) < 0) + if (gr_ip4_net_parse(arg_str(p, "IP_NET"), &req.addr.addr, false) < 0) return CMD_ERROR; if (iface_from_name(c, arg_str(p, "IFACE"), &iface) < 0) return CMD_ERROR; req.addr.iface_id = iface.id; - if (br_api_client_send_recv(c, BR_IP4_ADDR_ADD, sizeof(req), &req, NULL) < 0) + if (gr_api_client_send_recv(c, GR_IP4_ADDR_ADD, sizeof(req), &req, NULL) < 0) return CMD_ERROR; return CMD_SUCCESS; } -static cmd_status_t addr_del(const struct br_api_client *c, const struct ec_pnode *p) { - struct br_ip4_addr_del_req req = {.missing_ok = true}; - struct br_iface iface; +static cmd_status_t addr_del(const struct gr_api_client *c, const struct ec_pnode *p) { + struct gr_ip4_addr_del_req req = {.missing_ok = true}; + struct gr_iface iface; - if (br_ip4_net_parse(arg_str(p, "IP_NET"), &req.addr.addr, false) < 0) + if (gr_ip4_net_parse(arg_str(p, "IP_NET"), &req.addr.addr, false) < 0) return CMD_ERROR; if (iface_from_name(c, arg_str(p, "IFACE"), &iface) < 0) return CMD_ERROR; req.addr.iface_id = iface.id; - if (br_api_client_send_recv(c, BR_IP4_ADDR_DEL, sizeof(req), &req, NULL) < 0) + if (gr_api_client_send_recv(c, GR_IP4_ADDR_DEL, sizeof(req), &req, NULL) < 0) return CMD_ERROR; return CMD_SUCCESS; } -static cmd_status_t addr_list(const struct br_api_client *c, const struct ec_pnode *p) { +static cmd_status_t addr_list(const struct gr_api_client *c, const struct ec_pnode *p) { struct libscols_table *table = scols_new_table(); - const struct br_ip4_addr_list_resp *resp; - struct br_ip4_addr_list_req req = {0}; - struct br_iface iface; + const struct gr_ip4_addr_list_resp *resp; + struct gr_ip4_addr_list_req req = {0}; + struct gr_iface iface; void *resp_ptr = NULL; char buf[BUFSIZ]; @@ -66,7 +66,7 @@ static cmd_status_t addr_list(const struct br_api_client *c, const struct ec_pno return CMD_ERROR; } - if (br_api_client_send_recv(c, BR_IP4_ADDR_LIST, sizeof(req), &req, &resp_ptr) < 0) { + if (gr_api_client_send_recv(c, GR_IP4_ADDR_LIST, sizeof(req), &req, &resp_ptr) < 0) { scols_unref_table(table); return CMD_ERROR; } @@ -79,8 +79,8 @@ static cmd_status_t addr_list(const struct br_api_client *c, const struct ec_pno for (size_t i = 0; i < resp->n_addrs; i++) { struct libscols_line *line = scols_table_new_line(table, NULL); - const struct br_ip4_ifaddr *addr = &resp->addrs[i]; - br_ip4_net_format(&addr->addr, buf, sizeof(buf)); + const struct gr_ip4_ifaddr *addr = &resp->addrs[i]; + gr_ip4_net_format(&addr->addr, buf, sizeof(buf)); if (iface_from_id(c, addr->iface_id, &iface) == 0) scols_line_sprintf(line, 0, "%s", iface.name); else @@ -131,7 +131,7 @@ static int ctx_init(struct ec_node *root) { return 0; } -static struct br_cli_context ctx = { +static struct gr_cli_context ctx = { .name = "ipv4 address", .init = ctx_init, }; diff --git a/modules/ip/cli/ip.h b/modules/ip/cli/ip.h index 7ea648fe..5868a530 100644 --- a/modules/ip/cli/ip.h +++ b/modules/ip/cli/ip.h @@ -1,10 +1,10 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#ifndef _BR_CLI_IP -#define _BR_CLI_IP +#ifndef _GR_CLI_IP +#define _GR_CLI_IP -#include +#include #define IP_ADD_CTX(root) CLI_CONTEXT(root, CTX_ADD, CTX_ARG("ip", "Create IPv4 stack elements.")) #define IP_DEL_CTX(root) CLI_CONTEXT(root, CTX_DEL, CTX_ARG("ip", "Delete IPv4 stack elements.")) diff --git a/modules/ip/cli/nexthop.c b/modules/ip/cli/nexthop.c index 4650a5d1..949b0479 100644 --- a/modules/ip/cli/nexthop.c +++ b/modules/ip/cli/nexthop.c @@ -3,12 +3,12 @@ #include "ip.h" -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include @@ -16,28 +16,28 @@ #include #include -static cmd_status_t nh4_add(const struct br_api_client *c, const struct ec_pnode *p) { - struct br_ip4_nh_add_req req = {0}; - struct br_iface iface; +static cmd_status_t nh4_add(const struct gr_api_client *c, const struct ec_pnode *p) { + struct gr_ip4_nh_add_req req = {0}; + struct gr_iface iface; if (inet_pton(AF_INET, arg_str(p, "IP"), &req.nh.host) != 1) { errno = EINVAL; return CMD_ERROR; } - if (br_eth_addr_parse(arg_str(p, "MAC"), &req.nh.mac) < 0) + if (gr_eth_addr_parse(arg_str(p, "MAC"), &req.nh.mac) < 0) return CMD_ERROR; if (iface_from_name(c, arg_str(p, "IFACE"), &iface) < 0) return CMD_ERROR; req.nh.iface_id = iface.id; - if (br_api_client_send_recv(c, BR_IP4_NH_ADD, sizeof(req), &req, NULL) < 0) + if (gr_api_client_send_recv(c, GR_IP4_NH_ADD, sizeof(req), &req, NULL) < 0) return CMD_ERROR; return CMD_SUCCESS; } -static cmd_status_t nh4_del(const struct br_api_client *c, const struct ec_pnode *p) { - struct br_ip4_nh_del_req req = {.missing_ok = true}; +static cmd_status_t nh4_del(const struct gr_api_client *c, const struct ec_pnode *p) { + struct gr_ip4_nh_del_req req = {.missing_ok = true}; if (inet_pton(AF_INET, arg_str(p, "IP"), &req.host) != 1) { errno = EINVAL; @@ -46,18 +46,18 @@ static cmd_status_t nh4_del(const struct br_api_client *c, const struct ec_pnode if (arg_u16(p, "VRF", &req.vrf_id) < 0 && errno != ENOENT) return CMD_ERROR; - if (br_api_client_send_recv(c, BR_IP4_NH_DEL, sizeof(req), &req, NULL) < 0) + if (gr_api_client_send_recv(c, GR_IP4_NH_DEL, sizeof(req), &req, NULL) < 0) return CMD_ERROR; return CMD_SUCCESS; } -static cmd_status_t nh4_list(const struct br_api_client *c, const struct ec_pnode *p) { - struct br_ip4_nh_list_req req = {.vrf_id = UINT16_MAX}; +static cmd_status_t nh4_list(const struct gr_api_client *c, const struct ec_pnode *p) { + struct gr_ip4_nh_list_req req = {.vrf_id = UINT16_MAX}; struct libscols_table *table = scols_new_table(); - const struct br_ip4_nh_list_resp *resp; + const struct gr_ip4_nh_list_resp *resp; char ip[BUFSIZ], state[BUFSIZ]; - struct br_iface iface; + struct gr_iface iface; void *resp_ptr = NULL; ssize_t n; @@ -69,7 +69,7 @@ static cmd_status_t nh4_list(const struct br_api_client *c, const struct ec_pnod scols_unref_table(table); return CMD_ERROR; } - if (br_api_client_send_recv(c, BR_IP4_NH_LIST, sizeof(req), &req, &resp_ptr) < 0) { + if (gr_api_client_send_recv(c, GR_IP4_NH_LIST, sizeof(req), &req, &resp_ptr) < 0) { scols_unref_table(table); return CMD_ERROR; } @@ -87,15 +87,15 @@ static cmd_status_t nh4_list(const struct br_api_client *c, const struct ec_pnod for (size_t i = 0; i < resp->n_nhs; i++) { struct libscols_line *line = scols_table_new_line(table, NULL); - const struct br_ip4_nh *nh = &resp->nhs[i]; + const struct gr_ip4_nh *nh = &resp->nhs[i]; n = 0; state[0] = '\0'; for (uint8_t i = 0; i < 16; i++) { - br_ip4_nh_flags_t f = 1 << i; + gr_ip4_nh_flags_t f = 1 << i; if (f & nh->flags) { n += snprintf( - state + n, sizeof(state) - n, "%s ", br_ip4_nh_f_name(f) + state + n, sizeof(state) - n, "%s ", gr_ip4_nh_f_name(f) ); } } @@ -106,7 +106,7 @@ static cmd_status_t nh4_list(const struct br_api_client *c, const struct ec_pnod scols_line_sprintf(line, 0, "%u", nh->vrf_id); scols_line_sprintf(line, 1, "%s", ip); - if (nh->flags & BR_IP4_NH_F_REACHABLE) { + if (nh->flags & GR_IP4_NH_F_REACHABLE) { scols_line_sprintf(line, 2, ETH_ADDR_FMT, ETH_BYTES_SPLIT(nh->mac.bytes)); if (iface_from_id(c, nh->iface_id, &iface) == 0) scols_line_sprintf(line, 3, "%s", iface.name); @@ -167,7 +167,7 @@ static int ctx_init(struct ec_node *root) { return 0; } -static struct br_cli_context ctx = { +static struct gr_cli_context ctx = { .name = "ipv4 nexthop", .init = ctx_init, }; diff --git a/modules/ip/cli/route.c b/modules/ip/cli/route.c index 65a42d91..f2b95925 100644 --- a/modules/ip/cli/route.c +++ b/modules/ip/cli/route.c @@ -3,22 +3,22 @@ #include "ip.h" -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include #include -static cmd_status_t route4_add(const struct br_api_client *c, const struct ec_pnode *p) { - struct br_ip4_route_add_req req = {.exist_ok = true}; +static cmd_status_t route4_add(const struct gr_api_client *c, const struct ec_pnode *p) { + struct gr_ip4_route_add_req req = {.exist_ok = true}; - if (br_ip4_net_parse(arg_str(p, "DEST"), &req.dest, true) < 0) + if (gr_ip4_net_parse(arg_str(p, "DEST"), &req.dest, true) < 0) return CMD_ERROR; if (inet_pton(AF_INET, arg_str(p, "NH"), &req.nh) != 1) { errno = EINVAL; @@ -27,30 +27,30 @@ static cmd_status_t route4_add(const struct br_api_client *c, const struct ec_pn if (arg_u16(p, "VRF", &req.vrf_id) < 0 && errno != ENOENT) return CMD_ERROR; - if (br_api_client_send_recv(c, BR_IP4_ROUTE_ADD, sizeof(req), &req, NULL) < 0) + if (gr_api_client_send_recv(c, GR_IP4_ROUTE_ADD, sizeof(req), &req, NULL) < 0) return CMD_ERROR; return CMD_SUCCESS; } -static cmd_status_t route4_del(const struct br_api_client *c, const struct ec_pnode *p) { - struct br_ip4_route_del_req req = {.missing_ok = true}; +static cmd_status_t route4_del(const struct gr_api_client *c, const struct ec_pnode *p) { + struct gr_ip4_route_del_req req = {.missing_ok = true}; - if (br_ip4_net_parse(arg_str(p, "DEST"), &req.dest, true) < 0) + if (gr_ip4_net_parse(arg_str(p, "DEST"), &req.dest, true) < 0) return CMD_ERROR; if (arg_u16(p, "VRF", &req.vrf_id) < 0 && errno != ENOENT) return CMD_ERROR; - if (br_api_client_send_recv(c, BR_IP4_ROUTE_DEL, sizeof(req), &req, NULL) < 0) + if (gr_api_client_send_recv(c, GR_IP4_ROUTE_DEL, sizeof(req), &req, NULL) < 0) return CMD_ERROR; return CMD_SUCCESS; } -static cmd_status_t route4_list(const struct br_api_client *c, const struct ec_pnode *p) { +static cmd_status_t route4_list(const struct gr_api_client *c, const struct ec_pnode *p) { struct libscols_table *table = scols_new_table(); - const struct br_ip4_route_list_resp *resp; - struct br_ip4_route_list_req req = {0}; + const struct gr_ip4_route_list_resp *resp; + struct gr_ip4_route_list_req req = {0}; char dest[BUFSIZ], nh[BUFSIZ]; void *resp_ptr = NULL; @@ -62,7 +62,7 @@ static cmd_status_t route4_list(const struct br_api_client *c, const struct ec_p if (arg_u16(p, "VRF", &req.vrf_id) < 0 && errno != ENOENT) return CMD_ERROR; - if (br_api_client_send_recv(c, BR_IP4_ROUTE_LIST, sizeof(req), &req, &resp_ptr) < 0) { + if (gr_api_client_send_recv(c, GR_IP4_ROUTE_LIST, sizeof(req), &req, &resp_ptr) < 0) { scols_unref_table(table); return CMD_ERROR; } @@ -74,8 +74,8 @@ static cmd_status_t route4_list(const struct br_api_client *c, const struct ec_p for (size_t i = 0; i < resp->n_routes; i++) { struct libscols_line *line = scols_table_new_line(table, NULL); - const struct br_ip4_route *route = &resp->routes[i]; - br_ip4_net_format(&route->dest, dest, sizeof(dest)); + const struct gr_ip4_route *route = &resp->routes[i]; + gr_ip4_net_format(&route->dest, dest, sizeof(dest)); inet_ntop(AF_INET, &route->nh, nh, sizeof(nh)); scols_line_set_data(line, 0, dest); scols_line_set_data(line, 1, nh); @@ -88,10 +88,10 @@ static cmd_status_t route4_list(const struct br_api_client *c, const struct ec_p return CMD_SUCCESS; } -static cmd_status_t route4_get(const struct br_api_client *c, const struct ec_pnode *p) { - const struct br_ip4_route_get_resp *resp; - struct br_ip4_route_get_req req = {0}; - struct br_iface iface; +static cmd_status_t route4_get(const struct gr_api_client *c, const struct ec_pnode *p) { + const struct gr_ip4_route_get_resp *resp; + struct gr_ip4_route_get_req req = {0}; + struct gr_iface iface; void *resp_ptr = NULL; char buf[BUFSIZ]; const char *dest = arg_str(p, "DEST"); @@ -108,7 +108,7 @@ static cmd_status_t route4_get(const struct br_api_client *c, const struct ec_pn if (arg_u16(p, "VRF", &req.vrf_id) < 0 && errno != ENOENT) return CMD_ERROR; - if (br_api_client_send_recv(c, BR_IP4_ROUTE_GET, sizeof(req), &req, &resp_ptr) < 0) + if (gr_api_client_send_recv(c, GR_IP4_ROUTE_GET, sizeof(req), &req, &resp_ptr) < 0) return CMD_ERROR; resp = resp_ptr; @@ -162,7 +162,7 @@ static int ctx_init(struct ec_node *root) { return 0; } -static struct br_cli_context ctx = { +static struct gr_cli_context ctx = { .name = "ipv4 route", .init = ctx_init, }; diff --git a/modules/ip/control/address.c b/modules/ip/control/address.c index be65adbf..c9e35011 100644 --- a/modules/ip/control/address.c +++ b/modules/ip/control/address.c @@ -1,14 +1,14 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -38,7 +38,7 @@ struct nexthop *ip4_addr_get(uint16_t iface_id) { } static struct api_out addr_add(const void *request, void **response) { - const struct br_ip4_addr_add_req *req = request; + const struct gr_ip4_addr_add_req *req = request; const struct iface *iface; struct nexthop *nh; uint32_t nh_idx; @@ -64,8 +64,8 @@ static struct api_out addr_add(const void *request, void **response) { nh->iface_id = req->addr.iface_id; nh->prefixlen = req->addr.addr.prefixlen; - nh->flags = BR_IP4_NH_F_LOCAL | BR_IP4_NH_F_LINK | BR_IP4_NH_F_REACHABLE - | BR_IP4_NH_F_STATIC; + nh->flags = GR_IP4_NH_F_LOCAL | GR_IP4_NH_F_LINK | GR_IP4_NH_F_REACHABLE + | GR_IP4_NH_F_STATIC; if (iface_get_eth_addr(iface->id, &nh->lladdr) < 0) if (errno != EOPNOTSUPP) @@ -81,7 +81,7 @@ static struct api_out addr_add(const void *request, void **response) { } static struct api_out addr_del(const void *request, void **response) { - const struct br_ip4_addr_del_req *req = request; + const struct gr_ip4_addr_del_req *req = request; const struct iface *iface; struct nexthop *nh; @@ -95,7 +95,7 @@ static struct api_out addr_del(const void *request, void **response) { if (nh->ip != req->addr.addr.ip || nh->prefixlen != req->addr.addr.prefixlen) return api_out(ENOENT, 0); - if ((nh->flags & (BR_IP4_NH_F_LOCAL | BR_IP4_NH_F_LINK)) || nh->ref_count > 1) + if ((nh->flags & (GR_IP4_NH_F_LOCAL | GR_IP4_NH_F_LINK)) || nh->ref_count > 1) return api_out(EBUSY, 0); iface = iface_from_id(req->addr.iface_id); @@ -109,9 +109,9 @@ static struct api_out addr_del(const void *request, void **response) { } static struct api_out addr_list(const void *request, void **response) { - const struct br_ip4_addr_list_req *req = request; - struct br_ip4_addr_list_resp *resp = NULL; - struct br_ip4_ifaddr *addr; + const struct gr_ip4_addr_list_req *req = request; + struct gr_ip4_addr_list_resp *resp = NULL; + struct gr_ip4_ifaddr *addr; const struct nexthop *nh; uint16_t iface_id, num; size_t len; @@ -122,7 +122,7 @@ static struct api_out addr_list(const void *request, void **response) { num++; } - len = sizeof(*resp) + num * sizeof(struct br_ip4_ifaddr); + len = sizeof(*resp) + num * sizeof(struct gr_ip4_ifaddr); if ((resp = calloc(len, 1)) == NULL) return api_out(ENOMEM, 0); @@ -153,30 +153,30 @@ static void addr_fini(struct event_base *) { addrs = NULL; } -static struct br_api_handler addr_add_handler = { +static struct gr_api_handler addr_add_handler = { .name = "ipv4 address add", - .request_type = BR_IP4_ADDR_ADD, + .request_type = GR_IP4_ADDR_ADD, .callback = addr_add, }; -static struct br_api_handler addr_del_handler = { +static struct gr_api_handler addr_del_handler = { .name = "ipv4 address del", - .request_type = BR_IP4_ADDR_DEL, + .request_type = GR_IP4_ADDR_DEL, .callback = addr_del, }; -static struct br_api_handler addr_list_handler = { +static struct gr_api_handler addr_list_handler = { .name = "ipv4 address list", - .request_type = BR_IP4_ADDR_LIST, + .request_type = GR_IP4_ADDR_LIST, .callback = addr_list, }; -static struct br_module addr_module = { +static struct gr_module addr_module = { .name = "ipv4 address", .init = addr_init, .fini = addr_fini, }; RTE_INIT(address_constructor) { - br_register_api_handler(&addr_add_handler); - br_register_api_handler(&addr_del_handler); - br_register_api_handler(&addr_list_handler); - br_register_module(&addr_module); + gr_register_api_handler(&addr_add_handler); + gr_register_api_handler(&addr_del_handler); + gr_register_api_handler(&addr_list_handler); + gr_register_module(&addr_module); } diff --git a/modules/ip/control/br_ip4_control.h b/modules/ip/control/gr_ip4_control.h similarity index 94% rename from modules/ip/control/br_ip4_control.h rename to modules/ip/control/gr_ip4_control.h index bfa23cd0..ef83c4c1 100644 --- a/modules/ip/control/br_ip4_control.h +++ b/modules/ip/control/gr_ip4_control.h @@ -1,11 +1,11 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#ifndef _BR_IP4_CONTROL -#define _BR_IP4_CONTROL +#ifndef _GR_IP4_CONTROL +#define _GR_IP4_CONTROL -#include -#include +#include +#include #include #include @@ -16,7 +16,7 @@ #include struct __rte_cache_aligned nexthop { - br_ip4_nh_flags_t flags; + gr_ip4_nh_flags_t flags; struct rte_ether_addr lladdr; uint16_t vrf_id; uint16_t iface_id; diff --git a/modules/ip/control/nexthop.c b/modules/ip/control/nexthop.c index ebe69d20..92aa5d26 100644 --- a/modules/ip/control/nexthop.c +++ b/modules/ip/control/nexthop.c @@ -1,15 +1,15 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -86,7 +86,7 @@ void ip4_nexthop_incref(struct nexthop *nh) { } static struct api_out nh4_add(const void *request, void **response) { - const struct br_ip4_nh_add_req *req = request; + const struct gr_ip4_nh_add_req *req = request; struct nexthop *nh; uint32_t nh_idx; int ret; @@ -102,7 +102,7 @@ static struct api_out nh4_add(const void *request, void **response) { if (ip4_nexthop_lookup(req->nh.vrf_id, req->nh.host, &nh_idx, &nh) == 0) { if (req->exist_ok && req->nh.iface_id == nh->iface_id - && br_eth_addr_eq(&req->nh.mac, (void *)&nh->lladdr)) + && gr_eth_addr_eq(&req->nh.mac, (void *)&nh->lladdr)) return api_out(0, 0); return api_out(EEXIST, 0); } @@ -112,14 +112,14 @@ static struct api_out nh4_add(const void *request, void **response) { nh->iface_id = req->nh.iface_id; memcpy(&nh->lladdr, (void *)&req->nh.mac, sizeof(nh->lladdr)); - nh->flags = BR_IP4_NH_F_STATIC | BR_IP4_NH_F_REACHABLE; + nh->flags = GR_IP4_NH_F_STATIC | GR_IP4_NH_F_REACHABLE; ret = ip4_route_insert(nh->vrf_id, nh->ip, 32, nh_idx, nh); return api_out(-ret, 0); } static struct api_out nh4_del(const void *request, void **response) { - const struct br_ip4_nh_del_req *req = request; + const struct gr_ip4_nh_del_req *req = request; struct nexthop *nh; uint32_t idx; @@ -133,7 +133,7 @@ static struct api_out nh4_del(const void *request, void **response) { return api_out(0, 0); return api_out(errno, 0); } - if ((nh->flags & (BR_IP4_NH_F_LOCAL | BR_IP4_NH_F_LINK | BR_IP4_NH_F_GATEWAY)) + if ((nh->flags & (GR_IP4_NH_F_LOCAL | GR_IP4_NH_F_LINK | GR_IP4_NH_F_GATEWAY)) || nh->ref_count > 1) return api_out(EBUSY, 0); @@ -145,9 +145,9 @@ static struct api_out nh4_del(const void *request, void **response) { } static struct api_out nh4_list(const void *request, void **response) { - const struct br_ip4_nh_list_req *req = request; - struct br_ip4_nh_list_resp *resp = NULL; - struct br_ip4_nh *api_nh; + const struct gr_ip4_nh_list_req *req = request; + struct gr_ip4_nh_list_resp *resp = NULL; + struct gr_ip4_nh *api_nh; struct nexthop *nh; uint32_t num, iter; const void *key; @@ -163,7 +163,7 @@ static struct api_out nh4_list(const void *request, void **response) { num++; } - len = sizeof(*resp) + num * sizeof(struct br_ip4_nh); + len = sizeof(*resp) + num * sizeof(struct gr_ip4_nh); if ((resp = calloc(len, 1)) == NULL) return api_out(ENOMEM, 0); @@ -204,35 +204,35 @@ static void nexthop_gc(evutil_socket_t, short, void *) { while ((idx = rte_hash_iterate(nh_hash, &key, &data, &iter)) >= 0) { nh = ip4_nexthop_get(idx); - if (nh->flags & BR_IP4_NH_F_STATIC) + if (nh->flags & GR_IP4_NH_F_STATIC) continue; reply_age = (now - nh->last_reply) / rte_get_tsc_hz(); request_age = (now - nh->last_request) / rte_get_tsc_hz(); probes = nh->ucast_probes + nh->bcast_probes; - if (nh->flags & (BR_IP4_NH_F_PENDING | BR_IP4_NH_F_STALE) && request_age > probes) { - if (probes >= max_probes && !(nh->flags & BR_IP4_NH_F_GATEWAY)) { + if (nh->flags & (GR_IP4_NH_F_PENDING | GR_IP4_NH_F_STALE) && request_age > probes) { + if (probes >= max_probes && !(nh->flags & GR_IP4_NH_F_GATEWAY)) { LOG(DEBUG, "vrf=%u ip=0x%08x failed_probes=%u held_pkts=%u: %s -> failed", nh->vrf_id, ntohl(nh->ip), probes, nh->held_pkts_num, - br_ip4_nh_f_name( - nh->flags & (BR_IP4_NH_F_PENDING | BR_IP4_NH_F_STALE) + gr_ip4_nh_f_name( + nh->flags & (GR_IP4_NH_F_PENDING | GR_IP4_NH_F_STALE) )); - nh->flags &= ~(BR_IP4_NH_F_PENDING | BR_IP4_NH_F_STALE); - nh->flags |= BR_IP4_NH_F_FAILED; + nh->flags &= ~(GR_IP4_NH_F_PENDING | GR_IP4_NH_F_STALE); + nh->flags |= GR_IP4_NH_F_FAILED; } else { if (arp_output_request_solicit(nh) < 0) LOG(ERR, "arp_output_request_solicit: %s", strerror(errno)); } - } else if (nh->flags & BR_IP4_NH_F_REACHABLE + } else if (nh->flags & GR_IP4_NH_F_REACHABLE && reply_age > IP4_NH_LIFETIME_REACHABLE) { - nh->flags &= ~BR_IP4_NH_F_REACHABLE; - nh->flags |= BR_IP4_NH_F_STALE; - } else if (nh->flags & BR_IP4_NH_F_FAILED + nh->flags &= ~GR_IP4_NH_F_REACHABLE; + nh->flags |= GR_IP4_NH_F_STALE; + } else if (nh->flags & GR_IP4_NH_F_FAILED && request_age > IP4_NH_LIFETIME_UNREACHABLE) { LOG(DEBUG, "vrf=%u ip=0x%08x failed_probes=%u held_pkts=%u: failed -> ", @@ -300,31 +300,31 @@ static void nh4_fini(struct event_base *) { nh_array = NULL; } -static struct br_api_handler nh4_add_handler = { +static struct gr_api_handler nh4_add_handler = { .name = "ipv4 nexthop add", - .request_type = BR_IP4_NH_ADD, + .request_type = GR_IP4_NH_ADD, .callback = nh4_add, }; -static struct br_api_handler nh4_del_handler = { +static struct gr_api_handler nh4_del_handler = { .name = "ipv4 nexthop del", - .request_type = BR_IP4_NH_DEL, + .request_type = GR_IP4_NH_DEL, .callback = nh4_del, }; -static struct br_api_handler nh4_list_handler = { +static struct gr_api_handler nh4_list_handler = { .name = "ipv4 nexthop list", - .request_type = BR_IP4_NH_LIST, + .request_type = GR_IP4_NH_LIST, .callback = nh4_list, }; -static struct br_module nh4_module = { +static struct gr_module nh4_module = { .name = "ipv4 nexthop", .init = nh4_init, .fini = nh4_fini, }; RTE_INIT(control_ip_init) { - br_register_api_handler(&nh4_add_handler); - br_register_api_handler(&nh4_del_handler); - br_register_api_handler(&nh4_list_handler); - br_register_module(&nh4_module); + gr_register_api_handler(&nh4_add_handler); + gr_register_api_handler(&nh4_del_handler); + gr_register_api_handler(&nh4_list_handler); + gr_register_module(&nh4_module); } diff --git a/modules/ip/control/route.c b/modules/ip/control/route.c index dec47f95..f452884b 100644 --- a/modules/ip/control/route.c +++ b/modules/ip/control/route.c @@ -1,13 +1,13 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -156,7 +156,7 @@ int ip4_route_delete(uint16_t vrf_id, ip4_addr_t ip, uint8_t prefixlen) { } static struct api_out route4_add(const void *request, void **response) { - const struct br_ip4_route_add_req *req = request; + const struct gr_ip4_route_add_req *req = request; struct rte_fib *fib; struct nexthop *nh; uint32_t nh_idx; @@ -185,13 +185,13 @@ static struct api_out route4_add(const void *request, void **response) { return api_out(-ret, 0); ip4_nexthop_incref(nh); - nh->flags |= BR_IP4_NH_F_GATEWAY; + nh->flags |= GR_IP4_NH_F_GATEWAY; return api_out(0, 0); } static struct api_out route4_del(const void *request, void **response) { - const struct br_ip4_route_del_req *req = request; + const struct gr_ip4_route_del_req *req = request; struct nexthop *nh; (void)response; @@ -202,7 +202,7 @@ static struct api_out route4_del(const void *request, void **response) { return api_out(ENOENT, 0); } - if (!(nh->flags & BR_IP4_NH_F_GATEWAY)) + if (!(nh->flags & GR_IP4_NH_F_GATEWAY)) return api_out(EBUSY, 0); if (ip4_route_delete(req->vrf_id, req->dest.ip, req->dest.prefixlen) < 0) @@ -212,8 +212,8 @@ static struct api_out route4_del(const void *request, void **response) { } static struct api_out route4_get(const void *request, void **response) { - const struct br_ip4_route_get_req *req = request; - struct br_ip4_route_get_resp *resp = NULL; + const struct gr_ip4_route_get_req *req = request; + struct gr_ip4_route_get_resp *resp = NULL; struct nexthop *nh = NULL; nh = ip4_route_lookup(req->vrf_id, req->dest); @@ -234,11 +234,11 @@ static struct api_out route4_get(const void *request, void **response) { } static struct api_out route4_list(const void *request, void **response) { - const struct br_ip4_route_list_req *req = request; - struct br_ip4_route_list_resp *resp = NULL; + const struct gr_ip4_route_list_req *req = request; + struct gr_ip4_route_list_resp *resp = NULL; struct rte_fib *fib = get_fib(req->vrf_id); struct rte_rib_node *rn = NULL; - struct br_ip4_route *r; + struct gr_ip4_route *r; struct rte_rib *rib; struct nexthop *nh; size_t num, len; @@ -259,7 +259,7 @@ static struct api_out route4_list(const void *request, void **response) { if (rte_rib_lookup_exact(rib, 0, 0) != NULL) num++; - len = sizeof(*resp) + num * sizeof(struct br_ip4_route); + len = sizeof(*resp) + num * sizeof(struct gr_ip4_route); if ((resp = calloc(1, len)) == NULL) return api_out(ENOMEM, 0); @@ -301,28 +301,28 @@ static void route4_fini(struct event_base *) { vrf_fibs = NULL; } -static struct br_api_handler route4_add_handler = { +static struct gr_api_handler route4_add_handler = { .name = "ipv4 route add", - .request_type = BR_IP4_ROUTE_ADD, + .request_type = GR_IP4_ROUTE_ADD, .callback = route4_add, }; -static struct br_api_handler route4_del_handler = { +static struct gr_api_handler route4_del_handler = { .name = "ipv4 route del", - .request_type = BR_IP4_ROUTE_DEL, + .request_type = GR_IP4_ROUTE_DEL, .callback = route4_del, }; -static struct br_api_handler route4_get_handler = { +static struct gr_api_handler route4_get_handler = { .name = "ipv4 route get", - .request_type = BR_IP4_ROUTE_GET, + .request_type = GR_IP4_ROUTE_GET, .callback = route4_get, }; -static struct br_api_handler route4_list_handler = { +static struct gr_api_handler route4_list_handler = { .name = "ipv4 route list", - .request_type = BR_IP4_ROUTE_LIST, + .request_type = GR_IP4_ROUTE_LIST, .callback = route4_list, }; -static struct br_module route4_module = { +static struct gr_module route4_module = { .name = "ipv4 route", .init = route4_init, .fini = route4_fini, @@ -330,9 +330,9 @@ static struct br_module route4_module = { }; RTE_INIT(control_ip_init) { - br_register_api_handler(&route4_add_handler); - br_register_api_handler(&route4_del_handler); - br_register_api_handler(&route4_get_handler); - br_register_api_handler(&route4_list_handler); - br_register_module(&route4_module); + gr_register_api_handler(&route4_add_handler); + gr_register_api_handler(&route4_del_handler); + gr_register_api_handler(&route4_get_handler); + gr_register_api_handler(&route4_list_handler); + gr_register_module(&route4_module); } diff --git a/modules/ip/datapath/arp_input.c b/modules/ip/datapath/arp_input.c index 7b373d50..77197ab7 100644 --- a/modules/ip/datapath/arp_input.c +++ b/modules/ip/datapath/arp_input.c @@ -1,12 +1,12 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include @@ -35,7 +35,7 @@ static inline void update_nexthop( struct rte_mbuf *m, *next; // Static next hops never need updating. - if (nh->flags & BR_IP4_NH_F_STATIC) + if (nh->flags & GR_IP4_NH_F_STATIC) return; rte_spinlock_lock(&nh->lock); @@ -43,8 +43,8 @@ static inline void update_nexthop( // Refresh all fields. nh->last_reply = now; nh->iface_id = iface_id; - nh->flags |= BR_IP4_NH_F_REACHABLE; - nh->flags &= ~(BR_IP4_NH_F_STALE | BR_IP4_NH_F_PENDING | BR_IP4_NH_F_FAILED); + nh->flags |= GR_IP4_NH_F_REACHABLE; + nh->flags &= ~(GR_IP4_NH_F_STALE | GR_IP4_NH_F_PENDING | GR_IP4_NH_F_FAILED); nh->ucast_probes = 0; nh->bcast_probes = 0; rte_ether_addr_copy(&arp->arp_data.arp_sha, &nh->lladdr); @@ -135,10 +135,10 @@ arp_input_process(struct rte_graph *graph, struct rte_node *node, void **objs, u } static void arp_input_register(void) { - rte_edge_t edge = br_node_attach_parent("eth_input", "arp_input"); + rte_edge_t edge = gr_node_attach_parent("eth_input", "arp_input"); if (edge == RTE_EDGE_ID_INVALID) - ABORT("br_node_attach_parent(eth_input, arp_input) failed"); - br_eth_input_add_type(rte_cpu_to_be_16(RTE_ETHER_TYPE_ARP), edge); + ABORT("gr_node_attach_parent(eth_input, arp_input) failed"); + gr_eth_input_add_type(rte_cpu_to_be_16(RTE_ETHER_TYPE_ARP), edge); } static struct rte_node_register node = { @@ -158,15 +158,15 @@ static struct rte_node_register node = { }, }; -static struct br_node_info info = { +static struct gr_node_info info = { .node = &node, .register_callback = arp_input_register, }; -BR_NODE_REGISTER(info); +GR_NODE_REGISTER(info); -BR_DROP_REGISTER(arp_input_reply); -BR_DROP_REGISTER(arp_input_op_unsupp); -BR_DROP_REGISTER(arp_input_proto_unsupp); -BR_DROP_REGISTER(arp_input_error); -BR_DROP_REGISTER(arp_input_drop); +GR_DROP_REGISTER(arp_input_reply); +GR_DROP_REGISTER(arp_input_op_unsupp); +GR_DROP_REGISTER(arp_input_proto_unsupp); +GR_DROP_REGISTER(arp_input_error); +GR_DROP_REGISTER(arp_input_drop); diff --git a/modules/ip/datapath/arp_output_reply.c b/modules/ip/datapath/arp_output_reply.c index e116713b..c80bfe50 100644 --- a/modules/ip/datapath/arp_output_reply.c +++ b/modules/ip/datapath/arp_output_reply.c @@ -1,12 +1,12 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include @@ -87,10 +87,10 @@ static struct rte_node_register node = { }, }; -static struct br_node_info info = { +static struct gr_node_info info = { .node = &node, }; -BR_NODE_REGISTER(info); +GR_NODE_REGISTER(info); -BR_DROP_REGISTER(arp_output_reply_error); +GR_DROP_REGISTER(arp_output_reply_error); diff --git a/modules/ip/datapath/arp_output_request.c b/modules/ip/datapath/arp_output_request.c index 2d3c0d00..2508962e 100644 --- a/modules/ip/datapath/arp_output_request.c +++ b/modules/ip/datapath/arp_output_request.c @@ -1,13 +1,13 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -152,12 +152,12 @@ static struct rte_node_register arp_output_request_node = { }, }; -static struct br_node_info arp_output_request_info = { +static struct gr_node_info arp_output_request_info = { .node = &arp_output_request_node, .register_callback = arp_output_request_register, .unregister_callback = arp_output_request_unregister, }; -BR_NODE_REGISTER(arp_output_request_info); +GR_NODE_REGISTER(arp_output_request_info); -BR_DROP_REGISTER(arp_output_error); +GR_DROP_REGISTER(arp_output_error); diff --git a/modules/ip/datapath/br_ip4_datapath.h b/modules/ip/datapath/gr_ip4_datapath.h similarity index 79% rename from modules/ip/datapath/br_ip4_datapath.h rename to modules/ip/datapath/gr_ip4_datapath.h index ce78393e..a0f242c3 100644 --- a/modules/ip/datapath/br_ip4_datapath.h +++ b/modules/ip/datapath/gr_ip4_datapath.h @@ -1,12 +1,12 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#ifndef _BR_IP4_DATAPATH_H -#define _BR_IP4_DATAPATH_H +#ifndef _GR_IP4_DATAPATH_H +#define _GR_IP4_DATAPATH_H -#include -#include -#include +#include +#include +#include #include #include @@ -14,14 +14,14 @@ #include -BR_MBUF_PRIV_DATA_TYPE(ip_output_mbuf_data, { struct nexthop *nh; }); +GR_MBUF_PRIV_DATA_TYPE(ip_output_mbuf_data, { struct nexthop *nh; }); -BR_MBUF_PRIV_DATA_TYPE(arp_mbuf_data, { +GR_MBUF_PRIV_DATA_TYPE(arp_mbuf_data, { struct nexthop *local; struct nexthop *remote; }); -BR_MBUF_PRIV_DATA_TYPE(ip_local_mbuf_data, { +GR_MBUF_PRIV_DATA_TYPE(ip_local_mbuf_data, { ip4_addr_t src; ip4_addr_t dst; uint16_t len; diff --git a/modules/ip/datapath/icmp_input.c b/modules/ip/datapath/icmp_input.c index 7343967f..dc01e51e 100644 --- a/modules/ip/datapath/icmp_input.c +++ b/modules/ip/datapath/icmp_input.c @@ -1,12 +1,12 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include @@ -64,9 +64,9 @@ icmp_input_process(struct rte_graph *graph, struct rte_node *node, void **objs, } static void icmp_input_register(void) { - rte_edge_t edge = br_node_attach_parent("ip_input_local", "icmp_input"); + rte_edge_t edge = gr_node_attach_parent("ip_input_local", "icmp_input"); if (edge == RTE_EDGE_ID_INVALID) - ABORT("br_node_attach_parent(classify, icmp_input) failed"); + ABORT("gr_node_attach_parent(classify, icmp_input) failed"); ip_input_local_add_proto(IPPROTO_ICMP, edge); } @@ -83,12 +83,12 @@ static struct rte_node_register icmp_input_node = { }, }; -static struct br_node_info icmp_input_info = { +static struct gr_node_info icmp_input_info = { .node = &icmp_input_node, .register_callback = icmp_input_register, }; -BR_NODE_REGISTER(icmp_input_info); +GR_NODE_REGISTER(icmp_input_info); -BR_DROP_REGISTER(icmp_input_invalid); -BR_DROP_REGISTER(icmp_input_unsupported); +GR_DROP_REGISTER(icmp_input_invalid); +GR_DROP_REGISTER(icmp_input_unsupported); diff --git a/modules/ip/datapath/icmp_output.c b/modules/ip/datapath/icmp_output.c index d1a35c2f..b7926c77 100644 --- a/modules/ip/datapath/icmp_output.c +++ b/modules/ip/datapath/icmp_output.c @@ -1,12 +1,12 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include @@ -57,8 +57,8 @@ static struct rte_node_register icmp_output_node = { }, }; -static struct br_node_info icmp_output_info = { +static struct gr_node_info icmp_output_info = { .node = &icmp_output_node, }; -BR_NODE_REGISTER(icmp_output_info); +GR_NODE_REGISTER(icmp_output_info); diff --git a/modules/ip/datapath/ip_forward.c b/modules/ip/datapath/ip_forward.c index 2bed5d7a..299fe0a8 100644 --- a/modules/ip/datapath/ip_forward.c +++ b/modules/ip/datapath/ip_forward.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include +#include #include #include @@ -51,10 +51,10 @@ static struct rte_node_register forward_node = { }, }; -static struct br_node_info info = { +static struct gr_node_info info = { .node = &forward_node, }; -BR_NODE_REGISTER(info); +GR_NODE_REGISTER(info); -BR_DROP_REGISTER(ip_forward_ttl_exceeded); +GR_DROP_REGISTER(ip_forward_ttl_exceeded); diff --git a/modules/ip/datapath/ip_input.c b/modules/ip/datapath/ip_input.c index 2aa4ea93..40b77f39 100644 --- a/modules/ip/datapath/ip_input.c +++ b/modules/ip/datapath/ip_input.c @@ -1,11 +1,11 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include @@ -82,7 +82,7 @@ ip_input_process(struct rte_graph *graph, struct rte_node *node, void **objs, ui } // If the resolved next hop is local and the destination IP is ourselves, // send to ip_local. - if (nh->flags & BR_IP4_NH_F_LOCAL && ip->dst_addr == nh->ip) + if (nh->flags & GR_IP4_NH_F_LOCAL && ip->dst_addr == nh->ip) next = LOCAL; else next = FORWARD; @@ -96,10 +96,10 @@ ip_input_process(struct rte_graph *graph, struct rte_node *node, void **objs, ui } static void ip_input_register(void) { - rte_edge_t edge = br_node_attach_parent("eth_input", "ip_input"); + rte_edge_t edge = gr_node_attach_parent("eth_input", "ip_input"); if (edge == RTE_EDGE_ID_INVALID) - ABORT("br_node_attach_parent(eth_input, ip_input) failed"); - br_eth_input_add_type(rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4), edge); + ABORT("gr_node_attach_parent(eth_input, ip_input) failed"); + gr_eth_input_add_type(rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4), edge); } static struct rte_node_register input_node = { @@ -117,13 +117,13 @@ static struct rte_node_register input_node = { }, }; -static struct br_node_info info = { +static struct gr_node_info info = { .node = &input_node, .register_callback = ip_input_register, }; -BR_NODE_REGISTER(info); +GR_NODE_REGISTER(info); -BR_DROP_REGISTER(ip_input_no_route); -BR_DROP_REGISTER(ip_input_bad_checksum); -BR_DROP_REGISTER(ip_input_bad_length); +GR_DROP_REGISTER(ip_input_no_route); +GR_DROP_REGISTER(ip_input_bad_checksum); +GR_DROP_REGISTER(ip_input_bad_length); diff --git a/modules/ip/datapath/ip_local.c b/modules/ip/datapath/ip_local.c index 279aba5e..29a12191 100644 --- a/modules/ip/datapath/ip_local.c +++ b/modules/ip/datapath/ip_local.c @@ -1,9 +1,9 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include -#include -#include +#include +#include +#include #include #include @@ -57,10 +57,10 @@ static struct rte_node_register input_node = { }, }; -static struct br_node_info info = { +static struct gr_node_info info = { .node = &input_node, }; -BR_NODE_REGISTER(info); +GR_NODE_REGISTER(info); -BR_DROP_REGISTER(ip_input_local_unknown_proto); +GR_DROP_REGISTER(ip_input_local_unknown_proto); diff --git a/modules/ip/datapath/ip_output.c b/modules/ip/datapath/ip_output.c index a33e6f3e..b0c2dd9f 100644 --- a/modules/ip/datapath/ip_output.c +++ b/modules/ip/datapath/ip_output.c @@ -1,15 +1,15 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -42,7 +42,7 @@ typedef enum { static inline hold_status_t maybe_hold_packet(struct nexthop *nh, struct rte_mbuf *mbuf) { hold_status_t status; - if (nh->flags & BR_IP4_NH_F_REACHABLE) { + if (nh->flags & GR_IP4_NH_F_REACHABLE) { status = OK_TO_SEND; } else if (nh->held_pkts_num < IP4_NH_MAX_HELD_PKTS) { queue_mbuf_data(mbuf)->next = NULL; @@ -54,9 +54,9 @@ static inline hold_status_t maybe_hold_packet(struct nexthop *nh, struct rte_mbu nh->held_pkts_tail = mbuf; nh->held_pkts_num++; rte_spinlock_unlock(&nh->lock); - if (!(nh->flags & BR_IP4_NH_F_PENDING)) { + if (!(nh->flags & GR_IP4_NH_F_PENDING)) { arp_output_request_solicit(nh); - nh->flags |= BR_IP4_NH_F_PENDING; + nh->flags |= GR_IP4_NH_F_PENDING; } status = HELD; } else { @@ -99,7 +99,7 @@ ip_output_process(struct rte_graph *graph, struct rte_node *node, void **objs, u if (next != ETH_OUTPUT) goto next; - if (nh->flags & BR_IP4_NH_F_LINK && ip->dst_addr != nh->ip) { + if (nh->flags & GR_IP4_NH_F_LINK && ip->dst_addr != nh->ip) { // The resolved next hop is associated with a "connected" route. // We currently do not have an explicit entry for this destination IP. // Create a new next hop and its associated /32 route so that next @@ -154,12 +154,12 @@ struct rte_node_register output_node = { }, }; -static struct br_node_info info = { +static struct gr_node_info info = { .node = &output_node, }; -BR_NODE_REGISTER(info); +GR_NODE_REGISTER(info); -BR_DROP_REGISTER(ip_output_error); -BR_DROP_REGISTER(ip_output_no_route); -BR_DROP_REGISTER(arp_queue_full); +GR_DROP_REGISTER(ip_output_error); +GR_DROP_REGISTER(ip_output_no_route); +GR_DROP_REGISTER(arp_queue_full); diff --git a/modules/ipip/br_ipip.h b/modules/ipip/br_ipip.h deleted file mode 100644 index e5d6c471..00000000 --- a/modules/ipip/br_ipip.h +++ /dev/null @@ -1,27 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// Copyright (c) 2024 Robin Jarry - -#ifndef _BR_API_IPIP -#define _BR_API_IPIP - -#include -#include -#include -#include -#include - -#define BR_IFACE_TYPE_IPIP 0x0003 - -// IPIP reconfig attributes -#define BR_IPIP_SET_LOCAL BR_BIT64(32) -#define BR_IPIP_SET_REMOTE BR_BIT64(33) - -// Info for BR_IFACE_TYPE_IPIP interfaces -struct br_iface_info_ipip { - ip4_addr_t local; - ip4_addr_t remote; -}; - -static_assert(sizeof(struct br_iface_info_ipip) <= MEMBER_SIZE(struct br_iface, info)); - -#endif diff --git a/modules/ipip/cli.c b/modules/ipip/cli.c index 8b09c3c8..fb80230a 100644 --- a/modules/ipip/cli.c +++ b/modules/ipip/cli.c @@ -1,18 +1,18 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include -static void ipip_show(const struct br_api_client *c, const struct br_iface *iface) { - const struct br_iface_info_ipip *ipip = (const struct br_iface_info_ipip *)iface->info; +static void ipip_show(const struct gr_api_client *c, const struct gr_iface *iface) { + const struct gr_iface_info_ipip *ipip = (const struct gr_iface_info_ipip *)iface->info; char local[64], remote[64]; (void)c; @@ -24,8 +24,8 @@ static void ipip_show(const struct br_api_client *c, const struct br_iface *ifac } static void -ipip_list_info(const struct br_api_client *c, const struct br_iface *iface, char *buf, size_t len) { - const struct br_iface_info_ipip *ipip = (const struct br_iface_info_ipip *)iface->info; +ipip_list_info(const struct gr_api_client *c, const struct gr_iface *iface, char *buf, size_t len) { + const struct gr_iface_info_ipip *ipip = (const struct gr_iface_info_ipip *)iface->info; char local[64], remote[64]; (void)c; @@ -36,23 +36,23 @@ ipip_list_info(const struct br_api_client *c, const struct br_iface *iface, char } static struct cli_iface_type ipip_type = { - .type_id = BR_IFACE_TYPE_IPIP, + .type_id = GR_IFACE_TYPE_IPIP, .name = "ipip", .show = ipip_show, .list_info = ipip_list_info, }; static uint64_t parse_ipip_args( - const struct br_api_client *c, + const struct gr_api_client *c, const struct ec_pnode *p, - struct br_iface *iface, + struct gr_iface *iface, bool update ) { uint64_t set_attrs = parse_iface_args(c, p, iface, update); - struct br_iface_info_ipip *ipip; + struct gr_iface_info_ipip *ipip; const char *local, *remote; - ipip = (struct br_iface_info_ipip *)iface->info; + ipip = (struct gr_iface_info_ipip *)iface->info; local = arg_str(p, "LOCAL"); if (local != NULL) { @@ -60,7 +60,7 @@ static uint64_t parse_ipip_args( errno = EINVAL; return 0; } - set_attrs |= BR_IPIP_SET_LOCAL; + set_attrs |= GR_IPIP_SET_LOCAL; } remote = arg_str(p, "REMOTE"); if (remote != NULL) { @@ -68,7 +68,7 @@ static uint64_t parse_ipip_args( errno = EINVAL; return 0; } - set_attrs |= BR_IPIP_SET_REMOTE; + set_attrs |= GR_IPIP_SET_REMOTE; } if (ipip->local == ipip->remote) { errno = EADDRINUSE; @@ -80,17 +80,17 @@ static uint64_t parse_ipip_args( return set_attrs; } -static cmd_status_t ipip_add(const struct br_api_client *c, const struct ec_pnode *p) { - const struct br_infra_iface_add_resp *resp; - struct br_infra_iface_add_req req = { - .iface = {.type = BR_IFACE_TYPE_IPIP, .flags = BR_IFACE_F_UP} +static cmd_status_t ipip_add(const struct gr_api_client *c, const struct ec_pnode *p) { + const struct gr_infra_iface_add_resp *resp; + struct gr_infra_iface_add_req req = { + .iface = {.type = GR_IFACE_TYPE_IPIP, .flags = GR_IFACE_F_UP} }; void *resp_ptr = NULL; if (parse_ipip_args(c, p, &req.iface, false) == 0) return CMD_ERROR; - if (br_api_client_send_recv(c, BR_INFRA_IFACE_ADD, sizeof(req), &req, &resp_ptr) < 0) + if (gr_api_client_send_recv(c, GR_INFRA_IFACE_ADD, sizeof(req), &req, &resp_ptr) < 0) return CMD_ERROR; resp = resp_ptr; @@ -99,13 +99,13 @@ static cmd_status_t ipip_add(const struct br_api_client *c, const struct ec_pnod return CMD_SUCCESS; } -static cmd_status_t ipip_set(const struct br_api_client *c, const struct ec_pnode *p) { - struct br_infra_iface_set_req req = {0}; +static cmd_status_t ipip_set(const struct gr_api_client *c, const struct ec_pnode *p) { + struct gr_infra_iface_set_req req = {0}; if ((req.set_attrs = parse_ipip_args(c, p, &req.iface, true)) == 0) return CMD_ERROR; - if (br_api_client_send_recv(c, BR_INFRA_IFACE_SET, sizeof(req), &req, NULL) < 0) + if (gr_api_client_send_recv(c, GR_INFRA_IFACE_SET, sizeof(req), &req, NULL) < 0) return CMD_ERROR; return CMD_SUCCESS; @@ -136,7 +136,7 @@ static int ctx_init(struct ec_node *root) { "Modify ipip parameters.", with_help( "Interface name.", - ec_node_dyn("NAME", complete_iface_names, INT2PTR(BR_IFACE_TYPE_IPIP)) + ec_node_dyn("NAME", complete_iface_names, INT2PTR(GR_IFACE_TYPE_IPIP)) ), with_help("New interface name.", ec_node("any", "NEW_NAME")), IPIP_ATTRS_ARGS @@ -147,7 +147,7 @@ static int ctx_init(struct ec_node *root) { return 0; } -static struct br_cli_context ctx = { +static struct gr_cli_context ctx = { .name = "ipip", .init = ctx_init, }; diff --git a/modules/ipip/control.c b/modules/ipip/control.c index 9b6356fa..046d5e5f 100644 --- a/modules/ipip/control.c +++ b/modules/ipip/control.c @@ -1,15 +1,15 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2024 Robin Jarry -#include "br_ipip.h" +#include "gr_ipip.h" #include "ipip_priv.h" -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include @@ -52,12 +52,12 @@ static int iface_ipip_reconfig( const void *api_info ) { struct iface_info_ipip *cur = (struct iface_info_ipip *)iface->info; - const struct br_iface_info_ipip *next = api_info; + const struct gr_iface_info_ipip *next = api_info; struct ipip_key cur_key = {cur->local, cur->remote, iface->vrf_id}; struct ipip_key next_key = {next->local, next->remote, vrf_id}; int ret; - if (set_attrs & (BR_IFACE_SET_VRF | BR_IPIP_SET_LOCAL | BR_IPIP_SET_REMOTE)) { + if (set_attrs & (GR_IFACE_SET_VRF | GR_IPIP_SET_LOCAL | GR_IPIP_SET_REMOTE)) { if (vrf_id >= MAX_VRFS) return errno_set(EOVERFLOW); @@ -80,9 +80,9 @@ static int iface_ipip_reconfig( iface->vrf_id = vrf_id; } - if (set_attrs & BR_IFACE_SET_FLAGS) + if (set_attrs & GR_IFACE_SET_FLAGS) iface->flags = flags; - if (set_attrs & BR_IFACE_SET_MTU) + if (set_attrs & GR_IFACE_SET_MTU) iface->mtu = mtu; return 0; @@ -113,14 +113,14 @@ static int iface_ipip_init(struct iface *iface, const void *api_info) { static void ipip_to_api(void *info, const struct iface *iface) { const struct iface_info_ipip *ipip = (const struct iface_info_ipip *)iface->info; - struct br_iface_info_ipip *api = info; + struct gr_iface_info_ipip *api = info; api->local = ipip->local; api->remote = ipip->remote; } static struct iface_type iface_type_ipip = { - .id = BR_IFACE_TYPE_IPIP, + .id = GR_IFACE_TYPE_IPIP, .name = "ipip", .info_size = sizeof(struct iface_info_ipip), .init = iface_ipip_init, @@ -148,7 +148,7 @@ static void ipip_fini(struct event_base *) { ipip_hash = NULL; } -static struct br_module ipip_module = { +static struct gr_module ipip_module = { .name = "ipip", .init = ipip_init, .fini = ipip_fini, @@ -156,6 +156,6 @@ static struct br_module ipip_module = { }; RTE_INIT(ipip_constructor) { - br_register_module(&ipip_module); + gr_register_module(&ipip_module); iface_type_register(&iface_type_ipip); } diff --git a/modules/ipip/datapath_in.c b/modules/ipip/datapath_in.c index d9fa9fbb..1666f2a7 100644 --- a/modules/ipip/datapath_in.c +++ b/modules/ipip/datapath_in.c @@ -3,13 +3,13 @@ #include "ipip_priv.h" -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -68,9 +68,9 @@ ipip_input_process(struct rte_graph *graph, struct rte_node *node, void **objs, } static void ipip_input_register(void) { - rte_edge_t edge = br_node_attach_parent("ip_input_local", "ipip_input"); + rte_edge_t edge = gr_node_attach_parent("ip_input_local", "ipip_input"); if (edge == RTE_EDGE_ID_INVALID) - ABORT("br_node_attach_parent(ip_input_local, ipip_input) failed"); + ABORT("gr_node_attach_parent(ip_input_local, ipip_input) failed"); ip_input_local_add_proto(IPPROTO_IPIP, edge); } @@ -86,11 +86,11 @@ static struct rte_node_register ipip_input_node = { }, }; -static struct br_node_info ipip_input_info = { +static struct gr_node_info ipip_input_info = { .node = &ipip_input_node, .register_callback = ipip_input_register, }; -BR_NODE_REGISTER(ipip_input_info); +GR_NODE_REGISTER(ipip_input_info); -BR_DROP_REGISTER(ipip_input_no_tunnel); +GR_DROP_REGISTER(ipip_input_no_tunnel); diff --git a/modules/ipip/datapath_out.c b/modules/ipip/datapath_out.c index 0a10c55d..1a14cae8 100644 --- a/modules/ipip/datapath_out.c +++ b/modules/ipip/datapath_out.c @@ -3,14 +3,14 @@ #include "ipip_priv.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -42,7 +42,7 @@ ipip_output_process(struct rte_graph *graph, struct rte_node *node, void **objs, // Resolve the IPIP interface from the nexthop provided by ip_output. ip_data = ip_output_mbuf_data(mbuf); iface = iface_from_id(ip_data->nh->iface_id); - if (iface == NULL || iface->type_id != BR_IFACE_TYPE_IPIP) { + if (iface == NULL || iface->type_id != GR_IFACE_TYPE_IPIP) { next = NO_TUNNEL; goto next; } @@ -69,10 +69,10 @@ ipip_output_process(struct rte_graph *graph, struct rte_node *node, void **objs, } static void ipip_output_register(void) { - rte_edge_t edge = br_node_attach_parent("ip_output", "ipip_output"); + rte_edge_t edge = gr_node_attach_parent("ip_output", "ipip_output"); if (edge == RTE_EDGE_ID_INVALID) - ABORT("br_node_attach_parent(ip_output, ipip_output) failed"); - ip_output_add_tunnel(BR_IFACE_TYPE_IPIP, edge); + ABORT("gr_node_attach_parent(ip_output, ipip_output) failed"); + ip_output_add_tunnel(GR_IFACE_TYPE_IPIP, edge); } static struct rte_node_register ipip_output_node = { @@ -87,11 +87,11 @@ static struct rte_node_register ipip_output_node = { }, }; -static struct br_node_info ipip_output_info = { +static struct gr_node_info ipip_output_info = { .node = &ipip_output_node, .register_callback = ipip_output_register, }; -BR_NODE_REGISTER(ipip_output_info); +GR_NODE_REGISTER(ipip_output_info); -BR_DROP_REGISTER(ipip_output_no_tunnel); +GR_DROP_REGISTER(ipip_output_no_tunnel); diff --git a/modules/ipip/gr_ipip.h b/modules/ipip/gr_ipip.h new file mode 100644 index 00000000..bcd6802a --- /dev/null +++ b/modules/ipip/gr_ipip.h @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: BSD-3-Clause +// Copyright (c) 2024 Robin Jarry + +#ifndef _GR_API_IPIP +#define _GR_API_IPIP + +#include +#include +#include +#include +#include + +#define GR_IFACE_TYPE_IPIP 0x0003 + +// IPIP reconfig attributes +#define GR_IPIP_SET_LOCAL GR_BIT64(32) +#define GR_IPIP_SET_REMOTE GR_BIT64(33) + +// Info for GR_IFACE_TYPE_IPIP interfaces +struct gr_iface_info_ipip { + ip4_addr_t local; + ip4_addr_t remote; +}; + +static_assert(sizeof(struct gr_iface_info_ipip) <= MEMBER_SIZE(struct gr_iface, info)); + +#endif diff --git a/modules/ipip/ipip_priv.h b/modules/ipip/ipip_priv.h index 0259a335..f4131ad8 100644 --- a/modules/ipip/ipip_priv.h +++ b/modules/ipip/ipip_priv.h @@ -4,8 +4,8 @@ #ifndef _IPIP_PRIV_H #define _IPIP_PRIV_H -#include -#include +#include +#include #include diff --git a/modules/ipip/meson.build b/modules/ipip/meson.build index 83861235..69760d9e 100644 --- a/modules/ipip/meson.build +++ b/modules/ipip/meson.build @@ -8,6 +8,6 @@ src += files( 'datapath_out.c', ) -api_headers += files('br_ipip.h') +api_headers += files('gr_ipip.h') cli_inc += include_directories('.') cli_src += files('cli.c') diff --git a/smoke/_init.sh b/smoke/_init.sh index d14da5f7..f27296d9 100644 --- a/smoke/_init.sh +++ b/smoke/_init.sh @@ -3,17 +3,17 @@ set -e -if [ -S "$BR_SOCK_PATH" ]; then - run_br=false +if [ -S "$GROUT_SOCK_PATH" ]; then + run_grout=false else - run_br=true + run_grout=true fi cleanup() { set +e sh -x $tmp/cleanup - if [ "$run_br" = true ]; then - kill -INT %?br + if [ "$run_grout" = true ]; then + kill -INT %?grout wait fi rm -rf -- "$tmp" @@ -24,20 +24,20 @@ trap cleanup EXIT builddir=${1?builddir} run_id=$(echo $SRANDOM$SRANDOM | base32 -w6 | tr '[:upper:]' '[:lower:]' | head -n1) -if [ "$run_br" = true ]; then - export BR_SOCK_PATH=$tmp/br.sock +if [ "$run_grout" = true ]; then + export GROUT_SOCK_PATH=$tmp/grout.sock fi export PATH=$builddir:$PATH cat > $tmp/cleanup <> $tmp/cleanup diff --git a/smoke/run.sh b/smoke/run.sh index e586cd5c..a683d8dc 100755 --- a/smoke/run.sh +++ b/smoke/run.sh @@ -7,7 +7,7 @@ if [ "$1" = "--coredump" ]; then coredump=true ulimit -c unlimited trap "sysctl -qw 'kernel.core_pattern=$(sysctl -n kernel.core_pattern)'" EXIT - sysctl -qw kernel.core_pattern=/tmp/br-core.%e.%p + sysctl -qw kernel.core_pattern=/tmp/grout-core.%e.%p shift fi builddir=${1?build dir} @@ -32,7 +32,7 @@ for script in $here/*_test.sh; do if ! "$script" "$builddir"; then res=FAILED fi - for core in /tmp/br-core.*.*; do + for core in /tmp/grout-core.*.*; do [ -s "$core" ] || continue binary=$(file -b "$core" | sed -En "s/.*, execfn: '([^']+)',.*/\\1/p") [ -x "$binary" ] || continue diff --git a/smoke/vlan_forward_test.sh b/smoke/vlan_forward_test.sh index de298740..d4bf6e62 100755 --- a/smoke/vlan_forward_test.sh +++ b/smoke/vlan_forward_test.sh @@ -9,12 +9,12 @@ p1=${run_id}1 v0=$p0.42 v1=$p1.43 -br-cli add interface port $p0 devargs net_tap0,iface=$p0 mac f0:0d:ac:dc:00:00 -br-cli add interface port $p1 devargs net_tap1,iface=$p1 mac f0:0d:ac:dc:00:01 -br-cli add interface vlan $v0 parent $p0 vlan_id 42 -br-cli add interface vlan $v1 parent $p1 vlan_id 43 -br-cli add ip address 172.16.0.1/24 iface $v0 -br-cli add ip address 172.16.1.1/24 iface $v1 +grcli add interface port $p0 devargs net_tap0,iface=$p0 mac f0:0d:ac:dc:00:00 +grcli add interface port $p1 devargs net_tap1,iface=$p1 mac f0:0d:ac:dc:00:01 +grcli add interface vlan $v0 parent $p0 vlan_id 42 +grcli add interface vlan $v1 parent $p1 vlan_id 43 +grcli add ip address 172.16.0.1/24 iface $v0 +grcli add ip address 172.16.1.1/24 iface $v1 for n in 0 1; do p=$run_id$n diff --git a/smoke/vrf_forward_test.sh b/smoke/vrf_forward_test.sh index f85fc739..e74cea1d 100755 --- a/smoke/vrf_forward_test.sh +++ b/smoke/vrf_forward_test.sh @@ -9,14 +9,14 @@ p1=${run_id}1 p2=${run_id}2 p3=${run_id}3 -br-cli add interface port $p0 devargs net_tap0,iface=$p0 vrf 1 mac f0:0d:ac:dc:01:00 -br-cli add interface port $p1 devargs net_tap1,iface=$p1 vrf 1 mac f0:0d:ac:dc:01:01 -br-cli add interface port $p2 devargs net_tap2,iface=$p2 vrf 2 mac f0:0d:ac:dc:02:00 -br-cli add interface port $p3 devargs net_tap3,iface=$p3 vrf 2 mac f0:0d:ac:dc:02:01 -br-cli add ip address 172.16.0.1/24 iface $p0 -br-cli add ip address 172.16.1.1/24 iface $p1 -br-cli add ip address 172.16.0.1/24 iface $p2 -br-cli add ip address 172.16.1.1/24 iface $p3 +grcli add interface port $p0 devargs net_tap0,iface=$p0 vrf 1 mac f0:0d:ac:dc:01:00 +grcli add interface port $p1 devargs net_tap1,iface=$p1 vrf 1 mac f0:0d:ac:dc:01:01 +grcli add interface port $p2 devargs net_tap2,iface=$p2 vrf 2 mac f0:0d:ac:dc:02:00 +grcli add interface port $p3 devargs net_tap3,iface=$p3 vrf 2 mac f0:0d:ac:dc:02:01 +grcli add ip address 172.16.0.1/24 iface $p0 +grcli add ip address 172.16.1.1/24 iface $p1 +grcli add ip address 172.16.0.1/24 iface $p2 +grcli add ip address 172.16.1.1/24 iface $p3 for n in 0 1; do p=$run_id$n