Skip to content

Commit 2026364

Browse files
Jon Maloydavem330
authored andcommitted
tipc: remove restrictions on node address values
Nominally, TIPC organizes network nodes into a three-level network hierarchy consisting of the levels 'zone', 'cluster' and 'node'. This hierarchy is reflected in the node address format, - it is sub-divided into an 8-bit zone id, and 12 bit cluster id, and a 12-bit node id. However, the 'zone' and 'cluster' levels have in reality never been fully implemented,and never will be. The result of this has been that the first 20 bits the node identity structure have been wasted, and the usable node identity range within a cluster has been limited to 12 bits. This is starting to become a problem. In the following commits, we will need to be able to connect between nodes which are using the whole 32-bit value space of the node address. We therefore remove the restrictions on which values can be assigned to node identity, -it is from now on only a 32-bit integer with no assumed internal structure. Isolation between clusters is now achieved only by setting different values for the 'network id' field used during neighbor discovery, in practice leading to the latter becoming the new cluster identity. The rules for accepting discovery requests/responses from neighboring nodes now become: - If the user is using legacy address format on both peers, reception of discovery messages is subject to the legacy lookup domain check in addition to the cluster id check. - Otherwise, the discovery request/response is always accepted, provided both peers have the same network id. This secures backwards compatibility for users who have been using zone or cluster identities as cluster separators, instead of the intended 'network id'. Acked-by: Ying Xue <[email protected]> Signed-off-by: Jon Maloy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b39e465 commit 2026364

File tree

8 files changed

+21
-105
lines changed

8 files changed

+21
-105
lines changed

net/tipc/addr.c

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,6 @@
3838
#include "addr.h"
3939
#include "core.h"
4040

41-
/**
42-
* in_own_cluster - test for cluster inclusion; <0.0.0> always matches
43-
*/
44-
int in_own_cluster(struct net *net, u32 addr)
45-
{
46-
return in_own_cluster_exact(net, addr) || !addr;
47-
}
48-
49-
int in_own_cluster_exact(struct net *net, u32 addr)
50-
{
51-
struct tipc_net *tn = net_generic(net, tipc_net_id);
52-
53-
return !((addr ^ tn->own_addr) >> 12);
54-
}
55-
5641
/**
5742
* in_own_node - test for node inclusion; <0.0.0> always matches
5843
*/
@@ -63,46 +48,13 @@ int in_own_node(struct net *net, u32 addr)
6348
return (addr == tn->own_addr) || !addr;
6449
}
6550

66-
/**
67-
* tipc_addr_domain_valid - validates a network domain address
68-
*
69-
* Accepts <Z.C.N>, <Z.C.0>, <Z.0.0>, and <0.0.0>,
70-
* where Z, C, and N are non-zero.
71-
*
72-
* Returns 1 if domain address is valid, otherwise 0
73-
*/
74-
int tipc_addr_domain_valid(u32 addr)
75-
{
76-
u32 n = tipc_node(addr);
77-
u32 c = tipc_cluster(addr);
78-
u32 z = tipc_zone(addr);
79-
80-
if (n && (!z || !c))
81-
return 0;
82-
if (c && !z)
83-
return 0;
84-
return 1;
85-
}
86-
87-
/**
88-
* tipc_addr_node_valid - validates a proposed network address for this node
89-
*
90-
* Accepts <Z.C.N>, where Z, C, and N are non-zero.
91-
*
92-
* Returns 1 if address can be used, otherwise 0
93-
*/
94-
int tipc_addr_node_valid(u32 addr)
95-
{
96-
return tipc_addr_domain_valid(addr) && tipc_node(addr);
97-
}
98-
9951
int tipc_in_scope(u32 domain, u32 addr)
10052
{
10153
if (!domain || (domain == addr))
10254
return 1;
10355
if (domain == tipc_cluster_mask(addr)) /* domain <Z.C.0> */
10456
return 1;
105-
if (domain == tipc_zone_mask(addr)) /* domain <Z.0.0> */
57+
if (domain == (addr & TIPC_ZONE_MASK)) /* domain <Z.0.0> */
10658
return 1;
10759
return 0;
10860
}

net/tipc/addr.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ static inline u32 tipc_own_addr(struct net *net)
5050
return tn->own_addr;
5151
}
5252

