2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2005 Paolo Pisati <piso@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
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 alias_data *ah)
66 * Check here all the data that will be used later, if any field
67 * is empy/NULL, return a -1 value.
69 if (ah->dport == NULL || ah->sport == NULL || ah->lnk == NULL ||
73 * Fingerprint the incoming packet, if it matches any conditions
76 if (ntohs(*ah->dport) == 123 || ntohs(*ah->sport) == 456)
77 return (0); /* I know how to handle it. */
78 return (-1); /* I don't recognize this packet. */
82 * Wrap in this general purpose function, the real function used to alias the
87 protohandler(struct libalias *la, struct ip *pip, struct alias_data *ah)
89 AliasHandleDummy(la, pip, ah);
94 * NOTA BENE: the next variable MUST NOT be renamed in any case if you want
95 * your module to work in userland, cause it's used to find and use all
96 * the protocol handlers present in every module.
97 * So WATCH OUT, your module needs this variables and it needs it with
98 * ITS EXACT NAME: handlers.
101 struct proto_handler handlers [] = {
106 .fingerprint = &fingerprint,
107 .protohandler = &protohandler
113 mod_handler(module_t mod, int type, void *data)
120 LibAliasAttachHandlers(handlers);
124 LibAliasDetachHandlers(handlers);
135 moduledata_t alias_mod = {
136 "alias_dummy", mod_handler, NULL
140 DECLARE_MODULE(alias_dummy, alias_mod, SI_SUB_DRIVERS, SI_ORDER_SECOND);
141 MODULE_VERSION(alias_dummy, 1);
142 MODULE_DEPEND(alias_dummy, libalias, 1, 1, 1);
146 AliasHandleDummy(struct libalias *la, struct ip *ip, struct alias_data *ah)