From owner-freebsd-hackers@FreeBSD.ORG Thu Sep 21 17:06:16 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org 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 3B2C416A40F for ; Thu, 21 Sep 2006 17:06:16 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from cyrus.watson.org (cyrus.watson.org [209.31.154.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id BCB0A43D5A for ; Thu, 21 Sep 2006 17:06:13 +0000 (GMT) (envelope-from rwatson@FreeBSD.org) Received: from fledge.watson.org (fledge.watson.org [209.31.154.41]) by cyrus.watson.org (Postfix) with ESMTP id 4665746C8D; Thu, 21 Sep 2006 13:06:13 -0400 (EDT) Date: Thu, 21 Sep 2006 18:06:13 +0100 (BST) From: Robert Watson X-X-Sender: robert@fledge.watson.org To: Taras Danko In-Reply-To: <89b086450609200829t2ef4dd9ft13c2051644101ba8@mail.gmail.com> Message-ID: <20060921180348.S56349@fledge.watson.org> References: <89b086450609200829t2ef4dd9ft13c2051644101ba8@mail.gmail.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-hackers@freebsd.org Subject: Re: How to find a certain socket? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Sep 2006 17:06:16 -0000 On Wed, 20 Sep 2006, Taras Danko wrote: > I need to find and close a certain socket from kernel module. My current > implementation iterates over the "allproc" list and checks every process' > file descriptors list to find needed socket. But maybe there is an easier > way to do this? Some nixes have "inpcbtable" which holds all the open > sockets on the system. Is there anything similar in FreeBSD? What are you trying to do, exactly? The semantics of closing sockets open in processes are a bit tricky -- first off, you really don't want to actually close the file descriptor, as the application may misbehave in rather unfortunate ways, such as writing data to the wrong files, etc. So in that sense, what you're doing is better than actually closing the file descriptor, which would cause that to happen. If you're interested only in closing TCP sockets, then the existing tcpkill command may well do what you want. > And the second question: whats the correct way to close the socket which was > found? I'm not sure there's really a "correct" way to go about ripping a socket out from under an application. tcpkill does the next closest thing, which is to simulate a RST on the TCP connection and force it to close, which is propagated up the stack in a way the application will understand. Robert N M Watson Computer Laboratory University of Cambridge > > My implementation: > > ..... > mysocket = myproc->p_fd->fd_ofiles[i]->f_data; > myproc->p_fd->fd_ofiles[i]->f_data = NULL; > myproc->p_fd->fd_ofiles[i]->f_ops = &badfileops; > soclose(mysocket); > ..... > > The socket closes but it causes a kernel panic in 90% of cases and > file descriptor doesnt actualy released (as fstat shows), but is > marked as "error" (because of "badfileops" I suppose). Maybe I should > acqure some mutex lock or something before starting manipulations with > socket? Any exampe code will be very much appreciated. > > Its my first steps in fbsd kernel programming so please xcuse me for > newbie questions. > > Taras Danko. > - - - - - - - - - - - - - - - - - - - - - - > contact me: > email: gortaur@gmail.com > icq: 166956956 > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" >