udplite.c 3.2 KB

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