1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <linux/module.h>
25#include <linux/kernel.h>
26
27#include <net/ip_vs.h>
28
29
30static int
31ip_vs_wlc_init_svc(struct ip_vs_service *svc)
32{
33 return 0;
34}
35
36
37static int
38ip_vs_wlc_done_svc(struct ip_vs_service *svc)
39{
40 return 0;
41}
42
43
44static int
45ip_vs_wlc_update_svc(struct ip_vs_service *svc)
46{
47 return 0;
48}
49
50
51static inline unsigned int
52ip_vs_wlc_dest_overhead(struct ip_vs_dest *dest)
53{
54
55
56
57
58
59
60
61 return (atomic_read(&dest->activeconns) << 8) +
62 atomic_read(&dest->inactconns);
63}
64
65
66
67
68
69static struct ip_vs_dest *
70ip_vs_wlc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
71{
72 struct ip_vs_dest *dest, *least;
73 unsigned int loh, doh;
74
75 IP_VS_DBG(6, "ip_vs_wlc_schedule(): Scheduling...\n");
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90 list_for_each_entry(dest, &svc->destinations, n_list) {
91 if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) &&
92 atomic_read(&dest->weight) > 0) {
93 least = dest;
94 loh = ip_vs_wlc_dest_overhead(least);
95 goto nextstage;
96 }
97 }
98 return NULL;
99
100
101
102
103 nextstage:
104 list_for_each_entry_continue(dest, &svc->destinations, n_list) {
105 if (dest->flags & IP_VS_DEST_F_OVERLOAD)
106 continue;
107 doh = ip_vs_wlc_dest_overhead(dest);
108 if (loh * atomic_read(&dest->weight) >
109 doh * atomic_read(&least->weight)) {
110 least = dest;
111 loh = doh;
112 }
113 }
114
115 IP_VS_DBG(6, "WLC: server %u.%u.%u.%u:%u "
116 "activeconns %d refcnt %d weight %d overhead %d\n",
117 NIPQUAD(least->addr), ntohs(least->port),
118 atomic_read(&least->activeconns),
119 atomic_read(&least->refcnt),
120 atomic_read(&least->weight), loh);
121
122 return least;
123}
124
125
126static struct ip_vs_scheduler ip_vs_wlc_scheduler =
127{
128 .name = "wlc",
129 .refcnt = ATOMIC_INIT(0),
130 .module = THIS_MODULE,
131 .init_service = ip_vs_wlc_init_svc,
132 .done_service = ip_vs_wlc_done_svc,
133 .update_service = ip_vs_wlc_update_svc,
134 .schedule = ip_vs_wlc_schedule,
135};
136
137
138static int __init ip_vs_wlc_init(void)
139{
140 INIT_LIST_HEAD(&ip_vs_wlc_scheduler.n_list);
141 return register_ip_vs_scheduler(&ip_vs_wlc_scheduler);
142}
143
144static void __exit ip_vs_wlc_cleanup(void)
145{
146 unregister_ip_vs_scheduler(&ip_vs_wlc_scheduler);
147}
148
149module_init(ip_vs_wlc_init);
150module_exit(ip_vs_wlc_cleanup);
151MODULE_LICENSE("GPL");
152