Skip to content

Commit b89afb1

Browse files
Jon Maloydavem330
authored andcommitted
tipc: allow closest-first lookup algorithm when legacy address is configured
The removal of an internal structure of the node address has an unwanted side effect. - Currently, if a user is sending an anycast message with destination domain 0, the tipc_namebl_translate() function will use the 'closest- first' algorithm to first look for a node local destination, and only when no such is found, will it resort to the cluster global 'round- robin' lookup algorithm. - Current users can get around this, and enforce unconditional use of global round-robin by indicating a destination as Z.0.0 or Z.C.0. - This option disappears when we make the node address flat, since the lookup algorithm has no way of recognizing this case. So, as long as there are node local destinations, the algorithm will always select one of those, and there is nothing the sender can do to change this. We solve this by eliminating the 'closest-first' option, which was never a good idea anyway, for non-legacy users, but only for those. To distinguish between legacy users and non-legacy users we introduce a new flag 'legacy_addr_format' in struct tipc_core, to be set when the user configures a legacy-style Z.C.N node address. Hence, when a legacy user indicates a zero lookup domain 'closest-first' is selected, and in all other cases we use 'round-robin'. Acked-by: Ying Xue <[email protected]> Signed-off-by: Jon Maloy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2026364 commit b89afb1

File tree

6 files changed

+22
-18
lines changed

6 files changed

+22
-18
lines changed

net/tipc/addr.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ int in_own_node(struct net *net, u32 addr)
4848
return (addr == tn->own_addr) || !addr;
4949
}
5050

51-
int tipc_in_scope(u32 domain, u32 addr)
51+
bool tipc_in_scope(bool legacy_format, u32 domain, u32 addr)
5252
{
5353
if (!domain || (domain == addr))
54-
return 1;
54+
return true;
55+
if (!legacy_format)
56+
return false;
5557
if (domain == tipc_cluster_mask(addr)) /* domain <Z.C.0> */
56-
return 1;
58+
return true;
5759
if (domain == (addr & TIPC_ZONE_MASK)) /* domain <Z.0.0> */
58-
return 1;
59-
return 0;
60+
return true;
61+
return false;
6062
}
6163

6264
char *tipc_addr_string_fill(char *string, u32 addr)

net/tipc/addr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static inline int tipc_scope2node(struct net *net, int sc)
6767

6868
u32 tipc_own_addr(struct net *net);
6969
int in_own_node(struct net *net, u32 addr);
70-
int tipc_in_scope(u32 domain, u32 addr);
70+
bool tipc_in_scope(bool legacy_format, u32 domain, u32 addr);
7171
char *tipc_addr_string_fill(char *string, u32 addr);
7272

7373
#endif

net/tipc/core.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* net/tipc/core.h: Include file for TIPC global declarations
33
*
4-
* Copyright (c) 2005-2006, 2013 Ericsson AB
4+
* Copyright (c) 2005-2006, 2013-2018 Ericsson AB
55
* Copyright (c) 2005-2007, 2010-2013, Wind River Systems
66
* All rights reserved.
77
*
@@ -81,6 +81,7 @@ struct tipc_net {
8181
u32 own_addr;
8282
int net_id;
8383
int random;
84+
bool legacy_addr_format;
8485

8586
/* Node table and node list */
8687
spinlock_t node_list_lock;

net/tipc/discover.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ void tipc_disc_rcv(struct net *net, struct sk_buff *skb,
139139
struct tipc_net *tn = tipc_net(net);
140140
struct tipc_msg *hdr = buf_msg(skb);
141141
u16 caps = msg_node_capabilities(hdr);
142+
bool legacy = tn->legacy_addr_format;
142143
u32 signature = msg_node_sig(hdr);
143144
u32 dst = msg_dest_domain(hdr);
144145
u32 net_id = msg_bc_netid(hdr);
@@ -165,13 +166,11 @@ void tipc_disc_rcv(struct net *net, struct sk_buff *skb,
165166
disc_dupl_alert(b, self, &maddr);
166167
return;
167168
}
168-
/* Domain filter only works if both peers use legacy address format */
169-
if (b->domain) {
170-
if (!tipc_in_scope(dst, self))
171-
return;
172-
if (!tipc_in_scope(b->domain, src))
173-
return;
174-
}
169+
if (!tipc_in_scope(legacy, dst, self))
170+
return;
171+
if (!tipc_in_scope(legacy, b->domain, src))
172+
return;
173+
175174
tipc_node_check_dest(net, src, b, caps, signature,
176175
&maddr, &respond, &dupl_addr);
177176
if (dupl_addr)

net/tipc/name_table.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,15 +499,17 @@ struct publication *tipc_nametbl_remove_publ(struct net *net, u32 type,
499499
u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance,
500500
u32 *destnode)
501501
{
502-
struct tipc_net *tn = net_generic(net, tipc_net_id);
502+
struct tipc_net *tn = tipc_net(net);
503+
bool legacy = tn->legacy_addr_format;
504+
u32 self = tipc_own_addr(net);
503505
struct sub_seq *sseq;
504506
struct name_info *info;
505507
struct publication *publ;
506508
struct name_seq *seq;
507509
u32 port = 0;
508510
u32 node = 0;
509511

510-
if (!tipc_in_scope(*destnode, tn->own_addr))
512+
if (!tipc_in_scope(legacy, *destnode, self))
511513
return 0;
512514

513515
rcu_read_lock();
@@ -521,7 +523,7 @@ u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance,
521523
info = sseq->info;
522524

523525
/* Closest-First Algorithm */
524-
if (likely(!*destnode)) {
526+
if (legacy && !*destnode) {
525527
if (!list_empty(&info->local_publ)) {
526528
publ = list_first_entry(&info->local_publ,
527529
struct publication,

net/tipc/net.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
240240
addr = nla_get_u32(attrs[TIPC_NLA_NET_ADDR]);
241241
if (!addr)
242242
return -EINVAL;
243-
243+
tn->legacy_addr_format = true;
244244
tipc_net_start(net, addr);
245245
}
246246

0 commit comments

Comments
 (0)