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, 51c915fe13SPaolo Abeni .memory_allocated = &udp_memory_allocated, 52c915fe13SPaolo Abeni .sysctl_mem = sysctl_udp_mem, 53db8dac20SDavid S. Miller .obj_size = sizeof(struct udp6_sock), 54645ca708SEric Dumazet .h.udp_table = &udplite_table, 55db8dac20SDavid S. Miller #ifdef CONFIG_COMPAT 56db8dac20SDavid S. Miller .compat_setsockopt = compat_udpv6_setsockopt, 57db8dac20SDavid S. Miller .compat_getsockopt = compat_udpv6_getsockopt, 58db8dac20SDavid S. Miller #endif 59db8dac20SDavid S. Miller }; 60db8dac20SDavid S. Miller 61db8dac20SDavid S. Miller static struct inet_protosw udplite6_protosw = { 62db8dac20SDavid S. Miller .type = SOCK_DGRAM, 63db8dac20SDavid S. Miller .protocol = IPPROTO_UDPLITE, 64db8dac20SDavid S. Miller .prot = &udplitev6_prot, 65db8dac20SDavid S. Miller .ops = &inet6_dgram_ops, 66db8dac20SDavid S. Miller .flags = INET_PROTOSW_PERMANENT, 67db8dac20SDavid S. Miller }; 68db8dac20SDavid S. Miller 69db8dac20SDavid S. Miller int __init udplitev6_init(void) 70db8dac20SDavid S. Miller { 71db8dac20SDavid S. Miller int ret; 72db8dac20SDavid S. Miller 73db8dac20SDavid S. Miller ret = inet6_add_protocol(&udplitev6_protocol, IPPROTO_UDPLITE); 74db8dac20SDavid S. Miller if (ret) 75db8dac20SDavid S. Miller goto out; 76db8dac20SDavid S. Miller 77db8dac20SDavid S. Miller ret = inet6_register_protosw(&udplite6_protosw); 78db8dac20SDavid S. Miller if (ret) 79db8dac20SDavid S. Miller goto out_udplitev6_protocol; 80db8dac20SDavid S. Miller out: 81db8dac20SDavid S. Miller return ret; 82db8dac20SDavid S. Miller 83db8dac20SDavid S. Miller out_udplitev6_protocol: 84db8dac20SDavid S. Miller inet6_del_protocol(&udplitev6_protocol, IPPROTO_UDPLITE); 85db8dac20SDavid S. Miller goto out; 86db8dac20SDavid S. Miller } 87db8dac20SDavid S. Miller 88db8dac20SDavid S. Miller void udplitev6_exit(void) 89db8dac20SDavid S. Miller { 90db8dac20SDavid S. Miller inet6_unregister_protosw(&udplite6_protosw); 91db8dac20SDavid S. Miller inet6_del_protocol(&udplitev6_protocol, IPPROTO_UDPLITE); 92db8dac20SDavid S. Miller } 93db8dac20SDavid S. Miller 94db8dac20SDavid S. Miller #ifdef CONFIG_PROC_FS 95db8dac20SDavid S. Miller static struct udp_seq_afinfo udplite6_seq_afinfo = { 96db8dac20SDavid S. Miller .family = AF_INET6, 97645ca708SEric Dumazet .udp_table = &udplite_table, 98db8dac20SDavid S. Miller }; 99db8dac20SDavid S. Miller 1002c8c1e72SAlexey Dobriyan static int __net_init udplite6_proc_init_net(struct net *net) 10184c375afSPavel Emelyanov { 102c3506372SChristoph Hellwig if (!proc_create_net_data("udplite6", 0444, net->proc_net, 103c3506372SChristoph Hellwig &udp6_seq_ops, sizeof(struct udp_iter_state), 104c3506372SChristoph Hellwig &udplite6_seq_afinfo)) 105a3d2599bSChristoph Hellwig return -ENOMEM; 106a3d2599bSChristoph Hellwig return 0; 10784c375afSPavel Emelyanov } 10884c375afSPavel Emelyanov 1092c8c1e72SAlexey Dobriyan static void __net_exit udplite6_proc_exit_net(struct net *net) 11084c375afSPavel Emelyanov { 111a3d2599bSChristoph Hellwig remove_proc_entry("udplite6", net->proc_net); 11284c375afSPavel Emelyanov } 11384c375afSPavel Emelyanov 11484c375afSPavel Emelyanov static struct pernet_operations udplite6_net_ops = { 11584c375afSPavel Emelyanov .init = udplite6_proc_init_net, 11684c375afSPavel Emelyanov .exit = udplite6_proc_exit_net, 11784c375afSPavel Emelyanov }; 11884c375afSPavel Emelyanov 119db8dac20SDavid S. Miller int __init udplite6_proc_init(void) 120db8dac20SDavid S. Miller { 12184c375afSPavel Emelyanov return register_pernet_subsys(&udplite6_net_ops); 122db8dac20SDavid S. Miller } 123db8dac20SDavid S. Miller 124db8dac20SDavid S. Miller void udplite6_proc_exit(void) 125db8dac20SDavid S. Miller { 12684c375afSPavel Emelyanov unregister_pernet_subsys(&udplite6_net_ops); 127db8dac20SDavid S. Miller } 128db8dac20SDavid S. Miller #endif 129