2006-01-03 02:04:38 +08:00
|
|
|
/*
|
|
|
|
* net/tipc/bearer.c: TIPC bearer code
|
2007-02-09 22:25:21 +08:00
|
|
|
*
|
2006-01-12 02:14:19 +08:00
|
|
|
* Copyright (c) 1996-2006, Ericsson AB
|
2011-01-08 02:00:11 +08:00
|
|
|
* Copyright (c) 2004-2006, 2010-2011, Wind River Systems
|
2006-01-03 02:04:38 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2006-01-11 20:30:43 +08:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
2006-01-03 02:04:38 +08:00
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
2006-01-11 20:30:43 +08: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-03 02:04:38 +08:00
|
|
|
*
|
2006-01-11 20:30:43 +08: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-03 02:04:38 +08:00
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "core.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "bearer.h"
|
|
|
|
#include "discover.h"
|
|
|
|
|
|
|
|
#define MAX_ADDR_STR 32
|
|
|
|
|
2011-10-07 21:25:12 +08:00
|
|
|
static struct media *media_list[MAX_MEDIA];
|
2011-01-01 02:59:34 +08:00
|
|
|
static u32 media_count;
|
2006-01-03 02:04:38 +08:00
|
|
|
|
2011-01-08 02:00:11 +08:00
|
|
|
struct tipc_bearer tipc_bearers[MAX_BEARERS];
|
2006-01-03 02:04:38 +08:00
|
|
|
|
2011-04-22 02:58:26 +08:00
|
|
|
static void bearer_disable(struct tipc_bearer *b_ptr);
|
|
|
|
|
2006-01-03 02:04:38 +08:00
|
|
|
/**
|
|
|
|
* media_name_valid - validate media name
|
2007-02-09 22:25:21 +08:00
|
|
|
*
|
2006-01-03 02:04:38 +08:00
|
|
|
* Returns 1 if media name is valid, otherwise 0.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int media_name_valid(const char *name)
|
|
|
|
{
|
|
|
|
u32 len;
|
|
|
|
|
|
|
|
len = strlen(name);
|
|
|
|
if ((len + 1) > TIPC_MAX_MEDIA_NAME)
|
|
|
|
return 0;
|
2010-09-23 04:43:57 +08:00
|
|
|
return strspn(name, tipc_alphabet) == len;
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* media_find - locates specified media object by name
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct media *media_find(const char *name)
|
|
|
|
{
|
|
|
|
u32 i;
|
|
|
|
|
2011-10-07 21:25:12 +08:00
|
|
|
for (i = 0; i < media_count; i++) {
|
|
|
|
if (!strcmp(media_list[i]->name, name))
|
|
|
|
return media_list[i];
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
2006-03-21 14:36:47 +08:00
|
|
|
return NULL;
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
2011-10-07 04:40:55 +08:00
|
|
|
/**
|
|
|
|
* media_find_id - locates specified media object by type identifier
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct media *media_find_id(u8 type)
|
|
|
|
{
|
|
|
|
u32 i;
|
|
|
|
|
|
|
|
for (i = 0; i < media_count; i++) {
|
2011-10-07 21:25:12 +08:00
|
|
|
if (media_list[i]->type_id == type)
|
|
|
|
return media_list[i];
|
2011-10-07 04:40:55 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-01-03 02:04:38 +08:00
|
|
|
/**
|
|
|
|
* tipc_register_media - register a media type
|
2007-02-09 22:25:21 +08:00
|
|
|
*
|
2006-01-03 02:04:38 +08:00
|
|
|
* Bearers for this media type must be activated separately at a later stage.
|
|
|
|
*/
|
|
|
|
|
2011-10-07 03:28:44 +08:00
|
|
|
int tipc_register_media(struct media *m_ptr)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
|
|
|
int res = -EINVAL;
|
|
|
|
|
2006-01-18 07:38:21 +08:00
|
|
|
write_lock_bh(&tipc_net_lock);
|
2006-01-03 02:04:38 +08:00
|
|
|
|
2011-10-07 21:54:44 +08:00
|
|
|
if (!media_name_valid(m_ptr->name))
|
tipc: Fix oops on send prior to entering networked mode (v3)
Fix TIPC to disallow sending to remote addresses prior to entering NET_MODE
user programs can oops the kernel by sending datagrams via AF_TIPC prior to
entering networked mode. The following backtrace has been observed:
ID: 13459 TASK: ffff810014640040 CPU: 0 COMMAND: "tipc-client"
[exception RIP: tipc_node_select_next_hop+90]
RIP: ffffffff8869d3c3 RSP: ffff81002d9a5ab8 RFLAGS: 00010202
RAX: 0000000000000001 RBX: 0000000000000001 RCX: 0000000000000001
RDX: 0000000000000000 RSI: 0000000000000001 RDI: 0000000001001001
RBP: 0000000001001001 R8: 0074736575716552 R9: 0000000000000000
R10: ffff81003fbd0680 R11: 00000000000000c8 R12: 0000000000000008
R13: 0000000000000001 R14: 0000000000000001 R15: ffff810015c6ca00
ORIG_RAX: ffffffffffffffff CS: 0010 SS: 0018
RIP: 0000003cbd8d49a3 RSP: 00007fffc84e0be8 RFLAGS: 00010206
RAX: 000000000000002c RBX: ffffffff8005d116 RCX: 0000000000000000
RDX: 0000000000000008 RSI: 00007fffc84e0c00 RDI: 0000000000000003
RBP: 0000000000000000 R8: 00007fffc84e0c10 R9: 0000000000000010
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007fffc84e0d10 R14: 0000000000000000 R15: 00007fffc84e0c30
ORIG_RAX: 000000000000002c CS: 0033 SS: 002b
What happens is that, when the tipc module in inserted it enters a standalone
node mode in which communication to its own address is allowed <0.0.0> but not
to other addresses, since the appropriate data structures have not been
allocated yet (specifically the tipc_net pointer). There is nothing stopping a
client from trying to send such a message however, and if that happens, we
attempt to dereference tipc_net.zones while the pointer is still NULL, and
explode. The fix is pretty straightforward. Since these oopses all arise from
the dereference of global pointers prior to their assignment to allocated
values, and since these allocations are small (about 2k total), lets convert
these pointers to static arrays of the appropriate size. All the accesses to
these bits consider 0/NULL to be a non match when searching, so all the lookups
still work properly, and there is no longer a chance of a bad dererence
anywhere. As a bonus, this lets us eliminate the setup/teardown routines for
those pointers, and elimnates the need to preform any locking around them to
prevent access while their being allocated/freed.
I've updated the tipc_net structure to behave this way to fix the exact reported
problem, and also fixed up the tipc_bearers and media_list arrays to fix an
obvious simmilar problem that arises from issuing tipc-config commands to
manipulate bearers/links prior to entering networked mode
I've tested this for a few hours by running the sanity tests and stress test
with the tipcutils suite, and nothing has fallen over. There have been a few
lockdep warnings, but those were there before, and can be addressed later, as
they didn't actually result in any deadlock.
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
CC: Allan Stephens <allan.stephens@windriver.com>
CC: David S. Miller <davem@davemloft.net>
CC: tipc-discussion@lists.sourceforge.net
bearer.c | 37 ++++++-------------------------------
bearer.h | 2 +-
net.c | 25 ++++---------------------
3 files changed, 11 insertions(+), 53 deletions(-)
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-03-03 16:31:23 +08:00
|
|
|
goto exit;
|
2011-10-08 03:19:11 +08:00
|
|
|
if ((m_ptr->bcast_addr.media_id != m_ptr->type_id) ||
|
|
|
|
!m_ptr->bcast_addr.broadcast)
|
2006-01-03 02:04:38 +08:00
|
|
|
goto exit;
|
2011-10-07 21:54:44 +08:00
|
|
|
if (m_ptr->priority > TIPC_MAX_LINK_PRI)
|
2006-01-03 02:04:38 +08:00
|
|
|
goto exit;
|
2011-10-07 03:28:44 +08:00
|
|
|
if ((m_ptr->tolerance < TIPC_MIN_LINK_TOL) ||
|
2011-10-07 21:54:44 +08:00
|
|
|
(m_ptr->tolerance > TIPC_MAX_LINK_TOL))
|
2006-01-03 02:04:38 +08:00
|
|
|
goto exit;
|
2011-10-07 21:54:44 +08:00
|
|
|
if (media_count >= MAX_MEDIA)
|
2006-01-03 02:04:38 +08:00
|
|
|
goto exit;
|
2011-10-07 21:54:44 +08:00
|
|
|
if (media_find(m_ptr->name) || media_find_id(m_ptr->type_id))
|
2011-10-07 04:40:55 +08:00
|
|
|
goto exit;
|
2006-01-03 02:04:38 +08:00
|
|
|
|
2011-10-07 21:25:12 +08:00
|
|
|
media_list[media_count] = m_ptr;
|
2011-10-07 04:40:55 +08:00
|
|
|
media_count++;
|
2006-01-03 02:04:38 +08:00
|
|
|
res = 0;
|
|
|
|
exit:
|
2006-01-18 07:38:21 +08:00
|
|
|
write_unlock_bh(&tipc_net_lock);
|
2011-10-07 21:54:44 +08:00
|
|
|
if (res)
|
|
|
|
warn("Media <%s> registration error\n", m_ptr->name);
|
2006-01-03 02:04:38 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-01-18 07:38:21 +08:00
|
|
|
* tipc_media_addr_printf - record media address in print buffer
|
2006-01-03 02:04:38 +08:00
|
|
|
*/
|
|
|
|
|
2006-01-18 07:38:21 +08:00
|
|
|
void tipc_media_addr_printf(struct print_buf *pb, struct tipc_media_addr *a)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
2011-10-07 23:31:49 +08:00
|
|
|
char addr_str[MAX_ADDR_STR];
|
2006-01-03 02:04:38 +08:00
|
|
|
struct media *m_ptr;
|
|
|
|
|
2011-10-08 03:19:11 +08:00
|
|
|
m_ptr = media_find_id(a->media_id);
|
2006-01-03 02:04:38 +08:00
|
|
|
|
2011-10-07 23:31:49 +08:00
|
|
|
if (m_ptr && !m_ptr->addr2str(a, addr_str, sizeof(addr_str)))
|
|
|
|
tipc_printf(pb, "%s(%s)", m_ptr->name, addr_str);
|
|
|
|
else {
|
|
|
|
u32 i;
|
2006-01-03 02:04:38 +08:00
|
|
|
|
2011-10-08 03:19:11 +08:00
|
|
|
tipc_printf(pb, "UNKNOWN(%u)", a->media_id);
|
|
|
|
for (i = 0; i < sizeof(a->value); i++)
|
|
|
|
tipc_printf(pb, "-%02x", a->value[i]);
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-01-18 07:38:21 +08:00
|
|
|
* tipc_media_get_names - record names of registered media in buffer
|
2006-01-03 02:04:38 +08:00
|
|
|
*/
|
|
|
|
|
2006-01-18 07:38:21 +08:00
|
|
|
struct sk_buff *tipc_media_get_names(void)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
|
|
|
struct sk_buff *buf;
|
|
|
|
int i;
|
|
|
|
|
2006-01-18 07:38:21 +08:00
|
|
|
buf = tipc_cfg_reply_alloc(MAX_MEDIA * TLV_SPACE(TIPC_MAX_MEDIA_NAME));
|
2006-01-03 02:04:38 +08:00
|
|
|
if (!buf)
|
|
|
|
return NULL;
|
|
|
|
|
2006-01-18 07:38:21 +08:00
|
|
|
read_lock_bh(&tipc_net_lock);
|
2011-10-07 21:25:12 +08:00
|
|
|
for (i = 0; i < media_count; i++) {
|
|
|
|
tipc_cfg_append_tlv(buf, TIPC_TLV_MEDIA_NAME,
|
|
|
|
media_list[i]->name,
|
|
|
|
strlen(media_list[i]->name) + 1);
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
2006-01-18 07:38:21 +08:00
|
|
|
read_unlock_bh(&tipc_net_lock);
|
2006-01-03 02:04:38 +08:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bearer_name_validate - validate & (optionally) deconstruct bearer name
|
|
|
|
* @name - ptr to bearer name string
|
|
|
|
* @name_parts - ptr to area for bearer name components (or NULL if not needed)
|
2007-02-09 22:25:21 +08:00
|
|
|
*
|
2006-01-03 02:04:38 +08:00
|
|
|
* Returns 1 if bearer name is valid, otherwise 0.
|
|
|
|
*/
|
|
|
|
|
2007-02-09 22:25:21 +08:00
|
|
|
static int bearer_name_validate(const char *name,
|
2006-01-03 02:04:38 +08:00
|
|
|
struct bearer_name *name_parts)
|
|
|
|
{
|
|
|
|
char name_copy[TIPC_MAX_BEARER_NAME];
|
|
|
|
char *media_name;
|
|
|
|
char *if_name;
|
|
|
|
u32 media_len;
|
|
|
|
u32 if_len;
|
|
|
|
|
|
|
|
/* copy bearer name & ensure length is OK */
|
|
|
|
|
|
|
|
name_copy[TIPC_MAX_BEARER_NAME - 1] = 0;
|
|
|
|
/* need above in case non-Posix strncpy() doesn't pad with nulls */
|
|
|
|
strncpy(name_copy, name, TIPC_MAX_BEARER_NAME);
|
|
|
|
if (name_copy[TIPC_MAX_BEARER_NAME - 1] != 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* ensure all component parts of bearer name are present */
|
|
|
|
|
|
|
|
media_name = name_copy;
|
2011-01-01 02:59:33 +08:00
|
|
|
if_name = strchr(media_name, ':');
|
|
|
|
if (if_name == NULL)
|
2006-01-03 02:04:38 +08:00
|
|
|
return 0;
|
|
|
|
*(if_name++) = 0;
|
|
|
|
media_len = if_name - media_name;
|
|
|
|
if_len = strlen(if_name) + 1;
|
|
|
|
|
|
|
|
/* validate component parts of bearer name */
|
|
|
|
|
2007-02-09 22:25:21 +08:00
|
|
|
if ((media_len <= 1) || (media_len > TIPC_MAX_MEDIA_NAME) ||
|
|
|
|
(if_len <= 1) || (if_len > TIPC_MAX_IF_NAME) ||
|
2006-01-03 02:04:38 +08:00
|
|
|
(strspn(media_name, tipc_alphabet) != (media_len - 1)) ||
|
|
|
|
(strspn(if_name, tipc_alphabet) != (if_len - 1)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* return bearer name components, if necessary */
|
|
|
|
|
|
|
|
if (name_parts) {
|
|
|
|
strcpy(name_parts->media_name, media_name);
|
|
|
|
strcpy(name_parts->if_name, if_name);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bearer_find - locates bearer object with matching bearer name
|
|
|
|
*/
|
|
|
|
|
2011-01-08 02:00:11 +08:00
|
|
|
static struct tipc_bearer *bearer_find(const char *name)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
2011-01-08 02:00:11 +08:00
|
|
|
struct tipc_bearer *b_ptr;
|
2006-01-03 02:04:38 +08:00
|
|
|
u32 i;
|
|
|
|
|
2006-01-18 07:38:21 +08:00
|
|
|
for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) {
|
2011-01-08 02:00:11 +08:00
|
|
|
if (b_ptr->active && (!strcmp(b_ptr->name, name)))
|
2006-01-03 02:04:38 +08:00
|
|
|
return b_ptr;
|
|
|
|
}
|
2006-03-21 14:36:47 +08:00
|
|
|
return NULL;
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-01-18 07:38:21 +08:00
|
|
|
* tipc_bearer_find_interface - locates bearer object with matching interface name
|
2006-01-03 02:04:38 +08:00
|
|
|
*/
|
|
|
|
|
2011-01-08 02:00:11 +08:00
|
|
|
struct tipc_bearer *tipc_bearer_find_interface(const char *if_name)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
2011-01-08 02:00:11 +08:00
|
|
|
struct tipc_bearer *b_ptr;
|
2006-01-03 02:04:38 +08:00
|
|
|
char *b_if_name;
|
|
|
|
u32 i;
|
|
|
|
|
2006-01-18 07:38:21 +08:00
|
|
|
for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) {
|
2006-01-03 02:04:38 +08:00
|
|
|
if (!b_ptr->active)
|
|
|
|
continue;
|
2011-01-08 02:00:11 +08:00
|
|
|
b_if_name = strchr(b_ptr->name, ':') + 1;
|
2006-01-03 02:04:38 +08:00
|
|
|
if (!strcmp(b_if_name, if_name))
|
|
|
|
return b_ptr;
|
|
|
|
}
|
2006-03-21 14:36:47 +08:00
|
|
|
return NULL;
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-01-18 07:38:21 +08:00
|
|
|
* tipc_bearer_get_names - record names of bearers in buffer
|
2006-01-03 02:04:38 +08:00
|
|
|
*/
|
|
|
|
|
2006-01-18 07:38:21 +08:00
|
|
|
struct sk_buff *tipc_bearer_get_names(void)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
|
|
|
struct sk_buff *buf;
|
2011-01-08 02:00:11 +08:00
|
|
|
struct tipc_bearer *b_ptr;
|
2006-01-03 02:04:38 +08:00
|
|
|
int i, j;
|
|
|
|
|
2006-01-18 07:38:21 +08:00
|
|
|
buf = tipc_cfg_reply_alloc(MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME));
|
2006-01-03 02:04:38 +08:00
|
|
|
if (!buf)
|
|
|
|
return NULL;
|
|
|
|
|
2006-01-18 07:38:21 +08:00
|
|
|
read_lock_bh(&tipc_net_lock);
|
2011-10-07 21:25:12 +08:00
|
|
|
for (i = 0; i < media_count; i++) {
|
2006-01-03 02:04:38 +08:00
|
|
|
for (j = 0; j < MAX_BEARERS; j++) {
|
2006-01-18 07:38:21 +08:00
|
|
|
b_ptr = &tipc_bearers[j];
|
2011-10-07 21:25:12 +08:00
|
|
|
if (b_ptr->active && (b_ptr->media == media_list[i])) {
|
2007-02-09 22:25:21 +08:00
|
|
|
tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME,
|
2011-01-08 02:00:11 +08:00
|
|
|
b_ptr->name,
|
|
|
|
strlen(b_ptr->name) + 1);
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-01-18 07:38:21 +08:00
|
|
|
read_unlock_bh(&tipc_net_lock);
|
2006-01-03 02:04:38 +08:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2011-01-08 02:00:11 +08:00
|
|
|
void tipc_bearer_add_dest(struct tipc_bearer *b_ptr, u32 dest)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
2006-01-18 07:38:21 +08:00
|
|
|
tipc_nmap_add(&b_ptr->nodes, dest);
|
|
|
|
tipc_bcbearer_sort();
|
2011-04-22 08:05:25 +08:00
|
|
|
tipc_disc_add_dest(b_ptr->link_req);
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
2011-01-08 02:00:11 +08:00
|
|
|
void tipc_bearer_remove_dest(struct tipc_bearer *b_ptr, u32 dest)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
2006-01-18 07:38:21 +08:00
|
|
|
tipc_nmap_remove(&b_ptr->nodes, dest);
|
|
|
|
tipc_bcbearer_sort();
|
2011-04-22 08:05:25 +08:00
|
|
|
tipc_disc_remove_dest(b_ptr->link_req);
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* bearer_push(): Resolve bearer congestion. Force the waiting
|
|
|
|
* links to push out their unsent packets, one packet per link
|
|
|
|
* per iteration, until all packets are gone or congestion reoccurs.
|
2006-01-18 07:38:21 +08:00
|
|
|
* 'tipc_net_lock' is read_locked when this function is called
|
2006-01-03 02:04:38 +08:00
|
|
|
* bearer.lock must be taken before calling
|
|
|
|
* Returns binary true(1) ore false(0)
|
|
|
|
*/
|
2011-01-08 02:00:11 +08:00
|
|
|
static int bearer_push(struct tipc_bearer *b_ptr)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
2008-07-15 13:44:01 +08:00
|
|
|
u32 res = 0;
|
2006-01-03 02:04:38 +08:00
|
|
|
struct link *ln, *tln;
|
|
|
|
|
2011-01-08 02:00:11 +08:00
|
|
|
if (b_ptr->blocked)
|
2006-01-03 02:04:38 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
while (!list_empty(&b_ptr->cong_links) && (res != PUSH_FAILED)) {
|
|
|
|
list_for_each_entry_safe(ln, tln, &b_ptr->cong_links, link_list) {
|
2006-01-18 07:38:21 +08:00
|
|
|
res = tipc_link_push_packet(ln);
|
2006-01-03 02:04:38 +08:00
|
|
|
if (res == PUSH_FAILED)
|
|
|
|
break;
|
|
|
|
if (res == PUSH_FINISHED)
|
|
|
|
list_move_tail(&ln->link_list, &b_ptr->links);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list_empty(&b_ptr->cong_links);
|
|
|
|
}
|
|
|
|
|
2011-01-08 02:00:11 +08:00
|
|
|
void tipc_bearer_lock_push(struct tipc_bearer *b_ptr)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
2011-01-08 02:00:11 +08:00
|
|
|
spin_lock_bh(&b_ptr->lock);
|
2011-04-07 23:25:26 +08:00
|
|
|
bearer_push(b_ptr);
|
2011-01-08 02:00:11 +08:00
|
|
|
spin_unlock_bh(&b_ptr->lock);
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2007-02-09 22:25:21 +08:00
|
|
|
* Interrupt enabling new requests after bearer congestion or blocking:
|
|
|
|
* See bearer_send().
|
2006-01-03 02:04:38 +08:00
|
|
|
*/
|
2011-01-08 02:00:11 +08:00
|
|
|
void tipc_continue(struct tipc_bearer *b_ptr)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
2011-01-08 02:00:11 +08:00
|
|
|
spin_lock_bh(&b_ptr->lock);
|
2006-01-03 02:04:38 +08:00
|
|
|
if (!list_empty(&b_ptr->cong_links))
|
2006-01-18 07:38:21 +08:00
|
|
|
tipc_k_signal((Handler)tipc_bearer_lock_push, (unsigned long)b_ptr);
|
2011-01-08 02:00:11 +08:00
|
|
|
b_ptr->blocked = 0;
|
|
|
|
spin_unlock_bh(&b_ptr->lock);
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-02-09 22:25:21 +08:00
|
|
|
* Schedule link for sending of messages after the bearer
|
|
|
|
* has been deblocked by 'continue()'. This method is called
|
|
|
|
* when somebody tries to send a message via this link while
|
2006-01-18 07:38:21 +08:00
|
|
|
* the bearer is congested. 'tipc_net_lock' is in read_lock here
|
2006-01-03 02:04:38 +08:00
|
|
|
* bearer.lock is busy
|
|
|
|
*/
|
|
|
|
|
2011-01-08 02:00:11 +08:00
|
|
|
static void tipc_bearer_schedule_unlocked(struct tipc_bearer *b_ptr, struct link *l_ptr)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
|
|
|
list_move_tail(&l_ptr->link_list, &b_ptr->cong_links);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-02-09 22:25:21 +08:00
|
|
|
* Schedule link for sending of messages after the bearer
|
|
|
|
* has been deblocked by 'continue()'. This method is called
|
|
|
|
* when somebody tries to send a message via this link while
|
2006-01-18 07:38:21 +08:00
|
|
|
* the bearer is congested. 'tipc_net_lock' is in read_lock here,
|
2006-01-03 02:04:38 +08:00
|
|
|
* bearer.lock is free
|
|
|
|
*/
|
|
|
|
|
2011-01-08 02:00:11 +08:00
|
|
|
void tipc_bearer_schedule(struct tipc_bearer *b_ptr, struct link *l_ptr)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
2011-01-08 02:00:11 +08:00
|
|
|
spin_lock_bh(&b_ptr->lock);
|
2006-01-18 07:38:21 +08:00
|
|
|
tipc_bearer_schedule_unlocked(b_ptr, l_ptr);
|
2011-01-08 02:00:11 +08:00
|
|
|
spin_unlock_bh(&b_ptr->lock);
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-01-18 07:38:21 +08:00
|
|
|
* tipc_bearer_resolve_congestion(): Check if there is bearer congestion,
|
2006-01-03 02:04:38 +08:00
|
|
|
* and if there is, try to resolve it before returning.
|
2006-01-18 07:38:21 +08:00
|
|
|
* 'tipc_net_lock' is read_locked when this function is called
|
2006-01-03 02:04:38 +08:00
|
|
|
*/
|
2011-01-08 02:00:11 +08:00
|
|
|
int tipc_bearer_resolve_congestion(struct tipc_bearer *b_ptr, struct link *l_ptr)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
|
|
|
int res = 1;
|
|
|
|
|
|
|
|
if (list_empty(&b_ptr->cong_links))
|
|
|
|
return 1;
|
2011-01-08 02:00:11 +08:00
|
|
|
spin_lock_bh(&b_ptr->lock);
|
2006-01-03 02:04:38 +08:00
|
|
|
if (!bearer_push(b_ptr)) {
|
2006-01-18 07:38:21 +08:00
|
|
|
tipc_bearer_schedule_unlocked(b_ptr, l_ptr);
|
2006-01-03 02:04:38 +08:00
|
|
|
res = 0;
|
|
|
|
}
|
2011-01-08 02:00:11 +08:00
|
|
|
spin_unlock_bh(&b_ptr->lock);
|
2006-01-03 02:04:38 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-05-11 22:30:16 +08:00
|
|
|
/**
|
|
|
|
* tipc_bearer_congested - determines if bearer is currently congested
|
|
|
|
*/
|
|
|
|
|
2011-01-08 02:00:11 +08:00
|
|
|
int tipc_bearer_congested(struct tipc_bearer *b_ptr, struct link *l_ptr)
|
2010-05-11 22:30:16 +08:00
|
|
|
{
|
2011-01-08 02:00:11 +08:00
|
|
|
if (unlikely(b_ptr->blocked))
|
2010-05-11 22:30:16 +08:00
|
|
|
return 1;
|
|
|
|
if (likely(list_empty(&b_ptr->cong_links)))
|
|
|
|
return 0;
|
|
|
|
return !tipc_bearer_resolve_congestion(b_ptr, l_ptr);
|
|
|
|
}
|
2006-01-03 02:04:38 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* tipc_enable_bearer - enable bearer with the given name
|
2007-02-09 22:25:21 +08:00
|
|
|
*/
|
2006-01-03 02:04:38 +08:00
|
|
|
|
2011-03-01 03:56:15 +08:00
|
|
|
int tipc_enable_bearer(const char *name, u32 disc_domain, u32 priority)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
2011-01-08 02:00:11 +08:00
|
|
|
struct tipc_bearer *b_ptr;
|
2006-01-03 02:04:38 +08:00
|
|
|
struct media *m_ptr;
|
|
|
|
struct bearer_name b_name;
|
|
|
|
char addr_string[16];
|
|
|
|
u32 bearer_id;
|
|
|
|
u32 with_this_prio;
|
|
|
|
u32 i;
|
|
|
|
int res = -EINVAL;
|
|
|
|
|
2006-06-26 14:52:17 +08:00
|
|
|
if (tipc_mode != TIPC_NET_MODE) {
|
|
|
|
warn("Bearer <%s> rejected, not supported in standalone mode\n",
|
|
|
|
name);
|
2006-01-03 02:04:38 +08:00
|
|
|
return -ENOPROTOOPT;
|
2006-06-26 14:52:17 +08:00
|
|
|
}
|
|
|
|
if (!bearer_name_validate(name, &b_name)) {
|
|
|
|
warn("Bearer <%s> rejected, illegal name\n", name);
|
2006-01-14 05:22:22 +08:00
|
|
|
return -EINVAL;
|
2006-06-26 14:52:17 +08:00
|
|
|
}
|
2011-04-21 05:24:07 +08:00
|
|
|
if (tipc_addr_domain_valid(disc_domain) &&
|
|
|
|
(disc_domain != tipc_own_addr)) {
|
|
|
|
if (tipc_in_scope(disc_domain, tipc_own_addr)) {
|
|
|
|
disc_domain = tipc_own_addr & TIPC_CLUSTER_MASK;
|
|
|
|
res = 0; /* accept any node in own cluster */
|
|
|
|
} else if (in_own_cluster(disc_domain))
|
|
|
|
res = 0; /* accept specified node in own cluster */
|
|
|
|
}
|
|
|
|
if (res) {
|
2011-03-01 03:56:15 +08:00
|
|
|
warn("Bearer <%s> rejected, illegal discovery domain\n", name);
|
2006-06-26 14:52:17 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2006-01-14 05:22:22 +08:00
|
|
|
if ((priority < TIPC_MIN_LINK_PRI ||
|
|
|
|
priority > TIPC_MAX_LINK_PRI) &&
|
2006-06-26 14:52:17 +08:00
|
|
|
(priority != TIPC_MEDIA_LINK_PRI)) {
|
|
|
|
warn("Bearer <%s> rejected, illegal priority\n", name);
|
2006-01-03 02:04:38 +08:00
|
|
|
return -EINVAL;
|
2006-06-26 14:52:17 +08:00
|
|
|
}
|
2006-01-03 02:04:38 +08:00
|
|
|
|
2006-01-18 07:38:21 +08:00
|
|
|
write_lock_bh(&tipc_net_lock);
|
2006-01-03 02:04:38 +08:00
|
|
|
|
|
|
|
m_ptr = media_find(b_name.media_name);
|
|
|
|
if (!m_ptr) {
|
2006-06-26 14:52:17 +08:00
|
|
|
warn("Bearer <%s> rejected, media <%s> not registered\n", name,
|
|
|
|
b_name.media_name);
|
2011-04-22 02:58:26 +08:00
|
|
|
goto exit;
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
2006-01-14 05:22:22 +08:00
|
|
|
|
|
|
|
if (priority == TIPC_MEDIA_LINK_PRI)
|
2006-01-03 02:04:38 +08:00
|
|
|
priority = m_ptr->priority;
|
|
|
|
|
|
|
|
restart:
|
|
|
|
bearer_id = MAX_BEARERS;
|
|
|
|
with_this_prio = 1;
|
|
|
|
for (i = MAX_BEARERS; i-- != 0; ) {
|
2006-01-18 07:38:21 +08:00
|
|
|
if (!tipc_bearers[i].active) {
|
2006-01-03 02:04:38 +08:00
|
|
|
bearer_id = i;
|
|
|
|
continue;
|
|
|
|
}
|
2011-01-08 02:00:11 +08:00
|
|
|
if (!strcmp(name, tipc_bearers[i].name)) {
|
2006-06-26 14:52:17 +08:00
|
|
|
warn("Bearer <%s> rejected, already enabled\n", name);
|
2011-04-22 02:58:26 +08:00
|
|
|
goto exit;
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
2006-01-18 07:38:21 +08:00
|
|
|
if ((tipc_bearers[i].priority == priority) &&
|
2006-01-03 02:04:38 +08:00
|
|
|
(++with_this_prio > 2)) {
|
|
|
|
if (priority-- == 0) {
|
2006-06-26 14:52:17 +08:00
|
|
|
warn("Bearer <%s> rejected, duplicate priority\n",
|
|
|
|
name);
|
2011-04-22 02:58:26 +08:00
|
|
|
goto exit;
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
2006-06-26 14:52:17 +08:00
|
|
|
warn("Bearer <%s> priority adjustment required %u->%u\n",
|
2006-01-03 02:04:38 +08:00
|
|
|
name, priority + 1, priority);
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bearer_id >= MAX_BEARERS) {
|
2007-02-09 22:25:21 +08:00
|
|
|
warn("Bearer <%s> rejected, bearer limit reached (%u)\n",
|
2006-06-26 14:52:17 +08:00
|
|
|
name, MAX_BEARERS);
|
2011-04-22 02:58:26 +08:00
|
|
|
goto exit;
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
2006-01-18 07:38:21 +08:00
|
|
|
b_ptr = &tipc_bearers[bearer_id];
|
2011-01-08 02:00:11 +08:00
|
|
|
strcpy(b_ptr->name, name);
|
|
|
|
res = m_ptr->enable_bearer(b_ptr);
|
2006-01-03 02:04:38 +08:00
|
|
|
if (res) {
|
2006-06-26 14:52:17 +08:00
|
|
|
warn("Bearer <%s> rejected, enable failure (%d)\n", name, -res);
|
2011-04-22 02:58:26 +08:00
|
|
|
goto exit;
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
b_ptr->identity = bearer_id;
|
|
|
|
b_ptr->media = m_ptr;
|
|
|
|
b_ptr->net_plane = bearer_id + 'A';
|
|
|
|
b_ptr->active = 1;
|
|
|
|
b_ptr->priority = priority;
|
|
|
|
INIT_LIST_HEAD(&b_ptr->cong_links);
|
|
|
|
INIT_LIST_HEAD(&b_ptr->links);
|
2011-01-08 02:00:11 +08:00
|
|
|
spin_lock_init(&b_ptr->lock);
|
2011-04-22 02:58:26 +08:00
|
|
|
|
|
|
|
res = tipc_disc_create(b_ptr, &m_ptr->bcast_addr, disc_domain);
|
|
|
|
if (res) {
|
|
|
|
bearer_disable(b_ptr);
|
|
|
|
warn("Bearer <%s> rejected, discovery object creation failed\n",
|
|
|
|
name);
|
|
|
|
goto exit;
|
|
|
|
}
|
2006-01-14 05:22:22 +08:00
|
|
|
info("Enabled bearer <%s>, discovery domain %s, priority %u\n",
|
2011-03-01 03:56:15 +08:00
|
|
|
name, tipc_addr_string_fill(addr_string, disc_domain), priority);
|
2011-04-22 02:58:26 +08:00
|
|
|
exit:
|
2006-01-18 07:38:21 +08:00
|
|
|
write_unlock_bh(&tipc_net_lock);
|
2006-01-03 02:04:38 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tipc_block_bearer(): Block the bearer with the given name,
|
|
|
|
* and reset all its links
|
|
|
|
*/
|
|
|
|
|
|
|
|
int tipc_block_bearer(const char *name)
|
|
|
|
{
|
2011-01-08 02:00:11 +08:00
|
|
|
struct tipc_bearer *b_ptr = NULL;
|
2006-01-03 02:04:38 +08:00
|
|
|
struct link *l_ptr;
|
|
|
|
struct link *temp_l_ptr;
|
|
|
|
|
2006-01-18 07:38:21 +08:00
|
|
|
read_lock_bh(&tipc_net_lock);
|
2006-01-03 02:04:38 +08:00
|
|
|
b_ptr = bearer_find(name);
|
|
|
|
if (!b_ptr) {
|
|
|
|
warn("Attempt to block unknown bearer <%s>\n", name);
|
2006-01-18 07:38:21 +08:00
|
|
|
read_unlock_bh(&tipc_net_lock);
|
2006-01-03 02:04:38 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2006-06-26 14:52:17 +08:00
|
|
|
info("Blocking bearer <%s>\n", name);
|
2011-01-08 02:00:11 +08:00
|
|
|
spin_lock_bh(&b_ptr->lock);
|
|
|
|
b_ptr->blocked = 1;
|
2011-05-27 01:59:17 +08:00
|
|
|
list_splice_init(&b_ptr->cong_links, &b_ptr->links);
|
2006-01-03 02:04:38 +08:00
|
|
|
list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
|
2008-09-03 14:38:32 +08:00
|
|
|
struct tipc_node *n_ptr = l_ptr->owner;
|
2006-01-03 02:04:38 +08:00
|
|
|
|
|
|
|
spin_lock_bh(&n_ptr->lock);
|
2006-01-18 07:38:21 +08:00
|
|
|
tipc_link_reset(l_ptr);
|
2006-01-03 02:04:38 +08:00
|
|
|
spin_unlock_bh(&n_ptr->lock);
|
|
|
|
}
|
2011-01-08 02:00:11 +08:00
|
|
|
spin_unlock_bh(&b_ptr->lock);
|
2006-01-18 07:38:21 +08:00
|
|
|
read_unlock_bh(&tipc_net_lock);
|
2008-07-15 13:44:01 +08:00
|
|
|
return 0;
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bearer_disable -
|
2007-02-09 22:25:21 +08:00
|
|
|
*
|
2006-01-18 07:38:21 +08:00
|
|
|
* Note: This routine assumes caller holds tipc_net_lock.
|
2006-01-03 02:04:38 +08:00
|
|
|
*/
|
|
|
|
|
2011-01-08 02:00:11 +08:00
|
|
|
static void bearer_disable(struct tipc_bearer *b_ptr)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
|
|
|
struct link *l_ptr;
|
|
|
|
struct link *temp_l_ptr;
|
|
|
|
|
2011-01-08 02:00:11 +08:00
|
|
|
info("Disabling bearer <%s>\n", b_ptr->name);
|
|
|
|
spin_lock_bh(&b_ptr->lock);
|
|
|
|
b_ptr->blocked = 1;
|
|
|
|
b_ptr->media->disable_bearer(b_ptr);
|
2011-05-27 01:59:17 +08:00
|
|
|
list_splice_init(&b_ptr->cong_links, &b_ptr->links);
|
2006-01-03 02:04:38 +08:00
|
|
|
list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
|
2006-01-18 07:38:21 +08:00
|
|
|
tipc_link_delete(l_ptr);
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
2011-04-22 02:58:26 +08:00
|
|
|
if (b_ptr->link_req)
|
|
|
|
tipc_disc_delete(b_ptr->link_req);
|
2011-01-08 02:00:11 +08:00
|
|
|
spin_unlock_bh(&b_ptr->lock);
|
|
|
|
memset(b_ptr, 0, sizeof(struct tipc_bearer));
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int tipc_disable_bearer(const char *name)
|
|
|
|
{
|
2011-01-08 02:00:11 +08:00
|
|
|
struct tipc_bearer *b_ptr;
|
2006-01-03 02:04:38 +08:00
|
|
|
int res;
|
|
|
|
|
2006-01-18 07:38:21 +08:00
|
|
|
write_lock_bh(&tipc_net_lock);
|
2010-10-14 21:58:26 +08:00
|
|
|
b_ptr = bearer_find(name);
|
|
|
|
if (b_ptr == NULL) {
|
|
|
|
warn("Attempt to disable unknown bearer <%s>\n", name);
|
|
|
|
res = -EINVAL;
|
2010-11-30 20:00:56 +08:00
|
|
|
} else {
|
|
|
|
bearer_disable(b_ptr);
|
|
|
|
res = 0;
|
|
|
|
}
|
2006-01-18 07:38:21 +08:00
|
|
|
write_unlock_bh(&tipc_net_lock);
|
2006-01-03 02:04:38 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-01-18 07:38:21 +08:00
|
|
|
void tipc_bearer_stop(void)
|
2006-01-03 02:04:38 +08:00
|
|
|
{
|
|
|
|
u32 i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_BEARERS; i++) {
|
2006-01-18 07:38:21 +08:00
|
|
|
if (tipc_bearers[i].active)
|
2010-10-14 21:58:26 +08:00
|
|
|
bearer_disable(&tipc_bearers[i]);
|
2006-01-03 02:04:38 +08:00
|
|
|
}
|
|
|
|
media_count = 0;
|
|
|
|
}
|