udplite.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * UDPLITE An implementation of the UDP-Lite protocol (RFC 3828).
  3. *
  4. * Authors: Gerrit Renker <gerrit@erg.abdn.ac.uk>
  5. *
  6. * Changes:
  7. * Fixes:
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the License, or (at your option) any later version.
  12. */
  13. #define pr_fmt(fmt) "UDPLite: " fmt
  14. #include <linux/export.h>
  15. #include "udp_impl.h"
  16. struct udp_table udplite_table __read_mostly;
  17. EXPORT_SYMBOL(udplite_table);
  18. static int udplite_rcv(struct sk_buff *skb)
  19. {
  20. return __udp4_lib_rcv(skb, &udplite_table, IPPROTO_UDPLITE);
  21. }
  22. static void udplite_err(struct sk_buff *skb, u32 info)
  23. {
  24. __udp4_lib_err(skb, info, &udplite_table);
  25. }
  26. static const struct net_protocol udplite_protocol = {
  27. .handler = udplite_rcv,
  28. .err_handler = udplite_err,
  29. .no_policy = 1,
  30. .netns_ok = 1,
  31. };
  32. struct proto udplite_prot = {
  33. .name = "UDP-Lite",
  34. .owner = THIS_MODULE,
  35. .close = udp_lib_close,
  36. .connect = ip4_datagram_connect,
  37. .disconnect = udp_disconnect,
  38. .ioctl = udp_ioctl,
  39. .init = udplite_sk_init,
  40. .destroy = udp_destroy_sock,
  41. .setsockopt = udp_setsockopt,
  42. .getsockopt = udp_getsockopt,
  43. .sendmsg = udp_sendmsg,
  44. .recvmsg = udp_recvmsg,
  45. .sendpage = udp_sendpage,
  46. .backlog_rcv = udp_queue_rcv_skb,
  47. .hash = udp_lib_hash,
  48. .unhash = udp_lib_unhash,
  49. .get_port = udp_v4_get_port,
  50. .obj_size = sizeof(struct udp_sock),
  51. .slab_flags = SLAB_DESTROY_BY_RCU,
  52. .h.udp_table = &udplite_table,
  53. #ifdef CONFIG_COMPAT
  54. .compat_setsockopt = compat_udp_setsockopt,
  55. .compat_getsockopt = compat_udp_getsockopt,
  56. #endif
  57. .clear_sk = sk_prot_clear_portaddr_nulls,
  58. };
  59. EXPORT_SYMBOL(udplite_prot);
  60. static struct inet_protosw udplite4_protosw = {
  61. .type = SOCK_DGRAM,
  62. .protocol = IPPROTO_UDPLITE,
  63. .prot = &udplite_prot,
  64. .ops = &inet_dgram_ops,
  65. .no_check = 0, /* must checksum (RFC 3828) */
  66. .flags = INET_PROTOSW_PERMANENT,
  67. };
  68. #ifdef CONFIG_PROC_FS
  69. static const struct file_operations udplite_afinfo_seq_fops = {
  70. .owner = THIS_MODULE,
  71. .open = udp_seq_open,
  72. .read = seq_read,
  73. .llseek = seq_lseek,
  74. .release = seq_release_net
  75. };
  76. static struct udp_seq_afinfo udplite4_seq_afinfo = {
  77. .name = "udplite",
  78. .family = AF_INET,
  79. .udp_table = &udplite_table,
  80. .seq_fops = &udplite_afinfo_seq_fops,
  81. .seq_ops = {
  82. .show = udp4_seq_show,
  83. },
  84. };
  85. static int __net_init udplite4_proc_init_net(struct net *net)
  86. {
  87. return udp_proc_register(net, &udplite4_seq_afinfo);
  88. }
  89. static void __net_exit udplite4_proc_exit_net(struct net *net)
  90. {
  91. udp_proc_unregister(net, &udplite4_seq_afinfo);
  92. }
  93. static struct pernet_operations udplite4_net_ops = {
  94. .init = udplite4_proc_init_net,
  95. .exit = udplite4_proc_exit_net,
  96. };
  97. static __init int udplite4_proc_init(void)
  98. {
  99. return register_pernet_subsys(&udplite4_net_ops);
  100. }
  101. #else
  102. static inline int udplite4_proc_init(void)
  103. {
  104. return 0;
  105. }
  106. #endif
  107. void __init udplite4_register(void)
  108. {
  109. udp_table_init(&udplite_table, "UDP-Lite");
  110. if (proto_register(&udplite_prot, 1))
  111. goto out_register_err;
  112. if (inet_add_protocol(&udplite_protocol, IPPROTO_UDPLITE) < 0)
  113. goto out_unregister_proto;
  114. inet_register_protosw(&udplite4_protosw);
  115. if (udplite4_proc_init())
  116. pr_err("%s: Cannot register /proc!\n", __func__);
  117. return;
  118. out_unregister_proto:
  119. proto_unregister(&udplite_prot);
  120. out_register_err:
  121. pr_crit("%s: Cannot add UDP-Lite protocol\n", __func__);
  122. }