VirtualBox

source: vbox/trunk/src/VBox/Devices/Network/slirp/libalias/alias_mod.h@ 21333

Last change on this file since 21333 was 20958, checked in by vboxsync, 16 years ago

NAT: export of libalias

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1/*-
2 * Copyright (c) 2005 Paolo Pisati <[email protected]>
3 * All rights reserved.
4 *
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.
13 *
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.
25 *
26 * $FreeBSD: src/sys/netinet/libalias/alias_mod.h,v 1.1.8.1 2009/04/15 03:14:26 kensmith Exp $
27 */
28
29/*
30 * Alias_mod.h defines the outside world interfaces for the packet aliasing
31 * modular framework
32 */
33
34#ifndef _ALIAS_MOD_H_
35#define _ALIAS_MOD_H_
36
37#if defined(_KERNEL) && !defined(VBOX)
38MALLOC_DECLARE(M_ALIAS);
39
40/* Use kernel allocator. */
41#if defined(_SYS_MALLOC_H_)
42#define malloc(x) malloc(x, M_ALIAS, M_NOWAIT|M_ZERO)
43#define calloc(x, n) malloc(x*n)
44#define free(x) free(x, M_ALIAS)
45#endif
46#else /* !VBOX */
47# ifdef RT_OS_WINDOWS
48# undef IN
49# undef OUT
50# endif /* RT_OS_WINDOWS */
51#endif /* VBOX */
52
53/* Protocol handlers struct & function. */
54
55/* Packet flow direction. */
56#define IN 1
57#define OUT 2
58
59/* Working protocol. */
60#define IP 1
61#define TCP 2
62#define UDP 4
63
64/*
65 * Data passed to protocol handler module, it must be filled
66 * right before calling find_handler() to determine which
67 * module is elegible to be called.
68 */
69
70struct alias_data {
71 struct alias_link *lnk;
72 struct in_addr *oaddr; /* Original address. */
73 struct in_addr *aaddr; /* Alias address. */
74 uint16_t *aport; /* Alias port. */
75 uint16_t *sport, *dport; /* Source & destination port */
76 uint16_t maxpktsize; /* Max packet size. */
77};
78
79/*
80 * This structure contains all the information necessary to make
81 * a protocol handler correctly work.
82 */
83
84struct proto_handler {
85 u_int pri; /* Handler priority. */
86 int16_t dir; /* Flow direction. */
87 uint8_t proto; /* Working protocol. */
88 int (*fingerprint)(struct libalias *la, /* Fingerprint * function. */
89 struct ip *pip, struct alias_data *ah);
90 int (*protohandler)(struct libalias *la, /* Aliasing * function. */
91 struct ip *pip, struct alias_data *ah);
92 LIST_ENTRY(proto_handler) entries;
93};
94
95
96/*
97 * Used only in userland when libalias needs to keep track of all
98 * module loaded. In kernel land (kld mode) we don't need to care
99 * care about libalias modules cause it's kld to do it for us.
100 */
101
102#define DLL_LEN 32
103struct dll {
104 char name[DLL_LEN]; /* Name of module. */
105 void *handle; /*
106 * Ptr to shared obj obtained through
107 * dlopen() - use this ptr to get access
108 * to any symbols from a loaded module
109 * via dlsym().
110 */
111 SLIST_ENTRY(dll) next;
112};
113
114/* Functions used with protocol handlers. */
115
116void handler_chain_init(void);
117void handler_chain_destroy(void);
118int LibAliasAttachHandlers(struct proto_handler *);
119int LibAliasDetachHandlers(struct proto_handler *);
120int detach_handler(struct proto_handler *);
121int find_handler(int8_t, int8_t, struct libalias *,
122 struct ip *, struct alias_data *);
123struct proto_handler *first_handler(void);
124
125/* Functions used with dll module. */
126
127void dll_chain_init(void);
128void dll_chain_destroy(void);
129int attach_dll(struct dll *);
130void *detach_dll(char *);
131struct dll *walk_dll_chain(void);
132
133/* End of handlers. */
134#define EOH -1
135
136/*
137 * Some defines borrowed from sys/module.h used to compile a kld
138 * in userland as a shared lib.
139 */
140
141#ifndef _KERNEL
142typedef enum modeventtype {
143 MOD_LOAD,
144 MOD_UNLOAD,
145 MOD_SHUTDOWN,
146 MOD_QUIESCE
147} modeventtype_t;
148
149typedef struct module *module_t;
150typedef int (*modeventhand_t)(module_t, int /* modeventtype_t */, void *);
151
152/*
153 * Struct for registering modules statically via SYSINIT.
154 */
155typedef struct moduledata {
156 const char *name; /* module name */
157 modeventhand_t evhand; /* event handler */
158 void *priv; /* extra data */
159} moduledata_t;
160#endif
161
162#endif /* !_ALIAS_MOD_H_ */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette