Skip to content

Commit

Permalink
router: Some VTY cosmetics displaying routing ruleset
Browse files Browse the repository at this point in the history
  • Loading branch information
acassen committed Apr 1, 2024
1 parent 0e76b6a commit f757e87
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 42 deletions.
40 changes: 20 additions & 20 deletions src/gtp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,9 @@ DEFUN(request_channel,
/*
* Show
*/
DEFUN(show_gtp_fwd,
show_gtp_fwd_cmd,
"show gtp fwd",
DEFUN(show_xdp_forwarding,
show_xdp_forwarding_cmd,
"show xdp forwarding",
SHOW_STR
"XDP GTP Fowarding Dataplane ruleset\n")
{
Expand All @@ -572,9 +572,9 @@ DEFUN(show_gtp_fwd,
return CMD_SUCCESS;
}

DEFUN(show_xdp_fwd_iptnl,
show_xdp_fwd_iptnl_cmd,
"show xdp fwd iptunnel",
DEFUN(show_xdp_forwarding_iptnl,
show_xdp_forwarding_iptnl_cmd,
"show xdp forwarding iptunnel",
SHOW_STR
"GTP XDP Forwarding IPIP Tunnel ruleset\n")
{
Expand All @@ -596,9 +596,9 @@ DEFUN(show_xdp_fwd_iptnl,
return CMD_SUCCESS;
}

DEFUN(show_gtp_rt,
show_gtp_rt_cmd,
"show gtp rt",
DEFUN(show_xdp_routing,
show_xdp_routing_cmd,
"show xdp routing",
SHOW_STR
"GTP XDP Routing Dataplane ruleset\n")
{
Expand All @@ -620,9 +620,9 @@ DEFUN(show_gtp_rt,
return CMD_SUCCESS;
}

DEFUN(show_xdp_rt_iptnl,
show_xdp_rt_iptnl_cmd,
"show xdp rt iptunnel",
DEFUN(show_xdp_routing_iptnl,
show_xdp_routing_iptnl_cmd,
"show xdp routing iptunnel",
SHOW_STR
"GTP XDP Routing IPIP Tunnel ruleset\n")
{
Expand Down Expand Up @@ -891,17 +891,17 @@ gtp_vty_init(void)
install_element(PDN_NODE, &request_channel_cmd);

/* Install show commands */
install_element(VIEW_NODE, &show_gtp_fwd_cmd);
install_element(VIEW_NODE, &show_xdp_fwd_iptnl_cmd);
install_element(VIEW_NODE, &show_gtp_rt_cmd);
install_element(VIEW_NODE, &show_xdp_rt_iptnl_cmd);
install_element(VIEW_NODE, &show_xdp_forwarding_cmd);
install_element(VIEW_NODE, &show_xdp_forwarding_iptnl_cmd);
install_element(VIEW_NODE, &show_xdp_routing_cmd);
install_element(VIEW_NODE, &show_xdp_routing_iptnl_cmd);
install_element(VIEW_NODE, &show_xdp_mirror_cmd);
install_element(VIEW_NODE, &gtp_send_echo_request_standard_cmd);
install_element(VIEW_NODE, &gtp_send_echo_request_extended_cmd);
install_element(ENABLE_NODE, &show_gtp_fwd_cmd);
install_element(ENABLE_NODE, &show_xdp_fwd_iptnl_cmd);
install_element(ENABLE_NODE, &show_gtp_rt_cmd);
install_element(ENABLE_NODE, &show_xdp_rt_iptnl_cmd);
install_element(ENABLE_NODE, &show_xdp_forwarding_cmd);
install_element(ENABLE_NODE, &show_xdp_forwarding_iptnl_cmd);
install_element(ENABLE_NODE, &show_xdp_routing_cmd);
install_element(ENABLE_NODE, &show_xdp_routing_iptnl_cmd);
install_element(ENABLE_NODE, &show_xdp_mirror_cmd);
install_element(ENABLE_NODE, &gtp_send_echo_request_standard_cmd);
install_element(ENABLE_NODE, &gtp_send_echo_request_extended_cmd);
Expand Down
18 changes: 12 additions & 6 deletions src/gtp_xdp_fwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,6 @@ gtp_xdp_teid_action(struct bpf_map *map, int action, gtp_teid_t *t)
uint32_t key;
size_t sz;

/* If daemon is currently stopping, we simply skip action on ruleset.
* This reduce daemon exit time and entries are properly released during
* kernel BPF map release. */
if (__test_bit(GTP_FL_STOP_BIT, &daemon_data->flags))
return 0;

if (!t)
return -1;

Expand Down Expand Up @@ -247,6 +241,12 @@ gtp_xdp_fwd_teid_action(int action, gtp_teid_t *t)
{
gtp_bpf_opts_t *bpf_opts = &daemon_data->xdp_gtpu;

/* If daemon is currently stopping, we simply skip action on ruleset.
* This reduce daemon exit time and entries are properly released during
* kernel BPF map release. */
if (__test_bit(GTP_FL_STOP_BIT, &daemon_data->flags))
return 0;

if (!__test_bit(GTP_FL_GTPU_LOADED_BIT, &daemon_data->flags))
return -1;

Expand Down Expand Up @@ -287,6 +287,12 @@ gtp_xdp_fwd_iptnl_action(int action, gtp_iptnl_t *t)
{
gtp_bpf_opts_t *bpf_opts = &daemon_data->xdp_gtpu;

/* If daemon is currently stopping, we simply skip action on ruleset.
* This reduce daemon exit time and entries are properly released during
* kernel BPF map release. */
if (__test_bit(GTP_FL_STOP_BIT, &daemon_data->flags))
return 0;

if (!__test_bit(GTP_FL_GTPU_LOADED_BIT, &daemon_data->flags))
return -1;

Expand Down
25 changes: 16 additions & 9 deletions src/gtp_xdp_ppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,6 @@ gtp_xdp_ppp_map_action(struct bpf_map *map, int action, gtp_teid_t *t)
struct ppp_key ppp_k;
size_t sz;

/* If daemon is currently stopping, we simply skip action on ruleset.
* This reduce daemon exit time and entries are properly released during
* kernel BPF map release. */
if (__test_bit(GTP_FL_STOP_BIT, &daemon_data->flags))
return 0;

if (__test_bit(GTP_TEID_FL_EGRESS, &t->flags))
gtp_xdp_rt_key_set(t, &rt_k);
else
Expand Down Expand Up @@ -249,10 +243,9 @@ gtp_xdp_teid_vty(struct bpf_map *map, vty_t *vty, gtp_teid_t *t)
bytes += r[i].bytes;
}

vty_out(vty, "| 0x%.8x | %.2x:%.2x:%.2x:%.2x:%.2x:%.2x| %9s | %12ld | %19ld |%s"
vty_out(vty, "| 0x%.8x | " ETHER_FMT "| %9s | %12ld | %19ld |%s"
, ntohl(r[0].teid)
, r[0].h_dst[0], r[0].h_dst[1], r[0].h_dst[2]
, r[0].h_dst[3], r[0].h_dst[4], r[0].h_dst[5]
, ETHER_BYTES(r[0].h_dst)
, "ingress"
, packets, bytes
, VTY_NEWLINE);
Expand All @@ -266,6 +259,12 @@ int
gtp_xdp_ppp_action(int action, gtp_teid_t *t,
struct bpf_map *map_ingress, struct bpf_map *map_egress)
{
/* If daemon is currently stopping, we simply skip action on ruleset.
* This reduce daemon exit time and entries are properly released during
* kernel BPF map release. */
if (__test_bit(GTP_FL_STOP_BIT, &daemon_data->flags))
return 0;

if (__test_bit(GTP_TEID_FL_EGRESS, &t->flags))
return gtp_xdp_ppp_map_action(map_egress, action, t);

Expand All @@ -276,6 +275,14 @@ int
gtp_xdp_ppp_teid_vty(vty_t *vty, gtp_teid_t *t,
struct bpf_map *map_ingress, struct bpf_map *map_egress)
{
int err = 0;

if (!t) {
err = (map_ingress) ? gtp_xdp_teid_vty(map_ingress, vty, NULL) : 0;
err = (err) ? : (map_egress) ? gtp_xdp_teid_vty(map_egress, vty, NULL) : 0;
return err;
}

if (__test_bit(GTP_TEID_FL_EGRESS, &t->flags))
return gtp_xdp_teid_vty(map_egress, vty, t);

Expand Down
14 changes: 7 additions & 7 deletions src/gtp_xdp_rt.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,6 @@ gtp_xdp_rt_action(struct bpf_map *map, int action, gtp_teid_t *t)
struct ip_rt_key rt_key;
size_t sz;

/* If daemon is currently stopping, we simply skip action on ruleset.
* This reduce daemon exit time and entries are properly released during
* kernel BPF map release. */
if (__test_bit(GTP_FL_STOP_BIT, &daemon_data->flags))
return 0;

gtp_xdp_rt_key_set(t, &rt_key);

/* Set rule */
Expand Down Expand Up @@ -306,6 +300,12 @@ gtp_xdp_rt_teid_action(int action, gtp_teid_t *t)
gtp_apn_t *apn;
int direction;

/* If daemon is currently stopping, we simply skip action on ruleset.
* This reduce daemon exit time and entries are properly released during
* kernel BPF map release. */
if (__test_bit(GTP_FL_STOP_BIT, &daemon_data->flags))
return 0;

if (!__test_bit(GTP_FL_GTP_ROUTE_LOADED_BIT, &daemon_data->flags) || !t)
return -1;

Expand Down Expand Up @@ -360,7 +360,7 @@ gtp_xdp_rt_vty(vty_t *vty)
, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
gtp_xdp_teid_vty(bpf_opts->bpf_maps[XDP_RT_MAP_TEID_INGRESS].map, vty, NULL);
gtp_xdp_teid_vty(bpf_opts->bpf_maps[XDP_RT_MAP_TEID_EGRESS].map, vty, NULL);
gtp_xdp_teid_vty(bpf_opts->bpf_maps[XDP_RT_MAP_PPP_INGRESS].map, vty, NULL);
gtp_xdp_ppp_teid_vty(vty, NULL, bpf_opts->bpf_maps[XDP_RT_MAP_PPP_INGRESS].map, NULL);
vty_out(vty, "+------------+------------------+-----------+--------------+---------------------+%s"
, VTY_NEWLINE);
return 0;
Expand Down

0 comments on commit f757e87

Please sign in to comment.