From 0ac498d7d37fa27032021b193ab0a9d7ae17f227 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Thu, 18 Jan 2024 02:00:21 +0100 Subject: [PATCH] cli: Show acceleration interface name And allow selecting a session through it --- cli.c | 17 ++++++++++++++++- l2tpns.c | 6 ++++-- l2tpns.h | 6 +++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/cli.c b/cli.c index b0049ac..e3cea88 100644 --- a/cli.c +++ b/cli.c @@ -451,10 +451,23 @@ static int cmd_show_session(struct cli_def *cli, const char *command, char **arg for (i = 0; i < argc; i++) { unsigned int s, b_in, b_out, r; + int ifunit = -1; + + if (!strncmp(argv[i], PPP_IF_PREFIX, strlen(PPP_IF_PREFIX))) + { + char *start = argv[i]+strlen(PPP_IF_PREFIX); + char *end; + long res = strtol(start, &end, 10); + if (end != start && !*end) + ifunit = res; + } for (s = 0; s < MAXSESSION; s++) - if (!strcmp(argv[i], session[s].user)) + { + if ((ifunit >= 0 && sess_local[s].ppp_if_unit == ifunit) + || !strcmp(argv[i], session[s].user)) break; + } if (s >= MAXSESSION) { s = atoi(argv[i]); @@ -473,6 +486,8 @@ static int cmd_show_session(struct cli_def *cli, const char *command, char **arg cli_print(cli, "\tRemote ID:\t%d", session[s].far); if (session[s].bundle) cli_print(cli, "\tBundle ID:\t%d (%d)", session[s].bundle, bundle[session[s].bundle].num_of_links); + if (sess_local[s].ppp_if_unit >= 0) + cli_print(cli, "\tInterface:\tppp%d", sess_local[s].ppp_if_unit); cli_print(cli, "\tPPP Phase:\t%s", ppp_phase(session[s].ppp.phase)); switch (session[s].ppp.phase) { diff --git a/l2tpns.c b/l2tpns.c index 34afaf7..378e6fe 100644 --- a/l2tpns.c +++ b/l2tpns.c @@ -49,8 +49,6 @@ #define PPPIOCUNBRIDGECHAN _IO('t', 54) #endif -#define PPP_IF_PREFIX "ppp" - #include "md5.h" #include "dhcp6.h" #include "l2tpns.h" @@ -1228,6 +1226,7 @@ static int create_kernel_accel(sessionidt s) sess_local[s].pppox_fd = pppox_fd; sess_local[s].ppp_chan_fd = ppp_chan_fd; sess_local[s].ppp_if_fd = ppp_if_fd; + sess_local[s].ppp_if_unit = ifunit; sess_local[s].ppp_if_idx = ifr.ifr_ifindex; dhcpv6_listen(ifr.ifr_ifindex); @@ -1256,6 +1255,7 @@ static int delete_kernel_accel(sessionidt s) LOG(3, s, session[s].tunnel, "Stopping kernel-accelerated support for %u:%u\n", session[s].tunnel, s); + sess_local[s].ppp_if_unit = -1; sess_local[s].ppp_if_idx = 0; ioctl(sess_local[s].ppp_chan_fd, PPPIOCDISCONN); @@ -3666,6 +3666,7 @@ static void sessionclear(sessionidt s) sess_local[s].pppox_fd = -1; sess_local[s].ppp_chan_fd = -1; sess_local[s].ppp_if_fd = -1; + sess_local[s].ppp_if_unit = -1; memset(&cli_session_actions[s], 0, sizeof(cli_session_actions[s])); session[s].tunnel = T_FREE; // Mark it as free. @@ -6229,6 +6230,7 @@ static void initdata(int optdebug, char *optconfig) sess_local[i].pppox_fd = -1; sess_local[i].ppp_chan_fd = -1; sess_local[i].ppp_if_fd = -1; + sess_local[i].ppp_if_unit = -1; } session[MAXSESSION - 1].next = 0; sessionfree = 1; diff --git a/l2tpns.h b/l2tpns.h index 8b5468f..33e9f9a 100644 --- a/l2tpns.h +++ b/l2tpns.h @@ -31,6 +31,8 @@ // Tunnel Id reserved for pppoe #define TUNNEL_ID_PPPOE 1 +#define PPP_IF_PREFIX "ppp" + #define RADIUS_SHIFT 6 #define RADIUS_FDS (1 << RADIUS_SHIFT) #define RADIUS_MASK ((1 << RADIUS_SHIFT) - 1) @@ -459,7 +461,9 @@ typedef struct // ppp interface int ppp_if_fd; - // ppp interface index + // ppp interface number (ppp%d) + int ppp_if_unit; + // ppp interface index (for rtnetlink etc.) int ppp_if_idx; } sessionlocalt;