protocol.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * INET An implementation of the TCP/IP protocol suite for the LINUX
  4. * operating system. INET is implemented using the BSD Socket
  5. * interface as the means of communication with the user level.
  6. *
  7. * PF_INET6 protocol dispatch tables.
  8. *
  9. * Authors: Pedro Roque <roque@di.fc.ul.pt>
  10. */
  11. /*
  12. * Changes:
  13. *
  14. * Vince Laviano (vince@cs.stanford.edu) 16 May 2001
  15. * - Removed unused variable 'inet6_protocol_base'
  16. * - Modified inet6_del_protocol() to correctly maintain copy bit.
  17. */
  18. #include <linux/module.h>
  19. #include <linux/netdevice.h>
  20. #include <linux/spinlock.h>
  21. #include <net/protocol.h>
  22. #if IS_ENABLED(CONFIG_IPV6)
  23. struct inet6_protocol __rcu *inet6_protos[MAX_INET_PROTOS] __read_mostly;
  24. EXPORT_SYMBOL(inet6_protos);
  25. int inet6_add_protocol(const struct inet6_protocol *prot, unsigned char protocol)
  26. {
  27. return !cmpxchg((const struct inet6_protocol **)&inet6_protos[protocol],
  28. NULL, prot) ? 0 : -1;
  29. }
  30. EXPORT_SYMBOL(inet6_add_protocol);
  31. int inet6_del_protocol(const struct inet6_protocol *prot, unsigned char protocol)
  32. {
  33. int ret;
  34. ret = (cmpxchg((const struct inet6_protocol **)&inet6_protos[protocol],
  35. prot, NULL) == prot) ? 0 : -1;
  36. synchronize_net();
  37. return ret;
  38. }
  39. EXPORT_SYMBOL(inet6_del_protocol);
  40. #endif
  41. const struct net_offload __rcu *inet6_offloads[MAX_INET_PROTOS] __read_mostly;
  42. EXPORT_SYMBOL(inet6_offloads);
  43. int inet6_add_offload(const struct net_offload *prot, unsigned char protocol)
  44. {
  45. return !cmpxchg((const struct net_offload **)&inet6_offloads[protocol],
  46. NULL, prot) ? 0 : -1;
  47. }
  48. EXPORT_SYMBOL(inet6_add_offload);
  49. int inet6_del_offload(const struct net_offload *prot, unsigned char protocol)
  50. {
  51. int ret;
  52. ret = (cmpxchg((const struct net_offload **)&inet6_offloads[protocol],
  53. prot, NULL) == prot) ? 0 : -1;
  54. synchronize_net();
  55. return ret;
  56. }
  57. EXPORT_SYMBOL(inet6_del_offload);