xref: /openbmc/linux/net/ipv4/udplite.c (revision afd465030acb4098abcb6b965a5aebc7ea2209e0)
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  */
13*afd46503SJoe Perches 
14*afd46503SJoe Perches #define pr_fmt(fmt) "UDPLite: " fmt
15*afd46503SJoe Perches 
16bc3b2d7fSPaul Gortmaker #include <linux/export.h>
17db8dac20SDavid S. Miller #include "udp_impl.h"
18db8dac20SDavid S. Miller 
19f86dcc5aSEric Dumazet struct udp_table 	udplite_table __read_mostly;
20645ca708SEric Dumazet EXPORT_SYMBOL(udplite_table);
21db8dac20SDavid S. Miller 
22db8dac20SDavid S. Miller static int udplite_rcv(struct sk_buff *skb)
23db8dac20SDavid S. Miller {
24645ca708SEric Dumazet 	return __udp4_lib_rcv(skb, &udplite_table, IPPROTO_UDPLITE);
25db8dac20SDavid S. Miller }
26db8dac20SDavid S. Miller 
27db8dac20SDavid S. Miller static void udplite_err(struct sk_buff *skb, u32 info)
28db8dac20SDavid S. Miller {
29645ca708SEric Dumazet 	__udp4_lib_err(skb, info, &udplite_table);
30db8dac20SDavid S. Miller }
31db8dac20SDavid S. Miller 
3232613090SAlexey Dobriyan static const struct net_protocol udplite_protocol = {
33db8dac20SDavid S. Miller 	.handler	= udplite_rcv,
34db8dac20SDavid S. Miller 	.err_handler	= udplite_err,
35db8dac20SDavid S. Miller 	.no_policy	= 1,
3692f1fecbSDenis V. Lunev 	.netns_ok	= 1,
37db8dac20SDavid S. Miller };
38db8dac20SDavid S. Miller 
39db8dac20SDavid S. Miller struct proto 	udplite_prot = {
40db8dac20SDavid S. Miller 	.name		   = "UDP-Lite",
41db8dac20SDavid S. Miller 	.owner		   = THIS_MODULE,
42db8dac20SDavid S. Miller 	.close		   = udp_lib_close,
43db8dac20SDavid S. Miller 	.connect	   = ip4_datagram_connect,
44db8dac20SDavid S. Miller 	.disconnect	   = udp_disconnect,
45db8dac20SDavid S. Miller 	.ioctl		   = udp_ioctl,
46db8dac20SDavid S. Miller 	.init		   = udplite_sk_init,
47db8dac20SDavid S. Miller 	.destroy	   = udp_destroy_sock,
48db8dac20SDavid S. Miller 	.setsockopt	   = udp_setsockopt,
49db8dac20SDavid S. Miller 	.getsockopt	   = udp_getsockopt,
50db8dac20SDavid S. Miller 	.sendmsg	   = udp_sendmsg,
51db8dac20SDavid S. Miller 	.recvmsg	   = udp_recvmsg,
52db8dac20SDavid S. Miller 	.sendpage	   = udp_sendpage,
53db8dac20SDavid S. Miller 	.backlog_rcv	   = udp_queue_rcv_skb,
54db8dac20SDavid S. Miller 	.hash		   = udp_lib_hash,
55db8dac20SDavid S. Miller 	.unhash		   = udp_lib_unhash,
566ba5a3c5SPavel Emelyanov 	.get_port	   = udp_v4_get_port,
57db8dac20SDavid S. Miller 	.obj_size	   = sizeof(struct udp_sock),
58271b72c7SEric Dumazet 	.slab_flags	   = SLAB_DESTROY_BY_RCU,
59645ca708SEric Dumazet 	.h.udp_table	   = &udplite_table,
60db8dac20SDavid S. Miller #ifdef CONFIG_COMPAT
61db8dac20SDavid S. Miller 	.compat_setsockopt = compat_udp_setsockopt,
62db8dac20SDavid S. Miller 	.compat_getsockopt = compat_udp_getsockopt,
63db8dac20SDavid S. Miller #endif
64fcbdf09dSOctavian Purdila 	.clear_sk	   = sk_prot_clear_portaddr_nulls,
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 	.no_check	=  0,		/* must checksum (RFC 3828) */
74db8dac20SDavid S. Miller 	.flags		=  INET_PROTOSW_PERMANENT,
75db8dac20SDavid S. Miller };
76db8dac20SDavid S. Miller 
77db8dac20SDavid S. Miller #ifdef CONFIG_PROC_FS
7873cb88ecSArjan van de Ven 
7973cb88ecSArjan van de Ven static const struct file_operations udplite_afinfo_seq_fops = {
8073cb88ecSArjan van de Ven 	.owner    = THIS_MODULE,
8173cb88ecSArjan van de Ven 	.open     = udp_seq_open,
8273cb88ecSArjan van de Ven 	.read     = seq_read,
8373cb88ecSArjan van de Ven 	.llseek   = seq_lseek,
8473cb88ecSArjan van de Ven 	.release  = seq_release_net
8573cb88ecSArjan van de Ven };
8673cb88ecSArjan van de Ven 
87db8dac20SDavid S. Miller static struct udp_seq_afinfo udplite4_seq_afinfo = {
88db8dac20SDavid S. Miller 	.name		= "udplite",
89db8dac20SDavid S. Miller 	.family		= AF_INET,
90645ca708SEric Dumazet 	.udp_table 	= &udplite_table,
9173cb88ecSArjan van de Ven 	.seq_fops	= &udplite_afinfo_seq_fops,
92dda61925SDenis V. Lunev 	.seq_ops	= {
93dda61925SDenis V. Lunev 		.show		= udp4_seq_show,
94dda61925SDenis V. Lunev 	},
95db8dac20SDavid S. Miller };
96ff2bac6aSPavel Emelyanov 
972c8c1e72SAlexey Dobriyan static int __net_init udplite4_proc_init_net(struct net *net)
9884c375afSPavel Emelyanov {
9984c375afSPavel Emelyanov 	return udp_proc_register(net, &udplite4_seq_afinfo);
10084c375afSPavel Emelyanov }
10184c375afSPavel Emelyanov 
1022c8c1e72SAlexey Dobriyan static void __net_exit udplite4_proc_exit_net(struct net *net)
10384c375afSPavel Emelyanov {
10484c375afSPavel Emelyanov 	udp_proc_unregister(net, &udplite4_seq_afinfo);
10584c375afSPavel Emelyanov }
10684c375afSPavel Emelyanov 
10784c375afSPavel Emelyanov static struct pernet_operations udplite4_net_ops = {
10884c375afSPavel Emelyanov 	.init = udplite4_proc_init_net,
10984c375afSPavel Emelyanov 	.exit = udplite4_proc_exit_net,
11084c375afSPavel Emelyanov };
11184c375afSPavel Emelyanov 
112ff2bac6aSPavel Emelyanov static __init int udplite4_proc_init(void)
113ff2bac6aSPavel Emelyanov {
11484c375afSPavel Emelyanov 	return register_pernet_subsys(&udplite4_net_ops);
115ff2bac6aSPavel Emelyanov }
116ff2bac6aSPavel Emelyanov #else
117ff2bac6aSPavel Emelyanov static inline int udplite4_proc_init(void)
118ff2bac6aSPavel Emelyanov {
119ff2bac6aSPavel Emelyanov 	return 0;
120ff2bac6aSPavel Emelyanov }
121db8dac20SDavid S. Miller #endif
122db8dac20SDavid S. Miller 
123db8dac20SDavid S. Miller void __init udplite4_register(void)
124db8dac20SDavid S. Miller {
125f86dcc5aSEric Dumazet 	udp_table_init(&udplite_table, "UDP-Lite");
126db8dac20SDavid S. Miller 	if (proto_register(&udplite_prot, 1))
127db8dac20SDavid S. Miller 		goto out_register_err;
128db8dac20SDavid S. Miller 
129db8dac20SDavid S. Miller 	if (inet_add_protocol(&udplite_protocol, IPPROTO_UDPLITE) < 0)
130db8dac20SDavid S. Miller 		goto out_unregister_proto;
131db8dac20SDavid S. Miller 
132db8dac20SDavid S. Miller 	inet_register_protosw(&udplite4_protosw);
133db8dac20SDavid S. Miller 
134ff2bac6aSPavel Emelyanov 	if (udplite4_proc_init())
135058bd4d2SJoe Perches 		pr_err("%s: Cannot register /proc!\n", __func__);
136db8dac20SDavid S. Miller 	return;
137db8dac20SDavid S. Miller 
138db8dac20SDavid S. Miller out_unregister_proto:
139db8dac20SDavid S. Miller 	proto_unregister(&udplite_prot);
140db8dac20SDavid S. Miller out_register_err:
141058bd4d2SJoe Perches 	pr_crit("%s: Cannot add UDP-Lite protocol\n", __func__);
142db8dac20SDavid S. Miller }
143