Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * INET     An implementation of the TCP/IP protocol suite for the LINUX
0004  *      operating system.  INET is implemented using the  BSD Socket
0005  *      interface as the means of communication with the user level.
0006  *
0007  *      INET protocol dispatch tables.
0008  *
0009  * Authors: Ross Biro
0010  *      Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
0011  *
0012  * Fixes:
0013  *      Alan Cox    : Ahah! udp icmp errors don't work because
0014  *                udp_err is never called!
0015  *      Alan Cox    : Added new fields for init and ready for
0016  *                proper fragmentation (_NO_ 4K limits!)
0017  *      Richard Colella : Hang on hash collision
0018  *      Vince Laviano   : Modified inet_del_protocol() to correctly
0019  *                maintain copy bit.
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);