Skip to content

Commit 4ac1c8d

Browse files
ying-xuedavem330
authored andcommitted
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: 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>
1 parent e05b31f commit 4ac1c8d

15 files changed

Lines changed: 154 additions & 116 deletions

File tree

‎net/tipc/config.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ struct sk_buff *tipc_cfg_do_cmd(struct net *net, u32 orig_node, u16 cmd,
248248
req_tlv_space);
249249
break;
250250
case TIPC_CMD_SHOW_NAME_TABLE:
251-
rep_tlv_buf = tipc_nametbl_get(req_tlv_area, req_tlv_space);
251+
rep_tlv_buf = tipc_nametbl_get(net, req_tlv_area,
252+
req_tlv_space);
252253
break;
253254
case TIPC_CMD_GET_BEARER_NAMES:
254255
rep_tlv_buf = tipc_bearer_get_names(net);

‎net/tipc/core.c‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,24 @@ static int __net_init tipc_init_net(struct net *net)
6262
spin_lock_init(&tn->node_list_lock);
6363

6464
err = tipc_sk_rht_init(net);
65+
if (err)
66+
goto out_sk_rht;
67+
68+
err = tipc_nametbl_init(net);
69+
if (err)
70+
goto out_nametbl;
71+
return 0;
72+
73+
out_nametbl:
74+
tipc_sk_rht_destroy(net);
75+
out_sk_rht:
6576
return err;
6677
}
6778

6879
static void __net_exit tipc_exit_net(struct net *net)
6980
{
7081
tipc_net_stop(net);
82+
tipc_nametbl_stop(net);
7183
tipc_sk_rht_destroy(net);
7284
}
7385

@@ -98,10 +110,6 @@ static int __init tipc_init(void)
98110
if (err)
99111
goto out_pernet;
100112

101-
err = tipc_nametbl_init();
102-
if (err)
103-
goto out_nametbl;
104-
105113
err = tipc_netlink_start();
106114
if (err)
107115
goto out_netlink;
@@ -133,8 +141,6 @@ static int __init tipc_init(void)
133141
out_socket:
134142
tipc_netlink_stop();
135143
out_netlink:
136-
tipc_nametbl_stop();
137-
out_nametbl:
138144
unregister_pernet_subsys(&tipc_net_ops);
139145
out_pernet:
140146
pr_err("Unable to start in single node mode\n");
@@ -147,7 +153,6 @@ static void __exit tipc_exit(void)
147153
tipc_bearer_cleanup();
148154
tipc_netlink_stop();
149155
tipc_subscr_stop();
150-
tipc_nametbl_stop();
151156
tipc_socket_stop();
152157
tipc_unregister_sysctl();
153158

‎net/tipc/core.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ struct tipc_net {
105105

106106
/* Socket hash table */
107107
struct rhashtable sk_rht;
108+
109+
/* Name table */
110+
spinlock_t nametbl_lock;
111+
struct name_table *nametbl;
108112
};
109113

110114
#ifdef CONFIG_SYSCTL

