blob: 3c807964da96a95eb08f738974abda92b0959f87 [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 */
13#include "udp_impl.h"
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080014
15struct hlist_head udplite_hash[UDP_HTABLE_SIZE];
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080016
Adrian Bunkf5b99bc2006-11-30 17:22:29 -080017static int udplite_rcv(struct sk_buff *skb)
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080018{
Herbert Xu759e5d02007-03-25 20:10:56 -070019 return __udp4_lib_rcv(skb, udplite_hash, IPPROTO_UDPLITE);
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080020}
21
Adrian Bunkf5b99bc2006-11-30 17:22:29 -080022static void udplite_err(struct sk_buff *skb, u32 info)
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080023{
YOSHIFUJI Hideakifc80be82008-01-22 17:05:31 +090024 __udp4_lib_err(skb, info, udplite_hash);
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080025}
26
27static struct net_protocol udplite_protocol = {
28 .handler = udplite_rcv,
29 .err_handler = udplite_err,
30 .no_policy = 1,
Denis V. Lunev92f1fec2008-03-24 15:34:06 -070031 .netns_ok = 1,
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080032};
33
34struct proto udplite_prot = {
35 .name = "UDP-Lite",
36 .owner = THIS_MODULE,
37 .close = udp_lib_close,
38 .connect = ip4_datagram_connect,
39 .disconnect = udp_disconnect,
40 .ioctl = udp_ioctl,
41 .init = udplite_sk_init,
42 .destroy = udp_destroy_sock,
43 .setsockopt = udp_setsockopt,
44 .getsockopt = udp_getsockopt,
45 .sendmsg = udp_sendmsg,
46 .recvmsg = udp_recvmsg,
47 .sendpage = udp_sendpage,
48 .backlog_rcv = udp_queue_rcv_skb,
49 .hash = udp_lib_hash,
50 .unhash = udp_lib_unhash,
Pavel Emelyanov6ba5a3c2008-03-22 16:51:21 -070051 .get_port = udp_v4_get_port,
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080052 .obj_size = sizeof(struct udp_sock),
Pavel Emelyanov6ba5a3c2008-03-22 16:51:21 -070053 .h.udp_hash = udplite_hash,
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080054#ifdef CONFIG_COMPAT
55 .compat_setsockopt = compat_udp_setsockopt,
56 .compat_getsockopt = compat_udp_getsockopt,
57#endif
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080058};
59
60static struct inet_protosw udplite4_protosw = {
61 .type = SOCK_DGRAM,
62 .protocol = IPPROTO_UDPLITE,
63 .prot = &udplite_prot,
64 .ops = &inet_dgram_ops,
65 .capability = -1,
66 .no_check = 0, /* must checksum (RFC 3828) */
67 .flags = INET_PROTOSW_PERMANENT,
68};
69
70#ifdef CONFIG_PROC_FS
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080071static struct udp_seq_afinfo udplite4_seq_afinfo = {
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080072 .name = "udplite",
73 .family = AF_INET,
74 .hashtable = udplite_hash,
Denis V. Lunev4ad96d32008-03-28 18:25:53 -070075 .seq_fops = {
76 .owner = THIS_MODULE,
77 },
Denis V. Lunevdda61922008-03-28 18:24:26 -070078 .seq_ops = {
79 .show = udp4_seq_show,
80 },
Gerrit Renkerba4e58e2006-11-27 11:10:57 -080081};
Pavel Emelyanovff2bac62008-03-24 14:56:34 -070082
Pavel Emelyanov84c375a2008-03-24 14:56:57 -070083static int udplite4_proc_init_net(struct net *net)
84{
85 return udp_proc_register(net, &udplite4_seq_afinfo);
86}
87
88static void udplite4_proc_exit_net(struct net *net)
89{
90 udp_proc_unregister(net, &udplite4_seq_afinfo);
91}
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{
111 if (proto_register(&udplite_prot, 1))
112 goto out_register_err;
113
114 if (inet_add_protocol(&udplite_protocol, IPPROTO_UDPLITE) < 0)
115 goto out_unregister_proto;
116
117 inet_register_protosw(&udplite4_protosw);
118
Pavel Emelyanovff2bac62008-03-24 14:56:34 -0700119 if (udplite4_proc_init())
Harvey Harrison0dc47872008-03-05 20:47:47 -0800120 printk(KERN_ERR "%s: Cannot register /proc!\n", __func__);
Gerrit Renkerba4e58e2006-11-27 11:10:57 -0800121 return;
122
123out_unregister_proto:
124 proto_unregister(&udplite_prot);
125out_register_err:
Harvey Harrison0dc47872008-03-05 20:47:47 -0800126 printk(KERN_CRIT "%s: Cannot add UDP-Lite protocol.\n", __func__);
Gerrit Renkerba4e58e2006-11-27 11:10:57 -0800127}
128
129EXPORT_SYMBOL(udplite_hash);
130EXPORT_SYMBOL(udplite_prot);