Skip to content

Commit 928df18

Browse files
Jon Maloydavem330
authored andcommitted
tipc: obsolete TIPC_ZONE_SCOPE
Publications for TIPC_CLUSTER_SCOPE and TIPC_ZONE_SCOPE are in all aspects handled the same way, both on the publishing node and on the receiving nodes. Despite previous ambitions to the contrary, this is never going to change, so we take the conseqeunce of this and obsolete TIPC_ZONE_SCOPE and related macros/functions. Whenever a user is doing a bind() or a sendmsg() attempt using ZONE_SCOPE we translate this internally to CLUSTER_SCOPE, while we remain compatible with users and remote nodes still using ZONE_SCOPE. Furthermore, the non-formalized scope value 0 has always been permitted for use during lookup, with the same meaning as ZONE_SCOPE/CLUSTER_SCOPE. We now permit it even as binding scope, but for compatibility reasons we choose to not change the value of TIPC_CLUSTER_SCOPE. Acked-by: Ying Xue <ying.xue@windriver.com> Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4f1aec0 commit 928df18

7 files changed

Lines changed: 77 additions & 88 deletions

File tree

‎include/uapi/linux/tipc.h‎

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -61,50 +61,6 @@ struct tipc_name_seq {
6161
__u32 upper;
6262
};
6363

64-
/* TIPC Address Size, Offset, Mask specification for Z.C.N
65-
*/
66-
#define TIPC_NODE_BITS 12
67-
#define TIPC_CLUSTER_BITS 12
68-
#define TIPC_ZONE_BITS 8
69-
70-
#define TIPC_NODE_OFFSET 0
71-
#define TIPC_CLUSTER_OFFSET TIPC_NODE_BITS
72-
#define TIPC_ZONE_OFFSET (TIPC_CLUSTER_OFFSET + TIPC_CLUSTER_BITS)
73-
74-
#define TIPC_NODE_SIZE ((1UL << TIPC_NODE_BITS) - 1)
75-
#define TIPC_CLUSTER_SIZE ((1UL << TIPC_CLUSTER_BITS) - 1)
76-
#define TIPC_ZONE_SIZE ((1UL << TIPC_ZONE_BITS) - 1)
77-
78-
#define TIPC_NODE_MASK (TIPC_NODE_SIZE << TIPC_NODE_OFFSET)
79-
#define TIPC_CLUSTER_MASK (TIPC_CLUSTER_SIZE << TIPC_CLUSTER_OFFSET)
80-
#define TIPC_ZONE_MASK (TIPC_ZONE_SIZE << TIPC_ZONE_OFFSET)
81-
82-
#define TIPC_ZONE_CLUSTER_MASK (TIPC_ZONE_MASK | TIPC_CLUSTER_MASK)
83-
84-
static inline __u32 tipc_addr(unsigned int zone,
85-
unsigned int cluster,
86-
unsigned int node)
87-
{
88-
return (zone << TIPC_ZONE_OFFSET) |
89-
(cluster << TIPC_CLUSTER_OFFSET) |
90-
node;
91-
}
92-
93-
static inline unsigned int tipc_zone(__u32 addr)
94-
{
95-
return addr >> TIPC_ZONE_OFFSET;
96-
}
97-
98-
static inline unsigned int tipc_cluster(__u32 addr)
99-
{
100-
return (addr & TIPC_CLUSTER_MASK) >> TIPC_CLUSTER_OFFSET;
101-
}
102-
103-
static inline unsigned int tipc_node(__u32 addr)
104-
{
105-
return addr & TIPC_NODE_MASK;
106-
}
107-
10864
/*
10965
* Application-accessible port name types
11066
*/
@@ -117,9 +73,10 @@ static inline unsigned int tipc_node(__u32 addr)
11773
/*
11874
* Publication scopes when binding port names and port name sequences
11975
*/
120-
#define TIPC_ZONE_SCOPE 1
121-
#define TIPC_CLUSTER_SCOPE 2
122-
#define TIPC_NODE_SCOPE 3
76+
enum tipc_scope {
77+
TIPC_CLUSTER_SCOPE = 2, /* 0 can also be used */
78+
TIPC_NODE_SCOPE = 3
79+
};
12380

12481
/*
12582
* Limiting values for messages
@@ -243,7 +200,7 @@ struct sockaddr_tipc {
243200
struct tipc_group_req {
244201
__u32 type; /* group id */
245202
__u32 instance; /* member id */
246-
__u32 scope; /* zone/cluster/node */
203+
__u32 scope; /* cluster/node */
247204
__u32 flags;
248205
};
249206

