162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * UDPLITE An implementation of the UDP-Lite protocol (RFC 3828). 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Authors: Gerrit Renker <gerrit@erg.abdn.ac.uk> 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Changes: 862306a36Sopenharmony_ci * Fixes: 962306a36Sopenharmony_ci */ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#define pr_fmt(fmt) "UDPLite: " fmt 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#include <linux/export.h> 1462306a36Sopenharmony_ci#include <linux/proc_fs.h> 1562306a36Sopenharmony_ci#include "udp_impl.h" 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_cistruct udp_table udplite_table __read_mostly; 1862306a36Sopenharmony_ciEXPORT_SYMBOL(udplite_table); 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci/* Designate sk as UDP-Lite socket */ 2162306a36Sopenharmony_cistatic int udplite_sk_init(struct sock *sk) 2262306a36Sopenharmony_ci{ 2362306a36Sopenharmony_ci udp_init_sock(sk); 2462306a36Sopenharmony_ci pr_warn_once("UDP-Lite is deprecated and scheduled to be removed in 2025, " 2562306a36Sopenharmony_ci "please contact the netdev mailing list\n"); 2662306a36Sopenharmony_ci return 0; 2762306a36Sopenharmony_ci} 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_cistatic int udplite_rcv(struct sk_buff *skb) 3062306a36Sopenharmony_ci{ 3162306a36Sopenharmony_ci return __udp4_lib_rcv(skb, &udplite_table, IPPROTO_UDPLITE); 3262306a36Sopenharmony_ci} 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_cistatic int udplite_err(struct sk_buff *skb, u32 info) 3562306a36Sopenharmony_ci{ 3662306a36Sopenharmony_ci return __udp4_lib_err(skb, info, &udplite_table); 3762306a36Sopenharmony_ci} 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_cistatic const struct net_protocol udplite_protocol = { 4062306a36Sopenharmony_ci .handler = udplite_rcv, 4162306a36Sopenharmony_ci .err_handler = udplite_err, 4262306a36Sopenharmony_ci .no_policy = 1, 4362306a36Sopenharmony_ci}; 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_cistruct proto udplite_prot = { 4662306a36Sopenharmony_ci .name = "UDP-Lite", 4762306a36Sopenharmony_ci .owner = THIS_MODULE, 4862306a36Sopenharmony_ci .close = udp_lib_close, 4962306a36Sopenharmony_ci .connect = ip4_datagram_connect, 5062306a36Sopenharmony_ci .disconnect = udp_disconnect, 5162306a36Sopenharmony_ci .ioctl = udp_ioctl, 5262306a36Sopenharmony_ci .init = udplite_sk_init, 5362306a36Sopenharmony_ci .destroy = udp_destroy_sock, 5462306a36Sopenharmony_ci .setsockopt = udp_setsockopt, 5562306a36Sopenharmony_ci .getsockopt = udp_getsockopt, 5662306a36Sopenharmony_ci .sendmsg = udp_sendmsg, 5762306a36Sopenharmony_ci .recvmsg = udp_recvmsg, 5862306a36Sopenharmony_ci .hash = udp_lib_hash, 5962306a36Sopenharmony_ci .unhash = udp_lib_unhash, 6062306a36Sopenharmony_ci .rehash = udp_v4_rehash, 6162306a36Sopenharmony_ci .get_port = udp_v4_get_port, 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci .memory_allocated = &udp_memory_allocated, 6462306a36Sopenharmony_ci .per_cpu_fw_alloc = &udp_memory_per_cpu_fw_alloc, 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci .sysctl_mem = sysctl_udp_mem, 6762306a36Sopenharmony_ci .sysctl_wmem_offset = offsetof(struct net, ipv4.sysctl_udp_wmem_min), 6862306a36Sopenharmony_ci .sysctl_rmem_offset = offsetof(struct net, ipv4.sysctl_udp_rmem_min), 6962306a36Sopenharmony_ci .obj_size = sizeof(struct udp_sock), 7062306a36Sopenharmony_ci .h.udp_table = &udplite_table, 7162306a36Sopenharmony_ci}; 7262306a36Sopenharmony_ciEXPORT_SYMBOL(udplite_prot); 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_cistatic struct inet_protosw udplite4_protosw = { 7562306a36Sopenharmony_ci .type = SOCK_DGRAM, 7662306a36Sopenharmony_ci .protocol = IPPROTO_UDPLITE, 7762306a36Sopenharmony_ci .prot = &udplite_prot, 7862306a36Sopenharmony_ci .ops = &inet_dgram_ops, 7962306a36Sopenharmony_ci .flags = INET_PROTOSW_PERMANENT, 8062306a36Sopenharmony_ci}; 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci#ifdef CONFIG_PROC_FS 8362306a36Sopenharmony_cistatic struct udp_seq_afinfo udplite4_seq_afinfo = { 8462306a36Sopenharmony_ci .family = AF_INET, 8562306a36Sopenharmony_ci .udp_table = &udplite_table, 8662306a36Sopenharmony_ci}; 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_cistatic int __net_init udplite4_proc_init_net(struct net *net) 8962306a36Sopenharmony_ci{ 9062306a36Sopenharmony_ci if (!proc_create_net_data("udplite", 0444, net->proc_net, &udp_seq_ops, 9162306a36Sopenharmony_ci sizeof(struct udp_iter_state), &udplite4_seq_afinfo)) 9262306a36Sopenharmony_ci return -ENOMEM; 9362306a36Sopenharmony_ci return 0; 9462306a36Sopenharmony_ci} 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_cistatic void __net_exit udplite4_proc_exit_net(struct net *net) 9762306a36Sopenharmony_ci{ 9862306a36Sopenharmony_ci remove_proc_entry("udplite", net->proc_net); 9962306a36Sopenharmony_ci} 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_cistatic struct pernet_operations udplite4_net_ops = { 10262306a36Sopenharmony_ci .init = udplite4_proc_init_net, 10362306a36Sopenharmony_ci .exit = udplite4_proc_exit_net, 10462306a36Sopenharmony_ci}; 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_cistatic __init int udplite4_proc_init(void) 10762306a36Sopenharmony_ci{ 10862306a36Sopenharmony_ci return register_pernet_subsys(&udplite4_net_ops); 10962306a36Sopenharmony_ci} 11062306a36Sopenharmony_ci#else 11162306a36Sopenharmony_cistatic inline int udplite4_proc_init(void) 11262306a36Sopenharmony_ci{ 11362306a36Sopenharmony_ci return 0; 11462306a36Sopenharmony_ci} 11562306a36Sopenharmony_ci#endif 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_civoid __init udplite4_register(void) 11862306a36Sopenharmony_ci{ 11962306a36Sopenharmony_ci udp_table_init(&udplite_table, "UDP-Lite"); 12062306a36Sopenharmony_ci if (proto_register(&udplite_prot, 1)) 12162306a36Sopenharmony_ci goto out_register_err; 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ci if (inet_add_protocol(&udplite_protocol, IPPROTO_UDPLITE) < 0) 12462306a36Sopenharmony_ci goto out_unregister_proto; 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci inet_register_protosw(&udplite4_protosw); 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci if (udplite4_proc_init()) 12962306a36Sopenharmony_ci pr_err("%s: Cannot register /proc!\n", __func__); 13062306a36Sopenharmony_ci return; 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ciout_unregister_proto: 13362306a36Sopenharmony_ci proto_unregister(&udplite_prot); 13462306a36Sopenharmony_ciout_register_err: 13562306a36Sopenharmony_ci pr_crit("%s: Cannot add UDP-Lite protocol\n", __func__); 13662306a36Sopenharmony_ci} 137