Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-2-0]: src/dist/ipf/tools Pull up revision 1.4 (requested by chris...



details:   https://anonhg.NetBSD.org/src/rev/f54fd64751be
branches:  netbsd-2-0
changeset: 561199:f54fd64751be
user:      tron <tron%NetBSD.org@localhost>
date:      Sun May 30 11:22:28 2004 +0000

description:
Pull up revision 1.4 (requested by christos in ticket #416):
PR/25122: Peter Postma: ipfstat state top broken with IPv6 addresses
patch applied.

diffstat:

 dist/ipf/tools/ipfstat.c |  447 ++++++++++++++++++++++++++++++++--------------
 1 files changed, 309 insertions(+), 138 deletions(-)

diffs (truncated from 786 to 300 lines):

diff -r e3db59a87ed6 -r f54fd64751be dist/ipf/tools/ipfstat.c
--- a/dist/ipf/tools/ipfstat.c  Sun May 30 11:22:07 2004 +0000
+++ b/dist/ipf/tools/ipfstat.c  Sun May 30 11:22:28 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ipfstat.c,v 1.1.1.1.2.1 2004/04/07 21:43:30 jmc Exp $  */
+/*     $NetBSD: ipfstat.c,v 1.1.1.1.2.2 2004/05/30 11:22:28 tron Exp $ */
 
 /*
  * Copyright (C) 1993-2001, 2003 by Darren Reed.
@@ -29,7 +29,7 @@
 #include "netinet/ipl.h"
 #if defined(STATETOP)
 # if defined(_BSDI_VERSION)
-#  undef STATETOP)
+#  undef STATETOP
 # endif
 # if defined(__FreeBSD__) && \
      (!defined(__FreeBSD_version) || (__FreeBSD_version < 430000))
@@ -52,6 +52,7 @@
 #endif
 #ifdef STATETOP
 # include <ctype.h>
+# include <signal.h>
 # if SOLARIS || defined(__NetBSD__) || defined(_BSDI_VERSION) || \
      defined(__sgi)
 #  ifdef ERR
@@ -78,6 +79,7 @@
 
 extern char    *optarg;
 extern int     optind;
+extern int     opterr;
 
 #define        PRINTF  (void)printf
 #define        FPRINTF (void)fprintf
@@ -116,6 +118,7 @@
        u_short         st_sport;
        u_short         st_dport;
        u_char          st_p;
+       u_char          st_v;
        u_char          st_state[2];
        U_QUAD_T        st_pkts;
        U_QUAD_T        st_bytes;
@@ -123,22 +126,27 @@
 } statetop_t;
 #endif
 
-extern int     main __P((int, char *[]));
+int            main __P((int, char *[]));
+
 static void    showstats __P((friostat_t *, u_32_t));
 static void    showfrstates __P((ipfrstat_t *));
 static void    showlist __P((friostat_t *));
 static void    showipstates __P((ips_stat_t *));
 static void    showauthstates __P((fr_authstat_t *));
 static void    showgroups __P((friostat_t *));
-static void    Usage __P((char *));
+static void    usage __P((char *));
 static void    printlist __P((frentry_t *, char *));
-static void    parse_ipportstr __P((const char *, struct in_addr *, int *));
+static void    parse_ipportstr __P((const char *, i6addr_t *, int *));
 static void    ipfstate_live __P((char *, friostat_t **, ips_stat_t **,
                                   ipfrstat_t **, fr_authstat_t **, u_32_t *));
 static void    ipfstate_dead __P((char *, friostat_t **, ips_stat_t **,
                                   ipfrstat_t **, fr_authstat_t **, u_32_t *));
 #ifdef STATETOP
-static void    topipstates __P((struct in_addr, struct in_addr, int, int, int, int, int));
+static void    topipstates __P((i6addr_t, i6addr_t, int, int, int,
+                                int, int, int));
+static void    sig_break __P((int));
+static void    sig_resize __P((int));
+static char    *getip __P((int, i6addr_t *));
 static char    *ttl_to_string __P((long));
 static int     sort_p __P((const void *, const void *));
 static int     sort_pkts __P((const void *, const void *));
@@ -149,16 +157,21 @@
 #endif
 
 
-static void Usage(name)
+static void usage(name)
 char *name;
 {
 #ifdef  USE_INET6
-       fprintf(stderr, "Usage: %s [-6aACdfghIilnoRstv] [-d <device>]\n", name);
+       fprintf(stderr, "Usage: %s [-6aAdfghIilnoRsv]\n", name);
 #else
-       fprintf(stderr, "Usage: %s [-aACdfghIilnoRstv] [-d <device>]\n", name);
+       fprintf(stderr, "Usage: %s [-aAdfghIilnoRsv]\n", name);
 #endif
-       fprintf(stderr, "\t\t[-M corefile] [-N symbol-list]\n");
-       fprintf(stderr, "       %s -t [-S source address] [-D destination address] [-P protocol] [-T refreshtime] [-C] [-d <device>]\n", name);
+       fprintf(stderr, "       %s [-M corefile] [-N symbol-list]\n", name);
+#ifdef USE_INET6
+       fprintf(stderr, "       %s -t [-6C] ", name);
+#else
+       fprintf(stderr, "       %s -t [-C] ", name);
+#endif
+       fprintf(stderr, "[-D destination address] [-P protocol] [-S source address] [-T refresh time]\n");
        exit(1);
 }
 
@@ -176,7 +189,7 @@
        ipfrstat_t ifrst;
        ipfrstat_t *ifrstp = &ifrst;
        char    *device = IPL_NAME, *memf = NULL;
-       char    *kern = NULL;
+       char    *options, *kern = NULL;
        int     c, myoptind;
 
        int protocol = -1;              /* -1 = wild card for any protocol */
@@ -184,18 +197,31 @@
        int sport = -1;                 /* -1 = wild card for any source port */
        int dport = -1;                 /* -1 = wild card for any dest port */
        int topclosed = 0;              /* do not show closed tcp sessions */
-       struct in_addr saddr, daddr;
+       i6addr_t saddr, daddr;
        u_32_t frf;
 
-       saddr.s_addr = INADDR_ANY;      /* default any source addr */
-       daddr.s_addr = INADDR_ANY;      /* default any dest addr */
+#ifdef USE_INET6
+       options = "6aACdfghIilnostvD:M:N:P:RS:T:";
+#else
+       options = "aACdfghIilnostvD:M:N:P:RS:T:";
+#endif
+
+       saddr.in4.s_addr = INADDR_ANY;  /* default any v4 source addr */
+       daddr.in4.s_addr = INADDR_ANY;  /* default any v4 dest addr */
+#ifdef USE_INET6
+       saddr.in6 = in6addr_any;        /* default any v6 source addr */
+       daddr.in6 = in6addr_any;        /* default any v6 dest addr */
+#endif
+
+       /* Don't warn about invalid flags when we run getopt for the 1st time */
+       opterr = 0;
 
        /*
         * Parse these two arguments now lest there be any buffer overflows
         * in the parsing of the rest.
         */
        myoptind = optind;
-       while ((c = getopt(argc, argv, "6aACdfghIilnostvD:M:N:P:RS:T:")) != -1)
+       while ((c = getopt(argc, argv, options)) != -1) {
                switch (c)
                {
                case 'M' :
@@ -207,6 +233,7 @@
                        live_kernel = 0;
                        break;
                }
+       }
        optind = myoptind;
 
        if (live_kernel == 1) {
@@ -221,8 +248,7 @@
                }
        }
 
-       if (kern != NULL || memf != NULL)
-       {
+       if (kern != NULL || memf != NULL) {
                (void)setgid(getgid());
                (void)setuid(getuid());
        }
@@ -235,7 +261,9 @@
        (void)setgid(getgid());
        (void)setuid(getuid());
 
-       while ((c = getopt(argc, argv, "6aACdfghIilnostvD:M:N:P:RS:T:")) != -1)
+       opterr = 1;
+
+       while ((c = getopt(argc, argv, options)) != -1)
        {
                switch (c)
                {
@@ -290,7 +318,7 @@
                case 'P' :
                        protocol = getproto(optarg);
                        if (protocol == -1) {
-                               fprintf(stderr, "%s : Invalid protocol: %s\n",
+                               fprintf(stderr, "%s: Invalid protocol: %s\n",
                                        argv[0], optarg);
                                exit(-2);
                        }
@@ -310,7 +338,7 @@
                        break;
 #else
                        fprintf(stderr,
-                               "%s : state top facility not compiled in\n",
+                               "%s: state top facility not compiled in\n",
                                argv[0]);
                        exit(-2);
 #endif
@@ -318,7 +346,7 @@
                        if (!sscanf(optarg, "%d", &refreshtime) ||
                                    (refreshtime <= 0)) {
                                fprintf(stderr,
-                                       "%s : Invalid refreshtime < 1 : %s\n",
+                                       "%s: Invalid refreshtime < 1 : %s\n",
                                        argv[0], optarg);
                                exit(-2);
                        }
@@ -327,7 +355,7 @@
                        opts |= OPT_VERBOSE;
                        break;
                default :
-                       Usage(argv[0]);
+                       usage(argv[0]);
                        break;
                }
        }
@@ -350,21 +378,20 @@
                        opts &= ~OPT_OUTQUE;
                        showlist(fiop);
                }
-       } else {
-               if (opts & OPT_FRSTATES)
-                       showfrstates(ifrstp);
+       } else if (opts & OPT_FRSTATES)
+               showfrstates(ifrstp);
 #ifdef STATETOP
-               else if (opts & OPT_STATETOP)
-                       topipstates(saddr, daddr, sport, dport,
-                                   protocol, refreshtime, topclosed);
+       else if (opts & OPT_STATETOP)
+               topipstates(saddr, daddr, sport, dport, protocol,
+                           use_inet6 ? 6 : 4, refreshtime, topclosed);
 #endif
-               else if (opts & OPT_AUTHSTATS)
-                       showauthstates(frauthstp);
-               else if (opts & OPT_GROUPS)
-                       showgroups(fiop);
-               else
-                       showstats(fiop, frf);
-       }
+       else if (opts & OPT_AUTHSTATS)
+               showauthstates(frauthstp);
+       else if (opts & OPT_GROUPS)
+               showgroups(fiop);
+       else
+               showstats(fiop, frf);
+
        return 0;
 }
 
