12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 2db8dac20SDavid S. Miller /* 3db8dac20SDavid S. Miller * UDPLITEv6 An implementation of the UDP-Lite protocol over IPv6. 4db8dac20SDavid S. Miller * See also net/ipv4/udplite.c 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 */ 11bc3b2d7fSPaul Gortmaker #include <linux/export.h> 12a3d2599bSChristoph Hellwig #include <linux/proc_fs.h> 13db8dac20SDavid S. Miller #include "udp_impl.h" 14db8dac20SDavid S. Miller 15db8dac20SDavid S. Miller static int udplitev6_rcv(struct sk_buff *skb) 16db8dac20SDavid S. Miller { 17645ca708SEric Dumazet return __udp6_lib_rcv(skb, &udplite_table, IPPROTO_UDPLITE); 18db8dac20SDavid S. Miller } 19db8dac20SDavid S. Miller 2032bbd879SStefano Brivio static int udplitev6_err(struct sk_buff *skb, 21db8dac20SDavid S. Miller struct inet6_skb_parm *opt, 22d5fdd6baSBrian Haley u8 type, u8 code, int offset, __be32 info) 23db8dac20SDavid S. Miller { 2432bbd879SStefano Brivio return __udp6_lib_err(skb, opt, type, code, offset, info, 2532bbd879SStefano Brivio &udplite_table); 26db8dac20SDavid S. Miller } 27db8dac20SDavid S. Miller 2841135cc8SAlexey Dobriyan static const struct inet6_protocol udplitev6_protocol = { 29db8dac20SDavid S. Miller .handler = udplitev6_rcv, 30db8dac20SDavid S. Miller .err_handler = udplitev6_err, 31db8dac20SDavid S. Miller .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL, 32db8dac20SDavid S. Miller }; 33db8dac20SDavid S. Miller 34db8dac20SDavid S. Miller struct proto udplitev6_prot = { 35db8dac20SDavid S. Miller .name = "UDPLITEv6", 36db8dac20SDavid S. Miller .owner = THIS_MODULE, 37db8dac20SDavid S. Miller .close = udp_lib_close, 38db8dac20SDavid S. Miller .connect = ip6_datagram_connect, 39db8dac20SDavid S. Miller .disconnect = udp_disconnect, 40db8dac20SDavid S. Miller .ioctl = udp_ioctl, 41db8dac20SDavid S. Miller .init = udplite_sk_init, 42db8dac20SDavid S. Miller .destroy = udpv6_destroy_sock, 43db8dac20SDavid S. Miller .setsockopt = udpv6_setsockopt, 44db8dac20SDavid S. Miller .getsockopt = udpv6_getsockopt, 45db8dac20SDavid S. Miller .sendmsg = udpv6_sendmsg, 46db8dac20SDavid S. Miller .recvmsg = udpv6_recvmsg, 47db8dac20SDavid S. Miller .hash = udp_lib_hash, 48db8dac20SDavid S. Miller .unhash = udp_lib_unhash, 49f7c46156SAlexey Kodanev .rehash = udp_v6_rehash, 506ba5a3c5SPavel Emelyanov .get_port = udp_v6_get_port, 51*0defbb0aSEric Dumazet 52c915fe13SPaolo Abeni .memory_allocated = &udp_memory_allocated, 53*0defbb0aSEric Dumazet .per_cpu_fw_alloc = &udp_memory_per_cpu_fw_alloc, 54*0defbb0aSEric Dumazet 55c915fe13SPaolo Abeni .sysctl_mem = sysctl_udp_mem, 56db8dac20SDavid S. Miller .obj_size = sizeof(struct udp6_sock), 57645ca708SEric Dumazet .h.udp_table = &udplite_table, 58db8dac20SDavid S. Miller }; 59db8dac20SDavid S. Miller 60db8dac20SDavid S. Miller static struct inet_protosw udplite6_protosw = { 61db8dac20SDavid S. Miller .type = SOCK_DGRAM, 62db8dac20SDavid S. Miller .protocol = IPPROTO_UDPLITE, 63db8dac20SDavid S. Miller .prot = &udplitev6_prot, 64db8dac20SDavid S. Miller .ops = &inet6_dgram_ops, 65db8dac20SDavid S. Miller .flags = INET_PROTOSW_PERMANENT, 66db8dac20SDavid S. Miller }; 67db8dac20SDavid S. Miller 68db8dac20SDavid S. Miller int __init udplitev6_init(void) 69db8dac20SDavid S. Miller { 70db8dac20SDavid S. Miller int ret; 71db8dac20SDavid S. Miller 72db8dac20SDavid S. Miller ret = inet6_add_protocol(&udplitev6_protocol, IPPROTO_UDPLITE); 73db8dac20SDavid S. Miller if (ret) 74db8dac20SDavid S. Miller goto out; 75db8dac20SDavid S. Miller 76db8dac20SDavid S. Miller ret = inet6_register_protosw(&udplite6_protosw); 77db8dac20SDavid S. Miller if (ret) 78db8dac20SDavid S. Miller goto out_udplitev6_protocol; 79db8dac20SDavid S. Miller out: 80db8dac20SDavid S. Miller return ret; 81db8dac20SDavid S. Miller 82db8dac20SDavid S. Miller out_udplitev6_protocol: 83db8dac20SDavid S. Miller inet6_del_protocol(&udplitev6_protocol, IPPROTO_UDPLITE); 84db8dac20SDavid S. Miller goto out; 85db8dac20SDavid S. Miller } 86db8dac20SDavid S. Miller 87db8dac20SDavid S. Miller void udplitev6_exit(void) 88db8dac20SDavid S. Miller { 89db8dac20SDavid S. Miller inet6_unregister_protosw(&udplite6_protosw); 90db8dac20SDavid S. Miller inet6_del_protocol(&udplitev6_protocol, IPPROTO_UDPLITE); 91db8dac20SDavid S. Miller } 92db8dac20SDavid S. Miller 93db8dac20SDavid S. Miller #ifdef CONFIG_PROC_FS 94db8dac20SDavid S. Miller static struct udp_seq_afinfo udplite6_seq_afinfo = { 95db8dac20SDavid S. Miller .family = AF_INET6, 96645ca708SEric Dumazet .udp_table = &udplite_table, 97db8dac20SDavid S. Miller }; 98db8dac20SDavid S. Miller 992c8c1e72SAlexey Dobriyan static int __net_init udplite6_proc_init_net(struct net *net) 10084c375afSPavel Emelyanov { 101c3506372SChristoph Hellwig if (!proc_create_net_data("udplite6", 0444, net->proc_net, 102c3506372SChristoph Hellwig &udp6_seq_ops, sizeof(struct udp_iter_state), 103c3506372SChristoph Hellwig &udplite6_seq_afinfo)) 104a3d2599bSChristoph Hellwig return -ENOMEM; 105a3d2599bSChristoph Hellwig return 0; 10684c375afSPavel Emelyanov } 10784c375afSPavel Emelyanov 1082c8c1e72SAlexey Dobriyan static void __net_exit udplite6_proc_exit_net(struct net *net) 10984c375afSPavel Emelyanov { 110a3d2599bSChristoph Hellwig remove_proc_entry("udplite6", net->proc_net); 11184c375afSPavel Emelyanov } 11284c375afSPavel Emelyanov 11384c375afSPavel Emelyanov static struct pernet_operations udplite6_net_ops = { 11484c375afSPavel Emelyanov .init = udplite6_proc_init_net, 11584c375afSPavel Emelyanov .exit = udplite6_proc_exit_net, 11684c375afSPavel Emelyanov }; 11784c375afSPavel Emelyanov 118db8dac20SDavid S. Miller int __init udplite6_proc_init(void) 119db8dac20SDavid S. Miller { 12084c375afSPavel Emelyanov return register_pernet_subsys(&udplite6_net_ops); 121db8dac20SDavid S. Miller } 122db8dac20SDavid S. Miller 123db8dac20SDavid S. Miller void udplite6_proc_exit(void) 124db8dac20SDavid S. Miller { 12584c375afSPavel Emelyanov unregister_pernet_subsys(&udplite6_net_ops); 126db8dac20SDavid S. Miller } 127db8dac20SDavid S. Miller #endif 128