0f500c1cdaf00eefb2ca401385608c53864dbdca
[dragonfly.git] / sys / net / libalias / alias_mod.h
1 /*-
2  * Copyright (c) 2005 Paolo Pisati <piso@FreeBSD.org>
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.6.1 2008/11/25 02:59:29 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
38 /* Protocol handlers struct & function. */
39
40 /* Packet flow direction. */
41 #define IN                              1 
42 #define OUT                             2 
43
44 /* Working protocol. */
45 #define IP                              1
46 #define TCP                             2
47 #define UDP                             4
48
49 /* 
50  * Data passed to protocol handler module, it must be filled
51  * right before calling find_handler() to determine which
52  * module is elegible to be called.
53  */
54
55 struct alias_data {     
56         struct alias_link       *lnk;            
57         struct in_addr          *oaddr;         /* Original address. */
58         struct in_addr          *aaddr;         /* Alias address. */ 
59         uint16_t                *aport;         /* Alias port. */
60         uint16_t                *sport, *dport; /* Source & destination port */
61         uint16_t                maxpktsize;     /* Max packet size. */
62 }; 
63
64 /* 
65  * This structure contains all the information necessary to make
66  * a protocol handler correctly work.
67  */
68
69 struct proto_handler {
70         u_int pri;                                              /* Handler priority. */
71         int16_t dir;                                            /* Flow direction. */
72         uint8_t proto;                                          /* Working protocol. */ 
73         int (*fingerprint)(struct libalias *la,                 /* Fingerprint * function. */
74                  struct ip *pip, struct alias_data *ah);
75         int (*protohandler)(struct libalias *la,                /* Aliasing * function. */
76                  struct ip *pip, struct alias_data *ah);                 
77         LIST_ENTRY(proto_handler) entries;
78 };
79
80
81 /* 
82  * Used only in userland when libalias needs to keep track of all
83  * module loaded. In kernel land (kld mode) we don't need to care
84  * care about libalias modules cause it's kld to do it for us.
85  */
86
87 #define DLL_LEN         32
88 struct dll {    
89         char            name[DLL_LEN];  /* Name of module. */
90         void            *handle;        /* 
91                                          * Ptr to shared obj obtained through
92                                          * dlopen() - use this ptr to get access
93                                          * to any symbols from a loaded module                                   
94                                          * via dlsym(). 
95                                          */
96         SLIST_ENTRY(dll)        next;
97 };
98
99 /* Functions used with protocol handlers. */
100
101 void            handler_chain_init(void);
102 void            handler_chain_destroy(void);
103 int             LibAliasAttachHandlers(struct proto_handler *);
104 int             LibAliasDetachHandlers(struct proto_handler *);
105 int             detach_handler(struct proto_handler *);
106 int             find_handler(int8_t, int8_t, struct libalias *, 
107                            struct ip *, struct alias_data *);
108 struct proto_handler *first_handler(void);
109
110 /* Functions used with dll module. */
111
112 void            dll_chain_init(void);
113 void            dll_chain_destroy(void);
114 int             attach_dll(struct dll *);
115 void            *detach_dll(char *);
116 struct dll      *walk_dll_chain(void);
117
118 /* End of handlers. */
119 #define EOH     -1
120
121 /* 
122  * Some defines borrowed from sys/module.h used to compile a kld
123  * in userland as a shared lib.
124  */
125
126 #ifdef  _KERNEL
127
128 #else
129 typedef enum modeventtype {
130         MOD_LOAD,
131         MOD_UNLOAD,
132         MOD_SHUTDOWN,
133         MOD_QUIESCE
134 } modeventtype_t;
135         
136 typedef struct module *module_t;
137 typedef int (*modeventhand_t)(module_t, int /* modeventtype_t */, void *);
138
139 /*
140  * Struct for registering modules statically via SYSINIT.
141  */
142 typedef struct moduledata {
143         const char      *name;          /* module name */
144         modeventhand_t  evhand;         /* event handler */
145         void            *priv;          /* extra data */
146 } moduledata_t;
147 #endif
148
149 #endif                          /* !_ALIAS_MOD_H_ */