1 //==========================================================================
3 // src/sys/kern/uipc_accf.c
5 //==========================================================================
6 //####BSDCOPYRIGHTBEGIN####
8 // -------------------------------------------
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.
14 // Portions created by Red Hat are
15 // Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
17 // -------------------------------------------
19 //####BSDCOPYRIGHTEND####
20 //==========================================================================
23 * Copyright (c) 2000 Paycounter, Inc.
24 * Author: Alfred Perlstein <alfred@paycounter.com>, <alfred@FreeBSD.org>
25 * All rights reserved.
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
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.
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
48 * $FreeBSD: src/sys/kern/uipc_accf.c,v 1.2.2.2 2000/09/20 21:19:21 ps Exp $
51 #include <sys/param.h>
52 #include <sys/domain.h>
53 #include <sys/malloc.h>
55 #include <sys/protosw.h>
56 #include <sys/socket.h>
57 #include <sys/socketvar.h>
58 #include <sys/queue.h>
60 static SLIST_HEAD(, accept_filter) accept_filtlsthd =
61 SLIST_HEAD_INITIALIZER(&accept_filtlsthd);
63 #ifdef ACCEPT_FILTER_MOD
64 static int unloadable = 0;
68 * must be passed a malloc'd structure so we don't explode if the kld
69 * is unloaded, we leak the struct on deallocation to deal with this,
70 * but if a filter is loaded with the same name as a leaked one we re-use
74 accept_filt_add(struct accept_filter *filt)
76 struct accept_filter *p;
78 SLIST_FOREACH(p, &accept_filtlsthd, accf_next)
79 if (strcmp(p->accf_name, filt->accf_name) == 0) {
80 if (p->accf_callback != NULL) {
83 p->accf_callback = filt->accf_callback;
90 SLIST_INSERT_HEAD(&accept_filtlsthd, filt, accf_next);
95 accept_filt_del(char *name)
97 struct accept_filter *p;
99 p = accept_filt_get(name);
103 p->accf_callback = NULL;
107 struct accept_filter *
108 accept_filt_get(char *name)
110 struct accept_filter *p;
112 SLIST_FOREACH(p, &accept_filtlsthd, accf_next)
113 if (strcmp(p->accf_name, name) == 0)
119 #ifdef ACCEPT_FILTER_MOD
121 accept_filt_generic_mod_event(module_t mod, int event, void *data)
123 struct accept_filter *p;
124 struct accept_filter *accfp = (struct accept_filter *) data;
129 MALLOC(p, struct accept_filter *, sizeof(*p), M_ACCF, M_WAITOK);
130 bcopy(accfp, p, sizeof(*p));
132 error = accept_filt_add(p);
138 * Do not support unloading yet. we don't keep track of refcounts
139 * and unloading an accept filter callback and then having it called
140 * is a bad thing. A simple fix would be to track the refcount
141 * in the struct accept_filter.
143 if (unloadable != 0) {
145 error = accept_filt_del(accfp->accf_name);