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