Strange problem with vnodes and sockets
Kiss Tibor
grinder at pro.hu
Sun Mar 7 08:47:13 PST 2004
I want to create a small kernel module which logs the socket operations. So in my module
I have a socket structure, and i want to know which process (thread) owns that.
I try to solve this problem by this way:
...
struct proc *p;
struct vnode *vn;
struct filedesc *fdp;
...
sx_slock(&allproc_lock);
LIST_FOREACH(p, &allproc, p_list) {
PROC_LOCK(p);
if (p->p_fd != NULL) {
fdp = p->p_fd;
FILEDESC_LOCK(fdp);
printf("pid: %d\n", p->p_pid);
printf("fdp->fd_nfiles: %d\n", fdp->fd_nfiles);
printf("fdp->fd_lastfile: %d\n", fdp->fd_lastfile);
for (i=0; i < fdp->fd_nfiles; i++) {
if (fdp->fd_ofiles[i] == NULL) {
continue;
} else {
vn = (struct vnode *) fdp->fd_ofiles[i]->f_data;
printf("%d: %d\n", i, vn->v_type);
if (vn->v_type == VSOCK) {
if (vn->v_un.vu_socket->so_gencnt == pcb->inp_socket->so_gencnt) {
printf("found the socket, pid: %d\n", p->p_pid);
}
}
}
}
FILEDESC_UNLOCK(fdp);
}
PROC_UNLOCK(p);
} /* LIST_FOREACH */
sx_sunlock(&allproc_lock);
If i compile & insert this module, i found some strange things:
...
pid: 816
fdp->fd_nfiles: 20
fdp->fd_lastfile: 6
0: 4
1: 4
2: 4
3: 2048
4: 1
5: 2048
6: 4
pid: 635
fdp->fd_nfiles: 20
fdp->fd_lastfile: 6
0: 4
1: 4
2: 4
3: 2048
4: 4
5: 4
6: 4
...
So how can the v_type 2048? v_type is an enum (vnode.h) with 10 "options":
enum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD };
And the real problem is: why don't find that code any VSOCK type vnode in the
active process list? And how can i find the proc struct for a socket? :)
Thanks,
Tibor Kiss
More information about the freebsd-net
mailing list