From owner-freebsd-current@FreeBSD.ORG Tue Aug 26 10:16:53 2014 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D6823F53 for ; Tue, 26 Aug 2014 10:16:53 +0000 (UTC) Received: from mail-ie0-x236.google.com (mail-ie0-x236.google.com [IPv6:2607:f8b0:4001:c03::236]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id A0D5F3438 for ; Tue, 26 Aug 2014 10:16:53 +0000 (UTC) Received: by mail-ie0-f182.google.com with SMTP id y20so11280171ier.41 for ; Tue, 26 Aug 2014 03:16:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=2tlSmFODec+2wi2/EBCKLyte2emPSfzkytFDSF0rhjQ=; b=Ycw5W3saTvLbMsrrTNhb1H9By8w2+b+aWQcq0b0wedzUoMBo/WPRyYkcf5mDuHh4UA 74GhRXsTRfOWrcLHP2W8VmGsZvXiX+uWPtFbb93PtNgWWSd5Xqrlxvdzrnz+GAV5CKsl x6jKYZsPlg9TpQDdA6YNkhyiQL6hH+7PT2jkkx8AFJgXZ7WmeZyF+6hZtvsfO8yan2vY oR6J36BAEUaRALm27y/GnzZy7YhOWA5MmGBqVLctLsQVoMh55t2OCYnXeTg3x3Ajj3K7 fGEC+OkcvdpdNiIFELMjeUhl5aCzYLc8AncLM9u/SafwPwo3RLpE40xytGcqrIOUPh/y tszg== X-Received: by 10.50.55.68 with SMTP id q4mr21093083igp.44.1409048212982; Tue, 26 Aug 2014 03:16:52 -0700 (PDT) MIME-Version: 1.0 Sender: fedor.indutny@gmail.com Received: by 10.107.28.20 with HTTP; Tue, 26 Aug 2014 03:16:32 -0700 (PDT) In-Reply-To: <53FC57EC.2000107@gmail.com> References: <53FC57EC.2000107@gmail.com> From: Fedor Indutny Date: Tue, 26 Aug 2014 14:16:32 +0400 X-Google-Sender-Auth: UHjPWn3hdl-hNXzEVBqnvEbBYjM Message-ID: Subject: Re: KQueue 0-length UDP packet To: =?UTF-8?Q?Jan_Kokem=C3=BCller?= Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.18-1 Cc: freebsd-current@freebsd.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Aug 2014 10:16:53 -0000 Ok, thanks for a clarification! On Tue, Aug 26, 2014 at 1:48 PM, Jan Kokem=C3=BCller wrote: > Hi, > > > What I wanted to ask is: why does FreeBSD kqueue implementation treat >> `SO_RCVLOWAT` as a raw packet size watermark, and not using the actual >> data size for filtering out events? >> > > It looks like SO_RCVLOWAT refers to the number of bytes in the socket > buffer, not raw packet bytes. In the case of an arriving UDP packet there > is always a 'struct sockaddr' in the buffer that contains the source > address/port of the message. For IPv4 this is 16 bytes and for IPv6 28 > bytes. I think this is intended behavior, as this is data you can "read" > with recvfrom or recvmsg. > > POSIX says "Receive calls may still return less than the low water mark i= f > an error occurs, a signal is caught, or the type of data next in the > receive queue is different from that returned (for example, out-of-band > data)." So in this case this data is address data. > > On the other hand, NOTE_LOWAT from kevent refers to data/protocol bytes. > The semantics were changed in 2002: > http://marc.info/?l=3Dfreebsd-arch&m=3D103587526507822&w=3D2 > The value you get in 'data' also refers to the number of protocol data > bytes available. > > I've had a look at how OpenBSD handles this. It returns the number of > protocol data bytes with "ioctl(s, FIONREAD, &len)" but the number of byt= es > in the socket buffer in the 'data' member of kevent, so exactly the other > way around compared to FreeBSD. SO_RCVLOWAT works still the same, though. > > Cheers, > Jan >