Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/systat don't choke on non-INET6 kernel, or non-IPSEC...



details:   https://anonhg.NetBSD.org/src/rev/4b986749c9e5
branches:  trunk
changeset: 480393:4b986749c9e5
user:      itojun <itojun%NetBSD.org@localhost>
date:      Mon Jan 10 21:06:15 2000 +0000

description:
don't choke on non-INET6 kernel, or non-IPSEC kernel.
cleanup error handling on mode change failure.

TODO: non-IPv4 kernel support should be improved.  "netstat" should be okay,
"inet.ip" and "inet.icmp" needs more trick.

NetBSD PR: 9157

diffstat:

 usr.bin/systat/cmds.c    |   23 +++++-
 usr.bin/systat/ip6.c     |   11 +-
 usr.bin/systat/ipsec.c   |  156 +++++++++++++++++++++++++---------------------
 usr.bin/systat/netstat.c |  105 +++++++++++++++---------------
 4 files changed, 159 insertions(+), 136 deletions(-)

diffs (truncated from 492 to 300 lines):

diff -r 27983dd0e804 -r 4b986749c9e5 usr.bin/systat/cmds.c
--- a/usr.bin/systat/cmds.c     Mon Jan 10 19:33:18 2000 +0000
+++ b/usr.bin/systat/cmds.c     Mon Jan 10 21:06:15 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cmds.c,v 1.18 1999/12/20 23:11:50 jwise Exp $  */
+/*     $NetBSD: cmds.c,v 1.19 2000/01/10 21:06:15 itojun Exp $ */
 
 /*-
  * Copyright (c) 1980, 1992, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)cmds.c     8.2 (Berkeley) 4/29/95";
 #endif
-__RCSID("$NetBSD: cmds.c,v 1.18 1999/12/20 23:11:50 jwise Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.19 2000/01/10 21:06:15 itojun Exp $");
 #endif /* not lint */
 
 #include <stdlib.h>
@@ -104,6 +104,10 @@
 switch_mode(p)
        struct mode *p;
 {
+       int switchfail;
+
+       switchfail = 0;
+
        if (curmode == p)
                return;
 
@@ -111,7 +115,6 @@
        (*curmode->c_close)(wnd);
        wnd = (*p->c_open)();
        if (wnd == 0) {
-               error("Couldn't open new display");
                wnd = (*curmode->c_open)();
                if (wnd == 0) {
                        error("Couldn't change back to previous mode");
@@ -119,19 +122,27 @@
                }
 
                p = curmode;
+               switchfail++;
        }
 
        if ((p->c_flags & CF_INIT) == 0) {
                if ((*p->c_init)())
                        p->c_flags |= CF_INIT;
-               else
-                       return;
+               else {
+                       (*p->c_close)(wnd);
+                       wnd = (*curmode->c_open)();
+                       p = curmode;
+                       switchfail++;
+               }
        }
 
        curmode = p;
        labels();
        display(0);
-       status();
+       if (switchfail)
+               error("Couldn't switch mode, back to %s", curmode->c_name);
+       else
+               status();
 }
 
 void
