udplite.c 2.9 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0-or-later
2 3 4 5 6 7 8 9
/*
 *  UDPLITE     An implementation of the UDP-Lite protocol (RFC 3828).
 *
 *  Authors:    Gerrit Renker       <gerrit@erg.abdn.ac.uk>
 *
 *  Changes:
 *  Fixes:
 */
10 11 12

#define pr_fmt(fmt) "UDPLite: " fmt

13
#include <linux/export.h>
14
#include <linux/proc_fs.h>
15 16
#include "udp_impl.h"

17
struct udp_table 	udplite_table __read_mostly;
18
EXPORT_SYMBOL(udplite_table);
19

A
Adrian Bunk 已提交
20
static int udplite_rcv(struct sk_buff *skb)
21
{
22
	return __udp4_lib_rcv(skb, &udplite_table, IPPROTO_UDPLITE);
23 24
}

25
static int udplite_err(struct sk_buff *skb, u32 info)
26
{
27
	return __udp4_lib_err(skb, info, &udplite_table);
28 29
}

30
static const struct net_protocol udplite_protocol = {
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
	.handler	= udplite_rcv,
	.err_handler	= udplite_err,
	.no_policy	= 1,
};

struct proto 	udplite_prot = {
	.name		   = "UDP-Lite",
	.owner		   = THIS_MODULE,
	.close		   = udp_lib_close,
	.connect	   = ip4_datagram_connect,
	.disconnect	   = udp_disconnect,
	.ioctl		   = udp_ioctl,
	.init		   = udplite_sk_init,
	.destroy	   = udp_destroy_sock,
	.setsockopt	   = udp_setsockopt,
	.getsockopt	   = udp_getsockopt,
	.sendmsg	   = udp_sendmsg,
	.recvmsg	   = udp_recvmsg,
	.sendpage	   = udp_sendpage,
	.hash		   = udp_lib_hash,
	.unhash		   = udp_lib_unhash,
52
	.rehash		   = udp_v4_rehash,
53
	.get_port	   = udp_v4_get_port,
54

55
	.memory_allocated  = &udp_memory_allocated,
56 57
	.per_cpu_fw_alloc  = &udp_memory_per_cpu_fw_alloc,

58
	.sysctl_mem	   = sysctl_udp_mem,
59
	.obj_size	   = sizeof(struct udp_sock),
60
	.h.udp_table	   = &udplite_table,
61
};
E
Eric Dumazet 已提交
62
EXPORT_SYMBOL(udplite_prot);
63 64 65 66 67 68 69 70 71 72 73 74

static struct inet_protosw udplite4_protosw = {
	.type		=  SOCK_DGRAM,
	.protocol	=  IPPROTO_UDPLITE,
	.prot		=  &udplite_prot,
	.ops		=  &inet_dgram_ops,
	.flags		=  INET_PROTOSW_PERMANENT,
};

#ifdef CONFIG_PROC_FS
static struct udp_seq_afinfo udplite4_seq_afinfo = {
	.family		= AF_INET,
75
	.udp_table 	= &udplite_table,
76
};
77

78
static int __net_init udplite4_proc_init_net(struct net *net)
79
{
80 81
	if (!proc_create_net_data("udplite", 0444, net->proc_net, &udp_seq_ops,
			sizeof(struct udp_iter_state), &udplite4_seq_afinfo))
82 83
		return -ENOMEM;
	return 0;
84 85
}

86
static void __net_exit udplite4_proc_exit_net(struct net *net)
87
{
88
	remove_proc_entry("udplite", net->proc_net);
89 90 91 92 93 94 95
}

static struct pernet_operations udplite4_net_ops = {
	.init = udplite4_proc_init_net,
	.exit = udplite4_proc_exit_net,
};

96 97
static __init int udplite4_proc_init(void)
{
98
	return register_pernet_subsys(&udplite4_net_ops);
99 100 101 102 103 104
}
#else
static inline int udplite4_proc_init(void)
{
	return 0;
}
105 106 107 108
#endif

void __init udplite4_register(void)
{
109
	udp_table_init(&udplite_table, "UDP-Lite");
110 111 112 113 114 115 116 117
	if (proto_register(&udplite_prot, 1))
		goto out_register_err;

	if (inet_add_protocol(&udplite_protocol, IPPROTO_UDPLITE) < 0)
		goto out_unregister_proto;

	inet_register_protosw(&udplite4_protosw);

118
	if (udplite4_proc_init())
J
Joe Perches 已提交
119
		pr_err("%s: Cannot register /proc!\n", __func__);
120 121 122 123 124
	return;

out_unregister_proto:
	proto_unregister(&udplite_prot);
out_register_err:
J
Joe Perches 已提交
125
	pr_crit("%s: Cannot add UDP-Lite protocol\n", __func__);
126
}