2 * Copyright (c) 1982, 1986, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)socketvar.h 8.3 (Berkeley) 2/19/95
30 * $FreeBSD: src/sys/sys/socketvar.h,v 1.46.2.10 2003/08/24 08:24:39 hsu Exp $
31 * $DragonFly: src/sys/sys/sockbuf.h,v 1.1 2007/04/22 01:13:17 dillon Exp $
34 #ifndef _SYS_SOCKBUF_H_
35 #define _SYS_SOCKBUF_H_
38 #include <sys/types.h>
41 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
44 * Generic socket buffer for keeping track of mbuf chains. These
45 * are used primarily to manipulate mbuf chains in standalone pieces
49 u_long sb_cc
; /* actual chars in buffer */
50 u_long sb_mbcnt
; /* chars of mbufs used */
51 u_long sb_cc_prealloc
;
52 u_long sb_mbcnt_prealloc
;
53 u_long sb_climit
; /* data limit when used for I/O */
54 struct mbuf
*sb_mb
; /* the mbuf chain */
55 struct mbuf
*sb_lastmbuf
; /* last mbuf in sb_mb */
56 struct mbuf
*sb_lastrecord
; /* last record in sb_mb
57 * valid <=> sb_mb non-NULL */
60 #define SB_MAX (512*1024) /* default for max chars in sockbuf */
66 #include <machine/atomic.h>
72 * Macros for sockets and socket buffering.
76 #define sbcheck(sb) _sbcheck(sb)
81 /* adjust counters in sb reflecting allocation of m */
82 #define sballoc(sb, m) { \
83 (sb)->sb_cc += (m)->m_len; \
84 (sb)->sb_mbcnt += MSIZE; \
85 if ((m)->m_flags & M_EXT) \
86 (sb)->sb_mbcnt += (m)->m_ext.ext_size; \
89 /* adjust counters in sb reflecting allocation of m */
90 #define sbprealloc(sb, m) { \
93 atomic_add_long(&((sb)->sb_cc_prealloc), (m)->m_len); \
96 if ((m)->m_flags & M_EXT) \
97 __mbcnt_sz += (m)->m_ext.ext_size; \
98 atomic_add_long(&((sb)->sb_mbcnt_prealloc), __mbcnt_sz); \
101 /* adjust counters in sb reflecting freeing of m */
102 #define sbfree(sb, m) { \
105 (sb)->sb_cc -= (m)->m_len; \
106 atomic_subtract_long(&((sb)->sb_cc_prealloc), (m)->m_len); \
108 __mbcnt_sz = MSIZE; \
109 if ((m)->m_flags & M_EXT) \
110 __mbcnt_sz += (m)->m_ext.ext_size; \
111 (sb)->sb_mbcnt -= __mbcnt_sz; \
112 atomic_subtract_long(&((sb)->sb_mbcnt_prealloc), __mbcnt_sz); \
116 sbinit(struct sockbuf
*sb
, u_long climit
)
120 sb
->sb_cc_prealloc
= 0;
121 sb
->sb_mbcnt_prealloc
= 0;
122 sb
->sb_climit
= climit
;
124 sb
->sb_lastmbuf
= NULL
;
125 sb
->sb_lastrecord
= NULL
;
128 void sbappend (struct sockbuf
*sb
, struct mbuf
*m
);
129 int sbappendaddr (struct sockbuf
*sb
, const struct sockaddr
*asa
,
130 struct mbuf
*m0
, struct mbuf
*control
);
131 int sbappendcontrol (struct sockbuf
*sb
, struct mbuf
*m0
,
132 struct mbuf
*control
);
133 void sbappendrecord (struct sockbuf
*sb
, struct mbuf
*m0
);
134 void sbappendstream (struct sockbuf
*sb
, struct mbuf
*m
);
135 void _sbcheck (struct sockbuf
*sb
);
136 void sbcompress (struct sockbuf
*sb
, struct mbuf
*m
, struct mbuf
*n
);
138 sbcreatecontrol (caddr_t p
, int size
, int type
, int level
);
139 void sbdrop (struct sockbuf
*sb
, int len
);
140 void sbdroprecord (struct sockbuf
*sb
);
142 sbunlinkmbuf (struct sockbuf
*, struct mbuf
*, struct mbuf
**);
143 void sbflush (struct sockbuf
*sb
);
147 #endif /* !_SYS_SOCKBUF_H_ */