summaryrefslogtreecommitdiffstats
path: root/lib/libkvm/kvm_file2.c
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2013-10-22 16:40:25 +0000
committerguenther <guenther@openbsd.org>2013-10-22 16:40:25 +0000
commitcef0bbe1cc5517635356b7faa348b466660ec603 (patch)
tree8a975e0739a2b36fd5200d33c430980754b92498 /lib/libkvm/kvm_file2.c
parent- expand hardware list with iMX boards (diff)
downloadwireguard-openbsd-cef0bbe1cc5517635356b7faa348b466660ec603.tar.xz
wireguard-openbsd-cef0bbe1cc5517635356b7faa348b466660ec603.zip
- 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 'lib/libkvm/kvm_file2.c')
-rw-r--r--lib/libkvm/kvm_file2.c102
1 files changed, 65 insertions, 37 deletions
diff --git a/lib/libkvm/kvm_file2.c b/lib/libkvm/kvm_file2.c
index 5a5eb9efeb0..eef2c41ce32 100644
--- a/lib/libkvm/kvm_file2.c
+++ b/lib/libkvm/kvm_file2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_file2.c,v 1.27 2013/03/20 14:46:45 deraadt Exp $ */
+/* $OpenBSD: kvm_file2.c,v 1.28 2013/10/22 16:40:26 guenther Exp $ */
/*
* Copyright (c) 2009 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -70,8 +70,10 @@
#include <sys/protosw.h>
#include <sys/event.h>
#include <sys/eventvar.h>
+#include <sys/un.h>
#include <sys/unpcb.h>
#include <sys/filedesc.h>
+#include <sys/mbuf.h>
#include <sys/pipe.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
@@ -105,6 +107,7 @@
#include <nlist.h>
#include <kvm.h>
#include <db.h>
+#include <stddef.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
@@ -112,18 +115,18 @@
#include "kvm_private.h"
-static struct kinfo_file2 *kvm_deadfile2_byfile(kvm_t *, int, int,
+static struct kinfo_file *kvm_deadfile_byfile(kvm_t *, int, int,
size_t, int *);
-static struct kinfo_file2 *kvm_deadfile2_byid(kvm_t *, int, int,
+static struct kinfo_file *kvm_deadfile_byid(kvm_t *, int, int,
size_t, int *);
-static int fill_file2(kvm_t *, struct kinfo_file2 *, struct file *, u_long,
+static int fill_file(kvm_t *, struct kinfo_file *, struct file *, u_long,
struct vnode *, struct proc *, int, pid_t);
-static int filestat(kvm_t *, struct kinfo_file2 *, struct vnode *);
+static int filestat(kvm_t *, struct kinfo_file *, struct vnode *);
LIST_HEAD(proclist, proc);
-struct kinfo_file2 *
-kvm_getfile2(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
+struct kinfo_file *
+kvm_getfiles(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
{
int mib[6], rv;
size_t size;
@@ -139,7 +142,7 @@ kvm_getfile2(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
if (ISALIVE(kd)) {
mib[0] = CTL_KERN;
- mib[1] = KERN_FILE2;
+ mib[1] = KERN_FILE;
mib[2] = op;
mib[3] = arg;
mib[4] = esize;
@@ -150,7 +153,7 @@ kvm_getfile2(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
if (rv == -1) {
if (kd->vmfd != -1)
goto deadway;
- _kvm_syserr(kd, kd->program, "kvm_getfile2");
+ _kvm_syserr(kd, kd->program, "kvm_getfiles");
return (NULL);
}
kd->filebase = _kvm_malloc(kd, size);
@@ -161,15 +164,15 @@ kvm_getfile2(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
mib[5] = size / esize;
rv = sysctl(mib, 6, kd->filebase, &size, NULL, 0);
if (rv == -1) {
- _kvm_syserr(kd, kd->program, "kvm_getfile2");
+ _kvm_syserr(kd, kd->program, "kvm_getfiles");
return (NULL);
}
*cnt = size / esize;
- return ((struct kinfo_file2 *)kd->filebase);
+ return ((struct kinfo_file *)kd->filebase);
} else {
- if (esize > sizeof(struct kinfo_file2)) {
+ if (esize > sizeof(struct kinfo_file)) {
_kvm_syserr(kd, kd->program,
- "kvm_getfile2: unknown fields requested: libkvm out of date?");
+ "kvm_getfiles: unknown fields requested: libkvm out of date?");
return (NULL);
}
deadway:
@@ -180,11 +183,11 @@ kvm_getfile2(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
"%s: invalid argument");
return (NULL);
}
- return (kvm_deadfile2_byfile(kd, op, arg, esize, cnt));
+ return (kvm_deadfile_byfile(kd, op, arg, esize, cnt));
break;
case KERN_FILE_BYPID:
case KERN_FILE_BYUID:
- return (kvm_deadfile2_byid(kd, op, arg, esize, cnt));
+ return (kvm_deadfile_byid(kd, op, arg, esize, cnt));
break;
default:
return (NULL);
@@ -192,14 +195,14 @@ kvm_getfile2(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
}
}
-static struct kinfo_file2 *
-kvm_deadfile2_byfile(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
+static struct kinfo_file *
+kvm_deadfile_byfile(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
{
struct nlist nl[3], *p;
size_t buflen;
int n = 0;
char *where;
- struct kinfo_file2 kf;
+ struct kinfo_file kf;
struct file *fp, file;
struct filelist filehead;
int nfiles;
@@ -236,7 +239,7 @@ kvm_deadfile2_byfile(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
_kvm_err(kd, kd->program, "can't read kfp");
return (NULL);
}
- if (fill_file2(kd, &kf, &file, (u_long)fp, NULL, NULL, 0, 0)
+ if (fill_file(kd, &kf, &file, (u_long)fp, NULL, NULL, 0, 0)
== -1)
return (NULL);
memcpy(where, &kf, esize);
@@ -249,17 +252,17 @@ kvm_deadfile2_byfile(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
return (NULL);
}
*cnt = n;
- return ((struct kinfo_file2 *)kd->filebase);
+ return ((struct kinfo_file *)kd->filebase);
}
-static struct kinfo_file2 *
-kvm_deadfile2_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
+static struct kinfo_file *
+kvm_deadfile_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
{
size_t buflen;
struct nlist nl[4], *np;
int n = 0;
char *where;
- struct kinfo_file2 kf;
+ struct kinfo_file kf;
struct file *fp, file;
struct filelist filehead;
struct filedesc0 filed0;
@@ -389,7 +392,7 @@ kvm_deadfile2_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
if (proc.p_textvp) {
if (buflen < esize)
goto done;
- if (fill_file2(kd, &kf, NULL, 0, proc.p_textvp, &proc,
+ if (fill_file(kd, &kf, NULL, 0, proc.p_textvp, &proc,
KERN_FILE_TEXT, pid) == -1)
goto cleanup;
memcpy(where, &kf, esize);
@@ -400,7 +403,7 @@ kvm_deadfile2_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
if (filed.fd_cdir) {
if (buflen < esize)
goto done;
- if (fill_file2(kd, &kf, NULL, 0, filed.fd_cdir, &proc,
+ if (fill_file(kd, &kf, NULL, 0, filed.fd_cdir, &proc,
KERN_FILE_CDIR, pid) == -1)
goto cleanup;
memcpy(where, &kf, esize);
@@ -411,7 +414,7 @@ kvm_deadfile2_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
if (filed.fd_rdir) {
if (buflen < esize)
goto done;
- if (fill_file2(kd, &kf, NULL, 0, filed.fd_rdir, &proc,
+ if (fill_file(kd, &kf, NULL, 0, filed.fd_rdir, &proc,
KERN_FILE_RDIR, pid) == -1)
goto cleanup;
memcpy(where, &kf, esize);
@@ -422,7 +425,7 @@ kvm_deadfile2_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
if (process.ps_tracevp) {
if (buflen < esize)
goto done;
- if (fill_file2(kd, &kf, NULL, 0, process.ps_tracevp,
+ if (fill_file(kd, &kf, NULL, 0, process.ps_tracevp,
&proc, KERN_FILE_TRACE, pid) == -1)
goto cleanup;
memcpy(where, &kf, esize);
@@ -449,7 +452,7 @@ kvm_deadfile2_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
_kvm_err(kd, kd->program, "can't read file");
goto cleanup;
}
- if (fill_file2(kd, &kf, &file, (u_long)fp, NULL,
+ if (fill_file(kd, &kf, &file, (u_long)fp, NULL,
&proc, i, pid) == -1)
goto cleanup;
memcpy(where, &kf, esize);
@@ -461,14 +464,14 @@ kvm_deadfile2_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
done:
*cnt = n;
free(filebuf);
- return ((struct kinfo_file2 *)kd->filebase);
+ return ((struct kinfo_file *)kd->filebase);
cleanup:
free(filebuf);
return (NULL);
}
static int
-fill_file2(kvm_t *kd, struct kinfo_file2 *kf, struct file *fp, u_long fpaddr, struct vnode *vp,
+fill_file(kvm_t *kd, struct kinfo_file *kf, struct file *fp, u_long fpaddr, struct vnode *vp,
struct proc *p, int fd, pid_t pid)
{
struct ucred f_cred;
@@ -570,6 +573,8 @@ fill_file2(kvm_t *kd, struct kinfo_file2 *kf, struct file *fp, u_long fpaddr, st
return (-1);
}
kf->so_family = domain.dom_family;
+ kf->so_rcv_cc = sock.so_rcv.sb_cc;
+ kf->so_snd_cc = sock.so_snd.sb_cc;
if (sock.so_splice) {
kf->so_splice = PTRTOINT64(sock.so_splice);
kf->so_splicelen = sock.so_splicelen;
@@ -622,7 +627,30 @@ fill_file2(kvm_t *kd, struct kinfo_file2 *kf, struct file *fp, u_long fpaddr, st
_kvm_err(kd, kd->program, "can't read unpcb");
return (-1);
}
- kf->unp_conn = PTRTOINT64(unpcb.unp_conn);
+ 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);
+ if (unpcb.unp_addr != NULL) {
+ struct mbuf mb;
+ struct sockaddr_un un;
+
+ if (KREAD(kd, (u_long)unpcb.unp_addr, &mb)) {
+ _kvm_err(kd, kd->program,
+ "can't read sockaddr_un mbuf");
+ return (-1);
+ }
+ if (KREAD(kd, (u_long)mb.m_data, &un)) {
+ _kvm_err(kd, kd->program,
+ "can't read sockaddr_un");
+ return (-1);
+ }
+
+ kf->unp_addr = PTRTOINT64(unpcb.unp_addr);
+ memcpy(kf->unp_path, un.sun_path, un.sun_len
+ - offsetof(struct sockaddr_un,sun_path));
+ }
+
break;
}
}
@@ -714,7 +742,7 @@ _kvm_getftype(enum vtype v_type)
}
static int
-ufs_filestat(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp)
+ufs_filestat(kvm_t *kd, struct kinfo_file *kf, struct vnode *vp)
{
struct inode inode;
struct ufs1_dinode di1;
@@ -742,7 +770,7 @@ ufs_filestat(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp)
}
static int
-ext2fs_filestat(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp)
+ext2fs_filestat(kvm_t *kd, struct kinfo_file *kf, struct vnode *vp)
{
struct inode inode;
struct ext2fs_dinode e2di;
@@ -770,7 +798,7 @@ ext2fs_filestat(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp)
}
static int
-msdos_filestat(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp)
+msdos_filestat(kvm_t *kd, struct kinfo_file *kf, struct vnode *vp)
{
struct denode de;
struct msdosfsmount mp;
@@ -795,7 +823,7 @@ msdos_filestat(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp)
}
static int
-nfs_filestat(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp)
+nfs_filestat(kvm_t *kd, struct kinfo_file *kf, struct vnode *vp)
{
struct nfsnode nfsnode;
@@ -814,7 +842,7 @@ nfs_filestat(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp)
}
static int
-spec_filestat(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp)
+spec_filestat(kvm_t *kd, struct kinfo_file *kf, struct vnode *vp)
{
struct specinfo specinfo;
struct vnode parent;
@@ -840,7 +868,7 @@ spec_filestat(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp)
}
static int
-filestat(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp)
+filestat(kvm_t *kd, struct kinfo_file *kf, struct vnode *vp)
{
int ret = 0;