Usage of sosend() and its context

John Baldwin jhb at freebsd.org
Thu Jun 16 16:44:18 UTC 2016


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


More information about the freebsd-hackers mailing list