diff -r 27983dd0e804 -r 4b986749c9e5 usr.bin/systat/ip6.c
--- a/usr.bin/systat/ip6.c      Mon Jan 10 19:33:18 2000 +0000
+++ b/usr.bin/systat/ip6.c      Mon Jan 10 21:06:15 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip6.c,v 1.1 2000/01/08 23:12:37 itojun Exp $ */
+/*     $NetBSD: ip6.c,v 1.2 2000/01/10 21:06:16 itojun Exp $ */
 
 /*
  * Copyright (c) 1999 Andy Doran <ad%NetBSD.org@localhost>
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ip6.c,v 1.1 2000/01/08 23:12:37 itojun Exp $");
+__RCSID("$NetBSD: ip6.c,v 1.2 2000/01/10 21:06:16 itojun Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -193,13 +193,14 @@
 int
 initip6(void)
 {
+       int n;
 
        if (namelist[0].n_type == 0) {
-               if (kvm_nlist(kd, namelist)) {
+               n = kvm_nlist(kd, namelist);
+               if (n < 0) {
                        nlisterr(namelist);
                        return(0);
-               }
-               if (namelist[0].n_type == 0) {
+               } else if (n == sizeof(namelist) / sizeof(namelist[0]) - 1) {
                        error("No namelist");
                        return(0);
                }
diff -r 27983dd0e804 -r 4b986749c9e5 usr.bin/systat/ipsec.c
--- a/usr.bin/systat/ipsec.c    Mon Jan 10 19:33:18 2000 +0000
+++ b/usr.bin/systat/ipsec.c    Mon Jan 10 21:06:15 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ipsec.c,v 1.1 2000/01/08 23:12:37 itojun Exp $ */
+/*     $NetBSD: ipsec.c,v 1.2 2000/01/10 21:06:16 itojun Exp $ */
 
 /*
  * Copyright (c) 1999 Andy Doran <ad%NetBSD.org@localhost>
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ipsec.c,v 1.1 2000/01/08 23:12:37 itojun Exp $");
+__RCSID("$NetBSD: ipsec.c,v 1.2 2000/01/10 21:06:16 itojun Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -96,42 +96,46 @@
 
        wmove(wnd, 0, 0); wclrtoeol(wnd);
 
-       mvwprintw(wnd, 0, 0,  "------ IPv4 IPsec input ------");
-       LHD(1,  "processed successfully");
-       LHD(2,  "violated process policy");
-       LHD(3,  "with no SA available");
-       LHD(4,  "failed due to EINVAL");
-       LHD(5,  "failed getting SPI");
-       LHD(6,  "failed on AH replay check");
-       LHD(7,  "failed on ESP replay check");
-       LHD(8,  "considered authentic");
-       LHD(9,  "failed on authentication");
+       if (namelist[0].n_type) {
+               mvwprintw(wnd, 0, 0,  "------ IPv4 IPsec input ------");
+               LHD(1,  "processed successfully");
+               LHD(2,  "violated process policy");
+               LHD(3,  "with no SA available");
+               LHD(4,  "failed due to EINVAL");
+               LHD(5,  "failed getting SPI");
+               LHD(6,  "failed on AH replay check");
+               LHD(7,  "failed on ESP replay check");
+               LHD(8,  "considered authentic");
+               LHD(9,  "failed on authentication");
 
-       mvwprintw(wnd, 11, 0,  "------ IPv4 IPsec output ------");
-       LHD(12, "processed successfully");
-       LHD(13, "violated process policy");
-       LHD(14, "with no SA available");
-       LHD(15, "failed processing due to EINVAL");
-       LHD(16, "with no route");
+               mvwprintw(wnd, 11, 0,  "------ IPv4 IPsec output ------");
+               LHD(12, "processed successfully");
+               LHD(13, "violated process policy");
+               LHD(14, "with no SA available");
+               LHD(15, "failed processing due to EINVAL");
+               LHD(16, "with no route");
+       }
 
 #ifdef INET6
-       mvwprintw(wnd, 0, 35,  "------ IPv6 IPsec input ------");
-       RHD(1,  "processed successfully");
-       RHD(2,  "violated process policy");
-       RHD(3,  "with no SA available");
-       RHD(4,  "failed due to EINVAL");
-       RHD(5,  "failed getting SPI");
-       RHD(6,  "failed on AH replay check");
-       RHD(7,  "failed on ESP replay check");
-       RHD(8,  "considered authentic");
-       RHD(9,  "failed on authentication");
+       if (namelist[1].n_type) {
+               mvwprintw(wnd, 0, 35,  "------ IPv6 IPsec input ------");
+               RHD(1,  "processed successfully");
+               RHD(2,  "violated process policy");
+               RHD(3,  "with no SA available");
+               RHD(4,  "failed due to EINVAL");
+               RHD(5,  "failed getting SPI");
+               RHD(6,  "failed on AH replay check");
+               RHD(7,  "failed on ESP replay check");
+               RHD(8,  "considered authentic");
+               RHD(9,  "failed on authentication");
 
-       mvwprintw(wnd, 11, 35,  "------ IPv6 IPsec output ------");
-       RHD(12, "processed successfully");
-       RHD(13, "violated process policy");
-       RHD(14, "with no SA available");
-       RHD(15, "failed due to EINVAL");
-       RHD(16, "with no route");
+               mvwprintw(wnd, 11, 35,  "------ IPv6 IPsec output ------");
+               RHD(12, "processed successfully");
+               RHD(13, "violated process policy");
+               RHD(14, "with no SA available");
+               RHD(15, "failed due to EINVAL");
+               RHD(16, "with no route");
+       }
 #endif
 }
        
@@ -139,56 +143,58 @@
 showipsec(void)
 {
 
-       SHOW(i4.in_success,     1, 0);
-       SHOW(i4.in_polvio,      2, 0);
-       SHOW(i4.in_nosa,        3, 0);
-       SHOW(i4.in_inval,       4, 0);
-       SHOW(i4.in_badspi,      5, 0);
-       SHOW(i4.in_ahreplay,    6, 0);
-       SHOW(i4.in_espreplay,   7, 0);
-       SHOW(i4.in_ahauthsucc,  8, 0);
-       SHOW(i4.in_ahauthfail,  9, 0);
+       if (namelist[0].n_type) {
+               SHOW(i4.in_success,     1, 0);
+               SHOW(i4.in_polvio,      2, 0);
+               SHOW(i4.in_nosa,        3, 0);
+               SHOW(i4.in_inval,       4, 0);
+               SHOW(i4.in_badspi,      5, 0);
+               SHOW(i4.in_ahreplay,    6, 0);
+               SHOW(i4.in_espreplay,   7, 0);
+               SHOW(i4.in_ahauthsucc,  8, 0);
+               SHOW(i4.in_ahauthfail,  9, 0);
 
-       SHOW(i4.out_success,    12, 0);
-       SHOW(i4.out_polvio,     13, 0);
-       SHOW(i4.out_nosa,       14, 0);
-       SHOW(i4.out_inval,      15, 0);
-       SHOW(i4.out_noroute,    16, 0);
+               SHOW(i4.out_success,    12, 0);
+               SHOW(i4.out_polvio,     13, 0);
+               SHOW(i4.out_nosa,       14, 0);
+               SHOW(i4.out_inval,      15, 0);
+               SHOW(i4.out_noroute,    16, 0);
+       }
 
 #ifdef INET6
-       SHOW(i6.in_success,     1, 35);
-       SHOW(i6.in_polvio,      2, 35);
-       SHOW(i6.in_nosa,        3, 35);
-       SHOW(i6.in_inval,       4, 35);
-       SHOW(i6.in_badspi,      5, 35);
-       SHOW(i6.in_ahreplay,    6, 35);
-       SHOW(i6.in_espreplay,   7, 35);
-       SHOW(i6.in_ahauthsucc,  8, 35);
-       SHOW(i6.in_ahauthfail,  9, 35);
+       if (namelist[1].n_type) {
+               SHOW(i6.in_success,     1, 35);
+               SHOW(i6.in_polvio,      2, 35);
+               SHOW(i6.in_nosa,        3, 35);
+               SHOW(i6.in_inval,       4, 35);
+               SHOW(i6.in_badspi,      5, 35);
+               SHOW(i6.in_ahreplay,    6, 35);
+               SHOW(i6.in_espreplay,   7, 35);
+               SHOW(i6.in_ahauthsucc,  8, 35);
+               SHOW(i6.in_ahauthfail,  9, 35);
 
-       SHOW(i6.out_success,    12, 35);
-       SHOW(i6.out_polvio,     13, 35);
-       SHOW(i6.out_nosa,       14, 35);
-       SHOW(i6.out_inval,      15, 35);
-       SHOW(i6.out_noroute,    16, 35);
+               SHOW(i6.out_success,    12, 35);
+               SHOW(i6.out_polvio,     13, 35);
+               SHOW(i6.out_nosa,       14, 35);
+               SHOW(i6.out_inval,      15, 35);
+               SHOW(i6.out_noroute,    16, 35);
+       }
 #endif
 }
 
 int
 initipsec(void)
 {
-       int i;
+       int n;
 
        if (namelist[0].n_type == 0) {
-               if (kvm_nlist(kd, namelist)) {
+               n = kvm_nlist(kd, namelist);
+               if (n < 0) {
                        nlisterr(namelist);
                        return(0);
-               }
-               for (i = 0; i < sizeof(namelist)/sizeof(namelist[0]) - 1; i++) {
-                       if (namelist[i].n_type == 0) {
-                               error("No namelist");
-                               return(0);
-                       }
+               } else if (n == sizeof(namelist) / sizeof(namelist[0]) - 1) {
+                       error("No namelist");
+                       return(0);
                }
        }
        return 1;
@@ -198,8 +204,14 @@
 fetchipsec(void)
 {
 



Home | Main Index | Thread Index | Old Index