2006-01-02 21:04:38 +03:00
|
|
|
/*
|
|
|
|
* net/tipc/bearer.c: TIPC bearer code
|
2007-02-09 17:25:21 +03:00
|
|
|
*
|
2014-11-20 12:29:07 +03:00
|
|
|
* Copyright (c) 1996-2006, 2013-2014, Ericsson AB
|
2013-12-11 08:45:43 +04:00
|
|
|
* Copyright (c) 2004-2006, 2010-2013, Wind River Systems
|
2006-01-02 21:04:38 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2006-01-11 15:30:43 +03:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
2006-01-02 21:04:38 +03:00
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
2006-01-11 15:30:43 +03: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 21:04:38 +03:00
|
|
|
*
|
2006-01-11 15:30:43 +03: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 21:04:38 +03:00
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "core.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "bearer.h"
|
2014-11-20 12:29:07 +03:00
|
|
|
#include "link.h"
|
2006-01-02 21:04:38 +03:00
|
|
|
#include "discover.h"
|
|
|
|
|
2013-04-17 10:18:28 +04:00
|
|
|
#define MAX_ADDR_STR 60
|
2006-01-02 21:04:38 +03:00
|
|
|
|
2013-12-11 08:45:40 +04:00
|
|
|
static struct tipc_media * const media_info_array[] = {
|
2013-12-11 08:45:39 +04:00
|
|
|
ð_media_info,
|
|
|
|
#ifdef CONFIG_TIPC_MEDIA_IB
|
|
|
|
&ib_media_info,
|
|
|
|
#endif
|
|
|
|
NULL
|
|
|
|
};
|
2006-01-02 21:04:38 +03:00
|
|
|
|
2014-11-20 12:29:07 +03:00
|
|
|
static const struct nla_policy
|
|
|
|
tipc_nl_bearer_policy[TIPC_NLA_BEARER_MAX + 1] = {
|
|
|
|
[TIPC_NLA_BEARER_UNSPEC] = { .type = NLA_UNSPEC },
|
|
|
|
[TIPC_NLA_BEARER_NAME] = {
|
|
|
|
.type = NLA_STRING,
|
|
|
|
.len = TIPC_MAX_BEARER_NAME
|
|
|
|
},
|
|
|
|
[TIPC_NLA_BEARER_PROP] = { .type = NLA_NESTED },
|
|
|
|
[TIPC_NLA_BEARER_DOMAIN] = { .type = NLA_U32 }
|
|
|
|
};
|
|
|
|
|
2014-11-20 12:29:15 +03:00
|
|
|
static const struct nla_policy tipc_nl_media_policy[TIPC_NLA_MEDIA_MAX + 1] = {
|
|
|
|
[TIPC_NLA_MEDIA_UNSPEC] = { .type = NLA_UNSPEC },
|
|
|
|
[TIPC_NLA_MEDIA_NAME] = { .type = NLA_STRING },
|
|
|
|
[TIPC_NLA_MEDIA_PROP] = { .type = NLA_NESTED }
|
|
|
|
};
|
|
|
|
|
2014-04-21 06:55:45 +04:00
|
|
|
struct tipc_bearer __rcu *bearer_list[MAX_BEARERS + 1];
|
2006-01-02 21:04:38 +03:00
|
|
|
|
tipc: delay delete of link when failover is needed
When a bearer is disabled, all its attached links are deleted.
Ideally, we should do link failover to redundant links on other bearers,
if there are any, in such cases. This would be consistent with current
behavior when a link is reset, but not deleted. However, due to the
complexity involved, and the (wrongly) perceived low demand for this
feature, it was never implemented until now.
We mark the doomed link for deletion with a new flag, but wait until the
failover process is finished before we actually delete it. With the
improved link tunnelling/failover code introduced earlier in this commit
series, it is now easy to identify a spot in the code where the failover
is finished and it is safe to delete the marked link. Moreover, the test
for the flag and the deletion can be done synchronously, and outside the
most time critical data path.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-14 02:29:16 +04:00
|
|
|
static void bearer_disable(struct tipc_bearer *b_ptr, bool shutting_down);
|
2011-04-21 22:58:26 +04:00
|
|
|
|
2006-01-02 21:04:38 +03:00
|
|
|
/**
|
2011-10-18 19:34:29 +04:00
|
|
|
* tipc_media_find - locates specified media object by name
|
2006-01-02 21:04:38 +03:00
|
|
|
*/
|
2011-12-30 05:19:42 +04:00
|
|
|
struct tipc_media *tipc_media_find(const char *name)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
|
|
|
u32 i;
|
|
|
|
|
2013-12-11 08:45:40 +04:00
|
|
|
for (i = 0; media_info_array[i] != NULL; i++) {
|
|
|
|
if (!strcmp(media_info_array[i]->name, name))
|
2013-12-11 08:45:39 +04:00
|
|
|
break;
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
2013-12-11 08:45:40 +04:00
|
|
|
return media_info_array[i];
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
|
2011-10-07 00:40:55 +04:00
|
|
|
/**
|
|
|
|
* media_find_id - locates specified media object by type identifier
|
|
|
|
*/
|
2011-12-30 05:19:42 +04:00
|
|
|
static struct tipc_media *media_find_id(u8 type)
|
2011-10-07 00:40:55 +04:00
|
|
|
{
|
|
|
|
u32 i;
|
|
|
|
|
2013-12-11 08:45:40 +04:00
|
|
|
for (i = 0; media_info_array[i] != NULL; i++) {
|
|
|
|
if (media_info_array[i]->type_id == type)
|
2013-12-11 08:45:39 +04:00
|
|
|
break;
|
2011-10-07 00:40:55 +04:00
|
|
|
}
|
2013-12-11 08:45:40 +04:00
|
|
|
return media_info_array[i];
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-01-18 02:38:21 +03:00
|
|
|
* tipc_media_addr_printf - record media address in print buffer
|
2006-01-02 21:04:38 +03:00
|
|
|
*/
|
2012-06-29 08:50:23 +04:00
|
|
|
void tipc_media_addr_printf(char *buf, int len, struct tipc_media_addr *a)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
2011-10-07 19:31:49 +04:00
|
|
|
char addr_str[MAX_ADDR_STR];
|
2011-12-30 05:19:42 +04:00
|
|
|
struct tipc_media *m_ptr;
|
2012-06-29 08:50:23 +04:00
|
|
|
int ret;
|
2006-01-02 21:04:38 +03:00
|
|
|
|
2011-10-07 23:19:11 +04:00
|
|
|
m_ptr = media_find_id(a->media_id);
|
2006-01-02 21:04:38 +03:00
|
|
|
|
2011-10-07 19:31:49 +04:00
|
|
|
if (m_ptr && !m_ptr->addr2str(a, addr_str, sizeof(addr_str)))
|
2012-06-29 08:50:23 +04:00
|
|
|
ret = tipc_snprintf(buf, len, "%s(%s)", m_ptr->name, addr_str);
|
2011-10-07 19:31:49 +04:00
|
|
|
else {
|
|
|
|
u32 i;
|
2006-01-02 21:04:38 +03:00
|
|
|
|
2012-06-29 08:50:23 +04:00
|
|
|
ret = tipc_snprintf(buf, len, "UNKNOWN(%u)", a->media_id);
|
2011-10-07 23:19:11 +04:00
|
|
|
for (i = 0; i < sizeof(a->value); i++)
|
2012-06-29 08:50:23 +04:00
|
|
|
ret += tipc_snprintf(buf - ret, len + ret,
|
|
|
|
"-%02x", a->value[i]);
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-01-18 02:38:21 +03:00
|
|
|
* tipc_media_get_names - record names of registered media in buffer
|
2006-01-02 21:04:38 +03:00
|
|
|
*/
|
2006-01-18 02:38:21 +03:00
|
|
|
struct sk_buff *tipc_media_get_names(void)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
|
|
|
struct sk_buff *buf;
|
|
|
|
int i;
|
|
|
|
|
2006-01-18 02:38:21 +03:00
|
|
|
buf = tipc_cfg_reply_alloc(MAX_MEDIA * TLV_SPACE(TIPC_MAX_MEDIA_NAME));
|
2006-01-02 21:04:38 +03:00
|
|
|
if (!buf)
|
|
|
|
return NULL;
|
|
|
|
|
2013-12-11 08:45:40 +04:00
|
|
|
for (i = 0; media_info_array[i] != NULL; i++) {
|
2011-10-07 17:25:12 +04:00
|
|
|
tipc_cfg_append_tlv(buf, TIPC_TLV_MEDIA_NAME,
|
2013-12-11 08:45:40 +04:00
|
|
|
media_info_array[i]->name,
|
|
|
|
strlen(media_info_array[i]->name) + 1);
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bearer_name_validate - validate & (optionally) deconstruct bearer name
|
2012-07-10 14:55:09 +04:00
|
|
|
* @name: ptr to bearer name string
|
|
|
|
* @name_parts: ptr to area for bearer name components (or NULL if not needed)
|
2007-02-09 17:25:21 +03:00
|
|
|
*
|
2006-01-02 21:04:38 +03:00
|
|
|
* Returns 1 if bearer name is valid, otherwise 0.
|
|
|
|
*/
|
2007-02-09 17:25:21 +03:00
|
|
|
static int bearer_name_validate(const char *name,
|
2011-12-30 06:39:49 +04:00
|
|
|
struct tipc_bearer_names *name_parts)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
|
|
|
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;
|
2010-12-31 21:59:33 +03:00
|
|
|
if_name = strchr(media_name, ':');
|
|
|
|
if (if_name == NULL)
|
2006-01-02 21:04:38 +03: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 17:25:21 +03:00
|
|
|
if ((media_len <= 1) || (media_len > TIPC_MAX_MEDIA_NAME) ||
|
2012-08-16 16:09:08 +04:00
|
|
|
(if_len <= 1) || (if_len > TIPC_MAX_IF_NAME))
|
2006-01-02 21:04:38 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-10-18 19:34:29 +04:00
|
|
|
* tipc_bearer_find - locates bearer object with matching bearer name
|
2006-01-02 21:04:38 +03:00
|
|
|
*/
|
2011-10-18 19:34:29 +04:00
|
|
|
struct tipc_bearer *tipc_bearer_find(const char *name)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
2011-01-07 21:00:11 +03:00
|
|
|
struct tipc_bearer *b_ptr;
|
2006-01-02 21:04:38 +03:00
|
|
|
u32 i;
|
|
|
|
|
2014-03-27 08:54:33 +04:00
|
|
|
for (i = 0; i < MAX_BEARERS; i++) {
|
2014-04-21 06:55:45 +04:00
|
|
|
b_ptr = rtnl_dereference(bearer_list[i]);
|
2014-03-27 08:54:34 +04:00
|
|
|
if (b_ptr && (!strcmp(b_ptr->name, name)))
|
2006-01-02 21:04:38 +03:00
|
|
|
return b_ptr;
|
|
|
|
}
|
2006-03-21 09:36:47 +03:00
|
|
|
return NULL;
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-01-18 02:38:21 +03:00
|
|
|
* tipc_bearer_get_names - record names of bearers in buffer
|
2006-01-02 21:04:38 +03:00
|
|
|
*/
|
2006-01-18 02:38:21 +03:00
|
|
|
struct sk_buff *tipc_bearer_get_names(void)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
|
|
|
struct sk_buff *buf;
|
2013-12-11 08:45:40 +04:00
|
|
|
struct tipc_bearer *b;
|
2006-01-02 21:04:38 +03:00
|
|
|
int i, j;
|
|
|
|
|
2006-01-18 02:38:21 +03:00
|
|
|
buf = tipc_cfg_reply_alloc(MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME));
|
2006-01-02 21:04:38 +03:00
|
|
|
if (!buf)
|
|
|
|
return NULL;
|
|
|
|
|
2013-12-11 08:45:40 +04:00
|
|
|
for (i = 0; media_info_array[i] != NULL; i++) {
|
2006-01-02 21:04:38 +03:00
|
|
|
for (j = 0; j < MAX_BEARERS; j++) {
|
2014-04-21 06:55:45 +04:00
|
|
|
b = rtnl_dereference(bearer_list[j]);
|
2014-03-27 08:54:33 +04:00
|
|
|
if (!b)
|
|
|
|
continue;
|
2014-03-27 08:54:34 +04:00
|
|
|
if (b->media == media_info_array[i]) {
|
2007-02-09 17:25:21 +03:00
|
|
|
tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME,
|
2013-12-11 08:45:40 +04:00
|
|
|
b->name,
|
|
|
|
strlen(b->name) + 1);
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
tipc: decouple the relationship between bearer and link
Currently on both paths of message transmission and reception, the
read lock of tipc_net_lock must be held before bearer is accessed,
while the write lock of tipc_net_lock has to be taken before bearer
is configured. Although it can ensure that bearer is always valid on
the two data paths, link and bearer is closely bound together.
So as the part of effort of removing tipc_net_lock, the locking
policy of bearer protection will be adjusted as below: on the two
data paths, RCU is used, and on the configuration path of bearer,
RTNL lock is applied.
Now RCU just covers the path of message reception. To make it possible
to protect the path of message transmission with RCU, link should not
use its stored bearer pointer to access bearer, but it should use the
bearer identity of its attached bearer as index to get bearer instance
from bearer_list array, which can help us decouple the relationship
between bearer and link. As a result, bearer on the path of message
transmission can be safely protected by RCU when we access bearer_list
array within RCU lock protection.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 06:55:46 +04:00
|
|
|
void tipc_bearer_add_dest(u32 bearer_id, u32 dest)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
tipc: decouple the relationship between bearer and link
Currently on both paths of message transmission and reception, the
read lock of tipc_net_lock must be held before bearer is accessed,
while the write lock of tipc_net_lock has to be taken before bearer
is configured. Although it can ensure that bearer is always valid on
the two data paths, link and bearer is closely bound together.
So as the part of effort of removing tipc_net_lock, the locking
policy of bearer protection will be adjusted as below: on the two
data paths, RCU is used, and on the configuration path of bearer,
RTNL lock is applied.
Now RCU just covers the path of message reception. To make it possible
to protect the path of message transmission with RCU, link should not
use its stored bearer pointer to access bearer, but it should use the
bearer identity of its attached bearer as index to get bearer instance
from bearer_list array, which can help us decouple the relationship
between bearer and link. As a result, bearer on the path of message
transmission can be safely protected by RCU when we access bearer_list
array within RCU lock protection.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 06:55:46 +04:00
|
|
|
struct tipc_bearer *b_ptr;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
b_ptr = rcu_dereference_rtnl(bearer_list[bearer_id]);
|
|
|
|
if (b_ptr) {
|
2014-04-21 06:55:51 +04:00
|
|
|
tipc_bcbearer_sort(&b_ptr->nodes, dest, true);
|
tipc: decouple the relationship between bearer and link
Currently on both paths of message transmission and reception, the
read lock of tipc_net_lock must be held before bearer is accessed,
while the write lock of tipc_net_lock has to be taken before bearer
is configured. Although it can ensure that bearer is always valid on
the two data paths, link and bearer is closely bound together.
So as the part of effort of removing tipc_net_lock, the locking
policy of bearer protection will be adjusted as below: on the two
data paths, RCU is used, and on the configuration path of bearer,
RTNL lock is applied.
Now RCU just covers the path of message reception. To make it possible
to protect the path of message transmission with RCU, link should not
use its stored bearer pointer to access bearer, but it should use the
bearer identity of its attached bearer as index to get bearer instance
from bearer_list array, which can help us decouple the relationship
between bearer and link. As a result, bearer on the path of message
transmission can be safely protected by RCU when we access bearer_list
array within RCU lock protection.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 06:55:46 +04:00
|
|
|
tipc_disc_add_dest(b_ptr->link_req);
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
|
tipc: decouple the relationship between bearer and link
Currently on both paths of message transmission and reception, the
read lock of tipc_net_lock must be held before bearer is accessed,
while the write lock of tipc_net_lock has to be taken before bearer
is configured. Although it can ensure that bearer is always valid on
the two data paths, link and bearer is closely bound together.
So as the part of effort of removing tipc_net_lock, the locking
policy of bearer protection will be adjusted as below: on the two
data paths, RCU is used, and on the configuration path of bearer,
RTNL lock is applied.
Now RCU just covers the path of message reception. To make it possible
to protect the path of message transmission with RCU, link should not
use its stored bearer pointer to access bearer, but it should use the
bearer identity of its attached bearer as index to get bearer instance
from bearer_list array, which can help us decouple the relationship
between bearer and link. As a result, bearer on the path of message
transmission can be safely protected by RCU when we access bearer_list
array within RCU lock protection.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 06:55:46 +04:00
|
|
|
void tipc_bearer_remove_dest(u32 bearer_id, u32 dest)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
tipc: decouple the relationship between bearer and link
Currently on both paths of message transmission and reception, the
read lock of tipc_net_lock must be held before bearer is accessed,
while the write lock of tipc_net_lock has to be taken before bearer
is configured. Although it can ensure that bearer is always valid on
the two data paths, link and bearer is closely bound together.
So as the part of effort of removing tipc_net_lock, the locking
policy of bearer protection will be adjusted as below: on the two
data paths, RCU is used, and on the configuration path of bearer,
RTNL lock is applied.
Now RCU just covers the path of message reception. To make it possible
to protect the path of message transmission with RCU, link should not
use its stored bearer pointer to access bearer, but it should use the
bearer identity of its attached bearer as index to get bearer instance
from bearer_list array, which can help us decouple the relationship
between bearer and link. As a result, bearer on the path of message
transmission can be safely protected by RCU when we access bearer_list
array within RCU lock protection.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 06:55:46 +04:00
|
|
|
struct tipc_bearer *b_ptr;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
b_ptr = rcu_dereference_rtnl(bearer_list[bearer_id]);
|
|
|
|
if (b_ptr) {
|
2014-04-21 06:55:51 +04:00
|
|
|
tipc_bcbearer_sort(&b_ptr->nodes, dest, false);
|
tipc: decouple the relationship between bearer and link
Currently on both paths of message transmission and reception, the
read lock of tipc_net_lock must be held before bearer is accessed,
while the write lock of tipc_net_lock has to be taken before bearer
is configured. Although it can ensure that bearer is always valid on
the two data paths, link and bearer is closely bound together.
So as the part of effort of removing tipc_net_lock, the locking
policy of bearer protection will be adjusted as below: on the two
data paths, RCU is used, and on the configuration path of bearer,
RTNL lock is applied.
Now RCU just covers the path of message reception. To make it possible
to protect the path of message transmission with RCU, link should not
use its stored bearer pointer to access bearer, but it should use the
bearer identity of its attached bearer as index to get bearer instance
from bearer_list array, which can help us decouple the relationship
between bearer and link. As a result, bearer on the path of message
transmission can be safely protected by RCU when we access bearer_list
array within RCU lock protection.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 06:55:46 +04:00
|
|
|
tipc_disc_remove_dest(b_ptr->link_req);
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tipc_enable_bearer - enable bearer with the given name
|
2007-02-09 17:25:21 +03:00
|
|
|
*/
|
2015-01-09 10:27:04 +03:00
|
|
|
int tipc_enable_bearer(struct net *net, const char *name, u32 disc_domain,
|
|
|
|
u32 priority)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
2011-01-07 21:00:11 +03:00
|
|
|
struct tipc_bearer *b_ptr;
|
2011-12-30 05:19:42 +04:00
|
|
|
struct tipc_media *m_ptr;
|
2011-12-30 06:39:49 +04:00
|
|
|
struct tipc_bearer_names b_names;
|
2006-01-02 21:04:38 +03:00
|
|
|
char addr_string[16];
|
|
|
|
u32 bearer_id;
|
|
|
|
u32 with_this_prio;
|
|
|
|
u32 i;
|
|
|
|
int res = -EINVAL;
|
|
|
|
|
2011-11-08 22:48:28 +04:00
|
|
|
if (!tipc_own_addr) {
|
2012-06-29 08:16:37 +04:00
|
|
|
pr_warn("Bearer <%s> rejected, not supported in standalone mode\n",
|
|
|
|
name);
|
2006-01-02 21:04:38 +03:00
|
|
|
return -ENOPROTOOPT;
|
2006-06-26 10:52:17 +04:00
|
|
|
}
|
2011-12-30 06:39:49 +04:00
|
|
|
if (!bearer_name_validate(name, &b_names)) {
|
2012-06-29 08:16:37 +04:00
|
|
|
pr_warn("Bearer <%s> rejected, illegal name\n", name);
|
2006-01-14 00:22:22 +03:00
|
|
|
return -EINVAL;
|
2006-06-26 10:52:17 +04:00
|
|
|
}
|
2011-04-21 01:24:07 +04: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 */
|
2012-04-18 02:02:01 +04:00
|
|
|
} else if (in_own_cluster_exact(disc_domain))
|
2011-04-21 01:24:07 +04:00
|
|
|
res = 0; /* accept specified node in own cluster */
|
|
|
|
}
|
|
|
|
if (res) {
|
2012-06-29 08:16:37 +04:00
|
|
|
pr_warn("Bearer <%s> rejected, illegal discovery domain\n",
|
|
|
|
name);
|
2006-06-26 10:52:17 +04:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2011-11-03 21:15:10 +04:00
|
|
|
if ((priority > TIPC_MAX_LINK_PRI) &&
|
2006-06-26 10:52:17 +04:00
|
|
|
(priority != TIPC_MEDIA_LINK_PRI)) {
|
2012-06-29 08:16:37 +04:00
|
|
|
pr_warn("Bearer <%s> rejected, illegal priority\n", name);
|
2006-01-02 21:04:38 +03:00
|
|
|
return -EINVAL;
|
2006-06-26 10:52:17 +04:00
|
|
|
}
|
2006-01-02 21:04:38 +03:00
|
|
|
|
2011-12-30 06:39:49 +04:00
|
|
|
m_ptr = tipc_media_find(b_names.media_name);
|
2006-01-02 21:04:38 +03:00
|
|
|
if (!m_ptr) {
|
2012-06-29 08:16:37 +04:00
|
|
|
pr_warn("Bearer <%s> rejected, media <%s> not registered\n",
|
|
|
|
name, b_names.media_name);
|
tipc: purge tipc_net_lock lock
Now tipc routing hierarchy comprises the structures 'node', 'link'and
'bearer'. The whole hierarchy is protected by a big read/write lock,
tipc_net_lock, to ensure that nothing is added or removed while code
is accessing any of these structures. Obviously the locking policy
makes node, link and bearer components closely bound together so that
their relationship becomes unnecessarily complex. In the worst case,
such locking policy not only has a negative influence on performance,
but also it's prone to lead to deadlock occasionally.
In order o decouple the complex relationship between bearer and node
as well as link, the locking policy is adjusted as follows:
- Bearer level
RTNL lock is used on update side, and RCU is used on read side.
Meanwhile, all bearer instances including broadcast bearer are
saved into bearer_list array.
- Node and link level
All node instances are saved into two tipc_node_list and node_htable
lists. The two lists are protected by node_list_lock on write side,
and they are guarded with RCU lock on read side. All members in node
structure including link instances are protected by node spin lock.
- The relationship between bearer and node
When link accesses bearer, it first needs to find the bearer with
its bearer identity from the bearer_list array. When bearer accesses
node, it can iterate the node_htable hash list with the node
address to find the corresponding node.
In the new locking policy, every component has its private locking
solution and the relationship between bearer and node is very simple,
that is, they can find each other with node address or bearer identity
from node_htable hash list or bearer_list array.
Until now above all changes have been done, so tipc_net_lock can be
removed safely.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 06:55:48 +04:00
|
|
|
return -EINVAL;
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
2006-01-14 00:22:22 +03:00
|
|
|
|
|
|
|
if (priority == TIPC_MEDIA_LINK_PRI)
|
2006-01-02 21:04:38 +03:00
|
|
|
priority = m_ptr->priority;
|
|
|
|
|
|
|
|
restart:
|
|
|
|
bearer_id = MAX_BEARERS;
|
|
|
|
with_this_prio = 1;
|
|
|
|
for (i = MAX_BEARERS; i-- != 0; ) {
|
2014-04-21 06:55:45 +04:00
|
|
|
b_ptr = rtnl_dereference(bearer_list[i]);
|
2014-03-27 08:54:34 +04:00
|
|
|
if (!b_ptr) {
|
2006-01-02 21:04:38 +03:00
|
|
|
bearer_id = i;
|
|
|
|
continue;
|
|
|
|
}
|
2014-03-27 08:54:33 +04:00
|
|
|
if (!strcmp(name, b_ptr->name)) {
|
2012-06-29 08:16:37 +04:00
|
|
|
pr_warn("Bearer <%s> rejected, already enabled\n",
|
|
|
|
name);
|
tipc: purge tipc_net_lock lock
Now tipc routing hierarchy comprises the structures 'node', 'link'and
'bearer'. The whole hierarchy is protected by a big read/write lock,
tipc_net_lock, to ensure that nothing is added or removed while code
is accessing any of these structures. Obviously the locking policy
makes node, link and bearer components closely bound together so that
their relationship becomes unnecessarily complex. In the worst case,
such locking policy not only has a negative influence on performance,
but also it's prone to lead to deadlock occasionally.
In order o decouple the complex relationship between bearer and node
as well as link, the locking policy is adjusted as follows:
- Bearer level
RTNL lock is used on update side, and RCU is used on read side.
Meanwhile, all bearer instances including broadcast bearer are
saved into bearer_list array.
- Node and link level
All node instances are saved into two tipc_node_list and node_htable
lists. The two lists are protected by node_list_lock on write side,
and they are guarded with RCU lock on read side. All members in node
structure including link instances are protected by node spin lock.
- The relationship between bearer and node
When link accesses bearer, it first needs to find the bearer with
its bearer identity from the bearer_list array. When bearer accesses
node, it can iterate the node_htable hash list with the node
address to find the corresponding node.
In the new locking policy, every component has its private locking
solution and the relationship between bearer and node is very simple,
that is, they can find each other with node address or bearer identity
from node_htable hash list or bearer_list array.
Until now above all changes have been done, so tipc_net_lock can be
removed safely.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 06:55:48 +04:00
|
|
|
return -EINVAL;
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
2014-03-27 08:54:33 +04:00
|
|
|
if ((b_ptr->priority == priority) &&
|
2006-01-02 21:04:38 +03:00
|
|
|
(++with_this_prio > 2)) {
|
|
|
|
if (priority-- == 0) {
|
2012-06-29 08:16:37 +04:00
|
|
|
pr_warn("Bearer <%s> rejected, duplicate priority\n",
|
|
|
|
name);
|
tipc: purge tipc_net_lock lock
Now tipc routing hierarchy comprises the structures 'node', 'link'and
'bearer'. The whole hierarchy is protected by a big read/write lock,
tipc_net_lock, to ensure that nothing is added or removed while code
is accessing any of these structures. Obviously the locking policy
makes node, link and bearer components closely bound together so that
their relationship becomes unnecessarily complex. In the worst case,
such locking policy not only has a negative influence on performance,
but also it's prone to lead to deadlock occasionally.
In order o decouple the complex relationship between bearer and node
as well as link, the locking policy is adjusted as follows:
- Bearer level
RTNL lock is used on update side, and RCU is used on read side.
Meanwhile, all bearer instances including broadcast bearer are
saved into bearer_list array.
- Node and link level
All node instances are saved into two tipc_node_list and node_htable
lists. The two lists are protected by node_list_lock on write side,
and they are guarded with RCU lock on read side. All members in node
structure including link instances are protected by node spin lock.
- The relationship between bearer and node
When link accesses bearer, it first needs to find the bearer with
its bearer identity from the bearer_list array. When bearer accesses
node, it can iterate the node_htable hash list with the node
address to find the corresponding node.
In the new locking policy, every component has its private locking
solution and the relationship between bearer and node is very simple,
that is, they can find each other with node address or bearer identity
from node_htable hash list or bearer_list array.
Until now above all changes have been done, so tipc_net_lock can be
removed safely.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 06:55:48 +04:00
|
|
|
return -EINVAL;
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
2012-06-29 08:16:37 +04:00
|
|
|
pr_warn("Bearer <%s> priority adjustment required %u->%u\n",
|
|
|
|
name, priority + 1, priority);
|
2006-01-02 21:04:38 +03:00
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bearer_id >= MAX_BEARERS) {
|
2012-06-29 08:16:37 +04:00
|
|
|
pr_warn("Bearer <%s> rejected, bearer limit reached (%u)\n",
|
|
|
|
name, MAX_BEARERS);
|
tipc: purge tipc_net_lock lock
Now tipc routing hierarchy comprises the structures 'node', 'link'and
'bearer'. The whole hierarchy is protected by a big read/write lock,
tipc_net_lock, to ensure that nothing is added or removed while code
is accessing any of these structures. Obviously the locking policy
makes node, link and bearer components closely bound together so that
their relationship becomes unnecessarily complex. In the worst case,
such locking policy not only has a negative influence on performance,
but also it's prone to lead to deadlock occasionally.
In order o decouple the complex relationship between bearer and node
as well as link, the locking policy is adjusted as follows:
- Bearer level
RTNL lock is used on update side, and RCU is used on read side.
Meanwhile, all bearer instances including broadcast bearer are
saved into bearer_list array.
- Node and link level
All node instances are saved into two tipc_node_list and node_htable
lists. The two lists are protected by node_list_lock on write side,
and they are guarded with RCU lock on read side. All members in node
structure including link instances are protected by node spin lock.
- The relationship between bearer and node
When link accesses bearer, it first needs to find the bearer with
its bearer identity from the bearer_list array. When bearer accesses
node, it can iterate the node_htable hash list with the node
address to find the corresponding node.
In the new locking policy, every component has its private locking
solution and the relationship between bearer and node is very simple,
that is, they can find each other with node address or bearer identity
from node_htable hash list or bearer_list array.
Until now above all changes have been done, so tipc_net_lock can be
removed safely.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 06:55:48 +04:00
|
|
|
return -EINVAL;
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
|
2014-03-27 08:54:33 +04:00
|
|
|
b_ptr = kzalloc(sizeof(*b_ptr), GFP_ATOMIC);
|
tipc: purge tipc_net_lock lock
Now tipc routing hierarchy comprises the structures 'node', 'link'and
'bearer'. The whole hierarchy is protected by a big read/write lock,
tipc_net_lock, to ensure that nothing is added or removed while code
is accessing any of these structures. Obviously the locking policy
makes node, link and bearer components closely bound together so that
their relationship becomes unnecessarily complex. In the worst case,
such locking policy not only has a negative influence on performance,
but also it's prone to lead to deadlock occasionally.
In order o decouple the complex relationship between bearer and node
as well as link, the locking policy is adjusted as follows:
- Bearer level
RTNL lock is used on update side, and RCU is used on read side.
Meanwhile, all bearer instances including broadcast bearer are
saved into bearer_list array.
- Node and link level
All node instances are saved into two tipc_node_list and node_htable
lists. The two lists are protected by node_list_lock on write side,
and they are guarded with RCU lock on read side. All members in node
structure including link instances are protected by node spin lock.
- The relationship between bearer and node
When link accesses bearer, it first needs to find the bearer with
its bearer identity from the bearer_list array. When bearer accesses
node, it can iterate the node_htable hash list with the node
address to find the corresponding node.
In the new locking policy, every component has its private locking
solution and the relationship between bearer and node is very simple,
that is, they can find each other with node address or bearer identity
from node_htable hash list or bearer_list array.
Until now above all changes have been done, so tipc_net_lock can be
removed safely.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 06:55:48 +04:00
|
|
|
if (!b_ptr)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2011-01-07 21:00:11 +03:00
|
|
|
strcpy(b_ptr->name, name);
|
2013-12-11 08:45:43 +04:00
|
|
|
b_ptr->media = m_ptr;
|
2013-10-18 09:23:17 +04:00
|
|
|
res = m_ptr->enable_media(b_ptr);
|
2006-01-02 21:04:38 +03:00
|
|
|
if (res) {
|
2012-06-29 08:16:37 +04:00
|
|
|
pr_warn("Bearer <%s> rejected, enable failure (%d)\n",
|
|
|
|
name, -res);
|
tipc: purge tipc_net_lock lock
Now tipc routing hierarchy comprises the structures 'node', 'link'and
'bearer'. The whole hierarchy is protected by a big read/write lock,
tipc_net_lock, to ensure that nothing is added or removed while code
is accessing any of these structures. Obviously the locking policy
makes node, link and bearer components closely bound together so that
their relationship becomes unnecessarily complex. In the worst case,
such locking policy not only has a negative influence on performance,
but also it's prone to lead to deadlock occasionally.
In order o decouple the complex relationship between bearer and node
as well as link, the locking policy is adjusted as follows:
- Bearer level
RTNL lock is used on update side, and RCU is used on read side.
Meanwhile, all bearer instances including broadcast bearer are
saved into bearer_list array.
- Node and link level
All node instances are saved into two tipc_node_list and node_htable
lists. The two lists are protected by node_list_lock on write side,
and they are guarded with RCU lock on read side. All members in node
structure including link instances are protected by node spin lock.
- The relationship between bearer and node
When link accesses bearer, it first needs to find the bearer with
its bearer identity from the bearer_list array. When bearer accesses
node, it can iterate the node_htable hash list with the node
address to find the corresponding node.
In the new locking policy, every component has its private locking
solution and the relationship between bearer and node is very simple,
that is, they can find each other with node address or bearer identity
from node_htable hash list or bearer_list array.
Until now above all changes have been done, so tipc_net_lock can be
removed safely.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 06:55:48 +04:00
|
|
|
return -EINVAL;
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
b_ptr->identity = bearer_id;
|
2011-10-18 19:34:29 +04:00
|
|
|
b_ptr->tolerance = m_ptr->tolerance;
|
|
|
|
b_ptr->window = m_ptr->window;
|
2014-03-28 13:32:08 +04:00
|
|
|
b_ptr->domain = disc_domain;
|
2006-01-02 21:04:38 +03:00
|
|
|
b_ptr->net_plane = bearer_id + 'A';
|
|
|
|
b_ptr->priority = priority;
|
2011-04-21 22:58:26 +04:00
|
|
|
|
2015-01-09 10:27:04 +03:00
|
|
|
res = tipc_disc_create(net, b_ptr, &b_ptr->bcast_addr);
|
2011-04-21 22:58:26 +04:00
|
|
|
if (res) {
|
tipc: delay delete of link when failover is needed
When a bearer is disabled, all its attached links are deleted.
Ideally, we should do link failover to redundant links on other bearers,
if there are any, in such cases. This would be consistent with current
behavior when a link is reset, but not deleted. However, due to the
complexity involved, and the (wrongly) perceived low demand for this
feature, it was never implemented until now.
We mark the doomed link for deletion with a new flag, but wait until the
failover process is finished before we actually delete it. With the
improved link tunnelling/failover code introduced earlier in this commit
series, it is now easy to identify a spot in the code where the failover
is finished and it is safe to delete the marked link. Moreover, the test
for the flag and the deletion can be done synchronously, and outside the
most time critical data path.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-14 02:29:16 +04:00
|
|
|
bearer_disable(b_ptr, false);
|
2012-06-29 08:16:37 +04:00
|
|
|
pr_warn("Bearer <%s> rejected, discovery object creation failed\n",
|
|
|
|
name);
|
tipc: purge tipc_net_lock lock
Now tipc routing hierarchy comprises the structures 'node', 'link'and
'bearer'. The whole hierarchy is protected by a big read/write lock,
tipc_net_lock, to ensure that nothing is added or removed while code
is accessing any of these structures. Obviously the locking policy
makes node, link and bearer components closely bound together so that
their relationship becomes unnecessarily complex. In the worst case,
such locking policy not only has a negative influence on performance,
but also it's prone to lead to deadlock occasionally.
In order o decouple the complex relationship between bearer and node
as well as link, the locking policy is adjusted as follows:
- Bearer level
RTNL lock is used on update side, and RCU is used on read side.
Meanwhile, all bearer instances including broadcast bearer are
saved into bearer_list array.
- Node and link level
All node instances are saved into two tipc_node_list and node_htable
lists. The two lists are protected by node_list_lock on write side,
and they are guarded with RCU lock on read side. All members in node
structure including link instances are protected by node spin lock.
- The relationship between bearer and node
When link accesses bearer, it first needs to find the bearer with
its bearer identity from the bearer_list array. When bearer accesses
node, it can iterate the node_htable hash list with the node
address to find the corresponding node.
In the new locking policy, every component has its private locking
solution and the relationship between bearer and node is very simple,
that is, they can find each other with node address or bearer identity
from node_htable hash list or bearer_list array.
Until now above all changes have been done, so tipc_net_lock can be
removed safely.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 06:55:48 +04:00
|
|
|
return -EINVAL;
|
2011-04-21 22:58:26 +04:00
|
|
|
}
|
2014-03-27 08:54:33 +04:00
|
|
|
|
2014-04-21 06:55:45 +04:00
|
|
|
rcu_assign_pointer(bearer_list[bearer_id], b_ptr);
|
2014-03-27 08:54:33 +04:00
|
|
|
|
2012-06-29 08:16:37 +04:00
|
|
|
pr_info("Enabled bearer <%s>, discovery domain %s, priority %u\n",
|
|
|
|
name,
|
|
|
|
tipc_addr_string_fill(addr_string, disc_domain), priority);
|
2006-01-02 21:04:38 +03:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
tipc: remove interface state mirroring in bearer
struct 'tipc_bearer' is a generic representation of the underlying
media type, and exists in a one-to-one relationship to each interface
TIPC is using. The struct contains a 'blocked' flag that mirrors the
operational and execution state of the represented interface, and is
updated through notification calls from the latter. The users of
tipc_bearer are checking this flag before each attempt to send a
packet via the interface.
This state mirroring serves no purpose in the current code base. TIPC
links will not discover a media failure any faster through this
mechanism, and in reality the flag only adds overhead at packet
sending and reception.
Furthermore, the fact that the flag needs to be protected by a spinlock
aggregated into tipc_bearer has turned out to cause a serious and
completely unnecessary deadlock problem.
CPU0 CPU1
---- ----
Time 0: bearer_disable() link_timeout()
Time 1: spin_lock_bh(&b_ptr->lock) tipc_link_push_queue()
Time 2: tipc_link_delete() tipc_bearer_blocked(b_ptr)
Time 3: k_cancel_timer(&req->timer) spin_lock_bh(&b_ptr->lock)
Time 4: del_timer_sync(&req->timer)
I.e., del_timer_sync() on CPU0 never returns, because the timer handler
on CPU1 is waiting for the bearer lock.
We eliminate the 'blocked' flag from struct tipc_bearer, along with all
tests on this flag. This not only resolves the deadlock, but also
simplifies and speeds up the data path execution of TIPC. It also fits
well into our ongoing effort to make the locking policy simpler and
more manageable.
An effect of this change is that we can get rid of functions such as
tipc_bearer_blocked(), tipc_continue() and tipc_block_bearer().
We replace the latter with a new function, tipc_reset_bearer(), which
resets all links associated to the bearer immediately after an
interface goes down.
A user might notice one slight change in link behaviour after this
change. When an interface goes down, (e.g. through a NETDEV_DOWN
event) all attached links will be reset immediately, instead of
leaving it to each link to detect the failure through a timer-driven
mechanism. We consider this an improvement, and see no obvious risks
with the new behavior.
Signed-off-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Paul Gortmaker <Paul.Gortmaker@windriver.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-12-06 19:08:00 +04:00
|
|
|
* tipc_reset_bearer - Reset all links established over this bearer
|
2006-01-02 21:04:38 +03:00
|
|
|
*/
|
2015-01-09 10:27:04 +03:00
|
|
|
static int tipc_reset_bearer(struct net *net, struct tipc_bearer *b_ptr)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
tipc: remove interface state mirroring in bearer
struct 'tipc_bearer' is a generic representation of the underlying
media type, and exists in a one-to-one relationship to each interface
TIPC is using. The struct contains a 'blocked' flag that mirrors the
operational and execution state of the represented interface, and is
updated through notification calls from the latter. The users of
tipc_bearer are checking this flag before each attempt to send a
packet via the interface.
This state mirroring serves no purpose in the current code base. TIPC
links will not discover a media failure any faster through this
mechanism, and in reality the flag only adds overhead at packet
sending and reception.
Furthermore, the fact that the flag needs to be protected by a spinlock
aggregated into tipc_bearer has turned out to cause a serious and
completely unnecessary deadlock problem.
CPU0 CPU1
---- ----
Time 0: bearer_disable() link_timeout()
Time 1: spin_lock_bh(&b_ptr->lock) tipc_link_push_queue()
Time 2: tipc_link_delete() tipc_bearer_blocked(b_ptr)
Time 3: k_cancel_timer(&req->timer) spin_lock_bh(&b_ptr->lock)
Time 4: del_timer_sync(&req->timer)
I.e., del_timer_sync() on CPU0 never returns, because the timer handler
on CPU1 is waiting for the bearer lock.
We eliminate the 'blocked' flag from struct tipc_bearer, along with all
tests on this flag. This not only resolves the deadlock, but also
simplifies and speeds up the data path execution of TIPC. It also fits
well into our ongoing effort to make the locking policy simpler and
more manageable.
An effect of this change is that we can get rid of functions such as
tipc_bearer_blocked(), tipc_continue() and tipc_block_bearer().
We replace the latter with a new function, tipc_reset_bearer(), which
resets all links associated to the bearer immediately after an
interface goes down.
A user might notice one slight change in link behaviour after this
change. When an interface goes down, (e.g. through a NETDEV_DOWN
event) all attached links will be reset immediately, instead of
leaving it to each link to detect the failure through a timer-driven
mechanism. We consider this an improvement, and see no obvious risks
with the new behavior.
Signed-off-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Paul Gortmaker <Paul.Gortmaker@windriver.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-12-06 19:08:00 +04:00
|
|
|
pr_info("Resetting bearer <%s>\n", b_ptr->name);
|
tipc: remove 'links' list from tipc_bearer struct
In our ongoing effort to simplify the TIPC locking structure,
we see a need to remove the linked list for tipc_links
in the bearer. This can be explained as follows.
Currently, we have three different ways to access a link,
via three different lists/tables:
1: Via a node hash table:
Used by the time-critical outgoing/incoming data paths.
(e.g. link_send_sections_fast() and tipc_recv_msg() ):
grab net_lock(read)
find node from node hash table
grab node_lock
select link
grab bearer_lock
send_msg()
release bearer_lock
release node lock
release net_lock
2: Via a global linked list for nodes:
Used by configuration commands (link_cmd_set_value())
grab net_lock(read)
find node and link from global node list (using link name)
grab node_lock
update link
release node lock
release net_lock
(Same locking order as above. No problem.)
3: Via the bearer's linked link list:
Used by notifications from interface (e.g. tipc_disable_bearer() )
grab net_lock(write)
grab bearer_lock
get link ptr from bearer's link list
get node from link
grab node_lock
delete link
release node lock
release bearer_lock
release net_lock
(Different order from above, but works because we grab the
outer net_lock in write mode first, excluding all other access.)
The first major goal in our simplification effort is to get rid
of the "big" net_lock, replacing it with rcu-locks when accessing
the node list and node hash array. This will come in a later patch
series.
But to get there we first need to rewrite access methods ##2 and 3,
since removal of net_lock would introduce three major problems:
a) In access method #2, we access the link before taking the
protecting node_lock. This will not work once net_lock is gone,
so we will have to change the access order. We will deal with
this in a later commit in this series, "tipc: add node lock
protection to link found by link_find_link()".
b) When the outer protection from net_lock is gone, taking
bearer_lock and node_lock in opposite order of method 1) and 2)
will become an obvious deadlock hazard. This is fixed in the
commit ("tipc: remove bearer_lock from tipc_bearer struct")
later in this series.
c) Similar to what is described in problem a), access method #3
starts with using a link pointer that is unprotected by node_lock,
in order to via that pointer find the correct node struct and
lock it. Before we remove net_lock, this access order must be
altered. This is what we do with this commit.
We can avoid introducing problem problem c) by even here using the
global node list to find the node, before accessing its links. When
we loop though the node list we use the own bearer identity as search
criteria, thus easily finding the links that are associated to the
resetting/disabling bearer. It should be noted that although this
method is somewhat slower than the current list traversal, it is in
no way time critical. This is only about resetting or deleting links,
something that must be considered relatively infrequent events.
As a bonus, we can get rid of the mutual pointers between links and
bearers. After this commit, pointer dependency go in one direction
only: from the link to the bearer.
This commit pre-empts introduction of problem c) as described above.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-14 02:29:09 +04:00
|
|
|
tipc_link_reset_list(b_ptr->identity);
|
2015-01-09 10:27:04 +03:00
|
|
|
tipc_disc_reset(net, b_ptr);
|
2008-07-15 09:44:01 +04:00
|
|
|
return 0;
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-30 23:29:02 +04:00
|
|
|
* bearer_disable
|
2007-02-09 17:25:21 +03:00
|
|
|
*
|
tipc: purge tipc_net_lock lock
Now tipc routing hierarchy comprises the structures 'node', 'link'and
'bearer'. The whole hierarchy is protected by a big read/write lock,
tipc_net_lock, to ensure that nothing is added or removed while code
is accessing any of these structures. Obviously the locking policy
makes node, link and bearer components closely bound together so that
their relationship becomes unnecessarily complex. In the worst case,
such locking policy not only has a negative influence on performance,
but also it's prone to lead to deadlock occasionally.
In order o decouple the complex relationship between bearer and node
as well as link, the locking policy is adjusted as follows:
- Bearer level
RTNL lock is used on update side, and RCU is used on read side.
Meanwhile, all bearer instances including broadcast bearer are
saved into bearer_list array.
- Node and link level
All node instances are saved into two tipc_node_list and node_htable
lists. The two lists are protected by node_list_lock on write side,
and they are guarded with RCU lock on read side. All members in node
structure including link instances are protected by node spin lock.
- The relationship between bearer and node
When link accesses bearer, it first needs to find the bearer with
its bearer identity from the bearer_list array. When bearer accesses
node, it can iterate the node_htable hash list with the node
address to find the corresponding node.
In the new locking policy, every component has its private locking
solution and the relationship between bearer and node is very simple,
that is, they can find each other with node address or bearer identity
from node_htable hash list or bearer_list array.
Until now above all changes have been done, so tipc_net_lock can be
removed safely.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 06:55:48 +04:00
|
|
|
* Note: This routine assumes caller holds RTNL lock.
|
2006-01-02 21:04:38 +03:00
|
|
|
*/
|
tipc: delay delete of link when failover is needed
When a bearer is disabled, all its attached links are deleted.
Ideally, we should do link failover to redundant links on other bearers,
if there are any, in such cases. This would be consistent with current
behavior when a link is reset, but not deleted. However, due to the
complexity involved, and the (wrongly) perceived low demand for this
feature, it was never implemented until now.
We mark the doomed link for deletion with a new flag, but wait until the
failover process is finished before we actually delete it. With the
improved link tunnelling/failover code introduced earlier in this commit
series, it is now easy to identify a spot in the code where the failover
is finished and it is safe to delete the marked link. Moreover, the test
for the flag and the deletion can be done synchronously, and outside the
most time critical data path.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-14 02:29:16 +04:00
|
|
|
static void bearer_disable(struct tipc_bearer *b_ptr, bool shutting_down)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
2014-03-27 08:54:33 +04:00
|
|
|
u32 i;
|
|
|
|
|
2012-06-29 08:16:37 +04:00
|
|
|
pr_info("Disabling bearer <%s>\n", b_ptr->name);
|
2013-10-18 09:23:17 +04:00
|
|
|
b_ptr->media->disable_media(b_ptr);
|
tipc: avoid possible deadlock while enable and disable bearer
We met lockdep warning when enable and disable the bearer for commands such as:
tipc-config -netid=1234 -addr=1.1.3 -be=eth:eth0
tipc-config -netid=1234 -addr=1.1.3 -bd=eth:eth0
---------------------------------------------------
[ 327.693595] ======================================================
[ 327.693994] [ INFO: possible circular locking dependency detected ]
[ 327.694519] 3.11.0-rc3-wwd-default #4 Tainted: G O
[ 327.694882] -------------------------------------------------------
[ 327.695385] tipc-config/5825 is trying to acquire lock:
[ 327.695754] (((timer))#2){+.-...}, at: [<ffffffff8105be80>] del_timer_sync+0x0/0xd0
[ 327.696018]
[ 327.696018] but task is already holding lock:
[ 327.696018] (&(&b_ptr->lock)->rlock){+.-...}, at: [<ffffffffa02be58d>] bearer_disable+ 0xdd/0x120 [tipc]
[ 327.696018]
[ 327.696018] which lock already depends on the new lock.
[ 327.696018]
[ 327.696018]
[ 327.696018] the existing dependency chain (in reverse order) is:
[ 327.696018]
[ 327.696018] -> #1 (&(&b_ptr->lock)->rlock){+.-...}:
[ 327.696018] [<ffffffff810b3b4d>] validate_chain+0x6dd/0x870
[ 327.696018] [<ffffffff810b40bb>] __lock_acquire+0x3db/0x670
[ 327.696018] [<ffffffff810b4453>] lock_acquire+0x103/0x130
[ 327.696018] [<ffffffff814d65b1>] _raw_spin_lock_bh+0x41/0x80
[ 327.696018] [<ffffffffa02c5d48>] disc_timeout+0x18/0xd0 [tipc]
[ 327.696018] [<ffffffff8105b92a>] call_timer_fn+0xda/0x1e0
[ 327.696018] [<ffffffff8105bcd7>] run_timer_softirq+0x2a7/0x2d0
[ 327.696018] [<ffffffff8105379a>] __do_softirq+0x16a/0x2e0
[ 327.696018] [<ffffffff81053a35>] irq_exit+0xd5/0xe0
[ 327.696018] [<ffffffff81033005>] smp_apic_timer_interrupt+0x45/0x60
[ 327.696018] [<ffffffff814df4af>] apic_timer_interrupt+0x6f/0x80
[ 327.696018] [<ffffffff8100b70e>] arch_cpu_idle+0x1e/0x30
[ 327.696018] [<ffffffff810a039d>] cpu_idle_loop+0x1fd/0x280
[ 327.696018] [<ffffffff810a043e>] cpu_startup_entry+0x1e/0x20
[ 327.696018] [<ffffffff81031589>] start_secondary+0x89/0x90
[ 327.696018]
[ 327.696018] -> #0 (((timer))#2){+.-...}:
[ 327.696018] [<ffffffff810b33fe>] check_prev_add+0x43e/0x4b0
[ 327.696018] [<ffffffff810b3b4d>] validate_chain+0x6dd/0x870
[ 327.696018] [<ffffffff810b40bb>] __lock_acquire+0x3db/0x670
[ 327.696018] [<ffffffff810b4453>] lock_acquire+0x103/0x130
[ 327.696018] [<ffffffff8105bebd>] del_timer_sync+0x3d/0xd0
[ 327.696018] [<ffffffffa02c5855>] tipc_disc_delete+0x15/0x30 [tipc]
[ 327.696018] [<ffffffffa02be59f>] bearer_disable+0xef/0x120 [tipc]
[ 327.696018] [<ffffffffa02be74f>] tipc_disable_bearer+0x2f/0x60 [tipc]
[ 327.696018] [<ffffffffa02bfb32>] tipc_cfg_do_cmd+0x2e2/0x550 [tipc]
[ 327.696018] [<ffffffffa02c8c79>] handle_cmd+0x49/0xe0 [tipc]
[ 327.696018] [<ffffffff8143e898>] genl_family_rcv_msg+0x268/0x340
[ 327.696018] [<ffffffff8143ed30>] genl_rcv_msg+0x70/0xd0
[ 327.696018] [<ffffffff8143d4c9>] netlink_rcv_skb+0x89/0xb0
[ 327.696018] [<ffffffff8143e617>] genl_rcv+0x27/0x40
[ 327.696018] [<ffffffff8143d21e>] netlink_unicast+0x15e/0x1b0
[ 327.696018] [<ffffffff8143ddcf>] netlink_sendmsg+0x22f/0x400
[ 327.696018] [<ffffffff813f7836>] __sock_sendmsg+0x66/0x80
[ 327.696018] [<ffffffff813f7957>] sock_aio_write+0x107/0x120
[ 327.696018] [<ffffffff8117f76d>] do_sync_write+0x7d/0xc0
[ 327.696018] [<ffffffff8117fc56>] vfs_write+0x186/0x190
[ 327.696018] [<ffffffff811803e0>] SyS_write+0x60/0xb0
[ 327.696018] [<ffffffff814de852>] system_call_fastpath+0x16/0x1b
[ 327.696018]
[ 327.696018] other info that might help us debug this:
[ 327.696018]
[ 327.696018] Possible unsafe locking scenario:
[ 327.696018]
[ 327.696018] CPU0 CPU1
[ 327.696018] ---- ----
[ 327.696018] lock(&(&b_ptr->lock)->rlock);
[ 327.696018] lock(((timer))#2);
[ 327.696018] lock(&(&b_ptr->lock)->rlock);
[ 327.696018] lock(((timer))#2);
[ 327.696018]
[ 327.696018] *** DEADLOCK ***
[ 327.696018]
[ 327.696018] 5 locks held by tipc-config/5825:
[ 327.696018] #0: (cb_lock){++++++}, at: [<ffffffff8143e608>] genl_rcv+0x18/0x40
[ 327.696018] #1: (genl_mutex){+.+.+.}, at: [<ffffffff8143ed66>] genl_rcv_msg+0xa6/0xd0
[ 327.696018] #2: (config_mutex){+.+.+.}, at: [<ffffffffa02bf889>] tipc_cfg_do_cmd+0x39/ 0x550 [tipc]
[ 327.696018] #3: (tipc_net_lock){++.-..}, at: [<ffffffffa02be738>] tipc_disable_bearer+ 0x18/0x60 [tipc]
[ 327.696018] #4: (&(&b_ptr->lock)->rlock){+.-...}, at: [<ffffffffa02be58d>] bearer_disable+0xdd/0x120 [tipc]
[ 327.696018]
[ 327.696018] stack backtrace:
[ 327.696018] CPU: 2 PID: 5825 Comm: tipc-config Tainted: G O 3.11.0-rc3-wwd- default #4
[ 327.696018] Hardware name: Bochs Bochs, BIOS Bochs 01/01/2007
[ 327.696018] 00000000ffffffff ffff880037fa77a8 ffffffff814d03dd 0000000000000000
[ 327.696018] ffff880037fa7808 ffff880037fa77e8 ffffffff810b1c4f 0000000037fa77e8
[ 327.696018] ffff880037fa7808 ffff880037e4db40 0000000000000000 ffff880037e4e318
[ 327.696018] Call Trace:
[ 327.696018] [<ffffffff814d03dd>] dump_stack+0x4d/0xa0
[ 327.696018] [<ffffffff810b1c4f>] print_circular_bug+0x10f/0x120
[ 327.696018] [<ffffffff810b33fe>] check_prev_add+0x43e/0x4b0
[ 327.696018] [<ffffffff810b3b4d>] validate_chain+0x6dd/0x870
[ 327.696018] [<ffffffff81087a28>] ? sched_clock_cpu+0xd8/0x110
[ 327.696018] [<ffffffff810b40bb>] __lock_acquire+0x3db/0x670
[ 327.696018] [<ffffffff810b4453>] lock_acquire+0x103/0x130
[ 327.696018] [<ffffffff8105be80>] ? try_to_del_timer_sync+0x70/0x70
[ 327.696018] [<ffffffff8105bebd>] del_timer_sync+0x3d/0xd0
[ 327.696018] [<ffffffff8105be80>] ? try_to_del_timer_sync+0x70/0x70
[ 327.696018] [<ffffffffa02c5855>] tipc_disc_delete+0x15/0x30 [tipc]
[ 327.696018] [<ffffffffa02be59f>] bearer_disable+0xef/0x120 [tipc]
[ 327.696018] [<ffffffffa02be74f>] tipc_disable_bearer+0x2f/0x60 [tipc]
[ 327.696018] [<ffffffffa02bfb32>] tipc_cfg_do_cmd+0x2e2/0x550 [tipc]
[ 327.696018] [<ffffffff81218783>] ? security_capable+0x13/0x20
[ 327.696018] [<ffffffffa02c8c79>] handle_cmd+0x49/0xe0 [tipc]
[ 327.696018] [<ffffffff8143e898>] genl_family_rcv_msg+0x268/0x340
[ 327.696018] [<ffffffff8143ed30>] genl_rcv_msg+0x70/0xd0
[ 327.696018] [<ffffffff8143ecc0>] ? genl_lock+0x20/0x20
[ 327.696018] [<ffffffff8143d4c9>] netlink_rcv_skb+0x89/0xb0
[ 327.696018] [<ffffffff8143e608>] ? genl_rcv+0x18/0x40
[ 327.696018] [<ffffffff8143e617>] genl_rcv+0x27/0x40
[ 327.696018] [<ffffffff8143d21e>] netlink_unicast+0x15e/0x1b0
[ 327.696018] [<ffffffff81289d7c>] ? memcpy_fromiovec+0x6c/0x90
[ 327.696018] [<ffffffff8143ddcf>] netlink_sendmsg+0x22f/0x400
[ 327.696018] [<ffffffff813f7836>] __sock_sendmsg+0x66/0x80
[ 327.696018] [<ffffffff813f7957>] sock_aio_write+0x107/0x120
[ 327.696018] [<ffffffff813fe29c>] ? release_sock+0x8c/0xa0
[ 327.696018] [<ffffffff8117f76d>] do_sync_write+0x7d/0xc0
[ 327.696018] [<ffffffff8117fa24>] ? rw_verify_area+0x54/0x100
[ 327.696018] [<ffffffff8117fc56>] vfs_write+0x186/0x190
[ 327.696018] [<ffffffff811803e0>] SyS_write+0x60/0xb0
[ 327.696018] [<ffffffff814de852>] system_call_fastpath+0x16/0x1b
-----------------------------------------------------------------------
The problem is that the tipc_link_delete() will cancel the timer disc_timeout() when
the b_ptr->lock is hold, but the disc_timeout() still call b_ptr->lock to finish the
work, so the dead lock occurs.
We should unlock the b_ptr->lock when del the disc_timeout().
Remove link_timeout() still met the same problem, the patch:
http://article.gmane.org/gmane.network.tipc.general/4380
fix the problem, so no need to send patch for fix link_timeout() deadlock warming.
Signed-off-by: Wang Weidong <wangweidong1@huawei.com>
Signed-off-by: Ding Tianhong <dingtianhong@huawei.com>
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-08-09 13:12:58 +04:00
|
|
|
|
tipc: remove bearer_lock from tipc_bearer struct
After the earlier commits ("tipc: remove 'links' list from
tipc_bearer struct") and ("tipc: introduce new spinlock to protect
struct link_req"), there is no longer any need to protect struct
link_req or or any link list by use of bearer_lock. Furthermore,
we have eliminated the need for using bearer_lock during downcalls
(send) from the link to the bearer, since we have ensured that
bearers always have a longer life cycle that their associated links,
and always contain valid data.
So, the only need now for a lock protecting bearers is for guaranteeing
consistency of the bearer list itself. For this, it is sufficient, at
least for the time being, to continue applying 'net_lock´ in write mode.
By removing bearer_lock we also pre-empt introduction of issue b) descibed
in the previous commit "tipc: remove 'links' list from tipc_bearer struct":
"b) When the outer protection from net_lock is gone, taking
bearer_lock and node_lock in opposite order of method 1) and 2)
will become an obvious deadlock hazard".
Therefore, we now eliminate the bearer_lock spinlock.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-14 02:29:17 +04:00
|
|
|
tipc_link_delete_list(b_ptr->identity, shutting_down);
|
|
|
|
if (b_ptr->link_req)
|
|
|
|
tipc_disc_delete(b_ptr->link_req);
|
2014-03-27 08:54:33 +04:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_BEARERS; i++) {
|
2014-04-21 06:55:45 +04:00
|
|
|
if (b_ptr == rtnl_dereference(bearer_list[i])) {
|
|
|
|
RCU_INIT_POINTER(bearer_list[i], NULL);
|
2014-03-27 08:54:33 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-04-21 06:55:45 +04:00
|
|
|
kfree_rcu(b_ptr, rcu);
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int tipc_disable_bearer(const char *name)
|
|
|
|
{
|
2011-01-07 21:00:11 +03:00
|
|
|
struct tipc_bearer *b_ptr;
|
2006-01-02 21:04:38 +03:00
|
|
|
int res;
|
|
|
|
|
2011-10-18 19:34:29 +04:00
|
|
|
b_ptr = tipc_bearer_find(name);
|
2010-10-14 17:58:26 +04:00
|
|
|
if (b_ptr == NULL) {
|
2012-06-29 08:16:37 +04:00
|
|
|
pr_warn("Attempt to disable unknown bearer <%s>\n", name);
|
2010-10-14 17:58:26 +04:00
|
|
|
res = -EINVAL;
|
2010-11-30 15:00:56 +03:00
|
|
|
} else {
|
tipc: delay delete of link when failover is needed
When a bearer is disabled, all its attached links are deleted.
Ideally, we should do link failover to redundant links on other bearers,
if there are any, in such cases. This would be consistent with current
behavior when a link is reset, but not deleted. However, due to the
complexity involved, and the (wrongly) perceived low demand for this
feature, it was never implemented until now.
We mark the doomed link for deletion with a new flag, but wait until the
failover process is finished before we actually delete it. With the
improved link tunnelling/failover code introduced earlier in this commit
series, it is now easy to identify a spot in the code where the failover
is finished and it is safe to delete the marked link. Moreover, the test
for the flag and the deletion can be done synchronously, and outside the
most time critical data path.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-02-14 02:29:16 +04:00
|
|
|
bearer_disable(b_ptr, false);
|
2010-11-30 15:00:56 +03:00
|
|
|
res = 0;
|
|
|
|
}
|
2006-01-02 21:04:38 +03:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-12-11 08:45:43 +04:00
|
|
|
int tipc_enable_l2_media(struct tipc_bearer *b)
|
|
|
|
{
|
|
|
|
struct net_device *dev;
|
|
|
|
char *driver_name = strchr((const char *)b->name, ':') + 1;
|
|
|
|
|
|
|
|
/* Find device with specified name */
|
|
|
|
dev = dev_get_by_name(&init_net, driver_name);
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
tipc: improve and extend media address conversion functions
TIPC currently handles two media specific addresses: Ethernet MAC
addresses and InfiniBand addresses. Those are kept in three different
formats:
1) A "raw" format as obtained from the device. This format is known
only by the media specific adapter code in eth_media.c and
ib_media.c.
2) A "generic" internal format, in the form of struct tipc_media_addr,
which can be referenced and passed around by the generic media-
unaware code.
3) A serialized version of the latter, to be conveyed in neighbor
discovery messages.
Conversion between the three formats can only be done by the media
specific code, so we have function pointers for this purpose in
struct tipc_media. Here, the media adapters can install their own
conversion functions at startup.
We now introduce a new such function, 'raw2addr()', whose purpose
is to convert from format 1 to format 2 above. We also try to as far
as possible uniform commenting, variable names and usage of these
functions, with the purpose of making them more comprehensible.
We can now also remove the function tipc_l2_media_addr_set(), whose
job is done better by the new function.
Finally, we expand the field for serialized addresses (format 3)
in discovery messages from 20 to 32 bytes. This is permitted
according to the spec, and reduces the risk of problems when we
add new media in the future.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-05-14 13:39:13 +04:00
|
|
|
/* Associate TIPC bearer with L2 bearer */
|
2014-04-21 06:55:47 +04:00
|
|
|
rcu_assign_pointer(b->media_ptr, dev);
|
tipc: improve and extend media address conversion functions
TIPC currently handles two media specific addresses: Ethernet MAC
addresses and InfiniBand addresses. Those are kept in three different
formats:
1) A "raw" format as obtained from the device. This format is known
only by the media specific adapter code in eth_media.c and
ib_media.c.
2) A "generic" internal format, in the form of struct tipc_media_addr,
which can be referenced and passed around by the generic media-
unaware code.
3) A serialized version of the latter, to be conveyed in neighbor
discovery messages.
Conversion between the three formats can only be done by the media
specific code, so we have function pointers for this purpose in
struct tipc_media. Here, the media adapters can install their own
conversion functions at startup.
We now introduce a new such function, 'raw2addr()', whose purpose
is to convert from format 1 to format 2 above. We also try to as far
as possible uniform commenting, variable names and usage of these
functions, with the purpose of making them more comprehensible.
We can now also remove the function tipc_l2_media_addr_set(), whose
job is done better by the new function.
Finally, we expand the field for serialized addresses (format 3)
in discovery messages from 20 to 32 bytes. This is permitted
according to the spec, and reduces the risk of problems when we
add new media in the future.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-05-14 13:39:13 +04:00
|
|
|
memset(&b->bcast_addr, 0, sizeof(b->bcast_addr));
|
2013-12-11 08:45:43 +04:00
|
|
|
memcpy(b->bcast_addr.value, dev->broadcast, b->media->hwaddr_len);
|
|
|
|
b->bcast_addr.media_id = b->media->type_id;
|
|
|
|
b->bcast_addr.broadcast = 1;
|
|
|
|
b->mtu = dev->mtu;
|
tipc: improve and extend media address conversion functions
TIPC currently handles two media specific addresses: Ethernet MAC
addresses and InfiniBand addresses. Those are kept in three different
formats:
1) A "raw" format as obtained from the device. This format is known
only by the media specific adapter code in eth_media.c and
ib_media.c.
2) A "generic" internal format, in the form of struct tipc_media_addr,
which can be referenced and passed around by the generic media-
unaware code.
3) A serialized version of the latter, to be conveyed in neighbor
discovery messages.
Conversion between the three formats can only be done by the media
specific code, so we have function pointers for this purpose in
struct tipc_media. Here, the media adapters can install their own
conversion functions at startup.
We now introduce a new such function, 'raw2addr()', whose purpose
is to convert from format 1 to format 2 above. We also try to as far
as possible uniform commenting, variable names and usage of these
functions, with the purpose of making them more comprehensible.
We can now also remove the function tipc_l2_media_addr_set(), whose
job is done better by the new function.
Finally, we expand the field for serialized addresses (format 3)
in discovery messages from 20 to 32 bytes. This is permitted
according to the spec, and reduces the risk of problems when we
add new media in the future.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-05-14 13:39:13 +04:00
|
|
|
b->media->raw2addr(b, &b->addr, (char *)dev->dev_addr);
|
2013-12-11 08:45:43 +04:00
|
|
|
rcu_assign_pointer(dev->tipc_ptr, b);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
tipc: improve and extend media address conversion functions
TIPC currently handles two media specific addresses: Ethernet MAC
addresses and InfiniBand addresses. Those are kept in three different
formats:
1) A "raw" format as obtained from the device. This format is known
only by the media specific adapter code in eth_media.c and
ib_media.c.
2) A "generic" internal format, in the form of struct tipc_media_addr,
which can be referenced and passed around by the generic media-
unaware code.
3) A serialized version of the latter, to be conveyed in neighbor
discovery messages.
Conversion between the three formats can only be done by the media
specific code, so we have function pointers for this purpose in
struct tipc_media. Here, the media adapters can install their own
conversion functions at startup.
We now introduce a new such function, 'raw2addr()', whose purpose
is to convert from format 1 to format 2 above. We also try to as far
as possible uniform commenting, variable names and usage of these
functions, with the purpose of making them more comprehensible.
We can now also remove the function tipc_l2_media_addr_set(), whose
job is done better by the new function.
Finally, we expand the field for serialized addresses (format 3)
in discovery messages from 20 to 32 bytes. This is permitted
according to the spec, and reduces the risk of problems when we
add new media in the future.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-05-14 13:39:13 +04:00
|
|
|
/* tipc_disable_l2_media - detach TIPC bearer from an L2 interface
|
2013-12-11 08:45:43 +04:00
|
|
|
*
|
tipc: improve and extend media address conversion functions
TIPC currently handles two media specific addresses: Ethernet MAC
addresses and InfiniBand addresses. Those are kept in three different
formats:
1) A "raw" format as obtained from the device. This format is known
only by the media specific adapter code in eth_media.c and
ib_media.c.
2) A "generic" internal format, in the form of struct tipc_media_addr,
which can be referenced and passed around by the generic media-
unaware code.
3) A serialized version of the latter, to be conveyed in neighbor
discovery messages.
Conversion between the three formats can only be done by the media
specific code, so we have function pointers for this purpose in
struct tipc_media. Here, the media adapters can install their own
conversion functions at startup.
We now introduce a new such function, 'raw2addr()', whose purpose
is to convert from format 1 to format 2 above. We also try to as far
as possible uniform commenting, variable names and usage of these
functions, with the purpose of making them more comprehensible.
We can now also remove the function tipc_l2_media_addr_set(), whose
job is done better by the new function.
Finally, we expand the field for serialized addresses (format 3)
in discovery messages from 20 to 32 bytes. This is permitted
according to the spec, and reduces the risk of problems when we
add new media in the future.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-05-14 13:39:13 +04:00
|
|
|
* Mark L2 bearer as inactive so that incoming buffers are thrown away,
|
2013-12-11 08:45:43 +04:00
|
|
|
* then get worker thread to complete bearer cleanup. (Can't do cleanup
|
|
|
|
* here because cleanup code needs to sleep and caller holds spinlocks.)
|
|
|
|
*/
|
|
|
|
void tipc_disable_l2_media(struct tipc_bearer *b)
|
|
|
|
{
|
2014-04-21 06:55:47 +04:00
|
|
|
struct net_device *dev;
|
|
|
|
|
|
|
|
dev = (struct net_device *)rtnl_dereference(b->media_ptr);
|
|
|
|
RCU_INIT_POINTER(b->media_ptr, NULL);
|
2013-12-11 08:45:43 +04:00
|
|
|
RCU_INIT_POINTER(dev->tipc_ptr, NULL);
|
2014-04-21 06:55:49 +04:00
|
|
|
synchronize_net();
|
2013-12-11 08:45:43 +04:00
|
|
|
dev_put(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
tipc: improve and extend media address conversion functions
TIPC currently handles two media specific addresses: Ethernet MAC
addresses and InfiniBand addresses. Those are kept in three different
formats:
1) A "raw" format as obtained from the device. This format is known
only by the media specific adapter code in eth_media.c and
ib_media.c.
2) A "generic" internal format, in the form of struct tipc_media_addr,
which can be referenced and passed around by the generic media-
unaware code.
3) A serialized version of the latter, to be conveyed in neighbor
discovery messages.
Conversion between the three formats can only be done by the media
specific code, so we have function pointers for this purpose in
struct tipc_media. Here, the media adapters can install their own
conversion functions at startup.
We now introduce a new such function, 'raw2addr()', whose purpose
is to convert from format 1 to format 2 above. We also try to as far
as possible uniform commenting, variable names and usage of these
functions, with the purpose of making them more comprehensible.
We can now also remove the function tipc_l2_media_addr_set(), whose
job is done better by the new function.
Finally, we expand the field for serialized addresses (format 3)
in discovery messages from 20 to 32 bytes. This is permitted
according to the spec, and reduces the risk of problems when we
add new media in the future.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-05-14 13:39:13 +04:00
|
|
|
* tipc_l2_send_msg - send a TIPC packet out over an L2 interface
|
2013-12-11 08:45:43 +04:00
|
|
|
* @buf: the packet to be sent
|
2014-01-13 00:48:00 +04:00
|
|
|
* @b_ptr: the bearer through which the packet is to be sent
|
2013-12-11 08:45:43 +04:00
|
|
|
* @dest: peer destination address
|
|
|
|
*/
|
|
|
|
int tipc_l2_send_msg(struct sk_buff *buf, struct tipc_bearer *b,
|
|
|
|
struct tipc_media_addr *dest)
|
|
|
|
{
|
|
|
|
struct sk_buff *clone;
|
2014-04-21 06:55:47 +04:00
|
|
|
struct net_device *dev;
|
2013-12-11 08:45:43 +04:00
|
|
|
int delta;
|
2014-04-21 06:55:47 +04:00
|
|
|
|
|
|
|
dev = (struct net_device *)rcu_dereference_rtnl(b->media_ptr);
|
|
|
|
if (!dev)
|
|
|
|
return 0;
|
2013-12-11 08:45:43 +04:00
|
|
|
|
|
|
|
clone = skb_clone(buf, GFP_ATOMIC);
|
|
|
|
if (!clone)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
delta = dev->hard_header_len - skb_headroom(buf);
|
|
|
|
if ((delta > 0) &&
|
|
|
|
pskb_expand_head(clone, SKB_DATA_ALIGN(delta), 0, GFP_ATOMIC)) {
|
|
|
|
kfree_skb(clone);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
skb_reset_network_header(clone);
|
|
|
|
clone->dev = dev;
|
|
|
|
clone->protocol = htons(ETH_P_TIPC);
|
|
|
|
dev_hard_header(clone, dev, ETH_P_TIPC, dest->value,
|
|
|
|
dev->dev_addr, clone->len);
|
|
|
|
dev_queue_xmit(clone);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* tipc_bearer_send- sends buffer to destination over bearer
|
|
|
|
*
|
|
|
|
* IMPORTANT:
|
|
|
|
* The media send routine must not alter the buffer being passed in
|
|
|
|
* as it may be needed for later retransmission!
|
|
|
|
*/
|
tipc: decouple the relationship between bearer and link
Currently on both paths of message transmission and reception, the
read lock of tipc_net_lock must be held before bearer is accessed,
while the write lock of tipc_net_lock has to be taken before bearer
is configured. Although it can ensure that bearer is always valid on
the two data paths, link and bearer is closely bound together.
So as the part of effort of removing tipc_net_lock, the locking
policy of bearer protection will be adjusted as below: on the two
data paths, RCU is used, and on the configuration path of bearer,
RTNL lock is applied.
Now RCU just covers the path of message reception. To make it possible
to protect the path of message transmission with RCU, link should not
use its stored bearer pointer to access bearer, but it should use the
bearer identity of its attached bearer as index to get bearer instance
from bearer_list array, which can help us decouple the relationship
between bearer and link. As a result, bearer on the path of message
transmission can be safely protected by RCU when we access bearer_list
array within RCU lock protection.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 06:55:46 +04:00
|
|
|
void tipc_bearer_send(u32 bearer_id, struct sk_buff *buf,
|
2013-12-11 08:45:43 +04:00
|
|
|
struct tipc_media_addr *dest)
|
|
|
|
{
|
tipc: decouple the relationship between bearer and link
Currently on both paths of message transmission and reception, the
read lock of tipc_net_lock must be held before bearer is accessed,
while the write lock of tipc_net_lock has to be taken before bearer
is configured. Although it can ensure that bearer is always valid on
the two data paths, link and bearer is closely bound together.
So as the part of effort of removing tipc_net_lock, the locking
policy of bearer protection will be adjusted as below: on the two
data paths, RCU is used, and on the configuration path of bearer,
RTNL lock is applied.
Now RCU just covers the path of message reception. To make it possible
to protect the path of message transmission with RCU, link should not
use its stored bearer pointer to access bearer, but it should use the
bearer identity of its attached bearer as index to get bearer instance
from bearer_list array, which can help us decouple the relationship
between bearer and link. As a result, bearer on the path of message
transmission can be safely protected by RCU when we access bearer_list
array within RCU lock protection.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-21 06:55:46 +04:00
|
|
|
struct tipc_bearer *b_ptr;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
b_ptr = rcu_dereference_rtnl(bearer_list[bearer_id]);
|
|
|
|
if (likely(b_ptr))
|
|
|
|
b_ptr->media->send_msg(buf, b_ptr, dest);
|
|
|
|
rcu_read_unlock();
|
2013-12-11 08:45:43 +04:00
|
|
|
}
|
|
|
|
|
tipc: relocate common functions from media to bearer
Currently, registering a TIPC stack handler in the network device layer
is done twice, once for Ethernet (eth_media) and Infiniband (ib_media)
repectively. But, as this registration is not media specific, we can
avoid some code duplication by moving the registering function to
the generic bearer layer, to the file bearer.c, and call it only once.
The same is true for the network device event notifier.
As a side effect, the two workqueues we are using for for setting up/
cleaning up media can now be eliminated. Furthermore, the array for
storing the specific media type structs, media_array[], can be entirely
deleted.
Note that the eth_started and ib_started flags were removed during the
code relocation. There is now only one call to bearer_setup and
bearer_cleanup, and these can logically not race against each other.
Despite its size, this cleanup work incurs no functional changes in TIPC.
In particular, it should be noted that the sequence ordering of received
packets is unaffected by this change, since packet reception never was
subject to any work queue handling in the first place.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Cc: Patrick McHardy <kaber@trash.net>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-12-11 08:45:42 +04:00
|
|
|
/**
|
|
|
|
* tipc_l2_rcv_msg - handle incoming TIPC message from an interface
|
|
|
|
* @buf: the received packet
|
|
|
|
* @dev: the net device that the packet was received on
|
|
|
|
* @pt: the packet_type structure which was used to register this handler
|
|
|
|
* @orig_dev: the original receive net device in case the device is a bond
|
|
|
|
*
|
|
|
|
* Accept only packets explicitly sent to this node, or broadcast packets;
|
|
|
|
* ignores packets sent using interface multicast, and traffic sent to other
|
|
|
|
* nodes (which can happen if interface is running in promiscuous mode).
|
|
|
|
*/
|
|
|
|
static int tipc_l2_rcv_msg(struct sk_buff *buf, struct net_device *dev,
|
|
|
|
struct packet_type *pt, struct net_device *orig_dev)
|
|
|
|
{
|
|
|
|
struct tipc_bearer *b_ptr;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
2014-04-21 06:55:43 +04:00
|
|
|
b_ptr = rcu_dereference_rtnl(dev->tipc_ptr);
|
tipc: relocate common functions from media to bearer
Currently, registering a TIPC stack handler in the network device layer
is done twice, once for Ethernet (eth_media) and Infiniband (ib_media)
repectively. But, as this registration is not media specific, we can
avoid some code duplication by moving the registering function to
the generic bearer layer, to the file bearer.c, and call it only once.
The same is true for the network device event notifier.
As a side effect, the two workqueues we are using for for setting up/
cleaning up media can now be eliminated. Furthermore, the array for
storing the specific media type structs, media_array[], can be entirely
deleted.
Note that the eth_started and ib_started flags were removed during the
code relocation. There is now only one call to bearer_setup and
bearer_cleanup, and these can logically not race against each other.
Despite its size, this cleanup work incurs no functional changes in TIPC.
In particular, it should be noted that the sequence ordering of received
packets is unaffected by this change, since packet reception never was
subject to any work queue handling in the first place.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Cc: Patrick McHardy <kaber@trash.net>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-12-11 08:45:42 +04:00
|
|
|
if (likely(b_ptr)) {
|
|
|
|
if (likely(buf->pkt_type <= PACKET_BROADCAST)) {
|
|
|
|
buf->next = NULL;
|
2015-01-09 10:27:04 +03:00
|
|
|
tipc_rcv(dev_net(dev), buf, b_ptr);
|
tipc: relocate common functions from media to bearer
Currently, registering a TIPC stack handler in the network device layer
is done twice, once for Ethernet (eth_media) and Infiniband (ib_media)
repectively. But, as this registration is not media specific, we can
avoid some code duplication by moving the registering function to
the generic bearer layer, to the file bearer.c, and call it only once.
The same is true for the network device event notifier.
As a side effect, the two workqueues we are using for for setting up/
cleaning up media can now be eliminated. Furthermore, the array for
storing the specific media type structs, media_array[], can be entirely
deleted.
Note that the eth_started and ib_started flags were removed during the
code relocation. There is now only one call to bearer_setup and
bearer_cleanup, and these can logically not race against each other.
Despite its size, this cleanup work incurs no functional changes in TIPC.
In particular, it should be noted that the sequence ordering of received
packets is unaffected by this change, since packet reception never was
subject to any work queue handling in the first place.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Cc: Patrick McHardy <kaber@trash.net>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-12-11 08:45:42 +04:00
|
|
|
rcu_read_unlock();
|
|
|
|
return NET_RX_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
kfree_skb(buf);
|
|
|
|
return NET_RX_DROP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tipc_l2_device_event - handle device events from network device
|
|
|
|
* @nb: the context of the notification
|
|
|
|
* @evt: the type of event
|
|
|
|
* @ptr: the net device that the event was on
|
|
|
|
*
|
|
|
|
* This function is called by the Ethernet driver in case of link
|
|
|
|
* change event.
|
|
|
|
*/
|
|
|
|
static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt,
|
|
|
|
void *ptr)
|
|
|
|
{
|
|
|
|
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
|
2015-01-09 10:27:04 +03:00
|
|
|
struct net *net = dev_net(dev);
|
|
|
|
struct tipc_bearer *b_ptr;
|
tipc: relocate common functions from media to bearer
Currently, registering a TIPC stack handler in the network device layer
is done twice, once for Ethernet (eth_media) and Infiniband (ib_media)
repectively. But, as this registration is not media specific, we can
avoid some code duplication by moving the registering function to
the generic bearer layer, to the file bearer.c, and call it only once.
The same is true for the network device event notifier.
As a side effect, the two workqueues we are using for for setting up/
cleaning up media can now be eliminated. Furthermore, the array for
storing the specific media type structs, media_array[], can be entirely
deleted.
Note that the eth_started and ib_started flags were removed during the
code relocation. There is now only one call to bearer_setup and
bearer_cleanup, and these can logically not race against each other.
Despite its size, this cleanup work incurs no functional changes in TIPC.
In particular, it should be noted that the sequence ordering of received
packets is unaffected by this change, since packet reception never was
subject to any work queue handling in the first place.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Cc: Patrick McHardy <kaber@trash.net>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-12-11 08:45:42 +04:00
|
|
|
|
2014-04-21 06:55:43 +04:00
|
|
|
b_ptr = rtnl_dereference(dev->tipc_ptr);
|
|
|
|
if (!b_ptr)
|
tipc: relocate common functions from media to bearer
Currently, registering a TIPC stack handler in the network device layer
is done twice, once for Ethernet (eth_media) and Infiniband (ib_media)
repectively. But, as this registration is not media specific, we can
avoid some code duplication by moving the registering function to
the generic bearer layer, to the file bearer.c, and call it only once.
The same is true for the network device event notifier.
As a side effect, the two workqueues we are using for for setting up/
cleaning up media can now be eliminated. Furthermore, the array for
storing the specific media type structs, media_array[], can be entirely
deleted.
Note that the eth_started and ib_started flags were removed during the
code relocation. There is now only one call to bearer_setup and
bearer_cleanup, and these can logically not race against each other.
Despite its size, this cleanup work incurs no functional changes in TIPC.
In particular, it should be noted that the sequence ordering of received
packets is unaffected by this change, since packet reception never was
subject to any work queue handling in the first place.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Cc: Patrick McHardy <kaber@trash.net>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-12-11 08:45:42 +04:00
|
|
|
return NOTIFY_DONE;
|
|
|
|
|
|
|
|
b_ptr->mtu = dev->mtu;
|
|
|
|
|
|
|
|
switch (evt) {
|
|
|
|
case NETDEV_CHANGE:
|
|
|
|
if (netif_carrier_ok(dev))
|
|
|
|
break;
|
|
|
|
case NETDEV_DOWN:
|
|
|
|
case NETDEV_CHANGEMTU:
|
2015-01-09 10:27:04 +03:00
|
|
|
tipc_reset_bearer(net, b_ptr);
|
2014-03-28 13:32:08 +04:00
|
|
|
break;
|
tipc: relocate common functions from media to bearer
Currently, registering a TIPC stack handler in the network device layer
is done twice, once for Ethernet (eth_media) and Infiniband (ib_media)
repectively. But, as this registration is not media specific, we can
avoid some code duplication by moving the registering function to
the generic bearer layer, to the file bearer.c, and call it only once.
The same is true for the network device event notifier.
As a side effect, the two workqueues we are using for for setting up/
cleaning up media can now be eliminated. Furthermore, the array for
storing the specific media type structs, media_array[], can be entirely
deleted.
Note that the eth_started and ib_started flags were removed during the
code relocation. There is now only one call to bearer_setup and
bearer_cleanup, and these can logically not race against each other.
Despite its size, this cleanup work incurs no functional changes in TIPC.
In particular, it should be noted that the sequence ordering of received
packets is unaffected by this change, since packet reception never was
subject to any work queue handling in the first place.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Cc: Patrick McHardy <kaber@trash.net>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-12-11 08:45:42 +04:00
|
|
|
case NETDEV_CHANGEADDR:
|
tipc: improve and extend media address conversion functions
TIPC currently handles two media specific addresses: Ethernet MAC
addresses and InfiniBand addresses. Those are kept in three different
formats:
1) A "raw" format as obtained from the device. This format is known
only by the media specific adapter code in eth_media.c and
ib_media.c.
2) A "generic" internal format, in the form of struct tipc_media_addr,
which can be referenced and passed around by the generic media-
unaware code.
3) A serialized version of the latter, to be conveyed in neighbor
discovery messages.
Conversion between the three formats can only be done by the media
specific code, so we have function pointers for this purpose in
struct tipc_media. Here, the media adapters can install their own
conversion functions at startup.
We now introduce a new such function, 'raw2addr()', whose purpose
is to convert from format 1 to format 2 above. We also try to as far
as possible uniform commenting, variable names and usage of these
functions, with the purpose of making them more comprehensible.
We can now also remove the function tipc_l2_media_addr_set(), whose
job is done better by the new function.
Finally, we expand the field for serialized addresses (format 3)
in discovery messages from 20 to 32 bytes. This is permitted
according to the spec, and reduces the risk of problems when we
add new media in the future.
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-05-14 13:39:13 +04:00
|
|
|
b_ptr->media->raw2addr(b_ptr, &b_ptr->addr,
|
2014-03-28 13:32:08 +04:00
|
|
|
(char *)dev->dev_addr);
|
2015-01-09 10:27:04 +03:00
|
|
|
tipc_reset_bearer(net, b_ptr);
|
tipc: relocate common functions from media to bearer
Currently, registering a TIPC stack handler in the network device layer
is done twice, once for Ethernet (eth_media) and Infiniband (ib_media)
repectively. But, as this registration is not media specific, we can
avoid some code duplication by moving the registering function to
the generic bearer layer, to the file bearer.c, and call it only once.
The same is true for the network device event notifier.
As a side effect, the two workqueues we are using for for setting up/
cleaning up media can now be eliminated. Furthermore, the array for
storing the specific media type structs, media_array[], can be entirely
deleted.
Note that the eth_started and ib_started flags were removed during the
code relocation. There is now only one call to bearer_setup and
bearer_cleanup, and these can logically not race against each other.
Despite its size, this cleanup work incurs no functional changes in TIPC.
In particular, it should be noted that the sequence ordering of received
packets is unaffected by this change, since packet reception never was
subject to any work queue handling in the first place.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Cc: Patrick McHardy <kaber@trash.net>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-12-11 08:45:42 +04:00
|
|
|
break;
|
|
|
|
case NETDEV_UNREGISTER:
|
|
|
|
case NETDEV_CHANGENAME:
|
2014-04-21 06:55:50 +04:00
|
|
|
bearer_disable(b_ptr, false);
|
tipc: relocate common functions from media to bearer
Currently, registering a TIPC stack handler in the network device layer
is done twice, once for Ethernet (eth_media) and Infiniband (ib_media)
repectively. But, as this registration is not media specific, we can
avoid some code duplication by moving the registering function to
the generic bearer layer, to the file bearer.c, and call it only once.
The same is true for the network device event notifier.
As a side effect, the two workqueues we are using for for setting up/
cleaning up media can now be eliminated. Furthermore, the array for
storing the specific media type structs, media_array[], can be entirely
deleted.
Note that the eth_started and ib_started flags were removed during the
code relocation. There is now only one call to bearer_setup and
bearer_cleanup, and these can logically not race against each other.
Despite its size, this cleanup work incurs no functional changes in TIPC.
In particular, it should be noted that the sequence ordering of received
packets is unaffected by this change, since packet reception never was
subject to any work queue handling in the first place.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Cc: Patrick McHardy <kaber@trash.net>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-12-11 08:45:42 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NOTIFY_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct packet_type tipc_packet_type __read_mostly = {
|
2014-03-12 21:04:20 +04:00
|
|
|
.type = htons(ETH_P_TIPC),
|
tipc: relocate common functions from media to bearer
Currently, registering a TIPC stack handler in the network device layer
is done twice, once for Ethernet (eth_media) and Infiniband (ib_media)
repectively. But, as this registration is not media specific, we can
avoid some code duplication by moving the registering function to
the generic bearer layer, to the file bearer.c, and call it only once.
The same is true for the network device event notifier.
As a side effect, the two workqueues we are using for for setting up/
cleaning up media can now be eliminated. Furthermore, the array for
storing the specific media type structs, media_array[], can be entirely
deleted.
Note that the eth_started and ib_started flags were removed during the
code relocation. There is now only one call to bearer_setup and
bearer_cleanup, and these can logically not race against each other.
Despite its size, this cleanup work incurs no functional changes in TIPC.
In particular, it should be noted that the sequence ordering of received
packets is unaffected by this change, since packet reception never was
subject to any work queue handling in the first place.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Cc: Patrick McHardy <kaber@trash.net>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-12-11 08:45:42 +04:00
|
|
|
.func = tipc_l2_rcv_msg,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct notifier_block notifier = {
|
|
|
|
.notifier_call = tipc_l2_device_event,
|
|
|
|
.priority = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
int tipc_bearer_setup(void)
|
|
|
|
{
|
2014-02-20 07:32:50 +04:00
|
|
|
int err;
|
|
|
|
|
|
|
|
err = register_netdevice_notifier(¬ifier);
|
|
|
|
if (err)
|
|
|
|
return err;
|
tipc: relocate common functions from media to bearer
Currently, registering a TIPC stack handler in the network device layer
is done twice, once for Ethernet (eth_media) and Infiniband (ib_media)
repectively. But, as this registration is not media specific, we can
avoid some code duplication by moving the registering function to
the generic bearer layer, to the file bearer.c, and call it only once.
The same is true for the network device event notifier.
As a side effect, the two workqueues we are using for for setting up/
cleaning up media can now be eliminated. Furthermore, the array for
storing the specific media type structs, media_array[], can be entirely
deleted.
Note that the eth_started and ib_started flags were removed during the
code relocation. There is now only one call to bearer_setup and
bearer_cleanup, and these can logically not race against each other.
Despite its size, this cleanup work incurs no functional changes in TIPC.
In particular, it should be noted that the sequence ordering of received
packets is unaffected by this change, since packet reception never was
subject to any work queue handling in the first place.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Cc: Patrick McHardy <kaber@trash.net>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-12-11 08:45:42 +04:00
|
|
|
dev_add_pack(&tipc_packet_type);
|
2014-02-20 07:32:50 +04:00
|
|
|
return 0;
|
tipc: relocate common functions from media to bearer
Currently, registering a TIPC stack handler in the network device layer
is done twice, once for Ethernet (eth_media) and Infiniband (ib_media)
repectively. But, as this registration is not media specific, we can
avoid some code duplication by moving the registering function to
the generic bearer layer, to the file bearer.c, and call it only once.
The same is true for the network device event notifier.
As a side effect, the two workqueues we are using for for setting up/
cleaning up media can now be eliminated. Furthermore, the array for
storing the specific media type structs, media_array[], can be entirely
deleted.
Note that the eth_started and ib_started flags were removed during the
code relocation. There is now only one call to bearer_setup and
bearer_cleanup, and these can logically not race against each other.
Despite its size, this cleanup work incurs no functional changes in TIPC.
In particular, it should be noted that the sequence ordering of received
packets is unaffected by this change, since packet reception never was
subject to any work queue handling in the first place.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Cc: Patrick McHardy <kaber@trash.net>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-12-11 08:45:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void tipc_bearer_cleanup(void)
|
|
|
|
{
|
|
|
|
unregister_netdevice_notifier(¬ifier);
|
|
|
|
dev_remove_pack(&tipc_packet_type);
|
|
|
|
}
|
2006-01-02 21:04:38 +03:00
|
|
|
|
2006-01-18 02:38:21 +03:00
|
|
|
void tipc_bearer_stop(void)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
2014-03-27 08:54:33 +04:00
|
|
|
struct tipc_bearer *b_ptr;
|
2006-01-02 21:04:38 +03:00
|
|
|
u32 i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_BEARERS; i++) {
|
2014-04-21 06:55:45 +04:00
|
|
|
b_ptr = rtnl_dereference(bearer_list[i]);
|
2014-03-27 08:54:34 +04:00
|
|
|
if (b_ptr) {
|
2014-03-27 08:54:33 +04:00
|
|
|
bearer_disable(b_ptr, true);
|
|
|
|
bearer_list[i] = NULL;
|
|
|
|
}
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
}
|
2014-11-20 12:29:07 +03:00
|
|
|
|
2014-11-20 12:29:08 +03:00
|
|
|
/* Caller should hold rtnl_lock to protect the bearer */
|
2014-11-24 13:10:29 +03:00
|
|
|
static int __tipc_nl_add_bearer(struct tipc_nl_msg *msg,
|
|
|
|
struct tipc_bearer *bearer)
|
2014-11-20 12:29:08 +03:00
|
|
|
{
|
|
|
|
void *hdr;
|
|
|
|
struct nlattr *attrs;
|
|
|
|
struct nlattr *prop;
|
|
|
|
|
|
|
|
hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_v2_family,
|
|
|
|
NLM_F_MULTI, TIPC_NL_BEARER_GET);
|
|
|
|
if (!hdr)
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
|
|
|
attrs = nla_nest_start(msg->skb, TIPC_NLA_BEARER);
|
|
|
|
if (!attrs)
|
|
|
|
goto msg_full;
|
|
|
|
|
|
|
|
if (nla_put_string(msg->skb, TIPC_NLA_BEARER_NAME, bearer->name))
|
|
|
|
goto attr_msg_full;
|
|
|
|
|
|
|
|
prop = nla_nest_start(msg->skb, TIPC_NLA_BEARER_PROP);
|
|
|
|
if (!prop)
|
|
|
|
goto prop_msg_full;
|
|
|
|
if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, bearer->priority))
|
|
|
|
goto prop_msg_full;
|
|
|
|
if (nla_put_u32(msg->skb, TIPC_NLA_PROP_TOL, bearer->tolerance))
|
|
|
|
goto prop_msg_full;
|
|
|
|
if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN, bearer->window))
|
|
|
|
goto prop_msg_full;
|
|
|
|
|
|
|
|
nla_nest_end(msg->skb, prop);
|
|
|
|
nla_nest_end(msg->skb, attrs);
|
|
|
|
genlmsg_end(msg->skb, hdr);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
prop_msg_full:
|
|
|
|
nla_nest_cancel(msg->skb, prop);
|
|
|
|
attr_msg_full:
|
|
|
|
nla_nest_cancel(msg->skb, attrs);
|
|
|
|
msg_full:
|
|
|
|
genlmsg_cancel(msg->skb, hdr);
|
|
|
|
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tipc_nl_bearer_dump(struct sk_buff *skb, struct netlink_callback *cb)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
int i = cb->args[0];
|
|
|
|
struct tipc_bearer *bearer;
|
|
|
|
struct tipc_nl_msg msg;
|
|
|
|
|
|
|
|
if (i == MAX_BEARERS)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
msg.skb = skb;
|
|
|
|
msg.portid = NETLINK_CB(cb->skb).portid;
|
|
|
|
msg.seq = cb->nlh->nlmsg_seq;
|
|
|
|
|
|
|
|
rtnl_lock();
|
|
|
|
for (i = 0; i < MAX_BEARERS; i++) {
|
|
|
|
bearer = rtnl_dereference(bearer_list[i]);
|
|
|
|
if (!bearer)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
err = __tipc_nl_add_bearer(&msg, bearer);
|
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rtnl_unlock();
|
|
|
|
|
|
|
|
cb->args[0] = i;
|
|
|
|
return skb->len;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tipc_nl_bearer_get(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
char *name;
|
|
|
|
struct sk_buff *rep;
|
|
|
|
struct tipc_bearer *bearer;
|
|
|
|
struct tipc_nl_msg msg;
|
|
|
|
struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
|
|
|
|
|
|
|
|
if (!info->attrs[TIPC_NLA_BEARER])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
err = nla_parse_nested(attrs, TIPC_NLA_BEARER_MAX,
|
|
|
|
info->attrs[TIPC_NLA_BEARER],
|
|
|
|
tipc_nl_bearer_policy);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (!attrs[TIPC_NLA_BEARER_NAME])
|
|
|
|
return -EINVAL;
|
|
|
|
name = nla_data(attrs[TIPC_NLA_BEARER_NAME]);
|
|
|
|
|
|
|
|
rep = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
|
|
|
|
if (!rep)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
msg.skb = rep;
|
|
|
|
msg.portid = info->snd_portid;
|
|
|
|
msg.seq = info->snd_seq;
|
|
|
|
|
|
|
|
rtnl_lock();
|
|
|
|
bearer = tipc_bearer_find(name);
|
|
|
|
if (!bearer) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = __tipc_nl_add_bearer(&msg, bearer);
|
|
|
|
if (err)
|
|
|
|
goto err_out;
|
|
|
|
rtnl_unlock();
|
|
|
|
|
|
|
|
return genlmsg_reply(rep, info);
|
|
|
|
err_out:
|
|
|
|
rtnl_unlock();
|
|
|
|
nlmsg_free(rep);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-11-20 12:29:07 +03:00
|
|
|
int tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
char *name;
|
|
|
|
struct tipc_bearer *bearer;
|
|
|
|
struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
|
|
|
|
|
|
|
|
if (!info->attrs[TIPC_NLA_BEARER])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
err = nla_parse_nested(attrs, TIPC_NLA_BEARER_MAX,
|
|
|
|
info->attrs[TIPC_NLA_BEARER],
|
|
|
|
tipc_nl_bearer_policy);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (!attrs[TIPC_NLA_BEARER_NAME])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
name = nla_data(attrs[TIPC_NLA_BEARER_NAME]);
|
|
|
|
|
|
|
|
rtnl_lock();
|
|
|
|
bearer = tipc_bearer_find(name);
|
|
|
|
if (!bearer) {
|
|
|
|
rtnl_unlock();
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bearer_disable(bearer, false);
|
|
|
|
rtnl_unlock();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
2015-01-09 10:27:04 +03:00
|
|
|
struct net *net = genl_info_net(info);
|
2014-11-20 12:29:07 +03:00
|
|
|
int err;
|
|
|
|
char *bearer;
|
|
|
|
struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
|
|
|
|
u32 domain;
|
|
|
|
u32 prio;
|
|
|
|
|
|
|
|
prio = TIPC_MEDIA_LINK_PRI;
|
|
|
|
domain = tipc_own_addr & TIPC_CLUSTER_MASK;
|
|
|
|
|
|
|
|
if (!info->attrs[TIPC_NLA_BEARER])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
err = nla_parse_nested(attrs, TIPC_NLA_BEARER_MAX,
|
|
|
|
info->attrs[TIPC_NLA_BEARER],
|
|
|
|
tipc_nl_bearer_policy);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (!attrs[TIPC_NLA_BEARER_NAME])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
bearer = nla_data(attrs[TIPC_NLA_BEARER_NAME]);
|
|
|
|
|
|
|
|
if (attrs[TIPC_NLA_BEARER_DOMAIN])
|
|
|
|
domain = nla_get_u32(attrs[TIPC_NLA_BEARER_DOMAIN]);
|
|
|
|
|
|
|
|
if (attrs[TIPC_NLA_BEARER_PROP]) {
|
|
|
|
struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
|
|
|
|
|
|
|
|
err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_BEARER_PROP],
|
|
|
|
props);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (props[TIPC_NLA_PROP_PRIO])
|
|
|
|
prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
|
|
|
|
}
|
|
|
|
|
|
|
|
rtnl_lock();
|
2015-01-09 10:27:04 +03:00
|
|
|
err = tipc_enable_bearer(net, bearer, domain, prio);
|
2014-11-20 12:29:07 +03:00
|
|
|
if (err) {
|
|
|
|
rtnl_unlock();
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
rtnl_unlock();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-11-20 12:29:09 +03:00
|
|
|
|
|
|
|
int tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
char *name;
|
|
|
|
struct tipc_bearer *b;
|
|
|
|
struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
|
|
|
|
|
|
|
|
if (!info->attrs[TIPC_NLA_BEARER])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
err = nla_parse_nested(attrs, TIPC_NLA_BEARER_MAX,
|
|
|
|
info->attrs[TIPC_NLA_BEARER],
|
|
|
|
tipc_nl_bearer_policy);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (!attrs[TIPC_NLA_BEARER_NAME])
|
|
|
|
return -EINVAL;
|
|
|
|
name = nla_data(attrs[TIPC_NLA_BEARER_NAME]);
|
|
|
|
|
|
|
|
rtnl_lock();
|
|
|
|
b = tipc_bearer_find(name);
|
|
|
|
if (!b) {
|
|
|
|
rtnl_unlock();
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attrs[TIPC_NLA_BEARER_PROP]) {
|
|
|
|
struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
|
|
|
|
|
|
|
|
err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_BEARER_PROP],
|
|
|
|
props);
|
|
|
|
if (err) {
|
|
|
|
rtnl_unlock();
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (props[TIPC_NLA_PROP_TOL])
|
|
|
|
b->tolerance = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
|
|
|
|
if (props[TIPC_NLA_PROP_PRIO])
|
|
|
|
b->priority = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
|
|
|
|
if (props[TIPC_NLA_PROP_WIN])
|
|
|
|
b->window = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
|
|
|
|
}
|
|
|
|
rtnl_unlock();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-11-20 12:29:15 +03:00
|
|
|
|
2014-11-24 13:10:29 +03:00
|
|
|
static int __tipc_nl_add_media(struct tipc_nl_msg *msg,
|
|
|
|
struct tipc_media *media)
|
2014-11-20 12:29:15 +03:00
|
|
|
{
|
|
|
|
void *hdr;
|
|
|
|
struct nlattr *attrs;
|
|
|
|
struct nlattr *prop;
|
|
|
|
|
|
|
|
hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_v2_family,
|
|
|
|
NLM_F_MULTI, TIPC_NL_MEDIA_GET);
|
|
|
|
if (!hdr)
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
|
|
|
attrs = nla_nest_start(msg->skb, TIPC_NLA_MEDIA);
|
|
|
|
if (!attrs)
|
|
|
|
goto msg_full;
|
|
|
|
|
|
|
|
if (nla_put_string(msg->skb, TIPC_NLA_MEDIA_NAME, media->name))
|
|
|
|
goto attr_msg_full;
|
|
|
|
|
|
|
|
prop = nla_nest_start(msg->skb, TIPC_NLA_MEDIA_PROP);
|
|
|
|
if (!prop)
|
|
|
|
goto prop_msg_full;
|
|
|
|
if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, media->priority))
|
|
|
|
goto prop_msg_full;
|
|
|
|
if (nla_put_u32(msg->skb, TIPC_NLA_PROP_TOL, media->tolerance))
|
|
|
|
goto prop_msg_full;
|
|
|
|
if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN, media->window))
|
|
|
|
goto prop_msg_full;
|
|
|
|
|
|
|
|
nla_nest_end(msg->skb, prop);
|
|
|
|
nla_nest_end(msg->skb, attrs);
|
|
|
|
genlmsg_end(msg->skb, hdr);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
prop_msg_full:
|
|
|
|
nla_nest_cancel(msg->skb, prop);
|
|
|
|
attr_msg_full:
|
|
|
|
nla_nest_cancel(msg->skb, attrs);
|
|
|
|
msg_full:
|
|
|
|
genlmsg_cancel(msg->skb, hdr);
|
|
|
|
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tipc_nl_media_dump(struct sk_buff *skb, struct netlink_callback *cb)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
int i = cb->args[0];
|
|
|
|
struct tipc_nl_msg msg;
|
|
|
|
|
|
|
|
if (i == MAX_MEDIA)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
msg.skb = skb;
|
|
|
|
msg.portid = NETLINK_CB(cb->skb).portid;
|
|
|
|
msg.seq = cb->nlh->nlmsg_seq;
|
|
|
|
|
|
|
|
rtnl_lock();
|
|
|
|
for (; media_info_array[i] != NULL; i++) {
|
|
|
|
err = __tipc_nl_add_media(&msg, media_info_array[i]);
|
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rtnl_unlock();
|
|
|
|
|
|
|
|
cb->args[0] = i;
|
|
|
|
return skb->len;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tipc_nl_media_get(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
char *name;
|
|
|
|
struct tipc_nl_msg msg;
|
|
|
|
struct tipc_media *media;
|
|
|
|
struct sk_buff *rep;
|
|
|
|
struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
|
|
|
|
|
|
|
|
if (!info->attrs[TIPC_NLA_MEDIA])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
err = nla_parse_nested(attrs, TIPC_NLA_MEDIA_MAX,
|
|
|
|
info->attrs[TIPC_NLA_MEDIA],
|
|
|
|
tipc_nl_media_policy);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (!attrs[TIPC_NLA_MEDIA_NAME])
|
|
|
|
return -EINVAL;
|
|
|
|
name = nla_data(attrs[TIPC_NLA_MEDIA_NAME]);
|
|
|
|
|
|
|
|
rep = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
|
|
|
|
if (!rep)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
msg.skb = rep;
|
|
|
|
msg.portid = info->snd_portid;
|
|
|
|
msg.seq = info->snd_seq;
|
|
|
|
|
|
|
|
rtnl_lock();
|
|
|
|
media = tipc_media_find(name);
|
|
|
|
if (!media) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = __tipc_nl_add_media(&msg, media);
|
|
|
|
if (err)
|
|
|
|
goto err_out;
|
|
|
|
rtnl_unlock();
|
|
|
|
|
|
|
|
return genlmsg_reply(rep, info);
|
|
|
|
err_out:
|
|
|
|
rtnl_unlock();
|
|
|
|
nlmsg_free(rep);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
2014-11-20 12:29:16 +03:00
|
|
|
|
|
|
|
int tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
char *name;
|
|
|
|
struct tipc_media *m;
|
|
|
|
struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
|
|
|
|
|
|
|
|
if (!info->attrs[TIPC_NLA_MEDIA])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
err = nla_parse_nested(attrs, TIPC_NLA_MEDIA_MAX,
|
|
|
|
info->attrs[TIPC_NLA_MEDIA],
|
|
|
|
tipc_nl_media_policy);
|
|
|
|
|
|
|
|
if (!attrs[TIPC_NLA_MEDIA_NAME])
|
|
|
|
return -EINVAL;
|
|
|
|
name = nla_data(attrs[TIPC_NLA_MEDIA_NAME]);
|
|
|
|
|
|
|
|
rtnl_lock();
|
|
|
|
m = tipc_media_find(name);
|
|
|
|
if (!m) {
|
|
|
|
rtnl_unlock();
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attrs[TIPC_NLA_MEDIA_PROP]) {
|
|
|
|
struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
|
|
|
|
|
|
|
|
err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_MEDIA_PROP],
|
|
|
|
props);
|
|
|
|
if (err) {
|
|
|
|
rtnl_unlock();
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (props[TIPC_NLA_PROP_TOL])
|
|
|
|
m->tolerance = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
|
|
|
|
if (props[TIPC_NLA_PROP_PRIO])
|
|
|
|
m->priority = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
|
|
|
|
if (props[TIPC_NLA_PROP_WIN])
|
|
|
|
m->window = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
|
|
|
|
}
|
|
|
|
rtnl_unlock();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|