OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [bsd_tcpip/] [current/] [include/] [sys/] [socketvar.h] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      include/sys/socketvar.h
4
//
5
//==========================================================================
6
// ####BSDCOPYRIGHTBEGIN####                                    
7
// -------------------------------------------                  
8
// This file is part of eCos, the Embedded Configurable Operating System.
9
//
10
// Portions of this software may have been derived from FreeBSD 
11
// or other sources, and if so are covered by the appropriate copyright
12
// and license included herein.                                 
13
//
14
// Portions created by the Free Software Foundation are         
15
// Copyright (C) 2002 Free Software Foundation, Inc.            
16
// -------------------------------------------                  
17
// ####BSDCOPYRIGHTEND####                                      
18
//==========================================================================
19
 
20
/*-
21
 * Copyright (c) 1982, 1986, 1990, 1993
22
 *      The Regents of the University of California.  All rights reserved.
23
 *
24
 * Redistribution and use in source and binary forms, with or without
25
 * modification, are permitted provided that the following conditions
26
 * are met:
27
 * 1. Redistributions of source code must retain the above copyright
28
 *    notice, this list of conditions and the following disclaimer.
29
 * 2. Redistributions in binary form must reproduce the above copyright
30
 *    notice, this list of conditions and the following disclaimer in the
31
 *    documentation and/or other materials provided with the distribution.
32
 * 3. All advertising materials mentioning features or use of this software
33
 *    must display the following acknowledgement:
34
 *      This product includes software developed by the University of
35
 *      California, Berkeley and its contributors.
36
 * 4. Neither the name of the University nor the names of its contributors
37
 *    may be used to endorse or promote products derived from this software
38
 *    without specific prior written permission.
39
 *
40
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
41
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
44
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50
 * SUCH DAMAGE.
51
 *
52
 *      @(#)socketvar.h 8.3 (Berkeley) 2/19/95
53
 * $FreeBSD: src/sys/sys/socketvar.h,v 1.46.2.6 2001/08/31 13:45:49 jlemon Exp $
54
 */
55
 
56
#ifndef _SYS_SOCKETVAR_H_
57
#define _SYS_SOCKETVAR_H_
58
 
59
#include <sys/queue.h>                  /* for TAILQ macros */
60
 
61
/*
62
 * Kernel structure per socket.
63
 * Contains send and receive buffer queues,
64
 * handle on protocol and pointer to protocol
65
 * private data and error information.
66
 */
67
typedef u_quad_t so_gen_t;
68
 
69
struct accept_filter;
70
 
