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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * net/tipc/subscr.c: TIPC network topology service
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (c) 2000-2017, Ericsson AB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2005-2007, 2010-2013, Wind River Systems
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Redistribution and use in source and binary forms, with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * modification, are permitted provided that the following conditions are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * 1. Redistributions of source code must retain the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *    notice, this list of conditions and the following disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * 2. Redistributions in binary form must reproduce the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *    notice, this list of conditions and the following disclaimer in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *    documentation and/or other materials provided with the distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * 3. Neither the names of the copyright holders nor the names of its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *    contributors may be used to endorse or promote products derived from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *    this software without specific prior written permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * Alternatively, this software may be distributed under the terms of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * GNU General Public License ("GPL") version 2 as published by the Free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * POSSIBILITY OF SUCH DAMAGE.
^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) #include "core.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include "name_table.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include "subscr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static void tipc_sub_send_event(struct tipc_subscription *sub,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 				u32 found_lower, u32 found_upper,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 				u32 event, u32 port, u32 node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	struct tipc_event *evt = &sub->evt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	if (sub->inactive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	tipc_evt_write(evt, event, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	tipc_evt_write(evt, found_lower, found_lower);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	tipc_evt_write(evt, found_upper, found_upper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	tipc_evt_write(evt, port.ref, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	tipc_evt_write(evt, port.node, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	tipc_topsrv_queue_evt(sub->net, sub->conid, event, evt);
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * tipc_sub_check_overlap - test for subscription overlap with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * given values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * Returns 1 if there is overlap, otherwise 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) int tipc_sub_check_overlap(struct tipc_name_seq *seq, u32 found_lower,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			   u32 found_upper)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (found_lower < seq->lower)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		found_lower = seq->lower;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	if (found_upper > seq->upper)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		found_upper = seq->upper;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	if (found_lower > found_upper)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) void tipc_sub_report_overlap(struct tipc_subscription *sub,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			     u32 found_lower, u32 found_upper,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			     u32 event, u32 port, u32 node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			     u32 scope, int must)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	struct tipc_subscr *s = &sub->evt.s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	u32 filter = tipc_sub_read(s, filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct tipc_name_seq seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	seq.type = tipc_sub_read(s, seq.type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	seq.lower = tipc_sub_read(s, seq.lower);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	seq.upper = tipc_sub_read(s, seq.upper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (!tipc_sub_check_overlap(&seq, found_lower, found_upper))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	if (!must && !(filter & TIPC_SUB_PORTS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (filter & TIPC_SUB_CLUSTER_SCOPE && scope == TIPC_NODE_SCOPE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (filter & TIPC_SUB_NODE_SCOPE && scope != TIPC_NODE_SCOPE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	spin_lock(&sub->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	tipc_sub_send_event(sub, found_lower, found_upper,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			    event, port, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	spin_unlock(&sub->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static void tipc_sub_timeout(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	struct tipc_subscription *sub = from_timer(sub, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	struct tipc_subscr *s = &sub->evt.s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	spin_lock(&sub->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	tipc_sub_send_event(sub, s->seq.lower, s->seq.upper,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			    TIPC_SUBSCR_TIMEOUT, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	sub->inactive = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	spin_unlock(&sub->lock);
^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) static void tipc_sub_kref_release(struct kref *kref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	kfree(container_of(kref, struct tipc_subscription, kref));
^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 tipc_sub_put(struct tipc_subscription *subscription)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	kref_put(&subscription->kref, tipc_sub_kref_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) void tipc_sub_get(struct tipc_subscription *subscription)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	kref_get(&subscription->kref);
^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) struct tipc_subscription *tipc_sub_subscribe(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 					     struct tipc_subscr *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 					     int conid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	u32 filter = tipc_sub_read(s, filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	struct tipc_subscription *sub;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	u32 timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if ((filter & TIPC_SUB_PORTS && filter & TIPC_SUB_SERVICE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	    (tipc_sub_read(s, seq.lower) > tipc_sub_read(s, seq.upper))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		pr_warn("Subscription rejected, illegal request\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	sub = kmalloc(sizeof(*sub), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (!sub) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		pr_warn("Subscription rejected, no memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	INIT_LIST_HEAD(&sub->service_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	INIT_LIST_HEAD(&sub->sub_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	sub->net = net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	sub->conid = conid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	sub->inactive = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	memcpy(&sub->evt.s, s, sizeof(*s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	spin_lock_init(&sub->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	kref_init(&sub->kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	if (!tipc_nametbl_subscribe(sub)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		kfree(sub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	timer_setup(&sub->timer, tipc_sub_timeout, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	timeout = tipc_sub_read(&sub->evt.s, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (timeout != TIPC_WAIT_FOREVER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		mod_timer(&sub->timer, jiffies + msecs_to_jiffies(timeout));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	return sub;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) void tipc_sub_unsubscribe(struct tipc_subscription *sub)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	tipc_nametbl_unsubscribe(sub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	if (sub->evt.s.timeout != TIPC_WAIT_FOREVER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		del_timer_sync(&sub->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	list_del(&sub->sub_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	tipc_sub_put(sub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }