1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * UDPLITEv6 An implementation of the UDP-Lite protocol over IPv6.
4 * See also net/ipv4/udplite.c
5 *
6 * Authors: Gerrit Renker <gerrit@erg.abdn.ac.uk>
7 *
8 * Changes:
9 * Fixes:
10 */
11 #define pr_fmt(fmt) "UDPLite6: " fmt
12
13 #include <linux/export.h>
14 #include <linux/proc_fs.h>
15 #include "udp_impl.h"
16
udplitev6_sk_init(struct sock * sk)17 static int udplitev6_sk_init(struct sock *sk)
18 {
19 pr_warn_once("UDP-Lite is deprecated and scheduled to be removed in 2025, "
20 "please contact the netdev mailing list\n");
21 return udpv6_init_sock(sk);
22 }
23
udplitev6_rcv(struct sk_buff * skb)24 static int udplitev6_rcv(struct sk_buff *skb)
25 {
26 return __udp6_lib_rcv(skb, &udplite_table, IPPROTO_UDPLITE);
27 }
28
udplitev6_err(struct sk_buff * skb,struct inet6_skb_parm * opt,u8 type,u8 code,int offset,__be32 info)29 static int udplitev6_err(struct sk_buff *skb,
30 struct inet6_skb_parm *opt,
31 u8 type, u8 code, int offset, __be32 info)
32 {
33 return __udp6_lib_err(skb, opt, type, code, offset, info,
34 &udplite_table);
35 }
36
37 static const struct inet6_protocol udplitev6_protocol = {
38 .handler = udplitev6_rcv,
39 .err_handler = udplitev6_err,
40 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
41 };
42
43 struct proto udplitev6_prot = {
44 .name = "UDPLITEv6",
45 .owner = THIS_MODULE,
46 .close = udp_lib_close,
47 .connect = ip6_datagram_connect,
48 .disconnect = udp_disconnect,
49 .ioctl = udp_ioctl,
50 .init = udplitev6_sk_init,
51 .destroy = udpv6_destroy_sock,
52 .setsockopt = udpv6_setsockopt,
53 .getsockopt = udpv6_getsockopt,
54 .sendmsg = udpv6_sendmsg,
55 .recvmsg = udpv6_recvmsg,
56 .hash = udp_lib_hash,
57 .unhash = udp_lib_unhash,
58 .rehash = udp_v6_rehash,
59 .get_port = udp_v6_get_port,
60
61 .memory_allocated = &net_aligned_data.udp_memory_allocated,
62 .per_cpu_fw_alloc = &udp_memory_per_cpu_fw_alloc,
63
64 .sysctl_mem = sysctl_udp_mem,
65 .sysctl_wmem_offset = offsetof(struct net, ipv4.sysctl_udp_wmem_min),
66 .sysctl_rmem_offset = offsetof(struct net, ipv4.sysctl_udp_rmem_min),
67 .obj_size = sizeof(struct udp6_sock),
68 .ipv6_pinfo_offset = offsetof(struct udp6_sock, inet6),
69 .h.udp_table = &udplite_table,
70 };
71
72 static struct inet_protosw udplite6_protosw = {
73 .type = SOCK_DGRAM,
74 .protocol = IPPROTO_UDPLITE,
75 .prot = &udplitev6_prot,
76 .ops = &inet6_dgram_ops,
77 .flags = INET_PROTOSW_PERMANENT,
78 };
79
udplitev6_init(void)80 int __init udplitev6_init(void)
81 {
82 int ret;
83
84 ret = inet6_add_protocol(&udplitev6_protocol, IPPROTO_UDPLITE);
85 if (ret)
86 goto out;
87
88 ret = inet6_register_protosw(&udplite6_protosw);
89 if (ret)
90 goto out_udplitev6_protocol;
91 out:
92 return ret;
93
94 out_udplitev6_protocol:
95 inet6_del_protocol(&udplitev6_protocol, IPPROTO_UDPLITE);
96 goto out;
97 }
98
udplitev6_exit(void)99 void udplitev6_exit(void)
100 {
101 inet6_unregister_protosw(&udplite6_protosw);
102 inet6_del_protocol(&udplitev6_protocol, IPPROTO_UDPLITE);
103 }
104
105 #ifdef CONFIG_PROC_FS
106 static struct udp_seq_afinfo udplite6_seq_afinfo = {
107 .family = AF_INET6,
108 .udp_table = &udplite_table,
109 };
110
udplite6_proc_init_net(struct net * net)111 static int __net_init udplite6_proc_init_net(struct net *net)
112 {
113 if (!proc_create_net_data("udplite6", 0444, net->proc_net,
114 &udp6_seq_ops, sizeof(struct udp_iter_state),
115 &udplite6_seq_afinfo))
116 return -ENOMEM;
117 return 0;
118 }
119
udplite6_proc_exit_net(struct net * net)120 static void __net_exit udplite6_proc_exit_net(struct net *net)
121 {
122 remove_proc_entry("udplite6", net->proc_net);
123 }
124
125 static struct pernet_operations udplite6_net_ops = {
126 .init = udplite6_proc_init_net,
127 .exit = udplite6_proc_exit_net,
128 };
129
udplite6_proc_init(void)130 int __init udplite6_proc_init(void)
131 {
132 return register_pernet_subsys(&udplite6_net_ops);
133 }
134
udplite6_proc_exit(void)135 void udplite6_proc_exit(void)
136 {
137 unregister_pernet_subsys(&udplite6_net_ops);
138 }
139 #endif
140