File Index
Files and directories
Sign in
FILE

ip_vs_fo.c

File preview with syntax highlighting.

linux-6.19.14/net/netfilter/ipvs/ip_vs_fo.c C
 1// SPDX-License-Identifier: GPL-2.0-or-later
 2/*
 3 * IPVS:        Weighted Fail Over module
 4 *
 5 * Authors:     Kenny Mathis <kmathis@chokepoint.net>
 6 *
 7 * Changes:
 8 *     Kenny Mathis            :     added initial functionality based on weight
 9 */
10
11#define pr_fmt(fmt) "IPVS: " fmt
12
13#include <linux/module.h>
14#include <linux/kernel.h>
15
16#include <net/ip_vs.h>
17
18/* Weighted Fail Over Module */
19static struct ip_vs_dest *
20ip_vs_fo_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
21		  struct ip_vs_iphdr *iph)
22{
23	struct ip_vs_dest *dest, *hweight = NULL;
24	int hw = 0; /* Track highest weight */
25
26	IP_VS_DBG(6, "ip_vs_fo_schedule(): Scheduling...\n");
27
28	/* Basic failover functionality
29	 * Find virtual server with highest weight and send it traffic
30	 */
31	list_for_each_entry_rcu(dest, &svc->destinations, n_list) {
32		if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) &&
33		    atomic_read(&dest->weight) > hw) {
34			hweight = dest;
35			hw = atomic_read(&dest->weight);
36		}
37	}
38
39	if (hweight) {
40		IP_VS_DBG_BUF(6, "FO: server %s:%u activeconns %d weight %d\n",
41			      IP_VS_DBG_ADDR(hweight->af, &hweight->addr),
42			      ntohs(hweight->port),
43			      atomic_read(&hweight->activeconns),
44			      atomic_read(&hweight->weight));
45		return hweight;
46	}
47
48	ip_vs_scheduler_err(svc, "no destination available");
49	return NULL;
50}
51
52static struct ip_vs_scheduler ip_vs_fo_scheduler = {
53	.name =			"fo",
54	.refcnt =		ATOMIC_INIT(0),
55	.module =		THIS_MODULE,
56	.n_list =		LIST_HEAD_INIT(ip_vs_fo_scheduler.n_list),
57	.schedule =		ip_vs_fo_schedule,
58};
59
60static int __init ip_vs_fo_init(void)
61{
62	return register_ip_vs_scheduler(&ip_vs_fo_scheduler);
63}
64
65static void __exit ip_vs_fo_cleanup(void)
66{
67	unregister_ip_vs_scheduler(&ip_vs_fo_scheduler);
68	synchronize_rcu();
69}
70
71module_init(ip_vs_fo_init);
72module_exit(ip_vs_fo_cleanup);
73MODULE_LICENSE("GPL");
74MODULE_DESCRIPTION("ipvs weighted failover scheduler");
~/ Read-only file preview.