xref: /linux/net/ipv4/udplite.c (revision 0ea5c948cb64bab5bc7a5516774eb8536f05aa0d)
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 
20d38afeecSKuniyuki Iwashima /* Designate sk as UDP-Lite socket */
udplite_sk_init(struct sock * sk)21d38afeecSKuniyuki Iwashima static int udplite_sk_init(struct sock *sk)
22d38afeecSKuniyuki Iwashima {
23d38afeecSKuniyuki Iwashima 	udp_init_sock(sk);
24*be28c14aSKuniyuki Iwashima 	pr_warn_once("UDP-Lite is deprecated and scheduled to be removed in 2025, "
25*be28c14aSKuniyuki Iwashima 		     "please contact the netdev mailing list\n");
26d38afeecSKuniyuki Iwashima 	return 0;
27d38afeecSKuniyuki Iwashima }
28d38afeecSKuniyuki Iwashima 
udplite_rcv(struct sk_buff * skb)29db8dac20SDavid S. Miller static int udplite_rcv(struct sk_buff *skb)
30db8dac20SDavid S. Miller {
31645ca708SEric Dumazet 	return __udp4_lib_rcv(skb, &udplite_table, IPPROTO_UDPLITE);
32db8dac20SDavid S. Miller }
33db8dac20SDavid S. Miller 
udplite_err(struct sk_buff * skb,u32 info)3432bbd879SStefano Brivio static int udplite_err(struct sk_buff *skb, u32 info)
35db8dac20SDavid S. Miller {
3632bbd879SStefano Brivio 	return __udp4_lib_err(skb, info, &udplite_table);
37db8dac20SDavid S. Miller }
38db8dac20SDavid S. Miller 
3932613090SAlexey Dobriyan static const struct net_protocol udplite_protocol = {
40db8dac20SDavid S. Miller 	.handler	= udplite_rcv,
41db8dac20SDavid S. Miller 	.err_handler	= udplite_err,
42db8dac20SDavid S. Miller 	.no_policy	= 1,
43db8dac20SDavid S. Miller };
44db8dac20SDavid S. Miller 
45db8dac20SDavid S. Miller struct proto 	udplite_prot = {
46db8dac20SDavid S. Miller 	.name		   = "UDP-Lite",
47db8dac20SDavid S. Miller 	.owner		   = THIS_MODULE,
48db8dac20SDavid S. Miller 	.close		   = udp_lib_close,
49db8dac20SDavid S. Miller 	.connect	   = ip4_datagram_connect,
50db8dac20SDavid S. Miller 	.disconnect	   = udp_disconnect,
51db8dac20SDavid S. Miller 	.ioctl		   = udp_ioctl,
52db8dac20SDavid S. Miller 	.init		   = udplite_sk_init,
53db8dac20SDavid S. Miller 	.destroy	   = udp_destroy_sock,
54db8dac20SDavid S. Miller 	.setsockopt	   = udp_setsockopt,
55db8dac20SDavid S. Miller 	.getsockopt	   = udp_getsockopt,
56db8dac20SDavid S. Miller 	.sendmsg	   = udp_sendmsg,
57db8dac20SDavid S. Miller 	.recvmsg	   = udp_recvmsg,
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,
67ad42a35bSKuniyuki Iwashima 	.sysctl_wmem_offset = offsetof(struct net, ipv4.sysctl_udp_wmem_min),
68ad42a35bSKuniyuki Iwashima 	.sysctl_rmem_offset = offsetof(struct net, ipv4.sysctl_udp_rmem_min),
69db8dac20SDavid S. Miller 	.obj_size	   = sizeof(struct udp_sock),
70645ca708SEric Dumazet 	.h.udp_table	   = &udplite_table,
71db8dac20SDavid S. Miller };
724bc2f18bSEric Dumazet EXPORT_SYMBOL(udplite_prot);
73db8dac20SDavid S. Miller 
74db8dac20SDavid S. Miller static struct inet_protosw udplite4_protosw = {
75db8dac20SDavid S. Miller 	.type		=  SOCK_DGRAM,
76db8dac20SDavid S. Miller 	.protocol	=  IPPROTO_UDPLITE,
77db8dac20SDavid S. Miller 	.prot		=  &udplite_prot,
78db8dac20SDavid S. Miller 	.ops		=  &inet_dgram_ops,
79db8dac20SDavid S. Miller 	.flags		=  INET_PROTOSW_PERMANENT,
80db8dac20SDavid S. Miller };
81db8dac20SDavid S. Miller 
82db8dac20SDavid S. Miller #ifdef CONFIG_PROC_FS
83db8dac20SDavid S. Miller static struct udp_seq_afinfo udplite4_seq_afinfo = {
84db8dac20SDavid S. Miller 	.family		= AF_INET,
85645ca708SEric Dumazet 	.udp_table 	= &udplite_table,
86db8dac20SDavid S. Miller };
87ff2bac6aSPavel Emelyanov 
udplite4_proc_init_net(struct net * net)882c8c1e72SAlexey Dobriyan static int __net_init udplite4_proc_init_net(struct net *net)
8984c375afSPavel Emelyanov {
90c3506372SChristoph Hellwig 	if (!proc_create_net_data("udplite", 0444, net->proc_net, &udp_seq_ops,
91c3506372SChristoph Hellwig 			sizeof(struct udp_iter_state), &udplite4_seq_afinfo))
92a3d2599bSChristoph Hellwig 		return -ENOMEM;
93a3d2599bSChristoph Hellwig 	return 0;
9484c375afSPavel Emelyanov }
9584c375afSPavel Emelyanov 
udplite4_proc_exit_net(struct net * net)962c8c1e72SAlexey Dobriyan static void __net_exit udplite4_proc_exit_net(struct net *net)
9784c375afSPavel Emelyanov {
98a3d2599bSChristoph Hellwig 	remove_proc_entry("udplite", net->proc_net);
9984c375afSPavel Emelyanov }
10084c375afSPavel Emelyanov 
10184c375afSPavel Emelyanov static struct pernet_operations udplite4_net_ops = {
10284c375afSPavel Emelyanov 	.init = udplite4_proc_init_net,
10384c375afSPavel Emelyanov 	.exit = udplite4_proc_exit_net,
10484c375afSPavel Emelyanov };
10584c375afSPavel Emelyanov 
udplite4_proc_init(void)106ff2bac6aSPavel Emelyanov static __init int udplite4_proc_init(void)
107ff2bac6aSPavel Emelyanov {
10884c375afSPavel Emelyanov 	return register_pernet_subsys(&udplite4_net_ops);
109ff2bac6aSPavel Emelyanov }
110ff2bac6aSPavel Emelyanov #else
udplite4_proc_init(void)111ff2bac6aSPavel Emelyanov static inline int udplite4_proc_init(void)
112ff2bac6aSPavel Emelyanov {
113ff2bac6aSPavel Emelyanov 	return 0;
114ff2bac6aSPavel Emelyanov }
115db8dac20SDavid S. Miller #endif
116db8dac20SDavid S. Miller 
udplite4_register(void)117db8dac20SDavid S. Miller void __init udplite4_register(void)
118db8dac20SDavid S. Miller {
119f86dcc5aSEric Dumazet 	udp_table_init(&udplite_table, "UDP-Lite");
120db8dac20SDavid S. Miller 	if (proto_register(&udplite_prot, 1))
121db8dac20SDavid S. Miller 		goto out_register_err;
122db8dac20SDavid S. Miller 
123db8dac20SDavid S. Miller 	if (inet_add_protocol(&udplite_protocol, IPPROTO_UDPLITE) < 0)
124db8dac20SDavid S. Miller 		goto out_unregister_proto;
125db8dac20SDavid S. Miller 
126db8dac20SDavid S. Miller 	inet_register_protosw(&udplite4_protosw);
127db8dac20SDavid S. Miller 
128ff2bac6aSPavel Emelyanov 	if (udplite4_proc_init())
129058bd4d2SJoe Perches 		pr_err("%s: Cannot register /proc!\n", __func__);
130db8dac20SDavid S. Miller 	return;
131db8dac20SDavid S. Miller 
132db8dac20SDavid S. Miller out_unregister_proto:
133db8dac20SDavid S. Miller 	proto_unregister(&udplite_prot);
134db8dac20SDavid S. Miller out_register_err:
135058bd4d2SJoe Perches 	pr_crit("%s: Cannot add UDP-Lite protocol\n", __func__);
136db8dac20SDavid S. Miller }
137