Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Introduce a more general method of sbcreatecontrol, sbcr...



details:   https://anonhg.NetBSD.org/src/rev/8c559bc96a5f
branches:  trunk
changeset: 787649:8c559bc96a5f
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jun 27 18:53:17 2013 +0000

description:
Introduce a more general method of sbcreatecontrol, sbcreatecontrol1 that
can take flags (M_WAITOK), and allocate large messages if needed. It also
returns the allocated pointer instead of copying the data to the passed
pointer. Implement sbcreatecontrol() using that.

diffstat:

 sys/kern/uipc_socket2.c |  41 +++++++++++++++++++++++++++++------------
 sys/sys/socketvar.h     |   4 +++-
 2 files changed, 32 insertions(+), 13 deletions(-)

diffs (96 lines):

diff -r 49741112470a -r 8c559bc96a5f sys/kern/uipc_socket2.c
--- a/sys/kern/uipc_socket2.c   Thu Jun 27 17:47:18 2013 +0000
+++ b/sys/kern/uipc_socket2.c   Thu Jun 27 18:53:17 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_socket2.c,v 1.110 2011/12/20 23:56:28 christos Exp $      */
+/*     $NetBSD: uipc_socket2.c,v 1.111 2013/06/27 18:53:17 christos Exp $      */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.110 2011/12/20 23:56:28 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.111 2013/06/27 18:53:17 christos Exp $");
 
 #include "opt_mbuftrace.h"
 #include "opt_sb_max.h"
@@ -1301,32 +1301,49 @@
  * with the specified type for presentation on a socket buffer.
  */
 struct mbuf *
-sbcreatecontrol(void *p, int size, int type, int level)
+sbcreatecontrol1(void **p, int size, int type, int level, int flags)
 {
        struct cmsghdr  *cp;
        struct mbuf     *m;
+       int space = CMSG_SPACE(size);
 
-       if (CMSG_SPACE(size) > MCLBYTES) {
-               printf("sbcreatecontrol: message too large %d\n", size);
+       if ((flags & M_DONTWAIT) && space > MCLBYTES) {
+               printf("%s: message too large %d\n", __func__, space);
                return NULL;
        }
 
-       if ((m = m_get(M_DONTWAIT, MT_CONTROL)) == NULL)
-               return (NULL);
-       if (CMSG_SPACE(size) > MLEN) {
-               MCLGET(m, M_DONTWAIT);
+       if ((m = m_get(flags, MT_CONTROL)) == NULL)
+               return NULL;
+       if (space > MLEN) {
+               if (space > MCLBYTES)
+                       MEXTMALLOC(m, space, M_WAITOK);
+               else
+                       MCLGET(m, flags);
                if ((m->m_flags & M_EXT) == 0) {
                        m_free(m);
                        return NULL;
                }
        }
        cp = mtod(m, struct cmsghdr *);
-       memcpy(CMSG_DATA(cp), p, size);
-       m->m_len = CMSG_SPACE(size);
+       *p = CMSG_DATA(cp);
+       m->m_len = space;
        cp->cmsg_len = CMSG_LEN(size);
        cp->cmsg_level = level;
        cp->cmsg_type = type;
-       return (m);
+       return m;
+}
+
+struct mbuf *
+sbcreatecontrol(void *p, int size, int type, int level)
+{
+       struct mbuf *m;
+       void *v;
+
+       m = sbcreatecontrol1(&v, size, type, level, M_DONTWAIT);
+       if (m == NULL)
+               return NULL;
+       memcpy(v, p, size);
+       return m;
 }
 
 void
diff -r 49741112470a -r 8c559bc96a5f sys/sys/socketvar.h
--- a/sys/sys/socketvar.h       Thu Jun 27 17:47:18 2013 +0000
+++ b/sys/sys/socketvar.h       Thu Jun 27 18:53:17 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: socketvar.h,v 1.129 2012/02/01 02:27:23 matt Exp $     */
+/*     $NetBSD: socketvar.h,v 1.130 2013/06/27 18:53:18 christos Exp $ */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -272,6 +272,8 @@
 void   sbcompress(struct sockbuf *, struct mbuf *, struct mbuf *);
 struct mbuf *
        sbcreatecontrol(void *, int, int, int);
+struct mbuf *
+       sbcreatecontrol1(void **, int, int, int, int);
 void   sbdrop(struct sockbuf *, int);
 void   sbdroprecord(struct sockbuf *);
 void   sbflush(struct sockbuf *);



Home | Main Index | Thread Index | Old Index