‎net/tipc/msg.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ bool tipc_msg_reverse(struct sk_buff *buf, u32 *dnode, int err)
426426
* Returns 0 (TIPC_OK) if message ok and we can try again, -TIPC error
427427
* code if message to be rejected
428428
*/
429-
int tipc_msg_eval(struct sk_buff *buf, u32 *dnode)
429+
int tipc_msg_eval(struct net *net, struct sk_buff *buf, u32 *dnode)
430430
{
431431
struct tipc_msg *msg = buf_msg(buf);
432432
u32 dport;
@@ -441,7 +441,7 @@ int tipc_msg_eval(struct sk_buff *buf, u32 *dnode)
441441
return -TIPC_ERR_NO_NAME;
442442

443443
*dnode = addr_domain(msg_lookup_scope(msg));
444-
dport = tipc_nametbl_translate(msg_nametype(msg),
444+
dport = tipc_nametbl_translate(net, msg_nametype(msg),
445445
msg_nameinst(msg),
446446
dnode);
447447
if (!dport)

‎net/tipc/msg.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ static inline u32 msg_tot_origport(struct tipc_msg *m)
749749

750750
struct sk_buff *tipc_buf_acquire(u32 size);
751751
bool tipc_msg_reverse(struct sk_buff *buf, u32 *dnode, int err);
752-
int tipc_msg_eval(struct sk_buff *buf, u32 *dnode);
752+
int tipc_msg_eval(struct net *net, struct sk_buff *buf, u32 *dnode);
753753
void tipc_msg_init(struct tipc_msg *m, u32 user, u32 type, u32 hsize,
754754
u32 destnode);
755755
struct sk_buff *tipc_msg_create(uint user, uint type, uint hdr_sz,

‎net/tipc/name_distr.c‎

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,14 @@ void named_cluster_distribute(struct net *net, struct sk_buff *skb)
109109
/**
110110
* tipc_named_publish - tell other nodes about a new publication by this node
111111
*/
112-
struct sk_buff *tipc_named_publish(struct publication *publ)
112+
struct sk_buff *tipc_named_publish(struct net *net, struct publication *publ)
113113
{
114+
struct tipc_net *tn = net_generic(net, tipc_net_id);
114115
struct sk_buff *buf;
115116
struct distr_item *item;
116117

117118
list_add_tail_rcu(&publ->local_list,
118-
&tipc_nametbl->publ_list[publ->scope]);
119+
&tn->nametbl->publ_list[publ->scope]);
119120

120121
if (publ->scope == TIPC_NODE_SCOPE)
121122
return NULL;
@@ -206,15 +207,16 @@ static void named_distribute(struct net *net, struct sk_buff_head *list,
206207
*/
207208
void tipc_named_node_up(struct net *net, u32 dnode)
208209
{
210+
struct tipc_net *tn = net_generic(net, tipc_net_id);
209211
struct sk_buff_head head;
210212

211213
__skb_queue_head_init(&head);
212214

213215
rcu_read_lock();
214216
named_distribute(net, &head, dnode,
215-
&tipc_nametbl->publ_list[TIPC_CLUSTER_SCOPE]);
217+
&tn->nametbl->publ_list[TIPC_CLUSTER_SCOPE]);
216218
named_distribute(net, &head, dnode,
217-
&tipc_nametbl->publ_list[TIPC_ZONE_SCOPE]);
219+
&tn->nametbl->publ_list[TIPC_ZONE_SCOPE]);
218220
rcu_read_unlock();
219221

220222
tipc_link_xmit(net, &head, dnode, dnode);
@@ -262,14 +264,15 @@ static void tipc_publ_unsubscribe(struct net *net, struct publication *publ,
262264
*/
263265
static void tipc_publ_purge(struct net *net, struct publication *publ, u32 addr)
264266
{
267+
struct tipc_net *tn = net_generic(net, tipc_net_id);
265268
struct publication *p;
266269

267-
spin_lock_bh(&tipc_nametbl_lock);
268-
p = tipc_nametbl_remove_publ(publ->type, publ->lower,
270+
spin_lock_bh(&tn->nametbl_lock);
271+
p = tipc_nametbl_remove_publ(net, publ->type, publ->lower,
269272
publ->node, publ->ref, publ->key);
270273
if (p)
271274
tipc_publ_unsubscribe(net, p, addr);
272-
spin_unlock_bh(&tipc_nametbl_lock);
275+
spin_unlock_bh(&tn->nametbl_lock);
273276

274277
if (p != publ) {
275278
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,
302305
struct publication *publ = NULL;
303306

304307
if (dtype == PUBLICATION) {
305-
publ = tipc_nametbl_insert_publ(ntohl(i->type), ntohl(i->lower),
308+
publ = tipc_nametbl_insert_publ(net, ntohl(i->type),
309+
ntohl(i->lower),
306310
ntohl(i->upper),
307311
TIPC_CLUSTER_SCOPE, node,
308312
ntohl(i->ref), ntohl(i->key));
@@ -311,7 +315,8 @@ static bool tipc_update_nametbl(struct net *net, struct distr_item *i,
311315
return true;
312316
}
313317
} else if (dtype == WITHDRAWAL) {
314-
publ = tipc_nametbl_remove_publ(ntohl(i->type), ntohl(i->lower),
318+
publ = tipc_nametbl_remove_publ(net, ntohl(i->type),
319+
ntohl(i->lower),
315320
node, ntohl(i->ref),
316321
ntohl(i->key));
317322
if (publ) {
@@ -376,19 +381,20 @@ void tipc_named_process_backlog(struct net *net)
376381
*/
377382
void tipc_named_rcv(struct net *net, struct sk_buff *buf)
378383
{
384+
struct tipc_net *tn = net_generic(net, tipc_net_id);
379385
struct tipc_msg *msg = buf_msg(buf);
380386
struct distr_item *item = (struct distr_item *)msg_data(msg);
381387
u32 count = msg_data_sz(msg) / ITEM_SIZE;
382388
u32 node = msg_orignode(msg);
383389

384-
spin_lock_bh(&tipc_nametbl_lock);
390+
spin_lock_bh(&tn->nametbl_lock);
385391
while (count--) {
386392
if (!tipc_update_nametbl(net, item, node, msg_type(msg)))
387393
tipc_named_add_backlog(item, msg_type(msg), node);
388394
item++;
389395
}
390396
tipc_named_process_backlog(net);
391-
spin_unlock_bh(&tipc_nametbl_lock);
397+
spin_unlock_bh(&tn->nametbl_lock);
392398
kfree_skb(buf);
393399
}
394400

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

407-
spin_lock_bh(&tipc_nametbl_lock);
414+
spin_lock_bh(&tn->nametbl_lock);
408415

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

414-
spin_unlock_bh(&tipc_nametbl_lock);
421+
spin_unlock_bh(&tn->nametbl_lock);
415422
}

‎net/tipc/name_distr.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ struct distr_item {
6767
__be32 key;
6868
};
6969

70-
struct sk_buff *tipc_named_publish(struct publication *publ);
70+
struct sk_buff *tipc_named_publish(struct net *net, struct publication *publ);
7171
struct sk_buff *tipc_named_withdraw(struct publication *publ);
7272
void named_cluster_distribute(struct net *net, struct sk_buff *buf);
7373
void tipc_named_node_up(struct net *net, u32 dnode);
7474
void tipc_named_rcv(struct net *net, struct sk_buff *buf);
75-
void tipc_named_reinit(void);
75+
void tipc_named_reinit(struct net *net);
7676
void tipc_named_process_backlog(struct net *net);
7777
void tipc_publ_notify(struct net *net, struct list_head *nsub_list, u32 addr);
7878

0 commit comments

Comments
 (0)