71
struct socket {
72
        struct  vm_zone *so_zone;       /* zone we were allocated from */
73
        short   so_type;                /* generic type, see socket.h */
74
        short   so_options;             /* from socket call, see socket.h */
75
        short   so_linger;              /* time to linger while closing */
76
        short   so_state;               /* internal state flags SS_*, below */
77
        caddr_t so_pcb;                 /* protocol control block */
78
        struct  protosw *so_proto;      /* protocol handle */
79
/*
80
 * Variables for connection queuing.
81
 * Socket where accepts occur is so_head in all subsidiary sockets.
82
 * If so_head is 0, socket is not related to an accept.
83
 * For head socket so_incomp queues partially completed connections,
84
 * while so_comp is a queue of connections ready to be accepted.
85
 * If a connection is aborted and it has so_head set, then
86
 * it has to be pulled out of either so_incomp or so_comp.
87
 * We allow connections to queue up based on current queue lengths
88
 * and limit on number of queued connections for this socket.
89
 */
90
        struct  socket *so_head;        /* back pointer to accept socket */
91
        TAILQ_HEAD(, socket) so_incomp; /* queue of partial unaccepted connections */
92
        TAILQ_HEAD(, socket) so_comp;   /* queue of complete unaccepted connections */
93
        TAILQ_ENTRY(socket) so_list;    /* list of unaccepted connections */
94
        short   so_qlen;                /* number of unaccepted connections */
95
        short   so_incqlen;             /* number of unaccepted incomplete
96
                                           connections */
97
        short   so_qlimit;              /* max number queued connections */
98
        short   so_timeo;               /* connection timeout */
99
        u_short so_error;               /* error affecting connection */
100
        struct  sigio *so_sigio;        /* information for async I/O or
101
                                           out of band data (SIGURG) */
102
        u_long  so_oobmark;             /* chars to oob mark */
103
        TAILQ_HEAD(, aiocblist) so_aiojobq; /* AIO ops waiting on socket */
104
/*
105
 * Variables for socket buffering.
106
 */
107
        struct  sockbuf {
108
                u_long  sb_cc;          /* actual chars in buffer */
109
                u_long  sb_hiwat;       /* max actual char count */
110
                u_long  sb_mbcnt;       /* chars of mbufs used */
111
                u_long  sb_mbmax;       /* max chars of mbufs to use */
112
                long    sb_lowat;       /* low water mark */
113
                struct  mbuf *sb_mb;    /* the mbuf chain */
114
                struct  selinfo sb_sel; /* process selecting read/write */
115
                short   sb_flags;       /* flags, see below */
116
                short   sb_timeo;       /* timeout for read/write */
117
        } so_rcv, so_snd;
118
#define SB_MAX          (256*1024)      /* default for max chars in sockbuf */
119
#define SB_LOCK         0x01            /* lock on data queue */
120
#define SB_WANT         0x02            /* someone is waiting to lock */
121
#define SB_WAIT         0x04            /* someone is waiting for data/space */
122
#define SB_SEL          0x08            /* someone is selecting */
123
#define SB_ASYNC        0x10            /* ASYNC I/O, need signals */
124
#define SB_UPCALL       0x20            /* someone wants an upcall */
125
#define SB_NOINTR       0x40            /* operations not interruptible */
126
#define SB_AIO          0x80            /* AIO operations queued */
127
#define SB_KNOTE        0x100           /* kernel note attached */
128
 
129
        void    (*so_upcall) __P((struct socket *, void *, int));
130
        void    *so_upcallarg;
131
        struct  ucred *so_cred;         /* user credentials */
132
        /* NB: generation count must not be first; easiest to make it last. */
133
        so_gen_t so_gencnt;             /* generation count */
134
        void    *so_emuldata;           /* private data for emulators */
135
        struct  so_accf {
136
                struct  accept_filter *so_accept_filter;
137
                void    *so_accept_filter_arg;  /* saved filter args */
138
                char    *so_accept_filter_str;  /* saved user args */
139
        } *so_accf;
140
};
141
 
142
/*
143
 * Socket state bits.
144
 */
145
#define SS_NOFDREF              0x0001  /* no file table ref any more */
146
#define SS_ISCONNECTED          0x0002  /* socket connected to a peer */
147
#define SS_ISCONNECTING         0x0004  /* in process of connecting to peer */
148
#define SS_ISDISCONNECTING      0x0008  /* in process of disconnecting */
149
#define SS_CANTSENDMORE         0x0010  /* can't send more data to peer */
150
#define SS_CANTRCVMORE          0x0020  /* can't receive more data from peer */
151
#define SS_RCVATMARK            0x0040  /* at mark on input */
152
 
153
#define SS_NBIO                 0x0100  /* non-blocking ops */
154
#define SS_ASYNC                0x0200  /* async i/o notify */
155
#define SS_ISCONFIRMING         0x0400  /* deciding to accept connection req */
156
 
157
#define SS_INCOMP               0x0800  /* unaccepted, incomplete connection */
158
#define SS_COMP                 0x1000  /* unaccepted, complete connection */
159
#define SS_ISDISCONNECTED       0x2000  /* socket disconnected from peer */
160
 
161
/*
162
 * Externalized form of struct socket used by the sysctl(3) interface.
163
 */
164
struct  xsocket {
165
        size_t  xso_len;        /* length of this structure */
166
        struct  socket *xso_so; /* makes a convenient handle sometimes */
167
        short   so_type;
168
        short   so_options;
169
        short   so_linger;
170
        short   so_state;
171
        caddr_t so_pcb;         /* another convenient handle */
172
        int     xso_protocol;
173
        int     xso_family;
174
        short   so_qlen;
175
        short   so_incqlen;
176
        short   so_qlimit;
177
        short   so_timeo;
178
        u_short so_error;
179
        pid_t   so_pgid;
180
        u_long  so_oobmark;
181
        struct  xsockbuf {
182
                u_long  sb_cc;
183
                u_long  sb_hiwat;
184
                u_long  sb_mbcnt;
185
                u_long  sb_mbmax;
186
                long    sb_lowat;
187
                short   sb_flags;
188
                short   sb_timeo;
189
        } so_rcv, so_snd;
190
        uid_t   so_uid;         /* XXX */
191
};
192
 
