Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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)  * udp_diag.c	Module for monitoring UDP transport protocols sockets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Authors:	Pavel Emelyanov, <xemul@parallels.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/inet_diag.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/udp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <net/udp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <net/udplite.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/sock_diag.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) static int sk_diag_dump(struct sock *sk, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 			struct netlink_callback *cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 			const struct inet_diag_req_v2 *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 			struct nlattr *bc, bool net_admin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	if (!inet_diag_bc_sk(bc, sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	return inet_sk_diag_fill(sk, NULL, skb, cb, req, NLM_F_MULTI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 				 net_admin);
^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 int udp_dump_one(struct udp_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 			struct netlink_callback *cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 			const struct inet_diag_req_v2 *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct sk_buff *in_skb = cb->skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	int err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct sock *sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct sk_buff *rep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct net *net = sock_net(in_skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (req->sdiag_family == AF_INET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		/* src and dst are swapped for historical reasons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		sk = __udp4_lib_lookup(net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 				req->id.idiag_src[0], req->id.idiag_sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 				req->id.idiag_dst[0], req->id.idiag_dport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 				req->id.idiag_if, 0, tbl, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	else if (req->sdiag_family == AF_INET6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		sk = __udp6_lib_lookup(net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 				(struct in6_addr *)req->id.idiag_src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 				req->id.idiag_sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 				(struct in6_addr *)req->id.idiag_dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 				req->id.idiag_dport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 				req->id.idiag_if, 0, tbl, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (sk && !refcount_inc_not_zero(&sk->sk_refcnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	if (!sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		goto out_nosk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	err = sock_diag_check_cookie(sk, req->id.idiag_cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	rep = nlmsg_new(nla_total_size(sizeof(struct inet_diag_msg)) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			inet_diag_msg_attrs_size() +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			nla_total_size(sizeof(struct inet_diag_meminfo)) + 64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 			GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	if (!rep)
^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) 	err = inet_sk_diag_fill(sk, NULL, rep, cb, req, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 				netlink_net_capable(in_skb, CAP_NET_ADMIN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		WARN_ON(err == -EMSGSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		kfree_skb(rep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	err = netlink_unicast(net->diag_nlsk, rep, NETLINK_CB(in_skb).portid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 			      MSG_DONTWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	if (err > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	if (sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) out_nosk:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static void udp_dump(struct udp_table *table, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		     struct netlink_callback *cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		     const struct inet_diag_req_v2 *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	bool net_admin = netlink_net_capable(cb->skb, CAP_NET_ADMIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct net *net = sock_net(skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	struct inet_diag_dump_data *cb_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	int num, s_num, slot, s_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	struct nlattr *bc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	cb_data = cb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	bc = cb_data->inet_diag_nla_bc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	s_slot = cb->args[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	num = s_num = cb->args[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	for (slot = s_slot; slot <= table->mask; s_num = 0, slot++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		struct udp_hslot *hslot = &table->hash[slot];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		if (hlist_empty(&hslot->head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		spin_lock_bh(&hslot->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		sk_for_each(sk, &hslot->head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			struct inet_sock *inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			if (!net_eq(sock_net(sk), net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			if (num < s_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 				goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			if (!(r->idiag_states & (1 << sk->sk_state)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 				goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			if (r->sdiag_family != AF_UNSPEC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 					sk->sk_family != r->sdiag_family)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 				goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			if (r->id.idiag_sport != inet->inet_sport &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			    r->id.idiag_sport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 				goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			if (r->id.idiag_dport != inet->inet_dport &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			    r->id.idiag_dport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 				goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			if (sk_diag_dump(sk, skb, cb, r, bc, net_admin) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 				spin_unlock_bh(&hslot->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 				goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) next:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		spin_unlock_bh(&hslot->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	cb->args[0] = slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	cb->args[1] = num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static void udp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			  const struct inet_diag_req_v2 *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	udp_dump(&udp_table, skb, cb, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static int udp_diag_dump_one(struct netlink_callback *cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			     const struct inet_diag_req_v2 *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	return udp_dump_one(&udp_table, cb, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static void udp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		void *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	r->idiag_rqueue = udp_rqueue_get(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	r->idiag_wqueue = sk_wmem_alloc_get(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) #ifdef CONFIG_INET_DIAG_DESTROY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static int __udp_diag_destroy(struct sk_buff *in_skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			      const struct inet_diag_req_v2 *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			      struct udp_table *tbl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	struct net *net = sock_net(in_skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	if (req->sdiag_family == AF_INET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		sk = __udp4_lib_lookup(net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 				req->id.idiag_dst[0], req->id.idiag_dport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 				req->id.idiag_src[0], req->id.idiag_sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 				req->id.idiag_if, 0, tbl, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	else if (req->sdiag_family == AF_INET6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		if (ipv6_addr_v4mapped((struct in6_addr *)req->id.idiag_dst) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		    ipv6_addr_v4mapped((struct in6_addr *)req->id.idiag_src))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			sk = __udp4_lib_lookup(net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 					req->id.idiag_dst[3], req->id.idiag_dport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 					req->id.idiag_src[3], req->id.idiag_sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 					req->id.idiag_if, 0, tbl, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			sk = __udp6_lib_lookup(net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 					(struct in6_addr *)req->id.idiag_dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 					req->id.idiag_dport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 					(struct in6_addr *)req->id.idiag_src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 					req->id.idiag_sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 					req->id.idiag_if, 0, tbl, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	if (sk && !refcount_inc_not_zero(&sk->sk_refcnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (!sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	if (sock_diag_check_cookie(sk, req->id.idiag_cookie)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	err = sock_diag_destroy(sk, ECONNABORTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static int udp_diag_destroy(struct sk_buff *in_skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			    const struct inet_diag_req_v2 *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	return __udp_diag_destroy(in_skb, req, &udp_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static int udplite_diag_destroy(struct sk_buff *in_skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 				const struct inet_diag_req_v2 *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	return __udp_diag_destroy(in_skb, req, &udplite_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static const struct inet_diag_handler udp_diag_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	.dump		 = udp_diag_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	.dump_one	 = udp_diag_dump_one,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	.idiag_get_info  = udp_diag_get_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	.idiag_type	 = IPPROTO_UDP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	.idiag_info_size = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) #ifdef CONFIG_INET_DIAG_DESTROY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	.destroy	 = udp_diag_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static void udplite_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			      const struct inet_diag_req_v2 *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	udp_dump(&udplite_table, skb, cb, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static int udplite_diag_dump_one(struct netlink_callback *cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 				 const struct inet_diag_req_v2 *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	return udp_dump_one(&udplite_table, cb, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) static const struct inet_diag_handler udplite_diag_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	.dump		 = udplite_diag_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	.dump_one	 = udplite_diag_dump_one,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	.idiag_get_info  = udp_diag_get_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	.idiag_type	 = IPPROTO_UDPLITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	.idiag_info_size = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) #ifdef CONFIG_INET_DIAG_DESTROY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	.destroy	 = udplite_diag_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static int __init udp_diag_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	err = inet_diag_register(&udp_diag_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	err = inet_diag_register(&udplite_diag_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		goto out_lite;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) out_lite:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	inet_diag_unregister(&udp_diag_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static void __exit udp_diag_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	inet_diag_unregister(&udplite_diag_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	inet_diag_unregister(&udp_diag_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) module_init(udp_diag_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) module_exit(udp_diag_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, 2-17 /* AF_INET - IPPROTO_UDP */);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, 2-136 /* AF_INET - IPPROTO_UDPLITE */);