| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 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 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <asm/system.h> | 
|  | 16 | #include <asm/uaccess.h> | 
|  | 17 | #include <linux/types.h> | 
|  | 18 | #include <linux/sched.h> | 
|  | 19 | #include <linux/errno.h> | 
|  | 20 | #include <linux/timer.h> | 
|  | 21 | #include <linux/mm.h> | 
|  | 22 | #include <linux/kernel.h> | 
|  | 23 | #include <linux/fcntl.h> | 
|  | 24 | #include <linux/stat.h> | 
|  | 25 | #include <linux/socket.h> | 
|  | 26 | #include <linux/in.h> | 
|  | 27 | #include <linux/inet.h> | 
|  | 28 | #include <linux/netdevice.h> | 
|  | 29 | #include <linux/inetdevice.h> | 
|  | 30 | #include <linux/igmp.h> | 
|  | 31 | #include <linux/proc_fs.h> | 
|  | 32 | #include <linux/seq_file.h> | 
| Randy Dunlap | 6efd845 | 2005-06-13 14:29:06 -0700 | [diff] [blame] | 33 | #include <linux/module.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/mroute.h> | 
|  | 35 | #include <linux/init.h> | 
|  | 36 | #include <net/ip.h> | 
|  | 37 | #include <net/protocol.h> | 
|  | 38 | #include <linux/skbuff.h> | 
|  | 39 | #include <net/sock.h> | 
|  | 40 | #include <net/icmp.h> | 
|  | 41 | #include <net/udp.h> | 
|  | 42 | #include <net/raw.h> | 
|  | 43 | #include <linux/notifier.h> | 
|  | 44 | #include <linux/if_arp.h> | 
|  | 45 | #include <linux/netfilter_ipv4.h> | 
|  | 46 | #include <net/ipip.h> | 
|  | 47 | #include <net/checksum.h> | 
|  | 48 | #include <net/ip_mp_alg.h> | 
|  | 49 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | static void rr_select_route(const struct flowi *flp, | 
|  | 51 | struct rtable *first, struct rtable **rp) | 
|  | 52 | { | 
|  | 53 | struct rtable *nh, *result, *min_use_cand = NULL; | 
|  | 54 | int min_use = -1; | 
|  | 55 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | /* 1. make sure all alt. nexthops have the same GC related data | 
|  | 57 | * 2. determine the new candidate to be returned | 
|  | 58 | */ | 
|  | 59 | result = NULL; | 
|  | 60 | for (nh = rcu_dereference(first); nh; | 
|  | 61 | nh = rcu_dereference(nh->u.rt_next)) { | 
|  | 62 | if ((nh->u.dst.flags & DST_BALANCED) != 0 && | 
|  | 63 | multipath_comparekeys(&nh->fl, flp)) { | 
|  | 64 | nh->u.dst.lastuse = jiffies; | 
|  | 65 |  | 
|  | 66 | if (min_use == -1 || nh->u.dst.__use < min_use) { | 
|  | 67 | min_use = nh->u.dst.__use; | 
|  | 68 | min_use_cand = nh; | 
|  | 69 | } | 
|  | 70 | } | 
|  | 71 | } | 
|  | 72 | result = min_use_cand; | 
|  | 73 | if (!result) | 
|  | 74 | result = first; | 
|  | 75 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | result->u.dst.__use++; | 
|  | 77 | *rp = result; | 
|  | 78 | } | 
|  | 79 |  | 
|  | 80 | static struct ip_mp_alg_ops rr_ops = { | 
|  | 81 | .mp_alg_select_route	=	rr_select_route, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | }; | 
|  | 83 |  | 
|  | 84 | static int __init rr_init(void) | 
|  | 85 | { | 
|  | 86 | return multipath_alg_register(&rr_ops, IP_MP_ALG_RR); | 
|  | 87 | } | 
|  | 88 |  | 
|  | 89 | static void __exit rr_exit(void) | 
|  | 90 | { | 
|  | 91 | multipath_alg_unregister(&rr_ops, IP_MP_ALG_RR); | 
|  | 92 | } | 
|  | 93 |  | 
|  | 94 | module_init(rr_init); | 
|  | 95 | module_exit(rr_exit); | 
| Randy Dunlap | 6efd845 | 2005-06-13 14:29:06 -0700 | [diff] [blame] | 96 | MODULE_LICENSE("GPL"); |