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