2006-01-02 18:04:38 +00:00
|
|
|
/*
|
2008-05-19 20:30:13 +00:00
|
|
|
* net/tipc/subscr.c: TIPC network topology service
|
2007-02-09 14:25:21 +00:00
|
|
|
*
|
2006-01-11 18:14:19 +00:00
|
|
|
* Copyright (c) 2000-2006, Ericsson AB
|
2011-01-07 16:43:40 +00:00
|
|
|
* Copyright (c) 2005-2007, 2010-2011, Wind River Systems
|
2006-01-02 18:04:38 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2006-01-11 12:30:43 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
2006-01-02 18:04:38 +00:00
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
2006-01-11 12:30:43 +00:00
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the names of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
2006-01-02 18:04:38 +00:00
|
|
|
*
|
2006-01-11 12:30:43 +00:00
|
|
|
* Alternatively, this software may be distributed under the terms of the
|
|
|
|
* GNU General Public License ("GPL") version 2 as published by the Free
|
|
|
|
* Software Foundation.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
2006-01-02 18:04:38 +00:00
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "core.h"
|
|
|
|
#include "name_table.h"
|
2010-12-31 18:59:21 +00:00
|
|
|
#include "port.h"
|
2008-05-19 20:30:13 +00:00
|
|
|
#include "subscr.h"
|
2006-01-02 18:04:38 +00:00
|
|
|
|
|
|
|
/**
|
2011-12-30 01:49:39 +00:00
|
|
|
* struct tipc_subscriber - TIPC network topology subscriber
|
2008-05-19 20:29:47 +00:00
|
|
|
* @port_ref: object reference to server port connecting to subscriber
|
|
|
|
* @lock: pointer to spinlock controlling access to subscriber's server port
|
2006-01-02 18:04:38 +00:00
|
|
|
* @subscriber_list: adjacent subscribers in top. server's list of subscribers
|
|
|
|
* @subscription_list: list of subscription objects for this subscriber
|
|
|
|
*/
|
2011-12-30 01:49:39 +00:00
|
|
|
struct tipc_subscriber {
|
2008-05-19 20:29:47 +00:00
|
|
|
u32 port_ref;
|
2007-02-09 14:25:21 +00:00
|
|
|
spinlock_t *lock;
|
2006-01-02 18:04:38 +00:00
|
|
|
struct list_head subscriber_list;
|
|
|
|
struct list_head subscription_list;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct top_srv - TIPC network topology subscription service
|
|
|
|
* @setup_port: reference to TIPC port that handles subscription requests
|
|
|
|
* @subscription_count: number of active subscriptions (not subscribers!)
|
|
|
|
* @subscriber_list: list of ports subscribing to service
|
|
|
|
* @lock: spinlock govering access to subscriber list
|
|
|
|
*/
|
|
|
|
struct top_srv {
|
|
|
|
u32 setup_port;
|
|
|
|
atomic_t subscription_count;
|
|
|
|
struct list_head subscriber_list;
|
|
|
|
spinlock_t lock;
|
|
|
|
};
|
|
|
|
|
2010-12-31 18:59:34 +00:00
|
|
|
static struct top_srv topsrv;
|
2006-01-02 18:04:38 +00:00
|
|
|
|
2010-10-21 01:06:16 +00:00
|
|
|
/**
|
|
|
|
* htohl - convert value to endianness used by destination
|
|
|
|
* @in: value to convert
|
|
|
|
* @swap: non-zero if endianness must be reversed
|
|
|
|
*
|
|
|
|
* Returns converted value
|
|
|
|
*/
|
|
|
|
static u32 htohl(u32 in, int swap)
|
|
|
|
{
|
|
|
|
return swap ? swab32(in) : in;
|
|
|
|
}
|
|
|
|
|
2006-01-02 18:04:38 +00:00
|
|
|
/**
|
|
|
|
* subscr_send_event - send a message containing a tipc_event to the subscriber
|
2008-05-19 20:29:47 +00:00
|
|
|
*
|
|
|
|
* Note: Must not hold subscriber's server port lock, since tipc_send() will
|
|
|
|
* try to take the lock if the message is rejected and returned!
|
2006-01-02 18:04:38 +00:00
|
|
|
*/
|
2011-12-30 01:43:44 +00:00
|
|
|
static void subscr_send_event(struct tipc_subscription *sub,
|
2007-02-09 14:25:21 +00:00
|
|
|
u32 found_lower,
|
2006-01-02 18:04:38 +00:00
|
|
|
u32 found_upper,
|
2007-02-09 14:25:21 +00:00
|
|
|
u32 event,
|
|
|
|
u32 port_ref,
|
2006-01-02 18:04:38 +00:00
|
|
|
u32 node)
|
|
|
|
{
|
|
|
|
struct iovec msg_sect;
|
|
|
|
|
|
|
|
msg_sect.iov_base = (void *)&sub->evt;
|
|
|
|
msg_sect.iov_len = sizeof(struct tipc_event);
|
|
|
|
|
2010-10-21 01:06:16 +00:00
|
|
|
sub->evt.event = htohl(event, sub->swap);
|
|
|
|
sub->evt.found_lower = htohl(found_lower, sub->swap);
|
|
|
|
sub->evt.found_upper = htohl(found_upper, sub->swap);
|
|
|
|
sub->evt.port.ref = htohl(port_ref, sub->swap);
|
|
|
|
sub->evt.port.node = htohl(node, sub->swap);
|
tipc: Avoid recomputation of outgoing message length
Rework TIPC's message sending routines to take advantage of the total
amount of data value passed to it by the kernel socket infrastructure.
This change eliminates the need for TIPC to compute the size of outgoing
messages itself, as well as the check for an oversize message in
tipc_msg_build(). In addition, this change warrants an explanation:
- res = send_packet(NULL, sock, &my_msg, 0);
+ res = send_packet(NULL, sock, &my_msg, bytes_to_send);
Previously, the final argument to send_packet() was ignored (since the
amount of data being sent was recalculated by a lower-level routine)
and we could just pass in a dummy value (0). Now that the
recalculation is being eliminated, the argument value being passed to
send_packet() is significant and we have to supply the actual amount
of data we want to send.
Signed-off-by: Allan Stephens <Allan.Stephens@windriver.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
2011-04-21 15:42:07 +00:00
|
|
|
tipc_send(sub->server_ref, 1, &msg_sect, msg_sect.iov_len);
|
2006-01-02 18:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-01-17 23:38:21 +00:00
|
|
|
* tipc_subscr_overlap - test for subscription overlap with the given values
|
2006-01-02 18:04:38 +00:00
|
|
|
*
|
|
|
|
* Returns 1 if there is overlap, otherwise 0.
|
|
|
|
*/
|
2011-12-30 01:43:44 +00:00
|
|
|
int tipc_subscr_overlap(struct tipc_subscription *sub,
|
2007-02-09 14:25:21 +00:00
|
|
|
u32 found_lower,
|
2006-01-17 23:38:21 +00:00
|
|
|
u32 found_upper)
|
2006-01-02 18:04:38 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
if (found_lower < sub->seq.lower)
|
|
|
|
found_lower = sub->seq.lower;
|
|
|
|
if (found_upper > sub->seq.upper)
|
|
|
|
found_upper = sub->seq.upper;
|
|
|
|
if (found_lower > found_upper)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-01-17 23:38:21 +00:00
|
|
|
* tipc_subscr_report_overlap - issue event if there is subscription overlap
|
2007-02-09 14:25:21 +00:00
|
|
|
*
|
2006-01-02 18:04:38 +00:00
|
|
|
* Protected by nameseq.lock in name_table.c
|
|
|
|
*/
|
2011-12-30 01:43:44 +00:00
|
|
|
void tipc_subscr_report_overlap(struct tipc_subscription *sub,
|
2007-02-09 14:25:21 +00:00
|
|
|
u32 found_lower,
|
2006-01-17 23:38:21 +00:00
|
|
|
u32 found_upper,
|
2007-02-09 14:25:21 +00:00
|
|
|
u32 event,
|
|
|
|
u32 port_ref,
|
2006-01-17 23:38:21 +00:00
|
|
|
u32 node,
|
|
|
|
int must)
|
2006-01-02 18:04:38 +00:00
|
|
|
{
|
2006-01-17 23:38:21 +00:00
|
|
|
if (!tipc_subscr_overlap(sub, found_lower, found_upper))
|
2006-01-02 18:04:38 +00:00
|
|
|
return;
|
2006-10-17 04:59:42 +00:00
|
|
|
if (!must && !(sub->filter & TIPC_SUB_PORTS))
|
2006-01-02 18:04:38 +00:00
|
|
|
return;
|
2008-05-19 20:27:31 +00:00
|
|
|
|
2011-07-19 08:21:56 +00:00
|
|
|
subscr_send_event(sub, found_lower, found_upper, event, port_ref, node);
|
2006-01-02 18:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* subscr_timeout - subscription timeout has occurred
|
|
|
|
*/
|
2011-12-30 01:43:44 +00:00
|
|
|
static void subscr_timeout(struct tipc_subscription *sub)
|
2006-01-02 18:04:38 +00:00
|
|
|
{
|
2011-01-07 16:43:40 +00:00
|
|
|
struct tipc_port *server_port;
|
2006-01-02 18:04:38 +00:00
|
|
|
|
2008-05-19 20:29:47 +00:00
|
|
|
/* Validate server port reference (in case subscriber is terminating) */
|
|
|
|
server_port = tipc_port_lock(sub->server_ref);
|
|
|
|
if (server_port == NULL)
|
2006-01-02 18:04:38 +00:00
|
|
|
return;
|
|
|
|
|
2006-10-17 04:59:42 +00:00
|
|
|
/* Validate timeout (in case subscription is being cancelled) */
|
|
|
|
if (sub->timeout == TIPC_WAIT_FOREVER) {
|
2008-05-19 20:29:47 +00:00
|
|
|
tipc_port_unlock(server_port);
|
2006-10-17 04:59:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-01-02 18:04:38 +00:00
|
|
|
/* Unlink subscription from name table */
|
2006-01-17 23:38:21 +00:00
|
|
|
tipc_nametbl_unsubscribe(sub);
|
2006-01-02 18:04:38 +00:00
|
|
|
|
2008-05-19 20:29:47 +00:00
|
|
|
/* Unlink subscription from subscriber */
|
2006-01-02 18:04:38 +00:00
|
|
|
list_del(&sub->subscription_list);
|
|
|
|
|
2008-05-19 20:29:47 +00:00
|
|
|
/* Release subscriber's server port */
|
|
|
|
tipc_port_unlock(server_port);
|
|
|
|
|
|
|
|
/* Notify subscriber of timeout */
|
|
|
|
subscr_send_event(sub, sub->evt.s.seq.lower, sub->evt.s.seq.upper,
|
|
|
|
TIPC_SUBSCR_TIMEOUT, 0, 0);
|
|
|
|
|
2006-01-02 18:04:38 +00:00
|
|
|
/* Now destroy subscription */
|
|
|
|
k_term_timer(&sub->timer);
|
|
|
|
kfree(sub);
|
|
|
|
atomic_dec(&topsrv.subscription_count);
|
|
|
|
}
|
|
|
|
|
2006-10-17 04:59:42 +00:00
|
|
|
/**
|
|
|
|
* subscr_del - delete a subscription within a subscription list
|
|
|
|
*
|
2008-05-19 20:29:47 +00:00
|
|
|
* Called with subscriber port locked.
|
2006-10-17 04:59:42 +00:00
|
|
|
*/
|
2011-12-30 01:43:44 +00:00
|
|
|
static void subscr_del(struct tipc_subscription *sub)
|
2006-10-17 04:59:42 +00:00
|
|
|
{
|
|
|
|
tipc_nametbl_unsubscribe(sub);
|
|
|
|
list_del(&sub->subscription_list);
|
|
|
|
kfree(sub);
|
|
|
|
atomic_dec(&topsrv.subscription_count);
|
|
|
|
}
|
|
|
|
|
2006-01-02 18:04:38 +00:00
|
|
|
/**
|
|
|
|
* subscr_terminate - terminate communication with a subscriber
|
2007-02-09 14:25:21 +00:00
|
|
|
*
|
2008-05-19 20:29:47 +00:00
|
|
|
* Called with subscriber port locked. Routine must temporarily release lock
|
2007-02-09 14:25:21 +00:00
|
|
|
* to enable subscription timeout routine(s) to finish without deadlocking;
|
2006-01-02 18:04:38 +00:00
|
|
|
* the lock is then reclaimed to allow caller to release it upon return.
|
2007-02-09 14:25:21 +00:00
|
|
|
* (This should work even in the unlikely event some other thread creates
|
2006-01-02 18:04:38 +00:00
|
|
|
* a new object reference in the interim that uses this lock; this routine will
|
|
|
|
* simply wait for it to be released, then claim it.)
|
|
|
|
*/
|
2011-12-30 01:49:39 +00:00
|
|
|
static void subscr_terminate(struct tipc_subscriber *subscriber)
|
2006-01-02 18:04:38 +00:00
|
|
|
{
|
2008-05-19 20:29:47 +00:00
|
|
|
u32 port_ref;
|
2011-12-30 01:43:44 +00:00
|
|
|
struct tipc_subscription *sub;
|
|
|
|
struct tipc_subscription *sub_temp;
|
2006-01-02 18:04:38 +00:00
|
|
|
|
|
|
|
/* Invalidate subscriber reference */
|
2008-05-19 20:29:47 +00:00
|
|
|
port_ref = subscriber->port_ref;
|
|
|
|
subscriber->port_ref = 0;
|
2006-01-02 18:04:38 +00:00
|
|
|
spin_unlock_bh(subscriber->lock);
|
|
|
|
|
2008-05-19 20:29:47 +00:00
|
|
|
/* Sever connection to subscriber */
|
|
|
|
tipc_shutdown(port_ref);
|
|
|
|
tipc_deleteport(port_ref);
|
|
|
|
|
2006-01-02 18:04:38 +00:00
|
|
|
/* Destroy any existing subscriptions for subscriber */
|
|
|
|
list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list,
|
|
|
|
subscription_list) {
|
|
|
|
if (sub->timeout != TIPC_WAIT_FOREVER) {
|
|
|
|
k_cancel_timer(&sub->timer);
|
|
|
|
k_term_timer(&sub->timer);
|
|
|
|
}
|
2006-10-17 04:59:42 +00:00
|
|
|
subscr_del(sub);
|
2006-01-02 18:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove subscriber from topology server's subscriber list */
|
|
|
|
spin_lock_bh(&topsrv.lock);
|
|
|
|
list_del(&subscriber->subscriber_list);
|
|
|
|
spin_unlock_bh(&topsrv.lock);
|
|
|
|
|
2008-05-19 20:29:47 +00:00
|
|
|
/* Reclaim subscriber lock */
|
2006-01-02 18:04:38 +00:00
|
|
|
spin_lock_bh(subscriber->lock);
|
2008-05-19 20:29:47 +00:00
|
|
|
|
|
|
|
/* Now destroy subscriber */
|
2006-01-02 18:04:38 +00:00
|
|
|
kfree(subscriber);
|
|
|
|
}
|
|
|
|
|
2006-10-17 04:59:42 +00:00
|
|
|
/**
|
|
|
|
* subscr_cancel - handle subscription cancellation request
|
|
|
|
*
|
2008-05-19 20:29:47 +00:00
|
|
|
* Called with subscriber port locked. Routine must temporarily release lock
|
2006-10-17 04:59:42 +00:00
|
|
|
* to enable the subscription timeout routine to finish without deadlocking;
|
|
|
|
* the lock is then reclaimed to allow caller to release it upon return.
|
|
|
|
*
|
|
|
|
* Note that fields of 's' use subscriber's endianness!
|
|
|
|
*/
|
|
|
|
static void subscr_cancel(struct tipc_subscr *s,
|
2011-12-30 01:49:39 +00:00
|
|
|
struct tipc_subscriber *subscriber)
|
2006-10-17 04:59:42 +00:00
|
|
|
{
|
2011-12-30 01:43:44 +00:00
|
|
|
struct tipc_subscription *sub;
|
|
|
|
struct tipc_subscription *sub_temp;
|
2006-10-17 04:59:42 +00:00
|
|
|
int found = 0;
|
|
|
|
|
|
|
|
/* Find first matching subscription, exit if not found */
|
|
|
|
list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list,
|
|
|
|
subscription_list) {
|
2010-10-21 01:06:16 +00:00
|
|
|
if (!memcmp(s, &sub->evt.s, sizeof(struct tipc_subscr))) {
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
2006-10-17 04:59:42 +00:00
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Cancel subscription timer (if used), then delete subscription */
|
|
|
|
if (sub->timeout != TIPC_WAIT_FOREVER) {
|
|
|
|
sub->timeout = TIPC_WAIT_FOREVER;
|
|
|
|
spin_unlock_bh(subscriber->lock);
|
|
|
|
k_cancel_timer(&sub->timer);
|
|
|
|
k_term_timer(&sub->timer);
|
|
|
|
spin_lock_bh(subscriber->lock);
|
|
|
|
}
|
|
|
|
subscr_del(sub);
|
|
|
|
}
|
|
|
|
|
2006-01-02 18:04:38 +00:00
|
|
|
/**
|
|
|
|
* subscr_subscribe - create subscription for subscriber
|
2007-02-09 14:25:21 +00:00
|
|
|
*
|
2008-05-19 20:29:47 +00:00
|
|
|
* Called with subscriber port locked.
|
2006-01-02 18:04:38 +00:00
|
|
|
*/
|
2011-12-30 01:43:44 +00:00
|
|
|
static struct tipc_subscription *subscr_subscribe(struct tipc_subscr *s,
|
2011-12-30 01:49:39 +00:00
|
|
|
struct tipc_subscriber *subscriber)
|
2006-01-02 18:04:38 +00:00
|
|
|
{
|
2011-12-30 01:43:44 +00:00
|
|
|
struct tipc_subscription *sub;
|
2010-10-21 01:06:16 +00:00
|
|
|
int swap;
|
|
|
|
|
|
|
|
/* Determine subscriber's endianness */
|
|
|
|
swap = !(s->filter & (TIPC_SUB_PORTS | TIPC_SUB_SERVICE));
|
2006-10-17 04:59:42 +00:00
|
|
|
|
|
|
|
/* Detect & process a subscription cancellation request */
|
2010-10-21 01:06:16 +00:00
|
|
|
if (s->filter & htohl(TIPC_SUB_CANCEL, swap)) {
|
|
|
|
s->filter &= ~htohl(TIPC_SUB_CANCEL, swap);
|
2006-10-17 04:59:42 +00:00
|
|
|
subscr_cancel(s, subscriber);
|
2008-05-19 20:29:47 +00:00
|
|
|
return NULL;
|
2006-10-17 04:59:42 +00:00
|
|
|
}
|
|
|
|
|
2006-01-02 18:04:38 +00:00
|
|
|
/* Refuse subscription if global limit exceeded */
|
2012-08-16 12:09:13 +00:00
|
|
|
if (atomic_read(&topsrv.subscription_count) >= TIPC_MAX_SUBSCRIPTIONS) {
|
2012-06-29 04:16:37 +00:00
|
|
|
pr_warn("Subscription rejected, limit reached (%u)\n",
|
2012-08-16 12:09:13 +00:00
|
|
|
TIPC_MAX_SUBSCRIPTIONS);
|
2006-01-02 18:04:38 +00:00
|
|
|
subscr_terminate(subscriber);
|
2008-05-19 20:29:47 +00:00
|
|
|
return NULL;
|
2006-01-02 18:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate subscription object */
|
2008-05-19 20:29:47 +00:00
|
|
|
sub = kmalloc(sizeof(*sub), GFP_ATOMIC);
|
2006-06-26 06:52:17 +00:00
|
|
|
if (!sub) {
|
2012-06-29 04:16:37 +00:00
|
|
|
pr_warn("Subscription rejected, no memory\n");
|
2006-01-02 18:04:38 +00:00
|
|
|
subscr_terminate(subscriber);
|
2008-05-19 20:29:47 +00:00
|
|
|
return NULL;
|
2006-01-02 18:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize subscription object */
|
2010-10-21 01:06:16 +00:00
|
|
|
sub->seq.type = htohl(s->seq.type, swap);
|
|
|
|
sub->seq.lower = htohl(s->seq.lower, swap);
|
|
|
|
sub->seq.upper = htohl(s->seq.upper, swap);
|
|
|
|
sub->timeout = htohl(s->timeout, swap);
|
|
|
|
sub->filter = htohl(s->filter, swap);
|
2010-10-21 01:06:15 +00:00
|
|
|
if ((!(sub->filter & TIPC_SUB_PORTS) ==
|
|
|
|
!(sub->filter & TIPC_SUB_SERVICE)) ||
|
2009-11-30 00:55:45 +00:00
|
|
|
(sub->seq.lower > sub->seq.upper)) {
|
2012-06-29 04:16:37 +00:00
|
|
|
pr_warn("Subscription rejected, illegal request\n");
|
2006-01-02 18:04:38 +00:00
|
|
|
kfree(sub);
|
|
|
|
subscr_terminate(subscriber);
|
2008-05-19 20:29:47 +00:00
|
|
|
return NULL;
|
2006-01-02 18:04:38 +00:00
|
|
|
}
|
|
|
|
INIT_LIST_HEAD(&sub->nameseq_list);
|
|
|
|
list_add(&sub->subscription_list, &subscriber->subscription_list);
|
2008-05-19 20:29:47 +00:00
|
|
|
sub->server_ref = subscriber->port_ref;
|
2010-10-21 01:06:16 +00:00
|
|
|
sub->swap = swap;
|
2008-05-19 20:29:47 +00:00
|
|
|
memcpy(&sub->evt.s, s, sizeof(struct tipc_subscr));
|
2006-01-02 18:04:38 +00:00
|
|
|
atomic_inc(&topsrv.subscription_count);
|
|
|
|
if (sub->timeout != TIPC_WAIT_FOREVER) {
|
|
|
|
k_init_timer(&sub->timer,
|
|
|
|
(Handler)subscr_timeout, (unsigned long)sub);
|
|
|
|
k_start_timer(&sub->timer, sub->timeout);
|
|
|
|
}
|
2008-05-19 20:29:47 +00:00
|
|
|
|
|
|
|
return sub;
|
2006-01-02 18:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* subscr_conn_shutdown_event - handle termination request from subscriber
|
2008-05-19 20:29:47 +00:00
|
|
|
*
|
|
|
|
* Called with subscriber's server port unlocked.
|
2006-01-02 18:04:38 +00:00
|
|
|
*/
|
|
|
|
static void subscr_conn_shutdown_event(void *usr_handle,
|
2008-05-19 20:29:47 +00:00
|
|
|
u32 port_ref,
|
2006-01-02 18:04:38 +00:00
|
|
|
struct sk_buff **buf,
|
|
|
|
unsigned char const *data,
|
|
|
|
unsigned int size,
|
|
|
|
int reason)
|
|
|
|
{
|
2011-12-30 01:49:39 +00:00
|
|
|
struct tipc_subscriber *subscriber = usr_handle;
|
2006-01-02 18:04:38 +00:00
|
|
|
spinlock_t *subscriber_lock;
|
|
|
|
|
2008-05-19 20:29:47 +00:00
|
|
|
if (tipc_port_lock(port_ref) == NULL)
|
2006-01-02 18:04:38 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
subscriber_lock = subscriber->lock;
|
|
|
|
subscr_terminate(subscriber);
|
|
|
|
spin_unlock_bh(subscriber_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* subscr_conn_msg_event - handle new subscription request from subscriber
|
2008-05-19 20:29:47 +00:00
|
|
|
*
|
|
|
|
* Called with subscriber's server port unlocked.
|
2006-01-02 18:04:38 +00:00
|
|
|
*/
|
|
|
|
static void subscr_conn_msg_event(void *usr_handle,
|
|
|
|
u32 port_ref,
|
|
|
|
struct sk_buff **buf,
|
|
|
|
const unchar *data,
|
|
|
|
u32 size)
|
|
|
|
{
|
2011-12-30 01:49:39 +00:00
|
|
|
struct tipc_subscriber *subscriber = usr_handle;
|
2006-01-02 18:04:38 +00:00
|
|
|
spinlock_t *subscriber_lock;
|
2011-12-30 01:43:44 +00:00
|
|
|
struct tipc_subscription *sub;
|
2008-05-19 20:29:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Lock subscriber's server port (& make a local copy of lock pointer,
|
|
|
|
* in case subscriber is deleted while processing subscription request)
|
|
|
|
*/
|
|
|
|
if (tipc_port_lock(port_ref) == NULL)
|
2006-01-02 18:04:38 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
subscriber_lock = subscriber->lock;
|
2007-02-09 14:25:21 +00:00
|
|
|
|
2008-05-19 20:29:47 +00:00
|
|
|
if (size != sizeof(struct tipc_subscr)) {
|
|
|
|
subscr_terminate(subscriber);
|
|
|
|
spin_unlock_bh(subscriber_lock);
|
|
|
|
} else {
|
|
|
|
sub = subscr_subscribe((struct tipc_subscr *)data, subscriber);
|
|
|
|
spin_unlock_bh(subscriber_lock);
|
|
|
|
if (sub != NULL) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We must release the server port lock before adding a
|
|
|
|
* subscription to the name table since TIPC needs to be
|
|
|
|
* able to (re)acquire the port lock if an event message
|
|
|
|
* issued by the subscription process is rejected and
|
|
|
|
* returned. The subscription cannot be deleted while
|
|
|
|
* it is being added to the name table because:
|
|
|
|
* a) the single-threading of the native API port code
|
|
|
|
* ensures the subscription cannot be cancelled and
|
|
|
|
* the subscriber connection cannot be broken, and
|
|
|
|
* b) the name table lock ensures the subscription
|
|
|
|
* timeout code cannot delete the subscription,
|
|
|
|
* so the subscription object is still protected.
|
|
|
|
*/
|
|
|
|
tipc_nametbl_subscribe(sub);
|
|
|
|
}
|
|
|
|
}
|
2006-01-02 18:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* subscr_named_msg_event - handle request to establish a new subscriber
|
|
|
|
*/
|
|
|
|
static void subscr_named_msg_event(void *usr_handle,
|
|
|
|
u32 port_ref,
|
|
|
|
struct sk_buff **buf,
|
|
|
|
const unchar *data,
|
|
|
|
u32 size,
|
2007-02-09 14:25:21 +00:00
|
|
|
u32 importance,
|
2006-01-02 18:04:38 +00:00
|
|
|
struct tipc_portid const *orig,
|
|
|
|
struct tipc_name_seq const *dest)
|
|
|
|
{
|
2011-12-30 01:49:39 +00:00
|
|
|
struct tipc_subscriber *subscriber;
|
2008-05-19 20:29:47 +00:00
|
|
|
u32 server_port_ref;
|
2006-01-02 18:04:38 +00:00
|
|
|
|
|
|
|
/* Create subscriber object */
|
2011-12-30 01:49:39 +00:00
|
|
|
subscriber = kzalloc(sizeof(struct tipc_subscriber), GFP_ATOMIC);
|
2006-01-02 18:04:38 +00:00
|
|
|
if (subscriber == NULL) {
|
2012-06-29 04:16:37 +00:00
|
|
|
pr_warn("Subscriber rejected, no memory\n");
|
2006-01-02 18:04:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
INIT_LIST_HEAD(&subscriber->subscription_list);
|
|
|
|
INIT_LIST_HEAD(&subscriber->subscriber_list);
|
|
|
|
|
2008-05-19 20:29:47 +00:00
|
|
|
/* Create server port & establish connection to subscriber */
|
2010-12-31 18:59:22 +00:00
|
|
|
tipc_createport(subscriber,
|
2006-01-02 18:04:38 +00:00
|
|
|
importance,
|
2006-03-21 06:36:47 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2006-01-02 18:04:38 +00:00
|
|
|
subscr_conn_shutdown_event,
|
2006-03-21 06:36:47 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2006-01-02 18:04:38 +00:00
|
|
|
subscr_conn_msg_event,
|
2006-03-21 06:36:47 +00:00
|
|
|
NULL,
|
2006-01-02 18:04:38 +00:00
|
|
|
&subscriber->port_ref);
|
|
|
|
if (subscriber->port_ref == 0) {
|
2012-06-29 04:16:37 +00:00
|
|
|
pr_warn("Subscriber rejected, unable to create port\n");
|
2006-01-02 18:04:38 +00:00
|
|
|
kfree(subscriber);
|
|
|
|
return;
|
|
|
|
}
|
tipc: standardize across connect/disconnect function naming
Currently we have tipc_disconnect and tipc_disconnect_port. It is
not clear from the names alone, what they do or how they differ.
It turns out that tipc_disconnect just deals with the port locking
and then calls tipc_disconnect_port which does all the work.
If we rename as follows: tipc_disconnect_port --> __tipc_disconnect
then we will be following typical linux convention, where:
__tipc_disconnect: "raw" function that does all the work.
tipc_disconnect: wrapper that deals with locking and then calls
the real core __tipc_disconnect function
With this, the difference is immediately evident, and locking
violations are more apt to be spotted by chance while working on,
or even just while reading the code.
On the connect side of things, we currently only have the single
"tipc_connect2port" function. It does both the locking at enter/exit,
and the core of the work. Pending changes will make it desireable to
have the connect be a two part locking wrapper + worker function,
just like the disconnect is already.
Here, we make the connect look just like the updated disconnect case,
for the above reason, and for consistency. In the process, we also
get rid of the "2port" suffix that was on the original name, since
it adds no descriptive value.
On close examination, one might notice that the above connect
changes implicitly move the call to tipc_link_get_max_pkt() to be
within the scope of tipc_port_lock() protected region; when it was
not previously. We don't see any issues with this, and it is in
keeping with __tipc_connect doing the work and tipc_connect just
handling the locking.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
2012-11-29 18:48:40 +00:00
|
|
|
tipc_connect(subscriber->port_ref, orig);
|
2006-01-02 18:04:38 +00:00
|
|
|
|
2008-05-19 20:29:47 +00:00
|
|
|
/* Lock server port (& save lock address for future use) */
|
2011-01-07 16:43:40 +00:00
|
|
|
subscriber->lock = tipc_port_lock(subscriber->port_ref)->lock;
|
2006-01-02 18:04:38 +00:00
|
|
|
|
|
|
|
/* Add subscriber to topology server's subscriber list */
|
|
|
|
spin_lock_bh(&topsrv.lock);
|
|
|
|
list_add(&subscriber->subscriber_list, &topsrv.subscriber_list);
|
|
|
|
spin_unlock_bh(&topsrv.lock);
|
|
|
|
|
2008-05-19 20:29:47 +00:00
|
|
|
/* Unlock server port */
|
|
|
|
server_port_ref = subscriber->port_ref;
|
|
|
|
spin_unlock_bh(subscriber->lock);
|
2006-01-02 18:04:38 +00:00
|
|
|
|
2008-05-19 20:29:47 +00:00
|
|
|
/* Send an ACK- to complete connection handshaking */
|
tipc: Avoid recomputation of outgoing message length
Rework TIPC's message sending routines to take advantage of the total
amount of data value passed to it by the kernel socket infrastructure.
This change eliminates the need for TIPC to compute the size of outgoing
messages itself, as well as the check for an oversize message in
tipc_msg_build(). In addition, this change warrants an explanation:
- res = send_packet(NULL, sock, &my_msg, 0);
+ res = send_packet(NULL, sock, &my_msg, bytes_to_send);
Previously, the final argument to send_packet() was ignored (since the
amount of data being sent was recalculated by a lower-level routine)
and we could just pass in a dummy value (0). Now that the
recalculation is being eliminated, the argument value being passed to
send_packet() is significant and we have to supply the actual amount
of data we want to send.
Signed-off-by: Allan Stephens <Allan.Stephens@windriver.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
2011-04-21 15:42:07 +00:00
|
|
|
tipc_send(server_port_ref, 0, NULL, 0);
|
2008-05-19 20:29:47 +00:00
|
|
|
|
|
|
|
/* Handle optional subscription request */
|
|
|
|
if (size != 0) {
|
|
|
|
subscr_conn_msg_event(subscriber, server_port_ref,
|
|
|
|
buf, data, size);
|
|
|
|
}
|
2006-01-02 18:04:38 +00:00
|
|
|
}
|
|
|
|
|
2006-01-17 23:38:21 +00:00
|
|
|
int tipc_subscr_start(void)
|
2006-01-02 18:04:38 +00:00
|
|
|
{
|
|
|
|
struct tipc_name_seq seq = {TIPC_TOP_SRV, TIPC_TOP_SRV, TIPC_TOP_SRV};
|
2010-11-30 12:01:00 +00:00
|
|
|
int res;
|
2006-01-02 18:04:38 +00:00
|
|
|
|
2006-06-27 09:53:55 +00:00
|
|
|
spin_lock_init(&topsrv.lock);
|
2006-01-02 18:04:38 +00:00
|
|
|
INIT_LIST_HEAD(&topsrv.subscriber_list);
|
|
|
|
|
2010-12-31 18:59:22 +00:00
|
|
|
res = tipc_createport(NULL,
|
2007-02-09 14:25:21 +00:00
|
|
|
TIPC_CRITICAL_IMPORTANCE,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
subscr_named_msg_event,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&topsrv.setup_port);
|
|
|
|
if (res)
|
2006-01-02 18:04:38 +00:00
|
|
|
goto failed;
|
|
|
|
|
2011-11-02 19:49:40 +00:00
|
|
|
res = tipc_publish(topsrv.setup_port, TIPC_NODE_SCOPE, &seq);
|
2010-12-31 18:59:21 +00:00
|
|
|
if (res) {
|
|
|
|
tipc_deleteport(topsrv.setup_port);
|
|
|
|
topsrv.setup_port = 0;
|
2006-01-02 18:04:38 +00:00
|
|
|
goto failed;
|
2010-12-31 18:59:21 +00:00
|
|
|
}
|
2006-01-02 18:04:38 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
failed:
|
2012-06-29 04:16:37 +00:00
|
|
|
pr_err("Failed to create subscription service\n");
|
2006-01-02 18:04:38 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-01-17 23:38:21 +00:00
|
|
|
void tipc_subscr_stop(void)
|
2006-01-02 18:04:38 +00:00
|
|
|
{
|
2011-12-30 01:49:39 +00:00
|
|
|
struct tipc_subscriber *subscriber;
|
|
|
|
struct tipc_subscriber *subscriber_temp;
|
2006-01-02 18:04:38 +00:00
|
|
|
spinlock_t *subscriber_lock;
|
|
|
|
|
2010-12-31 18:59:21 +00:00
|
|
|
if (topsrv.setup_port) {
|
2006-01-02 18:04:38 +00:00
|
|
|
tipc_deleteport(topsrv.setup_port);
|
2010-12-31 18:59:21 +00:00
|
|
|
topsrv.setup_port = 0;
|
|
|
|
|
2007-02-09 14:25:21 +00:00
|
|
|
list_for_each_entry_safe(subscriber, subscriber_temp,
|
2006-01-02 18:04:38 +00:00
|
|
|
&topsrv.subscriber_list,
|
|
|
|
subscriber_list) {
|
|
|
|
subscriber_lock = subscriber->lock;
|
2008-05-19 20:29:47 +00:00
|
|
|
spin_lock_bh(subscriber_lock);
|
2006-01-02 18:04:38 +00:00
|
|
|
subscr_terminate(subscriber);
|
|
|
|
spin_unlock_bh(subscriber_lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|