blob: 8545457752fb95e9239ff683efbdacfd08f8a004 [file] [log] [blame]
Gerrit Renkerba4e58e2006-11-27 11:10:57 -08001/*
2 * UDPLITE An implementation of the UDP-Lite protocol (RFC 3828).
3 *
Gerrit Renkerba4e58e2006-11-27 11:10:57 -08004 * Authors: Gerrit Renker <gerrit@erg.abdn.ac.uk>
5 *
6 * Changes:
7 * Fixes:
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
12 */
Joe Perchesafd465032012-03-12 07:03:32 +000013
14#define pr_fmt(fmt) "UDPLite: " fmt
15
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040016#include <linux/export.h>
Christoph Hellwiga3d25992018-04-10 21:31:50 +020017#include <linux/proc_fs.h>
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080018#include "udp_impl.h"
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080019
Eric Dumazetf86dcc52009-10-07 00:37:59 +000020struct udp_table udplite_table __read_mostly;
Eric Dumazet645ca702008-10-29 01:41:45 -070021EXPORT_SYMBOL(udplite_table);
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080022
Adrian Bunkf5b99bc2006-11-30 17:22:29 -080023static int udplite_rcv(struct sk_buff *skb)
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080024{
Eric Dumazet645ca702008-10-29 01:41:45 -070025 return __udp4_lib_rcv(skb, &udplite_table, IPPROTO_UDPLITE);
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080026}
27
Adrian Bunkf5b99bc2006-11-30 17:22:29 -080028static void udplite_err(struct sk_buff *skb, u32 info)
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080029{
Eric Dumazet645ca702008-10-29 01:41:45 -070030 __udp4_lib_err(skb, info, &udplite_table);
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080031}
32
Alexey Dobriyan32613092009-09-14 12:21:47 +000033static const struct net_protocol udplite_protocol = {
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080034 .handler = udplite_rcv,
35 .err_handler = udplite_err,
36 .no_policy = 1,
Denis V. Lunev92f1fec2008-03-24 15:34:06 -070037 .netns_ok = 1,
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080038};
39
40struct proto udplite_prot = {
41 .name = "UDP-Lite",
42 .owner = THIS_MODULE,
43 .close = udp_lib_close,
44 .connect = ip4_datagram_connect,
45 .disconnect = udp_disconnect,
46 .ioctl = udp_ioctl,
47 .init = udplite_sk_init,
48 .destroy = udp_destroy_sock,
49 .setsockopt = udp_setsockopt,
50 .getsockopt = udp_getsockopt,
51 .sendmsg = udp_sendmsg,
52 .recvmsg = udp_recvmsg,
53 .sendpage = udp_sendpage,
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080054 .hash = udp_lib_hash,
55 .unhash = udp_lib_unhash,
Pavel Emelyanov6ba5a3c2008-03-22 16:51:21 -070056 .get_port = udp_v4_get_port,
Paolo Abenic915fe12016-11-15 16:37:53 +010057 .memory_allocated = &udp_memory_allocated,
58 .sysctl_mem = sysctl_udp_mem,
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080059 .obj_size = sizeof(struct udp_sock),
Eric Dumazet645ca702008-10-29 01:41:45 -070060 .h.udp_table = &udplite_table,
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080061#ifdef CONFIG_COMPAT
62 .compat_setsockopt = compat_udp_setsockopt,
63 .compat_getsockopt = compat_udp_getsockopt,
64#endif
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080065};
Eric Dumazet4bc2f182010-07-09 21:22:10 +000066EXPORT_SYMBOL(udplite_prot);
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080067
68static struct inet_protosw udplite4_protosw = {
69 .type = SOCK_DGRAM,
70 .protocol = IPPROTO_UDPLITE,
71 .prot = &udplite_prot,
72 .ops = &inet_dgram_ops,
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080073 .flags = INET_PROTOSW_PERMANENT,
74};
75
76#ifdef CONFIG_PROC_FS
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080077static struct udp_seq_afinfo udplite4_seq_afinfo = {
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080078 .family = AF_INET,
Eric Dumazet645ca702008-10-29 01:41:45 -070079 .udp_table = &udplite_table,
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080080};
Pavel Emelyanovff2bac62008-03-24 14:56:34 -070081
Alexey Dobriyan2c8c1e72010-01-17 03:35:32 +000082static int __net_init udplite4_proc_init_net(struct net *net)
Pavel Emelyanov84c375a2008-03-24 14:56:57 -070083{
Christoph Hellwigc3506372018-04-10 19:42:55 +020084 if (!proc_create_net_data("udplite", 0444, net->proc_net, &udp_seq_ops,
85 sizeof(struct udp_iter_state), &udplite4_seq_afinfo))
Christoph Hellwiga3d25992018-04-10 21:31:50 +020086 return -ENOMEM;
87 return 0;
Pavel Emelyanov84c375a2008-03-24 14:56:57 -070088}
89
Alexey Dobriyan2c8c1e72010-01-17 03:35:32 +000090static void __net_exit udplite4_proc_exit_net(struct net *net)
Pavel Emelyanov84c375a2008-03-24 14:56:57 -070091{
Christoph Hellwiga3d25992018-04-10 21:31:50 +020092 remove_proc_entry("udplite", net->proc_net);
Pavel Emelyanov84c375a2008-03-24 14:56:57 -070093}
94
95static struct pernet_operations udplite4_net_ops = {
96 .init = udplite4_proc_init_net,
97 .exit = udplite4_proc_exit_net,
98};
99
Pavel Emelyanovff2bac62008-03-24 14:56:34 -0700100static __init int udplite4_proc_init(void)
101{
Pavel Emelyanov84c375a2008-03-24 14:56:57 -0700102 return register_pernet_subsys(&udplite4_net_ops);
Pavel Emelyanovff2bac62008-03-24 14:56:34 -0700103}
104#else
105static inline int udplite4_proc_init(void)
106{
107 return 0;
108}
Gerrit Renkerba4e58e2006-11-27 11:10:57 -0800109#endif
110
111void __init udplite4_register(void)
112{
Eric Dumazetf86dcc52009-10-07 00:37:59 +0000113 udp_table_init(&udplite_table, "UDP-Lite");
Gerrit Renkerba4e58e2006-11-27 11:10:57 -0800114 if (proto_register(&udplite_prot, 1))
115 goto out_register_err;
116
117 if (inet_add_protocol(&udplite_protocol, IPPROTO_UDPLITE) < 0)
118 goto out_unregister_proto;
119
120 inet_register_protosw(&udplite4_protosw);
121
Pavel Emelyanovff2bac62008-03-24 14:56:34 -0700122 if (udplite4_proc_init())
Joe Perches058bd4d2012-03-11 18:36:11 +0000123 pr_err("%s: Cannot register /proc!\n", __func__);
Gerrit Renkerba4e58e2006-11-27 11:10:57 -0800124 return;
125
126out_unregister_proto:
127 proto_unregister(&udplite_prot);
128out_register_err:
Joe Perches058bd4d2012-03-11 18:36:11 +0000129 pr_crit("%s: Cannot add UDP-Lite protocol\n", __func__);
Gerrit Renkerba4e58e2006-11-27 11:10:57 -0800130}