aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorParthasarathy Bhuvaragan <parthasarathy.bhuvaragan@ericsson.com>2016-07-26 02:47:18 -0400
committerDavid S. Miller <davem@davemloft.net>2016-07-26 17:26:42 -0400
commit9ff26e9fabaf52f28fb5e875c0b9ffc2d1512039 (patch)
treed5eb3bafaf3a8d6a4e57a3547fb1a80e3795d448
parentd1c2b5010d07e967d7cbcc232a86b2308d824ca3 (diff)
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>
-rw-r--r--include/uapi/linux/tipc.h30
-rw-r--r--net/tipc/addr.h5
-rw-r--r--net/tipc/bearer.c4
3 files changed, 29 insertions, 10 deletions
diff --git a/include/uapi/linux/tipc.h b/include/uapi/linux/tipc.h
index 6f71b9b41595..bf049e8fe31b 100644
--- a/include/uapi/linux/tipc.h
+++ b/include/uapi/linux/tipc.h
@@ -60,26 +60,48 @@ struct tipc_name_seq {
60 __u32 upper; 60 __u32 upper;
61}; 61};
62 62
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
63static inline __u32 tipc_addr(unsigned int zone, 83static inline __u32 tipc_addr(unsigned int zone,
64 unsigned int cluster, 84 unsigned int cluster,
65 unsigned int node) 85 unsigned int node)
66{ 86{
67 return (zone << 24) | (cluster << 12) | node; 87 return (zone << TIPC_ZONE_OFFSET) |
88 (cluster << TIPC_CLUSTER_OFFSET) |
89 node;
68} 90}
69 91
70static inline unsigned int tipc_zone(__u32 addr) 92static inline unsigned int tipc_zone(__u32 addr)
71{ 93{
72 return addr >> 24; 94 return addr >> TIPC_ZONE_OFFSET;
73} 95}
74 96
75static inline unsigned int tipc_cluster(__u32 addr) 97static inline unsigned int tipc_cluster(__u32 addr)
76{ 98{
77 return (addr >> 12) & 0xfff; 99 return (addr & TIPC_CLUSTER_MASK) >> TIPC_CLUSTER_OFFSET;
78} 100}
79 101
80static inline unsigned int tipc_node(__u32 addr) 102static inline unsigned int tipc_node(__u32 addr)
81{ 103{
82 return addr & 0xfff; 104 return addr & TIPC_NODE_MASK;
83} 105}
84 106
85/* 107/*
diff --git a/net/tipc/addr.h b/net/tipc/addr.h
index 64f4004a6fac..bebb347803ce 100644
--- a/net/tipc/addr.h
+++ b/net/tipc/addr.h
@@ -43,9 +43,6 @@
43#include <net/netns/generic.h> 43#include <net/netns/generic.h>
44#include "core.h" 44#include "core.h"
45 45
46#define TIPC_ZONE_MASK 0xff000000u
47#define TIPC_CLUSTER_MASK 0xfffff000u
48
49static inline u32 tipc_own_addr(struct net *net) 46static inline u32 tipc_own_addr(struct net *net)
50{ 47{
51 struct tipc_net *tn = net_generic(net, tipc_net_id); 48 struct tipc_net *tn = net_generic(net, tipc_net_id);
@@ -60,7 +57,7 @@ static inline u32 tipc_zone_mask(u32 addr)
60 57
61static inline u32 tipc_cluster_mask(u32 addr) 58static inline u32 tipc_cluster_mask(u32 addr)
62{ 59{
63 return addr & TIPC_CLUSTER_MASK; 60 return addr & TIPC_ZONE_CLUSTER_MASK;
64} 61}
65 62
66u32 tipc_own_addr(struct net *net); 63u32 tipc_own_addr(struct net *net);
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index 4131d5a86f55..65b0998a9bab 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -225,7 +225,7 @@ static int tipc_enable_bearer(struct net *net, const char *name,
225 if (tipc_addr_domain_valid(disc_domain) && 225 if (tipc_addr_domain_valid(disc_domain) &&
226 (disc_domain != tn->own_addr)) { 226 (disc_domain != tn->own_addr)) {
227 if (tipc_in_scope(disc_domain, tn->own_addr)) { 227 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;
229 res = 0; /* accept any node in own cluster */ 229 res = 0; /* accept any node in own cluster */
230 } else if (in_own_cluster_exact(net, disc_domain)) 230 } else if (in_own_cluster_exact(net, disc_domain))
231 res = 0; /* accept specified node in own cluster */ 231 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)
832 u32 prio; 832 u32 prio;
833 833
834 prio = TIPC_MEDIA_LINK_PRI; 834 prio = TIPC_MEDIA_LINK_PRI;
835 domain = tn->own_addr & TIPC_CLUSTER_MASK; 835 domain = tn->own_addr & TIPC_ZONE_CLUSTER_MASK;
836 836
837 if (!info->attrs[TIPC_NLA_BEARER]) 837 if (!info->attrs[TIPC_NLA_BEARER])
838 return -EINVAL; 838 return -EINVAL;