2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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
32 * Alias_mod.h defines the outside world interfaces for the packet aliasing
40 MALLOC_DECLARE(M_ALIAS);
42 /* Use kernel allocator. */
43 #if defined(_SYS_MALLOC_H_)
45 #define malloc(x) malloc(x, M_ALIAS, M_NOWAIT|M_ZERO)
46 #define calloc(n, x) mallocarray((n), (x), M_ALIAS, M_NOWAIT|M_ZERO)
47 #define free(x) free(x, M_ALIAS)
51 /* Packet flow direction flags. */
56 /* Working protocol flags. */
62 * Data passed to protocol handler module, it must be filled
63 * right before calling find_handler() to determine which
64 * module is elegible to be called.
67 struct alias_link *lnk;
68 struct in_addr *oaddr; /* Original address. */
69 struct in_addr *aaddr; /* Alias address. */
70 uint16_t *aport; /* Alias port. */
71 uint16_t *sport, *dport; /* Source & destination port */
72 uint16_t maxpktsize; /* Max packet size. */
76 * This structure contains all the information necessary to make
77 * a protocol handler correctly work.
79 struct proto_handler {
80 u_int pri; /* Handler priority. */
81 int16_t dir; /* Flow direction. */
82 uint8_t proto; /* Working protocol. */
83 /* Fingerprint * function. */
84 int (*fingerprint)(struct libalias *, struct alias_data *);
85 /* Aliasing * function. */
86 int (*protohandler)(struct libalias *, struct ip *,
88 TAILQ_ENTRY(proto_handler) link;
91 /* End of handlers. */
92 #define EOH .dir = NODIR
94 /* Functions used with protocol handlers. */
95 int LibAliasAttachHandlers(struct proto_handler *);
96 int LibAliasDetachHandlers(struct proto_handler *);
97 int find_handler(int8_t, int8_t, struct libalias *, struct ip *,
99 struct proto_handler *first_handler(void);
103 * Used only in userland when libalias needs to keep track of all
104 * module loaded. In kernel land (kld mode) we don't need to care
105 * care about libalias modules cause it's kld to do it for us.
109 char name[DLL_LEN]; /* Name of module. */
111 * Ptr to shared obj obtained through
112 * dlopen() - use this ptr to get access
113 * to any symbols from a loaded module
116 SLIST_ENTRY(dll) next;
119 /* Functions used with dll module. */
120 void dll_chain_init(void);
121 void dll_chain_destroy(void);
122 int attach_dll(struct dll *);
123 void *detach_dll(char *);
124 struct dll *walk_dll_chain(void);
127 * Some defines borrowed from sys/module.h used to compile a kld
128 * in userland as a shared lib.
130 typedef enum modeventtype {
137 typedef struct module *module_t;
138 typedef int (*modeventhand_t)(module_t, int /* modeventtype_t */, void *);
141 * Struct for registering modules statically via SYSINIT.
143 typedef struct moduledata {
144 const char *name; /* module name */
145 modeventhand_t evhand; /* event handler */
146 void *priv; /* extra data */
148 #endif /* !_KERNEL */
150 #endif /* !_ALIAS_MOD_H_ */