tech-net archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: so_rerror
In article <20181103201927.008EA17FDA1%rebar.astron.com@localhost>,
Christos Zoulas <christos%zoulas.com@localhost> wrote:
>On Nov 3, 8:23pm, martin%duskware.de@localhost (Martin Husemann) wrote:
>-- Subject: Re: so_rerror
>
>| On Sat, Nov 03, 2018 at 06:53:49PM +0000, Christos Zoulas wrote:
>|
>| > @@ -537,6 +538,7 @@
>| > so->so_proto = prp;
>| > so->so_send = sosend;
>| > so->so_receive = soreceive;
>| > + so->so_options = sooptions;
>| > #ifdef MBUFTRACE
>| > so->so_rcv.sb_mowner = &prp->pr_domain->dom_mowner;
>| > so->so_snd.sb_mowner = &prp->pr_domain->dom_mowner;
>|
>|
>| I think we need to mask sooptions here or with an accessor function
>| when using the sysctl to write the value. It is likely not a good idea
>| to set e.g. "there is an accept filter running" to on when this is a lie.
>|
>| Maybe we should instead do a boolean sysctl and just set the single bit
>| in sooptions?
>
>I know, I thought about that but then I decided it was simpler and
>more functional to allow everything. I guess I can filter out the
>ones that don't make sense... Stay tuned.
>
Here's a patch that only allows the options that could be useful.
christos
Index: kern/uipc_socket.c
===================================================================
RCS file: /cvsroot/src/sys/kern/uipc_socket.c,v
retrieving revision 1.265
diff -u -u -r1.265 uipc_socket.c
--- kern/uipc_socket.c 3 Sep 2018 16:29:35 -0000 1.265
+++ kern/uipc_socket.c 3 Nov 2018 21:14:53 -0000
@@ -118,6 +118,7 @@
extern const struct fileops socketops;
+static int sooptions;
extern int somaxconn; /* patchable (XXX sysctl) */
int somaxconn = SOMAXCONN;
kmutex_t *softnet_lock;
@@ -537,6 +538,7 @@
so->so_proto = prp;
so->so_send = sosend;
so->so_receive = soreceive;
+ so->so_options = sooptions;
#ifdef MBUFTRACE
so->so_rcv.sb_mowner = &prp->pr_domain->dom_mowner;
so->so_snd.sb_mowner = &prp->pr_domain->dom_mowner;
@@ -1757,6 +1759,7 @@
case SO_OOBINLINE:
case SO_TIMESTAMP:
case SO_NOSIGPIPE:
+ case SO_RERROR:
#ifdef SO_OTIMESTAMP
case SO_OTIMESTAMP:
#endif
@@ -1958,6 +1961,7 @@
case SO_OOBINLINE:
case SO_TIMESTAMP:
case SO_NOSIGPIPE:
+ case SO_RERROR:
#ifdef SO_OTIMESTAMP
case SO_OTIMESTAMP:
#endif
@@ -2522,6 +2526,31 @@
return (error);
}
+/*
+ * sysctl helper routine for kern.sooptions. Ensures that only allowed
+ * options can be set.
+ */
+static int
+sysctl_kern_sooptions(SYSCTLFN_ARGS)
+{
+ int error, new_options;
+ struct sysctlnode node;
+
+ new_options = sooptions;
+ node = *rnode;
+ node.sysctl_data = &new_options;
+ error = sysctl_lookup(SYSCTLFN_CALL(&node));
+ if (error || newp == NULL)
+ return error;
+
+ if (new_options & ~SO_DEFOPTS)
+ return EINVAL;
+
+ sooptions = new_options;
+
+ return 0;
+}
+
static void
sysctl_kern_socket_setup(void)
{
@@ -2542,4 +2571,11 @@
SYSCTL_DESCR("Maximum socket buffer size"),
sysctl_kern_sbmax, 0, NULL, 0,
CTL_KERN, KERN_SBMAX, CTL_EOL);
+
+ sysctl_createv(&socket_sysctllog, 0, NULL, NULL,
+ CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+ CTLTYPE_INT, "sooptions",
+ SYSCTL_DESCR("Default socket options"),
+ sysctl_kern_sooptions, 0, NULL, 0,
+ CTL_KERN, CTL_CREATE, CTL_EOL);
}
Index: kern/uipc_socket2.c
===================================================================
RCS file: /cvsroot/src/sys/kern/uipc_socket2.c,v
retrieving revision 1.132
diff -u -u -r1.132 uipc_socket2.c
--- kern/uipc_socket2.c 3 Sep 2018 16:29:35 -0000 1.132
+++ kern/uipc_socket2.c 3 Nov 2018 21:14:53 -0000
@@ -509,8 +509,10 @@
KASSERT(solocked(so));
so->so_rcv.sb_overflowed++;
- so->so_rerror = ENOBUFS;
- sorwakeup(so);
+ if (so->so_options & SO_RERROR) {
+ so->so_rerror = ENOBUFS;
+ sorwakeup(so);
+ }
}
/*
Index: sys/socket.h
===================================================================
RCS file: /cvsroot/src/sys/sys/socket.h,v
retrieving revision 1.128
diff -u -u -r1.128 socket.h
--- sys/socket.h 16 Sep 2018 20:40:20 -0000 1.128
+++ sys/socket.h 3 Nov 2018 21:14:53 -0000
@@ -132,7 +132,30 @@
#define SO_NOSIGPIPE 0x0800 /* no SIGPIPE from EPIPE */
#define SO_ACCEPTFILTER 0x1000 /* there is an accept filter */
#define SO_TIMESTAMP 0x2000 /* timestamp received dgram traffic */
+#define SO_RERROR 0x4000 /* Keep track of receive errors */
+/* Allowed default option flags */
+#define SO_DEFOPTS (SO_DEBUG|SO_REUSEADDR|SO_KEEPALIVE|SO_DONTROUTE| \
+ SO_BROADCAST|SO_USELOOPBACK|SO_LINGER|SO_OOBINLINE|SO_REUSEPORT| \
+ SO_NOSIGPIPE|SO_TIMESTAMP|SO_RERROR)
+
+#define __SO_OPTION_BITS \
+ "\20" \
+ "\1SO_DEBUG" \
+ "\2SO_ACCEPTCONN" \
+ "\3SO_REUSEADDR" \
+ "\4SO_KEEPALIVE" \
+ "\5SO_DONTROUTE" \
+ "\6SO_BROADCAST" \
+ "\7SO_USELOOPBACK" \
+ "\10SO_LINGER" \
+ "\11SO_OOBINLINE" \
+ "\12SO_REUSEPORT" \
+ "\13SO_OTIMESTAMP" \
+ "\14SO_NOSIGPIPE" \
+ "\15SO_ACCEPTFILTER" \
+ "\16SO_TIMESTAMP" \
+ "\17SO_RERROR"
/*
* Additional options, not kept in so_options.
Home |
Main Index |
Thread Index |
Old Index