xref: /openbmc/linux/net/ipv4/udplite.c (revision a3d2599b24462c762719a70bc4d2ec8e8cb52fcf)
1db8dac20SDavid S. Miller /*
2db8dac20SDavid S. Miller  *  UDPLITE     An implementation of the UDP-Lite protocol (RFC 3828).
3db8dac20SDavid S. Miller  *
4db8dac20SDavid S. Miller  *  Authors:    Gerrit Renker       <gerrit@erg.abdn.ac.uk>
5db8dac20SDavid S. Miller  *
6db8dac20SDavid S. Miller  *  Changes:
7db8dac20SDavid S. Miller  *  Fixes:
8db8dac20SDavid S. Miller  *		This program is free software; you can redistribute it and/or
9db8dac20SDavid S. Miller  *		modify it under the terms of the GNU General Public License
10db8dac20SDavid S. Miller  *		as published by the Free Software Foundation; either version
11db8dac20SDavid S. Miller  *		2 of the License, or (at your option) any later version.
12db8dac20SDavid S. Miller  */
13afd46503SJoe Perches 
14afd46503SJoe Perches #define pr_fmt(fmt) "UDPLite: " fmt
15afd46503SJoe Perches 
16bc3b2d7fSPaul Gortmaker #include <linux/export.h>
17*a3d2599bSChristoph Hellwig #include <linux/proc_fs.h>
18db8dac20SDavid S. Miller #include "udp_impl.h"
19db8dac20SDavid S. Miller 
20f86dcc5aSEric Dumazet struct udp_table 	udplite_table __read_mostly;
21645ca708SEric Dumazet EXPORT_SYMBOL(udplite_table);
22db8dac20SDavid S. Miller 
23db8dac20SDavid S. Miller static int udplite_rcv(struct sk_buff *skb)
24db8dac20SDavid S. Miller {
25645ca708SEric Dumazet 	return __udp4_lib_rcv(skb, &udplite_table, IPPROTO_UDPLITE);
26db8dac20SDavid S. Miller }
27db8dac20SDavid S. Miller 
28db8dac20SDavid S. Miller static void udplite_err(struct sk_buff *skb, u32 info)
29db8dac20SDavid S. Miller {
30645ca708SEric Dumazet 	__udp4_lib_err(skb, info, &udplite_table);
31db8dac20SDavid S. Miller }
32db8dac20SDavid S. Miller 
3332613090SAlexey Dobriyan static const struct net_protocol udplite_protocol = {
34db8dac20SDavid S. Miller 	.handler	= udplite_rcv,
35db8dac20SDavid S. Miller 	.err_handler	= udplite_err,
36db8dac20SDavid S. Miller 	.no_policy	= 1,
3792f1fecbSDenis V. Lunev 	.netns_ok	= 1,
38db8dac20SDavid S. Miller };
39db8dac20SDavid S. Miller 
40db8dac20SDavid S. Miller struct proto 	udplite_prot = {
41db8dac20SDavid S. Miller 	.name		   = "UDP-Lite",
42db8dac20SDavid S. Miller 	.owner		   = THIS_MODULE,
43db8dac20SDavid S. Miller 	.close		   = udp_lib_close,
44db8dac20SDavid S. Miller 	.connect	   = ip4_datagram_connect,
45db8dac20SDavid S. Miller 	.disconnect	   = udp_disconnect,
46db8dac20SDavid S. Miller 	.ioctl		   = udp_ioctl,
47db8dac20SDavid S. Miller 	.init		   = udplite_sk_init,
48db8dac20SDavid S. Miller 	.destroy	   = udp_destroy_sock,
49db8dac20SDavid S. Miller 	.setsockopt	   = udp_setsockopt,
50db8dac20SDavid S. Miller 	.getsockopt	   = udp_getsockopt,
51db8dac20SDavid S. Miller 	.sendmsg	   = udp_sendmsg,
52db8dac20SDavid S. Miller 	.recvmsg	   = udp_recvmsg,
53db8dac20SDavid S. Miller 	.sendpage	   = udp_sendpage,
54db8dac20SDavid S. Miller 	.hash		   = udp_lib_hash,
55db8dac20SDavid S. Miller 	.unhash		   = udp_lib_unhash,
566ba5a3c5SPavel Emelyanov 	.get_port	   = udp_v4_get_port,
57c915fe13SPaolo Abeni 	.memory_allocated  = &udp_memory_allocated,
58c915fe13SPaolo Abeni 	.sysctl_mem	   = sysctl_udp_mem,
59db8dac20SDavid S. Miller 	.obj_size	   = sizeof(struct udp_sock),
60645ca708SEric Dumazet 	.h.udp_table	   = &udplite_table,
61db8dac20SDavid S. Miller #ifdef CONFIG_COMPAT
62db8dac20SDavid S. Miller 	.compat_setsockopt = compat_udp_setsockopt,
63db8dac20SDavid S. Miller 	.compat_getsockopt = compat_udp_getsockopt,
64db8dac20SDavid S. Miller #endif
65db8dac20SDavid S. Miller };
664bc2f18bSEric Dumazet EXPORT_SYMBOL(udplite_prot);
67db8dac20SDavid S. Miller 
68db8dac20SDavid S. Miller static struct inet_protosw udplite4_protosw = {
69db8dac20SDavid S. Miller 	.type		=  SOCK_DGRAM,
70db8dac20SDavid S. Miller 	.protocol	=  IPPROTO_UDPLITE,
71db8dac20SDavid S. Miller 	.prot		=  &udplite_prot,
72db8dac20SDavid S. Miller 	.ops		=  &inet_dgram_ops,
73db8dac20SDavid S. Miller 	.flags		=  INET_PROTOSW_PERMANENT,
74db8dac20SDavid S. Miller };
75db8dac20SDavid S. Miller 
76db8dac20SDavid S. Miller #ifdef CONFIG_PROC_FS
77db8dac20SDavid S. Miller static struct udp_seq_afinfo udplite4_seq_afinfo = {
78db8dac20SDavid S. Miller 	.family		= AF_INET,
79645ca708SEric Dumazet 	.udp_table 	= &udplite_table,
80db8dac20SDavid S. Miller };
81ff2bac6aSPavel Emelyanov 
822c8c1e72SAlexey Dobriyan static int __net_init udplite4_proc_init_net(struct net *net)
8384c375afSPavel Emelyanov {
84*a3d2599bSChristoph Hellwig 	if (!proc_create_data("udplite", 0444, net->proc_net,
85*a3d2599bSChristoph Hellwig 			&udp_afinfo_seq_fops, &udplite4_seq_afinfo))
86*a3d2599bSChristoph Hellwig 		return -ENOMEM;
87*a3d2599bSChristoph Hellwig 	return 0;
8884c375afSPavel Emelyanov }
8984c375afSPavel Emelyanov 
902c8c1e72SAlexey Dobriyan static void __net_exit udplite4_proc_exit_net(struct net *net)
9184c375afSPavel Emelyanov {
92*a3d2599bSChristoph Hellwig 	remove_proc_entry("udplite", net->proc_net);
9384c375afSPavel Emelyanov }
9484c375afSPavel Emelyanov 
9584c375afSPavel Emelyanov static struct pernet_operations udplite4_net_ops = {
9684c375afSPavel Emelyanov 	.init = udplite4_proc_init_net,
9784c375afSPavel Emelyanov 	.exit = udplite4_proc_exit_net,
9884c375afSPavel Emelyanov };
9984c375afSPavel Emelyanov 
100ff2bac6aSPavel Emelyanov static __init int udplite4_proc_init(void)
101ff2bac6aSPavel Emelyanov {
10284c375afSPavel Emelyanov 	return register_pernet_subsys(&udplite4_net_ops);
103ff2bac6aSPavel Emelyanov }
104ff2bac6aSPavel Emelyanov #else
105ff2bac6aSPavel Emelyanov static inline int udplite4_proc_init(void)
106ff2bac6aSPavel Emelyanov {
107ff2bac6aSPavel Emelyanov 	return 0;
108ff2bac6aSPavel Emelyanov }
109db8dac20SDavid S. Miller #endif
110db8dac20SDavid S. Miller 
111db8dac20SDavid S. Miller void __init udplite4_register(void)
112db8dac20SDavid S. Miller {
113f86dcc5aSEric Dumazet 	udp_table_init(&udplite_table, "UDP-Lite");
114db8dac20SDavid S. Miller 	if (proto_register(&udplite_prot, 1))
115db8dac20SDavid S. Miller 		goto out_register_err;
116db8dac20SDavid S. Miller 
117db8dac20SDavid S. Miller 	if (inet_add_protocol(&udplite_protocol, IPPROTO_UDPLITE) < 0)
118db8dac20SDavid S. Miller 		goto out_unregister_proto;
119db8dac20SDavid S. Miller 
120db8dac20SDavid S. Miller 	inet_register_protosw(&udplite4_protosw);
121db8dac20SDavid S. Miller 
122ff2bac6aSPavel Emelyanov 	if (udplite4_proc_init())
123058bd4d2SJoe Perches 		pr_err("%s: Cannot register /proc!\n", __func__);
124db8dac20SDavid S. Miller 	return;
125db8dac20SDavid S. Miller 
126db8dac20SDavid S. Miller out_unregister_proto:
127db8dac20SDavid S. Miller 	proto_unregister(&udplite_prot);
128db8dac20SDavid S. Miller out_register_err:
129058bd4d2SJoe Perches 	pr_crit("%s: Cannot add UDP-Lite protocol\n", __func__);
130db8dac20SDavid S. Miller }
131