GNU Linux-libre 5.15.137-gnu
[releases.git] / net / ipv6 / udplite.c
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 #include <linux/export.h>
12 #include <linux/proc_fs.h>
13 #include "udp_impl.h"
14
15 static int udplitev6_sk_init(struct sock *sk)
16 {
17         udpv6_init_sock(sk);
18         udp_sk(sk)->pcflag = UDPLITE_BIT;
19         return 0;
20 }
21
22 static int udplitev6_rcv(struct sk_buff *skb)
23 {
24         return __udp6_lib_rcv(skb, &udplite_table, IPPROTO_UDPLITE);
25 }
26
27 static int udplitev6_err(struct sk_buff *skb,
28                           struct inet6_skb_parm *opt,
29                           u8 type, u8 code, int offset, __be32 info)
30 {
31         return __udp6_lib_err(skb, opt, type, code, offset, info,
32                               &udplite_table);
33 }
34
35 static const struct inet6_protocol udplitev6_protocol = {
36         .handler        =       udplitev6_rcv,
37         .err_handler    =       udplitev6_err,
38         .flags          =       INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
39 };
40
41 struct proto udplitev6_prot = {
42         .name              = "UDPLITEv6",
43         .owner             = THIS_MODULE,
44         .close             = udp_lib_close,
45         .connect           = ip6_datagram_connect,
46         .disconnect        = udp_disconnect,
47         .ioctl             = udp_ioctl,
48         .init              = udplitev6_sk_init,
49         .destroy           = udpv6_destroy_sock,
50         .setsockopt        = udpv6_setsockopt,
51         .getsockopt        = udpv6_getsockopt,
52         .sendmsg           = udpv6_sendmsg,
53         .recvmsg           = udpv6_recvmsg,
54         .hash              = udp_lib_hash,
55         .unhash            = udp_lib_unhash,
56         .rehash            = udp_v6_rehash,
57         .get_port          = udp_v6_get_port,
58         .memory_allocated  = &udp_memory_allocated,
59         .sysctl_mem        = sysctl_udp_mem,
60         .sysctl_wmem_offset = offsetof(struct net, ipv4.sysctl_udp_wmem_min),
61         .sysctl_rmem_offset = offsetof(struct net, ipv4.sysctl_udp_rmem_min),
62         .obj_size          = sizeof(struct udp6_sock),
63         .h.udp_table       = &udplite_table,
64 };
65
66 static struct inet_protosw udplite6_protosw = {
67         .type           = SOCK_DGRAM,
68         .protocol       = IPPROTO_UDPLITE,
69         .prot           = &udplitev6_prot,
70         .ops            = &inet6_dgram_ops,
71         .flags          = INET_PROTOSW_PERMANENT,
72 };
73
74 int __init udplitev6_init(void)
75 {
76         int ret;
77
78         ret = inet6_add_protocol(&udplitev6_protocol, IPPROTO_UDPLITE);
79         if (ret)
80                 goto out;
81
82         ret = inet6_register_protosw(&udplite6_protosw);
83         if (ret)
84                 goto out_udplitev6_protocol;
85 out:
86         return ret;
87
88 out_udplitev6_protocol:
89         inet6_del_protocol(&udplitev6_protocol, IPPROTO_UDPLITE);
90         goto out;
91 }
92
93 void udplitev6_exit(void)
94 {
95         inet6_unregister_protosw(&udplite6_protosw);
96         inet6_del_protocol(&udplitev6_protocol, IPPROTO_UDPLITE);
97 }
98
99 #ifdef CONFIG_PROC_FS
100 static struct udp_seq_afinfo udplite6_seq_afinfo = {
101         .family         = AF_INET6,
102         .udp_table      = &udplite_table,
103 };
104
105 static int __net_init udplite6_proc_init_net(struct net *net)
106 {
107         if (!proc_create_net_data("udplite6", 0444, net->proc_net,
108                         &udp6_seq_ops, sizeof(struct udp_iter_state),
109                         &udplite6_seq_afinfo))
110                 return -ENOMEM;
111         return 0;
112 }
113
114 static void __net_exit udplite6_proc_exit_net(struct net *net)
115 {
116         remove_proc_entry("udplite6", net->proc_net);
117 }
118
119 static struct pernet_operations udplite6_net_ops = {
120         .init = udplite6_proc_init_net,
121         .exit = udplite6_proc_exit_net,
122 };
123
124 int __init udplite6_proc_init(void)
125 {
126         return register_pernet_subsys(&udplite6_net_ops);
127 }
128
129 void udplite6_proc_exit(void)
130 {
131         unregister_pernet_subsys(&udplite6_net_ops);
132 }
133 #endif