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