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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [net/] [bsd_tcpip/] [v2_0/] [src/] [sys/] [kern/] [uipc_accf.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      src/sys/kern/uipc_accf.c
4
//
5
//==========================================================================
6
//####BSDCOPYRIGHTBEGIN####
7
//
8
// -------------------------------------------
9
//
10
// Portions of this software may have been derived from OpenBSD, 
11
// FreeBSD or other sources, and are covered by the appropriate
12
// copyright disclaimers included herein.
13
//
14
// Portions created by Red Hat are
15
// Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
16
//
17
// -------------------------------------------
18
//
19
//####BSDCOPYRIGHTEND####
20
//==========================================================================
21
 
22
/*
23
 * Copyright (c) 2000 Paycounter, Inc.
24
 * Author: Alfred Perlstein <alfred@paycounter.com>, <alfred@FreeBSD.org>
25
 * All rights reserved.
26
 *
27
 * Redistribution and use in source and binary forms, with or without
28
 * modification, are permitted provided that the following conditions
29
 * are met:
30
 * 1. Redistributions of source code must retain the above copyright
31
 *    notice, this list of conditions and the following disclaimer.
32
 * 2. Redistributions in binary form must reproduce the above copyright
33
 *    notice, this list of conditions and the following disclaimer in the
34
 *    documentation and/or other materials provided with the distribution.
35
 *
36
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
37
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
40
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
41
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
42
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
44
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
45
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46
 * SUCH DAMAGE.
47
 *
48
 *      $FreeBSD: src/sys/kern/uipc_accf.c,v 1.2.2.2 2000/09/20 21:19:21 ps Exp $
49
 */
50
 
51
#include <sys/param.h>
52
#include <sys/domain.h>
53
#include <sys/malloc.h>
54
#include <sys/mbuf.h>
55
#include <sys/protosw.h>
56
#include <sys/socket.h>
57
#include <sys/socketvar.h>
58
#include <sys/queue.h>
59
 
60
static SLIST_HEAD(, accept_filter) accept_filtlsthd =
61
        SLIST_HEAD_INITIALIZER(&accept_filtlsthd);
62
 
63
static int unloadable = 0;
64
 
65
/*
66
 * must be passed a malloc'd structure so we don't explode if the kld
67
 * is unloaded, we leak the struct on deallocation to deal with this,
68
 * but if a filter is loaded with the same name as a leaked one we re-use
69
 * the entry.
70
 */
71
int
72
accept_filt_add(struct accept_filter *filt)
73
{
74
        struct accept_filter *p;
75
 
76
        SLIST_FOREACH(p, &accept_filtlsthd, accf_next)
77
                if (strcmp(p->accf_name, filt->accf_name) == 0)  {
78
                        if (p->accf_callback != NULL) {
79
                                return (EEXIST);
80
                        } else {
81
                                p->accf_callback = filt->accf_callback;
82
                                FREE(filt, M_ACCF);
83
                                return (0);
84
                        }
85
                }
86
 
87
        if (p == NULL)
88
                SLIST_INSERT_HEAD(&accept_filtlsthd, filt, accf_next);
89
        return (0);
90
}
91
 
92
int
93
accept_filt_del(char *name)
94
{
95
        struct accept_filter *p;
96
 
97
        p = accept_filt_get(name);
98
        if (p == NULL)
99
                return (ENOENT);
100
 
101
        p->accf_callback = NULL;
102
        return (0);
103
}
104
 
105
struct accept_filter *
106
accept_filt_get(char *name)
107
{
108
        struct accept_filter *p;
109
 
110
        SLIST_FOREACH(p, &accept_filtlsthd, accf_next)
111
                if (strcmp(p->accf_name, name) == 0)
112
                        return (p);
113
 
114
        return (NULL);
115
}
116
 
117
#ifdef ACCEPT_FILTER_MOD
118
int
119
accept_filt_generic_mod_event(module_t mod, int event, void *data)
120
{
121
        struct accept_filter *p;
122
        struct accept_filter *accfp = (struct accept_filter *) data;
123
        int     s, error;
124
 
125
        switch (event) {
126
        case MOD_LOAD:
127
                MALLOC(p, struct accept_filter *, sizeof(*p), M_ACCF, M_WAITOK);
128
                bcopy(accfp, p, sizeof(*p));
129
                s = splnet();
130
                error = accept_filt_add(p);
131
                splx(s);
132
                break;
133
 
134
        case MOD_UNLOAD:
135
                /*
136
                 * Do not support unloading yet. we don't keep track of refcounts
137
                 * and unloading an accept filter callback and then having it called
138
                 * is a bad thing.  A simple fix would be to track the refcount
139
                 * in the struct accept_filter.
140
                 */
141
                if (unloadable != 0) {
142
                        s = splnet();
143
                        error = accept_filt_del(accfp->accf_name);
144
                        splx(s);
145
                } else
146
                        error = EOPNOTSUPP;
147
                break;
148
 
149
        case MOD_SHUTDOWN:
150
                error = 0;
151
                break;
152
 
153
        default:
154
                error = EOPNOTSUPP;
155
                break;
156
        }
157
 
158
        return (error);
159
}
160
#endif

powered by: WebSVN 2.1.0

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