Blame view

net/ipv6/protocol.c 1.56 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
  /*
   * INET		An implementation of the TCP/IP protocol suite for the LINUX
   *		operating system.  INET is implemented using the  BSD Socket
   *		interface as the means of communication with the user level.
   *
   *		PF_INET6 protocol dispatch tables.
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
   * Authors:	Pedro Roque	<roque@di.fc.ul.pt>
   *
   *		This program is free software; you can redistribute it and/or
   *		modify it under the terms of the GNU General Public License
   *		as published by the Free Software Foundation; either version
   *		2 of the License, or (at your option) any later version.
   */
  
  /*
   *      Changes:
   *
   *      Vince Laviano (vince@cs.stanford.edu)       16 May 2001
   *      - Removed unused variable 'inet6_protocol_base'
   *      - Modified inet6_del_protocol() to correctly maintain copy bit.
   */
fa1a9c681   Alexey Dobriyan   headers: net/ipv[...
23
  #include <linux/module.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24
  #include <linux/netdevice.h>
fa1a9c681   Alexey Dobriyan   headers: net/ipv[...
25
  #include <linux/spinlock.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26
  #include <net/protocol.h>
e0ad61ec8   Eric Dumazet   net: add __rcu an...
27
  const struct inet6_protocol __rcu *inet6_protos[MAX_INET_PROTOS] __read_mostly;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
28

41135cc83   Alexey Dobriyan   net: constify str...
29
  int inet6_add_protocol(const struct inet6_protocol *prot, unsigned char protocol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30
  {
e0386005f   Eric Dumazet   net: inet_add_pro...
31
  	int hash = protocol & (MAX_INET_PROTOS - 1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32

e0ad61ec8   Eric Dumazet   net: add __rcu an...
33
34
  	return !cmpxchg((const struct inet6_protocol **)&inet6_protos[hash],
  			NULL, prot) ? 0 : -1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35
  }
7159039a1   YOSHIFUJI Hideaki   [IPV6]: Decentral...
36
  EXPORT_SYMBOL(inet6_add_protocol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
38
39
  /*
   *	Remove a protocol from the hash tables.
   */
1ab1457c4   YOSHIFUJI Hideaki   [NET] IPV6: Fix w...
40

41135cc83   Alexey Dobriyan   net: constify str...
41
  int inet6_del_protocol(const struct inet6_protocol *prot, unsigned char protocol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
43
  {
  	int ret, hash = protocol & (MAX_INET_PROTOS - 1);
e0ad61ec8   Eric Dumazet   net: add __rcu an...
44
45
  	ret = (cmpxchg((const struct inet6_protocol **)&inet6_protos[hash],
  		       prot, NULL) == prot) ? 0 : -1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
48
49
50
  
  	synchronize_net();
  
  	return ret;
  }
7159039a1   YOSHIFUJI Hideaki   [IPV6]: Decentral...
51
  EXPORT_SYMBOL(inet6_del_protocol);