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 <linux/inet_diag.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/sock_diag.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <net/inet_sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <net/raw.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <net/rawv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #ifdef pr_fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) # undef pr_fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) static struct raw_hashinfo *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) raw_get_hashinfo(const struct inet_diag_req_v2 *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	if (r->sdiag_family == AF_INET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 		return &raw_v4_hashinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	} else if (r->sdiag_family == AF_INET6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 		return &raw_v6_hashinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 		return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * Due to requirement of not breaking user API we can't simply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * rename @pad field in inet_diag_req_v2 structure, instead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * use helper to figure it out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static struct sock *raw_lookup(struct net *net, struct sock *from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 			       const struct inet_diag_req_v2 *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct inet_diag_req_raw *r = (void *)req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct sock *sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	if (r->sdiag_family == AF_INET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		sk = __raw_v4_lookup(net, from, r->sdiag_raw_protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 				     r->id.idiag_dst[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 				     r->id.idiag_src[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 				     r->id.idiag_if, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		sk = __raw_v6_lookup(net, from, r->sdiag_raw_protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 				     (const struct in6_addr *)r->id.idiag_src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 				     (const struct in6_addr *)r->id.idiag_dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 				     r->id.idiag_if, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	return sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static struct sock *raw_sock_get(struct net *net, const struct inet_diag_req_v2 *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct raw_hashinfo *hashinfo = raw_get_hashinfo(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct sock *sk = NULL, *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	int slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	if (IS_ERR(hashinfo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		return ERR_CAST(hashinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	read_lock(&hashinfo->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	for (slot = 0; slot < RAW_HTABLE_SIZE; slot++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		sk_for_each(s, &hashinfo->ht[slot]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 			sk = raw_lookup(net, s, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			if (sk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 				 * Grab it and keep until we fill
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 				 * diag meaage to be reported, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 				 * caller should call sock_put then.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 				 * We can do that because we're keeping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 				 * hashinfo->lock here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 				sock_hold(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 				goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 			}
^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) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	read_unlock(&hashinfo->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	return sk ? sk : ERR_PTR(-ENOENT);
^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) static int raw_diag_dump_one(struct netlink_callback *cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			     const struct inet_diag_req_v2 *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct sk_buff *in_skb = cb->skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	struct sk_buff *rep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct net *net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	net = sock_net(in_skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	sk = raw_sock_get(net, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	if (IS_ERR(sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		return PTR_ERR(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	rep = nlmsg_new(nla_total_size(sizeof(struct inet_diag_msg)) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			inet_diag_msg_attrs_size() +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			nla_total_size(sizeof(struct inet_diag_meminfo)) + 64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (!rep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	err = inet_sk_diag_fill(sk, NULL, rep, cb, r, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 				netlink_net_capable(in_skb, CAP_NET_ADMIN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		kfree_skb(rep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	err = netlink_unicast(net->diag_nlsk, rep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			      NETLINK_CB(in_skb).portid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			      MSG_DONTWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (err > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static int sk_diag_dump(struct sock *sk, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			struct netlink_callback *cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			const struct inet_diag_req_v2 *r,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			struct nlattr *bc, bool net_admin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if (!inet_diag_bc_sk(bc, sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	return inet_sk_diag_fill(sk, NULL, skb, cb, r, NLM_F_MULTI, net_admin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static void raw_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			  const struct inet_diag_req_v2 *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	bool net_admin = netlink_net_capable(cb->skb, CAP_NET_ADMIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	struct raw_hashinfo *hashinfo = raw_get_hashinfo(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct net *net = sock_net(skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	struct inet_diag_dump_data *cb_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	int num, s_num, slot, s_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	struct sock *sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	struct nlattr *bc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (IS_ERR(hashinfo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	cb_data = cb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	bc = cb_data->inet_diag_nla_bc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	s_slot = cb->args[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	num = s_num = cb->args[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	read_lock(&hashinfo->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	for (slot = s_slot; slot < RAW_HTABLE_SIZE; s_num = 0, slot++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		sk_for_each(sk, &hashinfo->ht[slot]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			struct inet_sock *inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			if (!net_eq(sock_net(sk), net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			if (num < s_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 				goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			if (sk->sk_family != r->sdiag_family)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 				goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			if (r->id.idiag_sport != inet->inet_sport &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			    r->id.idiag_sport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 				goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			if (r->id.idiag_dport != inet->inet_dport &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			    r->id.idiag_dport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 				goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			if (sk_diag_dump(sk, skb, cb, r, bc, net_admin) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 				goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) next:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	read_unlock(&hashinfo->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	cb->args[0] = slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	cb->args[1] = num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static void raw_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			      void *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	r->idiag_rqueue = sk_rmem_alloc_get(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	r->idiag_wqueue = sk_wmem_alloc_get(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #ifdef CONFIG_INET_DIAG_DESTROY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static int raw_diag_destroy(struct sk_buff *in_skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			    const struct inet_diag_req_v2 *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	struct net *net = sock_net(in_skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	sk = raw_sock_get(net, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	if (IS_ERR(sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		return PTR_ERR(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	err = sock_diag_destroy(sk, ECONNABORTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static const struct inet_diag_handler raw_diag_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	.dump			= raw_diag_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	.dump_one		= raw_diag_dump_one,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	.idiag_get_info		= raw_diag_get_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	.idiag_type		= IPPROTO_RAW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	.idiag_info_size	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) #ifdef CONFIG_INET_DIAG_DESTROY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	.destroy		= raw_diag_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static void __always_unused __check_inet_diag_req_raw(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	 * Make sure the two structures are identical,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	 * except the @pad field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) #define __offset_mismatch(m1, m2)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	(offsetof(struct inet_diag_req_v2, m1) !=	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	 offsetof(struct inet_diag_req_raw, m2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	BUILD_BUG_ON(sizeof(struct inet_diag_req_v2) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		     sizeof(struct inet_diag_req_raw));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	BUILD_BUG_ON(__offset_mismatch(sdiag_family, sdiag_family));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	BUILD_BUG_ON(__offset_mismatch(sdiag_protocol, sdiag_protocol));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	BUILD_BUG_ON(__offset_mismatch(idiag_ext, idiag_ext));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	BUILD_BUG_ON(__offset_mismatch(pad, sdiag_raw_protocol));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	BUILD_BUG_ON(__offset_mismatch(idiag_states, idiag_states));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	BUILD_BUG_ON(__offset_mismatch(id, id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #undef __offset_mismatch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static int __init raw_diag_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	return inet_diag_register(&raw_diag_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static void __exit raw_diag_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	inet_diag_unregister(&raw_diag_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) module_init(raw_diag_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) module_exit(raw_diag_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, 2-255 /* AF_INET - IPPROTO_RAW */);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, 10-255 /* AF_INET6 - IPPROTO_RAW */);