193
/*
194
 * Macros for sockets and socket buffering.
195
 */
196
 
197
/*
198
 * Do we need to notify the other side when I/O is possible?
199
 */
200
#define sb_notify(sb)   (((sb)->sb_flags & (SB_WAIT | SB_SEL | SB_ASYNC | \
201
    SB_UPCALL | SB_AIO | SB_KNOTE)) != 0)
202
 
203
/*
204
 * How much space is there in a socket buffer (so->so_snd or so->so_rcv)?
205
 * This is problematical if the fields are unsigned, as the space might
206
 * still be negative (cc > hiwat or mbcnt > mbmax).  Should detect
207
 * overflow and return 0.  Should use "lmin" but it doesn't exist now.
208
 */
209
#define sbspace(sb) \
210
    ((long) imin((int)((sb)->sb_hiwat - (sb)->sb_cc), \
211
         (int)((sb)->sb_mbmax - (sb)->sb_mbcnt)))
212
 
213
/* do we have to send all at once on a socket? */
214
#define sosendallatonce(so) \
215
    ((so)->so_proto->pr_flags & PR_ATOMIC)
216
 
217
/* can we read something from so? */
218
#define soreadable(so) \
219
    ((so)->so_rcv.sb_cc >= (so)->so_rcv.sb_lowat || \
220
        ((so)->so_state & SS_CANTRCVMORE) || \
221
        (so)->so_comp.tqh_first || (so)->so_error)
222
 
223
/* can we write something to so? */
224
#define sowriteable(so) \
225
    ((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat && \
226
        (((so)->so_state&SS_ISCONNECTED) || \
227
          ((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0)) || \
228
     ((so)->so_state & SS_CANTSENDMORE) || \
229
     (so)->so_error)
230
 
231
/* adjust counters in sb reflecting allocation of m */
232
#define sballoc(sb, m) { \
233
        (sb)->sb_cc += (m)->m_len; \
234
        (sb)->sb_mbcnt += MSIZE; \
235
        if ((m)->m_flags & M_EXT) \
236
                (sb)->sb_mbcnt += (m)->m_ext.ext_size; \
237
}
238
 
239
/* adjust counters in sb reflecting freeing of m */
240
#define sbfree(sb, m) { \
241
        (sb)->sb_cc -= (m)->m_len; \
242
        (sb)->sb_mbcnt -= MSIZE; \
243
        if ((m)->m_flags & M_EXT) \
244
                (sb)->sb_mbcnt -= (m)->m_ext.ext_size; \
245
}
246
 
247
/*
248
 * Set lock on sockbuf sb; sleep if lock is already held.
249
 * Unless SB_NOINTR is set on sockbuf, sleep is interruptible.
250
 * Returns error without lock if sleep is interrupted.
251
 */
252
#define sblock(sb, wf) ((sb)->sb_flags & SB_LOCK ? \
253
                (((wf) == M_WAITOK) ? sb_lock(sb) : EWOULDBLOCK) : \
254
                ((sb)->sb_flags |= SB_LOCK, 0))
255
 
256
/* release lock on sockbuf sb */
257
#define sbunlock(sb) { \
258
        (sb)->sb_flags &= ~SB_LOCK; \
259
        if ((sb)->sb_flags & SB_WANT) { \
260
                (sb)->sb_flags &= ~SB_WANT; \
261
                wakeup((caddr_t)&(sb)->sb_flags); \
262
        } \
263
}
264
 
265
#define sorwakeup(so)   do { \
266
                          if (sb_notify(&(so)->so_rcv)) \
267
                            sowakeup((so), &(so)->so_rcv); \
268
                        } while (0)
269
 
270
#define sowwakeup(so)   do { \
271
                          if (sb_notify(&(so)->so_snd)) \
272
                            sowakeup((so), &(so)->so_snd); \
273
                        } while (0)
274
 
275
#ifdef _KERNEL
276
 
277
/*
278
 * Argument structure for sosetopt et seq.  This is in the KERNEL
279
 * section because it will never be visible to user code.
280
 */
281
enum sopt_dir { SOPT_GET, SOPT_SET };
282
struct sockopt {
283
        enum    sopt_dir sopt_dir; /* is this a get or a set? */
284
        int     sopt_level;     /* second arg of [gs]etsockopt */
285
        int     sopt_name;      /* third arg of [gs]etsockopt */
286
        void   *sopt_val;       /* fourth arg of [gs]etsockopt */
287
        size_t  sopt_valsize;   /* (almost) fifth arg of [gs]etsockopt */
288
        struct  proc *sopt_p;   /* calling process or null if kernel */
289
};
290
 
291
struct sf_buf {
292
        SLIST_ENTRY(sf_buf) free_list;  /* list of free buffer slots */
293
        int             refcnt;         /* reference count */
294
        struct          vm_page *m;     /* currently mapped page */
295
        vm_offset_t     kva;            /* va of mapping */
296
};
297
 
298
struct accept_filter {
299
        char    accf_name[16];
300
        void    (*accf_callback)
301
                __P((struct socket *so, void *arg, int waitflag));
302
        void *  (*accf_create)
303
                __P((struct socket *so, char *arg));
304
        void    (*accf_destroy)
305
                __P((struct socket *so));
306
        SLIST_ENTRY(accept_filter) accf_next;   /* next on the list */
307
};
308
 
309
#ifdef MALLOC_DECLARE
310
MALLOC_DECLARE(M_PCB);
311
MALLOC_DECLARE(M_SONAME);
312
MALLOC_DECLARE(M_ACCF);
313
#endif
314
 
315
extern int      maxsockets;
316
extern u_long   sb_max;
317
extern struct   vm_zone *socket_zone;
318
extern so_gen_t so_gencnt;
319
 
320
struct file;
321
struct filedesc;
322
struct mbuf;
323
struct sockaddr;
324
struct stat;
325
struct ucred;
326
struct uio;
327
struct knote;
328
 
329
/*
330
 * File operations on sockets.
331
 */
332
int     soo_read __P((struct file *fp, struct uio *uio, struct ucred *cred,
333
            int flags, struct proc *p));
334
int     soo_write __P((struct file *fp, struct uio *uio, struct ucred *cred,
335
            int flags, struct proc *p));
336
int     soo_close __P((struct file *fp, struct proc *p));
337
int     soo_ioctl __P((struct file *fp, u_long cmd, caddr_t data,
338
            struct proc *p));
339
int     soo_poll __P((struct file *fp, int events, struct ucred *cred,
340
            struct proc *p));
341
int     soo_stat __P((struct file *fp, struct stat *ub, struct proc *p));
342
int     sokqfilter __P((struct file *fp, struct knote *kn));
343
 
344
/*
345
 * From uipc_socket and friends
346
 */
347
struct  sockaddr *dup_sockaddr __P((struct sockaddr *sa, int canwait));
348
int     holdsock __P((struct filedesc *fdp, int fdes, struct file **fpp));
349
int     sockargs __P((struct mbuf **mp, caddr_t buf, int buflen, int type));
350
void    sbappend __P((struct sockbuf *sb, struct mbuf *m));
351
int     sbappendaddr __P((struct sockbuf *sb, struct sockaddr *asa,
352
            struct mbuf *m0, struct mbuf *control));
353
int     sbappendcontrol __P((struct sockbuf *sb, struct mbuf *m0,
354
            struct mbuf *control));
355
void    sbappendrecord __P((struct sockbuf *sb, struct mbuf *m0));
356
void    sbcheck __P((struct sockbuf *sb));
357
void    sbcompress __P((struct sockbuf *sb, struct mbuf *m, struct mbuf *n));
358
struct mbuf *
359
        sbcreatecontrol __P((caddr_t p, int size, int type, int level));
