2006-01-02 19:04:38 +01:00
|
|
|
/*
|
|
|
|
|
* net/tipc/port.c: TIPC port code
|
2007-02-09 23:25:21 +09:00
|
|
|
*
|
2014-03-12 11:31:09 -04:00
|
|
|
* Copyright (c) 1992-2007, 2014, Ericsson AB
|
2013-06-17 10:54:42 -04:00
|
|
|
* Copyright (c) 2004-2008, 2010-2013, Wind River Systems
|
2006-01-02 19:04:38 +01:00
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
2006-01-11 13:30:43 +01:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
2006-01-02 19:04:38 +01:00
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
|
*
|
2006-01-11 13:30:43 +01: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 19:04:38 +01:00
|
|
|
*
|
2006-01-11 13:30:43 +01: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 19:04:38 +01:00
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "core.h"
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "port.h"
|
|
|
|
|
#include "name_table.h"
|
2014-03-12 11:31:09 -04:00
|
|
|
#include "socket.h"
|
2006-01-02 19:04:38 +01:00
|
|
|
|
|
|
|
|
#define MAX_REJECT_SIZE 1024
|
|
|
|
|
|
2012-07-10 10:55:09 +00:00
|
|
|
/**
|
2012-04-17 18:42:28 -04:00
|
|
|
* tipc_port_peer_msg - verify message was sent by connected port's peer
|
|
|
|
|
*
|
|
|
|
|
* Handles cases where the node's network address has changed from
|
|
|
|
|
* the default of <0.0.0> to its configured setting.
|
|
|
|
|
*/
|
|
|
|
|
int tipc_port_peer_msg(struct tipc_port *p_ptr, struct tipc_msg *msg)
|
|
|
|
|
{
|
|
|
|
|
u32 peernode;
|
|
|
|
|
u32 orignode;
|
|
|
|
|
|
2014-03-12 11:31:08 -04:00
|
|
|
if (msg_origport(msg) != tipc_port_peerport(p_ptr))
|
2012-04-17 18:42:28 -04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
orignode = msg_orignode(msg);
|
2014-03-12 11:31:08 -04:00
|
|
|
peernode = tipc_port_peernode(p_ptr);
|
2012-04-17 18:42:28 -04:00
|
|
|
return (orignode == peernode) ||
|
|
|
|
|
(!orignode && (peernode == tipc_own_addr)) ||
|
|
|
|
|
(!peernode && (orignode == tipc_own_addr));
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-27 10:18:28 +08:00
|
|
|
int tipc_publish(struct tipc_port *p_ptr, unsigned int scope,
|
|
|
|
|
struct tipc_name_seq const *seq)
|
2006-01-02 19:04:38 +01:00
|
|
|
{
|
|
|
|
|
struct publication *publ;
|
|
|
|
|
u32 key;
|
|
|
|
|
|
2013-12-27 10:18:28 +08:00
|
|
|
if (p_ptr->connected)
|
2006-10-31 16:59:35 -08:00
|
|
|
return -EINVAL;
|
2013-12-27 10:18:28 +08:00
|
|
|
key = p_ptr->ref + p_ptr->pub_count + 1;
|
|
|
|
|
if (key == p_ptr->ref)
|
|
|
|
|
return -EADDRINUSE;
|
2006-10-31 16:59:35 -08:00
|
|
|
|
2006-01-18 00:38:21 +01:00
|
|
|
publ = tipc_nametbl_publish(seq->type, seq->lower, seq->upper,
|
2011-01-07 11:43:40 -05:00
|
|
|
scope, p_ptr->ref, key);
|
2006-01-02 19:04:38 +01:00
|
|
|
if (publ) {
|
|
|
|
|
list_add(&publ->pport_list, &p_ptr->publications);
|
|
|
|
|
p_ptr->pub_count++;
|
2011-01-07 11:43:40 -05:00
|
|
|
p_ptr->published = 1;
|
2013-12-27 10:18:28 +08:00
|
|
|
return 0;
|
2006-01-02 19:04:38 +01:00
|
|
|
}
|
2013-12-27 10:18:28 +08:00
|
|
|
return -EINVAL;
|
2006-01-02 19:04:38 +01:00
|
|
|
}
|
|
|
|
|
|
2013-12-27 10:18:28 +08:00
|
|
|
int tipc_withdraw(struct tipc_port *p_ptr, unsigned int scope,
|
|
|
|
|
struct tipc_name_seq const *seq)
|
2006-01-02 19:04:38 +01:00
|
|
|
{
|
|
|
|
|
struct publication *publ;
|
|
|
|
|
struct publication *tpubl;
|
|
|
|
|
int res = -EINVAL;
|
2007-02-09 23:25:21 +09:00
|
|
|
|
2006-01-02 19:04:38 +01:00
|
|
|
if (!seq) {
|
2007-02-09 23:25:21 +09:00
|
|
|
list_for_each_entry_safe(publ, tpubl,
|
2006-01-02 19:04:38 +01:00
|
|
|
&p_ptr->publications, pport_list) {
|
2007-02-09 23:25:21 +09:00
|
|
|
tipc_nametbl_withdraw(publ->type, publ->lower,
|
2006-01-18 00:38:21 +01:00
|
|
|
publ->ref, publ->key);
|
2006-01-02 19:04:38 +01:00
|
|
|
}
|
2008-07-14 22:44:01 -07:00
|
|
|
res = 0;
|
2006-01-02 19:04:38 +01:00
|
|
|
} else {
|
2007-02-09 23:25:21 +09:00
|
|
|
list_for_each_entry_safe(publ, tpubl,
|
2006-01-02 19:04:38 +01:00
|
|
|
&p_ptr->publications, pport_list) {
|
|
|
|
|
if (publ->scope != scope)
|
|
|
|
|
continue;
|
|
|
|
|
if (publ->type != seq->type)
|
|
|
|
|
continue;
|
|
|
|
|
if (publ->lower != seq->lower)
|
|
|
|
|
continue;
|
|
|
|
|
if (publ->upper != seq->upper)
|
|
|
|
|
break;
|
2007-02-09 23:25:21 +09:00
|
|
|
tipc_nametbl_withdraw(publ->type, publ->lower,
|
2006-01-18 00:38:21 +01:00
|
|
|
publ->ref, publ->key);
|
2008-07-14 22:44:01 -07:00
|
|
|
res = 0;
|
2006-01-02 19:04:38 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (list_empty(&p_ptr->publications))
|
2011-01-07 11:43:40 -05:00
|
|
|
p_ptr->published = 0;
|
2006-01-02 19:04:38 +01:00
|
|
|
return res;
|
|
|
|
|
}
|