VirtualBox

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

Last change on this file was 52683, checked in by vboxsync, 10 years ago

NAT: Fix #else /* VBOX */ comments to reflect the condition when that
#else is selected. While here, add spaces inside cramped #endif /*VBOX*/
comments.

Same object code is generated.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 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);
118#ifdef VBOX
119int LibAliasAttachHandlers(PNATState pData, struct proto_handler *);
120int LibAliasDetachHandlers(PNATState pData, struct proto_handler *);
121int detach_handler(PNATState pData, struct proto_handler *);
122struct proto_handler *first_handler(PNATState pData);
123#else
124int LibAliasAttachHandlers(struct proto_handler *);
125int LibAliasDetachHandlers(struct proto_handler *);
126int detach_handler(struct proto_handler *);
127struct proto_handler *first_handler(void);
128#endif
129int find_handler(int8_t, int8_t, struct libalias *,
130 struct ip *, struct alias_data *);
131
132/* Functions used with dll module. */
133
134void dll_chain_init(void);
135void dll_chain_destroy(void);
136int attach_dll(struct dll *);
137void *detach_dll(char *);
138struct dll *walk_dll_chain(void);
139
140/* End of handlers. */
141#define EOH -1
142
143/*
144 * Some defines borrowed from sys/module.h used to compile a kld
145 * in userland as a shared lib.
146 */
147
148#ifndef _KERNEL
149typedef enum modeventtype {
150 MOD_LOAD,
151 MOD_UNLOAD,
152 MOD_SHUTDOWN,
153 MOD_QUIESCE
154} modeventtype_t;
155
156typedef struct module *module_t;
157typedef int (*modeventhand_t)(module_t, int /* modeventtype_t */, void *);
158
159/*
160 * Struct for registering modules statically via SYSINIT.
161 */
162typedef struct moduledata {
163 const char *name; /* module name */
164 modeventhand_t evhand; /* event handler */
165 void *priv; /* extra data */
166} moduledata_t;
167#endif
168
169#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