@@ -962,19 +989,23 @@
 
 
 #ifdef STATETOP
-static void topipstates(saddr, daddr, sport, dport, protocol,
+static int handle_resize = 0, handle_break = 0;
+
+static void topipstates(saddr, daddr, sport, dport, protocol, ver,
                        refreshtime, topclosed)
-struct in_addr saddr;
-struct in_addr daddr;
+i6addr_t saddr;
+i6addr_t daddr;
 int sport;
 int dport;
 int protocol;
+int ver;
 int refreshtime;
 int topclosed;
 {
        char str1[STSTRSIZE], str2[STSTRSIZE], str3[STSTRSIZE], str4[STSTRSIZE];
        int maxtsentries = 0, reverse = 0, sorting = STSORT_DEFAULT;
-       int i, j, winx, tsentry, maxx, maxy, redraw = 0;
+       int i, j, winy, tsentry, maxx, maxy, redraw = 0;
+       int len, srclen, dstlen, forward = 1, c = 0;
        ips_stat_t ipsst, *ipsstp = &ipsst;
        statetop_t *tstable = NULL, *tp;
        ipstate_t ips;
@@ -983,18 +1014,26 @@
        char hostnm[HOSTNMLEN];
        struct protoent *proto;
        fd_set readfd;
-       int c = 0;
        time_t t;
 
+       /* install signal handlers */
+       signal(SIGINT, sig_break);
+       signal(SIGQUIT, sig_break);
+       signal(SIGTERM, sig_break);
+       signal(SIGWINCH, sig_resize);
+
        /* init ncurses stuff */
        initscr();
        cbreak();
        noecho();
+       curs_set(0);
+       timeout(0);
+       getmaxyx(stdscr, maxy, maxx);
 
        /* init hostname */
        gethostname(hostnm, sizeof(hostnm) - 1);
        hostnm[sizeof(hostnm) - 1] = '\0';
-       
+
        /* init ipfobj_t stuff */



Home | Main Index | Thread Index | Old Index