int ipc_eval_route_packet(struct routemsg *msg) { struct route_entry rt_ent; char dev[5]; char gw[16]; char itoa_buf[10]; dev[4] = '\0'; memset(&gw[0], 0, 16); printf("Processing route packet\n"); memset(rt_ent.if_name, 0, MAX_IF_NAMESIZ); /* Fill struct */ memcpy(&rt_ent.gw, &msg->gateway_addr, ipsize); memcpy(&rt_ent.dst, &msg->target_addr, ipsize); memcpy(rt_ent.if_name, msg->device, 4); rt_ent.hopcnt = msg->metric; if (msg->add) { memcpy(&dev[0], &msg->device[0], 4); /*Add node to node list */ memcpy(&gw[0], ip_to_string(&msg->gateway_addr), 16); gui_itoa(msg->metric, itoa_buf); route_list_add(ip_to_string(&msg->target_addr), gw, dev, itoa_buf); printf("\tRoute to %s(hc %d) added\n", ip_to_string(&msg->target_addr), rt_ent.hopcnt); /* printf("\tRoute to %s added\n", ip_to_string(&msg->target_addr)); printf("\tGateway %s\n", gw); printf("\tInterface %s\n", msg->device); printf("\tMetric %d\n", msg->metric); */ } else { if (route_list_del(ip_to_string(&msg->target_addr)) < 1) printf("COULD NOT FIND ROUTE TO DELETE!\n\n"); printf("\tRoute to %s deleted\n", ip_to_string(&msg->target_addr)); } return 1; }
/** * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS message * * @param cls identification of the client * @param msg the actual message */ void handle_link_controllers (void *cls, const struct GNUNET_TESTBED_ControllerLinkRequest *msg) { struct GNUNET_SERVICE_Client *client = cls; struct LCFContext *lcf; struct Route *route; struct Route *new_route; uint64_t op_id; uint32_t delegated_host_id; uint32_t slave_host_id; if (NULL == GST_context) { GNUNET_break (0); GNUNET_SERVICE_client_drop (client); return; } delegated_host_id = ntohl (msg->delegated_host_id); if (delegated_host_id == GST_context->host_id) { GNUNET_break (0); LOG (GNUNET_ERROR_TYPE_WARNING, "Trying to link ourselves\n"); GNUNET_SERVICE_client_drop (client); return; } if ((delegated_host_id >= GST_host_list_size) || (NULL == GST_host_list[delegated_host_id])) { LOG (GNUNET_ERROR_TYPE_WARNING, "Delegated host %u not registered with us\n", delegated_host_id); GNUNET_SERVICE_client_drop (client); return; } slave_host_id = ntohl (msg->slave_host_id); if ((slave_host_id >= GST_host_list_size) || (NULL == GST_host_list[slave_host_id])) { LOG (GNUNET_ERROR_TYPE_WARNING, "Slave host %u not registered with us\n", slave_host_id); GNUNET_SERVICE_client_drop (client); return; } if (slave_host_id == delegated_host_id) { LOG (GNUNET_ERROR_TYPE_WARNING, "Slave and delegated host are same\n"); GNUNET_SERVICE_client_drop (client); return; } op_id = GNUNET_ntohll (msg->operation_id); if (slave_host_id == GST_context->host_id) /* Link from us */ { struct Slave *slave; struct LinkControllersContext *lcc; if (1 != msg->is_subordinate) { struct Neighbour *n; struct NeighbourConnectCtxt *ncc; if ((delegated_host_id < neighbour_list_size) && (NULL != neighbour_list[delegated_host_id])) { GNUNET_break (0); GNUNET_SERVICE_client_drop (client); return; } LOG_DEBUG ("Received request to establish a link to host %u\n", delegated_host_id); n = GST_create_neighbour (GST_host_list[delegated_host_id]); ncc = GNUNET_new (struct NeighbourConnectCtxt); ncc->n = n; ncc->op_id = op_id; ncc->client = client; ncc->nh = GST_neighbour_get_connection (n, &neighbour_connect_cb, ncc); ncc->timeout_task = GNUNET_SCHEDULER_add_delayed (GST_timeout, &timeout_neighbour_connect, ncc); GNUNET_CONTAINER_DLL_insert_tail (ncc_head, ncc_tail, ncc); GNUNET_SERVICE_client_continue (client); return; } if ( (delegated_host_id < GST_slave_list_size) && (NULL != GST_slave_list[delegated_host_id]) ) { GNUNET_break (0); GNUNET_SERVICE_client_drop (client); return; } LOG_DEBUG ("Received request to start and establish a link to host %u\n", delegated_host_id); slave = GNUNET_new (struct Slave); slave->host_id = delegated_host_id; slave->reghost_map = GNUNET_CONTAINER_multihashmap_create (100, GNUNET_NO); slave_list_add (slave); lcc = GNUNET_new (struct LinkControllersContext); lcc->operation_id = op_id; lcc->client = client; slave->lcc = lcc; slave->controller_proc = GNUNET_TESTBED_controller_start (GST_context->master_ip, GST_host_list[slave->host_id], &slave_status_cb, slave); new_route = GNUNET_new (struct Route); new_route->dest = delegated_host_id; new_route->thru = GST_context->host_id; route_list_add (new_route); return; } /* Route the request */ if (slave_host_id >= route_list_size) { LOG (GNUNET_ERROR_TYPE_WARNING, "No route towards slave host"); GNUNET_SERVICE_client_drop (client); return; } lcf = GNUNET_new (struct LCFContext); lcf->delegated_host_id = delegated_host_id; lcf->slave_host_id = slave_host_id; route = GST_find_dest_route (slave_host_id); GNUNET_assert (NULL != route); /* because we add routes carefully */ GNUNET_assert (route->dest < GST_slave_list_size); GNUNET_assert (NULL != GST_slave_list[route->dest]); lcf->is_subordinate = msg->is_subordinate; lcf->state = INIT; lcf->operation_id = op_id; lcf->gateway = GST_slave_list[route->dest]; lcf->client = client; if (NULL == lcf_head) { GNUNET_assert (NULL == lcf_proc_task_id); GNUNET_CONTAINER_DLL_insert_tail (lcf_head, lcf_tail, lcf); lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); } else { GNUNET_CONTAINER_DLL_insert_tail (lcf_head, lcf_tail, lcf); } /* FIXME: Adding a new route should happen after the controllers are linked * successfully */ if (1 != msg->is_subordinate) { GNUNET_SERVICE_client_continue (client); return; } if ( (delegated_host_id < route_list_size) && (NULL != route_list[delegated_host_id]) ) { GNUNET_break_op (0); /* Are you trying to link delegated host twice * with is subordinate flag set to GNUNET_YES? */ GNUNET_SERVICE_client_drop (client); return; } new_route = GNUNET_new (struct Route); new_route->dest = delegated_host_id; new_route->thru = route->dest; route_list_add (new_route); GNUNET_SERVICE_client_continue (client); }