udplite.c 3.4 KB

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