protocol.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * INET An implementation of the TCP/IP protocol suite for the LINUX
  3. * operating system. INET is implemented using the BSD Socket
  4. * interface as the means of communication with the user level.
  5. *
  6. * PF_INET6 protocol dispatch tables.
  7. *
  8. * Authors: Pedro Roque <roque@di.fc.ul.pt>
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version
  13. * 2 of the License, or (at your option) any later version.
  14. */
  15. /*
  16. * Changes:
  17. *
  18. * Vince Laviano (vince@cs.stanford.edu) 16 May 2001
  19. * - Removed unused variable 'inet6_protocol_base'
  20. * - Modified inet6_del_protocol() to correctly maintain copy bit.
  21. */
  22. #include <linux/errno.h>
  23. #include <linux/types.h>
  24. #include <linux/socket.h>
  25. #include <linux/sockios.h>
  26. #include <linux/net.h>
  27. #include <linux/in6.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/if_arp.h>
  30. #include <net/sock.h>
  31. #include <net/snmp.h>
  32. #include <net/ipv6.h>
  33. #include <net/protocol.h>
  34. struct inet6_protocol *inet6_protos[MAX_INET_PROTOS];
  35. static DEFINE_SPINLOCK(inet6_proto_lock);
  36. int inet6_add_protocol(struct inet6_protocol *prot, unsigned char protocol)
  37. {
  38. int ret, hash = protocol & (MAX_INET_PROTOS - 1);
  39. spin_lock_bh(&inet6_proto_lock);
  40. if (inet6_protos[hash]) {
  41. ret = -1;
  42. } else {
  43. inet6_protos[hash] = prot;
  44. ret = 0;
  45. }
  46. spin_unlock_bh(&inet6_proto_lock);
  47. return ret;
  48. }
  49. EXPORT_SYMBOL(inet6_add_protocol);
  50. /*
  51. * Remove a protocol from the hash tables.
  52. */
  53. int inet6_del_protocol(struct inet6_protocol *prot, unsigned char protocol)
  54. {
  55. int ret, hash = protocol & (MAX_INET_PROTOS - 1);
  56. spin_lock_bh(&inet6_proto_lock);
  57. if (inet6_protos[hash] != prot) {
  58. ret = -1;
  59. } else {
  60. inet6_protos[hash] = NULL;
  61. ret = 0;
  62. }
  63. spin_unlock_bh(&inet6_proto_lock);
  64. synchronize_net();
  65. return ret;
  66. }
  67. EXPORT_SYMBOL(inet6_del_protocol);