diff --git a/dialects/freebsd/dproc.c b/dialects/freebsd/dproc.c index 1eb3b3c6..d74a070b 100644 --- a/dialects/freebsd/dproc.c +++ b/dialects/freebsd/dproc.c @@ -93,7 +93,7 @@ read_xfiles(struct xfile **xfiles, size_t *count) /* Based on process_file() in lib/prfd.c */ static void -process_kinfo_file(struct kinfo_file *kf, struct xfile *xfile) +process_kinfo_file(struct kinfo_file *kf, struct xfile *xfile, struct pcb_lists *pcbs) { Lf->off = kf->kf_offset; if (kf->kf_ref_count) { @@ -129,7 +129,7 @@ process_kinfo_file(struct kinfo_file *kf, struct xfile *xfile) process_node(xfile ? xfile->xf_vnode : 0UL); break; case KF_TYPE_SOCKET: - process_socket(xfile ? xfile->xf_data : 0UL); + process_socket(kf, pcbs); break; case KF_TYPE_KQUEUE: process_kqueue(xfile ? xfile->xf_data : 0UL); @@ -155,7 +155,8 @@ process_kinfo_file(struct kinfo_file *kf, struct xfile *xfile) static void process_file_descriptors( struct kinfo_proc *p, short ckscko, - struct xfile *xfiles, size_t n_xfiles) + struct xfile *xfiles, size_t n_xfiles, + struct pcb_lists *pcbs) { struct kinfo_file *kfiles; int n_kfiles = 0; @@ -200,7 +201,7 @@ process_file_descriptors( fprintf(stderr, "%s: WARNING -- unsupported fd type %d\n", Pn, kfiles[i].kf_fd); } else { alloc_lfile(NULL, kfiles[i].kf_fd); - process_kinfo_file(&kfiles[i], xfile); + process_kinfo_file(&kfiles[i], xfile, pcbs); if (Lf->sf) link_lfile(); } @@ -240,6 +241,7 @@ gather_proc_info() struct kinfo_proc *p; struct xfile *xfiles; size_t n_xfiles; + struct pcb_lists *pcbs; #if defined(HASFSTRUCT) && !defined(HAS_FILEDESCENT) static char *pof = (char *)NULL; @@ -328,6 +330,10 @@ gather_proc_info() fprintf(stderr, "%s: WARNING -- reading xfile list failed: %s\n", Pn, strerror(errno)); qsort(xfiles, n_xfiles, sizeof(*xfiles), cmp_xfiles_pid_fd); + pcbs = read_pcb_lists(); + if (!pcbs && !Fwarn) + fprintf(stderr, "%s: WARNING -- reading PCBs failed: %s\n", + Pn, strerror(errno)); /* * Examine proc structures and their associated information. @@ -393,7 +399,7 @@ gather_proc_info() Kpa = (KA_T)p->P_ADDR; #endif /* defined(P_ADDR) */ - process_file_descriptors(p, ckscko, xfiles, n_xfiles); + process_file_descriptors(p, ckscko, xfiles, n_xfiles, pcbs); /* * Unless threads (tasks) are being processed, examine results. @@ -405,6 +411,7 @@ gather_proc_info() } free(xfiles); + free_pcb_lists(pcbs); } diff --git a/dialects/freebsd/dproto.h b/dialects/freebsd/dproto.h index 83da56d8..b22239e2 100644 --- a/dialects/freebsd/dproto.h +++ b/dialects/freebsd/dproto.h @@ -50,7 +50,7 @@ _PROTOTYPE(extern char *get_nlist_path,(int ap)); #endif /* !defined(N_UNIX) */ _PROTOTYPE(extern int is_file_named,(char *p, int cd)); -_PROTOTYPE(extern void process_socket,(KA_T sa)); +_PROTOTYPE(extern void process_socket,(struct kinfo_file *kf, struct pcb_lists *pcbs)); _PROTOTYPE(extern struct l_vfs *readvfs,(KA_T vm)); _PROTOTYPE(extern struct pcb_lists *read_pcb_lists,(void)); _PROTOTYPE(extern void free_pcb_lists,(struct pcb_lists *pcb_lists)); diff --git a/dialects/freebsd/dsock.c b/dialects/freebsd/dsock.c index 177c89ee..e2649bc0 100644 --- a/dialects/freebsd/dsock.c +++ b/dialects/freebsd/dsock.c @@ -78,7 +78,7 @@ static char copyright[] = * Local function prototypes */ -_PROTOTYPE(static int ckstate,(KA_T pcb, KA_T ta, struct tcpcb *t, int fam)); +_PROTOTYPE(static int ckstate,(struct xtcpcb *pcb, int fam)); static int @@ -138,6 +138,7 @@ get_unix_pcbs(const char *name, struct xunpcb **pcbs, size_t *n_pcbs) goto end; if (sysctlbyname(name, buffer, &len, NULL, 0)) goto end; + ug = (struct xunpgen *)buffer; for (ug = (struct xunpgen *)((char *)ug + ug->xug_len); ug->xug_len == sizeof(struct xunpcb); ug = (struct xunpgen *)((char *)ug + ug->xug_len)) { @@ -171,6 +172,7 @@ get_tcp_pcbs(struct xtcpcb **pcbs, size_t *n_pcbs) goto end; if (sysctlbyname("net.inet.tcp.pcblist", buffer, &len, NULL, 0)) goto end; + ig = (struct xinpgen *)buffer; for (ig = (struct xinpgen *)((char *)ig + ig->xig_len); ig->xig_len == sizeof(struct xtcpcb); ig = (struct xinpgen *)((char *)ig + ig->xig_len)) { @@ -204,6 +206,7 @@ get_udp_pcbs(struct xinpcb **pcbs, size_t *n_pcbs) goto end; if (sysctlbyname("net.inet.udp.pcblist", buffer, &len, NULL, 0)) goto end; + ig = (struct xinpgen *)buffer; for (ig = (struct xinpgen *)((char *)ig + ig->xig_len); ig->xig_len == sizeof(struct xinpcb); ig = (struct xinpgen *)((char *)ig + ig->xig_len)) { @@ -226,8 +229,6 @@ struct pcb_lists* read_pcb_lists(void) { struct pcb_lists *pcbs; - size_t len; - int ret; int succeeded = 0; pcbs = calloc(1, sizeof(struct pcb_lists)); @@ -278,27 +279,16 @@ free_pcb_lists(struct pcb_lists *pcbs) */ static int -ckstate(pcb, ta, t, fam) - KA_T pcb; /* PCB address */ - KA_T ta; /* TCP control block address */ - struct tcpcb *t; /* TCP control block receptor */ - int fam; /* protocol family */ +ckstate(struct xtcpcb *pcb, int fam) { int tsnx; -/* - * Read TCP control block. - */ - if (kread(ta, (char *)t, sizeof(struct tcpcb)) - || (KA_T)t->t_inpcb != pcb) - { - return(-1); - } + if (TcpStXn || TcpStIn) { /* * If there are TCP state inclusions or exclusions, check them. */ - if ((tsnx = (int)t->t_state + TcpStOff) >= TcpNstates) + if ((tsnx = (int)pcb->t_state + TcpStOff) >= TcpNstates) return(0); if (TcpStXn) { if (TcpStX[tsnx]) { @@ -326,10 +316,7 @@ ckstate(pcb, ta, t, fam) if (Fnet) { if (!FnetTy || ((FnetTy == 4) && (fam == AF_INET)) - -#if defined(HASIPv6) || ((FnetTy == 6) && (fam == AF_INET6)) -#endif /* defined(HASIPv6) */ ) { Lf->sf |= SELNET; @@ -340,274 +327,219 @@ ckstate(pcb, ta, t, fam) } +static void +find_pcb_and_xsocket(struct pcb_lists *pcbs, int domain, int type, uint64_t pcb_addr, + void **pcb, struct xsocket **xsocket) +{ + if (!pcbs) + return; + if (domain == PF_INET || domain == PF_INET6) { + if (type == SOCK_STREAM) { + struct xtcpcb key, *result; + key.xt_inp.xi_socket.so_pcb = pcb_addr; + result = bsearch(&key, pcbs->tcp_pcbs, pcbs->n_tcp_pcbs, sizeof(*pcbs->tcp_pcbs), cmp_xtcpcb_sock_pcb); + if (result) { + *xsocket = &result->xt_inp.xi_socket; + *pcb = result; + } + } else if (type == SOCK_DGRAM) { + struct xinpcb key, *result; + key.xi_socket.so_pcb = pcb_addr; + result = bsearch(&key, pcbs->udp_pcbs, pcbs->n_udp_pcbs, sizeof(*pcbs->udp_pcbs), cmp_xinpcb_sock_pcb); + if (result) { + *xsocket = &result->xi_socket; + *pcb = result; + } + } + } else if (domain == PF_UNIX) { + struct xunpcb key, *result = NULL; + key.xu_socket.so_pcb = pcb_addr; + if (type == SOCK_STREAM) { + result = bsearch(&key, pcbs->un_stream_pcbs, pcbs->n_un_stream_pcbs, sizeof(*pcbs->un_stream_pcbs), cmp_xunpcb_sock_pcb); + } else if (type == SOCK_DGRAM) { + result = bsearch(&key, pcbs->un_dgram_pcbs, pcbs->n_un_dgram_pcbs, sizeof(*pcbs->un_dgram_pcbs), cmp_xunpcb_sock_pcb); + } else if (type == SOCK_SEQPACKET) { + result = bsearch(&key, pcbs->un_seqpacket_pcbs, pcbs->n_un_seqpacket_pcbs, sizeof(*pcbs->un_seqpacket_pcbs), cmp_xunpcb_sock_pcb); + } + if (result) { + *xsocket = &result->xu_socket; + *pcb = result; + } + } +} + + /* * process_socket() - process socket */ void -process_socket(sa) - KA_T sa; /* socket address in kernel */ +process_socket(struct kinfo_file *kf, struct pcb_lists *pcbs) { - struct domain d; unsigned char *fa = (unsigned char *)NULL; int fam; int fp, lp; - struct inpcb inp; unsigned char *la = (unsigned char *)NULL; - struct protosw p; - struct socket s; - struct tcpcb t; + void *pcb; + struct xsocket *s; int ts = -1; - struct unpcb uc, unp; struct sockaddr_un *ua = NULL; - struct sockaddr_un un; int unl; -#if defined(HASIPv6) && !defined(HASINRIAIPv6) - struct inpcb in6p; -#endif /* defined(HASIPv6) && !defined(HASINRIAIPv6) */ - (void) snpf(Lf->type, sizeof(Lf->type), "sock"); Lf->inp_ty = 2; /* * Read the socket, protocol, and domain structures. */ - if (!sa) { - enter_nm("no socket address"); - return; - } - if (kread(sa, (char *) &s, sizeof(s))) { - (void) snpf(Namech, Namechl, "can't read socket struct from %s", - print_kptr(sa, (char *)NULL, 0)); - enter_nm(Namech); - return; - } - if (!s.so_type) { - enter_nm("no socket type"); - return; - } - if (!s.so_proto - || kread((KA_T)s.so_proto, (char *)&p, sizeof(p))) { - (void) snpf(Namech, Namechl, "can't read protocol switch from %s", - print_kptr((KA_T)s.so_proto, (char *)NULL, 0)); - enter_nm(Namech); - return; - } - if (!p.pr_domain - || kread((KA_T)p.pr_domain, (char *)&d, sizeof(d))) { - (void) snpf(Namech, Namechl, "can't read domain struct from %s", - print_kptr((KA_T)p.pr_domain, (char *)NULL, 0)); - enter_nm(Namech); - return; - } + find_pcb_and_xsocket(pcbs, + kf->kf_un.kf_sock.kf_sock_domain0, + kf->kf_un.kf_sock.kf_sock_type0, + kf->kf_un.kf_sock.kf_sock_pcb, + &pcb, + &s); /* * Save size information. */ if (Fsize) { if (Lf->access == 'r') - Lf->sz = (SZOFFTYPE)s.so_rcv.SOCK_CC; + Lf->sz = (SZOFFTYPE)kf->kf_un.kf_sock.kf_sock_recvq; else if (Lf->access == 'w') - Lf->sz = (SZOFFTYPE)s.so_snd.SOCK_CC; + Lf->sz = (SZOFFTYPE)kf->kf_un.kf_sock.kf_sock_sendq; else - Lf->sz = (SZOFFTYPE)(s.so_rcv.SOCK_CC + s.so_snd.SOCK_CC); + Lf->sz = (SZOFFTYPE)kf->kf_un.kf_sock.kf_sock_recvq + + (SZOFFTYPE)kf->kf_un.kf_sock.kf_sock_sendq; Lf->sz_def = 1; } else Lf->off_def = 1; #if defined(HASTCPTPIQ) - Lf->lts.rq = s.so_rcv.SOCK_CC; - Lf->lts.sq = s.so_snd.SOCK_CC; + Lf->lts.rq = kf->kf_un.kf_sock.kf_sock_recvq; + Lf->lts.sq = kf->kf_un.kf_sock.kf_sock_sendq; Lf->lts.rqs = Lf->lts.sqs = 1; #endif /* defined(HASTCPTPIQ) */ -#if defined(HASSOOPT) - Lf->lts.ltm = (unsigned int)s.so_linger; - Lf->lts.opt = (unsigned int)s.so_options; - -# if __FreeBSD_version>=1200027 - if (s.so_options & SO_ACCEPTCONN) { - Lf->lts.pqlen = (unsigned int)s.sol_incqlen; - Lf->lts.qlen = (unsigned int)s.sol_qlen; - Lf->lts.qlim = (unsigned int)s.sol_qlimit; - } else { - Lf->lts.rbsz = (unsigned long)s.so_rcv.sb_mbmax; - Lf->lts.sbsz = (unsigned long)s.so_snd.sb_mbmax; - -# if defined(HASSBSTATE) - Lf->lts.sbs_rcv = s.so_rcv.sb_state; - Lf->lts.sbs_snd = s.so_snd.sb_state; -# endif /* defined(HASSBSTATE) */ + if (s) { + Lf->lts.ltm = (unsigned int)s->so_linger; + Lf->lts.opt = (unsigned int)s->so_options; + + if (s->so_options & SO_ACCEPTCONN) { + Lf->lts.pqlen = (unsigned int)s->so_incqlen; + Lf->lts.qlen = (unsigned int)s->so_qlen; + Lf->lts.qlim = (unsigned int)s->so_qlimit; + } else { + Lf->lts.rbsz = (unsigned long)s->so_rcv.sb_mbmax; + Lf->lts.sbsz = (unsigned long)s->so_snd.sb_mbmax; +#if 0 +/* FIXME: later, when xsocket.xsockbuf gets sb_state: */ + Lf->lts.sbs_rcv = s->so_rcv.sb_state; + Lf->lts.sbs_snd = s->so_snd.sb_state; +#endif + } + Lf->lts.pqlens = Lf->lts.qlens = Lf->lts.qlims = Lf->lts.rbszs + = Lf->lts.sbszs = (unsigned char)1; + Lf->lts.ss = (unsigned int)s->so_state; } -# else /* __FreeBSD_version<1200027 */ - Lf->lts.pqlen = (unsigned int)s.so_incqlen; - Lf->lts.qlen = (unsigned int)s.so_qlen; - Lf->lts.qlim = (unsigned int)s.so_qlimit; - Lf->lts.rbsz = (unsigned long)s.so_rcv.sb_mbmax; - Lf->lts.sbsz = (unsigned long)s.so_snd.sb_mbmax; - -# if defined(HASSBSTATE) - Lf->lts.sbs_rcv = s.so_rcv.sb_state; - Lf->lts.sbs_snd = s.so_snd.sb_state; -# endif /* defined(HASSBSTATE) */ -# endif /*__FreeBSD_version>=1200027 */ - - Lf->lts.pqlens = Lf->lts.qlens = Lf->lts.qlims = Lf->lts.rbszs - = Lf->lts.sbszs = (unsigned char)1; - -# if defined(HASSOSTATE) - Lf->lts.ss = (unsigned int)s.so_state; -# endif /* defined(HASSOSTATE) */ -#endif /* defined(HASSOPT) */ - /* * Process socket by the associated domain family. */ - switch ((fam = d.dom_family)) { + switch ((fam = kf->kf_un.kf_sock.kf_sock_domain0)) { /* * Process an Internet domain socket. */ case AF_INET: - -#if defined(HASIPv6) case AF_INET6: -#endif /* defined(HASIPv6) */ if (Fnet) { if (!FnetTy || ((FnetTy == 4) && (fam == AF_INET)) - -#if defined(HASIPv6) || ((FnetTy == 6) && (fam == AF_INET6)) -#endif /* defined(HASIPv6) */ - ) { if (!TcpStIn && !UdpStIn) Lf->sf |= SELNET; } } - printiproto(p.pr_protocol); + printiproto(kf->kf_un.kf_sock.kf_sock_protocol0); -#if defined(HASIPv6) (void) snpf(Lf->type, sizeof(Lf->type), (fam == AF_INET) ? "IPv4" : "IPv6"); -#else /* !defined(HASIPv6) */ - (void) snpf(Lf->type, sizeof(Lf->type), "inet"); -#endif /* defined(HASIPv6) */ -#if defined(HASIPv6) && !defined(HASINRIAIPv6) if (fam == AF_INET6) { - + struct sockaddr_in6 *local_addr6, *foreign_addr6; + local_addr6 = (struct sockaddr_in6 *)&kf->kf_un.kf_sock.kf_sa_local; + foreign_addr6 = (struct sockaddr_in6 *)&kf->kf_un.kf_sock.kf_sa_peer; /* * Read IPv6 protocol control block. */ - if (!s.so_pcb - || kread((KA_T)s.so_pcb, (char *)&in6p, sizeof(in6p))) { + if (!pcb) { (void) snpf(Namech, Namechl, "can't read in6pcb at %s", - print_kptr((KA_T)s.so_pcb, (char *)NULL, 0)); + print_kptr((KA_T)kf->kf_un.kf_sock.kf_sock_pcb, (char *)NULL, 0)); enter_nm(Namech); return; } /* * Save IPv6 address information. */ - if (p.pr_protocol == IPPROTO_TCP) { - if (in6p.in6p_ppcb) { - if ((ts = ckstate((KA_T)s.so_pcb, (KA_T)in6p.in6p_ppcb, - &t, fam)) == 1) - { - return; - } + if (kf->kf_un.kf_sock.kf_sock_protocol0 == IPPROTO_TCP) { + if ((ts = ckstate((struct xtcpcb *)pcb, fam)) == 1) { + return; } } - enter_dev_ch(print_kptr((KA_T)(in6p.in6p_ppcb ? in6p.in6p_ppcb - : s.so_pcb), + enter_dev_ch(print_kptr((KA_T)(kf->kf_un.kf_sock.kf_sock_inpcb ? kf->kf_un.kf_sock.kf_sock_inpcb + : kf->kf_un.kf_sock.kf_sock_pcb), (char *)NULL, 0)); - la = (unsigned char *)&in6p.in6p_laddr; - lp = (int)ntohs(in6p.in6p_lport); - if (!IN6_IS_ADDR_UNSPECIFIED(&in6p.in6p_faddr) - || in6p.in6p_fport) + la = (unsigned char *)&local_addr6->sin6_addr; + lp = (int)ntohs(local_addr6->sin6_port); + if (!IN6_IS_ADDR_UNSPECIFIED(&foreign_addr6->sin6_addr) + || foreign_addr6->sin6_port) { - fa = (unsigned char *)&in6p.in6p_faddr; - fp = (int)ntohs(in6p.in6p_fport); + fa = (unsigned char *)&foreign_addr6->sin6_addr; + fp = (int)ntohs(foreign_addr6->sin6_port); } - } else -#endif /* defined(HASIPv6) && !defined(HASINRIAIPv6) */ - - { + } else { /* - * Read Ipv4 or IPv6 (INRIA) protocol control block. + * Read Ipv4 protocol control block. */ - if (!s.so_pcb - || kread((KA_T) s.so_pcb, (char *) &inp, sizeof(inp))) { - if (!s.so_pcb) { - (void) snpf(Namech, Namechl, "no PCB%s%s", - -#if defined(HASSBSTATE) - (s.so_snd.sb_state & SBS_CANTSENDMORE) ? -#else /* !defined(HASSBSTATE) */ - (s.so_state & SS_CANTSENDMORE) ? -#endif /* defined(HASSBSTATE) */ - - ", CANTSENDMORE" : "", -#if defined(HASSBSTATE) - (s.so_rcv.sb_state & SBS_CANTRCVMORE) ? -#else /* !defined(HASSBSTATE) */ - (s.so_state & SS_CANTRCVMORE) ? -#endif /* defined(HASSBSTATE) */ - - ", CANTRCVMORE" : ""); - } else { - (void) snpf(Namech, Namechl, "can't read inpcb at %s", - print_kptr((KA_T)s.so_pcb, (char *)NULL, 0)); - } + struct sockaddr_in *local_addr = (struct sockaddr_in*)&kf->kf_un.kf_sock.kf_sa_local; + struct sockaddr_in *foreign_addr = (struct sockaddr_in*)&kf->kf_un.kf_sock.kf_sa_peer; + if (!pcb) { +# if 0 +/* FIXME: later, when xsocket.xsockbuf gets sb_state: */ + (void) snpf(Namech, Namechl, "no PCB%s%s", + (s && (s->so_state & SBS_CANTSENDMORE)) ? + ", CANTSENDMORE" : "", + (s && (s->so_rcv.sb_state & SBS_CANTRCVMORE)) ? + ", CANTRCVMORE" : ""); +#else + snpf(Namech, Namechl, "no PCB"); +#endif enter_nm(Namech); return; } - if (p.pr_protocol == IPPROTO_TCP) { - if (inp.inp_ppcb) { - if ((ts = ckstate((KA_T)s.so_pcb, (KA_T)inp.inp_ppcb, - &t, fam)) == 1) - { + if (kf->kf_un.kf_sock.kf_sock_protocol0 == IPPROTO_TCP) { + if ((ts = ckstate((struct xtcpcb *)pcb, fam)) == 1) return; - } - } } - enter_dev_ch(print_kptr((KA_T)(inp.inp_ppcb ? inp.inp_ppcb - : s.so_pcb), + enter_dev_ch(print_kptr((KA_T)(kf->kf_un.kf_sock.kf_sock_inpcb ? kf->kf_un.kf_sock.kf_sock_inpcb + : kf->kf_un.kf_sock.kf_sock_pcb), (char *)NULL, 0)); - lp = (int)ntohs(inp.inp_lport); - if (fam == AF_INET) { - - /* - * Save IPv4 address information. - */ - la = (unsigned char *)&inp.inp_laddr; - if (inp.inp_faddr.s_addr != INADDR_ANY || inp.inp_fport) { - fa = (unsigned char *)&inp.inp_faddr; - fp = (int)ntohs(inp.inp_fport); - } - } + lp = (int)ntohs(local_addr->sin_port); + la = (unsigned char *)&local_addr->sin_addr; -#if defined(HASIPv6) && defined(HASINRIAIPv6) - else { - la = (unsigned char *)&inp.inp_laddr6; - if (!IN6_IS_ADDR_UNSPECIFIED(&inp.inp_faddr6) - || inp.inp_fport) - { - fa = (unsigned char *)&inp.inp_faddr6; - fp = (int)ntohs(inp.inp_fport); - } + /* + * Save IPv4 address information. + */ + if (foreign_addr->sin_addr.s_addr != INADDR_ANY || foreign_addr->sin_port) { + fp = (int)ntohs(foreign_addr->sin_port); + fa = (unsigned char *)&foreign_addr->sin_addr; } -#endif /* defined(HASIPv6) && defined(HASINRIAIPv6) */ } -#if defined(HASIPv6) if ((fam == AF_INET6) && ((la && IN6_IS_ADDR_V4MAPPED((struct in6_addr *)la)) || ((fa && IN6_IS_ADDR_V4MAPPED((struct in6_addr *)fa))))) { @@ -621,7 +553,6 @@ process_socket(sa) fa = (unsigned char *)IPv6_2_IPv4(fa); fam = AF_INET; } -#endif /* defined(HASIPv6) */ /* * Enter local and remote addresses by address family. @@ -629,13 +560,14 @@ process_socket(sa) if (fa || la) (void) ent_inaddr(la, lp, fa, fp, fam); if (ts == 0) { + struct xtcpcb *tcp_pcb = (struct xtcpcb *)pcb; Lf->lts.type = 0; - Lf->lts.state.i = (int)t.t_state; + Lf->lts.state.i = (int)tcp_pcb->t_state; #if defined(HASTCPOPT) - Lf->lts.mss = (unsigned long)t.t_maxseg; + Lf->lts.mss = (unsigned long)tcp_pcb->t_maxseg; Lf->lts.msss = (unsigned char)1; - Lf->lts.topt = (unsigned int)t.t_flags; + Lf->lts.topt = (unsigned int)tcp_pcb->t_flags; #endif /* defined(HASTCPOPT) */ } @@ -645,8 +577,8 @@ process_socket(sa) */ case AF_ROUTE: (void) snpf(Lf->type, sizeof(Lf->type), "rte"); - if (s.so_pcb) - enter_dev_ch(print_kptr((KA_T)(s.so_pcb), (char *)NULL, 0)); + if (s && s->so_pcb) + enter_dev_ch(print_kptr((KA_T)(s->so_pcb), (char *)NULL, 0)); else (void) snpf(Namech, Namechl, "no protocol control block"); if (!Fsize) @@ -656,6 +588,8 @@ process_socket(sa) * Process a Unix domain socket. */ case AF_UNIX: + { + struct xunpcb *unix_pcb = (struct xunpcb *)pcb; if (Funix) Lf->sf |= SELUNX; (void) snpf(Lf->type, sizeof(Lf->type), "unix"); @@ -663,57 +597,15 @@ process_socket(sa) * Read Unix protocol control block and the Unix address structure. */ - enter_dev_ch(print_kptr(sa, (char *)NULL, 0)); - if (kread((KA_T) s.so_pcb, (char *) &unp, sizeof(unp))) { + if (unix_pcb) + enter_dev_ch(print_kptr(unix_pcb->xu_socket.xso_so, (char *)NULL, 0)); + else { (void) snpf(Namech, Namechl, "can't read unpcb at %s", - print_kptr((KA_T)s.so_pcb, (char *)NULL, 0)); - break; - } - if ((struct socket *)sa != unp.unp_socket) { - (void) snpf(Namech, Namechl, "unp_socket (%s) mismatch", - print_kptr((KA_T)unp.unp_socket, (char *)NULL, 0)); + print_kptr(kf->kf_un.kf_sock.kf_sock_pcb, (char *)NULL, 0)); break; } - if (unp.unp_addr) { - - if (kread((KA_T)unp.unp_addr, (char *)&un, sizeof(un))) - - { - (void) snpf(Namech, Namechl, "can't read unp_addr at %s", - print_kptr((KA_T)unp.unp_addr, (char *)NULL, 0)); - break; - } - - ua = &un; + ua = (struct sockaddr_un *)&kf->kf_un.kf_sock.kf_sa_local; - } - if (!ua) { - ua = &un; - (void) bzero((char *)ua, sizeof(un)); - ua->sun_family = AF_UNSPEC; - } - /* - * Print information on Unix socket that has no address bound - * to it, although it may be connected to another Unix domain - * socket as a pipe. - */ - if (ua->sun_family != AF_UNIX) { - if (ua->sun_family == AF_UNSPEC) { - if (unp.unp_conn) { - if (kread((KA_T)unp.unp_conn, (char *)&uc, sizeof(uc))) - (void) snpf(Namech, Namechl, - "can't read unp_conn at %s", - print_kptr((KA_T)unp.unp_conn,(char *)NULL,0)); - else - (void) snpf(Namech, Namechl, "->%s", - print_kptr((KA_T)uc.unp_socket,(char *)NULL,0)); - } else - (void) snpf(Namech, Namechl, "->(none)"); - } else - (void) snpf(Namech, Namechl, "unknown sun_family (%d)", - ua->sun_family); - break; - } if (ua->sun_path[0]) { unl = ua->sun_len - offsetof(struct sockaddr_un, sun_path); @@ -725,9 +617,26 @@ process_socket(sa) Lf->sf |= SELNM; if (ua->sun_path[0] && !Namech[0]) (void) snpf(Namech, Namechl, "%s", ua->sun_path); + } else if (unix_pcb->unp_conn) { + struct xsocket *peer_socket = NULL; + void *peer_pcb; + find_pcb_and_xsocket(pcbs, + kf->kf_un.kf_sock.kf_sock_domain0, + kf->kf_un.kf_sock.kf_sock_type0, + kf->kf_un.kf_sock.kf_sock_unpconn, + &peer_pcb, + &peer_socket); + if (!peer_socket) + (void) snpf(Namech, Namechl, + "can't read unp_conn at %s", + print_kptr((KA_T)unix_pcb->unp_conn,(char *)NULL,0)); + else + (void) snpf(Namech, Namechl, "->%s", + print_kptr((KA_T)peer_socket->xso_so,(char *)NULL,0)); } else - (void) snpf(Namech, Namechl, "no address"); + (void) snpf(Namech, Namechl, "->(none)"); break; + } default: printunkaf(fam, 1); } diff --git a/dialects/freebsd/machine.h b/dialects/freebsd/machine.h index dc1ba56a..f1959140 100644 --- a/dialects/freebsd/machine.h +++ b/dialects/freebsd/machine.h @@ -622,7 +622,7 @@ typedef _Bool bool; #define USE_LIB_IS_FILE_NAMED 1 /* isfn.c */ #define USE_LIB_LKUPDEV 1 /* lkud.c */ #define USE_LIB_PRINTDEVNAME 1 /* pdvn.c */ -#define USE_LIB_PROCESS_FILE 1 /* prfp.c */ +/* #define USE_LIB_PROCESS_FILE 1 */ /* prfp.c */ #define USE_LIB_PRINT_TCPTPI 1 /* ptti.c */ #define USE_LIB_READDEV 1 /* rdev.c */ /* #define USE_LIB_READMNT 1 rmnt.c */