• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Based on net/ipv6/protocol.c
4  * Authors:	Pedro Roque	<roque@di.fc.ul.pt>
5  *
6  *      Changes:
7  *
8  *      Vince Laviano (vince@cs.stanford.edu)       16 May 2001
9  *      - Removed unused variable 'inet6_protocol_base'
10  *      - Modified inet6_del_protocol() to correctly maintain copy bit.
11  *
12  * NewIP INET An implementation of the TCP/IP protocol suite for the LINUX
13  * operating system. NewIP INET is implemented using the  BSD Socket
14  * interface as the means of communication with the user level.
15  *
16  * NewIP INET protocol dispatch tables.
17  */
18 #define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__
19 
20 #include <net/protocol.h>
21 #include <linux/module.h>
22 #include <linux/netdevice.h>
23 #include <linux/spinlock.h>
24 #include "tcp_nip_parameter.h"
25 
26 const struct ninet_protocol __rcu *ninet_protos[MAX_INET_PROTOS] __read_mostly;
27 
ninet_add_protocol(const struct ninet_protocol * prot,unsigned char protocol)28 int ninet_add_protocol(const struct ninet_protocol *prot,
29 		       unsigned char protocol)
30 {
31 	return !cmpxchg((const struct ninet_protocol **)&ninet_protos[protocol],
32 			NULL, prot) ? 0 : -1;
33 }
34 
ninet_del_protocol(const struct ninet_protocol * prot,unsigned char protocol)35 int ninet_del_protocol(const struct ninet_protocol *prot,
36 		       unsigned char protocol)
37 {
38 	int ret;
39 
40 	ret = (cmpxchg((const struct ninet_protocol **)&ninet_protos[protocol],
41 		       prot, NULL) == prot) ? 0 : -1;
42 
43 	synchronize_net();
44 
45 	return ret;
46 }
47 
48