Blame view

net/ipv4/protocol.c 1.76 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.
   *
   *		INET protocol dispatch tables.
   *
02c30a84e   Jesper Juhl   [PATCH] update Ro...
8
   * Authors:	Ross Biro
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
   *		Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
   *
   * Fixes:
   *		Alan Cox	: Ahah! udp icmp errors don't work because
   *				  udp_err is never called!
   *		Alan Cox	: Added new fields for init and ready for
   *				  proper fragmentation (_NO_ 4K limits!)
   *		Richard Colella	: Hang on hash collision
   *		Vince Laviano	: Modified inet_del_protocol() to correctly
   *				  maintain copy bit.
   *
   *		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.
   */
fa1a9c681   Alexey Dobriyan   headers: net/ipv[...
25
  #include <linux/cache.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26
  #include <linux/module.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
27
  #include <linux/netdevice.h>
fa1a9c681   Alexey Dobriyan   headers: net/ipv[...
28
  #include <linux/spinlock.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
  #include <net/protocol.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30

e0ad61ec8   Eric Dumazet   net: add __rcu an...
31
  const struct net_protocol __rcu *inet_protos[MAX_INET_PROTOS] __read_mostly;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32
33
34
35
  
  /*
   *	Add a protocol handler to the hash tables
   */
32613090a   Alexey Dobriyan   net: constify str...
36
  int inet_add_protocol(const struct net_protocol *prot, unsigned char protocol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
  {
e0386005f   Eric Dumazet   net: inet_add_pro...
38
  	int hash = protocol & (MAX_INET_PROTOS - 1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
39

e0ad61ec8   Eric Dumazet   net: add __rcu an...
40
41
  	return !cmpxchg((const struct net_protocol **)&inet_protos[hash],
  			NULL, prot) ? 0 : -1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
  }
4bc2f18ba   Eric Dumazet   net/ipv4: EXPORT_...
43
  EXPORT_SYMBOL(inet_add_protocol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
45
46
47
  
  /*
   *	Remove a protocol from the hash tables.
   */
e905a9eda   YOSHIFUJI Hideaki   [NET] IPV4: Fix w...
48

32613090a   Alexey Dobriyan   net: constify str...
49
  int inet_del_protocol(const struct net_protocol *prot, unsigned char protocol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50
  {
e0386005f   Eric Dumazet   net: inet_add_pro...
51
  	int ret, hash = protocol & (MAX_INET_PROTOS - 1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
52

e0ad61ec8   Eric Dumazet   net: add __rcu an...
53
54
  	ret = (cmpxchg((const struct net_protocol **)&inet_protos[hash],
  		       prot, NULL) == prot) ? 0 : -1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55
56
57
58
59
  
  	synchronize_net();
  
  	return ret;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
60
  EXPORT_SYMBOL(inet_del_protocol);