Module Name: src Committed By: christos Date: Thu Jun 27 18:53:18 UTC 2013
Modified Files: src/sys/kern: uipc_socket2.c src/sys/sys: socketvar.h Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.110 -r1.111 src/sys/kern/uipc_socket2.c cvs rdiff -u -r1.129 -r1.130 src/sys/sys/socketvar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/uipc_socket2.c diff -u src/sys/kern/uipc_socket2.c:1.110 src/sys/kern/uipc_socket2.c:1.111 --- src/sys/kern/uipc_socket2.c:1.110 Tue Dec 20 18:56:28 2011 +++ src/sys/kern/uipc_socket2.c Thu Jun 27 14:53:17 2013 @@ -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 @@ sbdroprecord(struct sockbuf *sb) * 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 Index: src/sys/sys/socketvar.h diff -u src/sys/sys/socketvar.h:1.129 src/sys/sys/socketvar.h:1.130 --- src/sys/sys/socketvar.h:1.129 Tue Jan 31 21:27:23 2012 +++ src/sys/sys/socketvar.h Thu Jun 27 14:53:18 2013 @@ -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 sbcheck(struct sockbuf *); 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 *);