12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 2db8dac20SDavid S. Miller /* 3db8dac20SDavid S. Miller * UDPLITE An implementation of the UDP-Lite protocol (RFC 3828). 4db8dac20SDavid S. Miller * 5db8dac20SDavid S. Miller * Authors: Gerrit Renker <gerrit@erg.abdn.ac.uk> 6db8dac20SDavid S. Miller * 7db8dac20SDavid S. Miller * Changes: 8db8dac20SDavid S. Miller * Fixes: 9db8dac20SDavid S. Miller */ 10afd46503SJoe Perches 11afd46503SJoe Perches #define pr_fmt(fmt) "UDPLite: " fmt 12afd46503SJoe Perches 13bc3b2d7fSPaul Gortmaker #include <linux/export.h> 14a3d2599bSChristoph Hellwig #include <linux/proc_fs.h> 15db8dac20SDavid S. Miller #include "udp_impl.h" 16db8dac20SDavid S. Miller 17f86dcc5aSEric Dumazet struct udp_table udplite_table __read_mostly; 18645ca708SEric Dumazet EXPORT_SYMBOL(udplite_table); 19db8dac20SDavid S. Miller 20*d38afeecSKuniyuki Iwashima /* Designate sk as UDP-Lite socket */ 21*d38afeecSKuniyuki Iwashima static int udplite_sk_init(struct sock *sk) 22*d38afeecSKuniyuki Iwashima { 23*d38afeecSKuniyuki Iwashima udp_init_sock(sk); 24*d38afeecSKuniyuki Iwashima udp_sk(sk)->pcflag = UDPLITE_BIT; 25*d38afeecSKuniyuki Iwashima return 0; 26*d38afeecSKuniyuki Iwashima } 27*d38afeecSKuniyuki Iwashima 28db8dac20SDavid S. Miller static int udplite_rcv(struct sk_buff *skb) 29db8dac20SDavid S. Miller { 30645ca708SEric Dumazet return __udp4_lib_rcv(skb, &udplite_table, IPPROTO_UDPLITE); 31db8dac20SDavid S. Miller } 32db8dac20SDavid S. Miller 3332bbd879SStefano Brivio static int udplite_err(struct sk_buff *skb, u32 info) 34db8dac20SDavid S. Miller { 3532bbd879SStefano Brivio return __udp4_lib_err(skb, info, &udplite_table); 36db8dac20SDavid S. Miller } 37db8dac20SDavid S. Miller 3832613090SAlexey Dobriyan static const struct net_protocol udplite_protocol = { 39db8dac20SDavid S. Miller .handler = udplite_rcv, 40db8dac20SDavid S. Miller .err_handler = udplite_err, 41db8dac20SDavid S. Miller .no_policy = 1, 42db8dac20SDavid S. Miller }; 43db8dac20SDavid S. Miller 44db8dac20SDavid S. Miller struct proto udplite_prot = { 45db8dac20SDavid S. Miller .name = "UDP-Lite", 46db8dac20SDavid S. Miller .owner = THIS_MODULE, 47db8dac20SDavid S. Miller .close = udp_lib_close, 48db8dac20SDavid S. Miller .connect = ip4_datagram_connect, 49db8dac20SDavid S. Miller .disconnect = udp_disconnect, 50db8dac20SDavid S. Miller .ioctl = udp_ioctl, 51db8dac20SDavid S. Miller .init = udplite_sk_init, 52db8dac20SDavid S. Miller .destroy = udp_destroy_sock, 53db8dac20SDavid S. Miller .setsockopt = udp_setsockopt, 54db8dac20SDavid S. Miller .getsockopt = udp_getsockopt, 55db8dac20SDavid S. Miller .sendmsg = udp_sendmsg, 56db8dac20SDavid S. Miller .recvmsg = udp_recvmsg, 57db8dac20SDavid S. Miller .sendpage = udp_sendpage, 58db8dac20SDavid S. Miller .hash = udp_lib_hash, 59db8dac20SDavid S. Miller .unhash = udp_lib_unhash, 608f6b5392SAlexey Kodanev .rehash = udp_v4_rehash, 616ba5a3c5SPavel Emelyanov .get_port = udp_v4_get_port, 620defbb0aSEric Dumazet 63c915fe13SPaolo Abeni .memory_allocated = &udp_memory_allocated, 640defbb0aSEric Dumazet .per_cpu_fw_alloc = &udp_memory_per_cpu_fw_alloc, 650defbb0aSEric Dumazet 66c915fe13SPaolo Abeni .sysctl_mem = sysctl_udp_mem, 67db8dac20SDavid S. Miller .obj_size = sizeof(struct udp_sock), 68645ca708SEric Dumazet .h.udp_table = &udplite_table, 69db8dac20SDavid S. Miller }; 704bc2f18bSEric Dumazet EXPORT_SYMBOL(udplite_prot); 71db8dac20SDavid S. Miller 72db8dac20SDavid S. Miller static struct inet_protosw udplite4_protosw = { 73db8dac20SDavid S. Miller .type = SOCK_DGRAM, 74db8dac20SDavid S. Miller .protocol = IPPROTO_UDPLITE, 75db8dac20SDavid S. Miller .prot = &udplite_prot, 76db8dac20SDavid S. Miller .ops = &inet_dgram_ops, 77db8dac20SDavid S. Miller .flags = INET_PROTOSW_PERMANENT, 78db8dac20SDavid S. Miller }; 79db8dac20SDavid S. Miller 80db8dac20SDavid S. Miller #ifdef CONFIG_PROC_FS 81db8dac20SDavid S. Miller static struct udp_seq_afinfo udplite4_seq_afinfo = { 82db8dac20SDavid S. Miller .family = AF_INET, 83645ca708SEric Dumazet .udp_table = &udplite_table, 84db8dac20SDavid S. Miller }; 85ff2bac6aSPavel Emelyanov 862c8c1e72SAlexey Dobriyan static int __net_init udplite4_proc_init_net(struct net *net) 8784c375afSPavel Emelyanov { 88c3506372SChristoph Hellwig if (!proc_create_net_data("udplite", 0444, net->proc_net, &udp_seq_ops, 89c3506372SChristoph Hellwig sizeof(struct udp_iter_state), &udplite4_seq_afinfo)) 90a3d2599bSChristoph Hellwig return -ENOMEM; 91a3d2599bSChristoph Hellwig return 0; 9284c375afSPavel Emelyanov } 9384c375afSPavel Emelyanov 942c8c1e72SAlexey Dobriyan static void __net_exit udplite4_proc_exit_net(struct net *net) 9584c375afSPavel Emelyanov { 96a3d2599bSChristoph Hellwig remove_proc_entry("udplite", net->proc_net); 9784c375afSPavel Emelyanov } 9884c375afSPavel Emelyanov 9984c375afSPavel Emelyanov static struct pernet_operations udplite4_net_ops = { 10084c375afSPavel Emelyanov .init = udplite4_proc_init_net, 10184c375afSPavel Emelyanov .exit = udplite4_proc_exit_net, 10284c375afSPavel Emelyanov }; 10384c375afSPavel Emelyanov 104ff2bac6aSPavel Emelyanov static __init int udplite4_proc_init(void) 105ff2bac6aSPavel Emelyanov { 10684c375afSPavel Emelyanov return register_pernet_subsys(&udplite4_net_ops); 107ff2bac6aSPavel Emelyanov } 108ff2bac6aSPavel Emelyanov #else 109ff2bac6aSPavel Emelyanov static inline int udplite4_proc_init(void) 110ff2bac6aSPavel Emelyanov { 111ff2bac6aSPavel Emelyanov return 0; 112ff2bac6aSPavel Emelyanov } 113db8dac20SDavid S. Miller #endif 114db8dac20SDavid S. Miller 115db8dac20SDavid S. Miller void __init udplite4_register(void) 116db8dac20SDavid S. Miller { 117f86dcc5aSEric Dumazet udp_table_init(&udplite_table, "UDP-Lite"); 118db8dac20SDavid S. Miller if (proto_register(&udplite_prot, 1)) 119db8dac20SDavid S. Miller goto out_register_err; 120db8dac20SDavid S. Miller 121db8dac20SDavid S. Miller if (inet_add_protocol(&udplite_protocol, IPPROTO_UDPLITE) < 0) 122db8dac20SDavid S. Miller goto out_unregister_proto; 123db8dac20SDavid S. Miller 124db8dac20SDavid S. Miller inet_register_protosw(&udplite4_protosw); 125db8dac20SDavid S. Miller 126ff2bac6aSPavel Emelyanov if (udplite4_proc_init()) 127058bd4d2SJoe Perches pr_err("%s: Cannot register /proc!\n", __func__); 128db8dac20SDavid S. Miller return; 129db8dac20SDavid S. Miller 130db8dac20SDavid S. Miller out_unregister_proto: 131db8dac20SDavid S. Miller proto_unregister(&udplite_prot); 132db8dac20SDavid S. Miller out_register_err: 133058bd4d2SJoe Perches pr_crit("%s: Cannot add UDP-Lite protocol\n", __func__); 134db8dac20SDavid S. Miller } 135