udplite.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. #include "udp_impl.h"
  14. struct hlist_head udplite_hash[UDP_HTABLE_SIZE];
  15. static int udplite_rcv(struct sk_buff *skb)
  16. {
  17. return __udp4_lib_rcv(skb, udplite_hash, IPPROTO_UDPLITE);
  18. }
  19. static void udplite_err(struct sk_buff *skb, u32 info)
  20. {
  21. __udp4_lib_err(skb, info, udplite_hash);
  22. }
  23. static struct net_protocol udplite_protocol = {
  24. .handler = udplite_rcv,
  25. .err_handler = udplite_err,
  26. .no_policy = 1,
  27. .netns_ok = 1,
  28. };
  29. struct proto udplite_prot = {
  30. .name = "UDP-Lite",
  31. .owner = THIS_MODULE,
  32. .close = udp_lib_close,
  33. .connect = ip4_datagram_connect,
  34. .disconnect = udp_disconnect,
  35. .ioctl = udp_ioctl,
  36. .init = udplite_sk_init,
  37. .destroy = udp_destroy_sock,
  38. .setsockopt = udp_setsockopt,
  39. .getsockopt = udp_getsockopt,
  40. .sendmsg = udp_sendmsg,
  41. .recvmsg = udp_recvmsg,
  42. .sendpage = udp_sendpage,
  43. .backlog_rcv = udp_queue_rcv_skb,
  44. .hash = udp_lib_hash,
  45. .unhash = udp_lib_unhash,
  46. .get_port = udp_v4_get_port,
  47. .obj_size = sizeof(struct udp_sock),
  48. .h.udp_hash = udplite_hash,
  49. #ifdef CONFIG_COMPAT
  50. .compat_setsockopt = compat_udp_setsockopt,
  51. .compat_getsockopt = compat_udp_getsockopt,
  52. #endif
  53. };
  54. static struct inet_protosw udplite4_protosw = {
  55. .type = SOCK_DGRAM,
  56. .protocol = IPPROTO_UDPLITE,
  57. .prot = &udplite_prot,
  58. .ops = &inet_dgram_ops,
  59. .capability = -1,
  60. .no_check = 0, /* must checksum (RFC 3828) */
  61. .flags = INET_PROTOSW_PERMANENT,
  62. };
  63. #ifdef CONFIG_PROC_FS
  64. static struct udp_seq_afinfo udplite4_seq_afinfo = {
  65. .name = "udplite",
  66. .family = AF_INET,
  67. .hashtable = udplite_hash,
  68. .seq_fops = {
  69. .owner = THIS_MODULE,
  70. },
  71. .seq_ops = {
  72. .show = udp4_seq_show,
  73. },
  74. };
  75. static int udplite4_proc_init_net(struct net *net)
  76. {
  77. return udp_proc_register(net, &udplite4_seq_afinfo);
  78. }
  79. static void udplite4_proc_exit_net(struct net *net)
  80. {
  81. udp_proc_unregister(net, &udplite4_seq_afinfo);
  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. if (proto_register(&udplite_prot, 1))
  100. goto out_register_err;
  101. if (inet_add_protocol(&udplite_protocol, IPPROTO_UDPLITE) < 0)
  102. goto out_unregister_proto;
  103. inet_register_protosw(&udplite4_protosw);
  104. if (udplite4_proc_init())
  105. printk(KERN_ERR "%s: Cannot register /proc!\n", __func__);
  106. return;
  107. out_unregister_proto:
  108. proto_unregister(&udplite_prot);
  109. out_register_err:
  110. printk(KERN_CRIT "%s: Cannot add UDP-Lite protocol.\n", __func__);
  111. }
  112. EXPORT_SYMBOL(udplite_hash);
  113. EXPORT_SYMBOL(udplite_prot);