1/* multipath.c: IPV4 multipath algorithm support. 2 * 3 * Copyright (C) 2004, 2005 Einar Lueck <elueck@de.ibm.com> 4 * Copyright (C) 2005 David S. Miller <davem@davemloft.net> 5 */ 6 7#include <linux/module.h> 8#include <linux/errno.h> 9#include <linux/netdevice.h> 10#include <linux/spinlock.h> 11 12#include <net/ip_mp_alg.h> 13 14static DEFINE_SPINLOCK(alg_table_lock); 15struct ip_mp_alg_ops *ip_mp_alg_table[IP_MP_ALG_MAX + 1]; 16 17int multipath_alg_register(struct ip_mp_alg_ops *ops, enum ip_mp_alg n) 18{ 19 struct ip_mp_alg_ops **slot; 20 int err; 21 22 if (n < IP_MP_ALG_NONE || n > IP_MP_ALG_MAX || 23 !ops->mp_alg_select_route) 24 return -EINVAL; 25 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; 33 } 34 spin_unlock(&alg_table_lock); 35 36 return err; 37} 38EXPORT_SYMBOL(multipath_alg_register); 39 40void multipath_alg_unregister(struct ip_mp_alg_ops *ops, enum ip_mp_alg n) 41{ 42 struct ip_mp_alg_ops **slot; 43 44 if (n < IP_MP_ALG_NONE || n > IP_MP_ALG_MAX) 45 return; 46 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); 52 53 synchronize_net(); 54} 55EXPORT_SYMBOL(multipath_alg_unregister); 56