Skip to content

Commit

Permalink
tipc: name tipc name table support net namespace
Browse files Browse the repository at this point in the history
TIPC name table is used to store the mapping relationship between
TIPC service name and socket port ID. When tipc supports namespace,
it allows users to publish service names only owned by a certain
namespace. Therefore, every namespace must have its private name
table to prevent service names published to one namespace from being
contaminated by other service names in another namespace. Therefore,
The name table global variable (ie, nametbl) and its lock must be
moved to tipc_net structure, and a parameter of namespace must be
added for necessary functions so that they can obtain name table
variable defined in tipc_net structure.

Signed-off-by: Ying Xue <ying.xue@windriver.com>
Tested-by: Tero Aho <Tero.Aho@coriant.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Ying Xue authored and David S. Miller committed Jan 12, 2015
1 parent e05b31f commit 4ac1c8d
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 116 deletions.
3 changes: 2 additions & 1 deletion net/tipc/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ struct sk_buff *tipc_cfg_do_cmd(struct net *net, u32 orig_node, u16 cmd,
req_tlv_space);
break;
case TIPC_CMD_SHOW_NAME_TABLE:
rep_tlv_buf = tipc_nametbl_get(req_tlv_area, req_tlv_space);
rep_tlv_buf = tipc_nametbl_get(net, req_tlv_area,
req_tlv_space);
break;
case TIPC_CMD_GET_BEARER_NAMES:
rep_tlv_buf = tipc_bearer_get_names(net);
Expand Down
19 changes: 12 additions & 7 deletions net/tipc/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,24 @@ static int __net_init tipc_init_net(struct net *net)
spin_lock_init(&tn->node_list_lock);

err = tipc_sk_rht_init(net);
if (err)
goto out_sk_rht;

err = tipc_nametbl_init(net);
if (err)
goto out_nametbl;
return 0;

out_nametbl:
tipc_sk_rht_destroy(net);
out_sk_rht:
return err;
}

static void __net_exit tipc_exit_net(struct net *net)
{
tipc_net_stop(net);
tipc_nametbl_stop(net);
tipc_sk_rht_destroy(net);
}

Expand Down Expand Up @@ -98,10 +110,6 @@ static int __init tipc_init(void)
if (err)
goto out_pernet;

err = tipc_nametbl_init();
if (err)
goto out_nametbl;

err = tipc_netlink_start();
if (err)
goto out_netlink;
Expand Down Expand Up @@ -133,8 +141,6 @@ static int __init tipc_init(void)
out_socket:
tipc_netlink_stop();
out_netlink:
tipc_nametbl_stop();
out_nametbl:
unregister_pernet_subsys(&tipc_net_ops);
out_pernet:
pr_err("Unable to start in single node mode\n");
Expand All @@ -147,7 +153,6 @@ static void __exit tipc_exit(void)
tipc_bearer_cleanup();
tipc_netlink_stop();
tipc_subscr_stop();
tipc_nametbl_stop();
tipc_socket_stop();
tipc_unregister_sysctl();

Expand Down
4 changes: 4 additions & 0 deletions net/tipc/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ struct tipc_net {

/* Socket hash table */
struct rhashtable sk_rht;

/* Name table */
spinlock_t nametbl_lock;
struct name_table *nametbl;
};

