Annotation of src/sys/sys/socketvar.h, Revision 1.42.2.6
1.42.2.6! nathanw 1: /* $NetBSD$ */
1.11 cgd 2:
1.1 cgd 3: /*-
1.8 mycroft 4: * Copyright (c) 1982, 1986, 1990, 1993
5: * The Regents of the University of California. All rights reserved.
1.1 cgd 6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. All advertising materials mentioning features or use of this software
16: * must display the following acknowledgement:
17: * This product includes software developed by the University of
18: * California, Berkeley and its contributors.
19: * 4. Neither the name of the University nor the names of its contributors
20: * may be used to endorse or promote products derived from this software
21: * without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33: * SUCH DAMAGE.
34: *
1.28 fvdl 35: * @(#)socketvar.h 8.3 (Berkeley) 2/19/95
1.1 cgd 36: */
37:
1.24 mikel 38: #ifndef _SYS_SOCKETVAR_H_
1.42 lukem 39: #define _SYS_SOCKETVAR_H_
1.24 mikel 40:
1.5 cgd 41: #include <sys/select.h> /* for struct selinfo */
1.27 thorpej 42: #include <sys/queue.h>
43:
1.38 simonb 44: #if !defined(_KERNEL) || defined(LKM)
1.29 matt 45: struct uio;
46: #endif
47:
1.27 thorpej 48: TAILQ_HEAD(soqhead, socket);
1.3 mycroft 49:
1.1 cgd 50: /*
51: * Kernel structure per socket.
52: * Contains send and receive buffer queues,
53: * handle on protocol and pointer to protocol
54: * private data and error information.
55: */
56: struct socket {
1.42 lukem 57: short so_type; /* generic type, see socket.h */
58: short so_options; /* from socket call, see socket.h */
59: short so_linger; /* time to linger while closing */
60: short so_state; /* internal state flags SS_*, below */
61: void *so_pcb; /* protocol control block */
62: struct protosw *so_proto; /* protocol handle */
1.1 cgd 63: /*
64: * Variables for connection queueing.
65: * Socket where accepts occur is so_head in all subsidiary sockets.
66: * If so_head is 0, socket is not related to an accept.
67: * For head socket so_q0 queues partially completed connections,
68: * while so_q is a queue of connections ready to be accepted.
69: * If a connection is aborted and it has so_head set, then
70: * it has to be pulled out of either so_q0 or so_q.
71: * We allow connections to queue up based on current queue lengths
72: * and limit on number of queued connections for this socket.
73: */
1.42 lukem 74: struct socket *so_head; /* back pointer to accept socket */
75: struct soqhead *so_onq; /* queue (q or q0) that we're on */
76: struct soqhead so_q0; /* queue of partial connections */
77: struct soqhead so_q; /* queue of incoming connections */
1.27 thorpej 78: TAILQ_ENTRY(socket) so_qe; /* our queue entry (q or q0) */
1.42 lukem 79: short so_q0len; /* partials on so_q0 */
80: short so_qlen; /* number of connections on so_q */
81: short so_qlimit; /* max number queued connections */
82: short so_timeo; /* connection timeout */
83: u_short so_error; /* error affecting connection */
84: pid_t so_pgid; /* pgid for signals */
85: u_long so_oobmark; /* chars to oob mark */
1.1 cgd 86: /*
87: * Variables for socket buffering.
88: */
1.42 lukem 89: struct sockbuf {
1.1 cgd 90: u_long sb_cc; /* actual chars in buffer */
91: u_long sb_hiwat; /* max actual char count */
92: u_long sb_mbcnt; /* chars of mbufs used */
93: u_long sb_mbmax; /* max chars of mbufs to use */
94: long sb_lowat; /* low water mark */
1.42 lukem 95: struct mbuf *sb_mb; /* the mbuf chain */
1.42.2.6! nathanw 96: struct mbuf *sb_mbtail; /* the last mbuf in the chain */
! 97: struct mbuf *sb_lastrecord;/* first mbuf of last record in
! 98: socket buffer */
1.42 lukem 99: struct selinfo sb_sel; /* process selecting read/write */
1.1 cgd 100: short sb_flags; /* flags, see below */
101: short sb_timeo; /* timeout for read/write */
102: } so_rcv, so_snd;
1.34 kml 103:
104: #ifndef SB_MAX
1.8 mycroft 105: #define SB_MAX (256*1024) /* default for max chars in sockbuf */
1.34 kml 106: #endif
107:
1.1 cgd 108: #define SB_LOCK 0x01 /* lock on data queue */
109: #define SB_WANT 0x02 /* someone is waiting to lock */
110: #define SB_WAIT 0x04 /* someone is waiting for data/space */
111: #define SB_SEL 0x08 /* someone is selecting */
112: #define SB_ASYNC 0x10 /* ASYNC I/O, need signals */
1.29 matt 113: #define SB_UPCALL 0x20 /* someone wants an upcall */
1.1 cgd 114: #define SB_NOINTR 0x40 /* operations not interruptible */
115:
1.42 lukem 116: void *so_internal; /* Space for svr4 stream data */
117: void (*so_upcall) __P((struct socket *so, caddr_t arg,
118: int waitf));
119: caddr_t so_upcallarg; /* Arg for above */
120: int (*so_send) __P((struct socket *so, struct mbuf *addr,
121: struct uio *uio, struct mbuf *top,
122: struct mbuf *control, int flags));
123: int (*so_receive) __P((struct socket *so,
124: struct mbuf **paddr,
125: struct uio *uio, struct mbuf **mp0,
126: struct mbuf **controlp, int *flagsp));
127: uid_t so_uid; /* who opened the socket */
1.42.2.5 nathanw 128: struct mbuf *so_pendfree; /* loaned-page mbufs w/ frees pending */
1.1 cgd 129: };
130:
1.42.2.6! nathanw 131: #define SB_EMPTY_FIXUP(sb) \
! 132: do { \
! 133: if ((sb)->sb_mb == NULL) { \
! 134: (sb)->sb_mbtail = NULL; \
! 135: (sb)->sb_lastrecord = NULL; \
! 136: } \
! 137: } while (/*CONSTCOND*/0)
! 138:
1.1 cgd 139: /*
140: * Socket state bits.
141: */
142: #define SS_NOFDREF 0x001 /* no file table ref any more */
143: #define SS_ISCONNECTED 0x002 /* socket connected to a peer */
144: #define SS_ISCONNECTING 0x004 /* in process of connecting to peer */
145: #define SS_ISDISCONNECTING 0x008 /* in process of disconnecting */
146: #define SS_CANTSENDMORE 0x010 /* can't send more data to peer */
147: #define SS_CANTRCVMORE 0x020 /* can't receive more data from peer */
148: #define SS_RCVATMARK 0x040 /* at mark on input */
1.33 mycroft 149: #define SS_ISDISCONNECTED 0x800 /* socket disconnected from peer */
1.1 cgd 150:
1.19 mycroft 151: #define SS_NBIO 0x080 /* non-blocking ops */
152: #define SS_ASYNC 0x100 /* async i/o notify */
153: #define SS_ISCONFIRMING 0x200 /* deciding to accept connection req */
1.42 lukem 154: #define SS_MORETOCOME 0x400 /*
155: * hint from sosend to lower layer;
156: * more data coming
157: */
1.42.2.2 nathanw 158: #define SS_ISAPIPE 0x800 /* socket is implementing a pipe */
1.1 cgd 159:
160:
161: /*
162: * Macros for sockets and socket buffering.
163: */
1.15 mycroft 164:
165: /*
166: * Do we need to notify the other side when I/O is possible?
167: */
1.42 lukem 168: #define sb_notify(sb) (((sb)->sb_flags & \
169: (SB_WAIT | SB_SEL | SB_ASYNC | SB_UPCALL)) != 0)
1.1 cgd 170:
171: /*
172: * How much space is there in a socket buffer (so->so_snd or so->so_rcv)?
173: * This is problematical if the fields are unsigned, as the space might
174: * still be negative (cc > hiwat or mbcnt > mbmax). Should detect
1.42.2.4 nathanw 175: * overflow and return 0.
1.1 cgd 176: */
177: #define sbspace(sb) \
1.42.2.4 nathanw 178: (lmin((sb)->sb_hiwat - (sb)->sb_cc, (sb)->sb_mbmax - (sb)->sb_mbcnt))
1.1 cgd 179:
180: /* do we have to send all at once on a socket? */
181: #define sosendallatonce(so) \
1.42 lukem 182: ((so)->so_proto->pr_flags & PR_ATOMIC)
1.1 cgd 183:
184: /* can we read something from so? */
185: #define soreadable(so) \
1.42 lukem 186: ((so)->so_rcv.sb_cc >= (so)->so_rcv.sb_lowat || \
187: ((so)->so_state & SS_CANTRCVMORE) || \
188: (so)->so_qlen || (so)->so_error)
1.1 cgd 189:
190: /* can we write something to so? */
191: #define sowriteable(so) \
1.42 lukem 192: ((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat && \
193: (((so)->so_state&SS_ISCONNECTED) || \
194: ((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0)) || \
195: ((so)->so_state & SS_CANTSENDMORE) || \
196: (so)->so_error)
1.1 cgd 197:
198: /* adjust counters in sb reflecting allocation of m */
1.42 lukem 199: #define sballoc(sb, m) \
200: do { \
201: (sb)->sb_cc += (m)->m_len; \
202: (sb)->sb_mbcnt += MSIZE; \
203: if ((m)->m_flags & M_EXT) \
204: (sb)->sb_mbcnt += (m)->m_ext.ext_size; \
1.42.2.2 nathanw 205: } while (/* CONSTCOND */ 0)
1.1 cgd 206:
207: /* adjust counters in sb reflecting freeing of m */
1.42 lukem 208: #define sbfree(sb, m) \
209: do { \
210: (sb)->sb_cc -= (m)->m_len; \
211: (sb)->sb_mbcnt -= MSIZE; \
212: if ((m)->m_flags & M_EXT) \
213: (sb)->sb_mbcnt -= (m)->m_ext.ext_size; \
1.42.2.2 nathanw 214: } while (/* CONSTCOND */ 0)
1.1 cgd 215:
216: /*
217: * Set lock on sockbuf sb; sleep if lock is already held.
218: * Unless SB_NOINTR is set on sockbuf, sleep is interruptible.
219: * Returns error without lock if sleep is interrupted.
220: */
1.42 lukem 221: #define sblock(sb, wf) \
222: ((sb)->sb_flags & SB_LOCK ? \
223: (((wf) == M_WAITOK) ? sb_lock(sb) : EWOULDBLOCK) : \
224: ((sb)->sb_flags |= SB_LOCK), 0)
1.1 cgd 225:
226: /* release lock on sockbuf sb */
1.42 lukem 227: #define sbunlock(sb) \
228: do { \
229: (sb)->sb_flags &= ~SB_LOCK; \
230: if ((sb)->sb_flags & SB_WANT) { \
231: (sb)->sb_flags &= ~SB_WANT; \
232: wakeup((caddr_t)&(sb)->sb_flags); \
233: } \
1.42.2.2 nathanw 234: } while (/* CONSTCOND */ 0)
1.42 lukem 235:
236: #define sorwakeup(so) \
237: do { \
238: if (sb_notify(&(so)->so_rcv)) \
239: sowakeup((so), &(so)->so_rcv); \
1.42.2.2 nathanw 240: } while (/* CONSTCOND */ 0)
1.42 lukem 241:
242: #define sowwakeup(so) \
243: do { \
244: if (sb_notify(&(so)->so_snd)) \
245: sowakeup((so), &(so)->so_snd); \
1.42.2.2 nathanw 246: } while (/* CONSTCOND */ 0)
1.1 cgd 247:
1.14 jtc 248: #ifdef _KERNEL
1.42 lukem 249: extern u_long sb_max;
1.1 cgd 250: /* to catch callers missing new second argument to sonewconn: */
251: #define sonewconn(head, connstatus) sonewconn1((head), (connstatus))
252:
253: /* strings for sleep message: */
1.42 lukem 254: extern const char netio[], netcon[], netcls[];
1.1 cgd 255:
1.42 lukem 256: extern struct pool socket_pool;
1.31 thorpej 257:
1.17 christos 258: struct mbuf;
259: struct sockaddr;
260: struct proc;
261: struct msghdr;
262: struct stat;
263:
1.1 cgd 264: /*
265: * File operations on sockets.
266: */
1.42 lukem 267: int soo_read(struct file *fp, off_t *offset, struct uio *uio,
268: struct ucred *cred, int flags);
269: int soo_write(struct file *fp, off_t *offset, struct uio *uio,
270: struct ucred *cred, int flags);
271: int soo_fcntl(struct file *fp, u_int cmd, caddr_t data, struct proc *p);
272: int soo_ioctl(struct file *fp, u_long cmd, caddr_t data, struct proc *p);
273: int soo_poll(struct file *fp, int events, struct proc *p);
274: int soo_close(struct file *fp, struct proc *p);
1.42.2.2 nathanw 275: int soo_stat(struct file *fp, struct stat *ub, struct proc *p);
1.42 lukem 276: int uipc_usrreq(struct socket *, int , struct mbuf *,
277: struct mbuf *, struct mbuf *, struct proc *);
278: int uipc_ctloutput(int, struct socket *, int, int, struct mbuf **);
279: void sbappend(struct sockbuf *sb, struct mbuf *m);
1.42.2.6! nathanw 280: void sbappendstream(struct sockbuf *sb, struct mbuf *m);
1.42 lukem 281: int sbappendaddr(struct sockbuf *sb, struct sockaddr *asa,
282: struct mbuf *m0, struct mbuf *control);
283: int sbappendcontrol(struct sockbuf *sb, struct mbuf *m0,
284: struct mbuf *control);
285: void sbappendrecord(struct sockbuf *sb, struct mbuf *m0);
286: void sbcheck(struct sockbuf *sb);
287: void sbcompress(struct sockbuf *sb, struct mbuf *m, struct mbuf *n);
1.23 thorpej 288: struct mbuf *
1.42 lukem 289: sbcreatecontrol(caddr_t p, int size, int type, int level);
290: void sbdrop(struct sockbuf *sb, int len);
291: void sbdroprecord(struct sockbuf *sb);
292: void sbflush(struct sockbuf *sb);
293: void sbinsertoob(struct sockbuf *sb, struct mbuf *m0);
294: void sbrelease(struct sockbuf *sb);
295: int sbreserve(struct sockbuf *sb, u_long cc);
296: int sbwait(struct sockbuf *sb);
297: int sb_lock(struct sockbuf *sb);
298: void soinit(void);
299: int soabort(struct socket *so);
300: int soaccept(struct socket *so, struct mbuf *nam);
301: int sobind(struct socket *so, struct mbuf *nam, struct proc *);
302: void socantrcvmore(struct socket *so);
303: void socantsendmore(struct socket *so);
304: int soclose(struct socket *so);
305: int soconnect(struct socket *so, struct mbuf *nam);
306: int soconnect2(struct socket *so1, struct socket *so2);
307: int socreate(int dom, struct socket **aso, int type, int proto);
308: int sodisconnect(struct socket *so);
309: void sofree(struct socket *so);
310: int sogetopt(struct socket *so, int level, int optname, struct mbuf **mp);
311: void sohasoutofband(struct socket *so);
312: void soisconnected(struct socket *so);
313: void soisconnecting(struct socket *so);
314: void soisdisconnected(struct socket *so);
315: void soisdisconnecting(struct socket *so);
316: int solisten(struct socket *so, int backlog);
1.7 mycroft 317: struct socket *
1.42 lukem 318: sonewconn1(struct socket *head, int connstatus);
319: void soqinsque(struct socket *head, struct socket *so, int q);
320: int soqremque(struct socket *so, int q);
321: int soreceive(struct socket *so, struct mbuf **paddr, struct uio *uio,
322: struct mbuf **mp0, struct mbuf **controlp, int *flagsp);
323: int soreserve(struct socket *so, u_long sndcc, u_long rcvcc);
324: void sorflush(struct socket *so);
325: int sosend(struct socket *so, struct mbuf *addr, struct uio *uio,
326: struct mbuf *top, struct mbuf *control, int flags);
327: int sosetopt(struct socket *so, int level, int optname, struct mbuf *m0);
328: int soshutdown(struct socket *so, int how);
329: void sowakeup(struct socket *so, struct sockbuf *sb);
1.42.2.3 nathanw 330: int sockargs(struct mbuf **, const void *, size_t, int);
1.42 lukem 331:
332: int sendit(struct proc *, int, struct msghdr *, int, register_t *);
333: int recvit(struct proc *, int, struct msghdr *, caddr_t, register_t *);
1.42.2.6! nathanw 334:
! 335: #ifdef SOCKBUF_DEBUG
! 336: void sblastrecordchk(struct sockbuf *, const char *);
! 337: #define SBLASTRECORDCHK(sb, where) sblastrecordchk((sb), (where))
! 338:
! 339: void sblastmbufchk(struct sockbuf *, const char *);
! 340: #define SBLASTMBUFCHK(sb, where) sblastmbufchk((sb), (where))
! 341: #else
! 342: #define SBLASTRECORDCHK(sb, where) /* nothing */
! 343: #define SBLASTMBUFCHK(sb, where) /* nothing */
! 344: #endif /* SOCKBUF_DEBUG */
1.17 christos 345:
1.14 jtc 346: #endif /* _KERNEL */
1.24 mikel 347:
348: #endif /* !_SYS_SOCKETVAR_H_ */
CVSweb <webmaster@jp.NetBSD.org>