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