udplite.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * UDPLITEv6 An implementation of the UDP-Lite protocol over IPv6.
  4. * See also net/ipv4/udplite.c
  5. *
  6. * Authors: Gerrit Renker <gerrit@erg.abdn.ac.uk>
  7. *
  8. * Changes:
  9. * Fixes:
  10. */
  11. #define pr_fmt(fmt) "UDPLite6: " fmt
  12. #include <linux/export.h>
  13. #include <linux/proc_fs.h>
  14. #include "udp_impl.h"
  15. static int udplitev6_sk_init(struct sock *sk)
  16. {
  17. udpv6_init_sock(sk);
  18. pr_warn_once("UDP-Lite is deprecated and scheduled to be removed in 2025, "
  19. "please contact the netdev mailing list\n");
  20. return 0;
  21. }
  22. static int udplitev6_rcv(struct sk_buff *skb)
  23. {
  24. return __udp6_lib_rcv(skb, &udplite_table, IPPROTO_UDPLITE);
  25. }
  26. static int udplitev6_err(struct sk_buff *skb,
  27. struct inet6_skb_parm *opt,
  28. u8 type, u8 code, int offset, __be32 info)
  29. {
  30. return __udp6_lib_err(skb, opt, type, code, offset, info,
  31. &udplite_table);
  32. }
  33. static const struct inet6_protocol udplitev6_protocol = {
  34. .handler = udplitev6_rcv,
  35. .err_handler = udplitev6_err,
  36. .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
  37. };
  38. struct proto udplitev6_prot = {
  39. .name = "UDPLITEv6",
  40. .owner = THIS_MODULE,
  41. .close = udp_lib_close,
  42. .connect = ip6_datagram_connect,
  43. .disconnect = udp_disconnect,
  44. .ioctl = udp_ioctl,
  45. .init = udplitev6_sk_init,
  46. .destroy = udpv6_destroy_sock,
  47. .setsockopt = udpv6_setsockopt,
  48. .getsockopt = udpv6_getsockopt,
  49. .sendmsg = udpv6_sendmsg,
  50. .recvmsg = udpv6_recvmsg,
  51. .hash = udp_lib_hash,
  52. .unhash = udp_lib_unhash,
  53. .rehash = udp_v6_rehash,
  54. .get_port = udp_v6_get_port,
  55. .memory_allocated = &udp_memory_allocated,
  56. .per_cpu_fw_alloc = &udp_memory_per_cpu_fw_alloc,
  57. .sysctl_mem = sysctl_udp_mem,
  58. .sysctl_wmem_offset = offsetof(struct net, ipv4.sysctl_udp_wmem_min),
  59. .sysctl_rmem_offset = offsetof(struct net, ipv4.sysctl_udp_rmem_min),
  60. .obj_size = sizeof(struct udp6_sock),
  61. .ipv6_pinfo_offset = offsetof(struct udp6_sock, inet6),
  62. .h.udp_table = &udplite_table,
  63. };
  64. static struct inet_protosw udplite6_protosw = {
  65. .type = SOCK_DGRAM,
  66. .protocol = IPPROTO_UDPLITE,
  67. .prot = &udplitev6_prot,
  68. .ops = &inet6_dgram_ops,
  69. .flags = INET_PROTOSW_PERMANENT,
  70. };
  71. int __init udplitev6_init(void)
  72. {
  73. int ret;
  74. ret = inet6_add_protocol(&udplitev6_protocol, IPPROTO_UDPLITE);
  75. if (ret)
  76. goto out;
  77. ret = inet6_register_protosw(&udplite6_protosw);
  78. if (ret)
  79. goto out_udplitev6_protocol;
  80. out:
  81. return ret;
  82. out_udplitev6_protocol:
  83. inet6_del_protocol(&udplitev6_protocol, IPPROTO_UDPLITE);
  84. goto out;
  85. }
  86. void udplitev6_exit(void)
  87. {
  88. inet6_unregister_protosw(&udplite6_protosw);
  89. inet6_del_protocol(&udplitev6_protocol, IPPROTO_UDPLITE);
  90. }
  91. #ifdef CONFIG_PROC_FS
  92. static struct udp_seq_afinfo udplite6_seq_afinfo = {
  93. .family = AF_INET6,
  94. .udp_table = &udplite_table,
  95. };
  96. static int __net_init udplite6_proc_init_net(struct net *net)
  97. {
  98. if (!proc_create_net_data("udplite6", 0444, net->proc_net,
  99. &udp6_seq_ops, sizeof(struct udp_iter_state),
  100. &udplite6_seq_afinfo))
  101. return -ENOMEM;
  102. return 0;
  103. }
  104. static void __net_exit udplite6_proc_exit_net(struct net *net)
  105. {
  106. remove_proc_entry("udplite6", net->proc_net);
  107. }
  108. static struct pernet_operations udplite6_net_ops = {
  109. .init = udplite6_proc_init_net,
  110. .exit = udplite6_proc_exit_net,
  111. };
  112. int __init udplite6_proc_init(void)
  113. {
  114. return register_pernet_subsys(&udplite6_net_ops);
  115. }
  116. void udplite6_proc_exit(void)
  117. {
  118. unregister_pernet_subsys(&udplite6_net_ops);
  119. }
  120. #endif