From owner-freebsd-hackers@FreeBSD.ORG Sun Mar 7 08:47:13 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8D8AD16A4CF for ; Sun, 7 Mar 2004 08:47:13 -0800 (PST) Received: from mail.tvnetwork.hu (zion.tvnetwork.hu [80.95.64.67]) by mx1.FreeBSD.org (Postfix) with SMTP id 6104A43D31 for ; Sun, 7 Mar 2004 08:47:12 -0800 (PST) (envelope-from grinder@ip-184-91.tvnetwork.hu) Received: (qmail 30333 invoked by uid 64014); 7 Mar 2004 16:47:07 -0000 Received: from grinder@ip-184-91.tvnetwork.hu by zion by uid 64011 with qmail-scanner-1.20rc3 (clamuko: 0.60. spamassassin: 2.60. Clear:RC:1:. Processed in 0.021241 secs); 07 Mar 2004 16:47:07 -0000 Received: from unknown (HELO ip-184-91.tvnetwork.hu) (80.95.91.184) by zion.tvnetwork.hu with SMTP; 7 Mar 2004 16:47:07 -0000 Received: by ip-184-91.tvnetwork.hu (Postfix, from userid 1001) id 35BBC3FDE0; Sun, 7 Mar 2004 17:54:54 +0000 (GMT) Date: Sun, 7 Mar 2004 17:54:53 +0000 From: Kiss Tibor To: freebsd-net@freebsd.org Message-ID: <20040307175453.GA44645@PSY.tvnetwork.hu> Mail-Followup-To: freebsd-net@freebsd.org, freebsd-hackers@freebsd.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i cc: freebsd-hackers@freebsd.org Subject: Strange problem with vnodes and sockets X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: grinder@pro.hu List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Mar 2004 16:47:13 -0000 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