1db8dac20SDavid S. Miller /* 2db8dac20SDavid S. Miller * UDPLITE An implementation of the UDP-Lite protocol (RFC 3828). 3db8dac20SDavid S. Miller * 4db8dac20SDavid S. Miller * Version: $Id: udplite.c,v 1.25 2006/10/19 07:22:36 gerrit Exp $ 5db8dac20SDavid S. Miller * 6db8dac20SDavid S. Miller * Authors: Gerrit Renker <gerrit@erg.abdn.ac.uk> 7db8dac20SDavid S. Miller * 8db8dac20SDavid S. Miller * Changes: 9db8dac20SDavid S. Miller * Fixes: 10db8dac20SDavid S. Miller * This program is free software; you can redistribute it and/or 11db8dac20SDavid S. Miller * modify it under the terms of the GNU General Public License 12db8dac20SDavid S. Miller * as published by the Free Software Foundation; either version 13db8dac20SDavid S. Miller * 2 of the License, or (at your option) any later version. 14db8dac20SDavid S. Miller */ 15db8dac20SDavid S. Miller #include "udp_impl.h" 16db8dac20SDavid S. Miller DEFINE_SNMP_STAT(struct udp_mib, udplite_statistics) __read_mostly; 17db8dac20SDavid S. Miller 18db8dac20SDavid S. Miller struct hlist_head udplite_hash[UDP_HTABLE_SIZE]; 19db8dac20SDavid S. Miller 20db8dac20SDavid S. Miller static int udplite_rcv(struct sk_buff *skb) 21db8dac20SDavid S. Miller { 22db8dac20SDavid S. Miller return __udp4_lib_rcv(skb, udplite_hash, IPPROTO_UDPLITE); 23db8dac20SDavid S. Miller } 24db8dac20SDavid S. Miller 25db8dac20SDavid S. Miller static void udplite_err(struct sk_buff *skb, u32 info) 26db8dac20SDavid S. Miller { 27db8dac20SDavid S. Miller __udp4_lib_err(skb, info, udplite_hash); 28db8dac20SDavid S. Miller } 29db8dac20SDavid S. Miller 30db8dac20SDavid S. Miller static struct net_protocol udplite_protocol = { 31db8dac20SDavid S. Miller .handler = udplite_rcv, 32db8dac20SDavid S. Miller .err_handler = udplite_err, 33db8dac20SDavid S. Miller .no_policy = 1, 3492f1fecbSDenis V. Lunev .netns_ok = 1, 35db8dac20SDavid S. Miller }; 36db8dac20SDavid S. Miller 37db8dac20SDavid S. Miller struct proto udplite_prot = { 38db8dac20SDavid S. Miller .name = "UDP-Lite", 39db8dac20SDavid S. Miller .owner = THIS_MODULE, 40db8dac20SDavid S. Miller .close = udp_lib_close, 41db8dac20SDavid S. Miller .connect = ip4_datagram_connect, 42db8dac20SDavid S. Miller .disconnect = udp_disconnect, 43db8dac20SDavid S. Miller .ioctl = udp_ioctl, 44db8dac20SDavid S. Miller .init = udplite_sk_init, 45db8dac20SDavid S. Miller .destroy = udp_destroy_sock, 46db8dac20SDavid S. Miller .setsockopt = udp_setsockopt, 47db8dac20SDavid S. Miller .getsockopt = udp_getsockopt, 48db8dac20SDavid S. Miller .sendmsg = udp_sendmsg, 49db8dac20SDavid S. Miller .recvmsg = udp_recvmsg, 50db8dac20SDavid S. Miller .sendpage = udp_sendpage, 51db8dac20SDavid S. Miller .backlog_rcv = udp_queue_rcv_skb, 52db8dac20SDavid S. Miller .hash = udp_lib_hash, 53db8dac20SDavid S. Miller .unhash = udp_lib_unhash, 546ba5a3c5SPavel Emelyanov .get_port = udp_v4_get_port, 55db8dac20SDavid S. Miller .obj_size = sizeof(struct udp_sock), 566ba5a3c5SPavel Emelyanov .h.udp_hash = udplite_hash, 57db8dac20SDavid S. Miller #ifdef CONFIG_COMPAT 58db8dac20SDavid S. Miller .compat_setsockopt = compat_udp_setsockopt, 59db8dac20SDavid S. Miller .compat_getsockopt = compat_udp_getsockopt, 60db8dac20SDavid S. Miller #endif 61db8dac20SDavid S. Miller }; 62db8dac20SDavid S. Miller 63db8dac20SDavid S. Miller static struct inet_protosw udplite4_protosw = { 64db8dac20SDavid S. Miller .type = SOCK_DGRAM, 65db8dac20SDavid S. Miller .protocol = IPPROTO_UDPLITE, 66db8dac20SDavid S. Miller .prot = &udplite_prot, 67db8dac20SDavid S. Miller .ops = &inet_dgram_ops, 68db8dac20SDavid S. Miller .capability = -1, 69db8dac20SDavid S. Miller .no_check = 0, /* must checksum (RFC 3828) */ 70db8dac20SDavid S. Miller .flags = INET_PROTOSW_PERMANENT, 71db8dac20SDavid S. Miller }; 72db8dac20SDavid S. Miller 73db8dac20SDavid S. Miller #ifdef CONFIG_PROC_FS 74db8dac20SDavid S. Miller static struct file_operations udplite4_seq_fops; 75db8dac20SDavid S. Miller static struct udp_seq_afinfo udplite4_seq_afinfo = { 76db8dac20SDavid S. Miller .owner = THIS_MODULE, 77db8dac20SDavid S. Miller .name = "udplite", 78db8dac20SDavid S. Miller .family = AF_INET, 79db8dac20SDavid S. Miller .hashtable = udplite_hash, 80db8dac20SDavid S. Miller .seq_fops = &udplite4_seq_fops, 81*dda61925SDenis V. Lunev .seq_ops = { 82*dda61925SDenis V. Lunev .show = udp4_seq_show, 83*dda61925SDenis V. Lunev }, 84db8dac20SDavid S. Miller }; 85ff2bac6aSPavel Emelyanov 8684c375afSPavel Emelyanov static int udplite4_proc_init_net(struct net *net) 8784c375afSPavel Emelyanov { 8884c375afSPavel Emelyanov return udp_proc_register(net, &udplite4_seq_afinfo); 8984c375afSPavel Emelyanov } 9084c375afSPavel Emelyanov 9184c375afSPavel Emelyanov static void udplite4_proc_exit_net(struct net *net) 9284c375afSPavel Emelyanov { 9384c375afSPavel Emelyanov udp_proc_unregister(net, &udplite4_seq_afinfo); 9484c375afSPavel Emelyanov } 9584c375afSPavel Emelyanov 9684c375afSPavel Emelyanov static struct pernet_operations udplite4_net_ops = { 9784c375afSPavel Emelyanov .init = udplite4_proc_init_net, 9884c375afSPavel Emelyanov .exit = udplite4_proc_exit_net, 9984c375afSPavel Emelyanov }; 10084c375afSPavel Emelyanov 101ff2bac6aSPavel Emelyanov static __init int udplite4_proc_init(void) 102ff2bac6aSPavel Emelyanov { 10384c375afSPavel Emelyanov return register_pernet_subsys(&udplite4_net_ops); 104ff2bac6aSPavel Emelyanov } 105ff2bac6aSPavel Emelyanov #else 106ff2bac6aSPavel Emelyanov static inline int udplite4_proc_init(void) 107ff2bac6aSPavel Emelyanov { 108ff2bac6aSPavel Emelyanov return 0; 109ff2bac6aSPavel Emelyanov } 110db8dac20SDavid S. Miller #endif 111db8dac20SDavid S. Miller 112db8dac20SDavid S. Miller void __init udplite4_register(void) 113db8dac20SDavid S. Miller { 114db8dac20SDavid S. Miller if (proto_register(&udplite_prot, 1)) 115db8dac20SDavid S. Miller goto out_register_err; 116db8dac20SDavid S. Miller 117db8dac20SDavid S. Miller if (inet_add_protocol(&udplite_protocol, IPPROTO_UDPLITE) < 0) 118db8dac20SDavid S. Miller goto out_unregister_proto; 119db8dac20SDavid S. Miller 120db8dac20SDavid S. Miller inet_register_protosw(&udplite4_protosw); 121db8dac20SDavid S. Miller 122ff2bac6aSPavel Emelyanov if (udplite4_proc_init()) 123db8dac20SDavid S. Miller printk(KERN_ERR "%s: Cannot register /proc!\n", __func__); 124db8dac20SDavid S. Miller return; 125db8dac20SDavid S. Miller 126db8dac20SDavid S. Miller out_unregister_proto: 127db8dac20SDavid S. Miller proto_unregister(&udplite_prot); 128db8dac20SDavid S. Miller out_register_err: 129db8dac20SDavid S. Miller printk(KERN_CRIT "%s: Cannot add UDP-Lite protocol.\n", __func__); 130db8dac20SDavid S. Miller } 131db8dac20SDavid S. Miller 132db8dac20SDavid S. Miller EXPORT_SYMBOL(udplite_hash); 133db8dac20SDavid S. Miller EXPORT_SYMBOL(udplite_prot); 134