void tipc_cltr_send_ext_routes(struct cluster *c_ptr, u32 dest) { struct sk_buff *buf; struct tipc_msg *msg; u32 highest = c_ptr->highest_node; u32 n_num; int send = 0; if (in_own_cluster(c_ptr->addr)) return; assert(!is_slave(dest)); assert(in_own_cluster(dest)); highest = c_ptr->highest_node; buf = tipc_cltr_prepare_routing_msg(highest + 1, c_ptr->addr); if (buf) { msg = buf_msg(buf); msg_set_remote_node(msg, c_ptr->addr); msg_set_type(msg, EXT_ROUTING_TABLE); for (n_num = 1; n_num <= highest; n_num++) { if (c_ptr->nodes[n_num] && tipc_node_has_active_links(c_ptr->nodes[n_num])) { send = 1; msg_set_dataoctet(msg, n_num); } } if (send) tipc_link_send(buf, dest, dest); else buf_discard(buf); } else { warn("Memory squeeze: broadcast of external route failed\n"); } }
static void tipc_cltr_multicast(struct cluster *c_ptr, struct sk_buff *buf, u32 lower, u32 upper) { struct sk_buff *buf_copy; struct tipc_node *n_ptr; u32 n_num; u32 tstop; assert(lower <= upper); assert(((lower >= 1) && (lower <= tipc_max_nodes)) || ((lower >= LOWEST_SLAVE) && (lower <= tipc_highest_allowed_slave))); assert(((upper >= 1) && (upper <= tipc_max_nodes)) || ((upper >= LOWEST_SLAVE) && (upper <= tipc_highest_allowed_slave))); assert(in_own_cluster(c_ptr->addr)); tstop = is_slave(upper) ? c_ptr->highest_slave : c_ptr->highest_node; if (tstop > upper) tstop = upper; for (n_num = lower; n_num <= tstop; n_num++) { n_ptr = c_ptr->nodes[n_num]; if (n_ptr && tipc_node_has_active_links(n_ptr)) { buf_copy = skb_copy(buf, GFP_ATOMIC); if (buf_copy == NULL) break; msg_set_destnode(buf_msg(buf_copy), n_ptr->addr); tipc_link_send(buf_copy, n_ptr->addr, n_ptr->addr); } } buf_discard(buf); }
struct tipc_node *tipc_cltr_select_node(struct cluster *c_ptr, u32 selector) { u32 n_num; u32 mask = tipc_max_nodes; u32 start_entry; assert(!in_own_cluster(c_ptr->addr)); if (!c_ptr->highest_node) return NULL; /* Start entry must be random */ while (mask > c_ptr->highest_node) { mask >>= 1; } start_entry = (selector & mask) ? selector & mask : 1u; assert(start_entry <= c_ptr->highest_node); /* Lookup upwards with wrap-around */ for (n_num = start_entry; n_num <= c_ptr->highest_node; n_num++) { if (tipc_node_has_active_links(c_ptr->nodes[n_num])) return c_ptr->nodes[n_num]; } for (n_num = 1; n_num < start_entry; n_num++) { if (tipc_node_has_active_links(c_ptr->nodes[n_num])) return c_ptr->nodes[n_num]; } return NULL; }
u32 tipc_cltr_select_router(struct cluster *c_ptr, u32 ref) { u32 n_num; u32 ulim = c_ptr->highest_node; u32 mask; u32 tstart; assert(!in_own_cluster(c_ptr->addr)); if (!ulim) return 0; /* Start entry must be random */ mask = tipc_max_nodes; while (mask > ulim) mask >>= 1; tstart = ref & mask; n_num = tstart; /* Lookup upwards with wrap-around */ do { if (tipc_node_is_up(c_ptr->nodes[n_num])) break; } while (++n_num <= ulim); if (n_num > ulim) { n_num = 1; do { if (tipc_node_is_up(c_ptr->nodes[n_num])) break; } while (++n_num < tstart); if (n_num == tstart) return 0; } assert(n_num <= ulim); return tipc_node_select_router(c_ptr->nodes[n_num], ref); }
void tipc_disc_link_event(u32 addr, char *name, int up) { if (in_own_cluster(addr)) return; /* * Code for inter cluster link setup here */ }
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; }
void tipc_zone_send_external_routes(struct _zone *z_ptr, u32 dest) { u32 c_num; for (c_num = 1; c_num <= tipc_max_clusters; c_num++) { if (z_ptr->clusters[c_num]) { if (in_own_cluster(z_ptr->addr)) continue; tipc_cltr_send_ext_routes(z_ptr->clusters[c_num], dest); } } }
void tipc_cltr_attach_node(struct cluster *c_ptr, struct tipc_node *n_ptr) { u32 n_num = tipc_node(n_ptr->addr); u32 max_n_num = tipc_max_nodes; if (in_own_cluster(n_ptr->addr)) max_n_num = tipc_highest_allowed_slave; assert(n_num > 0); assert(n_num <= max_n_num); assert(c_ptr->nodes[n_num] == NULL); c_ptr->nodes[n_num] = n_ptr; if (n_num > c_ptr->highest_node) c_ptr->highest_node = n_num; }
void tipc_cltr_remove_as_router(struct cluster *c_ptr, u32 router) { u32 start_entry; u32 tstop; u32 n_num; if (is_slave(router)) return; /* Slave nodes can not be routers */ if (in_own_cluster(c_ptr->addr)) { start_entry = LOWEST_SLAVE; tstop = c_ptr->highest_slave; } else { start_entry = 1; tstop = c_ptr->highest_node; } for (n_num = start_entry; n_num <= tstop; n_num++) { if (c_ptr->nodes[n_num]) { tipc_node_remove_router(c_ptr->nodes[n_num], router); } } }
void tipc_cltr_broadcast(struct sk_buff *buf) { struct sk_buff *buf_copy; struct cluster *c_ptr; struct tipc_node *n_ptr; u32 n_num; u32 tstart; u32 tstop; u32 node_type; if (tipc_mode == TIPC_NET_MODE) { c_ptr = tipc_cltr_find(tipc_own_addr); assert(in_own_cluster(c_ptr->addr)); /* For now */ /* Send to standard nodes, then repeat loop sending to slaves */ tstart = 1; tstop = c_ptr->highest_node; for (node_type = 1; node_type <= 2; node_type++) { for (n_num = tstart; n_num <= tstop; n_num++) { n_ptr = c_ptr->nodes[n_num]; if (n_ptr && tipc_node_has_active_links(n_ptr)) { buf_copy = skb_copy(buf, GFP_ATOMIC); if (buf_copy == NULL) goto exit; msg_set_destnode(buf_msg(buf_copy), n_ptr->addr); tipc_link_send(buf_copy, n_ptr->addr, n_ptr->addr); } } tstart = LOWEST_SLAVE; tstop = c_ptr->highest_slave; } } exit: buf_discard(buf); }
void tipc_disc_recv_msg(struct sk_buff *buf, struct bearer *b_ptr) { struct link *link; struct tipc_media_addr media_addr; struct tipc_msg *msg = buf_msg(buf); u32 dest = msg_dest_domain(msg); u32 orig = msg_prevnode(msg); u32 net_id = msg_bc_netid(msg); u32 type = msg_type(msg); msg_get_media_addr(msg,&media_addr); msg_dbg(msg, "RECV:"); buf_discard(buf); if (net_id != tipc_net_id) return; if (!tipc_addr_domain_valid(dest)) return; if (!tipc_addr_node_valid(orig)) return; if (orig == tipc_own_addr) { if (memcmp(&media_addr, &b_ptr->publ.addr, sizeof(media_addr))) disc_dupl_alert(b_ptr, tipc_own_addr, &media_addr); return; } if (!in_scope(dest, tipc_own_addr)) return; if (is_slave(tipc_own_addr) && is_slave(orig)) return; if (is_slave(orig) && !in_own_cluster(orig)) return; if (in_own_cluster(orig)) { /* Always accept link here */ struct sk_buff *rbuf; struct tipc_media_addr *addr; struct tipc_node *n_ptr = tipc_node_find(orig); int link_fully_up; dbg(" in own cluster\n"); if (n_ptr == NULL) { n_ptr = tipc_node_create(orig); if (!n_ptr) return; } spin_lock_bh(&n_ptr->lock); link = n_ptr->links[b_ptr->identity]; if (!link) { dbg("creating link\n"); link = tipc_link_create(b_ptr, orig, &media_addr); if (!link) { spin_unlock_bh(&n_ptr->lock); return; } } addr = &link->media_addr; if (memcmp(addr, &media_addr, sizeof(*addr))) { if (tipc_link_is_up(link) || (!link->started)) { disc_dupl_alert(b_ptr, orig, &media_addr); spin_unlock_bh(&n_ptr->lock); return; } warn("Resetting link <%s>, peer interface address changed\n", link->name); memcpy(addr, &media_addr, sizeof(*addr)); tipc_link_reset(link); } link_fully_up = (link->state == WORKING_WORKING); spin_unlock_bh(&n_ptr->lock); if ((type == DSC_RESP_MSG) || link_fully_up) return; rbuf = tipc_disc_init_msg(DSC_RESP_MSG, 1, orig, b_ptr); if (rbuf != NULL) { msg_dbg(buf_msg(rbuf),"SEND:"); b_ptr->media->send_msg(rbuf, &b_ptr->publ, &media_addr); buf_discard(rbuf); } } }
void tipc_disc_recv_msg(struct sk_buff *buf, struct bearer *b_ptr) { struct link *link; struct tipc_media_addr media_addr; struct tipc_msg *msg = buf_msg(buf); u32 dest = msg_dest_domain(msg); u32 orig = msg_prevnode(msg); u32 net_id = msg_bc_netid(msg); u32 type = msg_type(msg); msg_get_media_addr(msg, &media_addr); buf_discard(buf); if (net_id != tipc_net_id) return; if (!tipc_addr_domain_valid(dest)) return; if (!tipc_addr_node_valid(orig)) return; if (orig == tipc_own_addr) { if (memcmp(&media_addr, &b_ptr->publ.addr, sizeof(media_addr))) disc_dupl_alert(b_ptr, tipc_own_addr, &media_addr); return; } if (!tipc_in_scope(dest, tipc_own_addr)) return; if (in_own_cluster(orig)) { /* Always accept link here */ struct sk_buff *rbuf; struct tipc_media_addr *addr; struct tipc_node *n_ptr = tipc_node_find(orig); int link_fully_up; if (n_ptr == NULL) { n_ptr = tipc_node_create(orig); if (!n_ptr) return; } spin_lock_bh(&n_ptr->lock); /* Don't talk to neighbor during cleanup after last session */ if (n_ptr->cleanup_required) { spin_unlock_bh(&n_ptr->lock); return; } link = n_ptr->links[b_ptr->identity]; if (!link) { link = tipc_link_create(b_ptr, orig, &media_addr); if (!link) { spin_unlock_bh(&n_ptr->lock); return; } } addr = &link->media_addr; if (memcmp(addr, &media_addr, sizeof(*addr))) { if (tipc_link_is_up(link) || (!link->started)) { disc_dupl_alert(b_ptr, orig, &media_addr); spin_unlock_bh(&n_ptr->lock); return; } warn("Resetting link <%s>, peer interface address changed\n", link->name); memcpy(addr, &media_addr, sizeof(*addr)); tipc_link_reset(link); } link_fully_up = link_working_working(link); spin_unlock_bh(&n_ptr->lock); if ((type == DSC_RESP_MSG) || link_fully_up) return; rbuf = tipc_disc_init_msg(DSC_RESP_MSG, 1, orig, b_ptr); if (rbuf != NULL) { b_ptr->media->send_msg(rbuf, &b_ptr->publ, &media_addr); buf_discard(rbuf); } } }
void tipc_disc_recv_msg(struct sk_buff *buf) { struct bearer *b_ptr = (struct bearer *)TIPC_SKB_CB(buf)->handle; struct link *link; struct tipc_media_addr media_addr; struct tipc_msg *msg = buf_msg(buf); u32 dest = msg_dest_domain(msg); u32 orig = msg_prevnode(msg); u32 net_id = msg_bc_netid(msg); u32 type = msg_type(msg); msg_get_media_addr(msg,&media_addr); msg_dbg(msg, "RECV:"); buf_discard(buf); if (net_id != tipc_net_id) return; if (!tipc_addr_domain_valid(dest)) return; if (!tipc_addr_node_valid(orig)) return; if (orig == tipc_own_addr) return; if (!in_scope(dest, tipc_own_addr)) return; if (is_slave(tipc_own_addr) && is_slave(orig)) return; if (is_slave(orig) && !in_own_cluster(orig)) return; if (in_own_cluster(orig)) { /* Always accept link here */ struct sk_buff *rbuf; struct tipc_media_addr *addr; struct node *n_ptr = tipc_node_find(orig); int link_up; dbg(" in own cluster\n"); if (n_ptr == NULL) { n_ptr = tipc_node_create(orig); } if (n_ptr == NULL) { warn("Memory squeeze; Failed to create node\n"); return; } spin_lock_bh(&n_ptr->lock); link = n_ptr->links[b_ptr->identity]; if (!link) { dbg("creating link\n"); link = tipc_link_create(b_ptr, orig, &media_addr); if (!link) { spin_unlock_bh(&n_ptr->lock); return; } } addr = &link->media_addr; if (memcmp(addr, &media_addr, sizeof(*addr))) { char addr_string[16]; warn("New bearer address for %s\n", addr_string_fill(addr_string, orig)); memcpy(addr, &media_addr, sizeof(*addr)); tipc_link_reset(link); } link_up = tipc_link_is_up(link); spin_unlock_bh(&n_ptr->lock); if ((type == DSC_RESP_MSG) || link_up) return; rbuf = tipc_disc_init_msg(DSC_RESP_MSG, 1, orig, b_ptr); if (rbuf != NULL) { msg_dbg(buf_msg(rbuf),"SEND:"); b_ptr->media->send_msg(rbuf, &b_ptr->publ, &media_addr); buf_discard(rbuf); } } }
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); }