Commit 4ac1c8d0 authored by Ying Xue's avatar Ying Xue Committed by David S. Miller

tipc: name tipc name table support net namespace

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: default avatarYing Xue <ying.xue@windriver.com>
Tested-by: default avatarTero Aho <Tero.Aho@coriant.com>
Reviewed-by: default avatarJon Maloy <jon.maloy@ericsson.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e05b31f4
......@@ -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);
......
......@@ -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);
}
......@@ -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;
......@@ -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");
......@@ -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();
......
......@@ -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
......
......@@ -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;
......@@ -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)
......
......@@ -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,
......
......@@ -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;
......@@ -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);
......@@ -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"
......@@ -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));
......@@ -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) {
......@@ -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);
}
......@@ -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);
}
......@@ -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);
......
This diff is collapsed.
......@@ -95,28 +95,27 @@ struct name_table {
u32 local_publ_count;
};
extern spinlock_t tipc_nametbl_lock;
extern struct name_table *tipc_nametbl;
int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb);
struct sk_buff *tipc_nametbl_get(const void *req_tlv_area, int req_tlv_space);
u32 tipc_nametbl_translate(u32 type, u32 instance, u32 *node);
int tipc_nametbl_mc_translate(u32 type, u32 lower, u32 upper, u32 limit,
struct tipc_port_list *dports);
struct sk_buff *tipc_nametbl_get(struct net *net, const void *req_tlv_area,
int req_tlv_space);
u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance, u32 *node);
int tipc_nametbl_mc_translate(struct net *net, u32 type, u32 lower, u32 upper,
u32 limit, struct tipc_port_list *dports);
struct publication *tipc_nametbl_publish(struct net *net, u32 type, u32 lower,
u32 upper, u32 scope, u32 port_ref,
u32 key);
int tipc_nametbl_withdraw(struct net *net, u32 type, u32 lower, u32 ref,
u32 key);
struct publication *tipc_nametbl_insert_publ(u32 type, u32 lower, u32 upper,
u32 scope, u32 node, u32 ref,
struct publication *tipc_nametbl_insert_publ(struct net *net, u32 type,
u32 lower, u32 upper, u32 scope,
u32 node, u32 ref, u32 key);
struct publication *tipc_nametbl_remove_publ(struct net *net, u32 type,
u32 lower, u32 node, u32 ref,
u32 key);
struct publication *tipc_nametbl_remove_publ(u32 type, u32 lower, u32 node,
u32 ref, u32 key);
void tipc_nametbl_subscribe(struct tipc_subscription *s);
void tipc_nametbl_unsubscribe(struct tipc_subscription *s);
int tipc_nametbl_init(void);
void tipc_nametbl_stop(void);
int tipc_nametbl_init(struct net *net);
void tipc_nametbl_stop(struct net *net);
#endif
......@@ -116,7 +116,7 @@ int tipc_net_start(struct net *net, u32 addr)
int res;
tipc_own_addr = addr;
tipc_named_reinit();
tipc_named_reinit(net);
tipc_sk_reinit(net);
res = tipc_bclink_init(net);
if (res)
......
......@@ -256,7 +256,8 @@ static int tipc_receive_from_sock(struct tipc_conn *con)
goto out_close;
}
s->tipc_conn_recvmsg(con->conid, &addr, con->usr_data, buf, ret);
s->tipc_conn_recvmsg(sock_net(con->sock->sk), con->conid, &addr,
con->usr_data, buf, ret);
kmem_cache_free(s->rcvbuf_cache, buf);
......
......@@ -38,6 +38,7 @@
#include <linux/idr.h>
#include <linux/tipc.h>
#include <net/net_namespace.h>
#define TIPC_SERVER_NAME_LEN 32
......@@ -66,10 +67,11 @@ struct tipc_server {
struct workqueue_struct *rcv_wq;
struct workqueue_struct *send_wq;
int max_rcvbuf_size;
void *(*tipc_conn_new) (int conid);
void (*tipc_conn_shutdown) (int conid, void *usr_data);
void (*tipc_conn_recvmsg) (int conid, struct sockaddr_tipc *addr,
void *usr_data, void *buf, size_t len);
void *(*tipc_conn_new)(int conid);
void (*tipc_conn_shutdown)(int conid, void *usr_data);
void (*tipc_conn_recvmsg)(struct net *net, int conid,
struct sockaddr_tipc *addr, void *usr_data,
void *buf, size_t len);
struct sockaddr_tipc *saddr;
const char name[TIPC_SERVER_NAME_LEN];
int imp;
......
......@@ -778,11 +778,8 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff *buf)
scope = TIPC_NODE_SCOPE;
/* Create destination port list: */
tipc_nametbl_mc_translate(msg_nametype(msg),
msg_namelower(msg),
msg_nameupper(msg),
scope,
&dports);
tipc_nametbl_mc_translate(net, msg_nametype(msg), msg_namelower(msg),
msg_nameupper(msg), scope, &dports);
last = dports.count;
if (!last) {
kfree_skb(buf);
......@@ -943,7 +940,7 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock,
msg_set_nametype(mhdr, type);
msg_set_nameinst(mhdr, inst);
msg_set_lookup_scope(mhdr, tipc_addr_scope(domain));
dport = tipc_nametbl_translate(type, inst, &dnode);
dport = tipc_nametbl_translate(net, type, inst, &dnode);
msg_set_destnode(mhdr, dnode);
msg_set_destport(mhdr, dport);
if (unlikely(!dport && !dnode)) {
......@@ -1765,7 +1762,7 @@ int tipc_sk_rcv(struct net *net, struct sk_buff *skb)
/* Validate destination and message */
tsk = tipc_sk_lookup(net, dport);
if (unlikely(!tsk)) {
rc = tipc_msg_eval(skb, &dnode);
rc = tipc_msg_eval(net, skb, &dnode);
goto exit;
}
sk = &tsk->sk;
......
......@@ -50,8 +50,9 @@ struct tipc_subscriber {
struct list_head subscription_list;
};
static void subscr_conn_msg_event(int conid, struct sockaddr_tipc *addr,
void *usr_data, void *buf, size_t len);
static void subscr_conn_msg_event(struct net *net, int conid,
struct sockaddr_tipc *addr, void *usr_data,
void *buf, size_t len);
static void *subscr_named_msg_event(int conid);
static void subscr_conn_shutdown_event(int conid, void *usr_data);
......@@ -260,7 +261,7 @@ static void subscr_cancel(struct tipc_subscr *s,
*
* Called with subscriber lock held.
*/
static int subscr_subscribe(struct tipc_subscr *s,
static int subscr_subscribe(struct net *net, struct tipc_subscr *s,
struct tipc_subscriber *subscriber,
struct tipc_subscription **sub_p) {
struct tipc_subscription *sub;
......@@ -291,6 +292,7 @@ static int subscr_subscribe(struct tipc_subscr *s,
}
/* Initialize subscription object */
sub->net = net;
sub->seq.type = htohl(s->seq.type, swap);
sub->seq.lower = htohl(s->seq.lower, swap);
sub->seq.upper = htohl(s->seq.upper, swap);
......@@ -323,14 +325,16 @@ static void subscr_conn_shutdown_event(int conid, void *usr_data)
}
/* Handle one request to create a new subscription for the subscriber */
static void subscr_conn_msg_event(int conid, struct sockaddr_tipc *addr,
void *usr_data, void *buf, size_t len)
static void subscr_conn_msg_event(struct net *net, int conid,
struct sockaddr_tipc *addr, void *usr_data,
void *buf, size_t len)
{
struct tipc_subscriber *subscriber = usr_data;
struct tipc_subscription *sub = NULL;
spin_lock_bh(&subscriber->lock);
if (subscr_subscribe((struct tipc_subscr *)buf, subscriber, &sub) < 0) {
if (subscr_subscribe(net, (struct tipc_subscr *)buf, subscriber,
&sub) < 0) {
spin_unlock_bh(&subscriber->lock);
subscr_terminate(subscriber);
return;
......
......@@ -49,6 +49,7 @@ struct tipc_subscriber;
* struct tipc_subscription - TIPC network topology subscription object
* @subscriber: pointer to its subscriber
* @seq: name sequence associated with subscription
* @net: point to network namespace
* @timeout: duration of subscription (in ms)
* @filter: event filtering to be done for subscription
* @timer: timer governing subscription duration (optional)
......@@ -61,6 +62,7 @@ struct tipc_subscriber;
struct tipc_subscription {
struct tipc_subscriber *subscriber;
struct tipc_name_seq seq;
struct net *net;
unsigned long timeout;
u32 filter;
struct timer_list timer;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment