aboutsummaryrefslogtreecommitdiff
path: root/net/ipv6/protocol.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv6/protocol.c')
-rw-r--r--net/ipv6/protocol.c57
1 files changed, 27 insertions, 30 deletions
diff --git a/net/ipv6/protocol.c b/net/ipv6/protocol.c
index 1fa3468f0f3..e048cf1bb6a 100644
--- a/net/ipv6/protocol.c
+++ b/net/ipv6/protocol.c
@@ -25,52 +25,49 @@
#include <linux/spinlock.h>
#include <net/protocol.h>
-const 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(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);
+const struct net_offload __rcu *inet6_offloads[MAX_INET_PROTOS] __read_mostly;
-/*
- * Remove a protocol from the hash tables.
- */
-
-int inet6_del_protocol(const 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);