Skip to content

Commit d50ccc2

Browse files
Jon Maloydavem330
authored andcommitted
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 <[email protected]> Signed-off-by: Jon Maloy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 23fd3ea commit d50ccc2

File tree

12 files changed

+148
-56
lines changed

12 files changed

+148
-56
lines changed

include/uapi/linux/tipc_netlink.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ enum {
169169
TIPC_NLA_NET_UNSPEC,
170170
TIPC_NLA_NET_ID, /* u32 */
171171
TIPC_NLA_NET_ADDR, /* u32 */
172+
TIPC_NLA_NET_NODEID, /* u64 */
173+
TIPC_NLA_NET_NODEID_W1, /* u64 */
172174

173175
__TIPC_NLA_NET_MAX,
174176
TIPC_NLA_NET_MAX = __TIPC_NLA_NET_MAX - 1

net/tipc/addr.c

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* net/tipc/addr.c: TIPC address utility routines
33
*
4-
* Copyright (c) 2000-2006, Ericsson AB
4+
* Copyright (c) 2000-2006, 2018, Ericsson AB
55
* Copyright (c) 2004-2005, 2010-2011, Wind River Systems
66
* All rights reserved.
77
*
@@ -34,18 +34,9 @@
3434
* POSSIBILITY OF SUCH DAMAGE.
3535
*/
3636

37-
#include <linux/kernel.h>
3837
#include "addr.h"
3938
#include "core.h"
4039

41-
/**
42-
* in_own_node - test for node inclusion; <0.0.0> always matches
43-
*/
44-
int in_own_node(struct net *net, u32 addr)
45-
{
46-
return addr == tipc_own_addr(net) || !addr;
47-
}
48-
4940
bool tipc_in_scope(bool legacy_format, u32 domain, u32 addr)
5041
{
5142
if (!domain || (domain == addr))
@@ -61,9 +52,71 @@ bool tipc_in_scope(bool legacy_format, u32 domain, u32 addr)
6152
return false;
6253
}
6354

64-
char *tipc_addr_string_fill(char *string, u32 addr)
55+
void 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+
67+
void tipc_set_node_addr(struct net *net, u32 addr)
6568
{
66-
snprintf(string, 16, "<%u.%u.%u>",
67-
tipc_zone(addr), tipc_cluster(addr), tipc_node(addr));
68-
return string;
69+
struct tipc_net *tn = tipc_net(net);
70+
u8 node_id[NODE_ID_LEN] = {0,};
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+
80+
char *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;
69122
}

net/tipc/addr.h

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* net/tipc/addr.h: Include file for TIPC address utility routines
33
*
4-
* Copyright (c) 2000-2006, Ericsson AB
4+
* Copyright (c) 2000-2006, 2018, Ericsson AB
55
* Copyright (c) 2004-2005, Wind River Systems
66
* All rights reserved.
77
*
@@ -44,10 +44,22 @@
4444
#include "core.h"
4545

4646
static inline u32 tipc_own_addr(struct net *net)
47+
{
48+
return tipc_net(net)->node_addr;
49+
}
50+
51+
static inline u8 *tipc_own_id(struct net *net)
4752
{
4853
struct tipc_net *tn = tipc_net(net);
4954

50-
return tn->own_addr;
55+
if (!strlen(tn->node_id_string))
56+
return NULL;
57+
return tn->node_id;
58+
}
59+
60+
static inline char *tipc_own_id_string(struct net *net)
61+
{
62+
return tipc_net(net)->node_id_string;
5163
}
5264

5365
static inline u32 tipc_cluster_mask(u32 addr)
@@ -65,9 +77,15 @@ static inline int tipc_scope2node(struct net *net, int sc)
6577
return sc != TIPC_NODE_SCOPE ? 0 : tipc_own_addr(net);
6678
}
6779

68-
u32 tipc_own_addr(struct net *net);
69-
int in_own_node(struct net *net, u32 addr);
80+
static inline int in_own_node(struct net *net, u32 addr)
81+
{
82+
return addr == tipc_own_addr(net) || !addr;
83+
}
84+
7085
bool tipc_in_scope(bool legacy_format, u32 domain, u32 addr);
71-
char *tipc_addr_string_fill(char *string, u32 addr);
86+
void tipc_set_node_id(struct net *net, u8 *id);
87+
void tipc_set_node_addr(struct net *net, u32 addr);
88+
char *tipc_nodeid2string(char *str, u8 *id);
89+
u32 tipc_node_id2hash(u8 *id128);
7290

7391
#endif

net/tipc/core.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ static int __net_init tipc_init_net(struct net *net)
5656
int err;
5757

5858
tn->net_id = 4711;
59-
tn->own_addr = 0;
59+
tn->node_addr = 0;
60+
memset(tn->node_id, 0, sizeof(tn->node_id));
61+
memset(tn->node_id_string, 0, sizeof(tn->node_id_string));
6062
tn->mon_threshold = TIPC_DEF_MON_THRESHOLD;
6163
get_random_bytes(&tn->random, sizeof(int));
6264
INIT_LIST_HEAD(&tn->node_list);

