Skip to content

Commit a3796f8

Browse files
ajstephensPaul Gortmaker
authored andcommitted
tipc: Add network address mask helper routines
Introduces a pair of helper routines that convert the network address for a TIPC node into the network address for its cluster or zone. This is a cosmetic change designed to avoid future errors caused by the incorrect use of address bitmasks, and does not alter the existing operation of TIPC. Signed-off-by: Allan Stephens <Allan.Stephens@windriver.com> Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
1 parent aa84729 commit a3796f8

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

‎net/tipc/addr.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ int tipc_in_scope(u32 domain, u32 addr)
8181
{
8282
if (!domain || (domain == addr))
8383
return 1;
84-
if (domain == (addr & 0xfffff000u)) /* domain <Z.C.0> */
84+
if (domain == tipc_cluster_mask(addr)) /* domain <Z.C.0> */
8585
return 1;
86-
if (domain == (addr & 0xff000000u)) /* domain <Z.0.0> */
86+
if (domain == tipc_zone_mask(addr)) /* domain <Z.0.0> */
8787
return 1;
8888
return 0;
8989
}

‎net/tipc/addr.h‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@
3737
#ifndef _TIPC_ADDR_H
3838
#define _TIPC_ADDR_H
3939

40+
static inline u32 tipc_zone_mask(u32 addr)
41+
{
42+
return addr & 0xff000000u;
43+
}
44+
45+
static inline u32 tipc_cluster_mask(u32 addr)
46+
{
47+
return addr & 0xfffff000u;
48+
}
49+
4050
static inline int in_own_cluster(u32 addr)
4151
{
4252
return !((addr ^ tipc_own_addr) >> 12);
@@ -49,14 +59,13 @@ static inline int in_own_cluster(u32 addr)
4959
* after a network hop.
5060
*/
5161

52-
static inline int addr_domain(int sc)
62+
static inline u32 addr_domain(u32 sc)
5363
{
5464
if (likely(sc == TIPC_NODE_SCOPE))
5565
return tipc_own_addr;
5666
if (sc == TIPC_CLUSTER_SCOPE)
57-
return tipc_addr(tipc_zone(tipc_own_addr),
58-
tipc_cluster(tipc_own_addr), 0);
59-
return tipc_addr(tipc_zone(tipc_own_addr), 0, 0);
67+
return tipc_cluster_mask(tipc_own_addr);
68+
return tipc_zone_mask(tipc_own_addr);
6069
}
6170

6271
int tipc_addr_domain_valid(u32);

‎net/tipc/node.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space)
470470

471471
/* Add TLV for broadcast link */
472472

473-
link_info.dest = htonl(tipc_own_addr & 0xfffff000);
473+
link_info.dest = htonl(tipc_cluster_mask(tipc_own_addr));
474474
link_info.up = htonl(1);
475475
strlcpy(link_info.str, tipc_bclink_name, TIPC_MAX_LINK_NAME);
476476
tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO, &link_info, sizeof(link_info));

0 commit comments

Comments
 (0)