char* tipc_dtoa(tipc_domain_t domain, char *buf, size_t len) { snprintf(buf, len, "%u.%u.%u", tipc_zone(domain), tipc_cluster(domain),tipc_node(domain)); buf[len] = 0; return buf; }
static int node_list_cb(const struct nlmsghdr *nlh, void *data) { uint32_t addr; struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh); struct nlattr *info[TIPC_NLA_MAX + 1] = {}; struct nlattr *attrs[TIPC_NLA_NODE_MAX + 1] = {}; mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info); if (!info[TIPC_NLA_NODE]) return MNL_CB_ERROR; mnl_attr_parse_nested(info[TIPC_NLA_NODE], parse_attrs, attrs); if (!attrs[TIPC_NLA_NODE_ADDR]) return MNL_CB_ERROR; addr = mnl_attr_get_u32(attrs[TIPC_NLA_NODE_ADDR]); printf("<%u.%u.%u>: ", tipc_zone(addr), tipc_cluster(addr), tipc_node(addr)); if (attrs[TIPC_NLA_NODE_UP]) printf("up\n"); else printf("down\n"); return MNL_CB_OK; }
static int cmd_node_get_addr(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data) { int sk; socklen_t sz = sizeof(struct sockaddr_tipc); struct sockaddr_tipc addr; if (!(sk = socket(AF_TIPC, SOCK_RDM, 0))) { fprintf(stderr, "opening TIPC socket: %s\n", strerror(errno)); return -1; } if (getsockname(sk, (struct sockaddr *)&addr, &sz) < 0) { fprintf(stderr, "getting TIPC socket address: %s\n", strerror(errno)); close(sk); return -1; } close(sk); printf("<%u.%u.%u>\n", tipc_zone(addr.addr.id.node), tipc_cluster(addr.addr.id.node), tipc_node(addr.addr.id.node)); return 0; }
char* tipc_rtoa(uint32_t type, uint32_t lower, uint32_t upper, tipc_domain_t domain, char *buf, size_t len) { snprintf(buf, len, "%u:%u:%u:%u.%u.%u", type, lower, upper, tipc_zone(domain), tipc_cluster(domain),tipc_node(domain)); buf[len] = 0; return buf; }
char* tipc_ntoa(const struct tipc_addr *addr, char *buf, size_t len) { snprintf(buf, len, "%u:%u:%u.%u.%u", addr->type, addr->instance, tipc_zone(addr->domain), tipc_cluster(addr->domain),tipc_node(addr->domain)); buf[len] = 0; return buf; }
struct cluster *tipc_cltr_create(u32 addr) { struct _zone *z_ptr; struct cluster *c_ptr; int max_nodes; c_ptr = kzalloc(sizeof(*c_ptr), GFP_ATOMIC); if (c_ptr == NULL) { warn("Cluster creation failure, no memory\n"); return NULL; } c_ptr->addr = tipc_addr(tipc_zone(addr), tipc_cluster(addr), 0); if (in_own_cluster(addr)) max_nodes = LOWEST_SLAVE + tipc_max_slaves; else max_nodes = tipc_max_nodes + 1; c_ptr->nodes = kcalloc(max_nodes + 1, sizeof(void*), GFP_ATOMIC); if (c_ptr->nodes == NULL) { warn("Cluster creation failure, no memory for node area\n"); kfree(c_ptr); return NULL; } if (in_own_cluster(addr)) tipc_local_nodes = c_ptr->nodes; c_ptr->highest_slave = LOWEST_SLAVE - 1; c_ptr->highest_node = 0; z_ptr = tipc_zone_find(tipc_zone(addr)); if (!z_ptr) { z_ptr = tipc_zone_create(addr); } if (!z_ptr) { kfree(c_ptr->nodes); kfree(c_ptr); return NULL; } tipc_zone_attach_cluster(z_ptr, c_ptr); c_ptr->owner = z_ptr; return c_ptr; }
static const char *addr2str(__u32 addr) { static char addr_area[4][16]; /* allow up to 4 uses in one printf() */ static int addr_crs = 0; addr_crs = (addr_crs + 1) & 3; sprintf(&addr_area[addr_crs][0], "<%u.%u.%u>", tipc_zone(addr), tipc_cluster(addr), tipc_node(addr)); return &addr_area[addr_crs][0]; }
static const char *addr2str(__u32 addr) { static char addr_area[2][16]; static int addr_crs = 0; addr_crs = !addr_crs; sprintf(&addr_area[addr_crs][0], "<%u.%u.%u>", tipc_zone(addr), tipc_cluster(addr), tipc_node(addr)); return &addr_area[addr_crs][0]; }
static int tipc_nl_compat_sk_dump(struct tipc_nl_compat_msg *msg, struct nlattr **attrs) { int err; u32 sock_ref; struct nlattr *sock[TIPC_NLA_SOCK_MAX + 1]; if (!attrs[TIPC_NLA_SOCK]) return -EINVAL; err = nla_parse_nested(sock, TIPC_NLA_SOCK_MAX, attrs[TIPC_NLA_SOCK], NULL, NULL); if (err) return err; sock_ref = nla_get_u32(sock[TIPC_NLA_SOCK_REF]); tipc_tlv_sprintf(msg->rep, "%u:", sock_ref); if (sock[TIPC_NLA_SOCK_CON]) { u32 node; struct nlattr *con[TIPC_NLA_CON_MAX + 1]; err = nla_parse_nested(con, TIPC_NLA_CON_MAX, sock[TIPC_NLA_SOCK_CON], NULL, NULL); if (err) return err; node = nla_get_u32(con[TIPC_NLA_CON_NODE]); tipc_tlv_sprintf(msg->rep, " connected to <%u.%u.%u:%u>", tipc_zone(node), tipc_cluster(node), tipc_node(node), nla_get_u32(con[TIPC_NLA_CON_SOCK])); if (con[TIPC_NLA_CON_FLAG]) tipc_tlv_sprintf(msg->rep, " via {%u,%u}\n", nla_get_u32(con[TIPC_NLA_CON_TYPE]), nla_get_u32(con[TIPC_NLA_CON_INST])); else tipc_tlv_sprintf(msg->rep, "\n"); } else if (sock[TIPC_NLA_SOCK_HAS_PUBL]) { tipc_tlv_sprintf(msg->rep, " bound to"); err = tipc_nl_compat_publ_dump(msg, sock_ref); if (err) return err; } tipc_tlv_sprintf(msg->rep, "\n"); return 0; }
static int nametable_show_cb(const struct nlmsghdr *nlh, void *data) { int *iteration = data; char port_id[PORTID_STR_LEN]; struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh); struct nlattr *info[TIPC_NLA_MAX + 1] = {}; struct nlattr *attrs[TIPC_NLA_NAME_TABLE_MAX + 1] = {}; struct nlattr *publ[TIPC_NLA_PUBL_MAX + 1] = {}; const char *scope[] = { "", "zone", "cluster", "node" }; mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info); if (!info[TIPC_NLA_NAME_TABLE]) return MNL_CB_ERROR; mnl_attr_parse_nested(info[TIPC_NLA_NAME_TABLE], parse_attrs, attrs); if (!attrs[TIPC_NLA_NAME_TABLE_PUBL]) return MNL_CB_ERROR; mnl_attr_parse_nested(attrs[TIPC_NLA_NAME_TABLE_PUBL], parse_attrs, publ); if (!publ[TIPC_NLA_NAME_TABLE_PUBL]) return MNL_CB_ERROR; if (!*iteration) printf("%-10s %-10s %-10s %-26s %-10s\n", "Type", "Lower", "Upper", "Port Identity", "Publication Scope"); (*iteration)++; snprintf(port_id, sizeof(port_id), "<%u.%u.%u:%u>", tipc_zone(mnl_attr_get_u32(publ[TIPC_NLA_PUBL_NODE])), tipc_cluster(mnl_attr_get_u32(publ[TIPC_NLA_PUBL_NODE])), tipc_node(mnl_attr_get_u32(publ[TIPC_NLA_PUBL_NODE])), mnl_attr_get_u32(publ[TIPC_NLA_PUBL_REF])); printf("%-10u %-10u %-10u %-26s %-12u", mnl_attr_get_u32(publ[TIPC_NLA_PUBL_TYPE]), mnl_attr_get_u32(publ[TIPC_NLA_PUBL_LOWER]), mnl_attr_get_u32(publ[TIPC_NLA_PUBL_UPPER]), port_id, mnl_attr_get_u32(publ[TIPC_NLA_PUBL_KEY])); printf("%s\n", scope[mnl_attr_get_u32(publ[TIPC_NLA_PUBL_SCOPE])]); return MNL_CB_OK; }
static void link_mon_print_peer_state(const uint32_t addr, const char *status, const char *monitored, const uint32_t dom_gen) { char addr_str[16]; sprintf(addr_str, "%u.%u.%u", tipc_zone(addr), tipc_cluster(addr), tipc_node(addr)); if (is_json_context()) { print_string(PRINT_JSON, "node", NULL, addr_str); print_string(PRINT_JSON, "status", NULL, status); print_string(PRINT_JSON, "monitored", NULL, monitored); print_uint(PRINT_JSON, "generation", NULL, dom_gen); } else { printf("%-*s", MAX_NODE_WIDTH, addr_str); printf("%-*s", STATUS_WIDTH, status); printf("%-*s", DIRECTLY_MON_WIDTH, monitored); printf("%-*u", MAX_DOM_GEN_WIDTH, dom_gen); } }
struct _zone *tipc_zone_create(u32 addr) { struct _zone *z_ptr; u32 z_num; if (!tipc_addr_domain_valid(addr)) { err("Zone creation failed, invalid domain 0x%x\n", addr); return NULL; } z_ptr = kzalloc(sizeof(*z_ptr), GFP_ATOMIC); if (!z_ptr) { warn("Zone creation failed, insufficient memory\n"); return NULL; } z_num = tipc_zone(addr); z_ptr->addr = tipc_addr(z_num, 0, 0); tipc_net.zones[z_num] = z_ptr; return z_ptr; }
int tipc_addr_domain_valid(u32 addr) { u32 n = tipc_node(addr); u32 c = tipc_cluster(addr); u32 z = tipc_zone(addr); u32 max_nodes = tipc_max_nodes; if (is_slave(addr)) max_nodes = LOWEST_SLAVE + tipc_max_slaves; if (n > max_nodes) return 0; if (c > tipc_max_clusters) return 0; if (z > tipc_max_zones) return 0; if (n && (!z || !c)) return 0; if (c && !z) return 0; return 1; }
void tipcTestServer(void) { int test; /* this is the test passed from the Test Client process */ int testIndex; /* this is the index used to find the actual test we want to run*/ int ntimes; /* this is the number of times a test will be run */ int res; /* the return code from the recv() */ int msgSize; /* the size of the message */ int sockfd_S; /* the socket used to receive the test from the client */ struct sockaddr_tipc addr; /* the TIPC address data structure */ struct sockaddr_tipc from; /* the address data structure for the client */ struct sockaddr_tipc self; /* the TIPC address data structure */ socklen_t fromLen = sizeof(struct sockaddr_tipc); /* the length of the return address */ socklen_t selfLen = sizeof(struct sockaddr_tipc); /* the length of the return address */ __u32 domain; __u32 client_domain; debug("Starting Server\n"); setServerAddr (&addr); msgSize = sizeof(test); while (1) { fflush (stdout); ntimes = TS_NUMTIMES; /* Get test identifier from client */ sockfd_S = createSocketTIPC (SOCK_RDM); bindSocketTIPC (sockfd_S, &addr); sendSyncTIPC (TS_SYNC_WAITING_FOR_TEST_ID); res = recvfrom (sockfd_S, (char *)&test, msgSize, 0, (struct sockaddr *) &from, &fromLen); if (res > 0) test = (int)ntohl(test); else test = TS_INVALID_TEST; if (getsockname (sockfd_S, (struct sockaddr *) &self, &selfLen) != 0) failTest ("getsockname() error"); domain = self.addr.id.node; client_domain= from.addr.id.node; client_in_same_cluster = ((tipc_zone(domain) == tipc_zone(client_domain)) && (tipc_cluster(domain) == tipc_cluster(client_domain))); closeSocketTIPC (sockfd_S); /* Validate test identifier */ if (test == TS_KILL_SERVER) { break; } if ((test >= ts_lastStressTest) || ((test >= ts_lastSanityTest) && (test <TS_FIRST_STRESS_TEST))) { printf("TIPC Server: Invalid test number (%d)\n", test); killme(1); } /* Run the specified test */ info("Server says test # %d\n", test); recvSyncTIPC (TS_SYNC_FINISHED_TEST_ID); for (testIndex = 0; testIndex <= TS_NUMBER_OF_TESTS; testIndex++) { if (serverList[testIndex].testNum == test) do { info("TIPC Server %s test...STARTED!\n",testName(test)); serverList[testIndex].test(); info("TIPC Server %s test...PASSED!\n\n",testName(test)); } while ( --ntimes > 0 ); } } printf("TIPC Server: Client told us to quit\n"); }
u32 tipc_net_next_node(u32 a) { if (tipc_net.zones[tipc_zone(a)]) return tipc_zone_next_node(a); return 0; }
u32 tipc_net_select_router(u32 addr, u32 ref) { return tipc_zone_select_router(tipc_net.zones[tipc_zone(addr)], addr, ref); }
static int tipc_nl_compat_name_table_dump(struct tipc_nl_compat_msg *msg, struct nlattr **attrs) { char port_str[27]; struct tipc_name_table_query *ntq; struct nlattr *nt[TIPC_NLA_NAME_TABLE_MAX + 1]; struct nlattr *publ[TIPC_NLA_PUBL_MAX + 1]; u32 node, depth, type, lowbound, upbound; static const char * const scope_str[] = {"", " zone", " cluster", " node"}; nla_parse_nested(nt, TIPC_NLA_NAME_TABLE_MAX, attrs[TIPC_NLA_NAME_TABLE], NULL); nla_parse_nested(publ, TIPC_NLA_PUBL_MAX, nt[TIPC_NLA_NAME_TABLE_PUBL], NULL); ntq = (struct tipc_name_table_query *)TLV_DATA(msg->req); depth = ntohl(ntq->depth); type = ntohl(ntq->type); lowbound = ntohl(ntq->lowbound); upbound = ntohl(ntq->upbound); if (!(depth & TIPC_NTQ_ALLTYPES) && (type != nla_get_u32(publ[TIPC_NLA_PUBL_TYPE]))) return 0; if (lowbound && (lowbound > nla_get_u32(publ[TIPC_NLA_PUBL_UPPER]))) return 0; if (upbound && (upbound < nla_get_u32(publ[TIPC_NLA_PUBL_LOWER]))) return 0; tipc_tlv_sprintf(msg->rep, "%-10u ", nla_get_u32(publ[TIPC_NLA_PUBL_TYPE])); if (depth == 1) goto out; tipc_tlv_sprintf(msg->rep, "%-10u %-10u ", nla_get_u32(publ[TIPC_NLA_PUBL_LOWER]), nla_get_u32(publ[TIPC_NLA_PUBL_UPPER])); if (depth == 2) goto out; node = nla_get_u32(publ[TIPC_NLA_PUBL_NODE]); sprintf(port_str, "<%u.%u.%u:%u>", tipc_zone(node), tipc_cluster(node), tipc_node(node), nla_get_u32(publ[TIPC_NLA_PUBL_REF])); tipc_tlv_sprintf(msg->rep, "%-26s ", port_str); if (depth == 3) goto out; tipc_tlv_sprintf(msg->rep, "%-10u %s", nla_get_u32(publ[TIPC_NLA_PUBL_REF]), scope_str[nla_get_u32(publ[TIPC_NLA_PUBL_SCOPE])]); out: tipc_tlv_sprintf(msg->rep, "\n"); return 0; }
struct tipc_node *tipc_net_select_remote_node(u32 addr, u32 ref) { return tipc_zone_select_remote_node(tipc_net.zones[tipc_zone(addr)], addr, ref); }
void tipc_cltr_recv_routing_table(struct sk_buff *buf) { struct tipc_msg *msg = buf_msg(buf); struct cluster *c_ptr; struct tipc_node *n_ptr; unchar *node_table; u32 table_size; u32 router; u32 rem_node = msg_remote_node(msg); u32 z_num; u32 c_num; u32 n_num; c_ptr = tipc_cltr_find(rem_node); if (!c_ptr) { c_ptr = tipc_cltr_create(rem_node); if (!c_ptr) { buf_discard(buf); return; } } node_table = buf->data + msg_hdr_sz(msg); table_size = msg_size(msg) - msg_hdr_sz(msg); router = msg_prevnode(msg); z_num = tipc_zone(rem_node); c_num = tipc_cluster(rem_node); switch (msg_type(msg)) { case LOCAL_ROUTING_TABLE: assert(is_slave(tipc_own_addr)); case EXT_ROUTING_TABLE: for (n_num = 1; n_num < table_size; n_num++) { if (node_table[n_num]) { u32 addr = tipc_addr(z_num, c_num, n_num); n_ptr = c_ptr->nodes[n_num]; if (!n_ptr) { n_ptr = tipc_node_create(addr); } if (n_ptr) tipc_node_add_router(n_ptr, router); } } break; case SLAVE_ROUTING_TABLE: assert(!is_slave(tipc_own_addr)); assert(in_own_cluster(c_ptr->addr)); for (n_num = 1; n_num < table_size; n_num++) { if (node_table[n_num]) { u32 slave_num = n_num + LOWEST_SLAVE; u32 addr = tipc_addr(z_num, c_num, slave_num); n_ptr = c_ptr->nodes[slave_num]; if (!n_ptr) { n_ptr = tipc_node_create(addr); } if (n_ptr) tipc_node_add_router(n_ptr, router); } } break; case ROUTE_ADDITION: if (!is_slave(tipc_own_addr)) { assert(!in_own_cluster(c_ptr->addr) || is_slave(rem_node)); } else { assert(in_own_cluster(c_ptr->addr) && !is_slave(rem_node)); } n_ptr = c_ptr->nodes[tipc_node(rem_node)]; if (!n_ptr) n_ptr = tipc_node_create(rem_node); if (n_ptr) tipc_node_add_router(n_ptr, router); break; case ROUTE_REMOVAL: if (!is_slave(tipc_own_addr)) { assert(!in_own_cluster(c_ptr->addr) || is_slave(rem_node)); } else { assert(in_own_cluster(c_ptr->addr) && !is_slave(rem_node)); } n_ptr = c_ptr->nodes[tipc_node(rem_node)]; if (n_ptr) tipc_node_remove_router(n_ptr, router); break; default: assert(!"Illegal routing manager message received\n"); } buf_discard(buf); }