udplite.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 <linux/proc_fs.h>
  16. #include "udp_impl.h"
  17. struct udp_table udplite_table __read_mostly;
  18. EXPORT_SYMBOL(udplite_table);
  19. static int udplite_rcv(struct sk_buff *skb)
  20. {
  21. return __udp4_lib_rcv(skb, &udplite_table, IPPROTO_UDPLITE);
  22. }
  23. static void udplite_err(struct sk_buff *skb, u32 info)
  24. {
  25. __udp4_lib_err(skb, info, &udplite_table);
  26. }
  27. static const struct net_protocol udplite_protocol = {
  28. .handler = udplite_rcv,
  29. .err_handler = udplite_err,
  30. .no_policy = 1,
  31. .netns_ok = 1,
  32. };
  33. struct proto udplite_prot = {
  34. .name = "UDP-Lite",
  35. .owner = THIS_MODULE,
  36. .close = udp_lib_close,
  37. .connect = ip4_datagram_connect,
  38. .disconnect = udp_disconnect,
  39. .ioctl = udp_ioctl,
  40. .init = udplite_sk_init,
  41. .destroy = udp_destroy_sock,
  42. .setsockopt = udp_setsockopt,
  43. .getsockopt = udp_getsockopt,
  44. .sendmsg = udp_sendmsg,
  45. .recvmsg = udp_recvmsg,
  46. .sendpage = udp_sendpage,
  47. .hash = udp_lib_hash,
  48. .unhash = udp_lib_unhash,
  49. .get_port = udp_v4_get_port,
  50. .memory_allocated = &udp_memory_allocated,
  51. .sysctl_mem = sysctl_udp_mem,
  52. .obj_size = sizeof(struct udp_sock),
  53. .h.udp_table = &udplite_table,
  54. #ifdef CONFIG_COMPAT
  55. .compat_setsockopt = compat_udp_setsockopt,
  56. .compat_getsockopt = compat_udp_getsockopt,
  57. #endif
  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. .flags = INET_PROTOSW_PERMANENT,
  66. };
  67. #ifdef CONFIG_PROC_FS
  68. static struct udp_seq_afinfo udplite4_seq_afinfo = {
  69. .family = AF_INET,
  70. .udp_table = &udplite_table,
  71. };
  72. static int __net_init udplite4_proc_init_net(struct net *net)
  73. {
  74. if (!proc_create_net_data("udplite", 0444, net->proc_net, &udp_seq_ops,
  75. sizeof(struct udp_iter_state), &udplite4_seq_afinfo))
  76. return -ENOMEM;
  77. return 0;
  78. }
  79. static void __net_exit udplite4_proc_exit_net(struct net *net)
  80. {
  81. remove_proc_entry("udplite", net->proc_net);
  82. }
  83. static struct pernet_operations udplite4_net_ops = {
  84. .init = udplite4_proc_init_net,
  85. .exit = udplite4_proc_exit_net,
  86. };
  87. static __init int udplite4_proc_init(void)
  88. {
  89. return register_pernet_subsys(&udplite4_net_ops);
  90. }
  91. #else
  92. static inline int udplite4_proc_init(void)
  93. {
  94. return 0;
  95. }
  96. #endif
  97. void __init udplite4_register(void)
  98. {
  99. udp_table_init(&udplite_table, "UDP-Lite");
  100. if (proto_register(&udplite_prot, 1))
  101. goto out_register_err;
  102. if (inet_add_protocol(&udplite_protocol, IPPROTO_UDPLITE) < 0)
  103. goto out_unregister_proto;
  104. inet_register_protosw(&udplite4_protosw);
  105. if (udplite4_proc_init())
  106. pr_err("%s: Cannot register /proc!\n", __func__);
  107. return;
  108. out_unregister_proto:
  109. proto_unregister(&udplite_prot);
  110. out_register_err:
  111. pr_crit("%s: Cannot add UDP-Lite protocol\n", __func__);
  112. }