aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc
diff options
context:
space:
mode:
authorJon Maloy <jon.maloy@ericsson.com>2018-03-29 17:20:42 -0400
committerDavid S. Miller <davem@davemloft.net>2018-03-31 22:19:52 -0400
commitf20889f72bd531cad88fbb571755a52cabf43424 (patch)
treec7e892e9fd93ab583b9a88224f57e2538deffccc /net/tipc
parent218527fe27adaebeb81eb770459eb335517e90ee (diff)
tipc: refactor name table translate function
The function tipc_nametbl_translate() function is ugly and hard to follow. This can be improved somewhat by introducing a stack variable for holding the publication list to be used and re-ordering the if- clauses for selection of algorithm. Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc')
-rw-r--r--net/tipc/name_table.c61
1 files changed, 25 insertions, 36 deletions
diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c
index e06c7a8907aa..4bdc580c533b 100644
--- a/net/tipc/name_table.c
+++ b/net/tipc/name_table.c
@@ -399,29 +399,32 @@ struct publication *tipc_nametbl_remove_publ(struct net *net, u32 type,
399/** 399/**
400 * tipc_nametbl_translate - perform service instance to socket translation 400 * tipc_nametbl_translate - perform service instance to socket translation
401 * 401 *
402 * On entry, 'destnode' is the search domain used during translation. 402 * On entry, 'dnode' is the search domain used during translation.
403 * 403 *
404 * On exit: 404 * On exit:
405 * - if name translation is deferred to another node/cluster/zone, 405 * - if translation is deferred to another node, leave 'dnode' unchanged and
406 * leaves 'destnode' unchanged (will be non-zero) and returns 0 406 * return 0
407 * - if name translation is attempted and succeeds, sets 'destnode' 407 * - if translation is attempted and succeeds, set 'dnode' to the publishing
408 * to publication node and returns port reference (will be non-zero) 408 * node and return the published (non-zero) port number
409 * - if name translation is attempted and fails, sets 'destnode' to 0 409 * - if translation is attempted and fails, set 'dnode' to 0 and return 0
410 * and returns 0 410 *
411 * Note that for legacy users (node configured with Z.C.N address format) the
412 * 'closest-first' lookup algorithm must be maintained, i.e., if dnode is 0
413 * we must look in the local binding list first
411 */ 414 */
412u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance, 415u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance, u32 *dnode)
413 u32 *destnode)
414{ 416{
415 struct tipc_net *tn = tipc_net(net); 417 struct tipc_net *tn = tipc_net(net);
416 bool legacy = tn->legacy_addr_format; 418 bool legacy = tn->legacy_addr_format;
417 u32 self = tipc_own_addr(net); 419 u32 self = tipc_own_addr(net);
418 struct service_range *sr; 420 struct service_range *sr;
419 struct tipc_service *sc; 421 struct tipc_service *sc;
422 struct list_head *list;
420 struct publication *p; 423 struct publication *p;
421 u32 port = 0; 424 u32 port = 0;
422 u32 node = 0; 425 u32 node = 0;
423 426
424 if (!tipc_in_scope(legacy, *destnode, self)) 427 if (!tipc_in_scope(legacy, *dnode, self))
425 return 0; 428 return 0;
426 429
427 rcu_read_lock(); 430 rcu_read_lock();
@@ -434,43 +437,29 @@ u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance,
434 if (unlikely(!sr)) 437 if (unlikely(!sr))
435 goto no_match; 438 goto no_match;
436 439
437 /* Closest-First Algorithm */ 440 /* Select lookup algorithm: local, closest-first or round-robin */
438 if (legacy && !*destnode) { 441 if (*dnode == self) {
439 if (!list_empty(&sr->local_publ)) { 442 list = &sr->local_publ;
440 p = list_first_entry(&sr->local_publ, 443 if (list_empty(list))
441 struct publication,
442 local_publ);
443 list_move_tail(&p->local_publ,
444 &sr->local_publ);
445 } else {
446 p = list_first_entry(&sr->all_publ,
447 struct publication,
448 all_publ);
449 list_move_tail(&p->all_publ,
450 &sr->all_publ);
451 }
452 }
453
454 /* Round-Robin Algorithm */
455 else if (*destnode == self) {
456 if (list_empty(&sr->local_publ))
457 goto no_match; 444 goto no_match;
458 p = list_first_entry(&sr->local_publ, struct publication, 445 p = list_first_entry(list, struct publication, local_publ);
459 local_publ); 446 list_move_tail(&p->local_publ, &sr->local_publ);
447 } else if (legacy && !*dnode && !list_empty(&sr->local_publ)) {
448 list = &sr->local_publ;
449 p = list_first_entry(list, struct publication, local_publ);
460 list_move_tail(&p->local_publ, &sr->local_publ); 450 list_move_tail(&p->local_publ, &sr->local_publ);
461 } else { 451 } else {
462 p = list_first_entry(&sr->all_publ, struct publication, 452 list = &sr->all_publ;
463 all_publ); 453 p = list_first_entry(list, struct publication, all_publ);
464 list_move_tail(&p->all_publ, &sr->all_publ); 454 list_move_tail(&p->all_publ, &sr->all_publ);
465 } 455 }
466
467 port = p->port; 456 port = p->port;
468 node = p->node; 457 node = p->node;
469no_match: 458no_match:
470 spin_unlock_bh(&sc->lock); 459 spin_unlock_bh(&sc->lock);
471not_found: 460not_found:
472 rcu_read_unlock(); 461 rcu_read_unlock();
473 *destnode = node; 462 *dnode = node;
474 return port; 463 return port;
475} 464}
476 465