0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 #include "addr.h"
0039 #include "core.h"
0040
0041 bool tipc_in_scope(bool legacy_format, u32 domain, u32 addr)
0042 {
0043 if (!domain || (domain == addr))
0044 return true;
0045 if (!legacy_format)
0046 return false;
0047 if (domain == tipc_cluster_mask(addr))
0048 return true;
0049 if (domain == (addr & TIPC_ZONE_CLUSTER_MASK))
0050 return true;
0051 if (domain == (addr & TIPC_ZONE_MASK))
0052 return true;
0053 return false;
0054 }
0055
0056 void tipc_set_node_id(struct net *net, u8 *id)
0057 {
0058 struct tipc_net *tn = tipc_net(net);
0059
0060 memcpy(tn->node_id, id, NODE_ID_LEN);
0061 tipc_nodeid2string(tn->node_id_string, id);
0062 tn->trial_addr = hash128to32(id);
0063 pr_info("Node identity %s, cluster identity %u\n",
0064 tipc_own_id_string(net), tn->net_id);
0065 }
0066
0067 void tipc_set_node_addr(struct net *net, u32 addr)
0068 {
0069 struct tipc_net *tn = tipc_net(net);
0070 u8 node_id[NODE_ID_LEN] = {0,};
0071
0072 tn->node_addr = addr;
0073 if (!tipc_own_id(net)) {
0074 sprintf(node_id, "%x", addr);
0075 tipc_set_node_id(net, node_id);
0076 }
0077 tn->trial_addr = addr;
0078 tn->addr_trial_end = jiffies;
0079 pr_info("Node number set to %u\n", addr);
0080 }
0081
0082 char *tipc_nodeid2string(char *str, u8 *id)
0083 {
0084 int i;
0085 u8 c;
0086
0087
0088 for (i = 0; i < NODE_ID_LEN; i++) {
0089 c = id[i];
0090 if (c >= '0' && c <= '9')
0091 continue;
0092 if (c >= 'A' && c <= 'Z')
0093 continue;
0094 if (c >= 'a' && c <= 'z')
0095 continue;
0096 if (c == '.')
0097 continue;
0098 if (c == ':')
0099 continue;
0100 if (c == '_')
0101 continue;
0102 if (c == '-')
0103 continue;
0104 if (c == '@')
0105 continue;
0106 if (c != 0)
0107 break;
0108 }
0109 if (i == NODE_ID_LEN) {
0110 memcpy(str, id, NODE_ID_LEN);
0111 str[NODE_ID_LEN] = 0;
0112 return str;
0113 }
0114
0115
0116 for (i = 0; i < NODE_ID_LEN; i++)
0117 sprintf(&str[2 * i], "%02x", id[i]);
0118
0119
0120 for (i = NODE_ID_STR_LEN - 2; str[i] == '0'; i--)
0121 str[i] = 0;
0122
0123 return str;
0124 }