X-Git-Url: http://git.sameswireless.fr/l2tpns.git/blobdiff_plain/d19fdcba627f175fe92c9f9642eb4da7997fc54f..b5273cc1c65f9496c1a7c2135b61979dd98fcf08:/cli.c?ds=sidebyside diff --git a/cli.c b/cli.c index 32c82a9..65afb43 100644 --- a/cli.c +++ b/cli.c @@ -1,9 +1,6 @@ // L2TPNS Command Line Interface // vim: sw=8 ts=8 -char const *cvs_name = "$Name: $"; -char const *cvs_id_cli = "$Id: cli.c,v 1.76 2006/12/18 12:08:28 bodea Exp $"; - #include #include #include @@ -24,6 +21,7 @@ char const *cvs_id_cli = "$Id: cli.c,v 1.76 2006/12/18 12:08:28 bodea Exp $"; #include #include #include +#include #include "l2tpns.h" #include "constants.h" @@ -34,6 +32,9 @@ char const *cvs_id_cli = "$Id: cli.c,v 1.76 2006/12/18 12:08:28 bodea Exp $"; #ifdef BGP #include "bgp.h" #endif +#ifdef LAC +#include "l2tplac.h" +#endif extern tunnelt *tunnel; extern bundlet *bundle; @@ -102,7 +103,10 @@ static int cmd_remove_plugin(struct cli_def *cli, char *command, char **argv, in static int cmd_uptime(struct cli_def *cli, char *command, char **argv, int argc); static int cmd_shutdown(struct cli_def *cli, char *command, char **argv, int argc); static int cmd_reload(struct cli_def *cli, char *command, char **argv, int argc); - +#ifdef LAC +static int cmd_setforward(struct cli_def *cli, char *command, char **argv, int argc); +static int cmd_show_rmtlnsconf(struct cli_def *cli, char *command, char **argv, int argc); +#endif static int regular_stuff(struct cli_def *cli); @@ -139,8 +143,6 @@ void init_cli() char buf[4096]; struct cli_command *c; struct cli_command *c2; - int on = 1; - struct sockaddr_in addr; cli = cli_init(); @@ -155,6 +157,9 @@ void init_cli() cli_register_command(cli, c, "pool", cmd_show_pool, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show the IP address allocation pool"); cli_register_command(cli, c, "radius", cmd_show_radius, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show active radius queries"); cli_register_command(cli, c, "running-config", cmd_show_run, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Show the currently running configuration"); +#ifdef LAC + cli_register_command(cli, c, "remotelns-conf", cmd_show_rmtlnsconf, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Show a list of remote LNS configuration"); +#endif cli_register_command(cli, c, "session", cmd_show_session, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show a list of sessions or details for a single session"); cli_register_command(cli, c, "tbf", cmd_show_tbf, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "List all token bucket filters in use"); cli_register_command(cli, c, "throttle", cmd_show_throttle, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "List all throttled sessions and associated TBFs"); @@ -227,6 +232,10 @@ void init_cli() cli_register_command(cli, NULL, "set", cmd_set, PRIVILEGE_PRIVILEGED, MODE_CONFIG, "Set a configuration variable"); +#ifdef LAC + cli_register_command(cli, NULL, "setforward", cmd_setforward, PRIVILEGE_PRIVILEGED, MODE_CONFIG, "Set the Remote LNS Forward"); +#endif + c = cli_register_command(cli, NULL, "ip", NULL, PRIVILEGE_PRIVILEGED, MODE_CONFIG, NULL); cli_register_command(cli, c, "access-list", cmd_ip_access_list, PRIVILEGE_PRIVILEGED, MODE_CONFIG, "Add named access-list"); @@ -268,6 +277,17 @@ void init_cli() } fclose(f); } +} + +void cli_init_complete(char *hostname) +{ + int on = 1; + struct sockaddr_in addr; + + if (hostname && *hostname) + cli_set_hostname(cli, hostname); + else + cli_set_hostname(cli, "l2tpns"); memset(&addr, 0, sizeof(addr)); clifd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); @@ -297,14 +317,6 @@ void init_cli() } } -void cli_init_hostname(char *hostname) -{ - if (hostname && *hostname) - cli_set_hostname(cli, hostname); - else - cli_set_hostname(cli, "l2tpns"); -} - void cli_do(int sockfd) { int require_auth = 1; @@ -531,8 +543,15 @@ static int cmd_show_session(struct cli_def *cli, char *command, char **argv, int } // Show Summary +#ifdef LAC + cli_print(cli, "%5s %7s %4s %-32s %-15s %s %s %s %s %10s %10s %10s %4s %10s %-18s %s", +#else cli_print(cli, "%5s %4s %-32s %-15s %s %s %s %s %10s %10s %10s %4s %10s %-15s %s", +#endif "SID", +#ifdef LAC + "LkToSID", +#endif "TID", "Username", "IP", @@ -545,7 +564,11 @@ static int cmd_show_session(struct cli_def *cli, char *command, char **argv, int "uploaded", "idle", "Rem.Time", - "LAC", +#ifdef LAC + "LAC(L)/RLNS(R)/PPPOE(P)", +#else + "LAC(L)/PPPOE(P)", +#endif "CLI"); for (i = 1; i < MAXSESSION; i++) @@ -556,9 +579,15 @@ static int cmd_show_session(struct cli_def *cli, char *command, char **argv, int rem_time = session[i].timeout ? (session[i].timeout - bundle[session[i].bundle].online_time) : 0; else rem_time = session[i].timeout ? (session[i].timeout - (time_now-session[i].opened)) : 0; - - cli_print(cli, "%5d %4d %-32s %-15s %s %s %s %s %10u %10lu %10lu %4u %10lu %-15s %s", +#ifdef LAC + cli_print(cli, "%5d %7d %4d %-32s %-15s %s %s %s %s %10u %10lu %10lu %4u %10lu %3s%-20s %s", +#else + cli_print(cli, "%5d %4d %-32s %-15s %s %s %s %s %10u %10lu %10lu %4u %10lu %3s%-20s %s", +#endif i, +#ifdef LAC + session[i].forwardtosession, +#endif session[i].tunnel, session[i].user[0] ? session[i].user : "*", fmtaddr(htonl(session[i].ip), 0), @@ -571,7 +600,12 @@ static int cmd_show_session(struct cli_def *cli, char *command, char **argv, int (unsigned long)session[i].cin, abs(time_now - (session[i].last_packet ? session[i].last_packet : time_now)), (unsigned long)(rem_time), - fmtaddr(htonl(tunnel[ session[i].tunnel ].ip), 1), +#ifdef LAC + (session[i].tunnel == TUNNEL_ID_PPPOE)?"(P)":(tunnel[session[i].tunnel].isremotelns?"(R)":"(L)"), +#else + (session[i].tunnel == TUNNEL_ID_PPPOE)?"(P)":"(L)", +#endif + (session[i].tunnel == TUNNEL_ID_PPPOE)?fmtMacAddr(session[i].src_hwaddr):fmtaddr(htonl(tunnel[session[i].tunnel].ip), 1), session[i].calling[0] ? session[i].calling : "*"); } return CLI_OK; @@ -655,12 +689,18 @@ static int cmd_show_tunnels(struct cli_def *cli, char *command, char **argv, int if (!show_all && (!tunnel[i].ip || tunnel[i].die)) continue; for (x = 0; x < MAXSESSION; x++) if (session[x].tunnel == i && session[x].opened && !session[x].die) sessions++; - cli_print(cli, "%4d %20s %20s %6s %6d", + cli_print(cli, "%4d %20s %20s %6s %6d %s", i, *tunnel[i].hostname ? tunnel[i].hostname : "(null)", fmtaddr(htonl(tunnel[i].ip), 0), states[tunnel[i].state], - sessions); + sessions +#ifdef LAC + ,(i == TUNNEL_ID_PPPOE)?"Tunnel pppoe":(tunnel[i].isremotelns?"Tunnel To Remote LNS":"Tunnel To LAC") +#else + ,(i == TUNNEL_ID_PPPOE)?"Tunnel pppoe":"Tunnel To LAC" +#endif + ); } return CLI_OK; @@ -823,72 +863,10 @@ static int cmd_clear_counters(struct cli_def *cli, char *command, char **argv, i static int cmd_show_version(struct cli_def *cli, char *command, char **argv, int argc) { - int tag = 0; - int file = 0; - int i = 0; - if (CLI_HELP_REQUESTED) - return cli_arg_help(cli, 1, - "tag", "Include CVS release tag", - "file", "Include file versions", - NULL); - - for (i = 0; i < argc; i++) - if (!strcmp(argv[i], "tag")) - tag++; - else if (!strcmp(argv[i], "file")) - file++; + return CLI_HELP_NO_ARGS; cli_print(cli, "L2TPNS %s", VERSION); - if (tag) - { - char const *p = strchr(cvs_name, ':'); - char const *e; - if (p) - { - p++; - while (isspace(*p)) - p++; - } - - if (!p || *p == '$') - p = "HEAD"; - - e = strpbrk(p, " \t$"); - cli_print(cli, "Tag: %.*s", (int) (e ? e - p + 1 : strlen(p)), p); - } - - if (file) - { - extern linked_list *loaded_plugins; - void *p; - - cli_print(cli, "Files:"); - cli_print(cli, " %s", cvs_id_arp); -#ifdef BGP - cli_print(cli, " %s", cvs_id_bgp); -#endif /* BGP */ - cli_print(cli, " %s", cvs_id_cli); - cli_print(cli, " %s", cvs_id_cluster); - cli_print(cli, " %s", cvs_id_constants); - cli_print(cli, " %s", cvs_id_control); - cli_print(cli, " %s", cvs_id_icmp); - cli_print(cli, " %s", cvs_id_l2tpns); - cli_print(cli, " %s", cvs_id_ll); - cli_print(cli, " %s", cvs_id_ppp); - cli_print(cli, " %s", cvs_id_radius); - cli_print(cli, " %s", cvs_id_tbf); - cli_print(cli, " %s", cvs_id_util); - - ll_reset(loaded_plugins); - while ((p = ll_next(loaded_plugins))) - { - char const **id = dlsym(p, "cvs_id"); - if (id) - cli_print(cli, " %s", *id); - } - } - return CLI_OK; } @@ -1332,6 +1310,13 @@ static int cmd_drop_session(struct cli_def *cli, char *command, char **argv, int cli_print(cli, "Dropping session %d", s); cli_session_actions[s].action |= CLI_SESS_KILL; } +#ifdef LAC + else if (session[s].forwardtosession && session[s].opened && !session[s].die) + { + cli_print(cli, "Dropping session %d", s); + cli_session_actions[s].action |= CLI_SESS_KILL; + } +#endif else { cli_error(cli, "Session %d is not active.", s); @@ -3159,3 +3144,77 @@ static int cmd_reload(struct cli_def *cli, char *command, char **argv, int argc) kill(getppid(), SIGHUP); return CLI_OK; } + +#ifdef LAC + +static int cmd_setforward(struct cli_def *cli, char *command, char **argv, int argc) +{ + int ret; + + if (CLI_HELP_REQUESTED) + { + switch (argc) + { + case 1: + return cli_arg_help(cli, 0, + "MASK", "Users mask to forward (ex: myISP@operator.com)", NULL); + + case 2: + return cli_arg_help(cli, 0, + "IP", "IP of the remote LNS(ex: 64.64.64.64)", NULL); + + case 3: + return cli_arg_help(cli, 0, + "PORT", "Port of the remote LNS (ex: 1701)", NULL); + + case 4: + return cli_arg_help(cli, 0, + "SECRET", "l2tp secret of the remote LNS (ex: mysecretpsw)", NULL); + + default: + return cli_arg_help(cli, argc > 1, NULL); + } + } + + if (argc != 4) + { + cli_error(cli, "Specify variable and value"); + return CLI_OK; + } + + // lac_addremotelns(mask, IP_RemoteLNS, Port_RemoteLNS, SecretRemoteLNS) + ret = lac_addremotelns(argv[0], argv[1], argv[2], argv[3]); + + if (ret) + { + cli_print(cli, "setforward %s %s %s %s", argv[0], argv[1], argv[2], argv[3]); + if (ret == 2) + cli_print(cli, "%s Updated, the tunnel must be dropped", argv[0]); + } + else + cli_error(cli, "ERROR setforward %s %s %s %s", argv[0], argv[1], argv[2], argv[3]); + + return CLI_OK; +} + +static int cmd_show_rmtlnsconf(struct cli_def *cli, char *command, char **argv, int argc) +{ + confrlnsidt idrlns; + char strdisp[1024]; + + if (CLI_HELP_REQUESTED) + { + return cli_arg_help(cli, 0, "remotelns-conf", "Show a list of remote LNS configurations", NULL); + } + + for (idrlns = 0; idrlns < MAXRLNSTUNNEL; idrlns++) + { + if (lac_cli_show_remotelns(idrlns, strdisp) != 0) + cli_print(cli, "%s", strdisp); + else + break; + } + + return CLI_OK; +} +#endif