From owner-freebsd-hackers@freebsd.org Thu Jun 16 16:44:18 2016 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 83A45A47B07 for ; Thu, 16 Jun 2016 16:44:18 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 58A9F187F for ; Thu, 16 Jun 2016 16:44:18 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from ralph.baldwin.cx (c-73-231-226-104.hsd1.ca.comcast.net [73.231.226.104]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id E2AA5B948; Thu, 16 Jun 2016 12:44:16 -0400 (EDT) From: John Baldwin To: freebsd-hackers@freebsd.org Cc: Julian Kornberger Subject: Re: Usage of sosend() and its context Date: Thu, 16 Jun 2016 09:40:03 -0700 Message-ID: <2110371.3nz8SNp04Y@ralph.baldwin.cx> User-Agent: KMail/4.14.3 (FreeBSD/10.3-STABLE; KDE/4.14.3; amd64; ; ) In-Reply-To: <575F20CF.1020103@kornberger.name> References: <575F20CF.1020103@kornberger.name> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Thu, 16 Jun 2016 12:44:17 -0400 (EDT) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jun 2016 16:44:18 -0000 On Monday, June 13, 2016 11:08:31 PM Julian Kornberger wrote: > Hi, > > I am building a kernel module for fastd [1] and have the problem, that > on one of three machines the sosend() call seems to block. I use > sosend() [2] in a tunneling function that is set by > udp_set_kernel_tunneling(). > > Since I don't know which thread to pass to sosend() I just use > curthread. Is it possible that I should not use sosend() in this context > and instead build the IP packet manually and pass it to ip_output()? Any > other hints? > > [1] https://fastd.readthedocs.io/ > [2] > https://github.com/digineo/fastd/blob/97fd40b9992778a3bf11756f41aa7c2615bba2f3/kmod/fastd.c#L664 It's possible to ask sosend() to not block and fail with EWOULDBLOCK instead by passing MSG_NOWAIT in flags. However, you might still block on sblock(), so you may need to defer your work to a sleepable context using something like a taskqueue. -- John Baldwin