diff options
Diffstat (limited to 'net/ipv6/protocol.c')
| -rw-r--r-- | net/ipv6/protocol.c | 76 |
1 files changed, 30 insertions, 46 deletions
diff --git a/net/ipv6/protocol.c b/net/ipv6/protocol.c index f929f47b925..e048cf1bb6a 100644 --- a/net/ipv6/protocol.c +++ b/net/ipv6/protocol.c @@ -5,8 +5,6 @@ * * PF_INET6 protocol dispatch tables. * - * Version: $Id: protocol.c,v 1.10 2001/05/18 02:25:49 davem Exp $ - * * Authors: Pedro Roque <roque@di.fc.ul.pt> * * This program is free software; you can redistribute it and/or @@ -22,68 +20,54 @@ * - Removed unused variable 'inet6_protocol_base' * - Modified inet6_del_protocol() to correctly maintain copy bit. */ - -#include <linux/errno.h> -#include <linux/types.h> -#include <linux/socket.h> -#include <linux/sockios.h> -#include <linux/net.h> -#include <linux/in6.h> +#include <linux/module.h> #include <linux/netdevice.h> -#include <linux/if_arp.h> - -#include <net/sock.h> -#include <net/snmp.h> - -#include <net/ipv6.h> +#include <linux/spinlock.h> #include <net/protocol.h> -struct inet6_protocol *inet6_protos[MAX_INET_PROTOS]; -static DEFINE_SPINLOCK(inet6_proto_lock); - +#if IS_ENABLED(CONFIG_IPV6) +const struct inet6_protocol __rcu *inet6_protos[MAX_INET_PROTOS] __read_mostly; +EXPORT_SYMBOL(inet6_protos); -int inet6_add_protocol(struct inet6_protocol *prot, unsigned char protocol) +int inet6_add_protocol(const struct inet6_protocol *prot, unsigned char protocol) { - int ret, hash = protocol & (MAX_INET_PROTOS - 1); + return !cmpxchg((const struct inet6_protocol **)&inet6_protos[protocol], + NULL, prot) ? 0 : -1; +} +EXPORT_SYMBOL(inet6_add_protocol); - spin_lock_bh(&inet6_proto_lock); +int inet6_del_protocol(const struct inet6_protocol *prot, unsigned char protocol) +{ + int ret; - if (inet6_protos[hash]) { - ret = -1; - } else { - inet6_protos[hash] = prot; - ret = 0; - } + ret = (cmpxchg((const struct inet6_protocol **)&inet6_protos[protocol], + prot, NULL) == prot) ? 0 : -1; - spin_unlock_bh(&inet6_proto_lock); + synchronize_net(); return ret; } +EXPORT_SYMBOL(inet6_del_protocol); +#endif -EXPORT_SYMBOL(inet6_add_protocol); - -/* - * Remove a protocol from the hash tables. - */ +const struct net_offload __rcu *inet6_offloads[MAX_INET_PROTOS] __read_mostly; -int inet6_del_protocol(struct inet6_protocol *prot, unsigned char protocol) +int inet6_add_offload(const struct net_offload *prot, unsigned char protocol) { - int ret, hash = protocol & (MAX_INET_PROTOS - 1); - - spin_lock_bh(&inet6_proto_lock); + return !cmpxchg((const struct net_offload **)&inet6_offloads[protocol], + NULL, prot) ? 0 : -1; +} +EXPORT_SYMBOL(inet6_add_offload); - if (inet6_protos[hash] != prot) { - ret = -1; - } else { - inet6_protos[hash] = NULL; - ret = 0; - } +int inet6_del_offload(const struct net_offload *prot, unsigned char protocol) +{ + int ret; - spin_unlock_bh(&inet6_proto_lock); + ret = (cmpxchg((const struct net_offload **)&inet6_offloads[protocol], + prot, NULL) == prot) ? 0 : -1; synchronize_net(); return ret; } - -EXPORT_SYMBOL(inet6_del_protocol); +EXPORT_SYMBOL(inet6_del_offload); |
