Skip to content

Commit

Permalink
vrf: VTY display
Browse files Browse the repository at this point in the history
VTY interface via 'show ip vrf'

gtp-guard> sh ip vrf
vrf(1): vrf-name-1 (VRF-Description-here)
 PPPoE: interface br-lab (ifindex:16) sessions:0
  Discovery channel:
   #00: rx_packets:0 rx_bytes:0 tx_packets:0 tx_bytes:0
   #1: rx_packets:0 rx_bytes:0 tx_packets:0 tx_bytes:0
   #2: rx_packets:0 rx_bytes:0 tx_packets:0 tx_bytes:0
   #3: rx_packets:0 rx_bytes:0 tx_packets:0 tx_bytes:0
   #4: rx_packets:0 rx_bytes:0 tx_packets:0 tx_bytes:0
   #5: rx_packets:0 rx_bytes:0 tx_packets:0 tx_bytes:0
   #6: rx_packets:0 rx_bytes:0 tx_packets:0 tx_bytes:0
   #7: rx_packets:0 rx_bytes:0 tx_packets:0 tx_bytes:0
  Session channel:
   #00: rx_packets:0 rx_bytes:0 tx_packets:0 tx_bytes:0
   #1: rx_packets:0 rx_bytes:0 tx_packets:0 tx_bytes:0
   #2: rx_packets:0 rx_bytes:0 tx_packets:0 tx_bytes:0
   #3: rx_packets:0 rx_bytes:0 tx_packets:0 tx_bytes:0
   #4: rx_packets:0 rx_bytes:0 tx_packets:0 tx_bytes:0
   #5: rx_packets:0 rx_bytes:0 tx_packets:0 tx_bytes:0
   #6: rx_packets:0 rx_bytes:0 tx_packets:0 tx_bytes:0
   #7: rx_packets:0 rx_bytes:0 tx_packets:0 tx_bytes:0
  • Loading branch information
acassen committed Mar 18, 2024
1 parent 9c0642d commit 6ceed0c
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/gtp_pppoe.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,48 @@ gtp_pppoe_timer_destroy(gtp_pppoe_t *pppoe)
return 0;
}


/*
* VTY display
*/
static int
gtp_pppoe_worker_vty(vty_t *vty, gtp_pppoe_worker_t *w)
{
vty_out(vty, " #%.2d: rx_packets:%ld rx_bytes:%ld tx_packets:%ld tx_bytes:%ld%s"
, w->id, w->rx_packets, w->rx_bytes, w->tx_packets, w->tx_bytes
, VTY_NEWLINE);
return 0;
}

static int
gtp_pppoe_workers_vty(vty_t *vty, const char *desc, gtp_pppoe_worker_t *w, int count)
{
int i;

vty_out(vty, " %s:%s", desc, VTY_NEWLINE);
for (i = 0; i < count; i++)
gtp_pppoe_worker_vty(vty, &w[i]);

return 0;
}

int
gtp_pppoe_vty(vty_t *vty, gtp_pppoe_t *pppoe)
{
if (!pppoe)
return -1;

vty_out(vty, " PPPoE: interface %s (ifindex:%d) sessions:%d%s"
, pppoe->ifname, pppoe->ifindex, pppoe->session_count
, VTY_NEWLINE);
gtp_pppoe_workers_vty(vty, "Discovery channel:"
, pppoe->worker_disc, pppoe->thread_cnt);
gtp_pppoe_workers_vty(vty, "Session channel:"
, pppoe->worker_ses, pppoe->thread_cnt);
return 0;
}


/*
* PPPoE service init
*/
Expand Down
6 changes: 6 additions & 0 deletions src/gtp_pppoe_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,19 +269,25 @@ spppoe_generate_id(gtp_conn_t *c)
static int
spppoe_add(gtp_conn_t *c, spppoe_t *s)
{
gtp_pppoe_t *pppoe = s->pppoe;

pthread_mutex_lock(&c->session_mutex);
list_add_tail(&s->next, &c->pppoe_sessions);
__sync_add_and_fetch(&c->pppoe_cnt, 1);
pthread_mutex_unlock(&c->session_mutex);

__sync_add_and_fetch(&pppoe->session_count, 1);
return 0;
}

static int
__spppoe_del(gtp_conn_t *c, spppoe_t *s)
{
gtp_pppoe_t *pppoe = s->pppoe;

list_head_del(&s->next);
__sync_sub_and_fetch(&c->pppoe_cnt, 1);
__sync_sub_and_fetch(&pppoe->session_count, 1);
return 0;
}

Expand Down
38 changes: 38 additions & 0 deletions src/gtp_vrf_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,39 @@ DEFUN(ip_vrf_pppoe_lcp_max_failure,
return CMD_SUCCESS;
}

/*
* Show commands
*/
DEFUN(show_ip_vrf,
show_ip_vrf_cmd,
"show ip vrf [STRING]",
SHOW_STR
"IP VRF\n"
"VRF")
{
ip_vrf_t *vrf;
const char *vrf_name = NULL;

if (list_empty(&daemon_data->ip_vrf)) {
vty_out(vty, "%% No VRF configured...");
return CMD_SUCCESS;
}

if (argc == 1)
vrf_name = argv[0];

list_for_each_entry(vrf, &daemon_data->ip_vrf, next) {
if (vrf_name && strncmp(vrf->name, vrf_name, GTP_NAME_MAX_LEN))
continue;

vty_out(vty, "vrf(%d): %s (%s)%s"
, vrf->id, vrf->name, vrf->description, VTY_NEWLINE);
gtp_pppoe_vty(vty, vrf->pppoe);
}

return CMD_SUCCESS;
}


/* Configuration writer */
static int
Expand Down Expand Up @@ -770,5 +803,10 @@ gtp_vrf_vty_init(void)
install_element(IP_VRF_NODE, &ip_vrf_pppoe_lcp_max_configure_cmd);
install_element(IP_VRF_NODE, &ip_vrf_pppoe_lcp_max_failure_cmd);

/* Install show commands. */
install_element(VIEW_NODE, &show_ip_vrf_cmd);
install_element(ENABLE_NODE, &show_ip_vrf_cmd);


return 0;
}
2 changes: 2 additions & 0 deletions src/include/gtp_pppoe.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ typedef struct _gtp_pppoe {

gtp_htab_t session_tab; /* Session Tracking by sesion-id */
gtp_htab_t unique_tab; /* Session Tracking by unique */
int session_count; /* Number of session tracked */
timer_thread_t session_timer; /* Sesion timer */
timer_thread_t ppp_timer; /* PPP sesion timer */

Expand All @@ -178,6 +179,7 @@ typedef struct _gtp_pppoe {
extern int gtp_pppoe_disc_send(gtp_pppoe_t *, pkt_t *);
extern int gtp_pppoe_ses_send(gtp_pppoe_t *, pkt_t *);
extern int gtp_pppoe_put(gtp_pppoe_t *);
extern int gtp_pppoe_vty(vty_t *, gtp_pppoe_t *);
extern int gtp_pppoe_start(gtp_pppoe_t *);
extern int gtp_pppoe_release(gtp_pppoe_t *);
extern gtp_pppoe_t *gtp_pppoe_init(const char *);
Expand Down

0 comments on commit 6ceed0c

Please sign in to comment.