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_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
37 #include <sys/param.h>
38 #include <sys/kernel.h>
39 #include <sys/module.h>
42 #include <sys/types.h>
46 #include <netinet/in_systm.h>
47 #include <netinet/in.h>
48 #include <netinet/ip.h>
49 #include <netinet/udp.h>
52 #include <netinet/libalias/alias_local.h>
53 #include <netinet/libalias/alias_mod.h>
55 #include "alias_local.h"
56 #include "alias_mod.h"
60 AliasHandleDummy(struct libalias
*la
, struct ip
*ip
, struct alias_data
*ah
);
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
||
74 * Fingerprint the incoming packet, if it matches any conditions
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
89 protohandler(struct libalias
*la
, struct ip
*pip
, struct alias_data
*ah
)
92 AliasHandleDummy(la
, pip
, ah
);
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
[] = {
109 .fingerprint
= &fingerprint
,
110 .protohandler
= &protohandler
116 mod_handler(module_t mod
, int type
, void *data
)
123 LibAliasAttachHandlers(handlers
);
127 LibAliasDetachHandlers(handlers
);
138 moduledata_t alias_mod
= {
139 "alias_dummy", mod_handler
, NULL
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);
149 AliasHandleDummy(struct libalias
*la
, struct ip
*ip
, struct alias_data
*ah
)