diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2013-10-22 16:40:29 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2013-10-22 16:40:29 +0000 |
commit | 1e8e86830088bc4916f73acb3ff1c803a22d0711 (patch) | |
tree | 559b7726aea1589415802d71831be8c99d19b13d /sys | |
parent | d5e889686338eef83539b6067cc6fd1e27214fc8 (diff) |
- add UNIX-domain socket info to struct kinfo_file2
- convert netstat from kvm_getfiles() to kvm_getfile2() using that
- delete kvm_getfiles() and KERN_FILE as no longer used (bump libkvm's major)
- rename kvm_getfile2() to kvm_getfiles(), kinfo_file2 to kinfo_file
and KERN_FILE2 to KERN_FILE.
ok deraadt@, millert@
ports scan sthen@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/kern_sysctl.c | 103 | ||||
-rw-r--r-- | sys/sys/sysctl.h | 25 |
2 files changed, 43 insertions, 85 deletions
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 3781a4c02fc..e21e17708e3 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sysctl.c,v 1.240 2013/07/09 15:37:43 beck Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.241 2013/10/22 16:40:26 guenther Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /*- @@ -72,6 +72,7 @@ #include <sys/protosw.h> #include <sys/timetc.h> #include <sys/evcount.h> +#include <sys/un.h> #include <sys/unpcb.h> #include <sys/mount.h> @@ -121,7 +122,7 @@ int sysctl_sensors(int *, u_int, void *, size_t *, void *, size_t); int sysctl_emul(int *, u_int, void *, size_t *, void *, size_t); int sysctl_cptime2(int *, u_int, void *, size_t *, void *, size_t); -void fill_file2(struct kinfo_file2 *, struct file *, struct filedesc *, +void fill_file(struct kinfo_file *, struct file *, struct filedesc *, int, struct vnode *, struct proc *, struct proc *, int); void fill_kproc(struct proc *, struct kinfo_proc *, int, int); @@ -293,7 +294,7 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, case KERN_EVCOUNT: case KERN_TIMECOUNTER: case KERN_CPTIME2: - case KERN_FILE2: + case KERN_FILE: break; default: return (ENOTDIR); /* overloaded */ @@ -372,11 +373,9 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, case KERN_PROC_CWD: return (sysctl_proc_cwd(name + 1, namelen - 1, oldp, oldlenp, p)); - case KERN_FILE2: - return (sysctl_file2(name + 1, namelen - 1, oldp, oldlenp, p)); -#endif case KERN_FILE: - return (sysctl_file(oldp, oldlenp, p)); + return (sysctl_file(name + 1, namelen - 1, oldp, oldlenp, p)); +#endif case KERN_MBSTAT: return (sysctl_rdstruct(oldp, oldlenp, newp, &mbstat, sizeof(mbstat))); @@ -993,72 +992,9 @@ sysctl_rdstruct(void *oldp, size_t *oldlenp, void *newp, const void *sp, return (error); } -/* - * Get file structures. - */ -int -sysctl_file(char *where, size_t *sizep, struct proc *p) -{ - int buflen, error; - struct file *fp, cfile; - char *start = where; - struct ucred *cred = p->p_ucred; - - buflen = *sizep; - if (where == NULL) { - /* - * overestimate by KERN_FILESLOP files - */ - *sizep = sizeof(filehead) + - (nfiles + KERN_FILESLOP) * sizeof(struct file); - return (0); - } - - /* - * first copyout filehead - */ - if (buflen < sizeof(filehead)) { - *sizep = 0; - return (0); - } - error = copyout((caddr_t)&filehead, where, sizeof(filehead)); - if (error) - return (error); - buflen -= sizeof(filehead); - where += sizeof(filehead); - - /* - * followed by an array of file structures - */ - LIST_FOREACH(fp, &filehead, f_list) { - if (buflen < sizeof(struct file)) { - *sizep = where - start; - return (ENOMEM); - } - - /* Only let the superuser or the owner see some information */ - bcopy(fp, &cfile, sizeof (struct file)); - if (suser(p, 0) != 0 && cred->cr_uid != fp->f_cred->cr_uid) { - cfile.f_offset = (off_t)-1; - cfile.f_rxfer = 0; - cfile.f_wxfer = 0; - cfile.f_seek = 0; - cfile.f_rbytes = 0; - cfile.f_wbytes = 0; - } - error = copyout(&cfile, where, sizeof (struct file)); - if (error) - return (error); - buflen -= sizeof(struct file); - where += sizeof(struct file); - } - *sizep = where - start; - return (0); -} - #ifndef SMALL_KERNEL void -fill_file2(struct kinfo_file2 *kf, struct file *fp, struct filedesc *fdp, +fill_file(struct kinfo_file *kf, struct file *fp, struct filedesc *fdp, int fd, struct vnode *vp, struct proc *pp, struct proc *p, int show_pointers) { @@ -1139,8 +1075,12 @@ fill_file2(struct kinfo_file2 *kf, struct file *fp, struct filedesc *fdp, kf->so_state = so->so_state; if (show_pointers) kf->so_pcb = PTRTOINT64(so->so_pcb); + else + kf->so_pcb = -1; kf->so_protocol = so->so_proto->pr_protocol; kf->so_family = so->so_proto->pr_domain->dom_family; + kf->so_rcv_cc = so->so_rcv.sb_cc; + kf->so_snd_cc = so->so_snd.sb_cc; if (so->so_splice) { if (show_pointers) kf->so_splice = PTRTOINT64(so->so_splice); @@ -1182,8 +1122,19 @@ fill_file2(struct kinfo_file2 *kf, struct file *fp, struct filedesc *fdp, case AF_UNIX: { struct unpcb *unpcb = so->so_pcb; - if (show_pointers) - kf->unp_conn = PTRTOINT64(unpcb->unp_conn); + if (show_pointers) { + kf->unp_conn = PTRTOINT64(unpcb->unp_conn); + kf->unp_refs = PTRTOINT64(unpcb->unp_refs); + kf->unp_nextref = PTRTOINT64(unpcb->unp_nextref); + kf->v_un = PTRTOINT64(unpcb->unp_vnode); + kf->unp_addr = PTRTOINT64(unpcb->unp_addr); + } + if (unpcb->unp_addr != NULL) { + struct sockaddr_un *un = mtod(unpcb->unp_addr, + struct sockaddr_un *); + memcpy(kf->unp_path, un->sun_path, un->sun_len + - offsetof(struct sockaddr_un,sun_path)); + } break; } } @@ -1230,10 +1181,10 @@ fill_file2(struct kinfo_file2 *kf, struct file *fp, struct filedesc *fdp, * Get file structures. */ int -sysctl_file2(int *name, u_int namelen, char *where, size_t *sizep, +sysctl_file(int *name, u_int namelen, char *where, size_t *sizep, struct proc *p) { - struct kinfo_file2 *kf; + struct kinfo_file *kf; struct filedesc *fdp; struct file *fp; struct proc *pp; @@ -1264,7 +1215,7 @@ sysctl_file2(int *name, u_int namelen, char *where, size_t *sizep, #define FILLIT(fp, fdp, i, vp, pp) do { \ if (buflen >= elem_size && elem_count > 0) { \ - fill_file2(kf, fp, fdp, i, vp, pp, p, show_pointers); \ + fill_file(kf, fp, fdp, i, vp, pp, p, show_pointers); \ error = copyout(kf, dp, outsize); \ if (error) \ break; \ diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index 19bfee3c48e..02317a71132 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sysctl.h,v 1.138 2013/09/22 17:28:33 guenther Exp $ */ +/* $OpenBSD: sysctl.h,v 1.139 2013/10/22 16:40:26 guenther Exp $ */ /* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */ /* @@ -115,7 +115,7 @@ struct ctlname { #define KERN_CLOCKRATE 12 /* struct: struct clockinfo */ #define KERN_VNODE 13 /* struct: vnode structures */ /*define gap: was KERN_PROC 14 */ -#define KERN_FILE 15 /* struct: file entries */ +/*define gap: was KERN_FILE 15 */ #define KERN_PROF 16 /* node: kernel profiling info */ #define KERN_POSIX1 17 /* int: POSIX.1 version */ #define KERN_NGROUPS 18 /* int: # of supplemental group ids */ @@ -173,7 +173,7 @@ struct ctlname { #define KERN_MAXLOCKSPERUID 70 /* int: locks per uid */ #define KERN_CPTIME2 71 /* array: cp_time2 */ #define KERN_CACHEPCT 72 /* buffer cache % of physmem */ -#define KERN_FILE2 73 /* struct: file entries */ +#define KERN_FILE 73 /* struct: file entries */ /* was define KERN_RTHREADS 74 */ #define KERN_CONSDEV 75 /* dev_t: console terminal device */ #define KERN_NETLIVELOCKS 76 /* int: number of network livelocks */ @@ -197,7 +197,7 @@ struct ctlname { { "clockrate", CTLTYPE_STRUCT }, \ { "vnode", CTLTYPE_STRUCT }, \ { "gap", 0 }, \ - { "file", CTLTYPE_STRUCT }, \ + { "gap", 0 }, \ { "profiling", CTLTYPE_NODE }, \ { "posix1version", CTLTYPE_INT }, \ { "ngroups", CTLTYPE_INT }, \ @@ -255,7 +255,7 @@ struct ctlname { { "maxlocksperuid", CTLTYPE_INT }, \ { "cp_time2", CTLTYPE_STRUCT }, \ { "bufcachepercent", CTLTYPE_INT }, \ - { "file2", CTLTYPE_STRUCT }, \ + { "file", CTLTYPE_STRUCT }, \ { "gap", 0 }, \ { "consdev", CTLTYPE_STRUCT }, \ { "netlivelocks", CTLTYPE_INT }, \ @@ -608,7 +608,7 @@ do { \ /* - * kern.file2 returns an array of these structures, which are designed + * kern.file returns an array of these structures, which are designed * both to be immune to 32/64 bit emulation issues and to * provide backwards compatibility. The order differs slightly from * that of the real struct file, and some fields are taken from other @@ -626,8 +626,9 @@ do { \ #define KERN_FILE_TRACE -4 #define KI_MNAMELEN 96 /* rounded up from 90 */ +#define KI_UNPPATHLEN 104 -struct kinfo_file2 { +struct kinfo_file { uint64_t f_fileaddr; /* PTR: address of struct file */ uint32_t f_flag; /* SHORT: flags (see fcntl.h) */ uint32_t f_iflags; /* INT: internal flags */ @@ -665,6 +666,7 @@ struct kinfo_file2 { uint32_t so_type; /* SHORT: socket type */ uint32_t so_state; /* SHORT: socket state */ uint64_t so_pcb; /* PTR: socket pcb */ + /* for non-root: -1 if not NULL */ uint32_t so_protocol; /* SHORT: socket protocol type */ uint32_t so_family; /* INT: socket domain family */ uint64_t inp_ppcb; /* PTR: pointer to per-protocol pcb */ @@ -699,6 +701,12 @@ struct kinfo_file2 { uint64_t so_splice; /* PTR: f_data of spliced socket */ int64_t so_splicelen; /* OFF_T: already spliced count or */ /* -1 if this is target of splice */ + uint64_t so_rcv_cc; /* LONG: chars in receive buf */ + uint64_t so_snd_cc; /* LONG: chars in send buf */ + uint64_t unp_refs; /* PTR: connected sockets */ + uint64_t unp_nextref; /* PTR: link to next connected socket */ + uint64_t unp_addr; /* PTR: address of the socket address */ + char unp_path[KI_UNPPATHLEN]; }; /* @@ -879,8 +887,7 @@ int sysctl__string(void *, size_t *, void *, size_t, char *, int, int); int sysctl_rdstring(void *, size_t *, void *, const char *); int sysctl_rdstruct(void *, size_t *, void *, const void *, int); int sysctl_struct(void *, size_t *, void *, size_t, void *, int); -int sysctl_file(char *, size_t *, struct proc *); -int sysctl_file2(int *, u_int, char *, size_t *, struct proc *); +int sysctl_file(int *, u_int, char *, size_t *, struct proc *); int sysctl_doproc(int *, u_int, char *, size_t *); struct radix_node; struct walkarg; |