xref: /csrg-svn/sys/kern/uipc_socket2.c (revision 44228)
1 /*
2  * Copyright (c) 1982, 1986, 1988, 1990 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  *	@(#)uipc_socket2.c	7.13 (Berkeley) 06/25/90
18  */
19 
20 #include "param.h"
21 #include "systm.h"
22 #include "user.h"
23 #include "proc.h"
24 #include "file.h"
25 #include "buf.h"
26 #include "malloc.h"
27 #include "mbuf.h"
28 #include "protosw.h"
29 #include "socket.h"
30 #include "socketvar.h"
31 
32 /*
33  * Primitive routines for operating on sockets and socket buffers
34  */
35 
36 /* strings for sleep message: */
37 char	netio[] = "netio";
38 char	netcon[] = "netcon";
39 char	netcls[] = "netcls";
40 
41 u_long	sb_max = SB_MAX;		/* patchable */
42 
43 /*
44  * Procedures to manipulate state flags of socket
45  * and do appropriate wakeups.  Normal sequence from the
46  * active (originating) side is that soisconnecting() is
47  * called during processing of connect() call,
48  * resulting in an eventual call to soisconnected() if/when the
49  * connection is established.  When the connection is torn down
50  * soisdisconnecting() is called during processing of disconnect() call,
51  * and soisdisconnected() is called when the connection to the peer
52  * is totally severed.  The semantics of these routines are such that
53  * connectionless protocols can call soisconnected() and soisdisconnected()
54  * only, bypassing the in-progress calls when setting up a ``connection''
55  * takes no time.
56  *
57  * From the passive side, a socket is created with
58  * two queues of sockets: so_q0 for connections in progress
59  * and so_q for connections already made and awaiting user acceptance.
60  * As a protocol is preparing incoming connections, it creates a socket
61  * structure queued on so_q0 by calling sonewconn().  When the connection
62  * is established, soisconnected() is called, and transfers the
63  * socket structure to so_q, making it available to accept().
64  *
65  * If a socket is closed with sockets on either
66  * so_q0 or so_q, these sockets are dropped.
67  *
68  * If higher level protocols are implemented in
69  * the kernel, the wakeups done here will sometimes
70  * cause software-interrupt process scheduling.
71  */
72 
73 soisconnecting(so)
74 	register struct socket *so;
75 {
76 
77 	so->so_state &= ~(SS_ISCONNECTED|SS_ISDISCONNECTING);
78 	so->so_state |= SS_ISCONNECTING;
79 }
80 
81 soisconnected(so)
82 	register struct socket *so;
83 {
84 	register struct socket *head = so->so_head;
85 
86 	so->so_state &= ~(SS_ISCONNECTING|SS_ISDISCONNECTING|SS_ISCONFIRMING);
87 	so->so_state |= SS_ISCONNECTED;
88 	if (head && soqremque(so, 0)) {
89 		soqinsque(head, so, 1);
90 		sorwakeup(head);
91 		wakeup((caddr_t)&head->so_timeo);
92 	} else {
93 		wakeup((caddr_t)&so->so_timeo);
94 		sorwakeup(so);
95 		sowwakeup(so);
96 	}
97 }
98 
99 soisdisconnecting(so)
100 	register struct socket *so;
101 {
102 
103 	so->so_state &= ~SS_ISCONNECTING;
104 	so->so_state |= (SS_ISDISCONNECTING|SS_CANTRCVMORE|SS_CANTSENDMORE);
105 	wakeup((caddr_t)&so->so_timeo);
106 	sowwakeup(so);
107 	sorwakeup(so);
108 }
109 
110 soisdisconnected(so)
111 	register struct socket *so;
112 {
113 
114 	so->so_state &= ~(SS_ISCONNECTING|SS_ISCONNECTED|SS_ISDISCONNECTING);
115 	so->so_state |= (SS_CANTRCVMORE|SS_CANTSENDMORE);
116 	wakeup((caddr_t)&so->so_timeo);
117 	sowwakeup(so);
118 	sorwakeup(so);
119 }
120 
121 /*
122  * When an attempt at a new connection is noted on a socket
123  * which accepts connections, sonewconn is called.  If the
124  * connection is possible (subject to space constraints, etc.)
125  * then we allocate a new structure, propoerly linked into the
126  * data structure of the original socket, and return this.
127  * Connstatus may be 0, or SO_ISCONFIRMING, or SO_ISCONNECTED.
128  *
129  * Currently, sonewconn() is defined as sonewconn1() in socketvar.h
130  * to catch calls that are missing the (new) second parameter.
131  */
132 struct socket *
133 sonewconn1(head, connstatus)
134 	register struct socket *head;
135 	int connstatus;
136 {
137 	register struct socket *so;
138 	int soqueue = connstatus ? 1 : 0;
139 
140 	if (head->so_qlen + head->so_q0len > 3 * head->so_qlimit / 2)
141 		return ((struct socket *)0);
142 	MALLOC(so, struct socket *, sizeof(*so), M_SOCKET, M_DONTWAIT);
143 	if (so == NULL)
144 		return ((struct socket *)0);
145 	bzero((caddr_t)so, sizeof(*so));
146 	so->so_type = head->so_type;
147 	so->so_options = head->so_options &~ SO_ACCEPTCONN;
148 	so->so_linger = head->so_linger;
149 	so->so_state = head->so_state | SS_NOFDREF;
150 	so->so_proto = head->so_proto;
151 	so->so_timeo = head->so_timeo;
152 	so->so_pgid = head->so_pgid;
153 	(void) soreserve(so, head->so_snd.sb_hiwat, head->so_rcv.sb_hiwat);
154 	soqinsque(head, so, soqueue);
155 	if ((*so->so_proto->pr_usrreq)(so, PRU_ATTACH,
156 	    (struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0)) {
157 		(void) soqremque(so, soqueue);
158 		(void) free((caddr_t)so, M_SOCKET);
159 		return ((struct socket *)0);
160 	}
161 	if (connstatus) {
162 		sorwakeup(head);
163 		wakeup((caddr_t)&head->so_timeo);
164 		so->so_state |= connstatus;
165 	}
166 	return (so);
167 }
168 
169 soqinsque(head, so, q)
170 	register struct socket *head, *so;
171 	int q;
172 {
173 
174 	register struct socket **prev;
175 	so->so_head = head;
176 	if (q == 0) {
177 		head->so_q0len++;
178 		so->so_q0 = 0;
179 		for (prev = &(head->so_q0); *prev; )
180 			prev = &((*prev)->so_q0);
181 	} else {
182 		head->so_qlen++;
183 		so->so_q = 0;
184 		for (prev = &(head->so_q); *prev; )
185 			prev = &((*prev)->so_q);
186 	}
187 	*prev = so;
188 }
189 
190 soqremque(so, q)
191 	register struct socket *so;
192 	int q;
193 {
194 	register struct socket *head, *prev, *next;
195 
196 	head = so->so_head;
197 	prev = head;
198 	for (;;) {
199 		next = q ? prev->so_q : prev->so_q0;
200 		if (next == so)
201 			break;
202 		if (next == 0)
203 			return (0);
204 		prev = next;
205 	}
206 	if (q == 0) {
207 		prev->so_q0 = next->so_q0;
208 		head->so_q0len--;
209 	} else {
210 		prev->so_q = next->so_q;
211 		head->so_qlen--;
212 	}
213 	next->so_q0 = next->so_q = 0;
214 	next->so_head = 0;
215 	return (1);
216 }
217 
218 /*
219  * Socantsendmore indicates that no more data will be sent on the
220  * socket; it would normally be applied to a socket when the user
221  * informs the system that no more data is to be sent, by the protocol
222  * code (in case PRU_SHUTDOWN).  Socantrcvmore indicates that no more data
223  * will be received, and will normally be applied to the socket by a
224  * protocol when it detects that the peer will send no more data.
225  * Data queued for reading in the socket may yet be read.
226  */
227 
228 socantsendmore(so)
229 	struct socket *so;
230 {
231 
232 	so->so_state |= SS_CANTSENDMORE;
233 	sowwakeup(so);
234 }
235 
236 socantrcvmore(so)
237 	struct socket *so;
238 {
239 
240 	so->so_state |= SS_CANTRCVMORE;
241 	sorwakeup(so);
242 }
243 
244 /*
245  * Socket select/wakeup routines.
246  */
247 
248 /*
249  * Queue a process for a select on a socket buffer.
250  */
251 sbselqueue(sb)
252 	struct sockbuf *sb;
253 {
254 	struct proc *p;
255 
256 	if ((p = sb->sb_sel) && p->p_wchan == (caddr_t)&selwait)
257 		sb->sb_flags |= SB_COLL;
258 	else {
259 		sb->sb_sel = u.u_procp;
260 		sb->sb_flags |= SB_SEL;
261 	}
262 }
263 
264 /*
265  * Wait for data to arrive at/drain from a socket buffer.
266  */
267 sbwait(sb)
268 	struct sockbuf *sb;
269 {
270 
271 	sb->sb_flags |= SB_WAIT;
272 	return (tsleep((caddr_t)&sb->sb_cc,
273 	    (sb->sb_flags & SB_NOINTR) ? PSOCK : PSOCK | PCATCH, netio,
274 	    sb->sb_timeo));
275 }
276 
277 /*
278  * Lock a sockbuf already known to be locked;
279  * return any error returned from sleep (EINTR).
280  */
281 sb_lock(sb)
282 	register struct sockbuf *sb;
283 {
284 	int error;
285 
286 	while (sb->sb_flags & SB_LOCK) {
287 		sb->sb_flags |= SB_WANT;
288 		if (error = tsleep((caddr_t)&sb->sb_flags,
289 		    (sb->sb_flags & SB_NOINTR) ? PSOCK : PSOCK|PCATCH,
290 		    netio, 0))
291 			return (error);
292 	}
293 	sb->sb_flags |= SB_LOCK;
294 	return (0);
295 }
296 
297 /*
298  * Wakeup processes waiting on a socket buffer.
299  * Do asynchronous notification via SIGIO
300  * if the socket has the SS_ASYNC flag set.
301  */
302 sowakeup(so, sb)
303 	register struct socket *so;
304 	register struct sockbuf *sb;
305 {
306 	struct proc *p;
307 
308 	if (sb->sb_sel) {
309 		selwakeup(sb->sb_sel, sb->sb_flags & SB_COLL);
310 		sb->sb_sel = 0;
311 		sb->sb_flags &= ~(SB_SEL|SB_COLL);
312 	}
313 	if (sb->sb_flags & SB_WAIT) {
314 		sb->sb_flags &= ~SB_WAIT;
315 		wakeup((caddr_t)&sb->sb_cc);
316 	}
317 	if (so->so_state & SS_ASYNC) {
318 		if (so->so_pgid < 0)
319 			gsignal(-so->so_pgid, SIGIO);
320 		else if (so->so_pgid > 0 && (p = pfind(so->so_pgid)) != 0)
321 			psignal(p, SIGIO);
322 	}
323 }
324 
325 /*
326  * Socket buffer (struct sockbuf) utility routines.
327  *
328  * Each socket contains two socket buffers: one for sending data and
329  * one for receiving data.  Each buffer contains a queue of mbufs,
330  * information about the number of mbufs and amount of data in the
331  * queue, and other fields allowing select() statements and notification
332  * on data availability to be implemented.
333  *
334  * Data stored in a socket buffer is maintained as a list of records.
335  * Each record is a list of mbufs chained together with the m_next
336  * field.  Records are chained together with the m_nextpkt field. The upper
337  * level routine soreceive() expects the following conventions to be
338  * observed when placing information in the receive buffer:
339  *
340  * 1. If the protocol requires each message be preceded by the sender's
341  *    name, then a record containing that name must be present before
342  *    any associated data (mbuf's must be of type MT_SONAME).
343  * 2. If the protocol supports the exchange of ``access rights'' (really
344  *    just additional data associated with the message), and there are
345  *    ``rights'' to be received, then a record containing this data
346  *    should be present (mbuf's must be of type MT_RIGHTS).
347  * 3. If a name or rights record exists, then it must be followed by
348  *    a data record, perhaps of zero length.
349  *
350  * Before using a new socket structure it is first necessary to reserve
351  * buffer space to the socket, by calling sbreserve().  This should commit
352  * some of the available buffer space in the system buffer pool for the
353  * socket (currently, it does nothing but enforce limits).  The space
354  * should be released by calling sbrelease() when the socket is destroyed.
355  */
356 
357 soreserve(so, sndcc, rcvcc)
358 	register struct socket *so;
359 	u_long sndcc, rcvcc;
360 {
361 
362 	if (sbreserve(&so->so_snd, sndcc) == 0)
363 		goto bad;
364 	if (sbreserve(&so->so_rcv, rcvcc) == 0)
365 		goto bad2;
366 	if (so->so_rcv.sb_lowat == 0)
367 		so->so_rcv.sb_lowat = 1;
368 	if (so->so_snd.sb_lowat == 0)
369 		so->so_snd.sb_lowat = MCLBYTES;
370 	if (so->so_snd.sb_lowat > so->so_snd.sb_hiwat)
371 		so->so_snd.sb_lowat = so->so_snd.sb_hiwat;
372 	return (0);
373 bad2:
374 	sbrelease(&so->so_snd);
375 bad:
376 	return (ENOBUFS);
377 }
378 
379 /*
380  * Allot mbufs to a sockbuf.
381  * Attempt to scale mbmax so that mbcnt doesn't become limiting
382  * if buffering efficiency is near the normal case.
383  */
384 sbreserve(sb, cc)
385 	struct sockbuf *sb;
386 	u_long cc;
387 {
388 
389 	if (cc > sb_max * MCLBYTES / (MSIZE + MCLBYTES))
390 		return (0);
391 	sb->sb_hiwat = cc;
392 	sb->sb_mbmax = min(cc * 2, sb_max);
393 	if (sb->sb_lowat > sb->sb_hiwat)
394 		sb->sb_lowat = sb->sb_hiwat;
395 	return (1);
396 }
397 
398 /*
399  * Free mbufs held by a socket, and reserved mbuf space.
400  */
401 sbrelease(sb)
402 	struct sockbuf *sb;
403 {
404 
405 	sbflush(sb);
406 	sb->sb_hiwat = sb->sb_mbmax = 0;
407 }
408 
409 /*
410  * Routines to add and remove
411  * data from an mbuf queue.
412  *
413  * The routines sbappend() or sbappendrecord() are normally called to
414  * append new mbufs to a socket buffer, after checking that adequate
415  * space is available, comparing the function sbspace() with the amount
416  * of data to be added.  sbappendrecord() differs from sbappend() in
417  * that data supplied is treated as the beginning of a new record.
418  * To place a sender's address, optional access rights, and data in a
419  * socket receive buffer, sbappendaddr() should be used.  To place
420  * access rights and data in a socket receive buffer, sbappendrights()
421  * should be used.  In either case, the new data begins a new record.
422  * Note that unlike sbappend() and sbappendrecord(), these routines check
423  * for the caller that there will be enough space to store the data.
424  * Each fails if there is not enough space, or if it cannot find mbufs
425  * to store additional information in.
426  *
427  * Reliable protocols may use the socket send buffer to hold data
428  * awaiting acknowledgement.  Data is normally copied from a socket
429  * send buffer in a protocol with m_copy for output to a peer,
430  * and then removing the data from the socket buffer with sbdrop()
431  * or sbdroprecord() when the data is acknowledged by the peer.
432  */
433 
434 /*
435  * Append mbuf chain m to the last record in the
436  * socket buffer sb.  The additional space associated
437  * the mbuf chain is recorded in sb.  Empty mbufs are
438  * discarded and mbufs are compacted where possible.
439  */
440 sbappend(sb, m)
441 	struct sockbuf *sb;
442 	struct mbuf *m;
443 {
444 	register struct mbuf *n;
445 
446 	if (m == 0)
447 		return;
448 	if (n = sb->sb_mb) {
449 		while (n->m_nextpkt)
450 			n = n->m_nextpkt;
451 		while (n->m_next)
452 			if (n->m_flags & M_EOR) {
453 				sbappendrecord(sb, m); /* XXXXXX!!!! */
454 				return;
455 			} else
456 				n = n->m_next;
457 	}
458 	sbcompress(sb, m, n);
459 }
460 
461 /*
462  * As above, except the mbuf chain
463  * begins a new record.
464  */
465 sbappendrecord(sb, m0)
466 	register struct sockbuf *sb;
467 	register struct mbuf *m0;
468 {
469 	register struct mbuf *m;
470 
471 	if (m0 == 0)
472 		return;
473 	if (m = sb->sb_mb)
474 		while (m->m_nextpkt)
475 			m = m->m_nextpkt;
476 	/*
477 	 * Put the first mbuf on the queue.
478 	 * Note this permits zero length records.
479 	 */
480 	sballoc(sb, m0);
481 	if (m)
482 		m->m_nextpkt = m0;
483 	else
484 		sb->sb_mb = m0;
485 	m = m0->m_next;
486 	m0->m_next = 0;
487 	if (m && (m0->m_flags & M_EOR)) {
488 		m0->m_flags &= ~M_EOR;
489 		m->m_flags |= M_EOR;
490 	}
491 	sbcompress(sb, m, m0);
492 }
493 
494 /*
495  * As above except that OOB data
496  * is inserted at the beginning of the sockbuf,
497  * but after any other OOB data.
498  */
499 sbinsertoob(sb, m0)
500 	register struct sockbuf *sb;
501 	register struct mbuf *m0;
502 {
503 	register struct mbuf *m;
504 	register struct mbuf **mp;
505 
506 	if (m0 == 0)
507 		return;
508 	for (mp = &sb->sb_mb; m = *mp; mp = &((*mp)->m_nextpkt)) {
509 	    again:
510 		switch (m->m_type) {
511 
512 		case MT_OOBDATA:
513 			continue;		/* WANT next train */
514 
515 		case MT_CONTROL:
516 			if (m = m->m_next)
517 				goto again;	/* inspect THIS train further */
518 		}
519 		break;
520 	}
521 	/*
522 	 * Put the first mbuf on the queue.
523 	 * Note this permits zero length records.
524 	 */
525 	sballoc(sb, m0);
526 	m0->m_nextpkt = *mp;
527 	*mp = m0;
528 	m = m0->m_next;
529 	m0->m_next = 0;
530 	if (m && (m0->m_flags & M_EOR)) {
531 		m0->m_flags &= ~M_EOR;
532 		m->m_flags |= M_EOR;
533 	}
534 	sbcompress(sb, m, m0);
535 }
536 
537 /*
538  * Append address and data, and optionally, control (ancillary) data
539  * to the receive queue of a socket.  If present,
540  * m0 must include a packet header with total length.
541  * Returns 0 if no space in sockbuf or insufficient mbufs.
542  */
543 sbappendaddr(sb, asa, m0, control)
544 	register struct sockbuf *sb;
545 	struct sockaddr *asa;
546 	struct mbuf *m0, *control;
547 {
548 	register struct mbuf *m, *n;
549 	int space = asa->sa_len;
550 
551 if (m0 && (m0->m_flags & M_PKTHDR) == 0)
552 panic("sbappendaddr");
553 	if (m0)
554 		space += m0->m_pkthdr.len;
555 	for (n = control; n; n = n->m_next) {
556 		space += n->m_len;
557 		if (n->m_next == 0)	/* keep pointer to last control buf */
558 			break;
559 	}
560 	if (space > sbspace(sb))
561 		return (0);
562 	if (asa->sa_len > MLEN)
563 		return (0);
564 	MGET(m, M_DONTWAIT, MT_SONAME);
565 	if (m == 0)
566 		return (0);
567 	m->m_len = asa->sa_len;
568 	bcopy((caddr_t)asa, mtod(m, caddr_t), asa->sa_len);
569 	if (n)
570 		n->m_next = m0;		/* concatenate data to control */
571 	else
572 		control = m0;
573 	m->m_next = control;
574 	for (n = m; n; n = n->m_next)
575 		sballoc(sb, n);
576 	if (n = sb->sb_mb) {
577 		while (n->m_nextpkt)
578 			n = n->m_nextpkt;
579 		n->m_nextpkt = m;
580 	} else
581 		sb->sb_mb = m;
582 	return (1);
583 }
584 
585 sbappendcontrol(sb, m0, control)
586 	struct sockbuf *sb;
587 	struct mbuf *control, *m0;
588 {
589 	register struct mbuf *m, *n;
590 	int space = 0;
591 
592 	if (control == 0)
593 		panic("sbappendcontrol");
594 	for (m = control; ; m = m->m_next) {
595 		space += m->m_len;
596 		if (m->m_next == 0)
597 			break;
598 	}
599 	n = m;			/* save pointer to last control buffer */
600 	for (m = m0; m; m = m->m_next)
601 		space += m->m_len;
602 	if (space > sbspace(sb))
603 		return (0);
604 	n->m_next = m0;			/* concatenate data to control */
605 	for (m = control; m; m = m->m_next)
606 		sballoc(sb, m);
607 	if (n = sb->sb_mb) {
608 		while (n->m_nextpkt)
609 			n = n->m_nextpkt;
610 		n->m_nextpkt = control;
611 	} else
612 		sb->sb_mb = control;
613 	return (1);
614 }
615 
616 /*
617  * Compress mbuf chain m into the socket
618  * buffer sb following mbuf n.  If n
619  * is null, the buffer is presumed empty.
620  */
621 sbcompress(sb, m, n)
622 	register struct sockbuf *sb;
623 	register struct mbuf *m, *n;
624 {
625 	register int eor = 0;
626 
627 	while (m) {
628 		eor |= m->m_flags & M_EOR;
629 		if (m->m_len == 0) {
630 			m = m_free(m);
631 			continue;
632 		}
633 		if (n && (n->m_flags & (M_EXT | M_EOR)) == 0 &&
634 		    (n->m_data + n->m_len + m->m_len) < &n->m_dat[MLEN] &&
635 		    n->m_type == m->m_type) {
636 			bcopy(mtod(m, caddr_t), mtod(n, caddr_t) + n->m_len,
637 			    (unsigned)m->m_len);
638 			n->m_len += m->m_len;
639 			sb->sb_cc += m->m_len;
640 			m = m_free(m);
641 			continue;
642 		}
643 		if (n)
644 			n->m_next = m;
645 		else
646 			sb->sb_mb = m;
647 		sballoc(sb, m);
648 		n = m;
649 		m->m_flags &= ~M_EOR;
650 		m = m->m_next;
651 		n->m_next = 0;
652 	}
653 	if (n)
654 		n->m_flags |= eor;
655 }
656 
657 /*
658  * Free all mbufs in a sockbuf.
659  * Check that all resources are reclaimed.
660  */
661 sbflush(sb)
662 	register struct sockbuf *sb;
663 {
664 
665 	if (sb->sb_flags & SB_LOCK)
666 		panic("sbflush");
667 	while (sb->sb_mbcnt)
668 		sbdrop(sb, (int)sb->sb_cc);
669 	if (sb->sb_cc || sb->sb_mb)
670 		panic("sbflush 2");
671 }
672 
673 /*
674  * Drop data from (the front of) a sockbuf.
675  */
676 sbdrop(sb, len)
677 	register struct sockbuf *sb;
678 	register int len;
679 {
680 	register struct mbuf *m, *mn;
681 	struct mbuf *next;
682 
683 	next = (m = sb->sb_mb) ? m->m_nextpkt : 0;
684 	while (len > 0) {
685 		if (m == 0) {
686 			if (next == 0)
687 				panic("sbdrop");
688 			m = next;
689 			next = m->m_nextpkt;
690 			continue;
691 		}
692 		if (m->m_len > len) {
693 			m->m_len -= len;
694 			m->m_data += len;
695 			sb->sb_cc -= len;
696 			break;
697 		}
698 		len -= m->m_len;
699 		sbfree(sb, m);
700 		MFREE(m, mn);
701 		m = mn;
702 	}
703 	while (m && m->m_len == 0) {
704 		sbfree(sb, m);
705 		MFREE(m, mn);
706 		m = mn;
707 	}
708 	if (m) {
709 		sb->sb_mb = m;
710 		m->m_nextpkt = next;
711 	} else
712 		sb->sb_mb = next;
713 }
714 
715 /*
716  * Drop a record off the front of a sockbuf
717  * and move the next record to the front.
718  */
719 sbdroprecord(sb)
720 	register struct sockbuf *sb;
721 {
722 	register struct mbuf *m, *mn;
723 
724 	m = sb->sb_mb;
725 	if (m) {
726 		sb->sb_mb = m->m_nextpkt;
727 		do {
728 			sbfree(sb, m);
729 			MFREE(m, mn);
730 		} while (m = mn);
731 	}
732 }
733