udplite.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * UDPLITEv6 An implementation of the UDP-Lite protocol over IPv6.
  3. * See also net/ipv4/udplite.c
  4. *
  5. * Authors: Gerrit Renker <gerrit@erg.abdn.ac.uk>
  6. *
  7. * Changes:
  8. * Fixes:
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the License, or (at your option) any later version.
  13. */
  14. #include <linux/export.h>
  15. #include "udp_impl.h"
  16. static int udplitev6_rcv(struct sk_buff *skb)
  17. {
  18. return __udp6_lib_rcv(skb, &udplite_table, IPPROTO_UDPLITE);
  19. }
  20. static void udplitev6_err(struct sk_buff *skb,
  21. struct inet6_skb_parm *opt,
  22. u8 type, u8 code, int offset, __be32 info)
  23. {
  24. __udp6_lib_err(skb, opt, type, code, offset, info, &udplite_table);
  25. }
  26. static const struct inet6_protocol udplitev6_protocol = {
  27. .handler = udplitev6_rcv,
  28. .err_handler = udplitev6_err,
  29. .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
  30. };
  31. struct proto udplitev6_prot = {
  32. .name = "UDPLITEv6",
  33. .owner = THIS_MODULE,
  34. .close = udp_lib_close,
  35. .connect = ip6_datagram_connect,
  36. .disconnect = udp_disconnect,
  37. .ioctl = udp_ioctl,
  38. .init = udplite_sk_init,
  39. .destroy = udpv6_destroy_sock,
  40. .setsockopt = udpv6_setsockopt,
  41. .getsockopt = udpv6_getsockopt,
  42. .sendmsg = udpv6_sendmsg,
  43. .recvmsg = udpv6_recvmsg,
  44. .backlog_rcv = udpv6_queue_rcv_skb,
  45. .hash = udp_lib_hash,
  46. .unhash = udp_lib_unhash,
  47. .get_port = udp_v6_get_port,
  48. .obj_size = sizeof(struct udp6_sock),
  49. .slab_flags = SLAB_DESTROY_BY_RCU,
  50. .h.udp_table = &udplite_table,
  51. #ifdef CONFIG_COMPAT
  52. .compat_setsockopt = compat_udpv6_setsockopt,
  53. .compat_getsockopt = compat_udpv6_getsockopt,
  54. #endif
  55. .clear_sk = udp_v6_clear_sk,
  56. };
  57. static struct inet_protosw udplite6_protosw = {
  58. .type = SOCK_DGRAM,
  59. .protocol = IPPROTO_UDPLITE,
  60. .prot = &udplitev6_prot,
  61. .ops = &inet6_dgram_ops,
  62. .no_check = 0,
  63. .flags = INET_PROTOSW_PERMANENT,
  64. };
  65. int __init udplitev6_init(void)
  66. {
  67. int ret;
  68. ret = inet6_add_protocol(&udplitev6_protocol, IPPROTO_UDPLITE);
  69. if (ret)
  70. goto out;
  71. ret = inet6_register_protosw(&udplite6_protosw);
  72. if (ret)
  73. goto out_udplitev6_protocol;
  74. out:
  75. return ret;
  76. out_udplitev6_protocol:
  77. inet6_del_protocol(&udplitev6_protocol, IPPROTO_UDPLITE);
  78. goto out;
  79. }
  80. void udplitev6_exit(void)
  81. {
  82. inet6_unregister_protosw(&udplite6_protosw);
  83. inet6_del_protocol(&udplitev6_protocol, IPPROTO_UDPLITE);
  84. }
  85. #ifdef CONFIG_PROC_FS
  86. static const struct file_operations udplite6_afinfo_seq_fops = {
  87. .owner = THIS_MODULE,
  88. .open = udp_seq_open,
  89. .read = seq_read,
  90. .llseek = seq_lseek,
  91. .release = seq_release_net
  92. };
  93. static struct udp_seq_afinfo udplite6_seq_afinfo = {
  94. .name = "udplite6",
  95. .family = AF_INET6,
  96. .udp_table = &udplite_table,
  97. .seq_fops = &udplite6_afinfo_seq_fops,
  98. .seq_ops = {
  99. .show = udp6_seq_show,
  100. },
  101. };
  102. static int __net_init udplite6_proc_init_net(struct net *net)
  103. {
  104. return udp_proc_register(net, &udplite6_seq_afinfo);
  105. }
  106. static void __net_exit udplite6_proc_exit_net(struct net *net)
  107. {
  108. udp_proc_unregister(net, &udplite6_seq_afinfo);
  109. }
  110. static struct pernet_operations udplite6_net_ops = {
  111. .init = udplite6_proc_init_net,
  112. .exit = udplite6_proc_exit_net,
  113. };
  114. int __init udplite6_proc_init(void)
  115. {
  116. return register_pernet_subsys(&udplite6_net_ops);
  117. }
  118. void udplite6_proc_exit(void)
  119. {
  120. unregister_pernet_subsys(&udplite6_net_ops);
  121. }
  122. #endif