2 * Copyright (c) 2005 Paolo Pisati <piso@FreeBSD.org>
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.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD: src/sys/netinet/libalias/alias_mod.c,v 1.3.6.1 2008/11/25 02:59:29 kensmith Exp $");
31 #include <sys/libkern.h>
32 #include <sys/param.h>
35 #include <sys/queue.h>
39 #include <sys/types.h>
43 #include <netinet/in_systm.h>
44 #include <netinet/in.h>
45 #include <netinet/ip.h>
48 #include "alias_local.h"
49 #include "alias_mod.h"
51 /* Protocol and userland module handlers chains. */
52 LIST_HEAD(handler_chain, proto_handler) handler_chain = LIST_HEAD_INITIALIZER(foo);
54 SLIST_HEAD(dll_chain, dll) dll_chain = SLIST_HEAD_INITIALIZER(foo);
57 #define LIBALIAS_RWLOCK_INIT() ;
58 #define LIBALIAS_RWLOCK_DESTROY() ;
59 #define LIBALIAS_WLOCK_ASSERT() ;
60 #define LIBALIAS_RLOCK() ;
61 #define LIBALIAS_RUNLOCK() ;
62 #define LIBALIAS_WLOCK() ;
63 #define LIBALIAS_WUNLOCK() ;
64 #define _handler_chain_init() ;
65 #define _handler_chain_destroy() ;
68 handler_chain_init(void)
70 _handler_chain_init();
74 handler_chain_destroy(void)
76 _handler_chain_destroy();
80 _attach_handler(struct proto_handler *p)
82 struct proto_handler *b = NULL;
84 LIBALIAS_WLOCK_ASSERT();
85 LIST_FOREACH(b, &handler_chain, entries) {
86 if ((b->pri == p->pri) &&
88 (b->proto == p->proto))
89 return (EEXIST); /* Priority conflict. */
90 if (b->pri > p->pri) {
91 LIST_INSERT_BEFORE(b, p, entries);
95 /* End of list or found right position, inserts here. */
97 LIST_INSERT_AFTER(b, p, entries);
99 LIST_INSERT_HEAD(&handler_chain, p, entries);
104 _detach_handler(struct proto_handler *p)
106 struct proto_handler *b, *b_tmp;;
108 LIBALIAS_WLOCK_ASSERT();
110 LIST_FOREACH_MUTABLE(b, &handler_chain, entries, b_tmp) {
112 LIST_REMOVE(b, entries);
118 return (ENOENT); /* Handler not found. */
122 LibAliasAttachHandlers(struct proto_handler *_p)
128 if (*((int *)&_p[i]) == EOH)
130 error = _attach_handler(&_p[i]);
139 LibAliasDetachHandlers(struct proto_handler *_p)
145 if (*((int *)&_p[i]) == EOH)
147 error = _detach_handler(&_p[i]);
156 detach_handler(struct proto_handler *_p)
161 error = _detach_handler(_p);
167 find_handler(int8_t dir, int8_t proto, struct libalias *la, struct ip *pip,
168 struct alias_data *ad)
170 struct proto_handler *p;
175 LIST_FOREACH(p, &handler_chain, entries) {
176 if ((p->dir & dir) && (p->proto & proto))
177 if (p->fingerprint(la, pip, ad) == 0) {
178 error = p->protohandler(la, pip, ad);
186 struct proto_handler *
190 return (LIST_FIRST(&handler_chain));
193 /* Dll manipulation code - this code is not thread safe... */
202 t = SLIST_FIRST(&dll_chain);
205 SLIST_REMOVE_HEAD(&dll_chain, next);