diff options
author | Kurt Miller <kurt@cvs.openbsd.org> | 2007-02-26 23:53:34 +0000 |
---|---|---|
committer | Kurt Miller <kurt@cvs.openbsd.org> | 2007-02-26 23:53:34 +0000 |
commit | 82c0a20f7f1b697161e946c6653ad3aa6c2e1d59 (patch) | |
tree | 5cc3c0d9e6bea6d0d92378c8c35d30e675c8b292 | |
parent | 6808e06b15c6ed71ac3739a50b83bd53c629d43e (diff) |
exclude control data from the number of bytes returned by FIONREAD ioctl()
by adding a sb_datacc count to sockbuf that counts data excluding
MT_CONTROL and MT_SONAME mbuf types. w/help from deraadt@.
okay deraadt@ claudio@
-rw-r--r-- | sys/kern/sys_socket.c | 4 | ||||
-rw-r--r-- | sys/kern/uipc_socket.c | 3 | ||||
-rw-r--r-- | sys/kern/uipc_socket2.c | 7 | ||||
-rw-r--r-- | sys/sys/socketvar.h | 7 |
4 files changed, 16 insertions, 5 deletions
diff --git a/sys/kern/sys_socket.c b/sys/kern/sys_socket.c index 45e4aee5444..0bde91ca287 100644 --- a/sys/kern/sys_socket.c +++ b/sys/kern/sys_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys_socket.c,v 1.10 2005/12/13 10:33:14 jsg Exp $ */ +/* $OpenBSD: sys_socket.c,v 1.11 2007/02/26 23:53:33 kurt Exp $ */ /* $NetBSD: sys_socket.c,v 1.13 1995/08/12 23:59:09 mycroft Exp $ */ /* @@ -97,7 +97,7 @@ soo_ioctl(struct file *fp, u_long cmd, caddr_t data, struct proc *p) return (0); case FIONREAD: - *(int *)data = so->so_rcv.sb_cc; + *(int *)data = so->so_rcv.sb_datacc; return (0); case SIOCSPGRP: diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 093298d5a70..4b815e0c378 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket.c,v 1.65 2007/02/14 00:53:48 jsg Exp $ */ +/* $OpenBSD: uipc_socket.c,v 1.66 2007/02/26 23:53:33 kurt Exp $ */ /* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */ /* @@ -838,6 +838,7 @@ dontblock: m->m_data += len; m->m_len -= len; so->so_rcv.sb_cc -= len; + so->so_rcv.sb_datacc -= len; } } if (so->so_oobmark) { diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c index b72b5ca7d43..8fc53f4bf18 100644 --- a/sys/kern/uipc_socket2.c +++ b/sys/kern/uipc_socket2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket2.c,v 1.41 2006/01/05 05:05:07 jsg Exp $ */ +/* $OpenBSD: uipc_socket2.c,v 1.42 2007/02/26 23:53:33 kurt Exp $ */ /* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */ /* @@ -780,6 +780,8 @@ sbcompress(struct sockbuf *sb, struct mbuf *m, struct mbuf *n) (unsigned)m->m_len); n->m_len += m->m_len; sb->sb_cc += m->m_len; + if (m->m_type != MT_CONTROL && m->m_type != MT_SONAME) + sb->sb_datacc += m->m_len; m = m_free(m); continue; } @@ -817,6 +819,7 @@ sbflush(struct sockbuf *sb) sbdrop(sb, (int)sb->sb_cc); KASSERT(sb->sb_cc == 0); + KASSERT(sb->sb_datacc == 0); KASSERT(sb->sb_mb == NULL); KASSERT(sb->sb_mbtail == NULL); KASSERT(sb->sb_lastrecord == NULL); @@ -844,6 +847,8 @@ sbdrop(struct sockbuf *sb, int len) m->m_len -= len; m->m_data += len; sb->sb_cc -= len; + if (m->m_type != MT_CONTROL && m->m_type != MT_SONAME) + sb->sb_datacc -= len; break; } len -= m->m_len; diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h index 4d605a1ad41..99fe1142771 100644 --- a/sys/sys/socketvar.h +++ b/sys/sys/socketvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: socketvar.h,v 1.38 2005/11/21 18:16:46 millert Exp $ */ +/* $OpenBSD: socketvar.h,v 1.39 2007/02/26 23:53:33 kurt Exp $ */ /* $NetBSD: socketvar.h,v 1.18 1996/02/09 18:25:38 christos Exp $ */ /*- @@ -80,6 +80,7 @@ struct socket { */ struct sockbuf { u_long sb_cc; /* actual chars in buffer */ + u_long sb_datacc; /* data only chars in buffer */ u_long sb_hiwat; /* max actual char count */ u_long sb_mbcnt; /* chars of mbufs used */ u_long sb_mbmax; /* max chars of mbufs to use */ @@ -179,6 +180,8 @@ do { \ /* adjust counters in sb reflecting allocation of m */ #define sballoc(sb, m) { \ (sb)->sb_cc += (m)->m_len; \ + if ((m)->m_type != MT_CONTROL && (m)->m_type != MT_SONAME) \ + (sb)->sb_datacc += (m)->m_len; \ (sb)->sb_mbcnt += MSIZE; \ if ((m)->m_flags & M_EXT) \ (sb)->sb_mbcnt += (m)->m_ext.ext_size; \ @@ -187,6 +190,8 @@ do { \ /* adjust counters in sb reflecting freeing of m */ #define sbfree(sb, m) { \ (sb)->sb_cc -= (m)->m_len; \ + if ((m)->m_type != MT_CONTROL && (m)->m_type != MT_SONAME) \ + (sb)->sb_datacc -= (m)->m_len; \ (sb)->sb_mbcnt -= MSIZE; \ if ((m)->m_flags & M_EXT) \ (sb)->sb_mbcnt -= (m)->m_ext.ext_size; \ |