Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * IP Virtual Server | |
3 | * data structure and functionality definitions | |
4 | */ | |
5 | ||
bc4768eb JV |
6 | #ifndef _NET_IP_VS_H |
7 | #define _NET_IP_VS_H | |
1da177e4 | 8 | |
bc4768eb | 9 | #include <linux/ip_vs.h> /* definitions shared with userland */ |
1da177e4 | 10 | |
bc4768eb | 11 | /* old ipvsadm versions still include this file directly */ |
1da177e4 LT |
12 | #ifdef __KERNEL__ |
13 | ||
bc4768eb JV |
14 | #include <asm/types.h> /* for __uXX types */ |
15 | ||
16 | #include <linux/sysctl.h> /* for ctl_path */ | |
1da177e4 LT |
17 | #include <linux/list.h> /* for struct list_head */ |
18 | #include <linux/spinlock.h> /* for struct rwlock_t */ | |
1da177e4 | 19 | #include <asm/atomic.h> /* for struct atomic_t */ |
1da177e4 | 20 | #include <linux/compiler.h> |
14c85021 | 21 | #include <linux/timer.h> |
1da177e4 | 22 | |
14c85021 | 23 | #include <net/checksum.h> |
e7ade46a JV |
24 | #include <linux/netfilter.h> /* for union nf_inet_addr */ |
25 | #include <linux/ipv6.h> /* for struct ipv6hdr */ | |
26 | #include <net/ipv6.h> /* for ipv6_addr_copy */ | |
1da177e4 | 27 | |
64aae3cb JV |
28 | struct ip_vs_iphdr { |
29 | int len; | |
30 | __u8 protocol; | |
31 | union nf_inet_addr saddr; | |
32 | union nf_inet_addr daddr; | |
33 | }; | |
34 | ||
35 | static inline void | |
36 | ip_vs_fill_iphdr(int af, const void *nh, struct ip_vs_iphdr *iphdr) | |
37 | { | |
38 | #ifdef CONFIG_IP_VS_IPV6 | |
39 | if (af == AF_INET6) { | |
40 | const struct ipv6hdr *iph = nh; | |
41 | iphdr->len = sizeof(struct ipv6hdr); | |
42 | iphdr->protocol = iph->nexthdr; | |
43 | ipv6_addr_copy(&iphdr->saddr.in6, &iph->saddr); | |
44 | ipv6_addr_copy(&iphdr->daddr.in6, &iph->daddr); | |
45 | } else | |
46 | #endif | |
47 | { | |
48 | const struct iphdr *iph = nh; | |
49 | iphdr->len = iph->ihl * 4; | |
50 | iphdr->protocol = iph->protocol; | |
51 | iphdr->saddr.ip = iph->saddr; | |
52 | iphdr->daddr.ip = iph->daddr; | |
53 | } | |
54 | } | |
55 | ||
56 | static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst, | |
57 | const union nf_inet_addr *src) | |
58 | { | |
59 | #ifdef CONFIG_IP_VS_IPV6 | |
60 | if (af == AF_INET6) | |
61 | ipv6_addr_copy(&dst->in6, &src->in6); | |
62 | else | |
63 | #endif | |
64 | dst->ip = src->ip; | |
65 | } | |
66 | ||
67 | static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a, | |
68 | const union nf_inet_addr *b) | |
69 | { | |
70 | #ifdef CONFIG_IP_VS_IPV6 | |
71 | if (af == AF_INET6) | |
72 | return ipv6_addr_equal(&a->in6, &b->in6); | |
73 | #endif | |
74 | return a->ip == b->ip; | |
75 | } | |
76 | ||
1da177e4 | 77 | #ifdef CONFIG_IP_VS_DEBUG |
14c85021 ACM |
78 | #include <linux/net.h> |
79 | ||
1da177e4 LT |
80 | extern int ip_vs_get_debug_level(void); |
81 | #define IP_VS_DBG(level, msg...) \ | |
82 | do { \ | |
83 | if (level <= ip_vs_get_debug_level()) \ | |
84 | printk(KERN_DEBUG "IPVS: " msg); \ | |
85 | } while (0) | |
86 | #define IP_VS_DBG_RL(msg...) \ | |
87 | do { \ | |
88 | if (net_ratelimit()) \ | |
89 | printk(KERN_DEBUG "IPVS: " msg); \ | |
90 | } while (0) | |
91 | #define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) \ | |
92 | do { \ | |
93 | if (level <= ip_vs_get_debug_level()) \ | |
94 | pp->debug_packet(pp, skb, ofs, msg); \ | |
95 | } while (0) | |
96 | #define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) \ | |
97 | do { \ | |
98 | if (level <= ip_vs_get_debug_level() && \ | |
99 | net_ratelimit()) \ | |
100 | pp->debug_packet(pp, skb, ofs, msg); \ | |
101 | } while (0) | |
102 | #else /* NO DEBUGGING at ALL */ | |
103 | #define IP_VS_DBG(level, msg...) do {} while (0) | |
104 | #define IP_VS_DBG_RL(msg...) do {} while (0) | |
105 | #define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) do {} while (0) | |
106 | #define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) do {} while (0) | |
107 | #endif | |
108 | ||
109 | #define IP_VS_BUG() BUG() | |
110 | #define IP_VS_ERR(msg...) printk(KERN_ERR "IPVS: " msg) | |
111 | #define IP_VS_INFO(msg...) printk(KERN_INFO "IPVS: " msg) | |
112 | #define IP_VS_WARNING(msg...) \ | |
113 | printk(KERN_WARNING "IPVS: " msg) | |
114 | #define IP_VS_ERR_RL(msg...) \ | |
115 | do { \ | |
116 | if (net_ratelimit()) \ | |
117 | printk(KERN_ERR "IPVS: " msg); \ | |
118 | } while (0) | |
119 | ||
120 | #ifdef CONFIG_IP_VS_DEBUG | |
121 | #define EnterFunction(level) \ | |
122 | do { \ | |
123 | if (level <= ip_vs_get_debug_level()) \ | |
124 | printk(KERN_DEBUG "Enter: %s, %s line %i\n", \ | |
125 | __FUNCTION__, __FILE__, __LINE__); \ | |
126 | } while (0) | |
127 | #define LeaveFunction(level) \ | |
128 | do { \ | |
129 | if (level <= ip_vs_get_debug_level()) \ | |
130 | printk(KERN_DEBUG "Leave: %s, %s line %i\n", \ | |
131 | __FUNCTION__, __FILE__, __LINE__); \ | |
132 | } while (0) | |
133 | #else | |
134 | #define EnterFunction(level) do {} while (0) | |
135 | #define LeaveFunction(level) do {} while (0) | |
136 | #endif | |
137 | ||
138 | #define IP_VS_WAIT_WHILE(expr) while (expr) { cpu_relax(); } | |
139 | ||
140 | ||
141 | /* | |
142 | * The port number of FTP service (in network order). | |
143 | */ | |
144 | #define FTPPORT __constant_htons(21) | |
145 | #define FTPDATA __constant_htons(20) | |
146 | ||
1da177e4 LT |
147 | /* |
148 | * TCP State Values | |
149 | */ | |
150 | enum { | |
151 | IP_VS_TCP_S_NONE = 0, | |
152 | IP_VS_TCP_S_ESTABLISHED, | |
153 | IP_VS_TCP_S_SYN_SENT, | |
154 | IP_VS_TCP_S_SYN_RECV, | |
155 | IP_VS_TCP_S_FIN_WAIT, | |
156 | IP_VS_TCP_S_TIME_WAIT, | |
157 | IP_VS_TCP_S_CLOSE, | |
158 | IP_VS_TCP_S_CLOSE_WAIT, | |
159 | IP_VS_TCP_S_LAST_ACK, | |
160 | IP_VS_TCP_S_LISTEN, | |
161 | IP_VS_TCP_S_SYNACK, | |
162 | IP_VS_TCP_S_LAST | |
163 | }; | |
164 | ||
165 | /* | |
166 | * UDP State Values | |
167 | */ | |
168 | enum { | |
169 | IP_VS_UDP_S_NORMAL, | |
170 | IP_VS_UDP_S_LAST, | |
171 | }; | |
172 | ||
173 | /* | |
174 | * ICMP State Values | |
175 | */ | |
176 | enum { | |
177 | IP_VS_ICMP_S_NORMAL, | |
178 | IP_VS_ICMP_S_LAST, | |
179 | }; | |
180 | ||
181 | /* | |
182 | * Delta sequence info structure | |
183 | * Each ip_vs_conn has 2 (output AND input seq. changes). | |
184 | * Only used in the VS/NAT. | |
185 | */ | |
186 | struct ip_vs_seq { | |
187 | __u32 init_seq; /* Add delta from this seq */ | |
188 | __u32 delta; /* Delta in sequence numbers */ | |
189 | __u32 previous_delta; /* Delta in sequence numbers | |
190 | before last resized pkt */ | |
191 | }; | |
192 | ||
193 | ||
194 | /* | |
3a14a313 | 195 | * IPVS statistics objects |
1da177e4 | 196 | */ |
3a14a313 SW |
197 | struct ip_vs_estimator { |
198 | struct list_head list; | |
199 | ||
200 | u64 last_inbytes; | |
201 | u64 last_outbytes; | |
202 | u32 last_conns; | |
203 | u32 last_inpkts; | |
204 | u32 last_outpkts; | |
205 | ||
206 | u32 cps; | |
207 | u32 inpps; | |
208 | u32 outpps; | |
209 | u32 inbps; | |
210 | u32 outbps; | |
211 | }; | |
212 | ||
1da177e4 LT |
213 | struct ip_vs_stats |
214 | { | |
215 | __u32 conns; /* connections scheduled */ | |
216 | __u32 inpkts; /* incoming packets */ | |
217 | __u32 outpkts; /* outgoing packets */ | |
218 | __u64 inbytes; /* incoming bytes */ | |
219 | __u64 outbytes; /* outgoing bytes */ | |
220 | ||
221 | __u32 cps; /* current connection rate */ | |
222 | __u32 inpps; /* current in packet rate */ | |
223 | __u32 outpps; /* current out packet rate */ | |
224 | __u32 inbps; /* current in byte rate */ | |
225 | __u32 outbps; /* current out byte rate */ | |
226 | ||
3a14a313 SW |
227 | /* |
228 | * Don't add anything before the lock, because we use memcpy() to copy | |
229 | * the members before the lock to struct ip_vs_stats_user in | |
230 | * ip_vs_ctl.c. | |
231 | */ | |
232 | ||
1da177e4 | 233 | spinlock_t lock; /* spin lock */ |
3a14a313 SW |
234 | |
235 | struct ip_vs_estimator est; /* estimator */ | |
1da177e4 LT |
236 | }; |
237 | ||
14c85021 ACM |
238 | struct dst_entry; |
239 | struct iphdr; | |
1da177e4 LT |
240 | struct ip_vs_conn; |
241 | struct ip_vs_app; | |
14c85021 | 242 | struct sk_buff; |
1da177e4 LT |
243 | |
244 | struct ip_vs_protocol { | |
245 | struct ip_vs_protocol *next; | |
246 | char *name; | |
2ad17def JA |
247 | u16 protocol; |
248 | u16 num_states; | |
1da177e4 LT |
249 | int dont_defrag; |
250 | atomic_t appcnt; /* counter of proto app incs */ | |
251 | int *timeout_table; /* protocol timeout table */ | |
252 | ||
253 | void (*init)(struct ip_vs_protocol *pp); | |
254 | ||
255 | void (*exit)(struct ip_vs_protocol *pp); | |
256 | ||
257 | int (*conn_schedule)(struct sk_buff *skb, | |
258 | struct ip_vs_protocol *pp, | |
259 | int *verdict, struct ip_vs_conn **cpp); | |
260 | ||
261 | struct ip_vs_conn * | |
262 | (*conn_in_get)(const struct sk_buff *skb, | |
263 | struct ip_vs_protocol *pp, | |
264 | const struct iphdr *iph, | |
265 | unsigned int proto_off, | |
266 | int inverse); | |
267 | ||
268 | struct ip_vs_conn * | |
269 | (*conn_out_get)(const struct sk_buff *skb, | |
270 | struct ip_vs_protocol *pp, | |
271 | const struct iphdr *iph, | |
272 | unsigned int proto_off, | |
273 | int inverse); | |
274 | ||
3db05fea | 275 | int (*snat_handler)(struct sk_buff *skb, |
1da177e4 LT |
276 | struct ip_vs_protocol *pp, struct ip_vs_conn *cp); |
277 | ||
3db05fea | 278 | int (*dnat_handler)(struct sk_buff *skb, |
1da177e4 LT |
279 | struct ip_vs_protocol *pp, struct ip_vs_conn *cp); |
280 | ||
281 | int (*csum_check)(struct sk_buff *skb, struct ip_vs_protocol *pp); | |
282 | ||
283 | const char *(*state_name)(int state); | |
284 | ||
285 | int (*state_transition)(struct ip_vs_conn *cp, int direction, | |
286 | const struct sk_buff *skb, | |
287 | struct ip_vs_protocol *pp); | |
288 | ||
289 | int (*register_app)(struct ip_vs_app *inc); | |
290 | ||
291 | void (*unregister_app)(struct ip_vs_app *inc); | |
292 | ||
293 | int (*app_conn_bind)(struct ip_vs_conn *cp); | |
294 | ||
295 | void (*debug_packet)(struct ip_vs_protocol *pp, | |
296 | const struct sk_buff *skb, | |
297 | int offset, | |
298 | const char *msg); | |
299 | ||
300 | void (*timeout_change)(struct ip_vs_protocol *pp, int flags); | |
301 | ||
302 | int (*set_state_timeout)(struct ip_vs_protocol *pp, char *sname, int to); | |
303 | }; | |
304 | ||
305 | extern struct ip_vs_protocol * ip_vs_proto_get(unsigned short proto); | |
306 | ||
307 | /* | |
308 | * IP_VS structure allocated for each dynamically scheduled connection | |
309 | */ | |
310 | struct ip_vs_conn { | |
311 | struct list_head c_list; /* hashed list heads */ | |
312 | ||
313 | /* Protocol, addresses and port numbers */ | |
e7ade46a JV |
314 | u16 af; /* address family */ |
315 | union nf_inet_addr caddr; /* client address */ | |
316 | union nf_inet_addr vaddr; /* virtual address */ | |
317 | union nf_inet_addr daddr; /* destination address */ | |
014d730d AV |
318 | __be16 cport; |
319 | __be16 vport; | |
320 | __be16 dport; | |
1da177e4 LT |
321 | __u16 protocol; /* Which protocol (TCP/UDP) */ |
322 | ||
323 | /* counter and timer */ | |
324 | atomic_t refcnt; /* reference count */ | |
325 | struct timer_list timer; /* Expiration timer */ | |
326 | volatile unsigned long timeout; /* timeout */ | |
327 | ||
328 | /* Flags and state transition */ | |
329 | spinlock_t lock; /* lock for state transition */ | |
330 | volatile __u16 flags; /* status flags */ | |
331 | volatile __u16 state; /* state info */ | |
efac5276 RB |
332 | volatile __u16 old_state; /* old state, to be used for |
333 | * state transition triggerd | |
334 | * synchronization | |
335 | */ | |
1da177e4 LT |
336 | |
337 | /* Control members */ | |
338 | struct ip_vs_conn *control; /* Master control connection */ | |
339 | atomic_t n_control; /* Number of controlled ones */ | |
340 | struct ip_vs_dest *dest; /* real server */ | |
341 | atomic_t in_pkts; /* incoming packet counter */ | |
342 | ||
343 | /* packet transmitter for different forwarding methods. If it | |
344 | mangles the packet, it must return NF_DROP or better NF_STOLEN, | |
345 | otherwise this must be changed to a sk_buff **. | |
346 | */ | |
347 | int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp, | |
348 | struct ip_vs_protocol *pp); | |
349 | ||
350 | /* Note: we can group the following members into a structure, | |
351 | in order to save more space, and the following members are | |
352 | only used in VS/NAT anyway */ | |
353 | struct ip_vs_app *app; /* bound ip_vs_app object */ | |
354 | void *app_data; /* Application private data */ | |
355 | struct ip_vs_seq in_seq; /* incoming seq. struct */ | |
356 | struct ip_vs_seq out_seq; /* outgoing seq. struct */ | |
357 | }; | |
358 | ||
359 | ||
360 | /* | |
361 | * The information about the virtual service offered to the net | |
362 | * and the forwarding entries | |
363 | */ | |
364 | struct ip_vs_service { | |
365 | struct list_head s_list; /* for normal service table */ | |
366 | struct list_head f_list; /* for fwmark-based service table */ | |
367 | atomic_t refcnt; /* reference counter */ | |
368 | atomic_t usecnt; /* use counter */ | |
369 | ||
e7ade46a | 370 | u16 af; /* address family */ |
1da177e4 | 371 | __u16 protocol; /* which protocol (TCP/UDP) */ |
e7ade46a | 372 | union nf_inet_addr addr; /* IP address for virtual service */ |
014d730d | 373 | __be16 port; /* port number for the service */ |
1da177e4 LT |
374 | __u32 fwmark; /* firewall mark of the service */ |
375 | unsigned flags; /* service status flags */ | |
376 | unsigned timeout; /* persistent timeout in ticks */ | |
014d730d | 377 | __be32 netmask; /* grouping granularity */ |
1da177e4 LT |
378 | |
379 | struct list_head destinations; /* real server d-linked list */ | |
380 | __u32 num_dests; /* number of servers */ | |
381 | struct ip_vs_stats stats; /* statistics for the service */ | |
382 | struct ip_vs_app *inc; /* bind conns to this app inc */ | |
383 | ||
384 | /* for scheduling */ | |
385 | struct ip_vs_scheduler *scheduler; /* bound scheduler object */ | |
386 | rwlock_t sched_lock; /* lock sched_data */ | |
387 | void *sched_data; /* scheduler application data */ | |
388 | }; | |
389 | ||
390 | ||
391 | /* | |
392 | * The real server destination forwarding entry | |
393 | * with ip address, port number, and so on. | |
394 | */ | |
395 | struct ip_vs_dest { | |
396 | struct list_head n_list; /* for the dests in the service */ | |
397 | struct list_head d_list; /* for table with all the dests */ | |
398 | ||
e7ade46a JV |
399 | u16 af; /* address family */ |
400 | union nf_inet_addr addr; /* IP address of the server */ | |
014d730d | 401 | __be16 port; /* port number of the server */ |
1da177e4 LT |
402 | volatile unsigned flags; /* dest status flags */ |
403 | atomic_t conn_flags; /* flags to copy to conn */ | |
404 | atomic_t weight; /* server weight */ | |
405 | ||
406 | atomic_t refcnt; /* reference counter */ | |
407 | struct ip_vs_stats stats; /* statistics */ | |
408 | ||
409 | /* connection counters and thresholds */ | |
410 | atomic_t activeconns; /* active connections */ | |
411 | atomic_t inactconns; /* inactive connections */ | |
412 | atomic_t persistconns; /* persistent connections */ | |
413 | __u32 u_threshold; /* upper threshold */ | |
414 | __u32 l_threshold; /* lower threshold */ | |
415 | ||
416 | /* for destination cache */ | |
417 | spinlock_t dst_lock; /* lock of dst_cache */ | |
418 | struct dst_entry *dst_cache; /* destination cache entry */ | |
419 | u32 dst_rtos; /* RT_TOS(tos) for dst */ | |
420 | ||
421 | /* for virtual service */ | |
422 | struct ip_vs_service *svc; /* service it belongs to */ | |
423 | __u16 protocol; /* which protocol (TCP/UDP) */ | |
e7ade46a | 424 | union nf_inet_addr vaddr; /* virtual IP address */ |
014d730d | 425 | __be16 vport; /* virtual port number */ |
1da177e4 LT |
426 | __u32 vfwmark; /* firewall mark of service */ |
427 | }; | |
428 | ||
429 | ||
430 | /* | |
431 | * The scheduler object | |
432 | */ | |
433 | struct ip_vs_scheduler { | |
434 | struct list_head n_list; /* d-linked list head */ | |
435 | char *name; /* scheduler name */ | |
436 | atomic_t refcnt; /* reference counter */ | |
437 | struct module *module; /* THIS_MODULE/NULL */ | |
438 | ||
439 | /* scheduler initializing service */ | |
440 | int (*init_service)(struct ip_vs_service *svc); | |
441 | /* scheduling service finish */ | |
442 | int (*done_service)(struct ip_vs_service *svc); | |
443 | /* scheduler updating service */ | |
444 | int (*update_service)(struct ip_vs_service *svc); | |
445 | ||
446 | /* selecting a server from the given service */ | |
447 | struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc, | |
448 | const struct sk_buff *skb); | |
449 | }; | |
450 | ||
451 | ||
452 | /* | |
453 | * The application module object (a.k.a. app incarnation) | |
454 | */ | |
455 | struct ip_vs_app | |
456 | { | |
457 | struct list_head a_list; /* member in app list */ | |
458 | int type; /* IP_VS_APP_TYPE_xxx */ | |
459 | char *name; /* application module name */ | |
460 | __u16 protocol; | |
461 | struct module *module; /* THIS_MODULE/NULL */ | |
462 | struct list_head incs_list; /* list of incarnations */ | |
463 | ||
464 | /* members for application incarnations */ | |
465 | struct list_head p_list; /* member in proto app list */ | |
466 | struct ip_vs_app *app; /* its real application */ | |
014d730d | 467 | __be16 port; /* port number in net order */ |
1da177e4 LT |
468 | atomic_t usecnt; /* usage counter */ |
469 | ||
470 | /* output hook: return false if can't linearize. diff set for TCP. */ | |
471 | int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *, | |
3db05fea | 472 | struct sk_buff *, int *diff); |
1da177e4 LT |
473 | |
474 | /* input hook: return false if can't linearize. diff set for TCP. */ | |
475 | int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *, | |
3db05fea | 476 | struct sk_buff *, int *diff); |
1da177e4 LT |
477 | |
478 | /* ip_vs_app initializer */ | |
479 | int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *); | |
480 | ||
481 | /* ip_vs_app finish */ | |
482 | int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *); | |
483 | ||
484 | ||
485 | /* not used now */ | |
486 | int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *, | |
487 | struct ip_vs_protocol *); | |
488 | ||
489 | void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *); | |
490 | ||
491 | int * timeout_table; | |
492 | int * timeouts; | |
493 | int timeouts_size; | |
494 | ||
495 | int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app, | |
496 | int *verdict, struct ip_vs_conn **cpp); | |
497 | ||
498 | struct ip_vs_conn * | |
499 | (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app, | |
500 | const struct iphdr *iph, unsigned int proto_off, | |
501 | int inverse); | |
502 | ||
503 | struct ip_vs_conn * | |
504 | (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app, | |
505 | const struct iphdr *iph, unsigned int proto_off, | |
506 | int inverse); | |
507 | ||
508 | int (*state_transition)(struct ip_vs_conn *cp, int direction, | |
509 | const struct sk_buff *skb, | |
510 | struct ip_vs_app *app); | |
511 | ||
512 | void (*timeout_change)(struct ip_vs_app *app, int flags); | |
513 | }; | |
514 | ||
515 | ||
516 | /* | |
517 | * IPVS core functions | |
518 | * (from ip_vs_core.c) | |
519 | */ | |
520 | extern const char *ip_vs_proto_name(unsigned proto); | |
521 | extern void ip_vs_init_hash_table(struct list_head *table, int rows); | |
afdd6140 | 522 | #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t))) |
1da177e4 | 523 | |
1da177e4 LT |
524 | #define IP_VS_APP_TYPE_FTP 1 |
525 | ||
526 | /* | |
527 | * ip_vs_conn handling functions | |
528 | * (from ip_vs_conn.c) | |
529 | */ | |
530 | ||
531 | /* | |
532 | * IPVS connection entry hash table | |
533 | */ | |
534 | #ifndef CONFIG_IP_VS_TAB_BITS | |
535 | #define CONFIG_IP_VS_TAB_BITS 12 | |
536 | #endif | |
537 | /* make sure that IP_VS_CONN_TAB_BITS is located in [8, 20] */ | |
538 | #if CONFIG_IP_VS_TAB_BITS < 8 | |
539 | #define IP_VS_CONN_TAB_BITS 8 | |
540 | #endif | |
541 | #if CONFIG_IP_VS_TAB_BITS > 20 | |
542 | #define IP_VS_CONN_TAB_BITS 20 | |
543 | #endif | |
544 | #if 8 <= CONFIG_IP_VS_TAB_BITS && CONFIG_IP_VS_TAB_BITS <= 20 | |
545 | #define IP_VS_CONN_TAB_BITS CONFIG_IP_VS_TAB_BITS | |
546 | #endif | |
547 | #define IP_VS_CONN_TAB_SIZE (1 << IP_VS_CONN_TAB_BITS) | |
548 | #define IP_VS_CONN_TAB_MASK (IP_VS_CONN_TAB_SIZE - 1) | |
549 | ||
550 | enum { | |
551 | IP_VS_DIR_INPUT = 0, | |
552 | IP_VS_DIR_OUTPUT, | |
553 | IP_VS_DIR_INPUT_ONLY, | |
554 | IP_VS_DIR_LAST, | |
555 | }; | |
556 | ||
557 | extern struct ip_vs_conn *ip_vs_conn_in_get | |
014d730d | 558 | (int protocol, __be32 s_addr, __be16 s_port, __be32 d_addr, __be16 d_port); |
87375ab4 | 559 | extern struct ip_vs_conn *ip_vs_ct_in_get |
014d730d | 560 | (int protocol, __be32 s_addr, __be16 s_port, __be32 d_addr, __be16 d_port); |
1da177e4 | 561 | extern struct ip_vs_conn *ip_vs_conn_out_get |
014d730d | 562 | (int protocol, __be32 s_addr, __be16 s_port, __be32 d_addr, __be16 d_port); |
1da177e4 LT |
563 | |
564 | /* put back the conn without restarting its timer */ | |
565 | static inline void __ip_vs_conn_put(struct ip_vs_conn *cp) | |
566 | { | |
567 | atomic_dec(&cp->refcnt); | |
568 | } | |
569 | extern void ip_vs_conn_put(struct ip_vs_conn *cp); | |
014d730d | 570 | extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport); |
1da177e4 LT |
571 | |
572 | extern struct ip_vs_conn * | |
014d730d AV |
573 | ip_vs_conn_new(int proto, __be32 caddr, __be16 cport, __be32 vaddr, __be16 vport, |
574 | __be32 daddr, __be16 dport, unsigned flags, | |
1da177e4 LT |
575 | struct ip_vs_dest *dest); |
576 | extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp); | |
577 | ||
578 | extern const char * ip_vs_state_name(__u16 proto, int state); | |
579 | ||
580 | extern void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp); | |
581 | extern int ip_vs_check_template(struct ip_vs_conn *ct); | |
1da177e4 LT |
582 | extern void ip_vs_random_dropentry(void); |
583 | extern int ip_vs_conn_init(void); | |
584 | extern void ip_vs_conn_cleanup(void); | |
585 | ||
586 | static inline void ip_vs_control_del(struct ip_vs_conn *cp) | |
587 | { | |
588 | struct ip_vs_conn *ctl_cp = cp->control; | |
589 | if (!ctl_cp) { | |
590 | IP_VS_ERR("request control DEL for uncontrolled: " | |
591 | "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n", | |
592 | NIPQUAD(cp->caddr),ntohs(cp->cport), | |
593 | NIPQUAD(cp->vaddr),ntohs(cp->vport)); | |
594 | return; | |
595 | } | |
596 | ||
597 | IP_VS_DBG(7, "DELeting control for: " | |
598 | "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n", | |
599 | NIPQUAD(cp->caddr),ntohs(cp->cport), | |
600 | NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport)); | |
601 | ||
602 | cp->control = NULL; | |
603 | if (atomic_read(&ctl_cp->n_control) == 0) { | |
604 | IP_VS_ERR("BUG control DEL with n=0 : " | |
605 | "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n", | |
606 | NIPQUAD(cp->caddr),ntohs(cp->cport), | |
607 | NIPQUAD(cp->vaddr),ntohs(cp->vport)); | |
608 | return; | |
609 | } | |
610 | atomic_dec(&ctl_cp->n_control); | |
611 | } | |
612 | ||
613 | static inline void | |
614 | ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp) | |
615 | { | |
616 | if (cp->control) { | |
617 | IP_VS_ERR("request control ADD for already controlled: " | |
618 | "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n", | |
619 | NIPQUAD(cp->caddr),ntohs(cp->cport), | |
620 | NIPQUAD(cp->vaddr),ntohs(cp->vport)); | |
621 | ip_vs_control_del(cp); | |
622 | } | |
623 | ||
624 | IP_VS_DBG(7, "ADDing control for: " | |
625 | "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n", | |
626 | NIPQUAD(cp->caddr),ntohs(cp->cport), | |
627 | NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport)); | |
628 | ||
629 | cp->control = ctl_cp; | |
630 | atomic_inc(&ctl_cp->n_control); | |
631 | } | |
632 | ||
633 | ||
634 | /* | |
635 | * IPVS application functions | |
636 | * (from ip_vs_app.c) | |
637 | */ | |
638 | #define IP_VS_APP_MAX_PORTS 8 | |
639 | extern int register_ip_vs_app(struct ip_vs_app *app); | |
640 | extern void unregister_ip_vs_app(struct ip_vs_app *app); | |
641 | extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp); | |
642 | extern void ip_vs_unbind_app(struct ip_vs_conn *cp); | |
643 | extern int | |
644 | register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port); | |
645 | extern int ip_vs_app_inc_get(struct ip_vs_app *inc); | |
646 | extern void ip_vs_app_inc_put(struct ip_vs_app *inc); | |
647 | ||
3db05fea HX |
648 | extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb); |
649 | extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb); | |
dd0fc66f | 650 | extern int ip_vs_skb_replace(struct sk_buff *skb, gfp_t pri, |
1da177e4 LT |
651 | char *o_buf, int o_len, char *n_buf, int n_len); |
652 | extern int ip_vs_app_init(void); | |
653 | extern void ip_vs_app_cleanup(void); | |
654 | ||
655 | ||
656 | /* | |
657 | * IPVS protocol functions (from ip_vs_proto.c) | |
658 | */ | |
659 | extern int ip_vs_protocol_init(void); | |
660 | extern void ip_vs_protocol_cleanup(void); | |
661 | extern void ip_vs_protocol_timeout_change(int flags); | |
662 | extern int *ip_vs_create_timeout_table(int *table, int size); | |
663 | extern int | |
664 | ip_vs_set_state_timeout(int *table, int num, char **names, char *name, int to); | |
665 | extern void | |
666 | ip_vs_tcpudp_debug_packet(struct ip_vs_protocol *pp, const struct sk_buff *skb, | |
667 | int offset, const char *msg); | |
668 | ||
669 | extern struct ip_vs_protocol ip_vs_protocol_tcp; | |
670 | extern struct ip_vs_protocol ip_vs_protocol_udp; | |
671 | extern struct ip_vs_protocol ip_vs_protocol_icmp; | |
672 | extern struct ip_vs_protocol ip_vs_protocol_esp; | |
673 | extern struct ip_vs_protocol ip_vs_protocol_ah; | |
674 | ||
675 | ||
676 | /* | |
677 | * Registering/unregistering scheduler functions | |
678 | * (from ip_vs_sched.c) | |
679 | */ | |
680 | extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler); | |
681 | extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler); | |
682 | extern int ip_vs_bind_scheduler(struct ip_vs_service *svc, | |
683 | struct ip_vs_scheduler *scheduler); | |
684 | extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc); | |
685 | extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name); | |
686 | extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler); | |
687 | extern struct ip_vs_conn * | |
688 | ip_vs_schedule(struct ip_vs_service *svc, const struct sk_buff *skb); | |
689 | extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb, | |
690 | struct ip_vs_protocol *pp); | |
691 | ||
692 | ||
693 | /* | |
694 | * IPVS control data and functions (from ip_vs_ctl.c) | |
695 | */ | |
696 | extern int sysctl_ip_vs_cache_bypass; | |
697 | extern int sysctl_ip_vs_expire_nodest_conn; | |
698 | extern int sysctl_ip_vs_expire_quiescent_template; | |
699 | extern int sysctl_ip_vs_sync_threshold[2]; | |
700 | extern int sysctl_ip_vs_nat_icmp_send; | |
701 | extern struct ip_vs_stats ip_vs_stats; | |
5587da55 | 702 | extern const struct ctl_path net_vs_ctl_path[]; |
1da177e4 LT |
703 | |
704 | extern struct ip_vs_service * | |
014d730d | 705 | ip_vs_service_get(__u32 fwmark, __u16 protocol, __be32 vaddr, __be16 vport); |
1da177e4 LT |
706 | |
707 | static inline void ip_vs_service_put(struct ip_vs_service *svc) | |
708 | { | |
709 | atomic_dec(&svc->usecnt); | |
710 | } | |
711 | ||
712 | extern struct ip_vs_dest * | |
014d730d | 713 | ip_vs_lookup_real_service(__u16 protocol, __be32 daddr, __be16 dport); |
1da177e4 LT |
714 | extern int ip_vs_use_count_inc(void); |
715 | extern void ip_vs_use_count_dec(void); | |
716 | extern int ip_vs_control_init(void); | |
717 | extern void ip_vs_control_cleanup(void); | |
1e356f9c RB |
718 | extern struct ip_vs_dest * |
719 | ip_vs_find_dest(__be32 daddr, __be16 dport, | |
720 | __be32 vaddr, __be16 vport, __u16 protocol); | |
721 | extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp); | |
1da177e4 LT |
722 | |
723 | ||
724 | /* | |
725 | * IPVS sync daemon data and function prototypes | |
726 | * (from ip_vs_sync.c) | |
727 | */ | |
728 | extern volatile int ip_vs_sync_state; | |
729 | extern volatile int ip_vs_master_syncid; | |
730 | extern volatile int ip_vs_backup_syncid; | |
731 | extern char ip_vs_master_mcast_ifn[IP_VS_IFNAME_MAXLEN]; | |
732 | extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN]; | |
733 | extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid); | |
734 | extern int stop_sync_thread(int state); | |
735 | extern void ip_vs_sync_conn(struct ip_vs_conn *cp); | |
736 | ||
737 | ||
738 | /* | |
739 | * IPVS rate estimator prototypes (from ip_vs_est.c) | |
740 | */ | |
a919cf4b SW |
741 | extern int ip_vs_estimator_init(void); |
742 | extern void ip_vs_estimator_cleanup(void); | |
3a14a313 | 743 | extern void ip_vs_new_estimator(struct ip_vs_stats *stats); |
1da177e4 LT |
744 | extern void ip_vs_kill_estimator(struct ip_vs_stats *stats); |
745 | extern void ip_vs_zero_estimator(struct ip_vs_stats *stats); | |
746 | ||
747 | /* | |
748 | * Various IPVS packet transmitters (from ip_vs_xmit.c) | |
749 | */ | |
750 | extern int ip_vs_null_xmit | |
751 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); | |
752 | extern int ip_vs_bypass_xmit | |
753 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); | |
754 | extern int ip_vs_nat_xmit | |
755 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); | |
756 | extern int ip_vs_tunnel_xmit | |
757 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); | |
758 | extern int ip_vs_dr_xmit | |
759 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); | |
760 | extern int ip_vs_icmp_xmit | |
761 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, int offset); | |
762 | extern void ip_vs_dst_reset(struct ip_vs_dest *dest); | |
763 | ||
764 | ||
765 | /* | |
766 | * This is a simple mechanism to ignore packets when | |
767 | * we are loaded. Just set ip_vs_drop_rate to 'n' and | |
768 | * we start to drop 1/rate of the packets | |
769 | */ | |
770 | extern int ip_vs_drop_rate; | |
771 | extern int ip_vs_drop_counter; | |
772 | ||
773 | static __inline__ int ip_vs_todrop(void) | |
774 | { | |
775 | if (!ip_vs_drop_rate) return 0; | |
776 | if (--ip_vs_drop_counter > 0) return 0; | |
777 | ip_vs_drop_counter = ip_vs_drop_rate; | |
778 | return 1; | |
779 | } | |
780 | ||
781 | /* | |
782 | * ip_vs_fwd_tag returns the forwarding tag of the connection | |
783 | */ | |
784 | #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK) | |
785 | ||
732db659 | 786 | static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp) |
1da177e4 LT |
787 | { |
788 | char fwd; | |
789 | ||
790 | switch (IP_VS_FWD_METHOD(cp)) { | |
791 | case IP_VS_CONN_F_MASQ: | |
792 | fwd = 'M'; break; | |
793 | case IP_VS_CONN_F_LOCALNODE: | |
794 | fwd = 'L'; break; | |
795 | case IP_VS_CONN_F_TUNNEL: | |
796 | fwd = 'T'; break; | |
797 | case IP_VS_CONN_F_DROUTE: | |
798 | fwd = 'R'; break; | |
799 | case IP_VS_CONN_F_BYPASS: | |
800 | fwd = 'B'; break; | |
801 | default: | |
802 | fwd = '?'; break; | |
803 | } | |
804 | return fwd; | |
805 | } | |
806 | ||
1da177e4 LT |
807 | extern void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp, |
808 | struct ip_vs_conn *cp, int dir); | |
809 | ||
b1550f22 | 810 | extern __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset); |
1da177e4 | 811 | |
f9214b26 | 812 | static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum) |
1da177e4 | 813 | { |
f9214b26 | 814 | __be32 diff[2] = { ~old, new }; |
1da177e4 | 815 | |
f9214b26 AV |
816 | return csum_partial((char *) diff, sizeof(diff), oldsum); |
817 | } | |
818 | ||
819 | static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum) | |
820 | { | |
821 | __be16 diff[2] = { ~old, new }; | |
822 | ||
823 | return csum_partial((char *) diff, sizeof(diff), oldsum); | |
1da177e4 LT |
824 | } |
825 | ||
826 | #endif /* __KERNEL__ */ | |
827 | ||
bc4768eb | 828 | #endif /* _NET_IP_VS_H */ |