use standard uintN_t types for portability
[l2tpns.git] / cli.c
diff --git a/cli.c b/cli.c
index 190372e..a02f645 100644 (file)
--- a/cli.c
+++ b/cli.c
@@ -2,7 +2,7 @@
 // vim: sw=8 ts=8
 
 char const *cvs_name = "$Name:  $";
-char const *cvs_id_cli = "$Id: cli.c,v 1.34 2004/11/29 02:17:17 bodea Exp $";
+char const *cvs_id_cli = "$Id: cli.c,v 1.41 2004/12/16 08:49:52 bodea Exp $";
 
 #include <stdio.h>
 #include <stdarg.h>
@@ -22,6 +22,7 @@ char const *cvs_id_cli = "$Id: cli.c,v 1.34 2004/11/29 02:17:17 bodea Exp $";
 #include <unistd.h>
 #include <dlfcn.h>
 #include <libcli.h>
+#include <netdb.h>
 #include "l2tpns.h"
 #include "util.h"
 #include "cluster.h"
@@ -29,7 +30,6 @@ char const *cvs_id_cli = "$Id: cli.c,v 1.34 2004/11/29 02:17:17 bodea Exp $";
 #include "ll.h"
 #ifdef BGP
 #include "bgp.h"
-#include <netdb.h>
 #endif
 
 extern tunnelt *tunnel;
@@ -1003,7 +1003,7 @@ static int cmd_show_radius(struct cli_def *cli, char *command, char **argv, int
                        NULL);
        }
 
-       cli_print(cli, "%6s%6s%5s%6s%9s%9s%4s", "ID", "Radius", "Sock", "State", "Session", "Retry", "Try");
+       cli_print(cli, "%6s%7s%5s%6s%9s%9s%4s", "ID", "Radius", "Sock", "State", "Session", "Retry", "Try");
 
        time(&time_now);
 
@@ -1019,7 +1019,7 @@ static int cmd_show_radius(struct cli_def *cli, char *command, char **argv, int
 
                if (!show_all && radius[i].state == RADIUSNULL) continue;
 
-               cli_print(cli, "%6d%6d%5d%6s%9d%9u%4d",
+               cli_print(cli, "%6d%7d%5d%6s%9d%9u%4d",
                                i,
                                i >> RADIUS_SHIFT,
                                i & RADIUS_MASK,
@@ -1252,8 +1252,8 @@ static int cmd_drop_session(struct cli_def *cli, char *command, char **argv, int
 
 static int cmd_snoop(struct cli_def *cli, char *command, char **argv, int argc)
 {
-       ipt ip;
-       u16 port;
+       in_addr_t ip;
+       uint16_t port;
        sessionidt s;
 
        if (CLI_HELP_REQUESTED)
@@ -1861,42 +1861,44 @@ static int cmd_set(struct cli_def *cli, char *command, char **argv, int argc)
 
 int regular_stuff(struct cli_def *cli)
 {
-       int i = debug_rb_tail;
-       int reprompt = 0;
+       int out = 0;
+       int i;
 
 #ifdef RINGBUFFER
-       while (i != ringbuffer->tail)
+       for (i = debug_rb_tail; i != ringbuffer->tail; i = (i + 1) % RINGBUFFER_SIZE)
        {
-               int show_message = 0;
+               char *m = ringbuffer->buffer[i].message;
+               char *p;
+               int show = 0;
+
+               if (!*m) continue;
 
-               if (*ringbuffer->buffer[i].message)
+               switch (ringbuffer->buffer[i].level)
                {
-                       // Always show messages if we are doing general debug
-                       if (ringbuffer->buffer[i].level == 0 && debug_flags.critical) show_message = 1;
-                       if (ringbuffer->buffer[i].level == 1 && debug_flags.error)    show_message = 1;
-                       if (ringbuffer->buffer[i].level == 2 && debug_flags.warning)  show_message = 1;
-                       if (ringbuffer->buffer[i].level == 3 && debug_flags.info)     show_message = 1;
-                       if (ringbuffer->buffer[i].level == 4 && debug_flags.calls)    show_message = 1;
-                       if (ringbuffer->buffer[i].level == 5 && debug_flags.data)     show_message = 1;
+               case 0: show = debug_flags.critical;    break;
+               case 1: show = debug_flags.error;       break;
+               case 2: show = debug_flags.warning;     break;
+               case 3: show = debug_flags.info;        break;
+               case 4: show = debug_flags.calls;       break;
+               case 5: show = debug_flags.data;        break;
                }
 
-               if (show_message)
-               {
-                       cli_print(cli, "\r%s-%u-%u %s",
-                                       debug_levels[(int)ringbuffer->buffer[i].level],
-                                       ringbuffer->buffer[i].tunnel,
-                                       ringbuffer->buffer[i].session,
-                                       ringbuffer->buffer[i].message);
+               if (!show) continue;
 
-                       reprompt = 1;
-               }
+               if (!(p = strchr(m, '\n')))
+                       p = m + strlen(p);
+
+               cli_print(cli, "\r%s-%u-%u %.*s",
+                       debug_levels[(int)ringbuffer->buffer[i].level],
+                       ringbuffer->buffer[i].tunnel,
+                       ringbuffer->buffer[i].session,
+                       p - m, m);
 
-               if (++i == ringbuffer->tail) break;
-               if (i == RINGBUFFER_SIZE) i = 0;
+               out++;
        }
 
        debug_rb_tail = ringbuffer->tail;
-       if (reprompt)
+       if (out)
                cli_reprompt(cli);
 #endif
        return CLI_OK;
@@ -2391,7 +2393,7 @@ static int cmd_no_ip_access_list(struct cli_def *cli, char *command, char **argv
        return access_list(cli, argv, argc, 0);
 }
 
-static int show_ip_wild(char *buf, ipt ip, ipt wild)
+static int show_ip_wild(char *buf, in_addr_t ip, in_addr_t wild)
 {
        if (ip == INADDR_ANY && wild == INADDR_BROADCAST)
                return sprintf(buf, " any");
@@ -2522,8 +2524,8 @@ ip_filter_rulet *access_list_rule_ext(struct cli_def *cli, char *command, char *
 
        for (a = 1, i = 0; i < 2; i++)
        {
-               ipt *ip;
-               ipt *wild;
+               in_addr_t *ip;
+               in_addr_t *wild;
                ip_filter_portt *port;
 
                if (i == 0)
@@ -2665,7 +2667,7 @@ ip_filter_rulet *access_list_rule_ext(struct cli_def *cli, char *command, char *
 
                        while (a < argc && (argv[a][0] == '+' || argv[a][0] == '-'))
                        {
-                               u8 *f;
+                               uint8_t *f;
 
                                f = (argv[a][0] == '+') ? &rule.tcp_sflags : &rule.tcp_cflags;
 
@@ -2688,6 +2690,12 @@ ip_filter_rulet *access_list_rule_ext(struct cli_def *cli, char *command, char *
 
        if (a < argc && MATCH("fragments", argv[a]))
        {
+               if (rule.src_ports.op || rule.dst_ports.op || rule.tcp_flag_op)
+               {
+                       cli_print(cli, "Can't specify \"fragments\" on rules with layer 4 matches");
+                       return NULL;
+               }
+
                rule.frag = 1;
                a++;
        }
@@ -3008,6 +3016,9 @@ static int cmd_show_access_list(struct cli_def *cli, char *command, char **argv,
                        return CLI_OK;
                }
 
+               if (i)
+                       cli_print(cli, "");
+
                cli_print(cli, "%s IP access list %s",
                        ip_filters[f].extended ? "Extended" : "Standard",
                        ip_filters[f].name);