diff options
-rw-r--r-- | include/uapi/linux/tipc.h | 102 | ||||
-rw-r--r-- | net/tipc/addr.c | 31 | ||||
-rw-r--r-- | net/tipc/addr.h | 10 | ||||
-rw-r--r-- | net/tipc/msg.c | 2 | ||||
-rw-r--r-- | net/tipc/name_table.c | 3 | ||||
-rw-r--r-- | net/tipc/net.c | 2 | ||||
-rw-r--r-- | net/tipc/socket.c | 15 |
7 files changed, 77 insertions, 88 deletions
diff --git a/include/uapi/linux/tipc.h b/include/uapi/linux/tipc.h index 14bacc7e6cef..4ac9f1f02b06 100644 --- a/include/uapi/linux/tipc.h +++ b/include/uapi/linux/tipc.h | |||
@@ -61,50 +61,6 @@ struct tipc_name_seq { | |||
61 | __u32 upper; | 61 | __u32 upper; |
62 | }; | 62 | }; |
63 | 63 | ||
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 | |||
108 | /* | 64 | /* |
109 | * Application-accessible port name types | 65 | * Application-accessible port name types |
110 | */ | 66 | */ |
@@ -117,9 +73,10 @@ static inline unsigned int tipc_node(__u32 addr) | |||
117 | /* | 73 | /* |
118 | * Publication scopes when binding port names and port name sequences | 74 | * Publication scopes when binding port names and port name sequences |
119 | */ | 75 | */ |
120 | #define TIPC_ZONE_SCOPE 1 | 76 | enum tipc_scope { |
121 | #define TIPC_CLUSTER_SCOPE 2 | 77 | TIPC_CLUSTER_SCOPE = 2, /* 0 can also be used */ |
122 | #define TIPC_NODE_SCOPE 3 | 78 | TIPC_NODE_SCOPE = 3 |
79 | }; | ||
123 | 80 | ||
124 | /* | 81 | /* |
125 | * Limiting values for messages | 82 | * Limiting values for messages |
@@ -243,7 +200,7 @@ struct sockaddr_tipc { | |||
243 | struct tipc_group_req { | 200 | struct tipc_group_req { |
244 | __u32 type; /* group id */ | 201 | __u32 type; /* group id */ |
245 | __u32 instance; /* member id */ | 202 | __u32 instance; /* member id */ |
246 | __u32 scope; /* zone/cluster/node */ | 203 | __u32 scope; /* cluster/node */ |
247 | __u32 flags; | 204 | __u32 flags; |
248 | }; | 205 | }; |
249 | 206 | ||
@@ -268,4 +225,53 @@ struct tipc_sioc_ln_req { | |||
268 | __u32 bearer_id; | 225 | __u32 bearer_id; |
269 | char linkname[TIPC_MAX_LINK_NAME]; | 226 | char linkname[TIPC_MAX_LINK_NAME]; |
270 | }; | 227 | }; |
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 | |||
271 | #endif | 277 | #endif |
diff --git a/net/tipc/addr.c b/net/tipc/addr.c index 48fd3b5a73fb..97cd857d7f43 100644 --- a/net/tipc/addr.c +++ b/net/tipc/addr.c | |||
@@ -64,23 +64,6 @@ int in_own_node(struct net *net, u32 addr) | |||
64 | } | 64 | } |
65 | 65 | ||
66 | /** | 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 | |||
83 | /** | ||
84 | * tipc_addr_domain_valid - validates a network domain address | 67 | * tipc_addr_domain_valid - validates a network domain address |
85 | * | 68 | * |
86 | * Accepts <Z.C.N>, <Z.C.0>, <Z.0.0>, and <0.0.0>, | 69 | * Accepts <Z.C.N>, <Z.C.0>, <Z.0.0>, and <0.0.0>, |
@@ -124,20 +107,6 @@ int tipc_in_scope(u32 domain, u32 addr) | |||
124 | return 0; | 107 | return 0; |
125 | } | 108 | } |
126 | 109 | ||
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 | |||
141 | char *tipc_addr_string_fill(char *string, u32 addr) | 110 | char *tipc_addr_string_fill(char *string, u32 addr) |
142 | { | 111 | { |
143 | snprintf(string, 16, "<%u.%u.%u>", | 112 | snprintf(string, 16, "<%u.%u.%u>", |
diff --git a/net/tipc/addr.h b/net/tipc/addr.h index bebb347803ce..2ecf5a5d40dd 100644 --- a/net/tipc/addr.h +++ b/net/tipc/addr.h | |||
@@ -60,6 +60,16 @@ static inline u32 tipc_cluster_mask(u32 addr) | |||
60 | return addr & TIPC_ZONE_CLUSTER_MASK; | 60 | return addr & TIPC_ZONE_CLUSTER_MASK; |
61 | } | 61 | } |
62 | 62 | ||
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 | |||
63 | u32 tipc_own_addr(struct net *net); | 73 | u32 tipc_own_addr(struct net *net); |
64 | int in_own_cluster(struct net *net, u32 addr); | 74 | int in_own_cluster(struct net *net, u32 addr); |
65 | int in_own_cluster_exact(struct net *net, u32 addr); | 75 | int in_own_cluster_exact(struct net *net, u32 addr); |
diff --git a/net/tipc/msg.c b/net/tipc/msg.c index 4e1c6f6450bb..b6c45dccba3d 100644 --- a/net/tipc/msg.c +++ b/net/tipc/msg.c | |||
@@ -580,7 +580,7 @@ bool tipc_msg_lookup_dest(struct net *net, struct sk_buff *skb, int *err) | |||
580 | msg = buf_msg(skb); | 580 | msg = buf_msg(skb); |
581 | if (msg_reroute_cnt(msg)) | 581 | if (msg_reroute_cnt(msg)) |
582 | return false; | 582 | return false; |
583 | dnode = addr_domain(net, msg_lookup_scope(msg)); | 583 | dnode = tipc_scope2node(net, msg_lookup_scope(msg)); |
584 | dport = tipc_nametbl_translate(net, msg_nametype(msg), | 584 | dport = tipc_nametbl_translate(net, msg_nametype(msg), |
585 | msg_nameinst(msg), &dnode); | 585 | msg_nameinst(msg), &dnode); |
586 | if (!dport) | 586 | if (!dport) |
diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c index e01c9c691ba2..6772390fcb00 100644 --- a/net/tipc/name_table.c +++ b/net/tipc/name_table.c | |||
@@ -473,8 +473,7 @@ struct publication *tipc_nametbl_insert_publ(struct net *net, u32 type, | |||
473 | struct name_seq *seq = nametbl_find_seq(net, type); | 473 | struct name_seq *seq = nametbl_find_seq(net, type); |
474 | int index = hash(type); | 474 | int index = hash(type); |
475 | 475 | ||
476 | if ((scope < TIPC_ZONE_SCOPE) || (scope > TIPC_NODE_SCOPE) || | 476 | if (scope > TIPC_NODE_SCOPE || lower > upper) { |
477 | (lower > upper)) { | ||
478 | pr_debug("Failed to publish illegal {%u,%u,%u} with scope %u\n", | 477 | pr_debug("Failed to publish illegal {%u,%u,%u} with scope %u\n", |
479 | type, lower, upper, scope); | 478 | type, lower, upper, scope); |
480 | return NULL; | 479 | return NULL; |
diff --git a/net/tipc/net.c b/net/tipc/net.c index 1a2fde0d6f61..5c4c4405b78e 100644 --- a/net/tipc/net.c +++ b/net/tipc/net.c | |||
@@ -118,7 +118,7 @@ int tipc_net_start(struct net *net, u32 addr) | |||
118 | tipc_sk_reinit(net); | 118 | tipc_sk_reinit(net); |
119 | 119 | ||
120 | tipc_nametbl_publish(net, TIPC_CFG_SRV, tn->own_addr, tn->own_addr, | 120 | 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); |
122 | 122 | ||
123 | pr_info("Started in network mode\n"); | 123 | 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, network identity %u\n", |
diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 8b04e601311c..910d3827f499 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c | |||
@@ -644,7 +644,7 @@ static int tipc_bind(struct socket *sock, struct sockaddr *uaddr, | |||
644 | goto exit; | 644 | goto exit; |
645 | } | 645 | } |
646 | 646 | ||
647 | res = (addr->scope > 0) ? | 647 | res = (addr->scope >= 0) ? |
648 | tipc_sk_publish(tsk, addr->scope, &addr->addr.nameseq) : | 648 | tipc_sk_publish(tsk, addr->scope, &addr->addr.nameseq) : |
649 | tipc_sk_withdraw(tsk, -addr->scope, &addr->addr.nameseq); | 649 | tipc_sk_withdraw(tsk, -addr->scope, &addr->addr.nameseq); |
650 | exit: | 650 | exit: |
@@ -1280,8 +1280,8 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dlen) | |||
1280 | struct tipc_msg *hdr = &tsk->phdr; | 1280 | struct tipc_msg *hdr = &tsk->phdr; |
1281 | struct tipc_name_seq *seq; | 1281 | struct tipc_name_seq *seq; |
1282 | struct sk_buff_head pkts; | 1282 | struct sk_buff_head pkts; |
1283 | u32 type, inst, domain; | ||
1284 | u32 dnode, dport; | 1283 | u32 dnode, dport; |
1284 | u32 type, inst; | ||
1285 | int mtu, rc; | 1285 | int mtu, rc; |
1286 | 1286 | ||
1287 | if (unlikely(dlen > TIPC_MAX_USER_MSG_SIZE)) | 1287 | 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) | |||
1332 | if (dest->addrtype == TIPC_ADDR_NAME) { | 1332 | if (dest->addrtype == TIPC_ADDR_NAME) { |
1333 | type = dest->addr.name.name.type; | 1333 | type = dest->addr.name.name.type; |
1334 | inst = dest->addr.name.name.instance; | 1334 | inst = dest->addr.name.name.instance; |
1335 | domain = dest->addr.name.domain; | 1335 | dnode = dest->addr.name.domain; |
1336 | dnode = domain; | ||
1337 | msg_set_type(hdr, TIPC_NAMED_MSG); | 1336 | msg_set_type(hdr, TIPC_NAMED_MSG); |
1338 | msg_set_hdr_sz(hdr, NAMED_H_SIZE); | 1337 | msg_set_hdr_sz(hdr, NAMED_H_SIZE); |
1339 | msg_set_nametype(hdr, type); | 1338 | msg_set_nametype(hdr, type); |
1340 | msg_set_nameinst(hdr, inst); | 1339 | msg_set_nameinst(hdr, inst); |
1341 | msg_set_lookup_scope(hdr, tipc_addr_scope(domain)); | 1340 | msg_set_lookup_scope(hdr, tipc_node2scope(dnode)); |
1342 | dport = tipc_nametbl_translate(net, type, inst, &dnode); | 1341 | dport = tipc_nametbl_translate(net, type, inst, &dnode); |
1343 | msg_set_destnode(hdr, dnode); | 1342 | msg_set_destnode(hdr, dnode); |
1344 | msg_set_destport(hdr, dport); | 1343 | msg_set_destport(hdr, dport); |
@@ -2592,6 +2591,9 @@ static int tipc_sk_publish(struct tipc_sock *tsk, uint scope, | |||
2592 | struct publication *publ; | 2591 | struct publication *publ; |
2593 | u32 key; | 2592 | u32 key; |
2594 | 2593 | ||
2594 | if (scope != TIPC_NODE_SCOPE) | ||
2595 | scope = TIPC_CLUSTER_SCOPE; | ||
2596 | |||
2595 | if (tipc_sk_connected(sk)) | 2597 | if (tipc_sk_connected(sk)) |
2596 | return -EINVAL; | 2598 | return -EINVAL; |
2597 | key = tsk->portid + tsk->pub_count + 1; | 2599 | key = tsk->portid + tsk->pub_count + 1; |
@@ -2617,6 +2619,9 @@ static int tipc_sk_withdraw(struct tipc_sock *tsk, uint scope, | |||
2617 | struct publication *safe; | 2619 | struct publication *safe; |
2618 | int rc = -EINVAL; | 2620 | int rc = -EINVAL; |
2619 | 2621 | ||
2622 | if (scope != TIPC_NODE_SCOPE) | ||
2623 | scope = TIPC_CLUSTER_SCOPE; | ||
2624 | |||
2620 | list_for_each_entry_safe(publ, safe, &tsk->publications, pport_list) { | 2625 | list_for_each_entry_safe(publ, safe, &tsk->publications, pport_list) { |
2621 | if (seq) { | 2626 | if (seq) { |
2622 | if (publ->scope != scope) | 2627 | if (publ->scope != scope) |