#ifdef CONFIG_SYSCTL
Expand Down
4 changes: 2 additions & 2 deletions net/tipc/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ bool tipc_msg_reverse(struct sk_buff *buf, u32 *dnode, int err)
* Returns 0 (TIPC_OK) if message ok and we can try again, -TIPC error
* code if message to be rejected
*/
int tipc_msg_eval(struct sk_buff *buf, u32 *dnode)
int tipc_msg_eval(struct net *net, struct sk_buff *buf, u32 *dnode)
{
struct tipc_msg *msg = buf_msg(buf);
u32 dport;
Expand All @@ -441,7 +441,7 @@ int tipc_msg_eval(struct sk_buff *buf, u32 *dnode)
return -TIPC_ERR_NO_NAME;

*dnode = addr_domain(msg_lookup_scope(msg));
dport = tipc_nametbl_translate(msg_nametype(msg),
dport = tipc_nametbl_translate(net, msg_nametype(msg),
msg_nameinst(msg),
dnode);
if (!dport)
Expand Down
2 changes: 1 addition & 1 deletion net/tipc/msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ static inline u32 msg_tot_origport(struct tipc_msg *m)

struct sk_buff *tipc_buf_acquire(u32 size);
bool tipc_msg_reverse(struct sk_buff *buf, u32 *dnode, int err);
int tipc_msg_eval(struct sk_buff *buf, u32 *dnode);
int tipc_msg_eval(struct net *net, struct sk_buff *buf, u32 *dnode);
void tipc_msg_init(struct tipc_msg *m, u32 user, u32 type, u32 hsize,
u32 destnode);
struct sk_buff *tipc_msg_create(uint user, uint type, uint hdr_sz,
Expand Down
37 changes: 22 additions & 15 deletions net/tipc/name_distr.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,14 @@ void named_cluster_distribute(struct net *net, struct sk_buff *skb)
/**
* tipc_named_publish - tell other nodes about a new publication by this node
*/
struct sk_buff *tipc_named_publish(struct publication *publ)
struct sk_buff *tipc_named_publish(struct net *net, struct publication *publ)
{
struct tipc_net *tn = net_generic(net, tipc_net_id);
struct sk_buff *buf;
struct distr_item *item;

list_add_tail_rcu(&publ->local_list,
&tipc_nametbl->publ_list[publ->scope]);
&tn->nametbl->publ_list[publ->scope]);

if (publ->scope == TIPC_NODE_SCOPE)
return NULL;
Expand Down Expand Up @@ -206,15 +207,16 @@ static void named_distribute(struct net *net, struct sk_buff_head *list,
*/
void tipc_named_node_up(struct net *net, u32 dnode)
{
struct tipc_net *tn = net_generic(net, tipc_net_id);
struct sk_buff_head head;

__skb_queue_head_init(&head);

rcu_read_lock();
named_distribute(net, &head, dnode,
&tipc_nametbl->publ_list[TIPC_CLUSTER_SCOPE]);
&tn->nametbl->publ_list[TIPC_CLUSTER_SCOPE]);
named_distribute(net, &head, dnode,
&tipc_nametbl->publ_list[TIPC_ZONE_SCOPE]);
&tn->nametbl->publ_list[TIPC_ZONE_SCOPE]);
rcu_read_unlock();

tipc_link_xmit(net, &head, dnode, dnode);
Expand Down Expand Up @@ -262,14 +264,15 @@ static void tipc_publ_unsubscribe(struct net *net, struct publication *publ,
*/
static void tipc_publ_purge(struct net *net, struct publication *publ, u32 addr)
{
struct tipc_net *tn = net_generic(net, tipc_net_id);
struct publication *p;

spin_lock_bh(&tipc_nametbl_lock);
p = tipc_nametbl_remove_publ(publ->type, publ->lower,
spin_lock_bh(&tn->nametbl_lock);
p = tipc_nametbl_remove_publ(net, publ->type, publ->lower,
publ->node, publ->ref, publ->key);
if (p)
tipc_publ_unsubscribe(net, p, addr);
spin_unlock_bh(&tipc_nametbl_lock);
spin_unlock_bh(&tn->nametbl_lock);

if (p != publ) {
pr_err("Unable to remove publication from failed node\n"
Expand Down Expand Up @@ -302,7 +305,8 @@ static bool tipc_update_nametbl(struct net *net, struct distr_item *i,
struct publication *publ = NULL;

if (dtype == PUBLICATION) {
publ = tipc_nametbl_insert_publ(ntohl(i->type), ntohl(i->lower),
publ = tipc_nametbl_insert_publ(net, ntohl(i->type),
ntohl(i->lower),
ntohl(i->upper),
TIPC_CLUSTER_SCOPE, node,
ntohl(i->ref), ntohl(i->key));
Expand All @@ -311,7 +315,8 @@ static bool tipc_update_nametbl(struct net *net, struct distr_item *i,
return true;
}
} else if (dtype == WITHDRAWAL) {
publ = tipc_nametbl_remove_publ(ntohl(i->type), ntohl(i->lower),
publ = tipc_nametbl_remove_publ(net, ntohl(i->type),
ntohl(i->lower),
node, ntohl(i->ref),
ntohl(i->key));
if (publ) {
Expand Down Expand Up @@ -376,19 +381,20 @@ void tipc_named_process_backlog(struct net *net)
*/
void tipc_named_rcv(struct net *net, struct sk_buff *buf)
{
struct tipc_net *tn = net_generic(net, tipc_net_id);
struct tipc_msg *msg = buf_msg(buf);
struct distr_item *item = (struct distr_item *)msg_data(msg);
u32 count = msg_data_sz(msg) / ITEM_SIZE;
u32 node = msg_orignode(msg);

spin_lock_bh(&tipc_nametbl_lock);
spin_lock_bh(&tn->nametbl_lock);
while (count--) {
if (!tipc_update_nametbl(net, item, node, msg_type(msg)))
tipc_named_add_backlog(item, msg_type(msg), node);
item++;
}
tipc_named_process_backlog(net);
spin_unlock_bh(&tipc_nametbl_lock);
spin_unlock_bh(&tn->nametbl_lock);
kfree_skb(buf);
}

Expand All @@ -399,17 +405,18 @@ void tipc_named_rcv(struct net *net, struct sk_buff *buf)
* All name table entries published by this node are updated to reflect
* the node's new network address.
*/
void tipc_named_reinit(void)
void tipc_named_reinit(struct net *net)
{
struct tipc_net *tn = net_generic(net, tipc_net_id);
struct publication *publ;
int scope;

spin_lock_bh(&tipc_nametbl_lock);
spin_lock_bh(&tn->nametbl_lock);

for (scope = TIPC_ZONE_SCOPE; scope <= TIPC_NODE_SCOPE; scope++)
list_for_each_entry_rcu(publ, &tipc_nametbl->publ_list[scope],
list_for_each_entry_rcu(publ, &tn->nametbl->publ_list[scope],
local_list)
publ->node = tipc_own_addr;

spin_unlock_bh(&tipc_nametbl_lock);
spin_unlock_bh(&tn->nametbl_lock);
}
4 changes: 2 additions & 2 deletions net/tipc/name_distr.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ struct distr_item {
__be32 key;
};

struct sk_buff *tipc_named_publish(struct publication *publ);
struct sk_buff *tipc_named_publish(struct net *net, struct publication *publ);
struct sk_buff *tipc_named_withdraw(struct publication *publ);
void named_cluster_distribute(struct net *net, struct sk_buff *buf);
void tipc_named_node_up(struct net *net, u32 dnode);
void tipc_named_rcv(struct net *net, struct sk_buff *buf);
void tipc_named_reinit(void);
void tipc_named_reinit(struct net *net);
void tipc_named_process_backlog(struct net *net);
void tipc_publ_notify(struct net *net, struct list_head *nsub_list, u32 addr);

Expand Down
Loading

0 comments on commit 4ac1c8d

Please sign in to comment.