53-
static inline u32 tipc_zone_mask(u32 addr)
54-
{
55-
return addr & TIPC_ZONE_MASK;
56-
}
57-
5853
static inline u32 tipc_cluster_mask(u32 addr)
5954
{
6055
return addr & TIPC_ZONE_CLUSTER_MASK;
@@ -71,14 +66,8 @@ static inline int tipc_scope2node(struct net *net, int sc)
7166
}
7267

7368
u32 tipc_own_addr(struct net *net);
74-
int in_own_cluster(struct net *net, u32 addr);
75-
int in_own_cluster_exact(struct net *net, u32 addr);
7669
int in_own_node(struct net *net, u32 addr);
77-
u32 addr_domain(struct net *net, u32 sc);
78-
int tipc_addr_domain_valid(u32);
79-
int tipc_addr_node_valid(u32 addr);
8070
int tipc_in_scope(u32 domain, u32 addr);
81-
int tipc_addr_scope(u32 domain);
8271
char *tipc_addr_string_fill(char *string, u32 addr);
8372

8473
#endif

net/tipc/bearer.c

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ static int tipc_enable_bearer(struct net *net, const char *name,
240240
struct tipc_bearer *b;
241241
struct tipc_media *m;
242242
struct sk_buff *skb;
243-
char addr_string[16];
244243
int bearer_id = 0;
245244
int res = -EINVAL;
246245
char *errstr = "";
@@ -256,21 +255,6 @@ static int tipc_enable_bearer(struct net *net, const char *name,
256255
goto rejected;
257256
}
258257

259-
if (tipc_addr_domain_valid(disc_domain) && disc_domain != self) {
260-
if (tipc_in_scope(disc_domain, self)) {
261-
/* Accept any node in own cluster */
262-
disc_domain = self & TIPC_ZONE_CLUSTER_MASK;
263-
res = 0;
264-
} else if (in_own_cluster_exact(net, disc_domain)) {
265-
/* Accept specified node in own cluster */
266-
res = 0;
267-
}
268-
}
269-
if (res) {
270-
errstr = "illegal discovery domain";
271-
goto rejected;
272-
}
273-
274258
if (prio > TIPC_MAX_LINK_PRI && prio != TIPC_MEDIA_LINK_PRI) {
275259
errstr = "illegal priority";
276260
goto rejected;
@@ -354,12 +338,11 @@ static int tipc_enable_bearer(struct net *net, const char *name,
354338
return -ENOMEM;
355339
}
356340

357-
tipc_addr_string_fill(addr_string, disc_domain);
358-
pr_info("Enabled bearer <%s>, discovery scope %s, priority %u\n",
359-
name, addr_string, prio);
341+
pr_info("Enabled bearer <%s>, priority %u\n", name, prio);
342+
360343
return res;
361344
rejected:
362-
pr_warn("Bearer <%s> rejected, %s\n", name, errstr);
345+
pr_warn("Enabling of bearer <%s> rejected, %s\n", name, errstr);
363346
return res;
364347
}
365348

@@ -865,12 +848,10 @@ int __tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info)
865848
char *bearer;
866849
struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
867850
struct net *net = sock_net(skb->sk);
868-
struct tipc_net *tn = net_generic(net, tipc_net_id);
869-
u32 domain;
851+
u32 domain = 0;
870852
u32 prio;
871853

872854
prio = TIPC_MEDIA_LINK_PRI;
873-
domain = tn->own_addr & TIPC_ZONE_CLUSTER_MASK;
874855

875856
if (!info->attrs[TIPC_NLA_BEARER])
876857
return -EINVAL;

net/tipc/discover.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,17 @@ void tipc_disc_rcv(struct net *net, struct sk_buff *skb,
161161
return;
162162
if (net_id != tn->net_id)
163163
return;
164-
if (!tipc_addr_domain_valid(dst))
165-
return;
166-
if (!tipc_addr_node_valid(src))
167-
return;
168164
if (in_own_node(net, src)) {
169165
disc_dupl_alert(b, self, &maddr);
170166
return;
171167
}
172-
if (!tipc_in_scope(dst, self))
173-
return;
174-
if (!tipc_in_scope(b->domain, src))
175-
return;
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+
}
176175
tipc_node_check_dest(net, src, b, caps, signature,
177176
&maddr, &respond, &dupl_addr);
178177
if (dupl_addr)

net/tipc/link.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ char *tipc_link_name(struct tipc_link *l)
434434
*/
435435
bool tipc_link_create(struct net *net, char *if_name, int bearer_id,
436436
int tolerance, char net_plane, u32 mtu, int priority,
437-
int window, u32 session, u32 ownnode, u32 peer,
437+
int window, u32 session, u32 self, u32 peer,
438438
u16 peer_caps,
439439
struct tipc_link *bc_sndlink,
440440
struct tipc_link *bc_rcvlink,
@@ -451,9 +451,7 @@ bool tipc_link_create(struct net *net, char *if_name, int bearer_id,
451451
l->session = session;
452452

453453
/* Note: peer i/f name is completed by reset/activate message */
454-
sprintf(l->name, "%u.%u.%u:%s-%u.%u.%u:unknown",
455-
tipc_zone(ownnode), tipc_cluster(ownnode), tipc_node(ownnode),
456-
if_name, tipc_zone(peer), tipc_cluster(peer), tipc_node(peer));
454+
sprintf(l->name, "%x:%s-%x:unknown", self, if_name, peer);
457455
strcpy(l->if_name, if_name);
458456
l->addr = peer;
459457
l->peer_caps = peer_caps;

net/tipc/net.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ int tipc_net_start(struct net *net, u32 addr)
121121
TIPC_CLUSTER_SCOPE, 0, tn->own_addr);
122122

123123
pr_info("Started in network mode\n");
124-
pr_info("Own node address %s, network identity %u\n",
124+
pr_info("Own node address %s, cluster identity %u\n",
125125
tipc_addr_string_fill(addr_string, tn->own_addr),
126126
tn->net_id);
127127
return 0;
@@ -238,7 +238,7 @@ int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
238238
return -EPERM;
239239

240240
addr = nla_get_u32(attrs[TIPC_NLA_NET_ADDR]);
241-
if (!tipc_addr_node_valid(addr))
241+
if (!addr)
242242
return -EINVAL;
243243

244244
tipc_net_start(net, addr);

net/tipc/node.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,6 @@ static struct tipc_node *tipc_node_find(struct net *net, u32 addr)
233233
struct tipc_node *node;
234234
unsigned int thash = tipc_hashfn(addr);
235235

236-
if (unlikely(!in_own_cluster_exact(net, addr)))
237-
return NULL;
238-
239236
rcu_read_lock();
240237
hlist_for_each_entry_rcu(node, &tn->node_htable[thash], hash) {
241238
if (node->addr != addr)
@@ -836,10 +833,9 @@ void tipc_node_check_dest(struct net *net, u32 onode,
836833

837834
/* Now create new link if not already existing */
838835
if (!l) {
839-
if (n->link_cnt == 2) {
840-
pr_warn("Cannot establish 3rd link to %x\n", n->addr);
836+
if (n->link_cnt == 2)
841837
goto exit;
842-
}
838+
843839
if_name = strchr(b->name, ':') + 1;
844840
if (!tipc_link_create(net, if_name, b->identity, b->tolerance,
845841
b->net_plane, b->mtu, b->priority,

net/tipc/node.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ enum {
4949
TIPC_BCAST_STATE_NACK = (1 << 2),
5050
TIPC_BLOCK_FLOWCTL = (1 << 3),
5151
TIPC_BCAST_RCAST = (1 << 4),
52-
TIPC_MCAST_GROUPS = (1 << 5)
52+
TIPC_NODE_ID32 = (1 << 5)
5353
};
5454

5555
#define TIPC_NODE_CAPABILITIES (TIPC_BCAST_SYNCH | \
5656
TIPC_BCAST_STATE_NACK | \
5757
TIPC_BCAST_RCAST | \
58-
TIPC_BLOCK_FLOWCTL)
58+
TIPC_BLOCK_FLOWCTL | \
59+
TIPC_NODE_ID32)
5960
#define INVALID_BEARER_ID -1
6061

6162
void tipc_node_stop(struct net *net);

0 commit comments

Comments
 (0)