blob: 5936d66d1ce2f2e46248c1110c929b5e07c3b3b6 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Gerrit Renkerba4e58e2006-11-27 11:10:57 -08002/*
3 * UDPLITE An implementation of the UDP-Lite protocol (RFC 3828).
4 *
Gerrit Renkerba4e58e2006-11-27 11:10:57 -08005 * Authors: Gerrit Renker <gerrit@erg.abdn.ac.uk>
6 *
7 * Changes:
8 * Fixes:
Gerrit Renkerba4e58e2006-11-27 11:10:57 -08009 */
Joe Perchesafd465032012-03-12 07:03:32 +000010
11#define pr_fmt(fmt) "UDPLite: " fmt
12
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040013#include <linux/export.h>
Christoph Hellwiga3d25992018-04-10 21:31:50 +020014#include <linux/proc_fs.h>
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080015#include "udp_impl.h"
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080016
Eric Dumazetf86dcc52009-10-07 00:37:59 +000017struct udp_table udplite_table __read_mostly;
Eric Dumazet645ca702008-10-29 01:41:45 -070018EXPORT_SYMBOL(udplite_table);
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080019
Adrian Bunkf5b99bc2006-11-30 17:22:29 -080020static int udplite_rcv(struct sk_buff *skb)
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080021{
Eric Dumazet645ca702008-10-29 01:41:45 -070022 return __udp4_lib_rcv(skb, &udplite_table, IPPROTO_UDPLITE);
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080023}
24
Stefano Brivio32bbd872018-11-08 12:19:21 +010025static int udplite_err(struct sk_buff *skb, u32 info)
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080026{
Stefano Brivio32bbd872018-11-08 12:19:21 +010027 return __udp4_lib_err(skb, info, &udplite_table);
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080028}
29
Alexey Dobriyan32613092009-09-14 12:21:47 +000030static const struct net_protocol udplite_protocol = {
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080031 .handler = udplite_rcv,
32 .err_handler = udplite_err,
33 .no_policy = 1,
Denis V. Lunev92f1fec2008-03-24 15:34:06 -070034 .netns_ok = 1,
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080035};
36
37struct proto udplite_prot = {
38 .name = "UDP-Lite",
39 .owner = THIS_MODULE,
40 .close = udp_lib_close,
41 .connect = ip4_datagram_connect,
42 .disconnect = udp_disconnect,
43 .ioctl = udp_ioctl,
44 .init = udplite_sk_init,
45 .destroy = udp_destroy_sock,
46 .setsockopt = udp_setsockopt,
47 .getsockopt = udp_getsockopt,
48 .sendmsg = udp_sendmsg,
49 .recvmsg = udp_recvmsg,
50 .sendpage = udp_sendpage,
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080051 .hash = udp_lib_hash,
52 .unhash = udp_lib_unhash,
Alexey Kodanev8f6b5392019-01-16 19:17:44 +030053 .rehash = udp_v4_rehash,
Pavel Emelyanov6ba5a3c2008-03-22 16:51:21 -070054 .get_port = udp_v4_get_port,
Paolo Abenic915fe12016-11-15 16:37:53 +010055 .memory_allocated = &udp_memory_allocated,
56 .sysctl_mem = sysctl_udp_mem,
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080057 .obj_size = sizeof(struct udp_sock),
Eric Dumazet645ca702008-10-29 01:41:45 -070058 .h.udp_table = &udplite_table,
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080059#ifdef CONFIG_COMPAT
60 .compat_setsockopt = compat_udp_setsockopt,
61 .compat_getsockopt = compat_udp_getsockopt,
62#endif
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080063};
Eric Dumazet4bc2f182010-07-09 21:22:10 +000064EXPORT_SYMBOL(udplite_prot);
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080065
66static struct inet_protosw udplite4_protosw = {
67 .type = SOCK_DGRAM,
68 .protocol = IPPROTO_UDPLITE,
69 .prot = &udplite_prot,
70 .ops = &inet_dgram_ops,
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080071 .flags = INET_PROTOSW_PERMANENT,
72};
73
74#ifdef CONFIG_PROC_FS
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080075static struct udp_seq_afinfo udplite4_seq_afinfo = {
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080076 .family = AF_INET,
Eric Dumazet645ca702008-10-29 01:41:45 -070077 .udp_table = &udplite_table,
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080078};
Pavel Emelyanovff2bac62008-03-24 14:56:34 -070079
Alexey Dobriyan2c8c1e72010-01-17 03:35:32 +000080static int __net_init udplite4_proc_init_net(struct net *net)
Pavel Emelyanov84c375a2008-03-24 14:56:57 -070081{
Christoph Hellwigc3506372018-04-10 19:42:55 +020082 if (!proc_create_net_data("udplite", 0444, net->proc_net, &udp_seq_ops,
83 sizeof(struct udp_iter_state), &udplite4_seq_afinfo))
Christoph Hellwiga3d25992018-04-10 21:31:50 +020084 return -ENOMEM;
85 return 0;
Pavel Emelyanov84c375a2008-03-24 14:56:57 -070086}
87
Alexey Dobriyan2c8c1e72010-01-17 03:35:32 +000088static void __net_exit udplite4_proc_exit_net(struct net *net)
Pavel Emelyanov84c375a2008-03-24 14:56:57 -070089{
Christoph Hellwiga3d25992018-04-10 21:31:50 +020090 remove_proc_entry("udplite", net->proc_net);
Pavel Emelyanov84c375a2008-03-24 14:56:57 -070091}
92
93static struct pernet_operations udplite4_net_ops = {
94 .init = udplite4_proc_init_net,
95 .exit = udplite4_proc_exit_net,
96};
97
Pavel Emelyanovff2bac62008-03-24 14:56:34 -070098static __init int udplite4_proc_init(void)
99{
Pavel Emelyanov84c375a2008-03-24 14:56:57 -0700100 return register_pernet_subsys(&udplite4_net_ops);
Pavel Emelyanovff2bac62008-03-24 14:56:34 -0700101}
102#else
103static inline int udplite4_proc_init(void)
104{
105 return 0;
106}
Gerrit Renkerba4e58e2006-11-27 11:10:57 -0800107#endif
108
109void __init udplite4_register(void)
110{
Eric Dumazetf86dcc52009-10-07 00:37:59 +0000111 udp_table_init(&udplite_table, "UDP-Lite");
Gerrit Renkerba4e58e2006-11-27 11:10:57 -0800112 if (proto_register(&udplite_prot, 1))
113 goto out_register_err;
114
115 if (inet_add_protocol(&udplite_protocol, IPPROTO_UDPLITE) < 0)
116 goto out_unregister_proto;
117
118 inet_register_protosw(&udplite4_protosw);
119
Pavel Emelyanovff2bac62008-03-24 14:56:34 -0700120 if (udplite4_proc_init())
Joe Perches058bd4d2012-03-11 18:36:11 +0000121 pr_err("%s: Cannot register /proc!\n", __func__);
Gerrit Renkerba4e58e2006-11-27 11:10:57 -0800122 return;
123
124out_unregister_proto:
125 proto_unregister(&udplite_prot);
126out_register_err:
Joe Perches058bd4d2012-03-11 18:36:11 +0000127 pr_crit("%s: Cannot add UDP-Lite protocol\n", __func__);
Gerrit Renkerba4e58e2006-11-27 11:10:57 -0800128}