@@ -268,4 +225,53 @@ struct tipc_sioc_ln_req {
268225
__u32 bearer_id;
269226
char linkname[TIPC_MAX_LINK_NAME];
270227
};
228+
229+
230+
/* The macros and functions below are deprecated:
231+
*/
232+
233+
#define TIPC_ZONE_SCOPE 1
234+
235+
#define TIPC_NODE_BITS 12
236+
#define TIPC_CLUSTER_BITS 12
237+
#define TIPC_ZONE_BITS 8
238+
239+
#define TIPC_NODE_OFFSET 0
240+
#define TIPC_CLUSTER_OFFSET TIPC_NODE_BITS
241+
#define TIPC_ZONE_OFFSET (TIPC_CLUSTER_OFFSET + TIPC_CLUSTER_BITS)
242+
243+
#define TIPC_NODE_SIZE ((1UL << TIPC_NODE_BITS) - 1)
244+
#define TIPC_CLUSTER_SIZE ((1UL << TIPC_CLUSTER_BITS) - 1)
245+
#define TIPC_ZONE_SIZE ((1UL << TIPC_ZONE_BITS) - 1)
246+
247+
#define TIPC_NODE_MASK (TIPC_NODE_SIZE << TIPC_NODE_OFFSET)
248+
#define TIPC_CLUSTER_MASK (TIPC_CLUSTER_SIZE << TIPC_CLUSTER_OFFSET)
249+
#define TIPC_ZONE_MASK (TIPC_ZONE_SIZE << TIPC_ZONE_OFFSET)
250+
251+
#define TIPC_ZONE_CLUSTER_MASK (TIPC_ZONE_MASK | TIPC_CLUSTER_MASK)
252+
253+
static inline __u32 tipc_addr(unsigned int zone,
254+
unsigned int cluster,
255+
unsigned int node)
256+
{
257+
return (zone << TIPC_ZONE_OFFSET) |
258+
(cluster << TIPC_CLUSTER_OFFSET) |
259+
node;
260+
}
261+
262+
static inline unsigned int tipc_zone(__u32 addr)
263+
{
264+
return addr >> TIPC_ZONE_OFFSET;
265+
}
266+
267+
static inline unsigned int tipc_cluster(__u32 addr)
268+
{
269+
return (addr & TIPC_CLUSTER_MASK) >> TIPC_CLUSTER_OFFSET;
270+
}
271+
272+
static inline unsigned int tipc_node(__u32 addr)
273+
{
274+
return addr & TIPC_NODE_MASK;
275+
}
276+
271277
#endif

‎net/tipc/addr.c‎

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,6 @@ int in_own_node(struct net *net, u32 addr)
6363
return (addr == tn->own_addr) || !addr;
6464
}
6565

