summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorKurt Miller <kurt@cvs.openbsd.org>2007-02-26 23:53:34 +0000
committerKurt Miller <kurt@cvs.openbsd.org>2007-02-26 23:53:34 +0000
commit82c0a20f7f1b697161e946c6653ad3aa6c2e1d59 (patch)
tree5cc3c0d9e6bea6d0d92378c8c35d30e675c8b292 /sys/kern
parent6808e06b15c6ed71ac3739a50b83bd53c629d43e (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@
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/sys_socket.c4
-rw-r--r--sys/kern/uipc_socket.c3
-rw-r--r--sys/kern/uipc_socket2.c7
3 files changed, 10 insertions, 4 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;