summaryrefslogtreecommitdiff
path: root/usr.bin/sockstat
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2017-03-21 06:39:49 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2017-03-21 06:39:49 +0000
commitcc65eb4e792a203a8b4a17b0e3af7831e5044eca (patch)
tree969a970e8707f4144afbe92a15b95806217ec748 /usr.bin/sockstat
parent5a33a2afb3a35949545a572cffa0b8e637446d4a (diff)
downloadsrc-test-cc65eb4e792a203a8b4a17b0e3af7831e5044eca.tar.gz
src-test-cc65eb4e792a203a8b4a17b0e3af7831e5044eca.zip
Hide struct inpcb, struct tcpcb from the userland.
This is a painful change, but it is needed. On the one hand, we avoid modifying them, and this slows down some ideas, on the other hand we still eventually modify them and tools like netstat(1) never work on next version of FreeBSD. We maintain a ton of spares in them, and we already got some ifdef hell at the end of tcpcb. Details: - Hide struct inpcb, struct tcpcb under _KERNEL || _WANT_FOO. - Make struct xinpcb, struct xtcpcb pure API structures, not including kernel structures inpcb and tcpcb inside. Export into these structures the fields from inpcb and tcpcb that are known to be used, and put there a ton of spare space. - Make kernel and userland utilities compilable after these changes. - Bump __FreeBSD_version. Reviewed by: rrs, gnn Differential Revision: D10018
Notes
Notes: svn path=/head/; revision=315662
Diffstat (limited to 'usr.bin/sockstat')
-rw-r--r--usr.bin/sockstat/sockstat.c53
1 files changed, 25 insertions, 28 deletions
diff --git a/usr.bin/sockstat/sockstat.c b/usr.bin/sockstat/sockstat.c
index dea195c387b10..97add95457a89 100644
--- a/usr.bin/sockstat/sockstat.c
+++ b/usr.bin/sockstat/sockstat.c
@@ -562,7 +562,6 @@ gather_inet(int proto)
struct xinpgen *xig, *exig;
struct xinpcb *xip;
struct xtcpcb *xtp;
- struct inpcb *inp;
struct xsocket *so;
struct sock *sock;
struct addr *laddr, *faddr;
@@ -625,54 +624,52 @@ gather_inet(int proto)
xig = (struct xinpgen *)(void *)((char *)xig + xig->xig_len);
if (xig >= exig)
break;
- xip = (struct xinpcb *)xig;
- xtp = (struct xtcpcb *)xig;
switch (proto) {
case IPPROTO_TCP:
+ xtp = (struct xtcpcb *)xig;
+ xip = &xtp->xt_inp;
if (xtp->xt_len != sizeof(*xtp)) {
warnx("struct xtcpcb size mismatch");
goto out;
}
- inp = &xtp->xt_inp;
- so = &xtp->xt_socket;
- protoname = xtp->xt_tp.t_flags & TF_TOE ? "toe" : "tcp";
+ protoname = xtp->t_flags & TF_TOE ? "toe" : "tcp";
break;
case IPPROTO_UDP:
case IPPROTO_DIVERT:
+ xip = (struct xinpcb *)xig;
if (xip->xi_len != sizeof(*xip)) {
warnx("struct xinpcb size mismatch");
goto out;
}
- inp = &xip->xi_inp;
- so = &xip->xi_socket;
break;
default:
errx(1, "protocol %d not supported", proto);
}
- if ((inp->inp_vflag & vflag) == 0)
+ so = &xip->xi_socket;
+ if ((xip->inp_vflag & vflag) == 0)
continue;
- if (inp->inp_vflag & INP_IPV4) {
- if ((inp->inp_fport == 0 && !opt_l) ||
- (inp->inp_fport != 0 && !opt_c))
+ if (xip->inp_vflag & INP_IPV4) {
+ if ((xip->inp_fport == 0 && !opt_l) ||
+ (xip->inp_fport != 0 && !opt_c))
continue;
#define __IN_IS_ADDR_LOOPBACK(pina) \
((ntohl((pina)->s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET)
if (opt_L &&
- (__IN_IS_ADDR_LOOPBACK(&inp->inp_faddr) ||
- __IN_IS_ADDR_LOOPBACK(&inp->inp_laddr)))
+ (__IN_IS_ADDR_LOOPBACK(&xip->inp_faddr) ||
+ __IN_IS_ADDR_LOOPBACK(&xip->inp_laddr)))
continue;
#undef __IN_IS_ADDR_LOOPBACK
- } else if (inp->inp_vflag & INP_IPV6) {
- if ((inp->inp_fport == 0 && !opt_l) ||
- (inp->inp_fport != 0 && !opt_c))
+ } else if (xip->inp_vflag & INP_IPV6) {
+ if ((xip->inp_fport == 0 && !opt_l) ||
+ (xip->inp_fport != 0 && !opt_c))
continue;
if (opt_L &&
- (IN6_IS_ADDR_LOOPBACK(&inp->in6p_faddr) ||
- IN6_IS_ADDR_LOOPBACK(&inp->in6p_laddr)))
+ (IN6_IS_ADDR_LOOPBACK(&xip->in6p_faddr) ||
+ IN6_IS_ADDR_LOOPBACK(&xip->in6p_laddr)))
continue;
} else {
if (opt_v)
- warnx("invalid vflag 0x%x", inp->inp_vflag);
+ warnx("invalid vflag 0x%x", xip->inp_vflag);
continue;
}
if ((sock = calloc(1, sizeof(*sock))) == NULL)
@@ -683,26 +680,26 @@ gather_inet(int proto)
err(1, "malloc()");
sock->socket = so->xso_so;
sock->proto = proto;
- if (inp->inp_vflag & INP_IPV4) {
+ if (xip->inp_vflag & INP_IPV4) {
sock->family = AF_INET;
sockaddr(&laddr->address, sock->family,
- &inp->inp_laddr, inp->inp_lport);
+ &xip->inp_laddr, xip->inp_lport);
sockaddr(&faddr->address, sock->family,
- &inp->inp_faddr, inp->inp_fport);
- } else if (inp->inp_vflag & INP_IPV6) {
+ &xip->inp_faddr, xip->inp_fport);
+ } else if (xip->inp_vflag & INP_IPV6) {
sock->family = AF_INET6;
sockaddr(&laddr->address, sock->family,
- &inp->in6p_laddr, inp->inp_lport);
+ &xip->in6p_laddr, xip->inp_lport);
sockaddr(&faddr->address, sock->family,
- &inp->in6p_faddr, inp->inp_fport);
+ &xip->in6p_faddr, xip->inp_fport);
}
laddr->next = NULL;
faddr->next = NULL;
sock->laddr = laddr;
sock->faddr = faddr;
- sock->vflag = inp->inp_vflag;
+ sock->vflag = xip->inp_vflag;
if (proto == IPPROTO_TCP)
- sock->state = xtp->xt_tp.t_state;
+ sock->state = xtp->t_state;
sock->protoname = protoname;
hash = (int)((uintptr_t)sock->socket % HASHSIZE);
sock->next = sockhash[hash];