66-
/**
67-
* addr_domain - convert 2-bit scope value to equivalent message lookup domain
68-
*
69-
* Needed when address of a named message must be looked up a second time
70-
* after a network hop.
71-
*/
72-
u32 addr_domain(struct net *net, u32 sc)
73-
{
74-
struct tipc_net *tn = net_generic(net, tipc_net_id);
75-
76-
if (likely(sc == TIPC_NODE_SCOPE))
77-
return tn->own_addr;
78-
if (sc == TIPC_CLUSTER_SCOPE)
79-
return tipc_cluster_mask(tn->own_addr);
80-
return tipc_zone_mask(tn->own_addr);
81-
}
82-
8366
/**
8467
* tipc_addr_domain_valid - validates a network domain address
8568
*
@@ -124,20 +107,6 @@ int tipc_in_scope(u32 domain, u32 addr)
124107
return 0;
125108
}
126109

127-
/**
128-
* tipc_addr_scope - convert message lookup domain to a 2-bit scope value
129-
*/
130-
int tipc_addr_scope(u32 domain)
131-
{
132-
if (likely(!domain))
133-
return TIPC_ZONE_SCOPE;
134-
if (tipc_node(domain))
135-
return TIPC_NODE_SCOPE;
136-
if (tipc_cluster(domain))
137-
return TIPC_CLUSTER_SCOPE;
138-
return TIPC_ZONE_SCOPE;
139-
}
140-
141110
char *tipc_addr_string_fill(char *string, u32 addr)
142111
{
143112
snprintf(string, 16, "<%u.%u.%u>",

‎net/tipc/addr.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ static inline u32 tipc_cluster_mask(u32 addr)
6060
return addr & TIPC_ZONE_CLUSTER_MASK;
6161
}
6262

63+
static inline int tipc_node2scope(u32 node)
64+
{
65+
return node ? TIPC_NODE_SCOPE : TIPC_CLUSTER_SCOPE;
66+
}
67+
68+
static inline int tipc_scope2node(struct net *net, int sc)
69+
{
70+
return sc != TIPC_NODE_SCOPE ? 0 : tipc_own_addr(net);
71+
}
72+
6373
u32 tipc_own_addr(struct net *net);
6474
int in_own_cluster(struct net *net, u32 addr);
6575
int in_own_cluster_exact(struct net *net, u32 addr);

‎net/tipc/msg.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ bool tipc_msg_lookup_dest(struct net *net, struct sk_buff *skb, int *err)
580580
msg = buf_msg(skb);
581581
if (msg_reroute_cnt(msg))
582582
return false;
583-
dnode = addr_domain(net, msg_lookup_scope(msg));
583+
dnode = tipc_scope2node(net, msg_lookup_scope(msg));
584584
dport = tipc_nametbl_translate(net, msg_nametype(msg),
585585
msg_nameinst(msg), &dnode);
586586
if (!dport)

‎net/tipc/name_table.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,7 @@ struct publication *tipc_nametbl_insert_publ(struct net *net, u32 type,
473473
struct name_seq *seq = nametbl_find_seq(net, type);
474474
int index = hash(type);
475475

476-
if ((scope < TIPC_ZONE_SCOPE) || (scope > TIPC_NODE_SCOPE) ||
477-
(lower > upper)) {
476+
if (scope > TIPC_NODE_SCOPE || lower > upper) {
478477
pr_debug("Failed to publish illegal {%u,%u,%u} with scope %u\n",
479478
type, lower, upper, scope);
480479
return NULL;

‎net/tipc/net.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ int tipc_net_start(struct net *net, u32 addr)
118118
tipc_sk_reinit(net);
119119

120120
tipc_nametbl_publish(net, TIPC_CFG_SRV, tn->own_addr, tn->own_addr,
121-
TIPC_ZONE_SCOPE, 0, tn->own_addr);
121+
TIPC_CLUSTER_SCOPE, 0, tn->own_addr);
122122

123123
pr_info("Started in network mode\n");
124124
pr_info("Own node address %s, network identity %u\n",

‎net/tipc/socket.c‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ static int tipc_bind(struct socket *sock, struct sockaddr *uaddr,
644644
goto exit;
645645
}
646646

647-
res = (addr->scope > 0) ?
647+
res = (addr->scope >= 0) ?
648648
tipc_sk_publish(tsk, addr->scope, &addr->addr.nameseq) :
649649
tipc_sk_withdraw(tsk, -addr->scope, &addr->addr.nameseq);
650650
exit:
@@ -1280,8 +1280,8 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dlen)
12801280
struct tipc_msg *hdr = &tsk->phdr;
12811281
struct tipc_name_seq *seq;
12821282
struct sk_buff_head pkts;
1283-
u32 type, inst, domain;
12841283
u32 dnode, dport;
1284+
u32 type, inst;
12851285
int mtu, rc;
12861286

12871287
if (unlikely(dlen > TIPC_MAX_USER_MSG_SIZE))
@@ -1332,13 +1332,12 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dlen)
13321332
if (dest->addrtype == TIPC_ADDR_NAME) {
13331333
type = dest->addr.name.name.type;
13341334
inst = dest->addr.name.name.instance;
1335-
domain = dest->addr.name.domain;
1336-
dnode = domain;
1335+
dnode = dest->addr.name.domain;
13371336
msg_set_type(hdr, TIPC_NAMED_MSG);
13381337
msg_set_hdr_sz(hdr, NAMED_H_SIZE);
13391338
msg_set_nametype(hdr, type);
13401339
msg_set_nameinst(hdr, inst);
1341-
msg_set_lookup_scope(hdr, tipc_addr_scope(domain));
1340+
msg_set_lookup_scope(hdr, tipc_node2scope(dnode));
13421341
dport = tipc_nametbl_translate(net, type, inst, &dnode);
13431342
msg_set_destnode(hdr, dnode);
13441343
msg_set_destport(hdr, dport);
@@ -2592,6 +2591,9 @@ static int tipc_sk_publish(struct tipc_sock *tsk, uint scope,
25922591
struct publication *publ;
25932592
u32 key;
25942593

2594+
if (scope != TIPC_NODE_SCOPE)
2595+
scope = TIPC_CLUSTER_SCOPE;
2596+
25952597
if (tipc_sk_connected(sk))
25962598
return -EINVAL;
25972599
key = tsk->portid + tsk->pub_count + 1;
@@ -2617,6 +2619,9 @@ static int tipc_sk_withdraw(struct tipc_sock *tsk, uint scope,
26172619
struct publication *safe;
26182620
int rc = -EINVAL;
26192621

2622+
if (scope != TIPC_NODE_SCOPE)
2623+
scope = TIPC_CLUSTER_SCOPE;
2624+
26202625
list_for_each_entry_safe(publ, safe, &tsk->publications, pport_list) {
26212626
if (seq) {
26222627
if (publ->scope != scope)

0 commit comments

Comments
 (0)