kernel - cleanup vfs_cache debugging
[dragonfly.git] / sys / net / libalias / alias_dummy.c
blobfe4a6aea7b411597553c003113c50c007e64810f
1 /*-
2 * Copyright (c) 2005 Paolo Pisati <piso@FreeBSD.org>
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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
24 * SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD: src/sys/netinet/libalias/alias_dummy.c,v 1.1.6.1 2008/11/25 02:59:29 kensmith Exp $");
31 * Alias_dummy is just an empty skeleton used to demostrate how to write
32 * a module for libalias, that will run unalterated in userland or in
33 * kernel land.
36 #ifdef _KERNEL
37 #include <sys/param.h>
38 #include <sys/kernel.h>
39 #include <sys/module.h>
40 #else
41 #include <errno.h>
42 #include <sys/types.h>
43 #include <stdio.h>
44 #endif
46 #include <netinet/in_systm.h>
47 #include <netinet/in.h>
48 #include <netinet/ip.h>
49 #include <netinet/udp.h>
51 #ifdef _KERNEL
52 #include <netinet/libalias/alias_local.h>
53 #include <netinet/libalias/alias_mod.h>
54 #else
55 #include "alias_local.h"
56 #include "alias_mod.h"
57 #endif
59 static void
60 AliasHandleDummy(struct libalias *la, struct ip *ip, struct alias_data *ah);
62 static int
63 fingerprint(struct libalias *la, struct ip *pip, struct alias_data *ah)
67 * Check here all the data that will be used later, if any field
68 * is empy/NULL, return a -1 value.
70 if (ah->dport == NULL || ah->sport == NULL || ah->lnk == NULL ||
71 ah->maxpktsize == 0)
72 return (-1);
74 * Fingerprint the incoming packet, if it matches any conditions
75 * return an OK value.
77 if (ntohs(*ah->dport) == 123
78 || ntohs(*ah->sport) == 456)
79 return (0); /* I know how to handle it. */
80 return (-1); /* I don't recognize this packet. */
84 * Wrap in this general purpose function, the real function used to alias the
85 * packets.
88 static int
89 protohandler(struct libalias *la, struct ip *pip, struct alias_data *ah)
92 AliasHandleDummy(la, pip, ah);
93 return (0);
97 * NOTA BENE: the next variable MUST NOT be renamed in any case if you want
98 * your module to work in userland, cause it's used to find and use all
99 * the protocol handlers present in every module.
100 * So WATCH OUT, your module needs this variables and it needs it with
101 * ITS EXACT NAME: handlers.
104 struct proto_handler handlers [] = {
106 .pri = 666,
107 .dir = IN|OUT,
108 .proto = UDP|TCP,
109 .fingerprint = &fingerprint,
110 .protohandler = &protohandler
112 { EOH }
115 static int
116 mod_handler(module_t mod, int type, void *data)
118 int error;
120 switch (type) {
121 case MOD_LOAD:
122 error = 0;
123 LibAliasAttachHandlers(handlers);
124 break;
125 case MOD_UNLOAD:
126 error = 0;
127 LibAliasDetachHandlers(handlers);
128 break;
129 default:
130 error = EINVAL;
132 return (error);
135 #ifdef _KERNEL
136 static
137 #endif
138 moduledata_t alias_mod = {
139 "alias_dummy", mod_handler, NULL
142 #ifdef _KERNEL
143 DECLARE_MODULE(alias_dummy, alias_mod, SI_SUB_DRIVERS, SI_ORDER_SECOND);
144 MODULE_VERSION(alias_dummy, 1);
145 MODULE_DEPEND(alias_dummy, libalias, 1, 1, 1);
146 #endif
148 static void
149 AliasHandleDummy(struct libalias *la, struct ip *ip, struct alias_data *ah)
151 ; /* Dummy. */