From owner-freebsd-net@FreeBSD.ORG Tue Jan 15 08:49:35 2013 Return-Path: Delivered-To: net@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 1CF0F3DF; Tue, 15 Jan 2013 08:49:35 +0000 (UTC) (envelope-from lstewart@freebsd.org) Received: from lauren.room52.net (lauren.room52.net [210.50.193.198]) by mx1.freebsd.org (Postfix) with ESMTP id A7E3A683; Tue, 15 Jan 2013 08:49:34 +0000 (UTC) Received: from lstewart1.loshell.room52.net (ppp59-167-184-191.static.internode.on.net [59.167.184.191]) by lauren.room52.net (Postfix) with ESMTPSA id 784E17E88D; Tue, 15 Jan 2013 19:49:33 +1100 (EST) Message-ID: <50F5181D.6020508@freebsd.org> Date: Tue, 15 Jan 2013 19:49:33 +1100 From: Lawrence Stewart User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:13.0) Gecko/20120613 Thunderbird/13.0 MIME-Version: 1.0 To: John Baldwin Subject: Re: [PATCH] Don't imply TCP and UDP socket options are bitmasks References: <201301141550.13577.jhb@freebsd.org> In-Reply-To: <201301141550.13577.jhb@freebsd.org> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=0.0 required=5.0 tests=T_FRT_STOCK2, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on lauren.room52.net Cc: net@freebsd.org X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Jan 2013 08:49:35 -0000 On 01/15/13 07:50, John Baldwin wrote: > The constants used for TCP and UDP socket options (TCP_NODELAY, etc.) are > currently defined as hex values that are individual bits. However, socket > options are never masked together, they are used as a simple enumeration of > discrete values. Using a bitmask forces us to run out of bits and makes it > harder for vendors to try to use a high range of values for local custom > options (hoping that they never conflict with a new option value added in > stock FreeBSD). Yup. Should we be explicitly #defining the boundary between "bits reserved for FreeBSD" and "bits for private vendor use"? > The socket options in do use bitmasks for the low bits because > they map directly to bits so_options, but then they start a simple enumeration > at 0x1000. TCP and UDP socket options do not directly map to bits in a flags > field in the PCB (e.g. TF_NODELAY != TCP_NODELAY). I would like to change the > representation of the constants to be decimal instead of hex and encourage new > options to fill in the gaps between the existing values. This would preserve > the existing ABI but keep things more sane in the future (I believe). The > diff is this: > > Index: netinet/tcp.h > =================================================================== > --- netinet/tcp.h (revision 245225) > +++ netinet/tcp.h (working copy) > @@ -151,18 +151,18 @@ > /* > * User-settable options (used with setsockopt). > */ > -#define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */ > +#define TCP_NODELAY 1 /* don't delay send to coalesce packets */ > #if __BSD_VISIBLE > -#define TCP_MAXSEG 0x02 /* set maximum segment size */ > -#define TCP_NOPUSH 0x04 /* don't push last block of write */ > -#define TCP_NOOPT 0x08 /* don't use TCP options */ > -#define TCP_MD5SIG 0x10 /* use MD5 digests (RFC2385) */ > -#define TCP_INFO 0x20 /* retrieve tcp_info structure */ > -#define TCP_CONGESTION 0x40 /* get/set congestion control algorithm */ > -#define TCP_KEEPINIT 0x80 /* N, time to establish connection */ > -#define TCP_KEEPIDLE 0x100 /* L,N,X start keeplives after this period */ > -#define TCP_KEEPINTVL 0x200 /* L,N interval between keepalives */ > -#define TCP_KEEPCNT 0x400 /* L,N number of keepalives before close */ > +#define TCP_MAXSEG 2 /* set maximum segment size */ > +#define TCP_NOPUSH 4 /* don't push last block of write */ > +#define TCP_NOOPT 8 /* don't use TCP options */ > +#define TCP_MD5SIG 16 /* use MD5 digests (RFC2385) */ > +#define TCP_INFO 32 /* retrieve tcp_info structure */ > +#define TCP_CONGESTION 64 /* get/set congestion control algorithm */ > +#define TCP_KEEPINIT 128 /* N, time to establish connection */ > +#define TCP_KEEPIDLE 256 /* L,N,X start keeplives after this period */ > +#define TCP_KEEPINTVL 512 /* L,N interval between keepalives */ > +#define TCP_KEEPCNT 1024 /* L,N number of keepalives before close */ > > #define TCP_CA_NAME_MAX 16 /* max congestion control name length */ > > Index: netinet/udp.h > =================================================================== > --- netinet/udp.h (revision 245225) > +++ netinet/udp.h (working copy) > @@ -48,7 +48,7 @@ > /* > * User-settable options (used with setsockopt). > */ > -#define UDP_ENCAP 0x01 > +#define UDP_ENCAP 1 > > > /* > Thumbs up from me, modulo a potential tweak to define the boundary for FreeBSD/private use. Cheers, Lawrence