Source-Changes-HG archive

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

[src/trunk]: src/usr.bin Adjust userland commands for struct inpcb separation



details:   https://anonhg.NetBSD.org/src/rev/bf92b05f6471
branches:  trunk
changeset: 372134:bf92b05f6471
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Fri Oct 28 05:27:16 2022 +0000

description:
Adjust userland commands for struct inpcb separation

Only kvm users are affected.

diffstat:

 usr.bin/fstat/fstat.c    |  37 +++++++++++++-----------
 usr.bin/netstat/inet.c   |  30 ++++++++++---------
 usr.bin/netstat/inet6.c  |  30 ++++++++++---------
 usr.bin/systat/netcmds.c |  12 ++++----
 usr.bin/systat/netstat.c |  72 +++++++++++++++++++++++++----------------------
 5 files changed, 96 insertions(+), 85 deletions(-)

diffs (truncated from 440 to 300 lines):

diff -r 0ef1f2363a5d -r bf92b05f6471 usr.bin/fstat/fstat.c
--- a/usr.bin/fstat/fstat.c     Fri Oct 28 05:26:29 2022 +0000
+++ b/usr.bin/fstat/fstat.c     Fri Oct 28 05:27:16 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fstat.c,v 1.116 2022/10/28 05:24:07 ozaki-r Exp $      */
+/*     $NetBSD: fstat.c,v 1.117 2022/10/28 05:27:16 ozaki-r Exp $      */
 
 /*-
  * Copyright (c) 1988, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)fstat.c    8.3 (Berkeley) 5/2/95";
 #else
-__RCSID("$NetBSD: fstat.c,v 1.116 2022/10/28 05:24:07 ozaki-r Exp $");
+__RCSID("$NetBSD: fstat.c,v 1.117 2022/10/28 05:27:16 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -1061,7 +1061,8 @@
        struct socket   so;
        struct protosw  proto;
        struct domain   dom;
-       struct inpcb    inpcb;
+       struct in4pcb   in4pcb;
+       struct in6pcb   in6pcb;
        struct unpcb    unpcb;
        struct ddpcb    ddpcb;
        int len;
@@ -1123,15 +1124,16 @@
                case IPPROTO_TCP:
                        if (so.so_pcb == NULL)
                                break;
-                       if (kvm_read(kd, (u_long)so.so_pcb, (char *)&inpcb,
-                           sizeof(inpcb)) != sizeof(inpcb)) {
-                               dprintf("can't read inpcb at %p", so.so_pcb);
+                       if (kvm_read(kd, (u_long)so.so_pcb, (char *)&in4pcb,
+                           sizeof(in4pcb)) != sizeof(in4pcb)) {
+                               dprintf("can't read in4pcb at %p", so.so_pcb);
                                goto bad;
                        }
-                       inet_addrstr(lbuf, sizeof(lbuf), &inpcb.inp_laddr,
-                           ntohs(inpcb.inp_lport), isdgram);
-                       inet_addrstr(fbuf, sizeof(fbuf), &inpcb.inp_faddr,
-                           ntohs(inpcb.inp_fport), isdgram);
+                       struct inpcb *inp = (struct inpcb *)&in4pcb;
+                       inet_addrstr(lbuf, sizeof(lbuf), &in4p_laddr(inp),
+                           ntohs(inp->inp_lport), isdgram);
+                       inet_addrstr(fbuf, sizeof(fbuf), &in4p_faddr(inp),
+                           ntohs(inp->inp_fport), isdgram);
                        break;
                default:
                        break;
@@ -1147,15 +1149,16 @@
                case IPPROTO_TCP:
                        if (so.so_pcb == NULL)
                                break;
-                       if (kvm_read(kd, (u_long)so.so_pcb, (char *)&inpcb,
-                           sizeof(inpcb)) != sizeof(inpcb)) {
-                               dprintf("can't read inpcb at %p", so.so_pcb);
+                       if (kvm_read(kd, (u_long)so.so_pcb, (char *)&in6pcb,
+                           sizeof(in6pcb)) != sizeof(in6pcb)) {
+                               dprintf("can't read in6pcb at %p", so.so_pcb);
                                goto bad;
                        }
-                       inet6_addrstr(lbuf, sizeof(lbuf), &inpcb.inp_laddr6,
-                           ntohs(inpcb.inp_lport), isdgram);
-                       inet6_addrstr(fbuf, sizeof(fbuf), &inpcb.inp_faddr6,
-                           ntohs(inpcb.inp_fport), isdgram);
+                       struct inpcb *inp = (struct inpcb *)&in6pcb;
+                       inet6_addrstr(lbuf, sizeof(lbuf), &in6p_laddr(inp),
+                           ntohs(inp->inp_lport), isdgram);
+                       inet6_addrstr(fbuf, sizeof(fbuf), &in6p_faddr(inp),
+                           ntohs(inp->inp_fport), isdgram);
                        break;
                default:
                        break;
diff -r 0ef1f2363a5d -r bf92b05f6471 usr.bin/netstat/inet.c
--- a/usr.bin/netstat/inet.c    Fri Oct 28 05:26:29 2022 +0000
+++ b/usr.bin/netstat/inet.c    Fri Oct 28 05:27:16 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: inet.c,v 1.118 2022/10/28 05:24:07 ozaki-r Exp $       */
+/*     $NetBSD: inet.c,v 1.119 2022/10/28 05:27:17 ozaki-r Exp $       */
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)inet.c       8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet.c,v 1.118 2022/10/28 05:24:07 ozaki-r Exp $");
+__RCSID("$NetBSD: inet.c,v 1.119 2022/10/28 05:27:17 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -276,7 +276,8 @@
 {
        struct inpcbtable table;
        struct inpcb *next, *prev;
-       struct inpcb inpcb;
+       struct in4pcb in4pcb;
+       struct inpcb *inp;
        struct tcpcb tcpcb;
        struct socket sockb;
        int istcp = strcmp(name, "tcp") == 0;
@@ -301,31 +302,32 @@
 
        i = 0;
        while (next != TAILQ_END(head)) {
-               kread((u_long)next, (char *)&inpcb, sizeof inpcb);
+               kread((u_long)next, (char *)&in4pcb, sizeof in4pcb);
                prev = next;
-               next = TAILQ_NEXT(&inpcb, inp_queue);
+               inp = (struct inpcb *)&in4pcb;
+               next = TAILQ_NEXT(inp, inp_queue);
 
-               if (inpcb.inp_af != AF_INET)
+               if (inp->inp_af != AF_INET)
                        continue;
 
-               kread((u_long)inpcb.inp_socket, (char *)&sockb, sizeof(sockb));
+               kread((u_long)inp->inp_socket, (char *)&sockb, sizeof(sockb));
                if (istcp) {
-                       kread((u_long)inpcb.inp_ppcb,
+                       kread((u_long)inp->inp_ppcb,
                            (char *)&tcpcb, sizeof (tcpcb));
                }
                pcblist[i].ki_ppcbaddr =
-                   istcp ? (uintptr_t) inpcb.inp_ppcb : (uintptr_t) prev;
+                   istcp ? (uintptr_t) inp->inp_ppcb : (uintptr_t) prev;
                pcblist[i].ki_rcvq = (uint64_t)sockb.so_rcv.sb_cc;
                pcblist[i].ki_sndq = (uint64_t)sockb.so_snd.sb_cc;
 
-               sin.sin_addr = inpcb.inp_laddr;
-               sin.sin_port = inpcb.inp_lport;
+               sin.sin_addr = in4p_laddr(inp);
+               sin.sin_port = inp->inp_lport;
                memcpy(&pcblist[i].ki_s, &sin, sizeof(sin));
-               sin.sin_addr = inpcb.inp_faddr;
-               sin.sin_port = inpcb.inp_fport;
+               sin.sin_addr = in4p_faddr(inp);
+               sin.sin_port = inp->inp_fport;
                memcpy(&pcblist[i].ki_d, &sin, sizeof(sin));
                pcblist[i].ki_tstate = tcpcb.t_state;
-               pcblist[i].ki_pflags = inpcb.inp_flags;
+               pcblist[i].ki_pflags = inp->inp_flags;
                if (i++ == size) {
                        size += 100;
                        if (reallocarr(&pcblist, size, sizeof(*pcblist)) != 0)
diff -r 0ef1f2363a5d -r bf92b05f6471 usr.bin/netstat/inet6.c
--- a/usr.bin/netstat/inet6.c   Fri Oct 28 05:26:29 2022 +0000
+++ b/usr.bin/netstat/inet6.c   Fri Oct 28 05:27:16 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: inet6.c,v 1.83 2022/10/28 05:24:07 ozaki-r Exp $       */
+/*     $NetBSD: inet6.c,v 1.84 2022/10/28 05:27:17 ozaki-r Exp $       */
 /*     BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp   */
 
 /*
@@ -64,7 +64,7 @@
 #if 0
 static char sccsid[] = "@(#)inet.c     8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet6.c,v 1.83 2022/10/28 05:24:07 ozaki-r Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.84 2022/10/28 05:27:17 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -141,7 +141,7 @@
 
 #ifdef INET6
 
-struct inpcb inpcb;
+struct in6pcb in6pcb;
 #ifdef TCP6
 struct tcp6cb tcp6cb;
 #else
@@ -288,6 +288,7 @@
        struct socket sockb;
        struct inpcbtable table;
        struct inpcb *next, *prev;
+       struct inpcb *inp;
        int istcp = strcmp(name, "tcp6") == 0;
        struct kinfo_pcb *pcblist;
        size_t size = 100, i;
@@ -309,33 +310,34 @@
 
        i = 0;
        while (next != TAILQ_END(head)) {
-               kread((u_long)next, (char *)&inpcb, sizeof inpcb);
-               next = TAILQ_NEXT(&inpcb, inp_queue);
+               kread((u_long)next, (char *)&in6pcb, sizeof in6pcb);
+               inp = (struct inpcb *)&in6pcb;
+               next = TAILQ_NEXT(inp, inp_queue);
                prev = next;
 
-               if (inpcb.inp_af != AF_INET6)
+               if (inp->inp_af != AF_INET6)
                        continue;
 
-               kread((u_long)inpcb.inp_socket, (char *)&sockb,
+               kread((u_long)inp->inp_socket, (char *)&sockb,
                    sizeof (sockb));
                if (istcp) {
 #ifdef TCP6
-                       kread((u_long)inpcb.inp_ppcb,
+                       kread((u_long)inp->inp_ppcb,
                            (char *)&tcp6cb, sizeof (tcp6cb));
 #else
-                       kread((u_long)inpcb.inp_ppcb,
+                       kread((u_long)inp->inp_ppcb,
                            (char *)&tcpcb, sizeof (tcpcb));
 #endif
                }
                pcblist[i].ki_ppcbaddr =
-                   istcp ? (uintptr_t) inpcb.inp_ppcb : (uintptr_t) prev;
+                   istcp ? (uintptr_t) inp->inp_ppcb : (uintptr_t) prev;
                pcblist[i].ki_rcvq = (uint64_t)sockb.so_rcv.sb_cc;
                pcblist[i].ki_sndq = (uint64_t)sockb.so_snd.sb_cc;
-               sin6.sin6_addr = inpcb.inp_laddr6;
-               sin6.sin6_port = inpcb.inp_lport;
+               sin6.sin6_addr = in6p_laddr(inp);
+               sin6.sin6_port = inp->inp_lport;
                memcpy(&pcblist[i].ki_s, &sin6, sizeof(sin6));
-               sin6.sin6_addr = inpcb.inp_faddr6;
-               sin6.sin6_port = inpcb.inp_fport;
+               sin6.sin6_addr = in6p_faddr(inp);
+               sin6.sin6_port = inp->inp_fport;
                memcpy(&pcblist[i].ki_d, &sin6, sizeof(sin6));
                pcblist[i].ki_tstate = tcpcb.t_state;
                if (i++ == size) {
diff -r 0ef1f2363a5d -r bf92b05f6471 usr.bin/systat/netcmds.c
--- a/usr.bin/systat/netcmds.c  Fri Oct 28 05:26:29 2022 +0000
+++ b/usr.bin/systat/netcmds.c  Fri Oct 28 05:27:16 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netcmds.c,v 1.23 2022/10/28 05:24:08 ozaki-r Exp $     */
+/*     $NetBSD: netcmds.c,v 1.24 2022/10/28 05:27:17 ozaki-r Exp $     */
 
 /*-
  * Copyright (c) 1980, 1992, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)netcmds.c  8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: netcmds.c,v 1.23 2022/10/28 05:24:08 ozaki-r Exp $");
+__RCSID("$NetBSD: netcmds.c,v 1.24 2022/10/28 05:27:17 ozaki-r Exp $");
 #endif /* not lint */
 
 /*
@@ -331,8 +331,8 @@
                        if (((struct sockaddr *)&p->addr)->sa_family != AF_INET)
                                continue;
                        s_in = (struct sockaddr_in *)&p->addr;
-                       if (s_in->sin_addr.s_addr == inp->inp_laddr.s_addr ||
-                           s_in->sin_addr.s_addr == inp->inp_faddr.s_addr)
+                       if (s_in->sin_addr.s_addr == in4p_laddr(inp).s_addr ||
+                           s_in->sin_addr.s_addr == in4p_faddr(inp).s_addr)
                                return (p->onoff);
                }
        return (1);
@@ -350,8 +350,8 @@
                        if (((struct sockaddr *)&p->addr)->sa_family != AF_INET6)
                                continue;
                        sin6 = (struct sockaddr_in6 *)&p->addr;
-                       if (IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr, &inp->inp_laddr6) ||
-                           IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr, &inp->inp_faddr6))
+                       if (IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr, &in6p_laddr(inp)) ||
+                           IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr, &in6p_faddr(inp)))
                                return (p->onoff);
                }
        return (1);
diff -r 0ef1f2363a5d -r bf92b05f6471 usr.bin/systat/netstat.c
--- a/usr.bin/systat/netstat.c  Fri Oct 28 05:26:29 2022 +0000
+++ b/usr.bin/systat/netstat.c  Fri Oct 28 05:27:16 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netstat.c,v 1.31 2022/10/28 05:24:08 ozaki-r Exp $     */
+/*     $NetBSD: netstat.c,v 1.32 2022/10/28 05:27:17 ozaki-r Exp $     */
 
 /*-
  * Copyright (c) 1980, 1992, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)netstat.c  8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: netstat.c,v 1.31 2022/10/28 05:24:08 ozaki-r Exp $");
+__RCSID("$NetBSD: netstat.c,v 1.32 2022/10/28 05:27:17 ozaki-r Exp $");
 #endif /* not lint */
 
 /*
@@ -215,7 +215,8 @@
        struct inpcbtable pcbtable;
        struct inpcb **pprev, *next;
        struct netinfo *p;
-       struct inpcb inpcb, *inpcbp;
+       struct inpcb *inpcbp, *inp;
+       struct in4pcb in4pcb;
        struct socket sockb;
        struct tcpcb tcpcb;
 
@@ -224,30 +225,31 @@
        next = TAILQ_FIRST(&pcbtable.inpt_queue);
        while (next != TAILQ_END(&pcbtable.inpt_queue)) {



Home | Main Index | Thread Index | Old Index