1 |
199 |
simons |
/*
|
2 |
|
|
* IP masquerading functionality definitions
|
3 |
|
|
*/
|
4 |
|
|
|
5 |
|
|
#ifndef _IP_MASQ_H
|
6 |
|
|
#define _IP_MASQ_H
|
7 |
|
|
|
8 |
|
|
#include <linux/types.h>
|
9 |
|
|
#include <linux/netdevice.h>
|
10 |
|
|
#include <linux/skbuff.h>
|
11 |
|
|
#include <linux/config.h>
|
12 |
|
|
|
13 |
|
|
/*
|
14 |
|
|
* This define affects the number of ports that can be handled
|
15 |
|
|
* by each of the protocol helper modules.
|
16 |
|
|
*/
|
17 |
|
|
#define MAX_MASQ_APP_PORTS 12
|
18 |
|
|
|
19 |
|
|
/*
|
20 |
|
|
* Linux ports don't normally get allocated above 32K.
|
21 |
|
|
* I used an extra 4K port-space
|
22 |
|
|
*/
|
23 |
|
|
|
24 |
|
|
#define PORT_MASQ_BEGIN 61000
|
25 |
|
|
#define PORT_MASQ_END (PORT_MASQ_BEGIN+4096)
|
26 |
|
|
|
27 |
|
|
/*
|
28 |
|
|
* Default timeouts for masquerade functions The control channels now
|
29 |
|
|
* expire the same as TCP channels (other than being updated by
|
30 |
|
|
* packets on their associated data channels.
|
31 |
|
|
*/
|
32 |
|
|
#define MASQUERADE_EXPIRE_TCP 15*60*HZ
|
33 |
|
|
#define MASQUERADE_EXPIRE_TCP_FIN 2*60*HZ
|
34 |
|
|
#define MASQUERADE_EXPIRE_UDP 5*60*HZ
|
35 |
|
|
/*
|
36 |
|
|
* ICMP can no longer be modified on the fly using an ioctl - this
|
37 |
|
|
* define is the only way to change the timeouts
|
38 |
|
|
*/
|
39 |
|
|
#define MASQUERADE_EXPIRE_ICMP 125*HZ
|
40 |
|
|
|
41 |
|
|
#define IP_AUTOFW_EXPIRE 15*HZ
|
42 |
|
|
|
43 |
|
|
#define IP_MASQ_F_OUT_SEQ 0x01 /* must do output seq adjust */
|
44 |
|
|
#define IP_MASQ_F_IN_SEQ 0x02 /* must do input seq adjust */
|
45 |
|
|
#define IP_MASQ_F_NO_DPORT 0x04 /* no dport set yet */
|
46 |
|
|
#define IP_MASQ_F_NO_DADDR 0x08 /* no daddr yet */
|
47 |
|
|
#define IP_MASQ_F_HASHED 0x10 /* hashed entry */
|
48 |
|
|
#define IP_MASQ_F_SAW_RST 0x20 /* tcp rst pkt seen */
|
49 |
|
|
#define IP_MASQ_F_SAW_FIN_IN 0x40 /* tcp fin pkt seen incoming */
|
50 |
|
|
#define IP_MASQ_F_SAW_FIN_OUT 0x80 /* tcp fin pkt seen outgoing */
|
51 |
|
|
#define IP_MASQ_F_SAW_FIN (IP_MASQ_F_SAW_FIN_IN | \
|
52 |
|
|
IP_MASQ_F_SAW_FIN_OUT)
|
53 |
|
|
/* tcp fin pkts seen */
|
54 |
|
|
#define IP_MASQ_F_CONTROL 0x100 /* this is a control channel */
|
55 |
|
|
#define IP_MASQ_F_NO_SPORT 0x200 /* no sport set yet */
|
56 |
|
|
#define IP_MASQ_F_FTP_PASV 0x400 /* ftp PASV command just issued */
|
57 |
|
|
#define IP_MASQ_F_NO_REPLY 0x800 /* no reply yet from outside */
|
58 |
|
|
#define IP_MASQ_F_AFW_PORT 0x1000
|
59 |
|
|
|
60 |
|
|
#ifdef __KERNEL__
|
61 |
|
|
|
62 |
|
|
/*
|
63 |
|
|
* Delta seq. info structure
|
64 |
|
|
* Each MASQ struct has 2 (output AND input seq. changes).
|
65 |
|
|
*/
|
66 |
|
|
|
67 |
|
|
struct ip_masq_seq {
|
68 |
|
|
__u32 init_seq; /* Add delta from this seq */
|
69 |
|
|
short delta; /* Delta in sequence numbers */
|
70 |
|
|
short previous_delta; /* Delta in sequence numbers before last resized pkt */
|
71 |
|
|
};
|
72 |
|
|
|
73 |
|
|
/*
|
74 |
|
|
* MASQ structure allocated for each masqueraded association
|
75 |
|
|
*/
|
76 |
|
|
struct ip_masq {
|
77 |
|
|
struct ip_masq *m_link, *s_link; /* hashed link ptrs */
|
78 |
|
|
struct timer_list timer; /* Expiration timer */
|
79 |
|
|
__u16 protocol; /* Which protocol are we talking? */
|
80 |
|
|
__u16 sport, dport, mport; /* src, dst & masq ports */
|
81 |
|
|
__u32 saddr, daddr, maddr; /* src, dst & masq addresses */
|
82 |
|
|
struct ip_masq_seq out_seq, in_seq;
|
83 |
|
|
struct ip_masq_app *app; /* bound ip_masq_app object */
|
84 |
|
|
void *app_data; /* Application private data */
|
85 |
|
|
unsigned flags; /* status flags */
|
86 |
|
|
struct ip_masq *control; /* Corresponding control connection */
|
87 |
|
|
#ifdef CONFIG_IP_MASQUERADE_IPSEC
|
88 |
|
|
struct ip_masq *d_link; /* hashed link ptr */
|
89 |
|
|
__u32 ospi, ispi; /* outbound and inbound SPI keys for IPSEC */
|
90 |
|
|
/* also the icookie for ISAKMP masquerade */
|
91 |
|
|
short ocnt; /* counter of inits sent - limit blocking */
|
92 |
|
|
short blocking; /* if we're blocking another host */
|
93 |
|
|
#endif /* CONFIG_IP_MASQUERADE_IPSEC */
|
94 |
|
|
};
|
95 |
|
|
|
96 |
|
|
/*
|
97 |
|
|
* timeout values
|
98 |
|
|
*/
|
99 |
|
|
|
100 |
|
|
struct ip_fw_masq {
|
101 |
|
|
int tcp_timeout;
|
102 |
|
|
int tcp_fin_timeout;
|
103 |
|
|
int udp_timeout;
|
104 |
|
|
};
|
105 |
|
|
|
106 |
|
|
extern struct ip_fw_masq *ip_masq_expire;
|
107 |
|
|
|
108 |
|
|
/*
|
109 |
|
|
* [0]: UDP free_ports
|
110 |
|
|
* [1]: TCP free_ports
|
111 |
|
|
* [2]: ICMP free ids
|
112 |
|
|
*/
|
113 |
|
|
|
114 |
|
|
extern int ip_masq_free_ports[3];
|
115 |
|
|
|
116 |
|
|
/*
|
117 |
|
|
* ip_masq initializer (registers symbols and /proc/net entries)
|
118 |
|
|
*/
|
119 |
|
|
extern int ip_masq_init(void);
|
120 |
|
|
|
121 |
|
|
/*
|
122 |
|
|
* functions called from ip layer
|
123 |
|
|
*/
|
124 |
|
|
extern int ip_fw_masquerade(struct sk_buff **, struct device *);
|
125 |
|
|
extern int ip_fw_masq_icmp(struct sk_buff **, struct device *);
|
126 |
|
|
extern int ip_fw_demasquerade(struct sk_buff **, struct device *);
|
127 |
|
|
|
128 |
|
|
/*
|
129 |
|
|
* ip_masq obj creation/deletion functions.
|
130 |
|
|
*/
|
131 |
|
|
extern struct ip_masq *ip_masq_new(struct device *dev, int proto, __u32 saddr, __u16 sport, __u32 daddr, __u16 dport, unsigned flags);
|
132 |
|
|
extern void ip_masq_set_expire(struct ip_masq *ms, unsigned long tout);
|
133 |
|
|
|
134 |
|
|
#ifdef CONFIG_IP_MASQUERADE_IPAUTOFW
|
135 |
|
|
extern void ip_autofw_expire(unsigned long data);
|
136 |
|
|
#endif
|
137 |
|
|
|
138 |
|
|
/*
|
139 |
|
|
*
|
140 |
|
|
* IP_MASQ_APP: IP application masquerading definitions
|
141 |
|
|
*
|
142 |
|
|
*/
|
143 |
|
|
|
144 |
|
|
struct ip_masq_app
|
145 |
|
|
{
|
146 |
|
|
struct ip_masq_app *next;
|
147 |
|
|
char *name; /* name of application proxy */
|
148 |
|
|
unsigned type; /* type = proto<<16 | port (host byte order)*/
|
149 |
|
|
int n_attach;
|
150 |
|
|
int (*masq_init_1) /* ip_masq initializer */
|
151 |
|
|
(struct ip_masq_app *, struct ip_masq *);
|
152 |
|
|
int (*masq_done_1) /* ip_masq fin. */
|
153 |
|
|
(struct ip_masq_app *, struct ip_masq *);
|
154 |
|
|
int (*pkt_out) /* output (masquerading) hook */
|
155 |
|
|
(struct ip_masq_app *, struct ip_masq *, struct sk_buff **, struct device *);
|
156 |
|
|
int (*pkt_in) /* input (demasq) hook */
|
157 |
|
|
(struct ip_masq_app *, struct ip_masq *, struct sk_buff **, struct device *);
|
158 |
|
|
};
|
159 |
|
|
|
160 |
|
|
/*
|
161 |
|
|
* ip_masq_app initializer
|
162 |
|
|
*/
|
163 |
|
|
extern int ip_masq_app_init(void);
|
164 |
|
|
|
165 |
|
|
/*
|
166 |
|
|
* ip_masq_app object registration functions (port: host byte order)
|
167 |
|
|
*/
|
168 |
|
|
extern int register_ip_masq_app(struct ip_masq_app *mapp, unsigned short proto, __u16 port);
|
169 |
|
|
extern int unregister_ip_masq_app(struct ip_masq_app *mapp);
|
170 |
|
|
|
171 |
|
|
/*
|
172 |
|
|
* get ip_masq_app obj by proto,port(net_byte_order)
|
173 |
|
|
*/
|
174 |
|
|
extern struct ip_masq_app * ip_masq_app_get(unsigned short proto, __u16 port);
|
175 |
|
|
|
176 |
|
|
/*
|
177 |
|
|
* ip_masq TO ip_masq_app (un)binding functions.
|
178 |
|
|
*/
|
179 |
|
|
extern struct ip_masq_app * ip_masq_bind_app(struct ip_masq *ms);
|
180 |
|
|
extern int ip_masq_unbind_app(struct ip_masq *ms);
|
181 |
|
|
|
182 |
|
|
/*
|
183 |
|
|
* output and input app. masquerading hooks.
|
184 |
|
|
*
|
185 |
|
|
*/
|
186 |
|
|
extern int ip_masq_app_pkt_out(struct ip_masq *, struct sk_buff **skb_p, struct device *dev);
|
187 |
|
|
extern int ip_masq_app_pkt_in(struct ip_masq *, struct sk_buff **skb_p, struct device *dev);
|
188 |
|
|
|
189 |
|
|
/*
|
190 |
|
|
* service routine(s).
|
191 |
|
|
*/
|
192 |
|
|
extern struct ip_masq * ip_masq_out_get_2(int protocol, __u32 s_addr, __u16 s_port, __u32 d_addr, __u16 d_port);
|
193 |
|
|
extern struct ip_masq * ip_masq_in_get_2(int protocol, __u32 s_addr, __u16 s_port, __u32 d_addr, __u16 d_port);
|
194 |
|
|
|
195 |
|
|
/*
|
196 |
|
|
* /proc/net entry
|
197 |
|
|
*/
|
198 |
|
|
extern int ip_masq_app_getinfo(char *buffer, char **start, off_t offset, int length, int dummy);
|
199 |
|
|
|
200 |
|
|
/*
|
201 |
|
|
* skb_replace function used by "client" modules to replace
|
202 |
|
|
* a segment of skb.
|
203 |
|
|
*/
|
204 |
|
|
extern struct sk_buff * ip_masq_skb_replace(struct sk_buff *skb, int pri, char *o_buf, int o_len, char *n_buf, int n_len);
|
205 |
|
|
|
206 |
|
|
#ifdef CONFIG_IP_MASQUERADE_IPAUTOFW
|
207 |
|
|
extern struct ip_autofw * ip_autofw_hosts;
|
208 |
|
|
#endif /* CONFIG_IP_MASQUERADE_IPAUTOFW */
|
209 |
|
|
|
210 |
|
|
#endif /* __KERNEL__ */
|
211 |
|
|
|
212 |
|
|
#endif /* _IP_MASQ_H */
|