net/tipc/core.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,17 @@ struct tipc_monitor;
7272
#define NODE_HTABLE_SIZE 512
7373
#define MAX_BEARERS 3
7474
#define TIPC_DEF_MON_THRESHOLD 32
75+
#define NODE_ID_LEN 16
76+
#define NODE_ID_STR_LEN (NODE_ID_LEN * 2 + 1)
7577

7678
extern unsigned int tipc_net_id __read_mostly;
7779
extern int sysctl_tipc_rmem[3] __read_mostly;
7880
extern int sysctl_tipc_named_timeout __read_mostly;
7981

8082
struct tipc_net {
81-
u32 own_addr;
83+
u8 node_id[NODE_ID_LEN];
84+
u32 node_addr;
85+
char node_id_string[NODE_ID_STR_LEN];
8286
int net_id;
8387
int random;
8488
bool legacy_addr_format;

net/tipc/discover.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,11 @@ static void tipc_disc_msg_xmit(struct net *net, u32 mtyp, u32 dst, u32 src,
118118
static void disc_dupl_alert(struct tipc_bearer *b, u32 node_addr,
119119
struct tipc_media_addr *media_addr)
120120
{
121-
char node_addr_str[16];
122121
char media_addr_str[64];
123122

124-
tipc_addr_string_fill(node_addr_str, node_addr);
125123
tipc_media_addr_printf(media_addr_str, sizeof(media_addr_str),
126124
media_addr);
127-
pr_warn("Duplicate %s using %s seen on <%s>\n", node_addr_str,
125+
pr_warn("Duplicate %x using %s seen on <%s>\n", node_addr,
128126
media_addr_str, b->name);
129127
}
130128

net/tipc/link.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ bool tipc_link_create(struct net *net, char *if_name, int bearer_id,
442442
struct sk_buff_head *namedq,
443443
struct tipc_link **link)
444444
{
445+
char *self_str = tipc_own_id_string(net);
445446
struct tipc_link *l;
446447

447448
l = kzalloc(sizeof(*l), GFP_ATOMIC);
@@ -451,7 +452,10 @@ bool tipc_link_create(struct net *net, char *if_name, int bearer_id,
451452
l->session = session;
452453

453454
/* Note: peer i/f name is completed by reset/activate message */
454-
sprintf(l->name, "%x:%s-%x:unknown", self, if_name, peer);
455+
if (strlen(self_str) > 16)
456+
sprintf(l->name, "%x:%s-%x:unknown", self, if_name, peer);
457+
else
458+
sprintf(l->name, "%s:%s-%x:unknown", self_str, if_name, peer);
455459
strcpy(l->if_name, if_name);
456460
l->addr = peer;
457461
l->peer_caps = peer_caps;

net/tipc/name_distr.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,20 +318,18 @@ void tipc_named_process_backlog(struct net *net)
318318
{
319319
struct distr_queue_item *e, *tmp;
320320
struct tipc_net *tn = net_generic(net, tipc_net_id);
321-
char addr[16];
322321
unsigned long now = get_jiffies_64();
323322

324323
list_for_each_entry_safe(e, tmp, &tn->dist_queue, next) {
325324
if (time_after(e->expires, now)) {
326325
if (!tipc_update_nametbl(net, &e->i, e->node, e->dtype))
327326
continue;
328327
} else {
329-
tipc_addr_string_fill(addr, e->node);
330-
pr_warn_ratelimited("Dropping name table update (%d) of {%u, %u, %u} from %s key=%u\n",
328+
pr_warn_ratelimited("Dropping name table update (%d) of {%u, %u, %u} from %x key=%u\n",
331329
e->dtype, ntohl(e->i.type),
332330
ntohl(e->i.lower),
333331
ntohl(e->i.upper),
334-
addr, ntohl(e->i.key));
332+
e->node, ntohl(e->i.key));
335333
}
336334
list_del(&e->next);
337335
kfree(e);

net/tipc/net.c

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,27 +104,31 @@
104104
* - A local spin_lock protecting the queue of subscriber events.
105105
*/
106106

107-
int tipc_net_start(struct net *net, u32 addr)
107+
int tipc_net_init(struct net *net, u8 *node_id, u32 addr)
108108
{
109-
struct tipc_net *tn = tipc_net(net);
110-
char addr_string[16];
109+
if (tipc_own_id(net)) {
110+
pr_info("Cannot configure node identity twice\n");
111+
return -1;
112+
}
113+
pr_info("Started in network mode\n");
111114

112-
tn->own_addr = addr;
115+
if (node_id) {
116+
tipc_set_node_id(net, node_id);
117+
tipc_net_finalize(net, tipc_own_addr(net));
118+
}
119+
if (addr)
120+
tipc_net_finalize(net, addr);
121+
return 0;
122+
}
113123

114-
/* Ensure that the new address is visible before we reinit. */
124+
void tipc_net_finalize(struct net *net, u32 addr)
125+
{
126+
tipc_set_node_addr(net, addr);
115127
smp_mb();
116-
117128
tipc_named_reinit(net);
118129
tipc_sk_reinit(net);
119-
120130
tipc_nametbl_publish(net, TIPC_CFG_SRV, addr, addr,
121131
TIPC_CLUSTER_SCOPE, 0, addr);
122-
123-
pr_info("Started in network mode\n");
124-
pr_info("Own node address %s, cluster identity %u\n",
125-
tipc_addr_string_fill(addr_string, addr),
126-
tn->net_id);
127-
return 0;
128132
}
129133

130134
void tipc_net_stop(struct net *net)
@@ -146,8 +150,10 @@ void tipc_net_stop(struct net *net)
146150
static int __tipc_nl_add_net(struct net *net, struct tipc_nl_msg *msg)
147151
{
148152
struct tipc_net *tn = net_generic(net, tipc_net_id);
149-
void *hdr;
153+
u64 *w0 = (u64 *)&tn->node_id[0];
154+
u64 *w1 = (u64 *)&tn->node_id[8];
150155
struct nlattr *attrs;
156+
void *hdr;
151157

152158
hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
153159
NLM_F_MULTI, TIPC_NL_NET_GET);
@@ -160,7 +166,10 @@ static int __tipc_nl_add_net(struct net *net, struct tipc_nl_msg *msg)
160166

161167
if (nla_put_u32(msg->skb, TIPC_NLA_NET_ID, tn->net_id))
162168
goto attr_msg_full;
163-
169+
if (nla_put_u64_64bit(msg->skb, TIPC_NLA_NET_NODEID, *w0, 0))
170+
goto attr_msg_full;
171+
if (nla_put_u64_64bit(msg->skb, TIPC_NLA_NET_NODEID_W1, *w1, 0))
172+
goto attr_msg_full;
164173
nla_nest_end(msg->skb, attrs);
165174
genlmsg_end(msg->skb, hdr);
166175

@@ -212,6 +221,7 @@ int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
212221
err = nla_parse_nested(attrs, TIPC_NLA_NET_MAX,
213222
info->attrs[TIPC_NLA_NET], tipc_nl_net_policy,
214223
info->extack);
224+
215225
if (err)
216226
return err;
217227

@@ -236,9 +246,18 @@ int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
236246
if (!addr)
237247
return -EINVAL;
238248
tn->legacy_addr_format = true;
239-
tipc_net_start(net, addr);
249+
tipc_net_init(net, NULL, addr);
240250
}
241251

252+
if (attrs[TIPC_NLA_NET_NODEID]) {
253+
u8 node_id[NODE_ID_LEN];
254+
u64 *w0 = (u64 *)&node_id[0];
255+
u64 *w1 = (u64 *)&node_id[8];
256+
257+
*w0 = nla_get_u64(attrs[TIPC_NLA_NET_NODEID]);
258+
*w1 = nla_get_u64(attrs[TIPC_NLA_NET_NODEID_W1]);
259+
tipc_net_init(net, node_id, 0);
260+
}
242261
return 0;
243262
}
244263

net/tipc/net.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@
4141

4242
extern const struct nla_policy tipc_nl_net_policy[];
4343

44-
int tipc_net_start(struct net *net, u32 addr);
45-
44+
void tipc_net_finalize(struct net *net, u32 addr);
4645
void tipc_net_stop(struct net *net);
47-
4846
int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb);
4947
int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info);
5048
int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info);

net/tipc/node.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -883,11 +883,9 @@ void tipc_node_delete_links(struct net *net, int bearer_id)
883883

884884
static void tipc_node_reset_links(struct tipc_node *n)
885885
{
886-
char addr_string[16];
887886
int i;
888887

889-
pr_warn("Resetting all links to %s\n",
890-
tipc_addr_string_fill(addr_string, n->addr));
888+
pr_warn("Resetting all links to %x\n", n->addr);
891889

892890
for (i = 0; i < MAX_BEARERS; i++) {
893891
tipc_node_link_down(n, i, false);
@@ -1074,15 +1072,13 @@ static void tipc_node_fsm_evt(struct tipc_node *n, int evt)
10741072
static void node_lost_contact(struct tipc_node *n,
10751073
struct sk_buff_head *inputq)
10761074
{
1077-
char addr_string[16];
10781075
struct tipc_sock_conn *conn, *safe;
10791076
struct tipc_link *l;
10801077
struct list_head *conns = &n->conn_sks;
10811078
struct sk_buff *skb;
10821079
uint i;
10831080

1084-
pr_debug("Lost contact with %s\n",
1085-
tipc_addr_string_fill(addr_string, n->addr));
1081+
pr_debug("Lost contact with %x\n", n->addr);
10861082

10871083
/* Clean up broadcast state */
10881084
tipc_bcast_remove_peer(n->net, n->bc_entry.link);

0 commit comments

Comments
 (0)