diff options
author | Gleb Smirnoff <glebius@FreeBSD.org> | 2017-03-21 06:39:49 +0000 |
---|---|---|
committer | Gleb Smirnoff <glebius@FreeBSD.org> | 2017-03-21 06:39:49 +0000 |
commit | cc65eb4e792a203a8b4a17b0e3af7831e5044eca (patch) | |
tree | 969a970e8707f4144afbe92a15b95806217ec748 /usr.bin/systat | |
parent | 5a33a2afb3a35949545a572cffa0b8e637446d4a (diff) | |
download | src-test2-cc65eb4e792a203a8b4a17b0e3af7831e5044eca.tar.gz src-test2-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/systat')
-rw-r--r-- | usr.bin/systat/extern.h | 6 | ||||
-rw-r--r-- | usr.bin/systat/netcmds.c | 10 | ||||
-rw-r--r-- | usr.bin/systat/netstat.c | 65 |
3 files changed, 41 insertions, 40 deletions
diff --git a/usr.bin/systat/extern.h b/usr.bin/systat/extern.h index 1e214df3d08d..5d92f88f4b66 100644 --- a/usr.bin/systat/extern.h +++ b/usr.bin/systat/extern.h @@ -56,7 +56,7 @@ extern int protos; extern int verbose; extern unsigned int delay; -struct inpcb; +struct in_conninfo; extern struct device_selection *dev_select; extern long generation; @@ -67,8 +67,8 @@ extern long select_generation; extern struct nlist namelist[]; -int checkhost(struct inpcb *); -int checkport(struct inpcb *); +int checkhost(struct in_conninfo *); +int checkport(struct in_conninfo *); void closeicmp(WINDOW *); void closeicmp6(WINDOW *); void closeifstat(WINDOW *); diff --git a/usr.bin/systat/netcmds.c b/usr.bin/systat/netcmds.c index 084496804479..f8ff64a35c99 100644 --- a/usr.bin/systat/netcmds.c +++ b/usr.bin/systat/netcmds.c @@ -224,13 +224,13 @@ selectport(long port, int onoff) } int -checkport(struct inpcb *inp) +checkport(struct in_conninfo *inc) { struct pitem *p; if (ports) for (p = ports; p < ports+nports; p++) - if (p->port == inp->inp_lport || p->port == inp->inp_fport) + if (p->port == inc->inc_lport || p->port == inc->inc_fport) return (p->onoff); return (1); } @@ -281,14 +281,14 @@ selecthost(struct in_addr *in, int onoff) } int -checkhost(struct inpcb *inp) +checkhost(struct in_conninfo *inc) { struct hitem *p; if (hosts) for (p = hosts; p < hosts+nhosts; p++) - if (p->addr.s_addr == inp->inp_laddr.s_addr || - p->addr.s_addr == inp->inp_faddr.s_addr) + if (p->addr.s_addr == inc->inc_laddr.s_addr || + p->addr.s_addr == inc->inc_faddr.s_addr) return (p->onoff); return (1); } diff --git a/usr.bin/systat/netstat.c b/usr.bin/systat/netstat.c index 0ac2244b25b2..5ab367a0a878 100644 --- a/usr.bin/systat/netstat.c +++ b/usr.bin/systat/netstat.c @@ -52,6 +52,7 @@ static const char sccsid[] = "@(#)netstat.c 8.1 (Berkeley) 6/6/93"; #ifdef INET6 #include <netinet/ip6.h> #endif +#define _WANT_INPCB #include <netinet/in_pcb.h> #include <netinet/ip_icmp.h> #include <netinet/icmp_var.h> @@ -62,6 +63,7 @@ static const char sccsid[] = "@(#)netstat.c 8.1 (Berkeley) 6/6/93"; #define TCPSTATES #include <netinet/tcp_fsm.h> #include <netinet/tcp_timer.h> +#define _WANT_TCPCB #include <netinet/tcp_var.h> #include <netinet/tcp_debug.h> #include <netinet/udp.h> @@ -76,9 +78,9 @@ static const char sccsid[] = "@(#)netstat.c 8.1 (Berkeley) 6/6/93"; #include "systat.h" #include "extern.h" -static struct netinfo *enter(struct inpcb *, int, const char *); +static struct netinfo *enter(struct in_conninfo *, uint8_t, int, const char *); static void enter_kvm(struct inpcb *, struct socket *, int, const char *); -static void enter_sysctl(struct inpcb *, struct xsocket *, int, const char *); +static void enter_sysctl(struct xinpcb *, struct xsocket *, int, const char *); static void fetchnetstat_kvm(void); static void fetchnetstat_sysctl(void); static char *inetname(struct sockaddr *); @@ -212,9 +214,9 @@ again: } #endif } - if (nhosts && !checkhost(&inpcb)) + if (nhosts && !checkhost(&inpcb.inp_inc)) continue; - if (nports && !checkport(&inpcb)) + if (nports && !checkport(&inpcb.inp_inc)) continue; if (istcp) { if (inpcb.inp_flags & INP_TIMEWAIT) { @@ -245,7 +247,6 @@ fetchnetstat_sysctl(void) int idx; struct xinpgen *inpg; char *cur, *end; - struct inpcb *inpcb; struct xinpcb *xip = NULL; struct xtcpcb *xtp = NULL; int plen; @@ -291,37 +292,36 @@ fetchnetstat_sysctl(void) while (cur + plen <= end) { if (idx == 0) { /* TCP */ xtp = (struct xtcpcb *)cur; - inpcb = &xtp->xt_inp; + xip = &xtp->xt_inp; } else { xip = (struct xinpcb *)cur; - inpcb = &xip->xi_inp; } cur += plen; if (!aflag) { - if (inpcb->inp_vflag & INP_IPV4) { - if (inet_lnaof(inpcb->inp_laddr) == + if (xip->inp_vflag & INP_IPV4) { + if (inet_lnaof(xip->inp_laddr) == INADDR_ANY) continue; } #ifdef INET6 - else if (inpcb->inp_vflag & INP_IPV6) { - if (memcmp(&inpcb->in6p_laddr, + else if (xip->inp_vflag & INP_IPV6) { + if (memcmp(&xip->in6p_laddr, &in6addr_any, sizeof(in6addr_any)) == 0) continue; } #endif } - if (nhosts && !checkhost(inpcb)) + if (nhosts && !checkhost(&xip->inp_inc)) continue; - if (nports && !checkport(inpcb)) + if (nports && !checkport(&xip->inp_inc)) continue; - if (idx == 0) /* TCP */ - enter_sysctl(inpcb, &xtp->xt_socket, - xtp->xt_tp.t_state, "tcp"); - else /* UDP */ - enter_sysctl(inpcb, &xip->xi_socket, 0, "udp"); + if (idx == 0) + enter_sysctl(xip, &xip->xi_socket, + xtp->t_state, "tcp"); + else + enter_sysctl(xip, &xip->xi_socket, 0, "udp"); } free(inpg); } @@ -332,25 +332,26 @@ enter_kvm(struct inpcb *inp, struct socket *so, int state, const char *proto) { struct netinfo *p; - if ((p = enter(inp, state, proto)) != NULL) { + if ((p = enter(&inp->inp_inc, inp->inp_vflag, state, proto)) != NULL) { p->ni_rcvcc = so->so_rcv.sb_ccc; p->ni_sndcc = so->so_snd.sb_ccc; } } static void -enter_sysctl(struct inpcb *inp, struct xsocket *so, int state, const char *proto) +enter_sysctl(struct xinpcb *xip, struct xsocket *so, int state, + const char *proto) { struct netinfo *p; - if ((p = enter(inp, state, proto)) != NULL) { + if ((p = enter(&xip->inp_inc, xip->inp_vflag, state, proto)) != NULL) { p->ni_rcvcc = so->so_rcv.sb_cc; p->ni_sndcc = so->so_snd.sb_cc; } } static struct netinfo * -enter(struct inpcb *inp, int state, const char *proto) +enter(struct in_conninfo *inc, uint8_t vflag, int state, const char *proto) { struct netinfo *p; struct sockaddr_storage lsa, fsa; @@ -361,32 +362,32 @@ enter(struct inpcb *inp, int state, const char *proto) memset(&lsa, 0, sizeof(lsa)); memset(&fsa, 0, sizeof(fsa)); - if (inp->inp_vflag & INP_IPV4) { + if (vflag & INP_IPV4) { sa4 = (struct sockaddr_in *)&lsa; - sa4->sin_addr = inp->inp_laddr; - sa4->sin_port = inp->inp_lport; + sa4->sin_addr = inc->inc_laddr; + sa4->sin_port = inc->inc_lport; sa4->sin_family = AF_INET; sa4->sin_len = sizeof(struct sockaddr_in); sa4 = (struct sockaddr_in *)&fsa; - sa4->sin_addr = inp->inp_faddr; - sa4->sin_port = inp->inp_fport; + sa4->sin_addr = inc->inc_faddr; + sa4->sin_port = inc->inc_fport; sa4->sin_family = AF_INET; sa4->sin_len = sizeof(struct sockaddr_in); } #ifdef INET6 - else if (inp->inp_vflag & INP_IPV6) { + else if (vflag & INP_IPV6) { sa6 = (struct sockaddr_in6 *)&lsa; - memcpy(&sa6->sin6_addr, &inp->in6p_laddr, + memcpy(&sa6->sin6_addr, &inc->inc6_laddr, sizeof(struct in6_addr)); - sa6->sin6_port = inp->inp_lport; + sa6->sin6_port = inc->inc_lport; sa6->sin6_family = AF_INET6; sa6->sin6_len = sizeof(struct sockaddr_in6); sa6 = (struct sockaddr_in6 *)&fsa; - memcpy(&sa6->sin6_addr, &inp->in6p_faddr, + memcpy(&sa6->sin6_addr, &inc->inc6_faddr, sizeof(struct in6_addr)); - sa6->sin6_port = inp->inp_fport; + sa6->sin6_port = inc->inc_fport; sa6->sin6_family = AF_INET6; sa6->sin6_len = sizeof(struct sockaddr_in6); } |