360
void    sbdrop __P((struct sockbuf *sb, int len));
361
void    sbdroprecord __P((struct sockbuf *sb));
362
void    sbflush __P((struct sockbuf *sb));
363
void    sbinsertoob __P((struct sockbuf *sb, struct mbuf *m0));
364
void    sbrelease __P((struct sockbuf *sb, struct socket *so));
365
int     sbreserve __P((struct sockbuf *sb, u_long cc, struct socket *so,
366
                       struct proc *p));
367
void    sbtoxsockbuf __P((struct sockbuf *sb, struct xsockbuf *xsb));
368
int     sbwait __P((struct sockbuf *sb));
369
int     sb_lock __P((struct sockbuf *sb));
370
int     soabort __P((struct socket *so));
371
int     soaccept __P((struct socket *so, struct sockaddr **nam));
372
struct  socket *soalloc __P((int waitok));
373
int     sobind __P((struct socket *so, struct sockaddr *nam, struct proc *p));
374
void    socantrcvmore __P((struct socket *so));
375
void    socantsendmore __P((struct socket *so));
376
int     soclose __P((struct socket *so));
377
int     soconnect __P((struct socket *so, struct sockaddr *nam, struct proc *p));
378
int     soconnect2 __P((struct socket *so1, struct socket *so2));
379
int     socreate __P((int dom, struct socket **aso, int type, int proto,
380
            struct proc *p));
381
void    sodealloc __P((struct socket *so));
382
int     sodisconnect __P((struct socket *so));
383
void    sofree __P((struct socket *so));
384
int     sogetopt __P((struct socket *so, struct sockopt *sopt));
385
void    sohasoutofband __P((struct socket *so));
386
void    soisconnected __P((struct socket *so));
387
void    soisconnecting __P((struct socket *so));
388
void    soisdisconnected __P((struct socket *so));
389
void    soisdisconnecting __P((struct socket *so));
390
int     solisten __P((struct socket *so, int backlog, struct proc *p));
391
struct socket *
392
        sodropablereq __P((struct socket *head));
393
struct socket *
394
        sonewconn __P((struct socket *head, int connstatus));
395
struct socket *
396
        sonewconn3 __P((struct socket *head, int connstatus, struct proc *p));
397
int     sooptcopyin __P((struct sockopt *sopt, void *buf, size_t len,
398
                         size_t minlen));
399
int     sooptcopyout __P((struct sockopt *sopt, void *buf, size_t len));
400
 
401
/* XXX; prepare mbuf for (__FreeBSD__ < 3) routines. */
402
int     soopt_getm __P((struct sockopt *sopt, struct mbuf **mp));
403
int     soopt_mcopyin __P((struct sockopt *sopt, struct mbuf *m));
404
int     soopt_mcopyout __P((struct sockopt *sopt, struct mbuf *m));
405
 
406
int     sopoll __P((struct socket *so, int events, struct ucred *cred,
407
                    struct proc *p));
408
int     soreceive __P((struct socket *so, struct sockaddr **paddr,
409
                       struct uio *uio, struct mbuf **mp0,
410
                       struct mbuf **controlp, int *flagsp));
411
int     soreserve __P((struct socket *so, u_long sndcc, u_long rcvcc));
412
void    sorflush __P((struct socket *so));
413
int     sosend __P((struct socket *so, struct sockaddr *addr, struct uio *uio,
414
                    struct mbuf *top, struct mbuf *control, int flags,
415
                    struct proc *p));
416
int     sosetopt __P((struct socket *so, struct sockopt *sopt));
417
int     soshutdown __P((struct socket *so, int how));
418
void    sotoxsocket __P((struct socket *so, struct xsocket *xso));
419
void    sowakeup __P((struct socket *so, struct sockbuf *sb));
420
 
421
/* accept filter functions */
422
int     accept_filt_add __P((struct accept_filter *filt));
423
int     accept_filt_del __P((char *name));
424
struct accept_filter *  accept_filt_get __P((char *name));
425
#ifdef ACCEPT_FILTER_MOD
426
int accept_filt_generic_mod_event __P((module_t mod, int event, void *data));
427
SYSCTL_DECL(_net_inet_accf);
428
#endif /* ACCEPT_FILTER_MOD */
429
 
430
#endif /* _KERNEL */
431
 
432
#endif /* !_SYS_SOCKETVAR_H_ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.