blob: b6cd2870478f9db2700e5a49839f07782ac758da [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Round robin policy for multipath.
3 *
4 *
5 * Version: $Id: multipath_rr.c,v 1.1.2.2 2004/09/16 07:42:34 elueck Exp $
6 *
7 * Authors: Einar Lueck <elueck@de.ibm.com><lkml@einar-lueck.de>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 */
14
15#include <linux/config.h>
16#include <asm/system.h>
17#include <asm/uaccess.h>
18#include <linux/types.h>
19#include <linux/sched.h>
20#include <linux/errno.h>
21#include <linux/timer.h>
22#include <linux/mm.h>
23#include <linux/kernel.h>
24#include <linux/fcntl.h>
25#include <linux/stat.h>
26#include <linux/socket.h>
27#include <linux/in.h>
28#include <linux/inet.h>
29#include <linux/netdevice.h>
30#include <linux/inetdevice.h>
31#include <linux/igmp.h>
32#include <linux/proc_fs.h>
33#include <linux/seq_file.h>
Randy Dunlap6efd8452005-06-13 14:29:06 -070034#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/mroute.h>
36#include <linux/init.h>
37#include <net/ip.h>
38#include <net/protocol.h>
39#include <linux/skbuff.h>
40#include <net/sock.h>
41#include <net/icmp.h>
42#include <net/udp.h>
43#include <net/raw.h>
44#include <linux/notifier.h>
45#include <linux/if_arp.h>
46#include <linux/netfilter_ipv4.h>
47#include <net/ipip.h>
48#include <net/checksum.h>
49#include <net/ip_mp_alg.h>
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051static void rr_select_route(const struct flowi *flp,
52 struct rtable *first, struct rtable **rp)
53{
54 struct rtable *nh, *result, *min_use_cand = NULL;
55 int min_use = -1;
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 /* 1. make sure all alt. nexthops have the same GC related data
58 * 2. determine the new candidate to be returned
59 */
60 result = NULL;
61 for (nh = rcu_dereference(first); nh;
62 nh = rcu_dereference(nh->u.rt_next)) {
63 if ((nh->u.dst.flags & DST_BALANCED) != 0 &&
64 multipath_comparekeys(&nh->fl, flp)) {
65 nh->u.dst.lastuse = jiffies;
66
67 if (min_use == -1 || nh->u.dst.__use < min_use) {
68 min_use = nh->u.dst.__use;
69 min_use_cand = nh;
70 }
71 }
72 }
73 result = min_use_cand;
74 if (!result)
75 result = first;
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 result->u.dst.__use++;
78 *rp = result;
79}
80
81static struct ip_mp_alg_ops rr_ops = {
82 .mp_alg_select_route = rr_select_route,
Linus Torvalds1da177e2005-04-16 15:20:36 -070083};
84
85static int __init rr_init(void)
86{
87 return multipath_alg_register(&rr_ops, IP_MP_ALG_RR);
88}
89
90static void __exit rr_exit(void)
91{
92 multipath_alg_unregister(&rr_ops, IP_MP_ALG_RR);
93}
94
95module_init(rr_init);
96module_exit(rr_exit);
Randy Dunlap6efd8452005-06-13 14:29:06 -070097MODULE_LICENSE("GPL");