aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/addr.c
diff options
context:
space:
mode:
authorJon Maloy <jon.maloy@ericsson.com>2018-03-22 15:42:50 -0400
committerDavid S. Miller <davem@davemloft.net>2018-03-23 13:12:18 -0400
commitd50ccc2d3909fc1b4d40e4af16b026f05dc68707 (patch)
tree09ef046f87dc8eb6d4611b26a355477293a01bbd /net/tipc/addr.c
parent23fd3eace088ab1872ee59c19191a119ec779ac9 (diff)
tipc: add 128-bit node identifier
We add a 128-bit node identity, as an alternative to the currently used 32-bit node address. For the sake of compatibility and to minimize message header changes we retain the existing 32-bit address field. When not set explicitly by the user, this field will be filled with a hash value generated from the much longer node identity, and be used as a shorthand value for the latter. We permit either the address or the identity to be set by configuration, but not both, so when the address value is set by a legacy user the corresponding 128-bit node identity is generated based on the that value. 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>
Diffstat (limited to 'net/tipc/addr.c')
-rw-r--r--net/tipc/addr.c81
1 files changed, 67 insertions, 14 deletions
diff --git a/net/tipc/addr.c b/net/tipc/addr.c
index 6e06b4d981f1..4841e98591d0 100644
--- a/net/tipc/addr.c
+++ b/net/tipc/addr.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * net/tipc/addr.c: TIPC address utility routines 2 * net/tipc/addr.c: TIPC address utility routines
3 * 3 *
4 * Copyright (c) 2000-2006, Ericsson AB 4 * Copyright (c) 2000-2006, 2018, Ericsson AB
5 * Copyright (c) 2004-2005, 2010-2011, Wind River Systems 5 * Copyright (c) 2004-2005, 2010-2011, Wind River Systems
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
@@ -34,18 +34,9 @@
34 * POSSIBILITY OF SUCH DAMAGE. 34 * POSSIBILITY OF SUCH DAMAGE.
35 */ 35 */
36 36
37#include <linux/kernel.h>
38#include "addr.h" 37#include "addr.h"
39#include "core.h" 38#include "core.h"
40 39
41/**
42 * in_own_node - test for node inclusion; <0.0.0> always matches
43 */
44int in_own_node(struct net *net, u32 addr)
45{
46 return addr == tipc_own_addr(net) || !addr;
47}
48
49bool tipc_in_scope(bool legacy_format, u32 domain, u32 addr) 40bool tipc_in_scope(bool legacy_format, u32 domain, u32 addr)
50{ 41{
51 if (!domain || (domain == addr)) 42 if (!domain || (domain == addr))
@@ -61,9 +52,71 @@ bool tipc_in_scope(bool legacy_format, u32 domain, u32 addr)
61 return false; 52 return false;
62} 53}
63 54
64char *tipc_addr_string_fill(char *string, u32 addr) 55void tipc_set_node_id(struct net *net, u8 *id)
56{
57 struct tipc_net *tn = tipc_net(net);
58 u32 *tmp = (u32 *)id;
59
60 memcpy(tn->node_id, id, NODE_ID_LEN);
61 tipc_nodeid2string(tn->node_id_string, id);
62 tn->node_addr = tmp[0] ^ tmp[1] ^ tmp[2] ^ tmp[3];
63 pr_info("Own node identity %s, cluster identity %u\n",
64 tipc_own_id_string(net), tn->net_id);
65}
66
67void tipc_set_node_addr(struct net *net, u32 addr)
65{ 68{
66 snprintf(string, 16, "<%u.%u.%u>", 69 struct tipc_net *tn = tipc_net(net);
67 tipc_zone(addr), tipc_cluster(addr), tipc_node(addr)); 70 u8 node_id[NODE_ID_LEN] = {0,};
68 return string; 71
72 tn->node_addr = addr;
73 if (!tipc_own_id(net)) {
74 sprintf(node_id, "%x", addr);
75 tipc_set_node_id(net, node_id);
76 }
77 pr_info("32-bit node address hash set to %x\n", addr);
78}
79
80char *tipc_nodeid2string(char *str, u8 *id)
81{
82 int i;
83 u8 c;
84
85 /* Already a string ? */
86 for (i = 0; i < NODE_ID_LEN; i++) {
87 c = id[i];
88 if (c >= '0' && c <= '9')
89 continue;
90 if (c >= 'A' && c <= 'Z')
91 continue;
92 if (c >= 'a' && c <= 'z')
93 continue;
94 if (c == '.')
95 continue;
96 if (c == ':')
97 continue;
98 if (c == '_')
99 continue;
100 if (c == '-')
101 continue;
102 if (c == '@')
103 continue;
104 if (c != 0)
105 break;
106 }
107 if (i == NODE_ID_LEN) {
108 memcpy(str, id, NODE_ID_LEN);
109 str[NODE_ID_LEN] = 0;
110 return str;
111 }
112
113 /* Translate to hex string */
114 for (i = 0; i < NODE_ID_LEN; i++)
115 sprintf(&str[2 * i], "%02x", id[i]);
116
117 /* Strip off trailing zeroes */
118 for (i = NODE_ID_STR_LEN - 2; str[i] == '0'; i--)
119 str[i] = 0;
120
121 return str;
69} 122}