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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/netlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/sock_diag.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/netlink_diag.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/rhashtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "af_netlink.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) static int sk_diag_dump_groups(struct sock *sk, struct sk_buff *nlskb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 	struct netlink_sock *nlk = nlk_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	if (nlk->groups == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	return nla_put(nlskb, NETLINK_DIAG_GROUPS, NLGRPSZ(nlk->ngroups),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 		       nlk->groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static int sk_diag_put_flags(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	struct netlink_sock *nlk = nlk_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	u32 flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	if (nlk->cb_running)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		flags |= NDIAG_FLAG_CB_RUNNING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	if (nlk->flags & NETLINK_F_RECV_PKTINFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		flags |= NDIAG_FLAG_PKTINFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	if (nlk->flags & NETLINK_F_BROADCAST_SEND_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		flags |= NDIAG_FLAG_BROADCAST_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	if (nlk->flags & NETLINK_F_RECV_NO_ENOBUFS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		flags |= NDIAG_FLAG_NO_ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	if (nlk->flags & NETLINK_F_LISTEN_ALL_NSID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		flags |= NDIAG_FLAG_LISTEN_ALL_NSID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	if (nlk->flags & NETLINK_F_CAP_ACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		flags |= NDIAG_FLAG_CAP_ACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	return nla_put_u32(skb, NETLINK_DIAG_FLAGS, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static int sk_diag_fill(struct sock *sk, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 			struct netlink_diag_req *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			u32 portid, u32 seq, u32 flags, int sk_ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct nlmsghdr *nlh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	struct netlink_diag_msg *rep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct netlink_sock *nlk = nlk_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	nlh = nlmsg_put(skb, portid, seq, SOCK_DIAG_BY_FAMILY, sizeof(*rep),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 			flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (!nlh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	rep = nlmsg_data(nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	rep->ndiag_family	= AF_NETLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	rep->ndiag_type		= sk->sk_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	rep->ndiag_protocol	= sk->sk_protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	rep->ndiag_state	= sk->sk_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	rep->ndiag_ino		= sk_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	rep->ndiag_portid	= nlk->portid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	rep->ndiag_dst_portid	= nlk->dst_portid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	rep->ndiag_dst_group	= nlk->dst_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	sock_diag_save_cookie(sk, rep->ndiag_cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	if ((req->ndiag_show & NDIAG_SHOW_GROUPS) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	    sk_diag_dump_groups(sk, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		goto out_nlmsg_trim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if ((req->ndiag_show & NDIAG_SHOW_MEMINFO) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	    sock_diag_put_meminfo(sk, skb, NETLINK_DIAG_MEMINFO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		goto out_nlmsg_trim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if ((req->ndiag_show & NDIAG_SHOW_FLAGS) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	    sk_diag_put_flags(sk, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		goto out_nlmsg_trim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	nlmsg_end(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) out_nlmsg_trim:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	nlmsg_cancel(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static int __netlink_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 				int protocol, int s_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct rhashtable_iter *hti = (void *)cb->args[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct netlink_table *tbl = &nl_table[protocol];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	struct net *net = sock_net(skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	struct netlink_diag_req *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct netlink_sock *nlsk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	int num = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	req = nlmsg_data(cb->nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	if (s_num > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		goto mc_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	num--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (!hti) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		hti = kmalloc(sizeof(*hti), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		if (!hti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		cb->args[2] = (long)hti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	if (!s_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		rhashtable_walk_enter(&tbl->hash, hti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	rhashtable_walk_start(hti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	while ((nlsk = rhashtable_walk_next(hti))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		if (IS_ERR(nlsk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			ret = PTR_ERR(nlsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			if (ret == -EAGAIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 				ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		sk = (struct sock *)nlsk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		if (!net_eq(sock_net(sk), net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		if (sk_diag_fill(sk, skb, req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 				 NETLINK_CB(cb->skb).portid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 				 cb->nlh->nlmsg_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 				 NLM_F_MULTI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 				 sock_i_ino(sk)) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	rhashtable_walk_stop(hti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	rhashtable_walk_exit(hti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) mc_list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	read_lock(&nl_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	sk_for_each_bound(sk, &tbl->mc_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		if (sk_hashed(sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		if (!net_eq(sock_net(sk), net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		if (num < s_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		if (sk_diag_fill(sk, skb, req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 				 NETLINK_CB(cb->skb).portid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 				 cb->nlh->nlmsg_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 				 NLM_F_MULTI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 				 sock_i_ino(sk)) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	read_unlock(&nl_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	cb->args[0] = num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static int netlink_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	struct netlink_diag_req *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	int s_num = cb->args[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	req = nlmsg_data(cb->nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (req->sdiag_protocol == NDIAG_PROTO_ALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		for (i = cb->args[1]; i < MAX_LINKS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			err = __netlink_diag_dump(skb, cb, i, s_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			s_num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		cb->args[1] = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		if (req->sdiag_protocol >= MAX_LINKS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		err = __netlink_diag_dump(skb, cb, req->sdiag_protocol, s_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	return err < 0 ? err : skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static int netlink_diag_dump_done(struct netlink_callback *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	struct rhashtable_iter *hti = (void *)cb->args[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (cb->args[0] == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		rhashtable_walk_exit(hti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	kfree(hti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) static int netlink_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	int hdrlen = sizeof(struct netlink_diag_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	struct net *net = sock_net(skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (nlmsg_len(h) < hdrlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (h->nlmsg_flags & NLM_F_DUMP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		struct netlink_dump_control c = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			.dump = netlink_diag_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			.done = netlink_diag_dump_done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		return netlink_dump_start(net->diag_nlsk, skb, h, &c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static const struct sock_diag_handler netlink_diag_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	.family = AF_NETLINK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	.dump = netlink_diag_handler_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static int __init netlink_diag_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	return sock_diag_register(&netlink_diag_handler);
^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 __exit netlink_diag_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	sock_diag_unregister(&netlink_diag_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) module_init(netlink_diag_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) module_exit(netlink_diag_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, 16 /* AF_NETLINK */);