diff options
author | Andrea Bastoni <bastoni@cs.unc.edu> | 2011-08-27 09:43:54 -0400 |
---|---|---|
committer | Andrea Bastoni <bastoni@cs.unc.edu> | 2011-08-27 10:06:11 -0400 |
commit | 7b1bb388bc879ffcc6c69b567816d5c354afe42b (patch) | |
tree | 5a217fdfb0b5e5a327bdcd624506337c1ae1fe32 /include/net/ip_vs.h | |
parent | 7d754596756240fa918b94cd0c3011c77a638987 (diff) | |
parent | 02f8c6aee8df3cdc935e9bdd4f2d020306035dbe (diff) |
Merge 'Linux v3.0' into Litmus
Some notes:
* Litmus^RT scheduling class is the topmost scheduling class
(above stop_sched_class).
* scheduler_ipi() function (e.g., in smp_reschedule_interrupt())
may increase IPI latencies.
* Added path into schedule() to quickly re-evaluate scheduling
decision without becoming preemptive again. This used to be
a standard path before the removal of BKL.
Conflicts:
Makefile
arch/arm/kernel/calls.S
arch/arm/kernel/smp.c
arch/x86/include/asm/unistd_32.h
arch/x86/kernel/smp.c
arch/x86/kernel/syscall_table_32.S
include/linux/hrtimer.h
kernel/printk.c
kernel/sched.c
kernel/sched_fair.c
Diffstat (limited to 'include/net/ip_vs.h')
-rw-r--r-- | include/net/ip_vs.h | 653 |
1 files changed, 561 insertions, 92 deletions
diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h index f976885f686f..481f856c650f 100644 --- a/include/net/ip_vs.h +++ b/include/net/ip_vs.h | |||
@@ -8,9 +8,6 @@ | |||
8 | 8 | ||
9 | #include <linux/ip_vs.h> /* definitions shared with userland */ | 9 | #include <linux/ip_vs.h> /* definitions shared with userland */ |
10 | 10 | ||
11 | /* old ipvsadm versions still include this file directly */ | ||
12 | #ifdef __KERNEL__ | ||
13 | |||
14 | #include <asm/types.h> /* for __uXX types */ | 11 | #include <asm/types.h> /* for __uXX types */ |
15 | 12 | ||
16 | #include <linux/sysctl.h> /* for ctl_path */ | 13 | #include <linux/sysctl.h> /* for ctl_path */ |
@@ -25,7 +22,83 @@ | |||
25 | #include <linux/ip.h> | 22 | #include <linux/ip.h> |
26 | #include <linux/ipv6.h> /* for struct ipv6hdr */ | 23 | #include <linux/ipv6.h> /* for struct ipv6hdr */ |
27 | #include <net/ipv6.h> /* for ipv6_addr_copy */ | 24 | #include <net/ipv6.h> /* for ipv6_addr_copy */ |
25 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) | ||
26 | #include <net/netfilter/nf_conntrack.h> | ||
27 | #endif | ||
28 | #include <net/net_namespace.h> /* Netw namespace */ | ||
28 | 29 | ||
30 | /* | ||
31 | * Generic access of ipvs struct | ||
32 | */ | ||
33 | static inline struct netns_ipvs *net_ipvs(struct net* net) | ||
34 | { | ||
35 | return net->ipvs; | ||
36 | } | ||
37 | /* | ||
38 | * Get net ptr from skb in traffic cases | ||
39 | * use skb_sknet when call is from userland (ioctl or netlink) | ||
40 | */ | ||
41 | static inline struct net *skb_net(const struct sk_buff *skb) | ||
42 | { | ||
43 | #ifdef CONFIG_NET_NS | ||
44 | #ifdef CONFIG_IP_VS_DEBUG | ||
45 | /* | ||
46 | * This is used for debug only. | ||
47 | * Start with the most likely hit | ||
48 | * End with BUG | ||
49 | */ | ||
50 | if (likely(skb->dev && skb->dev->nd_net)) | ||
51 | return dev_net(skb->dev); | ||
52 | if (skb_dst(skb) && skb_dst(skb)->dev) | ||
53 | return dev_net(skb_dst(skb)->dev); | ||
54 | WARN(skb->sk, "Maybe skb_sknet should be used in %s() at line:%d\n", | ||
55 | __func__, __LINE__); | ||
56 | if (likely(skb->sk && skb->sk->sk_net)) | ||
57 | return sock_net(skb->sk); | ||
58 | pr_err("There is no net ptr to find in the skb in %s() line:%d\n", | ||
59 | __func__, __LINE__); | ||
60 | BUG(); | ||
61 | #else | ||
62 | return dev_net(skb->dev ? : skb_dst(skb)->dev); | ||
63 | #endif | ||
64 | #else | ||
65 | return &init_net; | ||
66 | #endif | ||
67 | } | ||
68 | |||
69 | static inline struct net *skb_sknet(const struct sk_buff *skb) | ||
70 | { | ||
71 | #ifdef CONFIG_NET_NS | ||
72 | #ifdef CONFIG_IP_VS_DEBUG | ||
73 | /* Start with the most likely hit */ | ||
74 | if (likely(skb->sk && skb->sk->sk_net)) | ||
75 | return sock_net(skb->sk); | ||
76 | WARN(skb->dev, "Maybe skb_net should be used instead in %s() line:%d\n", | ||
77 | __func__, __LINE__); | ||
78 | if (likely(skb->dev && skb->dev->nd_net)) | ||
79 | return dev_net(skb->dev); | ||
80 | pr_err("There is no net ptr to find in the skb in %s() line:%d\n", | ||
81 | __func__, __LINE__); | ||
82 | BUG(); | ||
83 | #else | ||
84 | return sock_net(skb->sk); | ||
85 | #endif | ||
86 | #else | ||
87 | return &init_net; | ||
88 | #endif | ||
89 | } | ||
90 | /* | ||
91 | * This one needed for single_open_net since net is stored directly in | ||
92 | * private not as a struct i.e. seq_file_net can't be used. | ||
93 | */ | ||
94 | static inline struct net *seq_file_single_net(struct seq_file *seq) | ||
95 | { | ||
96 | #ifdef CONFIG_NET_NS | ||
97 | return (struct net *)seq->private; | ||
98 | #else | ||
99 | return &init_net; | ||
100 | #endif | ||
101 | } | ||
29 | 102 | ||
30 | /* Connections' size value needed by ip_vs_ctl.c */ | 103 | /* Connections' size value needed by ip_vs_ctl.c */ |
31 | extern int ip_vs_conn_tab_size; | 104 | extern int ip_vs_conn_tab_size; |
@@ -134,24 +207,24 @@ static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len, | |||
134 | if (net_ratelimit()) \ | 207 | if (net_ratelimit()) \ |
135 | printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \ | 208 | printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \ |
136 | } while (0) | 209 | } while (0) |
137 | #define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) \ | 210 | #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) \ |
138 | do { \ | 211 | do { \ |
139 | if (level <= ip_vs_get_debug_level()) \ | 212 | if (level <= ip_vs_get_debug_level()) \ |
140 | pp->debug_packet(pp, skb, ofs, msg); \ | 213 | pp->debug_packet(af, pp, skb, ofs, msg); \ |
141 | } while (0) | 214 | } while (0) |
142 | #define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) \ | 215 | #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) \ |
143 | do { \ | 216 | do { \ |
144 | if (level <= ip_vs_get_debug_level() && \ | 217 | if (level <= ip_vs_get_debug_level() && \ |
145 | net_ratelimit()) \ | 218 | net_ratelimit()) \ |
146 | pp->debug_packet(pp, skb, ofs, msg); \ | 219 | pp->debug_packet(af, pp, skb, ofs, msg); \ |
147 | } while (0) | 220 | } while (0) |
148 | #else /* NO DEBUGGING at ALL */ | 221 | #else /* NO DEBUGGING at ALL */ |
149 | #define IP_VS_DBG_BUF(level, msg...) do {} while (0) | 222 | #define IP_VS_DBG_BUF(level, msg...) do {} while (0) |
150 | #define IP_VS_ERR_BUF(msg...) do {} while (0) | 223 | #define IP_VS_ERR_BUF(msg...) do {} while (0) |
151 | #define IP_VS_DBG(level, msg...) do {} while (0) | 224 | #define IP_VS_DBG(level, msg...) do {} while (0) |
152 | #define IP_VS_DBG_RL(msg...) do {} while (0) | 225 | #define IP_VS_DBG_RL(msg...) do {} while (0) |
153 | #define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) do {} while (0) | 226 | #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) do {} while (0) |
154 | #define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) do {} while (0) | 227 | #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) do {} while (0) |
155 | #endif | 228 | #endif |
156 | 229 | ||
157 | #define IP_VS_BUG() BUG() | 230 | #define IP_VS_BUG() BUG() |
@@ -256,6 +329,23 @@ struct ip_vs_seq { | |||
256 | before last resized pkt */ | 329 | before last resized pkt */ |
257 | }; | 330 | }; |
258 | 331 | ||
332 | /* | ||
333 | * counters per cpu | ||
334 | */ | ||
335 | struct ip_vs_counters { | ||
336 | __u32 conns; /* connections scheduled */ | ||
337 | __u32 inpkts; /* incoming packets */ | ||
338 | __u32 outpkts; /* outgoing packets */ | ||
339 | __u64 inbytes; /* incoming bytes */ | ||
340 | __u64 outbytes; /* outgoing bytes */ | ||
341 | }; | ||
342 | /* | ||
343 | * Stats per cpu | ||
344 | */ | ||
345 | struct ip_vs_cpu_stats { | ||
346 | struct ip_vs_counters ustats; | ||
347 | struct u64_stats_sync syncp; | ||
348 | }; | ||
259 | 349 | ||
260 | /* | 350 | /* |
261 | * IPVS statistics objects | 351 | * IPVS statistics objects |
@@ -277,10 +367,11 @@ struct ip_vs_estimator { | |||
277 | }; | 367 | }; |
278 | 368 | ||
279 | struct ip_vs_stats { | 369 | struct ip_vs_stats { |
280 | struct ip_vs_stats_user ustats; /* statistics */ | 370 | struct ip_vs_stats_user ustats; /* statistics */ |
281 | struct ip_vs_estimator est; /* estimator */ | 371 | struct ip_vs_estimator est; /* estimator */ |
282 | 372 | struct ip_vs_cpu_stats *cpustats; /* per cpu counters */ | |
283 | spinlock_t lock; /* spin lock */ | 373 | spinlock_t lock; /* spin lock */ |
374 | struct ip_vs_stats_user ustats0; /* reset values */ | ||
284 | }; | 375 | }; |
285 | 376 | ||
286 | struct dst_entry; | 377 | struct dst_entry; |
@@ -288,6 +379,7 @@ struct iphdr; | |||
288 | struct ip_vs_conn; | 379 | struct ip_vs_conn; |
289 | struct ip_vs_app; | 380 | struct ip_vs_app; |
290 | struct sk_buff; | 381 | struct sk_buff; |
382 | struct ip_vs_proto_data; | ||
291 | 383 | ||
292 | struct ip_vs_protocol { | 384 | struct ip_vs_protocol { |
293 | struct ip_vs_protocol *next; | 385 | struct ip_vs_protocol *next; |
@@ -295,21 +387,22 @@ struct ip_vs_protocol { | |||
295 | u16 protocol; | 387 | u16 protocol; |
296 | u16 num_states; | 388 | u16 num_states; |
297 | int dont_defrag; | 389 | int dont_defrag; |
298 | atomic_t appcnt; /* counter of proto app incs */ | ||
299 | int *timeout_table; /* protocol timeout table */ | ||
300 | 390 | ||
301 | void (*init)(struct ip_vs_protocol *pp); | 391 | void (*init)(struct ip_vs_protocol *pp); |
302 | 392 | ||
303 | void (*exit)(struct ip_vs_protocol *pp); | 393 | void (*exit)(struct ip_vs_protocol *pp); |
304 | 394 | ||
395 | void (*init_netns)(struct net *net, struct ip_vs_proto_data *pd); | ||
396 | |||
397 | void (*exit_netns)(struct net *net, struct ip_vs_proto_data *pd); | ||
398 | |||
305 | int (*conn_schedule)(int af, struct sk_buff *skb, | 399 | int (*conn_schedule)(int af, struct sk_buff *skb, |
306 | struct ip_vs_protocol *pp, | 400 | struct ip_vs_proto_data *pd, |
307 | int *verdict, struct ip_vs_conn **cpp); | 401 | int *verdict, struct ip_vs_conn **cpp); |
308 | 402 | ||
309 | struct ip_vs_conn * | 403 | struct ip_vs_conn * |
310 | (*conn_in_get)(int af, | 404 | (*conn_in_get)(int af, |
311 | const struct sk_buff *skb, | 405 | const struct sk_buff *skb, |
312 | struct ip_vs_protocol *pp, | ||
313 | const struct ip_vs_iphdr *iph, | 406 | const struct ip_vs_iphdr *iph, |
314 | unsigned int proto_off, | 407 | unsigned int proto_off, |
315 | int inverse); | 408 | int inverse); |
@@ -317,7 +410,6 @@ struct ip_vs_protocol { | |||
317 | struct ip_vs_conn * | 410 | struct ip_vs_conn * |
318 | (*conn_out_get)(int af, | 411 | (*conn_out_get)(int af, |
319 | const struct sk_buff *skb, | 412 | const struct sk_buff *skb, |
320 | struct ip_vs_protocol *pp, | ||
321 | const struct ip_vs_iphdr *iph, | 413 | const struct ip_vs_iphdr *iph, |
322 | unsigned int proto_off, | 414 | unsigned int proto_off, |
323 | int inverse); | 415 | int inverse); |
@@ -335,40 +427,69 @@ struct ip_vs_protocol { | |||
335 | 427 | ||
336 | int (*state_transition)(struct ip_vs_conn *cp, int direction, | 428 | int (*state_transition)(struct ip_vs_conn *cp, int direction, |
337 | const struct sk_buff *skb, | 429 | const struct sk_buff *skb, |
338 | struct ip_vs_protocol *pp); | 430 | struct ip_vs_proto_data *pd); |
339 | 431 | ||
340 | int (*register_app)(struct ip_vs_app *inc); | 432 | int (*register_app)(struct net *net, struct ip_vs_app *inc); |
341 | 433 | ||
342 | void (*unregister_app)(struct ip_vs_app *inc); | 434 | void (*unregister_app)(struct net *net, struct ip_vs_app *inc); |
343 | 435 | ||
344 | int (*app_conn_bind)(struct ip_vs_conn *cp); | 436 | int (*app_conn_bind)(struct ip_vs_conn *cp); |
345 | 437 | ||
346 | void (*debug_packet)(struct ip_vs_protocol *pp, | 438 | void (*debug_packet)(int af, struct ip_vs_protocol *pp, |
347 | const struct sk_buff *skb, | 439 | const struct sk_buff *skb, |
348 | int offset, | 440 | int offset, |
349 | const char *msg); | 441 | const char *msg); |
350 | 442 | ||
351 | void (*timeout_change)(struct ip_vs_protocol *pp, int flags); | 443 | void (*timeout_change)(struct ip_vs_proto_data *pd, int flags); |
444 | }; | ||
352 | 445 | ||
353 | int (*set_state_timeout)(struct ip_vs_protocol *pp, char *sname, int to); | 446 | /* |
447 | * protocol data per netns | ||
448 | */ | ||
449 | struct ip_vs_proto_data { | ||
450 | struct ip_vs_proto_data *next; | ||
451 | struct ip_vs_protocol *pp; | ||
452 | int *timeout_table; /* protocol timeout table */ | ||
453 | atomic_t appcnt; /* counter of proto app incs. */ | ||
454 | struct tcp_states_t *tcp_state_table; | ||
354 | }; | 455 | }; |
355 | 456 | ||
356 | extern struct ip_vs_protocol * ip_vs_proto_get(unsigned short proto); | 457 | extern struct ip_vs_protocol *ip_vs_proto_get(unsigned short proto); |
458 | extern struct ip_vs_proto_data *ip_vs_proto_data_get(struct net *net, | ||
459 | unsigned short proto); | ||
460 | |||
461 | struct ip_vs_conn_param { | ||
462 | struct net *net; | ||
463 | const union nf_inet_addr *caddr; | ||
464 | const union nf_inet_addr *vaddr; | ||
465 | __be16 cport; | ||
466 | __be16 vport; | ||
467 | __u16 protocol; | ||
468 | u16 af; | ||
469 | |||
470 | const struct ip_vs_pe *pe; | ||
471 | char *pe_data; | ||
472 | __u8 pe_data_len; | ||
473 | }; | ||
357 | 474 | ||
358 | /* | 475 | /* |
359 | * IP_VS structure allocated for each dynamically scheduled connection | 476 | * IP_VS structure allocated for each dynamically scheduled connection |
360 | */ | 477 | */ |
361 | struct ip_vs_conn { | 478 | struct ip_vs_conn { |
362 | struct list_head c_list; /* hashed list heads */ | 479 | struct hlist_node c_list; /* hashed list heads */ |
363 | 480 | #ifdef CONFIG_NET_NS | |
481 | struct net *net; /* Name space */ | ||
482 | #endif | ||
364 | /* Protocol, addresses and port numbers */ | 483 | /* Protocol, addresses and port numbers */ |
365 | u16 af; /* address family */ | 484 | u16 af; /* address family */ |
366 | union nf_inet_addr caddr; /* client address */ | 485 | __be16 cport; |
367 | union nf_inet_addr vaddr; /* virtual address */ | 486 | __be16 vport; |
368 | union nf_inet_addr daddr; /* destination address */ | 487 | __be16 dport; |
369 | __be16 cport; | 488 | __u32 fwmark; /* Fire wall mark from skb */ |
370 | __be16 vport; | 489 | union nf_inet_addr caddr; /* client address */ |
371 | __be16 dport; | 490 | union nf_inet_addr vaddr; /* virtual address */ |
491 | union nf_inet_addr daddr; /* destination address */ | ||
492 | volatile __u32 flags; /* status flags */ | ||
372 | __u16 protocol; /* Which protocol (TCP/UDP) */ | 493 | __u16 protocol; /* Which protocol (TCP/UDP) */ |
373 | 494 | ||
374 | /* counter and timer */ | 495 | /* counter and timer */ |
@@ -378,7 +499,6 @@ struct ip_vs_conn { | |||
378 | 499 | ||
379 | /* Flags and state transition */ | 500 | /* Flags and state transition */ |
380 | spinlock_t lock; /* lock for state transition */ | 501 | spinlock_t lock; /* lock for state transition */ |
381 | volatile __u16 flags; /* status flags */ | ||
382 | volatile __u16 state; /* state info */ | 502 | volatile __u16 state; /* state info */ |
383 | volatile __u16 old_state; /* old state, to be used for | 503 | volatile __u16 old_state; /* old state, to be used for |
384 | * state transition triggerd | 504 | * state transition triggerd |
@@ -394,6 +514,7 @@ struct ip_vs_conn { | |||
394 | /* packet transmitter for different forwarding methods. If it | 514 | /* packet transmitter for different forwarding methods. If it |
395 | mangles the packet, it must return NF_DROP or better NF_STOLEN, | 515 | mangles the packet, it must return NF_DROP or better NF_STOLEN, |
396 | otherwise this must be changed to a sk_buff **. | 516 | otherwise this must be changed to a sk_buff **. |
517 | NF_ACCEPT can be returned when destination is local. | ||
397 | */ | 518 | */ |
398 | int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp, | 519 | int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp, |
399 | struct ip_vs_protocol *pp); | 520 | struct ip_vs_protocol *pp); |
@@ -405,8 +526,39 @@ struct ip_vs_conn { | |||
405 | void *app_data; /* Application private data */ | 526 | void *app_data; /* Application private data */ |
406 | struct ip_vs_seq in_seq; /* incoming seq. struct */ | 527 | struct ip_vs_seq in_seq; /* incoming seq. struct */ |
407 | struct ip_vs_seq out_seq; /* outgoing seq. struct */ | 528 | struct ip_vs_seq out_seq; /* outgoing seq. struct */ |
529 | |||
530 | const struct ip_vs_pe *pe; | ||
531 | char *pe_data; | ||
532 | __u8 pe_data_len; | ||
408 | }; | 533 | }; |
409 | 534 | ||
535 | /* | ||
536 | * To save some memory in conn table when name space is disabled. | ||
537 | */ | ||
538 | static inline struct net *ip_vs_conn_net(const struct ip_vs_conn *cp) | ||
539 | { | ||
540 | #ifdef CONFIG_NET_NS | ||
541 | return cp->net; | ||
542 | #else | ||
543 | return &init_net; | ||
544 | #endif | ||
545 | } | ||
546 | static inline void ip_vs_conn_net_set(struct ip_vs_conn *cp, struct net *net) | ||
547 | { | ||
548 | #ifdef CONFIG_NET_NS | ||
549 | cp->net = net; | ||
550 | #endif | ||
551 | } | ||
552 | |||
553 | static inline int ip_vs_conn_net_eq(const struct ip_vs_conn *cp, | ||
554 | struct net *net) | ||
555 | { | ||
556 | #ifdef CONFIG_NET_NS | ||
557 | return cp->net == net; | ||
558 | #else | ||
559 | return 1; | ||
560 | #endif | ||
561 | } | ||
410 | 562 | ||
411 | /* | 563 | /* |
412 | * Extended internal versions of struct ip_vs_service_user and | 564 | * Extended internal versions of struct ip_vs_service_user and |
@@ -426,6 +578,7 @@ struct ip_vs_service_user_kern { | |||
426 | 578 | ||
427 | /* virtual service options */ | 579 | /* virtual service options */ |
428 | char *sched_name; | 580 | char *sched_name; |
581 | char *pe_name; | ||
429 | unsigned flags; /* virtual service flags */ | 582 | unsigned flags; /* virtual service flags */ |
430 | unsigned timeout; /* persistent timeout in sec */ | 583 | unsigned timeout; /* persistent timeout in sec */ |
431 | u32 netmask; /* persistent netmask */ | 584 | u32 netmask; /* persistent netmask */ |
@@ -465,6 +618,7 @@ struct ip_vs_service { | |||
465 | unsigned flags; /* service status flags */ | 618 | unsigned flags; /* service status flags */ |
466 | unsigned timeout; /* persistent timeout in ticks */ | 619 | unsigned timeout; /* persistent timeout in ticks */ |
467 | __be32 netmask; /* grouping granularity */ | 620 | __be32 netmask; /* grouping granularity */ |
621 | struct net *net; | ||
468 | 622 | ||
469 | struct list_head destinations; /* real server d-linked list */ | 623 | struct list_head destinations; /* real server d-linked list */ |
470 | __u32 num_dests; /* number of servers */ | 624 | __u32 num_dests; /* number of servers */ |
@@ -475,6 +629,9 @@ struct ip_vs_service { | |||
475 | struct ip_vs_scheduler *scheduler; /* bound scheduler object */ | 629 | struct ip_vs_scheduler *scheduler; /* bound scheduler object */ |
476 | rwlock_t sched_lock; /* lock sched_data */ | 630 | rwlock_t sched_lock; /* lock sched_data */ |
477 | void *sched_data; /* scheduler application data */ | 631 | void *sched_data; /* scheduler application data */ |
632 | |||
633 | /* alternate persistence engine */ | ||
634 | struct ip_vs_pe *pe; | ||
478 | }; | 635 | }; |
479 | 636 | ||
480 | 637 | ||
@@ -487,8 +644,8 @@ struct ip_vs_dest { | |||
487 | struct list_head d_list; /* for table with all the dests */ | 644 | struct list_head d_list; /* for table with all the dests */ |
488 | 645 | ||
489 | u16 af; /* address family */ | 646 | u16 af; /* address family */ |
490 | union nf_inet_addr addr; /* IP address of the server */ | ||
491 | __be16 port; /* port number of the server */ | 647 | __be16 port; /* port number of the server */ |
648 | union nf_inet_addr addr; /* IP address of the server */ | ||
492 | volatile unsigned flags; /* dest status flags */ | 649 | volatile unsigned flags; /* dest status flags */ |
493 | atomic_t conn_flags; /* flags to copy to conn */ | 650 | atomic_t conn_flags; /* flags to copy to conn */ |
494 | atomic_t weight; /* server weight */ | 651 | atomic_t weight; /* server weight */ |
@@ -507,12 +664,14 @@ struct ip_vs_dest { | |||
507 | spinlock_t dst_lock; /* lock of dst_cache */ | 664 | spinlock_t dst_lock; /* lock of dst_cache */ |
508 | struct dst_entry *dst_cache; /* destination cache entry */ | 665 | struct dst_entry *dst_cache; /* destination cache entry */ |
509 | u32 dst_rtos; /* RT_TOS(tos) for dst */ | 666 | u32 dst_rtos; /* RT_TOS(tos) for dst */ |
667 | u32 dst_cookie; | ||
668 | union nf_inet_addr dst_saddr; | ||
510 | 669 | ||
511 | /* for virtual service */ | 670 | /* for virtual service */ |
512 | struct ip_vs_service *svc; /* service it belongs to */ | 671 | struct ip_vs_service *svc; /* service it belongs to */ |
513 | __u16 protocol; /* which protocol (TCP/UDP) */ | 672 | __u16 protocol; /* which protocol (TCP/UDP) */ |
514 | union nf_inet_addr vaddr; /* virtual IP address */ | ||
515 | __be16 vport; /* virtual port number */ | 673 | __be16 vport; /* virtual port number */ |
674 | union nf_inet_addr vaddr; /* virtual IP address */ | ||
516 | __u32 vfwmark; /* firewall mark of service */ | 675 | __u32 vfwmark; /* firewall mark of service */ |
517 | }; | 676 | }; |
518 | 677 | ||
@@ -538,6 +697,21 @@ struct ip_vs_scheduler { | |||
538 | const struct sk_buff *skb); | 697 | const struct sk_buff *skb); |
539 | }; | 698 | }; |
540 | 699 | ||
700 | /* The persistence engine object */ | ||
701 | struct ip_vs_pe { | ||
702 | struct list_head n_list; /* d-linked list head */ | ||
703 | char *name; /* scheduler name */ | ||
704 | atomic_t refcnt; /* reference counter */ | ||
705 | struct module *module; /* THIS_MODULE/NULL */ | ||
706 | |||
707 | /* get the connection template, if any */ | ||
708 | int (*fill_param)(struct ip_vs_conn_param *p, struct sk_buff *skb); | ||
709 | bool (*ct_match)(const struct ip_vs_conn_param *p, | ||
710 | struct ip_vs_conn *ct); | ||
711 | u32 (*hashkey_raw)(const struct ip_vs_conn_param *p, u32 initval, | ||
712 | bool inverse); | ||
713 | int (*show_pe_data)(const struct ip_vs_conn *cp, char *buf); | ||
714 | }; | ||
541 | 715 | ||
542 | /* | 716 | /* |
543 | * The application module object (a.k.a. app incarnation) | 717 | * The application module object (a.k.a. app incarnation) |
@@ -556,11 +730,19 @@ struct ip_vs_app { | |||
556 | __be16 port; /* port number in net order */ | 730 | __be16 port; /* port number in net order */ |
557 | atomic_t usecnt; /* usage counter */ | 731 | atomic_t usecnt; /* usage counter */ |
558 | 732 | ||
559 | /* output hook: return false if can't linearize. diff set for TCP. */ | 733 | /* |
734 | * output hook: Process packet in inout direction, diff set for TCP. | ||
735 | * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok, | ||
736 | * 2=Mangled but checksum was not updated | ||
737 | */ | ||
560 | int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *, | 738 | int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *, |
561 | struct sk_buff *, int *diff); | 739 | struct sk_buff *, int *diff); |
562 | 740 | ||
563 | /* input hook: return false if can't linearize. diff set for TCP. */ | 741 | /* |
742 | * input hook: Process packet in outin direction, diff set for TCP. | ||
743 | * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok, | ||
744 | * 2=Mangled but checksum was not updated | ||
745 | */ | ||
564 | int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *, | 746 | int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *, |
565 | struct sk_buff *, int *diff); | 747 | struct sk_buff *, int *diff); |
566 | 748 | ||
@@ -601,6 +783,171 @@ struct ip_vs_app { | |||
601 | void (*timeout_change)(struct ip_vs_app *app, int flags); | 783 | void (*timeout_change)(struct ip_vs_app *app, int flags); |
602 | }; | 784 | }; |
603 | 785 | ||
786 | /* IPVS in network namespace */ | ||
787 | struct netns_ipvs { | ||
788 | int gen; /* Generation */ | ||
789 | int enable; /* enable like nf_hooks do */ | ||
790 | /* | ||
791 | * Hash table: for real service lookups | ||
792 | */ | ||
793 | #define IP_VS_RTAB_BITS 4 | ||
794 | #define IP_VS_RTAB_SIZE (1 << IP_VS_RTAB_BITS) | ||
795 | #define IP_VS_RTAB_MASK (IP_VS_RTAB_SIZE - 1) | ||
796 | |||
797 | struct list_head rs_table[IP_VS_RTAB_SIZE]; | ||
798 | /* ip_vs_app */ | ||
799 | struct list_head app_list; | ||
800 | /* ip_vs_ftp */ | ||
801 | struct ip_vs_app *ftp_app; | ||
802 | /* ip_vs_proto */ | ||
803 | #define IP_VS_PROTO_TAB_SIZE 32 /* must be power of 2 */ | ||
804 | struct ip_vs_proto_data *proto_data_table[IP_VS_PROTO_TAB_SIZE]; | ||
805 | /* ip_vs_proto_tcp */ | ||
806 | #ifdef CONFIG_IP_VS_PROTO_TCP | ||
807 | #define TCP_APP_TAB_BITS 4 | ||
808 | #define TCP_APP_TAB_SIZE (1 << TCP_APP_TAB_BITS) | ||
809 | #define TCP_APP_TAB_MASK (TCP_APP_TAB_SIZE - 1) | ||
810 | struct list_head tcp_apps[TCP_APP_TAB_SIZE]; | ||
811 | spinlock_t tcp_app_lock; | ||
812 | #endif | ||
813 | /* ip_vs_proto_udp */ | ||
814 | #ifdef CONFIG_IP_VS_PROTO_UDP | ||
815 | #define UDP_APP_TAB_BITS 4 | ||
816 | #define UDP_APP_TAB_SIZE (1 << UDP_APP_TAB_BITS) | ||
817 | #define UDP_APP_TAB_MASK (UDP_APP_TAB_SIZE - 1) | ||
818 | struct list_head udp_apps[UDP_APP_TAB_SIZE]; | ||
819 | spinlock_t udp_app_lock; | ||
820 | #endif | ||
821 | /* ip_vs_proto_sctp */ | ||
822 | #ifdef CONFIG_IP_VS_PROTO_SCTP | ||
823 | #define SCTP_APP_TAB_BITS 4 | ||
824 | #define SCTP_APP_TAB_SIZE (1 << SCTP_APP_TAB_BITS) | ||
825 | #define SCTP_APP_TAB_MASK (SCTP_APP_TAB_SIZE - 1) | ||
826 | /* Hash table for SCTP application incarnations */ | ||
827 | struct list_head sctp_apps[SCTP_APP_TAB_SIZE]; | ||
828 | spinlock_t sctp_app_lock; | ||
829 | #endif | ||
830 | /* ip_vs_conn */ | ||
831 | atomic_t conn_count; /* connection counter */ | ||
832 | |||
833 | /* ip_vs_ctl */ | ||
834 | struct ip_vs_stats tot_stats; /* Statistics & est. */ | ||
835 | |||
836 | int num_services; /* no of virtual services */ | ||
837 | |||
838 | rwlock_t rs_lock; /* real services table */ | ||
839 | /* semaphore for IPVS sockopts. And, [gs]etsockopt may sleep. */ | ||
840 | struct lock_class_key ctl_key; /* ctl_mutex debuging */ | ||
841 | /* Trash for destinations */ | ||
842 | struct list_head dest_trash; | ||
843 | /* Service counters */ | ||
844 | atomic_t ftpsvc_counter; | ||
845 | atomic_t nullsvc_counter; | ||
846 | |||
847 | #ifdef CONFIG_SYSCTL | ||
848 | /* 1/rate drop and drop-entry variables */ | ||
849 | struct delayed_work defense_work; /* Work handler */ | ||
850 | int drop_rate; | ||
851 | int drop_counter; | ||
852 | atomic_t dropentry; | ||
853 | /* locks in ctl.c */ | ||
854 | spinlock_t dropentry_lock; /* drop entry handling */ | ||
855 | spinlock_t droppacket_lock; /* drop packet handling */ | ||
856 | spinlock_t securetcp_lock; /* state and timeout tables */ | ||
857 | |||
858 | /* sys-ctl struct */ | ||
859 | struct ctl_table_header *sysctl_hdr; | ||
860 | struct ctl_table *sysctl_tbl; | ||
861 | #endif | ||
862 | |||
863 | /* sysctl variables */ | ||
864 | int sysctl_amemthresh; | ||
865 | int sysctl_am_droprate; | ||
866 | int sysctl_drop_entry; | ||
867 | int sysctl_drop_packet; | ||
868 | int sysctl_secure_tcp; | ||
869 | #ifdef CONFIG_IP_VS_NFCT | ||
870 | int sysctl_conntrack; | ||
871 | #endif | ||
872 | int sysctl_snat_reroute; | ||
873 | int sysctl_sync_ver; | ||
874 | int sysctl_cache_bypass; | ||
875 | int sysctl_expire_nodest_conn; | ||
876 | int sysctl_expire_quiescent_template; | ||
877 | int sysctl_sync_threshold[2]; | ||
878 | int sysctl_nat_icmp_send; | ||
879 | |||
880 | /* ip_vs_lblc */ | ||
881 | int sysctl_lblc_expiration; | ||
882 | struct ctl_table_header *lblc_ctl_header; | ||
883 | struct ctl_table *lblc_ctl_table; | ||
884 | /* ip_vs_lblcr */ | ||
885 | int sysctl_lblcr_expiration; | ||
886 | struct ctl_table_header *lblcr_ctl_header; | ||
887 | struct ctl_table *lblcr_ctl_table; | ||
888 | /* ip_vs_est */ | ||
889 | struct list_head est_list; /* estimator list */ | ||
890 | spinlock_t est_lock; | ||
891 | struct timer_list est_timer; /* Estimation timer */ | ||
892 | /* ip_vs_sync */ | ||
893 | struct list_head sync_queue; | ||
894 | spinlock_t sync_lock; | ||
895 | struct ip_vs_sync_buff *sync_buff; | ||
896 | spinlock_t sync_buff_lock; | ||
897 | struct sockaddr_in sync_mcast_addr; | ||
898 | struct task_struct *master_thread; | ||
899 | struct task_struct *backup_thread; | ||
900 | int send_mesg_maxlen; | ||
901 | int recv_mesg_maxlen; | ||
902 | volatile int sync_state; | ||
903 | volatile int master_syncid; | ||
904 | volatile int backup_syncid; | ||
905 | /* multicast interface name */ | ||
906 | char master_mcast_ifn[IP_VS_IFNAME_MAXLEN]; | ||
907 | char backup_mcast_ifn[IP_VS_IFNAME_MAXLEN]; | ||
908 | /* net name space ptr */ | ||
909 | struct net *net; /* Needed by timer routines */ | ||
910 | }; | ||
911 | |||
912 | #define DEFAULT_SYNC_THRESHOLD 3 | ||
913 | #define DEFAULT_SYNC_PERIOD 50 | ||
914 | #define DEFAULT_SYNC_VER 1 | ||
915 | |||
916 | #ifdef CONFIG_SYSCTL | ||
917 | |||
918 | static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs) | ||
919 | { | ||
920 | return ipvs->sysctl_sync_threshold[0]; | ||
921 | } | ||
922 | |||
923 | static inline int sysctl_sync_period(struct netns_ipvs *ipvs) | ||
924 | { | ||
925 | return ipvs->sysctl_sync_threshold[1]; | ||
926 | } | ||
927 | |||
928 | static inline int sysctl_sync_ver(struct netns_ipvs *ipvs) | ||
929 | { | ||
930 | return ipvs->sysctl_sync_ver; | ||
931 | } | ||
932 | |||
933 | #else | ||
934 | |||
935 | static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs) | ||
936 | { | ||
937 | return DEFAULT_SYNC_THRESHOLD; | ||
938 | } | ||
939 | |||
940 | static inline int sysctl_sync_period(struct netns_ipvs *ipvs) | ||
941 | { | ||
942 | return DEFAULT_SYNC_PERIOD; | ||
943 | } | ||
944 | |||
945 | static inline int sysctl_sync_ver(struct netns_ipvs *ipvs) | ||
946 | { | ||
947 | return DEFAULT_SYNC_VER; | ||
948 | } | ||
949 | |||
950 | #endif | ||
604 | 951 | ||
605 | /* | 952 | /* |
606 | * IPVS core functions | 953 | * IPVS core functions |
@@ -624,26 +971,35 @@ enum { | |||
624 | IP_VS_DIR_LAST, | 971 | IP_VS_DIR_LAST, |
625 | }; | 972 | }; |
626 | 973 | ||
627 | extern struct ip_vs_conn *ip_vs_conn_in_get | 974 | static inline void ip_vs_conn_fill_param(struct net *net, int af, int protocol, |
628 | (int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port, | 975 | const union nf_inet_addr *caddr, |
629 | const union nf_inet_addr *d_addr, __be16 d_port); | 976 | __be16 cport, |
977 | const union nf_inet_addr *vaddr, | ||
978 | __be16 vport, | ||
979 | struct ip_vs_conn_param *p) | ||
980 | { | ||
981 | p->net = net; | ||
982 | p->af = af; | ||
983 | p->protocol = protocol; | ||
984 | p->caddr = caddr; | ||
985 | p->cport = cport; | ||
986 | p->vaddr = vaddr; | ||
987 | p->vport = vport; | ||
988 | p->pe = NULL; | ||
989 | p->pe_data = NULL; | ||
990 | } | ||
630 | 991 | ||
631 | extern struct ip_vs_conn *ip_vs_ct_in_get | 992 | struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p); |
632 | (int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port, | 993 | struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p); |
633 | const union nf_inet_addr *d_addr, __be16 d_port); | ||
634 | 994 | ||
635 | struct ip_vs_conn * ip_vs_conn_in_get_proto(int af, const struct sk_buff *skb, | 995 | struct ip_vs_conn * ip_vs_conn_in_get_proto(int af, const struct sk_buff *skb, |
636 | struct ip_vs_protocol *pp, | ||
637 | const struct ip_vs_iphdr *iph, | 996 | const struct ip_vs_iphdr *iph, |
638 | unsigned int proto_off, | 997 | unsigned int proto_off, |
639 | int inverse); | 998 | int inverse); |
640 | 999 | ||
641 | extern struct ip_vs_conn *ip_vs_conn_out_get | 1000 | struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p); |
642 | (int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port, | ||
643 | const union nf_inet_addr *d_addr, __be16 d_port); | ||
644 | 1001 | ||
645 | struct ip_vs_conn * ip_vs_conn_out_get_proto(int af, const struct sk_buff *skb, | 1002 | struct ip_vs_conn * ip_vs_conn_out_get_proto(int af, const struct sk_buff *skb, |
646 | struct ip_vs_protocol *pp, | ||
647 | const struct ip_vs_iphdr *iph, | 1003 | const struct ip_vs_iphdr *iph, |
648 | unsigned int proto_off, | 1004 | unsigned int proto_off, |
649 | int inverse); | 1005 | int inverse); |
@@ -656,18 +1012,17 @@ static inline void __ip_vs_conn_put(struct ip_vs_conn *cp) | |||
656 | extern void ip_vs_conn_put(struct ip_vs_conn *cp); | 1012 | extern void ip_vs_conn_put(struct ip_vs_conn *cp); |
657 | extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport); | 1013 | extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport); |
658 | 1014 | ||
659 | extern struct ip_vs_conn * | 1015 | struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p, |
660 | ip_vs_conn_new(int af, int proto, const union nf_inet_addr *caddr, __be16 cport, | 1016 | const union nf_inet_addr *daddr, |
661 | const union nf_inet_addr *vaddr, __be16 vport, | 1017 | __be16 dport, unsigned flags, |
662 | const union nf_inet_addr *daddr, __be16 dport, unsigned flags, | 1018 | struct ip_vs_dest *dest, __u32 fwmark); |
663 | struct ip_vs_dest *dest); | ||
664 | extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp); | 1019 | extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp); |
665 | 1020 | ||
666 | extern const char * ip_vs_state_name(__u16 proto, int state); | 1021 | extern const char * ip_vs_state_name(__u16 proto, int state); |
667 | 1022 | ||
668 | extern void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp); | 1023 | extern void ip_vs_tcp_conn_listen(struct net *net, struct ip_vs_conn *cp); |
669 | extern int ip_vs_check_template(struct ip_vs_conn *ct); | 1024 | extern int ip_vs_check_template(struct ip_vs_conn *ct); |
670 | extern void ip_vs_random_dropentry(void); | 1025 | extern void ip_vs_random_dropentry(struct net *net); |
671 | extern int ip_vs_conn_init(void); | 1026 | extern int ip_vs_conn_init(void); |
672 | extern void ip_vs_conn_cleanup(void); | 1027 | extern void ip_vs_conn_cleanup(void); |
673 | 1028 | ||
@@ -731,18 +1086,34 @@ ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp) | |||
731 | atomic_inc(&ctl_cp->n_control); | 1086 | atomic_inc(&ctl_cp->n_control); |
732 | } | 1087 | } |
733 | 1088 | ||
1089 | /* | ||
1090 | * IPVS netns init & cleanup functions | ||
1091 | */ | ||
1092 | extern int __ip_vs_estimator_init(struct net *net); | ||
1093 | extern int __ip_vs_control_init(struct net *net); | ||
1094 | extern int __ip_vs_protocol_init(struct net *net); | ||
1095 | extern int __ip_vs_app_init(struct net *net); | ||
1096 | extern int __ip_vs_conn_init(struct net *net); | ||
1097 | extern int __ip_vs_sync_init(struct net *net); | ||
1098 | extern void __ip_vs_conn_cleanup(struct net *net); | ||
1099 | extern void __ip_vs_app_cleanup(struct net *net); | ||
1100 | extern void __ip_vs_protocol_cleanup(struct net *net); | ||
1101 | extern void __ip_vs_control_cleanup(struct net *net); | ||
1102 | extern void __ip_vs_estimator_cleanup(struct net *net); | ||
1103 | extern void __ip_vs_sync_cleanup(struct net *net); | ||
1104 | extern void __ip_vs_service_cleanup(struct net *net); | ||
734 | 1105 | ||
735 | /* | 1106 | /* |
736 | * IPVS application functions | 1107 | * IPVS application functions |
737 | * (from ip_vs_app.c) | 1108 | * (from ip_vs_app.c) |
738 | */ | 1109 | */ |
739 | #define IP_VS_APP_MAX_PORTS 8 | 1110 | #define IP_VS_APP_MAX_PORTS 8 |
740 | extern int register_ip_vs_app(struct ip_vs_app *app); | 1111 | extern int register_ip_vs_app(struct net *net, struct ip_vs_app *app); |
741 | extern void unregister_ip_vs_app(struct ip_vs_app *app); | 1112 | extern void unregister_ip_vs_app(struct net *net, struct ip_vs_app *app); |
742 | extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp); | 1113 | extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
743 | extern void ip_vs_unbind_app(struct ip_vs_conn *cp); | 1114 | extern void ip_vs_unbind_app(struct ip_vs_conn *cp); |
744 | extern int | 1115 | extern int register_ip_vs_app_inc(struct net *net, struct ip_vs_app *app, |
745 | register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port); | 1116 | __u16 proto, __u16 port); |
746 | extern int ip_vs_app_inc_get(struct ip_vs_app *inc); | 1117 | extern int ip_vs_app_inc_get(struct ip_vs_app *inc); |
747 | extern void ip_vs_app_inc_put(struct ip_vs_app *inc); | 1118 | extern void ip_vs_app_inc_put(struct ip_vs_app *inc); |
748 | 1119 | ||
@@ -751,19 +1122,38 @@ extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb); | |||
751 | extern int ip_vs_app_init(void); | 1122 | extern int ip_vs_app_init(void); |
752 | extern void ip_vs_app_cleanup(void); | 1123 | extern void ip_vs_app_cleanup(void); |
753 | 1124 | ||
1125 | void ip_vs_bind_pe(struct ip_vs_service *svc, struct ip_vs_pe *pe); | ||
1126 | void ip_vs_unbind_pe(struct ip_vs_service *svc); | ||
1127 | int register_ip_vs_pe(struct ip_vs_pe *pe); | ||
1128 | int unregister_ip_vs_pe(struct ip_vs_pe *pe); | ||
1129 | struct ip_vs_pe *ip_vs_pe_getbyname(const char *name); | ||
1130 | struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name); | ||
1131 | |||
1132 | static inline void ip_vs_pe_get(const struct ip_vs_pe *pe) | ||
1133 | { | ||
1134 | if (pe && pe->module) | ||
1135 | __module_get(pe->module); | ||
1136 | } | ||
1137 | |||
1138 | static inline void ip_vs_pe_put(const struct ip_vs_pe *pe) | ||
1139 | { | ||
1140 | if (pe && pe->module) | ||
1141 | module_put(pe->module); | ||
1142 | } | ||
754 | 1143 | ||
755 | /* | 1144 | /* |
756 | * IPVS protocol functions (from ip_vs_proto.c) | 1145 | * IPVS protocol functions (from ip_vs_proto.c) |
757 | */ | 1146 | */ |
758 | extern int ip_vs_protocol_init(void); | 1147 | extern int ip_vs_protocol_init(void); |
759 | extern void ip_vs_protocol_cleanup(void); | 1148 | extern void ip_vs_protocol_cleanup(void); |
760 | extern void ip_vs_protocol_timeout_change(int flags); | 1149 | extern void ip_vs_protocol_timeout_change(struct netns_ipvs *ipvs, int flags); |
761 | extern int *ip_vs_create_timeout_table(int *table, int size); | 1150 | extern int *ip_vs_create_timeout_table(int *table, int size); |
762 | extern int | 1151 | extern int |
763 | ip_vs_set_state_timeout(int *table, int num, const char *const *names, | 1152 | ip_vs_set_state_timeout(int *table, int num, const char *const *names, |
764 | const char *name, int to); | 1153 | const char *name, int to); |
765 | extern void | 1154 | extern void |
766 | ip_vs_tcpudp_debug_packet(struct ip_vs_protocol *pp, const struct sk_buff *skb, | 1155 | ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp, |
1156 | const struct sk_buff *skb, | ||
767 | int offset, const char *msg); | 1157 | int offset, const char *msg); |
768 | 1158 | ||
769 | extern struct ip_vs_protocol ip_vs_protocol_tcp; | 1159 | extern struct ip_vs_protocol ip_vs_protocol_tcp; |
@@ -785,24 +1175,24 @@ extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc); | |||
785 | extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name); | 1175 | extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name); |
786 | extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler); | 1176 | extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler); |
787 | extern struct ip_vs_conn * | 1177 | extern struct ip_vs_conn * |
788 | ip_vs_schedule(struct ip_vs_service *svc, const struct sk_buff *skb); | 1178 | ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb, |
1179 | struct ip_vs_proto_data *pd, int *ignored); | ||
789 | extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb, | 1180 | extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb, |
790 | struct ip_vs_protocol *pp); | 1181 | struct ip_vs_proto_data *pd); |
1182 | |||
1183 | extern void ip_vs_scheduler_err(struct ip_vs_service *svc, const char *msg); | ||
791 | 1184 | ||
792 | 1185 | ||
793 | /* | 1186 | /* |
794 | * IPVS control data and functions (from ip_vs_ctl.c) | 1187 | * IPVS control data and functions (from ip_vs_ctl.c) |
795 | */ | 1188 | */ |
796 | extern int sysctl_ip_vs_cache_bypass; | ||
797 | extern int sysctl_ip_vs_expire_nodest_conn; | ||
798 | extern int sysctl_ip_vs_expire_quiescent_template; | ||
799 | extern int sysctl_ip_vs_sync_threshold[2]; | ||
800 | extern int sysctl_ip_vs_nat_icmp_send; | ||
801 | extern struct ip_vs_stats ip_vs_stats; | 1189 | extern struct ip_vs_stats ip_vs_stats; |
802 | extern const struct ctl_path net_vs_ctl_path[]; | 1190 | extern const struct ctl_path net_vs_ctl_path[]; |
1191 | extern int sysctl_ip_vs_sync_ver; | ||
803 | 1192 | ||
1193 | extern void ip_vs_sync_switch_mode(struct net *net, int mode); | ||
804 | extern struct ip_vs_service * | 1194 | extern struct ip_vs_service * |
805 | ip_vs_service_get(int af, __u32 fwmark, __u16 protocol, | 1195 | ip_vs_service_get(struct net *net, int af, __u32 fwmark, __u16 protocol, |
806 | const union nf_inet_addr *vaddr, __be16 vport); | 1196 | const union nf_inet_addr *vaddr, __be16 vport); |
807 | 1197 | ||
808 | static inline void ip_vs_service_put(struct ip_vs_service *svc) | 1198 | static inline void ip_vs_service_put(struct ip_vs_service *svc) |
@@ -811,7 +1201,7 @@ static inline void ip_vs_service_put(struct ip_vs_service *svc) | |||
811 | } | 1201 | } |
812 | 1202 | ||
813 | extern struct ip_vs_dest * | 1203 | extern struct ip_vs_dest * |
814 | ip_vs_lookup_real_service(int af, __u16 protocol, | 1204 | ip_vs_lookup_real_service(struct net *net, int af, __u16 protocol, |
815 | const union nf_inet_addr *daddr, __be16 dport); | 1205 | const union nf_inet_addr *daddr, __be16 dport); |
816 | 1206 | ||
817 | extern int ip_vs_use_count_inc(void); | 1207 | extern int ip_vs_use_count_inc(void); |
@@ -819,8 +1209,9 @@ extern void ip_vs_use_count_dec(void); | |||
819 | extern int ip_vs_control_init(void); | 1209 | extern int ip_vs_control_init(void); |
820 | extern void ip_vs_control_cleanup(void); | 1210 | extern void ip_vs_control_cleanup(void); |
821 | extern struct ip_vs_dest * | 1211 | extern struct ip_vs_dest * |
822 | ip_vs_find_dest(int af, const union nf_inet_addr *daddr, __be16 dport, | 1212 | ip_vs_find_dest(struct net *net, int af, const union nf_inet_addr *daddr, |
823 | const union nf_inet_addr *vaddr, __be16 vport, __u16 protocol); | 1213 | __be16 dport, const union nf_inet_addr *vaddr, __be16 vport, |
1214 | __u16 protocol, __u32 fwmark); | ||
824 | extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp); | 1215 | extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp); |
825 | 1216 | ||
826 | 1217 | ||
@@ -828,14 +1219,12 @@ extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp); | |||
828 | * IPVS sync daemon data and function prototypes | 1219 | * IPVS sync daemon data and function prototypes |
829 | * (from ip_vs_sync.c) | 1220 | * (from ip_vs_sync.c) |
830 | */ | 1221 | */ |
831 | extern volatile int ip_vs_sync_state; | 1222 | extern int start_sync_thread(struct net *net, int state, char *mcast_ifn, |
832 | extern volatile int ip_vs_master_syncid; | 1223 | __u8 syncid); |
833 | extern volatile int ip_vs_backup_syncid; | 1224 | extern int stop_sync_thread(struct net *net, int state); |
834 | extern char ip_vs_master_mcast_ifn[IP_VS_IFNAME_MAXLEN]; | 1225 | extern void ip_vs_sync_conn(struct net *net, struct ip_vs_conn *cp); |
835 | extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN]; | 1226 | extern int ip_vs_sync_init(void); |
836 | extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid); | 1227 | extern void ip_vs_sync_cleanup(void); |
837 | extern int stop_sync_thread(int state); | ||
838 | extern void ip_vs_sync_conn(struct ip_vs_conn *cp); | ||
839 | 1228 | ||
840 | 1229 | ||
841 | /* | 1230 | /* |
@@ -843,9 +1232,11 @@ extern void ip_vs_sync_conn(struct ip_vs_conn *cp); | |||
843 | */ | 1232 | */ |
844 | extern int ip_vs_estimator_init(void); | 1233 | extern int ip_vs_estimator_init(void); |
845 | extern void ip_vs_estimator_cleanup(void); | 1234 | extern void ip_vs_estimator_cleanup(void); |
846 | extern void ip_vs_new_estimator(struct ip_vs_stats *stats); | 1235 | extern void ip_vs_start_estimator(struct net *net, struct ip_vs_stats *stats); |
847 | extern void ip_vs_kill_estimator(struct ip_vs_stats *stats); | 1236 | extern void ip_vs_stop_estimator(struct net *net, struct ip_vs_stats *stats); |
848 | extern void ip_vs_zero_estimator(struct ip_vs_stats *stats); | 1237 | extern void ip_vs_zero_estimator(struct ip_vs_stats *stats); |
1238 | extern void ip_vs_read_estimator(struct ip_vs_stats_user *dst, | ||
1239 | struct ip_vs_stats *stats); | ||
849 | 1240 | ||
850 | /* | 1241 | /* |
851 | * Various IPVS packet transmitters (from ip_vs_xmit.c) | 1242 | * Various IPVS packet transmitters (from ip_vs_xmit.c) |
@@ -861,7 +1252,8 @@ extern int ip_vs_tunnel_xmit | |||
861 | extern int ip_vs_dr_xmit | 1252 | extern int ip_vs_dr_xmit |
862 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); | 1253 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
863 | extern int ip_vs_icmp_xmit | 1254 | extern int ip_vs_icmp_xmit |
864 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, int offset); | 1255 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, |
1256 | int offset, unsigned int hooknum); | ||
865 | extern void ip_vs_dst_reset(struct ip_vs_dest *dest); | 1257 | extern void ip_vs_dst_reset(struct ip_vs_dest *dest); |
866 | 1258 | ||
867 | #ifdef CONFIG_IP_VS_IPV6 | 1259 | #ifdef CONFIG_IP_VS_IPV6 |
@@ -875,24 +1267,28 @@ extern int ip_vs_dr_xmit_v6 | |||
875 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); | 1267 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
876 | extern int ip_vs_icmp_xmit_v6 | 1268 | extern int ip_vs_icmp_xmit_v6 |
877 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, | 1269 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, |
878 | int offset); | 1270 | int offset, unsigned int hooknum); |
879 | #endif | 1271 | #endif |
880 | 1272 | ||
1273 | #ifdef CONFIG_SYSCTL | ||
881 | /* | 1274 | /* |
882 | * This is a simple mechanism to ignore packets when | 1275 | * This is a simple mechanism to ignore packets when |
883 | * we are loaded. Just set ip_vs_drop_rate to 'n' and | 1276 | * we are loaded. Just set ip_vs_drop_rate to 'n' and |
884 | * we start to drop 1/rate of the packets | 1277 | * we start to drop 1/rate of the packets |
885 | */ | 1278 | */ |
886 | extern int ip_vs_drop_rate; | ||
887 | extern int ip_vs_drop_counter; | ||
888 | 1279 | ||
889 | static __inline__ int ip_vs_todrop(void) | 1280 | static inline int ip_vs_todrop(struct netns_ipvs *ipvs) |
890 | { | 1281 | { |
891 | if (!ip_vs_drop_rate) return 0; | 1282 | if (!ipvs->drop_rate) |
892 | if (--ip_vs_drop_counter > 0) return 0; | 1283 | return 0; |
893 | ip_vs_drop_counter = ip_vs_drop_rate; | 1284 | if (--ipvs->drop_counter > 0) |
1285 | return 0; | ||
1286 | ipvs->drop_counter = ipvs->drop_rate; | ||
894 | return 1; | 1287 | return 1; |
895 | } | 1288 | } |
1289 | #else | ||
1290 | static inline int ip_vs_todrop(struct netns_ipvs *ipvs) { return 0; } | ||
1291 | #endif | ||
896 | 1292 | ||
897 | /* | 1293 | /* |
898 | * ip_vs_fwd_tag returns the forwarding tag of the connection | 1294 | * ip_vs_fwd_tag returns the forwarding tag of the connection |
@@ -955,9 +1351,82 @@ static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum) | |||
955 | return csum_partial(diff, sizeof(diff), oldsum); | 1351 | return csum_partial(diff, sizeof(diff), oldsum); |
956 | } | 1352 | } |
957 | 1353 | ||
1354 | /* | ||
1355 | * Forget current conntrack (unconfirmed) and attach notrack entry | ||
1356 | */ | ||
1357 | static inline void ip_vs_notrack(struct sk_buff *skb) | ||
1358 | { | ||
1359 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) | ||
1360 | enum ip_conntrack_info ctinfo; | ||
1361 | struct nf_conn *ct = nf_ct_get(skb, &ctinfo); | ||
1362 | |||
1363 | if (!ct || !nf_ct_is_untracked(ct)) { | ||
1364 | nf_reset(skb); | ||
1365 | skb->nfct = &nf_ct_untracked_get()->ct_general; | ||
1366 | skb->nfctinfo = IP_CT_NEW; | ||
1367 | nf_conntrack_get(skb->nfct); | ||
1368 | } | ||
1369 | #endif | ||
1370 | } | ||
1371 | |||
1372 | #ifdef CONFIG_IP_VS_NFCT | ||
1373 | /* | ||
1374 | * Netfilter connection tracking | ||
1375 | * (from ip_vs_nfct.c) | ||
1376 | */ | ||
1377 | static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs) | ||
1378 | { | ||
1379 | #ifdef CONFIG_SYSCTL | ||
1380 | return ipvs->sysctl_conntrack; | ||
1381 | #else | ||
1382 | return 0; | ||
1383 | #endif | ||
1384 | } | ||
1385 | |||
958 | extern void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp, | 1386 | extern void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp, |
959 | int outin); | 1387 | int outin); |
1388 | extern int ip_vs_confirm_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp); | ||
1389 | extern void ip_vs_nfct_expect_related(struct sk_buff *skb, struct nf_conn *ct, | ||
1390 | struct ip_vs_conn *cp, u_int8_t proto, | ||
1391 | const __be16 port, int from_rs); | ||
1392 | extern void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp); | ||
1393 | |||
1394 | #else | ||
1395 | |||
1396 | static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs) | ||
1397 | { | ||
1398 | return 0; | ||
1399 | } | ||
960 | 1400 | ||
961 | #endif /* __KERNEL__ */ | 1401 | static inline void ip_vs_update_conntrack(struct sk_buff *skb, |
1402 | struct ip_vs_conn *cp, int outin) | ||
1403 | { | ||
1404 | } | ||
1405 | |||
1406 | static inline int ip_vs_confirm_conntrack(struct sk_buff *skb, | ||
1407 | struct ip_vs_conn *cp) | ||
1408 | { | ||
1409 | return NF_ACCEPT; | ||
1410 | } | ||
1411 | |||
1412 | static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp) | ||
1413 | { | ||
1414 | } | ||
1415 | /* CONFIG_IP_VS_NFCT */ | ||
1416 | #endif | ||
1417 | |||
1418 | static inline unsigned int | ||
1419 | ip_vs_dest_conn_overhead(struct ip_vs_dest *dest) | ||
1420 | { | ||
1421 | /* | ||
1422 | * We think the overhead of processing active connections is 256 | ||
1423 | * times higher than that of inactive connections in average. (This | ||
1424 | * 256 times might not be accurate, we will change it later) We | ||
1425 | * use the following formula to estimate the overhead now: | ||
1426 | * dest->activeconns*256 + dest->inactconns | ||
1427 | */ | ||
1428 | return (atomic_read(&dest->activeconns) << 8) + | ||
1429 | atomic_read(&dest->inactconns); | ||
1430 | } | ||
962 | 1431 | ||
963 | #endif /* _NET_IP_VS_H */ | 1432 | #endif /* _NET_IP_VS_H */ |