change gdium conf to print message out both on uart and lcd
[pmon-gdium.git] / sys / kern / uipc_socket2.c
blob3d6fe281ecf4c3c660be4d516a945ea78086c9a7
1 /* $Id: uipc_socket2.c,v 1.1.1.1 2006/09/14 01:59:08 root Exp $ */
2 /* $OpenBSD: uipc_socket2.c,v 1.10 1999/02/19 15:06:52 millert Exp $ */
3 /* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */
5 /*
6 * Copyright (c) 1982, 1986, 1988, 1990, 1993
7 * The Regents of the University of California. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
37 * @(#)uipc_socket2.c 8.1 (Berkeley) 6/10/93
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/proc.h>
43 #include <sys/file.h>
44 #include <sys/buf.h>
45 #include <sys/malloc.h>
46 #include <sys/mbuf.h>
47 #include <sys/protosw.h>
48 #include <sys/socket.h>
49 #include <sys/socketvar.h>
50 #include <sys/signalvar.h>
53 * Primitive routines for operating on sockets and socket buffers
56 /* strings for sleep message: */
57 char netio[] = "netio";
58 char netcon[] = "netcon";
59 char netcls[] = "netcls";
61 u_long sb_max = SB_MAX; /* patchable */
64 * Procedures to manipulate state flags of socket
65 * and do appropriate wakeups. Normal sequence from the
66 * active (originating) side is that soisconnecting() is
67 * called during processing of connect() call,
68 * resulting in an eventual call to soisconnected() if/when the
69 * connection is established. When the connection is torn down
70 * soisdisconnecting() is called during processing of disconnect() call,
71 * and soisdisconnected() is called when the connection to the peer
72 * is totally severed. The semantics of these routines are such that
73 * connectionless protocols can call soisconnected() and soisdisconnected()
74 * only, bypassing the in-progress calls when setting up a ``connection''
75 * takes no time.
77 * From the passive side, a socket is created with
78 * two queues of sockets: so_q0 for connections in progress
79 * and so_q for connections already made and awaiting user acceptance.
80 * As a protocol is preparing incoming connections, it creates a socket
81 * structure queued on so_q0 by calling sonewconn(). When the connection
82 * is established, soisconnected() is called, and transfers the
83 * socket structure to so_q, making it available to accept().
85 * If a socket is closed with sockets on either
86 * so_q0 or so_q, these sockets are dropped.
88 * If higher level protocols are implemented in
89 * the kernel, the wakeups done here will sometimes
90 * cause software-interrupt process scheduling.
93 void
94 soisconnecting(so)
95 register struct socket *so;
98 so->so_state &= ~(SS_ISCONNECTED|SS_ISDISCONNECTING);
99 so->so_state |= SS_ISCONNECTING;
102 void
103 soisconnected(so)
104 register struct socket *so;
106 register struct socket *head = so->so_head;
108 so->so_state &= ~(SS_ISCONNECTING|SS_ISDISCONNECTING|SS_ISCONFIRMING);
109 so->so_state |= SS_ISCONNECTED;
110 if (head && soqremque(so, 0)) {
111 soqinsque(head, so, 1);
112 sorwakeup(head);
113 wakeup((caddr_t)&head->so_timeo);
114 } else {
115 wakeup((caddr_t)&so->so_timeo);
116 sorwakeup(so);
117 sowwakeup(so);
121 void
122 soisdisconnecting(so)
123 register struct socket *so;
126 so->so_state &= ~SS_ISCONNECTING;
127 so->so_state |= (SS_ISDISCONNECTING|SS_CANTRCVMORE|SS_CANTSENDMORE);
128 wakeup((caddr_t)&so->so_timeo);
129 sowwakeup(so);
130 sorwakeup(so);
133 void
134 soisdisconnected(so)
135 register struct socket *so;
138 so->so_state &= ~(SS_ISCONNECTING|SS_ISCONNECTED|SS_ISDISCONNECTING);
139 so->so_state |= (SS_CANTRCVMORE|SS_CANTSENDMORE|SS_ISDISCONNECTED);
140 wakeup((caddr_t)&so->so_timeo);
141 sowwakeup(so);
142 sorwakeup(so);
146 * When an attempt at a new connection is noted on a socket
147 * which accepts connections, sonewconn is called. If the
148 * connection is possible (subject to space constraints, etc.)
149 * then we allocate a new structure, propoerly linked into the
150 * data structure of the original socket, and return this.
151 * Connstatus may be 0, or SO_ISCONFIRMING, or SO_ISCONNECTED.
153 * Currently, sonewconn() is defined as sonewconn1() in socketvar.h
154 * to catch calls that are missing the (new) second parameter.
156 struct socket *
157 sonewconn1(head, connstatus)
158 register struct socket *head;
159 int connstatus;
161 register struct socket *so;
162 int soqueue = connstatus ? 1 : 0;
164 if (head->so_qlen + head->so_q0len > head->so_qlimit * 3)
165 return ((struct socket *)0);
166 MALLOC(so, struct socket *, sizeof(*so), M_SOCKET, M_DONTWAIT);
167 if (so == NULL)
168 return ((struct socket *)0);
169 bzero((caddr_t)so, sizeof(*so));
170 so->so_type = head->so_type;
171 so->so_options = head->so_options &~ SO_ACCEPTCONN;
172 so->so_linger = head->so_linger;
173 so->so_state = head->so_state | SS_NOFDREF;
174 so->so_proto = head->so_proto;
175 so->so_timeo = head->so_timeo;
176 so->so_pgid = head->so_pgid;
177 so->so_euid = head->so_euid;
178 so->so_ruid = head->so_ruid;
179 (void) soreserve(so, head->so_snd.sb_hiwat, head->so_rcv.sb_hiwat);
180 soqinsque(head, so, soqueue);
181 if ((*so->so_proto->pr_usrreq)(so, PRU_ATTACH,
182 (struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0)) {
183 (void) soqremque(so, soqueue);
184 (void) free((caddr_t)so, M_SOCKET);
185 return ((struct socket *)0);
187 if (connstatus) {
188 sorwakeup(head);
189 wakeup((caddr_t)&head->so_timeo);
190 so->so_state |= connstatus;
192 return (so);
195 void
196 soqinsque(head, so, q)
197 register struct socket *head, *so;
198 int q;
201 register struct socket **prev;
202 so->so_head = head;
203 if (q == 0) {
204 head->so_q0len++;
205 so->so_q0 = 0;
206 for (prev = &(head->so_q0); *prev; )
207 prev = &((*prev)->so_q0);
208 } else {
209 head->so_qlen++;
210 so->so_q = 0;
211 for (prev = &(head->so_q); *prev; )
212 prev = &((*prev)->so_q);
214 *prev = so;
218 soqremque(so, q)
219 register struct socket *so;
220 int q;
222 register struct socket *head, *prev, *next;
224 head = so->so_head;
225 prev = head;
226 for (;;) {
227 next = q ? prev->so_q : prev->so_q0;
228 if (next == so)
229 break;
230 if (next == 0)
231 return (0);
232 prev = next;
234 if (q == 0) {
235 prev->so_q0 = next->so_q0;
236 head->so_q0len--;
237 } else {
238 prev->so_q = next->so_q;
239 head->so_qlen--;
241 next->so_q0 = next->so_q = 0;
242 next->so_head = 0;
243 return (1);
247 * Socantsendmore indicates that no more data will be sent on the
248 * socket; it would normally be applied to a socket when the user
249 * informs the system that no more data is to be sent, by the protocol
250 * code (in case PRU_SHUTDOWN). Socantrcvmore indicates that no more data
251 * will be received, and will normally be applied to the socket by a
252 * protocol when it detects that the peer will send no more data.
253 * Data queued for reading in the socket may yet be read.
256 void
257 socantsendmore(so)
258 struct socket *so;
261 so->so_state |= SS_CANTSENDMORE;
262 sowwakeup(so);
265 void
266 socantrcvmore(so)
267 struct socket *so;
270 so->so_state |= SS_CANTRCVMORE;
271 sorwakeup(so);
275 * Wait for data to arrive at/drain from a socket buffer.
278 sbwait(sb)
279 struct sockbuf *sb;
282 sb->sb_flags |= SB_WAIT;
283 return (tsleep((caddr_t)&sb->sb_cc,
284 (sb->sb_flags & SB_NOINTR) ? PSOCK : PSOCK | PCATCH, netio,
285 sb->sb_timeo));
289 * Lock a sockbuf already known to be locked;
290 * return any error returned from sleep (EINTR).
293 sb_lock(sb)
294 register struct sockbuf *sb;
296 int error;
298 while (sb->sb_flags & SB_LOCK) {
299 sb->sb_flags |= SB_WANT;
300 error = tsleep((caddr_t)&sb->sb_flags,
301 (sb->sb_flags & SB_NOINTR) ?
302 PSOCK : PSOCK|PCATCH, netio, 0);
303 if (error)
304 return (error);
306 sb->sb_flags |= SB_LOCK;
307 return (0);
311 * Wakeup processes waiting on a socket buffer.
312 * Do asynchronous notification via SIGIO
313 * if the socket has the SS_ASYNC flag set.
315 void
316 sowakeup(so, sb)
317 register struct socket *so;
318 register struct sockbuf *sb;
320 selwakeup(&sb->sb_sel);
321 sb->sb_flags &= ~SB_SEL;
322 if (sb->sb_flags & SB_WAIT) {
323 sb->sb_flags &= ~SB_WAIT;
324 wakeup((caddr_t)&sb->sb_cc);
326 if (so->so_state & SS_ASYNC)
327 csignal(so->so_pgid, SIGIO, so->so_siguid, so->so_sigeuid);
331 * Socket buffer (struct sockbuf) utility routines.
333 * Each socket contains two socket buffers: one for sending data and
334 * one for receiving data. Each buffer contains a queue of mbufs,
335 * information about the number of mbufs and amount of data in the
336 * queue, and other fields allowing select() statements and notification
337 * on data availability to be implemented.
339 * Data stored in a socket buffer is maintained as a list of records.
340 * Each record is a list of mbufs chained together with the m_next
341 * field. Records are chained together with the m_nextpkt field. The upper
342 * level routine soreceive() expects the following conventions to be
343 * observed when placing information in the receive buffer:
345 * 1. If the protocol requires each message be preceded by the sender's
346 * name, then a record containing that name must be present before
347 * any associated data (mbuf's must be of type MT_SONAME).
348 * 2. If the protocol supports the exchange of ``access rights'' (really
349 * just additional data associated with the message), and there are
350 * ``rights'' to be received, then a record containing this data
351 * should be present (mbuf's must be of type MT_CONTROL).
352 * 3. If a name or rights record exists, then it must be followed by
353 * a data record, perhaps of zero length.
355 * Before using a new socket structure it is first necessary to reserve
356 * buffer space to the socket, by calling sbreserve(). This should commit
357 * some of the available buffer space in the system buffer pool for the
358 * socket (currently, it does nothing but enforce limits). The space
359 * should be released by calling sbrelease() when the socket is destroyed.
363 soreserve(so, sndcc, rcvcc)
364 register struct socket *so;
365 u_long sndcc, rcvcc;
368 if (sbreserve(&so->so_snd, sndcc) == 0)
369 goto bad;
370 if (sbreserve(&so->so_rcv, rcvcc) == 0)
371 goto bad2;
372 if (so->so_rcv.sb_lowat == 0)
373 so->so_rcv.sb_lowat = 1;
374 if (so->so_snd.sb_lowat == 0)
375 so->so_snd.sb_lowat = MCLBYTES;
376 if (so->so_snd.sb_lowat > so->so_snd.sb_hiwat)
377 so->so_snd.sb_lowat = so->so_snd.sb_hiwat;
378 return (0);
379 bad2:
380 sbrelease(&so->so_snd);
381 bad:
382 return (ENOBUFS);
386 * Allot mbufs to a sockbuf.
387 * Attempt to scale mbmax so that mbcnt doesn't become limiting
388 * if buffering efficiency is near the normal case.
391 sbreserve(sb, cc)
392 struct sockbuf *sb;
393 u_long cc;
396 if (cc == 0 || cc > sb_max * MCLBYTES / (MSIZE + MCLBYTES))
397 return (0);
398 sb->sb_hiwat = cc;
399 sb->sb_mbmax = min(cc * 2, sb_max);
400 if (sb->sb_lowat > sb->sb_hiwat)
401 sb->sb_lowat = sb->sb_hiwat;
402 return (1);
406 * Free mbufs held by a socket, and reserved mbuf space.
408 void
409 sbrelease(sb)
410 struct sockbuf *sb;
413 sbflush(sb);
414 sb->sb_hiwat = sb->sb_mbmax = 0;
418 * Routines to add and remove
419 * data from an mbuf queue.
421 * The routines sbappend() or sbappendrecord() are normally called to
422 * append new mbufs to a socket buffer, after checking that adequate
423 * space is available, comparing the function sbspace() with the amount
424 * of data to be added. sbappendrecord() differs from sbappend() in
425 * that data supplied is treated as the beginning of a new record.
426 * To place a sender's address, optional access rights, and data in a
427 * socket receive buffer, sbappendaddr() should be used. To place
428 * access rights and data in a socket receive buffer, sbappendrights()
429 * should be used. In either case, the new data begins a new record.
430 * Note that unlike sbappend() and sbappendrecord(), these routines check
431 * for the caller that there will be enough space to store the data.
432 * Each fails if there is not enough space, or if it cannot find mbufs
433 * to store additional information in.
435 * Reliable protocols may use the socket send buffer to hold data
436 * awaiting acknowledgement. Data is normally copied from a socket
437 * send buffer in a protocol with m_copy for output to a peer,
438 * and then removing the data from the socket buffer with sbdrop()
439 * or sbdroprecord() when the data is acknowledged by the peer.
443 * Append mbuf chain m to the last record in the
444 * socket buffer sb. The additional space associated
445 * the mbuf chain is recorded in sb. Empty mbufs are
446 * discarded and mbufs are compacted where possible.
448 void
449 sbappend(sb, m)
450 struct sockbuf *sb;
451 struct mbuf *m;
453 register struct mbuf *n;
455 if (m == 0)
456 return;
457 if ((n = sb->sb_mb) != NULL) {
458 while (n->m_nextpkt)
459 n = n->m_nextpkt;
460 do {
461 if (n->m_flags & M_EOR) {
462 sbappendrecord(sb, m); /* XXXXXX!!!! */
463 return;
465 } while (n->m_next && (n = n->m_next));
467 sbcompress(sb, m, n);
470 #ifdef SOCKBUF_DEBUG
471 void
472 sbcheck(sb)
473 register struct sockbuf *sb;
475 register struct mbuf *m;
476 register int len = 0, mbcnt = 0;
478 for (m = sb->sb_mb; m; m = m->m_next) {
479 len += m->m_len;
480 mbcnt += MSIZE;
481 if (m->m_flags & M_EXT)
482 mbcnt += m->m_ext.ext_size;
483 if (m->m_nextpkt)
484 panic("sbcheck nextpkt");
486 if (len != sb->sb_cc || mbcnt != sb->sb_mbcnt) {
487 printf("cc %d != %d || mbcnt %d != %d\n", len, sb->sb_cc,
488 mbcnt, sb->sb_mbcnt);
489 panic("sbcheck");
492 #endif
495 * As above, except the mbuf chain
496 * begins a new record.
498 void
499 sbappendrecord(sb, m0)
500 register struct sockbuf *sb;
501 register struct mbuf *m0;
503 register struct mbuf *m;
505 if (m0 == 0)
506 return;
507 if ((m = sb->sb_mb) != NULL)
508 while (m->m_nextpkt)
509 m = m->m_nextpkt;
511 * Put the first mbuf on the queue.
512 * Note this permits zero length records.
514 sballoc(sb, m0);
515 if (m)
516 m->m_nextpkt = m0;
517 else
518 sb->sb_mb = m0;
519 m = m0->m_next;
520 m0->m_next = 0;
521 if (m && (m0->m_flags & M_EOR)) {
522 m0->m_flags &= ~M_EOR;
523 m->m_flags |= M_EOR;
525 sbcompress(sb, m, m0);
529 * As above except that OOB data
530 * is inserted at the beginning of the sockbuf,
531 * but after any other OOB data.
533 void
534 sbinsertoob(sb, m0)
535 register struct sockbuf *sb;
536 register struct mbuf *m0;
538 register struct mbuf *m;
539 register struct mbuf **mp;
541 if (m0 == 0)
542 return;
543 for (mp = &sb->sb_mb; (m = *mp) != NULL; mp = &((*mp)->m_nextpkt)) {
544 again:
545 switch (m->m_type) {
547 case MT_OOBDATA:
548 continue; /* WANT next train */
550 case MT_CONTROL:
551 if ((m = m->m_next) != NULL)
552 goto again; /* inspect THIS train further */
554 break;
557 * Put the first mbuf on the queue.
558 * Note this permits zero length records.
560 sballoc(sb, m0);
561 m0->m_nextpkt = *mp;
562 *mp = m0;
563 m = m0->m_next;
564 m0->m_next = 0;
565 if (m && (m0->m_flags & M_EOR)) {
566 m0->m_flags &= ~M_EOR;
567 m->m_flags |= M_EOR;
569 sbcompress(sb, m, m0);
573 * Append address and data, and optionally, control (ancillary) data
574 * to the receive queue of a socket. If present,
575 * m0 must include a packet header with total length.
576 * Returns 0 if no space in sockbuf or insufficient mbufs.
579 sbappendaddr(sb, asa, m0, control)
580 register struct sockbuf *sb;
581 struct sockaddr *asa;
582 struct mbuf *m0, *control;
584 register struct mbuf *m, *n;
585 int space = asa->sa_len;
587 if (m0 && (m0->m_flags & M_PKTHDR) == 0)
588 panic("sbappendaddr");
589 if (m0)
590 space += m0->m_pkthdr.len;
591 for (n = control; n; n = n->m_next) {
592 space += n->m_len;
593 if (n->m_next == 0) /* keep pointer to last control buf */
594 break;
596 if (space > sbspace(sb))
597 return (0);
598 if (asa->sa_len > MLEN)
599 return (0);
600 MGET(m, M_DONTWAIT, MT_SONAME);
601 if (m == 0)
602 return (0);
603 m->m_len = asa->sa_len;
604 bcopy((caddr_t)asa, mtod(m, caddr_t), asa->sa_len);
605 if (n)
606 n->m_next = m0; /* concatenate data to control */
607 else
608 control = m0;
609 m->m_next = control;
610 for (n = m; n; n = n->m_next)
611 sballoc(sb, n);
612 if ((n = sb->sb_mb) != NULL) {
613 while (n->m_nextpkt)
614 n = n->m_nextpkt;
615 n->m_nextpkt = m;
616 } else
617 sb->sb_mb = m;
618 return (1);
622 sbappendcontrol(sb, m0, control)
623 struct sockbuf *sb;
624 struct mbuf *m0, *control;
626 register struct mbuf *m, *n;
627 int space = 0;
629 if (control == 0)
630 panic("sbappendcontrol");
631 for (m = control; ; m = m->m_next) {
632 space += m->m_len;
633 if (m->m_next == 0)
634 break;
636 n = m; /* save pointer to last control buffer */
637 for (m = m0; m; m = m->m_next)
638 space += m->m_len;
639 if (space > sbspace(sb))
640 return (0);
641 n->m_next = m0; /* concatenate data to control */
642 for (m = control; m; m = m->m_next)
643 sballoc(sb, m);
644 if ((n = sb->sb_mb) != NULL) {
645 while (n->m_nextpkt)
646 n = n->m_nextpkt;
647 n->m_nextpkt = control;
648 } else
649 sb->sb_mb = control;
650 return (1);
654 * Compress mbuf chain m into the socket
655 * buffer sb following mbuf n. If n
656 * is null, the buffer is presumed empty.
658 void
659 sbcompress(sb, m, n)
660 register struct sockbuf *sb;
661 register struct mbuf *m, *n;
663 register int eor = 0;
664 register struct mbuf *o;
666 while (m) {
667 eor |= m->m_flags & M_EOR;
668 if (m->m_len == 0 &&
669 (eor == 0 ||
670 (((o = m->m_next) || (o = n)) &&
671 o->m_type == m->m_type))) {
672 m = m_free(m);
673 continue;
675 if (n && (n->m_flags & (M_EXT | M_EOR)) == 0 &&
676 (n->m_data + n->m_len + m->m_len) < &n->m_dat[MLEN] &&
677 n->m_type == m->m_type) {
678 bcopy(mtod(m, caddr_t), mtod(n, caddr_t) + n->m_len,
679 (unsigned)m->m_len);
680 n->m_len += m->m_len;
681 sb->sb_cc += m->m_len;
682 m = m_free(m);
683 continue;
685 if (n)
686 n->m_next = m;
687 else
688 sb->sb_mb = m;
689 sballoc(sb, m);
690 n = m;
691 m->m_flags &= ~M_EOR;
692 m = m->m_next;
693 n->m_next = 0;
695 if (eor) {
696 if (n)
697 n->m_flags |= eor;
698 else
699 printf("semi-panic: sbcompress\n");
704 * Free all mbufs in a sockbuf.
705 * Check that all resources are reclaimed.
707 void
708 sbflush(sb)
709 register struct sockbuf *sb;
712 if (sb->sb_flags & SB_LOCK)
713 panic("sbflush");
714 while (sb->sb_mbcnt)
715 sbdrop(sb, (int)sb->sb_cc);
716 if (sb->sb_cc || sb->sb_mb)
717 panic("sbflush 2");
721 * Drop data from (the front of) a sockbuf.
723 void
724 sbdrop(sb, len)
725 register struct sockbuf *sb;
726 register int len;
728 register struct mbuf *m, *mn;
729 struct mbuf *next;
731 next = (m = sb->sb_mb) ? m->m_nextpkt : 0;
732 while (len > 0) {
733 if (m == 0) {
734 if (next == 0)
735 panic("sbdrop");
736 m = next;
737 next = m->m_nextpkt;
738 continue;
740 if (m->m_len > len) {
741 m->m_len -= len;
742 m->m_data += len;
743 sb->sb_cc -= len;
744 break;
746 len -= m->m_len;
747 sbfree(sb, m);
748 MFREE(m, mn);
749 m = mn;
751 while (m && m->m_len == 0) {
752 sbfree(sb, m);
753 MFREE(m, mn);
754 m = mn;
756 if (m) {
757 sb->sb_mb = m;
758 m->m_nextpkt = next;
759 } else
760 sb->sb_mb = next;
764 * Drop a record off the front of a sockbuf
765 * and move the next record to the front.
767 void
768 sbdroprecord(sb)
769 register struct sockbuf *sb;
771 register struct mbuf *m, *mn;
773 m = sb->sb_mb;
774 if (m) {
775 sb->sb_mb = m->m_nextpkt;
776 do {
777 sbfree(sb, m);
778 MFREE(m, mn);
779 } while ((m = mn) != NULL);