0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include <linux/cache.h>
0022 #include <linux/module.h>
0023 #include <linux/netdevice.h>
0024 #include <linux/spinlock.h>
0025 #include <net/protocol.h>
0026
0027 struct net_protocol __rcu *inet_protos[MAX_INET_PROTOS] __read_mostly;
0028 EXPORT_SYMBOL(inet_protos);
0029 const struct net_offload __rcu *inet_offloads[MAX_INET_PROTOS] __read_mostly;
0030 EXPORT_SYMBOL(inet_offloads);
0031
0032 int inet_add_protocol(const struct net_protocol *prot, unsigned char protocol)
0033 {
0034 return !cmpxchg((const struct net_protocol **)&inet_protos[protocol],
0035 NULL, prot) ? 0 : -1;
0036 }
0037 EXPORT_SYMBOL(inet_add_protocol);
0038
0039 int inet_add_offload(const struct net_offload *prot, unsigned char protocol)
0040 {
0041 return !cmpxchg((const struct net_offload **)&inet_offloads[protocol],
0042 NULL, prot) ? 0 : -1;
0043 }
0044 EXPORT_SYMBOL(inet_add_offload);
0045
0046 int inet_del_protocol(const struct net_protocol *prot, unsigned char protocol)
0047 {
0048 int ret;
0049
0050 ret = (cmpxchg((const struct net_protocol **)&inet_protos[protocol],
0051 prot, NULL) == prot) ? 0 : -1;
0052
0053 synchronize_net();
0054
0055 return ret;
0056 }
0057 EXPORT_SYMBOL(inet_del_protocol);
0058
0059 int inet_del_offload(const struct net_offload *prot, unsigned char protocol)
0060 {
0061 int ret;
0062
0063 ret = (cmpxchg((const struct net_offload **)&inet_offloads[protocol],
0064 prot, NULL) == prot) ? 0 : -1;
0065
0066 synchronize_net();
0067
0068 return ret;
0069 }
0070 EXPORT_SYMBOL(inet_del_offload);