12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2db8dac20SDavid S. Miller /*
3db8dac20SDavid S. Miller * UDPLITEv6 An implementation of the UDP-Lite protocol over IPv6.
4db8dac20SDavid S. Miller * See also net/ipv4/udplite.c
5db8dac20SDavid S. Miller *
6db8dac20SDavid S. Miller * Authors: Gerrit Renker <gerrit@erg.abdn.ac.uk>
7db8dac20SDavid S. Miller *
8db8dac20SDavid S. Miller * Changes:
9db8dac20SDavid S. Miller * Fixes:
10db8dac20SDavid S. Miller */
11be28c14aSKuniyuki Iwashima #define pr_fmt(fmt) "UDPLite6: " fmt
12be28c14aSKuniyuki Iwashima
13bc3b2d7fSPaul Gortmaker #include <linux/export.h>
14a3d2599bSChristoph Hellwig #include <linux/proc_fs.h>
15db8dac20SDavid S. Miller #include "udp_impl.h"
16db8dac20SDavid S. Miller
udplitev6_sk_init(struct sock * sk)17d38afeecSKuniyuki Iwashima static int udplitev6_sk_init(struct sock *sk)
18d38afeecSKuniyuki Iwashima {
19d38afeecSKuniyuki Iwashima udpv6_init_sock(sk);
20be28c14aSKuniyuki Iwashima pr_warn_once("UDP-Lite is deprecated and scheduled to be removed in 2025, "
21be28c14aSKuniyuki Iwashima "please contact the netdev mailing list\n");
22d38afeecSKuniyuki Iwashima return 0;
23d38afeecSKuniyuki Iwashima }
24d38afeecSKuniyuki Iwashima
udplitev6_rcv(struct sk_buff * skb)25db8dac20SDavid S. Miller static int udplitev6_rcv(struct sk_buff *skb)
26db8dac20SDavid S. Miller {
27645ca708SEric Dumazet return __udp6_lib_rcv(skb, &udplite_table, IPPROTO_UDPLITE);
28db8dac20SDavid S. Miller }
29db8dac20SDavid S. Miller
udplitev6_err(struct sk_buff * skb,struct inet6_skb_parm * opt,u8 type,u8 code,int offset,__be32 info)3032bbd879SStefano Brivio static int udplitev6_err(struct sk_buff *skb,
31db8dac20SDavid S. Miller struct inet6_skb_parm *opt,
32d5fdd6baSBrian Haley u8 type, u8 code, int offset, __be32 info)
33db8dac20SDavid S. Miller {
3432bbd879SStefano Brivio return __udp6_lib_err(skb, opt, type, code, offset, info,
3532bbd879SStefano Brivio &udplite_table);
36db8dac20SDavid S. Miller }
37db8dac20SDavid S. Miller
3841135cc8SAlexey Dobriyan static const struct inet6_protocol udplitev6_protocol = {
39db8dac20SDavid S. Miller .handler = udplitev6_rcv,
40db8dac20SDavid S. Miller .err_handler = udplitev6_err,
41db8dac20SDavid S. Miller .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
42db8dac20SDavid S. Miller };
43db8dac20SDavid S. Miller
44db8dac20SDavid S. Miller struct proto udplitev6_prot = {
45db8dac20SDavid S. Miller .name = "UDPLITEv6",
46db8dac20SDavid S. Miller .owner = THIS_MODULE,
47db8dac20SDavid S. Miller .close = udp_lib_close,
48db8dac20SDavid S. Miller .connect = ip6_datagram_connect,
49db8dac20SDavid S. Miller .disconnect = udp_disconnect,
50db8dac20SDavid S. Miller .ioctl = udp_ioctl,
51d38afeecSKuniyuki Iwashima .init = udplitev6_sk_init,
52db8dac20SDavid S. Miller .destroy = udpv6_destroy_sock,
53db8dac20SDavid S. Miller .setsockopt = udpv6_setsockopt,
54db8dac20SDavid S. Miller .getsockopt = udpv6_getsockopt,
55db8dac20SDavid S. Miller .sendmsg = udpv6_sendmsg,
56db8dac20SDavid S. Miller .recvmsg = udpv6_recvmsg,
57db8dac20SDavid S. Miller .hash = udp_lib_hash,
58db8dac20SDavid S. Miller .unhash = udp_lib_unhash,
59f7c46156SAlexey Kodanev .rehash = udp_v6_rehash,
606ba5a3c5SPavel Emelyanov .get_port = udp_v6_get_port,
610defbb0aSEric Dumazet
62c915fe13SPaolo Abeni .memory_allocated = &udp_memory_allocated,
630defbb0aSEric Dumazet .per_cpu_fw_alloc = &udp_memory_per_cpu_fw_alloc,
640defbb0aSEric Dumazet
65c915fe13SPaolo Abeni .sysctl_mem = sysctl_udp_mem,
66ad42a35bSKuniyuki Iwashima .sysctl_wmem_offset = offsetof(struct net, ipv4.sysctl_udp_wmem_min),
67ad42a35bSKuniyuki Iwashima .sysctl_rmem_offset = offsetof(struct net, ipv4.sysctl_udp_rmem_min),
68db8dac20SDavid S. Miller .obj_size = sizeof(struct udp6_sock),
69*f5f80e32SEric Dumazet .ipv6_pinfo_offset = offsetof(struct udp6_sock, inet6),
70645ca708SEric Dumazet .h.udp_table = &udplite_table,
71db8dac20SDavid S. Miller };
72db8dac20SDavid S. Miller
73db8dac20SDavid S. Miller static struct inet_protosw udplite6_protosw = {
74db8dac20SDavid S. Miller .type = SOCK_DGRAM,
75db8dac20SDavid S. Miller .protocol = IPPROTO_UDPLITE,
76db8dac20SDavid S. Miller .prot = &udplitev6_prot,
77db8dac20SDavid S. Miller .ops = &inet6_dgram_ops,
78db8dac20SDavid S. Miller .flags = INET_PROTOSW_PERMANENT,
79db8dac20SDavid S. Miller };
80db8dac20SDavid S. Miller
udplitev6_init(void)81db8dac20SDavid S. Miller int __init udplitev6_init(void)
82db8dac20SDavid S. Miller {
83db8dac20SDavid S. Miller int ret;
84db8dac20SDavid S. Miller
85db8dac20SDavid S. Miller ret = inet6_add_protocol(&udplitev6_protocol, IPPROTO_UDPLITE);
86db8dac20SDavid S. Miller if (ret)
87db8dac20SDavid S. Miller goto out;
88db8dac20SDavid S. Miller
89db8dac20SDavid S. Miller ret = inet6_register_protosw(&udplite6_protosw);
90db8dac20SDavid S. Miller if (ret)
91db8dac20SDavid S. Miller goto out_udplitev6_protocol;
92db8dac20SDavid S. Miller out:
93db8dac20SDavid S. Miller return ret;
94db8dac20SDavid S. Miller
95db8dac20SDavid S. Miller out_udplitev6_protocol:
96db8dac20SDavid S. Miller inet6_del_protocol(&udplitev6_protocol, IPPROTO_UDPLITE);
97db8dac20SDavid S. Miller goto out;
98db8dac20SDavid S. Miller }
99db8dac20SDavid S. Miller
udplitev6_exit(void)100db8dac20SDavid S. Miller void udplitev6_exit(void)
101db8dac20SDavid S. Miller {
102db8dac20SDavid S. Miller inet6_unregister_protosw(&udplite6_protosw);
103db8dac20SDavid S. Miller inet6_del_protocol(&udplitev6_protocol, IPPROTO_UDPLITE);
104db8dac20SDavid S. Miller }
105db8dac20SDavid S. Miller
106db8dac20SDavid S. Miller #ifdef CONFIG_PROC_FS
107db8dac20SDavid S. Miller static struct udp_seq_afinfo udplite6_seq_afinfo = {
108db8dac20SDavid S. Miller .family = AF_INET6,
109645ca708SEric Dumazet .udp_table = &udplite_table,
110db8dac20SDavid S. Miller };
111db8dac20SDavid S. Miller
udplite6_proc_init_net(struct net * net)1122c8c1e72SAlexey Dobriyan static int __net_init udplite6_proc_init_net(struct net *net)
11384c375afSPavel Emelyanov {
114c3506372SChristoph Hellwig if (!proc_create_net_data("udplite6", 0444, net->proc_net,
115c3506372SChristoph Hellwig &udp6_seq_ops, sizeof(struct udp_iter_state),
116c3506372SChristoph Hellwig &udplite6_seq_afinfo))
117a3d2599bSChristoph Hellwig return -ENOMEM;
118a3d2599bSChristoph Hellwig return 0;
11984c375afSPavel Emelyanov }
12084c375afSPavel Emelyanov
udplite6_proc_exit_net(struct net * net)1212c8c1e72SAlexey Dobriyan static void __net_exit udplite6_proc_exit_net(struct net *net)
12284c375afSPavel Emelyanov {
123a3d2599bSChristoph Hellwig remove_proc_entry("udplite6", net->proc_net);
12484c375afSPavel Emelyanov }
12584c375afSPavel Emelyanov
12684c375afSPavel Emelyanov static struct pernet_operations udplite6_net_ops = {
12784c375afSPavel Emelyanov .init = udplite6_proc_init_net,
12884c375afSPavel Emelyanov .exit = udplite6_proc_exit_net,
12984c375afSPavel Emelyanov };
13084c375afSPavel Emelyanov
udplite6_proc_init(void)131db8dac20SDavid S. Miller int __init udplite6_proc_init(void)
132db8dac20SDavid S. Miller {
13384c375afSPavel Emelyanov return register_pernet_subsys(&udplite6_net_ops);
134db8dac20SDavid S. Miller }
135db8dac20SDavid S. Miller
udplite6_proc_exit(void)136db8dac20SDavid S. Miller void udplite6_proc_exit(void)
137db8dac20SDavid S. Miller {
13884c375afSPavel Emelyanov unregister_pernet_subsys(&udplite6_net_ops);
139db8dac20SDavid S. Miller }
140db8dac20SDavid S. Miller #endif
141