1
2
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
12
13
14
15
16
17 #define PORT_MASQ_BEGIN 60000
18 #define PORT_MASQ_END (PORT_MASQ_BEGIN+4096)
19
20 #define MASQUERADE_EXPIRE_TCP 15*60*HZ
21 #define MASQUERADE_EXPIRE_TCP_FIN 2*60*HZ
22 #define MASQUERADE_EXPIRE_UDP 5*60*HZ
23
24 #define IP_MASQ_F_OUT_SEQ 0x01
25 #define IP_MASQ_F_IN_SEQ 0x02
26 #define IP_MASQ_F_NO_DPORT 0x04
27 #define IP_MASQ_F_NO_DADDR 0x08
28 #define IP_MASQ_F_HASHED 0x10
29 #define IP_MASQ_F_SAW_FIN 0x20
30
31 #ifdef __KERNEL__
32
33
34
35
36
37
38 struct ip_masq_seq {
39 __u32 init_seq;
40 short delta;
41 short previous_delta;
42 };
43
44
45
46
47 struct ip_masq {
48 struct ip_masq *m_link, *s_link;
49 struct timer_list timer;
50 __u16 protocol;
51 __u16 sport, dport, mport;
52 __u32 saddr, daddr, maddr;
53 struct ip_masq_seq out_seq, in_seq;
54 struct ip_masq_app *app;
55 unsigned flags;
56 };
57
58
59
60
61
62 struct ip_fw_masq {
63 int tcp_timeout;
64 int tcp_fin_timeout;
65 int udp_timeout;
66 };
67
68 extern struct ip_fw_masq *ip_masq_expire;
69
70
71
72
73
74
75 extern int ip_masq_free_ports[2];
76
77
78
79
80 extern int ip_masq_init(void);
81
82
83
84
85 extern void ip_fw_masquerade(struct sk_buff **, struct device *);
86 extern int ip_fw_demasquerade(struct sk_buff **, struct device *);
87
88
89
90
91 extern struct ip_masq *ip_masq_new(struct device *dev, int proto, __u32 saddr, __u16 sport, __u32 daddr, __u16 dport, unsigned flags);
92 extern void ip_masq_set_expire(struct ip_masq *ms, unsigned long tout);
93
94
95
96
97
98
99
100
101 struct ip_masq_app
102 {
103 struct ip_masq_app *next;
104 unsigned type;
105 int n_attach;
106 int (*masq_init_1)
107 (struct ip_masq_app *, struct ip_masq *);
108 int (*masq_done_1)
109 (struct ip_masq_app *, struct ip_masq *);
110 int (*pkt_out)
111 (struct ip_masq_app *, struct ip_masq *, struct sk_buff **, struct device *);
112 int (*pkt_in)
113 (struct ip_masq_app *, struct ip_masq *, struct sk_buff **, struct device *);
114 };
115
116
117
118
119 extern int ip_masq_app_init(void);
120
121
122
123
124 extern int register_ip_masq_app(struct ip_masq_app *mapp, unsigned short proto, __u16 port);
125 extern int unregister_ip_masq_app(struct ip_masq_app *mapp);
126
127
128
129
130 extern struct ip_masq_app * ip_masq_app_get(unsigned short proto, __u16 port);
131
132
133
134
135 extern struct ip_masq_app * ip_masq_bind_app(struct ip_masq *ms);
136 extern int ip_masq_unbind_app(struct ip_masq *ms);
137
138
139
140
141
142 extern int ip_masq_app_pkt_out(struct ip_masq *, struct sk_buff **skb_p, struct device *dev);
143 extern int ip_masq_app_pkt_in(struct ip_masq *, struct sk_buff **skb_p, struct device *dev);
144
145
146
147
148 extern int ip_masq_app_getinfo(char *buffer, char **start, off_t offset, int length, int dummy);
149
150
151
152
153
154 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);
155
156 #endif
157
158 #endif