Skip to content

Commit 9ff26e9

Browse files
Parthasarathy Bhuvaragandavem330
authored andcommitted
tipc: introduce constants for tipc address validation
In this commit, we introduce defines for tipc address size, offset and mask specification for Zone.Cluster.Node. There is no functional change in this commit. Reviewed-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: Parthasarathy Bhuvaragan <parthasarathy.bhuvaragan@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d1c2b50 commit 9ff26e9

3 files changed

Lines changed: 29 additions & 10 deletions

File tree

include/uapi/linux/tipc.h

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,48 @@ struct tipc_name_seq {
6060
__u32 upper;
6161
};
6262

63+
/* TIPC Address Size, Offset, Mask specification for Z.C.N
64+
*/
65+
#define TIPC_NODE_BITS 12
66+
#define TIPC_CLUSTER_BITS 12
67+
#define TIPC_ZONE_BITS 8
68+
69+
#define TIPC_NODE_OFFSET 0
70+
#define TIPC_CLUSTER_OFFSET TIPC_NODE_BITS
71+
#define TIPC_ZONE_OFFSET (TIPC_CLUSTER_OFFSET + TIPC_CLUSTER_BITS)
72+
73+
#define TIPC_NODE_SIZE ((1UL << TIPC_NODE_BITS) - 1)
74+
#define TIPC_CLUSTER_SIZE ((1UL << TIPC_CLUSTER_BITS) - 1)
75+
#define TIPC_ZONE_SIZE ((1UL << TIPC_ZONE_BITS) - 1)
76+
77+
#define TIPC_NODE_MASK (TIPC_NODE_SIZE << TIPC_NODE_OFFSET)
78+
#define TIPC_CLUSTER_MASK (TIPC_CLUSTER_SIZE << TIPC_CLUSTER_OFFSET)
79+
#define TIPC_ZONE_MASK (TIPC_ZONE_SIZE << TIPC_ZONE_OFFSET)
80+
81+
#define TIPC_ZONE_CLUSTER_MASK (TIPC_ZONE_MASK | TIPC_CLUSTER_MASK)
82+
6383
static inline __u32 tipc_addr(unsigned int zone,
6484
unsigned int cluster,
6585
unsigned int node)
6686
{
67-
return (zone << 24) | (cluster << 12) | node;
87+
return (zone << TIPC_ZONE_OFFSET) |
88+
(cluster << TIPC_CLUSTER_OFFSET) |
89+
node;
6890
}
6991

7092
static inline unsigned int tipc_zone(__u32 addr)
7193
{
72-
return addr >> 24;
94+
return addr >> TIPC_ZONE_OFFSET;
7395
}
7496

7597
static inline unsigned int tipc_cluster(__u32 addr)
7698
{
77-
return (addr >> 12) & 0xfff;
99+
return (addr & TIPC_CLUSTER_MASK) >> TIPC_CLUSTER_OFFSET;
78100
}
79101

80102
static inline unsigned int tipc_node(__u32 addr)
81103
{
82-
return addr & 0xfff;
104+
return addr & TIPC_NODE_MASK;
83105
}
84106

85107
/*

net/tipc/addr.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@
4343
#include <net/netns/generic.h>
4444
#include "core.h"
4545

46-
#define TIPC_ZONE_MASK 0xff000000u
47-
#define TIPC_CLUSTER_MASK 0xfffff000u
48-
4946
static inline u32 tipc_own_addr(struct net *net)
5047
{
5148
struct tipc_net *tn = net_generic(net, tipc_net_id);
@@ -60,7 +57,7 @@ static inline u32 tipc_zone_mask(u32 addr)
6057

6158
static inline u32 tipc_cluster_mask(u32 addr)
6259
{
63-
return addr & TIPC_CLUSTER_MASK;
60+
return addr & TIPC_ZONE_CLUSTER_MASK;
6461
}
6562

6663
u32 tipc_own_addr(struct net *net);

net/tipc/bearer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ static int tipc_enable_bearer(struct net *net, const char *name,
225225
if (tipc_addr_domain_valid(disc_domain) &&
226226
(disc_domain != tn->own_addr)) {
227227
if (tipc_in_scope(disc_domain, tn->own_addr)) {
228-
disc_domain = tn->own_addr & TIPC_CLUSTER_MASK;
228+
disc_domain = tn->own_addr & TIPC_ZONE_CLUSTER_MASK;
229229
res = 0; /* accept any node in own cluster */
230230
} else if (in_own_cluster_exact(net, disc_domain))
231231
res = 0; /* accept specified node in own cluster */
@@ -832,7 +832,7 @@ int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info)
832832
u32 prio;
833833

834834
prio = TIPC_MEDIA_LINK_PRI;
835-
domain = tn->own_addr & TIPC_CLUSTER_MASK;
835+
domain = tn->own_addr & TIPC_ZONE_CLUSTER_MASK;
836836

837837
if (!info->attrs[TIPC_NLA_BEARER])
838838
return -EINVAL;

0 commit comments

Comments
 (0)