Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/sparc-2.6
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / ipv4 / multipath.c
blob4e9ca7c76407da4d1ddfeb29ba5e80322effafda
1 /* multipath.c: IPV4 multipath algorithm support.
3 * Copyright (C) 2004, 2005 Einar Lueck <elueck@de.ibm.com>
4 * Copyright (C) 2005 David S. Miller <davem@davemloft.net>
5 */
7 #include <linux/module.h>
8 #include <linux/errno.h>
9 #include <linux/netdevice.h>
10 #include <linux/spinlock.h>
12 #include <net/ip_mp_alg.h>
14 static DEFINE_SPINLOCK(alg_table_lock);
15 struct ip_mp_alg_ops *ip_mp_alg_table[IP_MP_ALG_MAX + 1];
17 int multipath_alg_register(struct ip_mp_alg_ops *ops, enum ip_mp_alg n)
19 struct ip_mp_alg_ops **slot;
20 int err;
22 if (n < IP_MP_ALG_NONE || n > IP_MP_ALG_MAX ||
23 !ops->mp_alg_select_route)
24 return -EINVAL;
26 spin_lock(&alg_table_lock);
27 slot = &ip_mp_alg_table[n];
28 if (*slot != NULL) {
29 err = -EBUSY;
30 } else {
31 *slot = ops;
32 err = 0;
34 spin_unlock(&alg_table_lock);
36 return err;
38 EXPORT_SYMBOL(multipath_alg_register);
40 void multipath_alg_unregister(struct ip_mp_alg_ops *ops, enum ip_mp_alg n)
42 struct ip_mp_alg_ops **slot;
44 if (n < IP_MP_ALG_NONE || n > IP_MP_ALG_MAX)
45 return;
47 spin_lock(&alg_table_lock);
48 slot = &ip_mp_alg_table[n];
49 if (*slot == ops)
50 *slot = NULL;
51 spin_unlock(&alg_table_lock);
53 synchronize_net();
55 EXPORT_SYMBOL(multipath_alg_unregister);